Skip to content

Commit

Permalink
Add setjmp/longjmp and fix global constructors
Browse files Browse the repository at this point in the history
- GCC: Fix sibling indirect calls by appointing all caller-saved
  registers (except R1) as available register for the sibling
  function pointer. Closes issue #4.
- Fix constructors/destructors invocation from CRT. Closes issue #6.
- NEWLIB: Add setjmp/longjmp implementation. Closes issue #5.
- NEWLIB: Add empty gettimeofday to fix linker errors in some
  GCC test cases.
- GCC: Minor updates to the testsuite to filter out test cases that
  are note compatible with the PRU.
- BINUTILS: Switch ELF e_machine to 0x90, to be compatible with TI
  toolchain.  Please be warned that we cannot yet intermix
  intermediate object files between GCC and TI toolchains.
- BINUTILS: Remove the unused IMM5 relocation.

Results from running the GCC C testsuite:
                 === gcc Summary ===
 # of expected passes            81298
 # of unexpected failures        43
 # of unexpected successes       1
 # of expected failures          97
 # of unsupported tests          1964

Signed-off-by: Dimitar Dimitrov <dinuxbg@gmail.com>
  • Loading branch information
dinuxbg committed Jan 3, 2015
1 parent b92c58d commit c11cca8
Show file tree
Hide file tree
Showing 6 changed files with 6,841 additions and 277 deletions.
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

# On which upstream commits to apply patches. I frequently rebase so
# expect these to be somewhat random.
GCC_BASECOMMIT=d4f5579a0472648c2dfc7a73b3ed49d33128bb94
BINUTILS_BASECOMMIT=3946f7973c754ed65b7d1e0bf24b8e0618788242
NEWLIB_BASECOMMIT=183c67027c75ccc0f5b4953ce65a85eaa710e826
GCC_BASECOMMIT=4c7093c28bed4aeab4a6f0457f8631830465fdec
BINUTILS_BASECOMMIT=6bf6fd090ac8b4551a4f7906310fb77d0405545a
NEWLIB_BASECOMMIT=0daa4d6f9b06af8530e50d0dce793ef9a5292aec

GCC_GIT=https://github.com/mirrors/gcc.git
BINUTILS_GIT=https://github.com/bminor/binutils-gdb.git
Expand Down
168 changes: 73 additions & 95 deletions patches/binutils-gdb/0001-Initial-TI-PRU-binutils-port.patch
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
From 3bd5986ddf32cc91ff34d75028ee105e28e0cb89 Mon Sep 17 00:00:00 2001
From c11a97c82f67133b820fa9f265f040b576ccd368 Mon Sep 17 00:00:00 2001
From: Dimitar Dimitrov <dinuxbg@gmail.com>
Date: Sun, 23 Feb 2014 22:25:35 +0200
Subject: [PATCH 1/5] Initial TI PRU binutils port
Subject: [PATCH 1/4] Initial TI PRU binutils port

Although not very well tested, core functionality should be there.
PRU ELF format is still not finalized. Intention is to gradually make
it compatible with the TI one.

Signed-off-by: Dimitar Dimitrov <dinuxbg@gmail.com>
---
.gitignore | 2 +
bfd/Makefile.am | 4 +
bfd/Makefile.in | 6 +
bfd/archures.c | 4 +
bfd/bfd-in2.h | 14 +
bfd/bfd-in2.h | 13 +
bfd/config.bfd | 5 +
bfd/configure | 1 +
bfd/configure.ac | 1 +
bfd/cpu-pru.c | 43 +
bfd/elf-bfd.h | 1 +
bfd/elf32-pru.c | 919 ++
bfd/libbfd.h | 10 +
bfd/elf32-pru.c | 904 ++
bfd/libbfd.h | 9 +
bfd/po/SRC-POTFILES.in | 2 +
bfd/reloc.c | 23 +
bfd/reloc.c | 21 +
bfd/targets.c | 3 +
binutils/readelf.c | 11 +
config.sub | 2 +
elfcpp/elfcpp.h | 3 +-
elfcpp/elfcpp.h | 1 +
gas/Makefile.am | 2 +
gas/Makefile.in | 17 +
gas/config/obj-elf.c | 4 +
gas/config/tc-pru.c | 1623 ++++
gas/config/tc-pru.c | 1621 ++++
gas/config/tc-pru.h | 91 +
gas/configure.tgt | 2 +
gas/po/POTFILES.in | 2 +
Expand Down Expand Up @@ -62,14 +63,14 @@ Signed-off-by: Dimitar Dimitrov <dinuxbg@gmail.com>
gdb/pru-tdep.c | 871 ++
gdb/pru-tdep.h | 51 +
include/dis-asm.h | 1 +
include/elf/common.h | 3 +
include/elf/pru.h | 55 +
include/elf/common.h | 2 +-
include/elf/pru.h | 54 +
include/opcode/pru.h | 405 +
ld/Makefile.am | 5 +
ld/Makefile.in | 5 +
ld/configure.tgt | 1 +
ld/emulparams/pruelf.sh | 18 +
ld/scripttempl/pru.sc | 203 +
ld/scripttempl/pru.sc | 205 +
opcodes/Makefile.am | 2 +
opcodes/Makefile.in | 4 +
opcodes/configure | 1 +
Expand All @@ -89,7 +90,7 @@ Signed-off-by: Dimitar Dimitrov <dinuxbg@gmail.com>
sim/pru/pru.h | 95 +
sim/pru/pru.isa | 250 +
sim/pru/sim-main.h | 81 +
82 files changed, 22441 insertions(+), 3 deletions(-)
82 files changed, 22418 insertions(+), 3 deletions(-)
create mode 100644 bfd/cpu-pru.c
create mode 100644 bfd/elf32-pru.c
create mode 100644 gas/config/tc-pru.c
Expand Down Expand Up @@ -264,7 +265,7 @@ index 067e654..e524019 100644
&bfd_rl78_arch,
&bfd_rx_arch,
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 7f45316..686fa43 100644
index 7f45316..ff333c5 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2260,6 +2260,8 @@ enum bfd_architecture
Expand All @@ -276,14 +277,13 @@ index 7f45316..686fa43 100644
bfd_arch_last
};

@@ -5306,6 +5308,18 @@ a matching LO8XG part. */
@@ -5306,6 +5308,17 @@ a matching LO8XG part. */
BFD_RELOC_NIOS2_CALL_LO,
BFD_RELOC_NIOS2_CALL_HA,

+/* Relocations used by the TI PRU processor. */
+ BFD_RELOC_PRU_U8,
+ BFD_RELOC_PRU_U16,
+ BFD_RELOC_PRU_IMM5,
+ BFD_RELOC_PRU_HI16,
+ BFD_RELOC_PRU_LO16,
+ BFD_RELOC_PRU_U16_PMEMIMM,
Expand Down Expand Up @@ -405,10 +405,10 @@ index 5e53cba..a637100 100644
SPARC_ELF_DATA,
diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
new file mode 100644
index 0000000..4e3d579
index 0000000..e6d42cb
--- /dev/null
+++ b/bfd/elf32-pru.c
@@ -0,0 +1,919 @@
@@ -0,0 +1,904 @@
+/* 32-bit ELF support for TI PRU.
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Contributed by Dimitar Dimitrov <dinuxbg@gmail.com>
Expand Down Expand Up @@ -511,20 +511,6 @@ index 0000000..4e3d579
+ 0x00ffff00, /* dest_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_PRU_IMM5,
+ 0,
+ 2,
+ 5,
+ FALSE,
+ 16,
+ complain_overflow_bitfield,
+ bfd_elf_generic_reloc,
+ "R_PRU_IMM5",
+ FALSE,
+ 0x00ff0000,
+ 0x00ff0000,
+ FALSE),
+
+ HOWTO (R_PRU_HI16,
+ 0,
+ 2,
Expand Down Expand Up @@ -705,7 +691,6 @@ index 0000000..4e3d579
+static const struct elf_reloc_map pru_reloc_map[] = {
+ {BFD_RELOC_PRU_U8, R_PRU_U8},
+ {BFD_RELOC_PRU_U16, R_PRU_U16},
+ {BFD_RELOC_PRU_IMM5, R_PRU_IMM5},
+ {BFD_RELOC_PRU_HI16, R_PRU_HI16},
+ {BFD_RELOC_PRU_LO16, R_PRU_LO16},
+ {BFD_RELOC_PRU_U16_PMEMIMM, R_PRU_U16_PMEMIMM},
Expand Down Expand Up @@ -1329,16 +1314,15 @@ index 0000000..4e3d579
+
+#include "elf32-target.h"
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 8687ece..33a217e 100644
index 8687ece..f217cb7 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -2586,6 +2586,16 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
@@ -2586,6 +2586,15 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
"BFD_RELOC_NIOS2_GOT_HA",
"BFD_RELOC_NIOS2_CALL_LO",
"BFD_RELOC_NIOS2_CALL_HA",
+ "BFD_RELOC_PRU_U8",
+ "BFD_RELOC_PRU_U16",
+ "BFD_RELOC_PRU_IMM5",
+ "BFD_RELOC_PRU_HI16",
+ "BFD_RELOC_PRU_LO16",
+ "BFD_RELOC_PRU_U16_PMEMIMM",
Expand Down Expand Up @@ -1370,19 +1354,17 @@ index 83e393d..83a056e 100644
elf32-rx.c
elf32-s390.c
diff --git a/bfd/reloc.c b/bfd/reloc.c
index d902a9b..c46807e 100644
index 1677e86..b686e8a 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -6211,6 +6211,29 @@ ENUMDOC
@@ -6211,6 +6211,27 @@ ENUMDOC
Relocations used by the Altera Nios II core.

ENUM
+ BFD_RELOC_PRU_U8
+ENUMX
+ BFD_RELOC_PRU_U16
+ENUMX
+ BFD_RELOC_PRU_IMM5
+ENUMX
+ BFD_RELOC_PRU_HI16
+ENUMX
+ BFD_RELOC_PRU_LO16
Expand Down Expand Up @@ -1425,7 +1407,7 @@ index 71e59e0..44c3da9 100644

#ifdef BFD64
diff --git a/binutils/readelf.c b/binutils/readelf.c
index d9ddb35..ada9954 100644
index 8a53248..4d3d0fcf 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -137,6 +137,7 @@
Expand Down Expand Up @@ -1468,7 +1450,7 @@ index d9ddb35..ada9954 100644
case EM_PPC:
return reloc_type == 1; /* R_PPC_ADDR32. */
+ case EM_PRU:
+ return reloc_type == 12; /* R_PRU_BFD_RELOC_32. */
+ return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
case EM_RL78:
return reloc_type == 1; /* R_RL78_DIR32. */
case EM_RX:
Expand Down Expand Up @@ -1502,19 +1484,17 @@ index 7ffe373..5445010 100755
| rl78-* | romp-* | rs6000-* | rx-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h
index 3e55db5..ddf15e7 100644
index 3e55db5..7da3664 100644
--- a/elfcpp/elfcpp.h
+++ b/elfcpp/elfcpp.h
@@ -285,7 +285,8 @@ enum EM
// Vitesse IQ2000
EM_IQ2000 = 0xfeba,
// NIOS
- EM_NIOS32 = 0xfebb
+ EM_NIOS32 = 0xfebb,
+ EM_PRU = 0xfebc
// Old AVR objects used 0x1057 (EM_AVR is correct).
// Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
// Old FR30 objects used 0x3330 (EM_FR30 is correct).
@@ -268,6 +268,7 @@ enum EM
EM_UNICORE = 110,
EM_ALTERA_NIOS2 = 113,
EM_CRX = 114,
+ EM_PRU = 144,
EM_AARCH64 = 183,
EM_TILEGX = 191,
// The Morph MT.
diff --git a/gas/Makefile.am b/gas/Makefile.am
index f65225f..8419f2f 100644
--- a/gas/Makefile.am
Expand Down Expand Up @@ -1601,10 +1581,10 @@ index e2ef99e..bc6d5f6 100644
static void obj_elf_type (int);
diff --git a/gas/config/tc-pru.c b/gas/config/tc-pru.c
new file mode 100644
index 0000000..a88b7f8
index 0000000..693b30e
--- /dev/null
+++ b/gas/config/tc-pru.c
@@ -0,0 +1,1623 @@
@@ -0,0 +1,1621 @@
+/* TI PRU assembler.
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Contributed by Dimitar Dimitrov <dinuxbg@gmail.com>
Expand Down Expand Up @@ -2089,8 +2069,7 @@ index 0000000..a88b7f8
+ if (fixP->fx_r_type == BFD_RELOC_8
+ || fixP->fx_r_type == BFD_RELOC_16
+ || fixP->fx_r_type == BFD_RELOC_32
+ || fixP->fx_r_type == BFD_RELOC_PRU_U8
+ || fixP->fx_r_type == BFD_RELOC_PRU_IMM5)
+ || fixP->fx_r_type == BFD_RELOC_PRU_U8)
+ /* These relocs are against data, not instructions. */
+ as_bad_where (fixP->fx_file, fixP->fx_line,
+ _("immediate value 0x%x truncated to 0x%x"),
Expand Down Expand Up @@ -2167,7 +2146,6 @@ index 0000000..a88b7f8
+ || fixP->fx_r_type == BFD_RELOC_64
+ || fixP->fx_r_type == BFD_RELOC_PRU_U8
+ || fixP->fx_r_type == BFD_RELOC_PRU_U16
+ || fixP->fx_r_type == BFD_RELOC_PRU_IMM5
+ || fixP->fx_r_type == BFD_RELOC_PRU_HI16
+ || fixP->fx_r_type == BFD_RELOC_PRU_LO16
+ || fixP->fx_r_type == BFD_RELOC_PRU_U16_PMEMIMM
Expand Down Expand Up @@ -3935,7 +3913,7 @@ index be69b6f..8c4357d 100644
remote-m32r-sdi.c remote-mips.c \
remote-sim.c \
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 065e797..e8f1ab0 100644
index b2c752f..1e7f5a3 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -459,6 +459,12 @@ powerpc*-*-*)
Expand Down Expand Up @@ -5036,25 +5014,24 @@ index 7260d59..796afc3 100644
extern int print_insn_s390 (bfd_vma, disassemble_info *);
extern int print_insn_sh (bfd_vma, disassemble_info *);
diff --git a/include/elf/common.h b/include/elf/common.h
index 1d68f80..5a64ed0 100644
index 1d68f80..8c7f3e9 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -392,6 +392,9 @@
/* NIOS magic number - no EABI available. */
#define EM_NIOS32 0xFEBB

+/* PRU magic number */
+#define EM_PRU 0xFEBC
+
#define EM_CYGNUS_MEP 0xF00D /* Toshiba MeP */

#define EM_MOXIE 0xFEED /* Moxie */
@@ -245,7 +245,7 @@
#define EM_TI_C2000 141 /* Texas Instruments TMS320C2000 DSP family */
#define EM_TI_C5500 142 /* Texas Instruments TMS320C55x DSP family */
#define EM_res143 143 /* Reserved */
-#define EM_res144 144 /* Reserved */
+#define EM_PRU 144 /* Texas Instruments PRUSS */
#define EM_res145 145 /* Reserved */
#define EM_res146 146 /* Reserved */
#define EM_res147 147 /* Reserved */
diff --git a/include/elf/pru.h b/include/elf/pru.h
new file mode 100644
index 0000000..bdb75e1
index 0000000..7418ef8
--- /dev/null
+++ b/include/elf/pru.h
@@ -0,0 +1,55 @@
@@ -0,0 +1,54 @@
+/* TI PRU ELF support for BFD.
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Contributed by Dimitar Dimitrov <dinuxbg@gmail.com>
Expand Down Expand Up @@ -5093,18 +5070,17 @@ index 0000000..bdb75e1
+ RELOC_NUMBER (R_PRU_NONE, 0)
+ RELOC_NUMBER (R_PRU_U8, 1)
+ RELOC_NUMBER (R_PRU_U16, 2)
+ RELOC_NUMBER (R_PRU_IMM5, 3)
+ RELOC_NUMBER (R_PRU_HI16, 4)
+ RELOC_NUMBER (R_PRU_LO16, 5)
+ RELOC_NUMBER (R_PRU_U16_PMEMIMM, 6)
+ RELOC_NUMBER (R_PRU_S10_PCREL, 7)
+ RELOC_NUMBER (R_PRU_U8_PCREL, 8)
+ RELOC_NUMBER (R_PRU_32_PMEM, 9)
+ RELOC_NUMBER (R_PRU_16_PMEM, 10)
+ RELOC_NUMBER (R_PRU_BFD_RELOC_32, 11)
+ RELOC_NUMBER (R_PRU_BFD_RELOC_16, 12)
+ RELOC_NUMBER (R_PRU_BFD_RELOC_8, 13)
+ RELOC_NUMBER (R_PRU_ILLEGAL, 14)
+ RELOC_NUMBER (R_PRU_HI16, 3)
+ RELOC_NUMBER (R_PRU_LO16, 4)
+ RELOC_NUMBER (R_PRU_U16_PMEMIMM, 5)
+ RELOC_NUMBER (R_PRU_S10_PCREL, 6)
+ RELOC_NUMBER (R_PRU_U8_PCREL, 7)
+ RELOC_NUMBER (R_PRU_32_PMEM, 8)
+ RELOC_NUMBER (R_PRU_16_PMEM, 9)
+ RELOC_NUMBER (R_PRU_BFD_RELOC_32, 10)
+ RELOC_NUMBER (R_PRU_BFD_RELOC_16, 11)
+ RELOC_NUMBER (R_PRU_BFD_RELOC_8, 12)
+ RELOC_NUMBER (R_PRU_ILLEGAL, 13)
+END_RELOC_NUMBERS (R_PRU_maxext)
+
+/* Processor-specific section flags. */
Expand Down Expand Up @@ -5591,10 +5567,10 @@ index 0000000..8cfd10f
+ENTRY=_start
diff --git a/ld/scripttempl/pru.sc b/ld/scripttempl/pru.sc
new file mode 100644
index 0000000..41ca866
index 0000000..7648b82
--- /dev/null
+++ b/ld/scripttempl/pru.sc
@@ -0,0 +1,203 @@
@@ -0,0 +1,205 @@
+cat <<EOF
+OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
+OUTPUT_ARCH(${ARCH})
Expand Down Expand Up @@ -5702,15 +5678,6 @@ index 0000000..41ca866
+ *(.init9)
+ KEEP (*(.init9))
+
+ ${CONSTRUCTING+ __ctors_start = . ; }
+ ${CONSTRUCTING+ *(.ctors) }
+ ${CONSTRUCTING+ __ctors_end = . ; }
+ ${CONSTRUCTING+ __dtors_start = . ; }
+ ${CONSTRUCTING+ *(.dtors) }
+ ${CONSTRUCTING+ __dtors_end = . ; }
+ KEEP(SORT(*)(.ctors))
+ KEEP(SORT(*)(.dtors))
+
+ ${RELOCATING+. = ALIGN(4);}
+ *(.text)
+ ${RELOCATING+. = ALIGN(4);}
Expand Down Expand Up @@ -5742,7 +5709,18 @@ index 0000000..41ca866
+
+ .data ${RELOCATING-0} :
+ {
+ /* optional variable that user is prepared to have NULL address */
+ ${RELOCATING+ *(.data.atzero*)}
+
+ /* CRT is prepared for constructor/destructor table to have
+ a "valid" NULL address. */
+ ${CONSTRUCTING+ __ctors_start = . ; }
+ ${CONSTRUCTING+ KEEP (*(SORT_BY_INIT_PRIORITY(.ctors.*)))}
+ ${CONSTRUCTING+ __ctors_end = . ; }
+ ${CONSTRUCTING+ __dtors_start = . ; }
+ ${CONSTRUCTING+ KEEP (*(SORT_BY_INIT_PRIORITY(.dtors.*)))}
+ ${CONSTRUCTING+ __dtors_end = . ; }
+
+ /* DATA memory starts at address 0. So to avoid placing a valid static
+ variable at the invalid NULL address, we introduce the .data.atzero
+ section. If CRT can make some use of it - great. Otherwise skip a
Expand Down
Loading

0 comments on commit c11cca8

Please sign in to comment.