Skip to contentSkip to conversation

OpenRISC binutils updates and new relocs

PATCH New Stafford Horne 4 participants 16 messages Aug 21, 2018 – Oct 1, 2018

lore
Share & tools
lore
#0 lore raw

cover OpenRISC binutils updates and new relocs

Hello,

This series contains a lot of updates for OpenRISC binutils. Including:
- Definitions for missing instructions.
- New relocations used in the new GCC OpenRISC port
- A new instruction l.adrp

The patches were for the most part written by Richard Henderson, I have fixed a few bugs, added additional tests and wrote the ChangeLogs.

These patches have been tested and used in the new OpenRISC GCC clean-room rewrite done by Richard and Me.

http://stffrdhrn.github.io/software/embedded/openrisc/2018/02/03/openrisc_gcc_rewrite.html

-Stafford

Richard Henderson (2):
or1k: Add relocations for high-signed and low-stores
or1k: Add the l.muld, l.muldu, l.macu, l.msbu insns

Stafford Horne (2):
or1k: Fix messages for relocations in shared libraries
or1k: Add the l.adrp insn and supporting relocations

 bfd/bfd-in2.h                                 |   19 +-
 bfd/elf32-or1k.c                              | 1002 +++++++++++++----
 bfd/libbfd.h                                  |   19 +-
 bfd/reloc.c                                   |   34 +-
 cpu/or1k.opc                                  |  582 +++++-----
 cpu/or1korbis.cpu                             |  300 +++--
 gas/config/tc-or1k.c                          |    6 +
 gas/testsuite/gas/or1k/allinsn.d              |   50 +-
 gas/testsuite/gas/or1k/allinsn.s              |   25 +
 .../gas/or1k/{allinsn.exp => or1k.exp}        |    1 +
 gas/testsuite/gas/or1k/reloc-1.d              |   72 ++
 gas/testsuite/gas/or1k/reloc-1.s              |   76 ++
 gas/testsuite/gas/or1k/reloc-2.l              |   11 +
 gas/testsuite/gas/or1k/reloc-2.s              |   13 +
 include/elf/or1k.h                            |   19 +
 ld/testsuite/ld-or1k/offsets1.d               |  212 ++++
 ld/testsuite/ld-or1k/offsets1.s               |   14 +
 ld/testsuite/ld-or1k/or1k.exp                 |   91 ++
 ld/testsuite/ld-or1k/plt1.dd                  |   27 +
 ld/testsuite/ld-or1k/plt1.s                   |   11 +
 ld/testsuite/ld-or1k/plt1.x.dd                |   27 +
 ld/testsuite/ld-or1k/plta1.dd                 |   27 +
 ld/testsuite/ld-or1k/plta1.s                  |   11 +
 ld/testsuite/ld-or1k/pltlib.s                 |   12 +
 opcodes/or1k-asm.c                            |  587 +++++-----
 opcodes/or1k-desc.c                           |   34 +-
 opcodes/or1k-desc.h                           |   48 +-
 opcodes/or1k-dis.c                            |    3 +
 opcodes/or1k-ibld.c                           |   29 +-
 opcodes/or1k-opc.c                            |   44 +-
 opcodes/or1k-opc.h                            |   65 +-
 opcodes/or1k-opinst.c                         |   98 +-
 sim/common/cgen-ops.h                         |   36 +
 sim/or1k/cpu.h                                |   32 +
 sim/or1k/decode.c                             |  239 +++-
 sim/or1k/decode.h                             |   82 +-
 sim/or1k/model.c                              |  186 ++-
 sim/or1k/sem-switch.c                         |  281 ++++-
 sim/or1k/sem.c                                |  293 ++++-
 sim/testsuite/sim/or1k/div.S                  |   12 +-
 sim/testsuite/sim/or1k/mul.S                  |  109 +-
 41 files changed, 3643 insertions(+), 1196 deletions(-)
 rename gas/testsuite/gas/or1k/{allinsn.exp => or1k.exp} (83%)
 create mode 100644 gas/testsuite/gas/or1k/reloc-1.d
 create mode 100644 gas/testsuite/gas/or1k/reloc-1.s
 create mode 100644 gas/testsuite/gas/or1k/reloc-2.l
 create mode 100644 gas/testsuite/gas/or1k/reloc-2.s
 create mode 100644 ld/testsuite/ld-or1k/offsets1.d
 create mode 100644 ld/testsuite/ld-or1k/offsets1.s
 create mode 100644 ld/testsuite/ld-or1k/or1k.exp
 create mode 100644 ld/testsuite/ld-or1k/plt1.dd
 create mode 100644 ld/testsuite/ld-or1k/plt1.s
 create mode 100644 ld/testsuite/ld-or1k/plt1.x.dd
 create mode 100644 ld/testsuite/ld-or1k/plta1.dd
 create mode 100644 ld/testsuite/ld-or1k/plta1.s
 create mode 100644 ld/testsuite/ld-or1k/pltlib.s
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/4 or1k: Add relocations for high-signed and low-stores

From: Richard Henderson <[email protected]>

This patch adds the following target relocations:

- BFD_RELOC_HI16_S High 16-bit relocation, for used with signed
asm: ha() lower.
- BFD_RELOC_HI16_S_GOTOFF High 16-bit GOT offset relocation for local
asm: gotoffha() symbols, for use with signed lower.
- BFD_RELOC_OR1K_TLS_IE_AHI16 High 16-bit TLS relocation with initial
asm: gottpoffha() executable calculation, for use with signed
lower.
- BFD_RELOC_OR1K_TLS_LE_AHI16 High 16-bit TLS relocation for local executable
asm: tpoffha() variables, for use with signed lower.

- BFD_RELOC_OR1K_SLO16 Split lower 16-bit relocation, used with
asm: lo() OpenRISC store instructions.
- BFD_RELOC_OR1K_GOTOFF_SLO16 Split lower 16-bit GOT offset relocation for
asm: gotofflo() local symbols, used with OpenRISC store
instructions.
- BFD_RELOC_OR1K_TLS_LE_SLO16 Split lower 16-bit relocation for TLS local
asm: tpofflo() executable variables, used with OpenRISC store
instructions.

bfd/ChangeLog:

yyyy-mm-dd Richard Henderson <[email protected]>

* bfd-in2.h: Regenerated.
* elf32-or1k.c (N_ONES): New macro. (or1k_elf_howto_table): Fix R_OR1K_PLT26 to complain on overflow. Add definitions for R_OR1K_TLS_TPOFF, R_OR1K_TLS_DTPOFF, R_OR1K_TLS_DTPMOD, R_OR1K_AHI16, R_OR1K_GOTOFF_AHI16, R_OR1K_TLS_IE_AHI16, R_OR1K_TLS_LE_AHI16, R_OR1K_SLO16, R_OR1K_GOTOFF_SLO16, R_OR1K_TLS_LE_SLO16. (or1k_reloc_map): Add entries for BFD_RELOC_HI16_S, BFD_RELOC_LO16_GOTOFF, BFD_RELOC_HI16_GOTOFF, BFD_RELOC_HI16_S_GOTOFF, BFD_RELOC_OR1K_TLS_IE_AHI16, BFD_RELOC_OR1K_TLS_LE_AHI16, BFD_RELOC_OR1K_SLO16, BFD_RELOC_OR1K_GOTOFF_SLO16, BFD_RELOC_OR1K_TLS_LE_SLO16.
(or1k_reloc_type_lookup): Change search loop to start ad index 0 and also check results before returning. (or1k_reloc_name_lookup): Simplify loop to use R_OR1K_max as index limit.
(or1k_final_link_relocate): New function. (or1k_elf_relocate_section): Add support for new AHI and SLO relocations. Use or1k_final_link_relocate instead of generic _bfd_final_link_relocate.
(or1k_elf_check_relocs): Add support for new AHI and SLO relocations.
* reloc.c: Add new enums for BFD_RELOC_OR1K_SLO16, BFD_RELOC_OR1K_GOTOFF_SLO16, BFD_RELOC_OR1K_TLS_IE_AHI16, BFD_RELOC_OR1K_TLS_IE_AHI16, BFD_RELOC_OR1K_TLS_LE_AHI16, BFD_RELOC_OR1K_TLS_LE_SLO16. Remove unused BFD_RELOC_OR1K_GOTOFF_HI16 and BFD_RELOC_OR1K_GOTOFF_LO16.
* libbfd.h: Regenerated.

cpu/ChangeLog:

yyyy-mm-dd Richard Henderson <[email protected]>

* or1k.opc: Add RTYPE_ enum.
(INVALID_STORE_RELOC): New string. (or1k_imm16_relocs): New array array.
(parse_reloc): New static function that just does the parsing. (parse_imm16): New static function for generic parsing. (parse_simm16): Change to just call parse_imm16. (parse_simm16_split): New function.
(parse_uimm16): Change to call parse_imm16. (parse_uimm16_split): New function.
* or1korbis.cpu (simm16-split): Change to use new simm16_split. (uimm16-split): Change to use new uimm16_split.

gas/ChangeLog:

yyyy-mm-dd Richard Henderson <[email protected]>

* testsuite/gas/or1k/allinsn.d (l_ha): Add result for ha() relocation.
* testsuite/gas/or1k/allinsn.s (l_ha): Add test for ha() relocations.
* testsuite/gas/or1k/allinsn.exp: Renamed to or1k.exp.
* testsuite/gas/or1k/or1k.exp: Add reloc-2 list test.
* testsuite/gas/or1k/reloc-1.d: New file.
* testsuite/gas/or1k/reloc-1.s: New file.
* testsuite/gas/or1k/reloc-2.l: New file.
* testsuite/gas/or1k/reloc-2.s: New file.

include/ChangeLog:

yyyy-mm-dd Richard Henderson <[email protected]>

	* elf/or1k.h (elf_or1k_reloc_type): Add R_OR1K_AHI16,
	R_OR1K_GOTOFF_AHI16, R_OR1K_TLS_IE_AHI16, R_OR1K_TLS_LE_AHI16,
	R_OR1K_SLO16, R_OR1K_GOTOFF_SLO16, R_OR1K_TLS_LE_SLO16.

ld/ChangeLog:

yyyy-mm-dd Richard Henderson <[email protected]>

* testsuite/ld-or1k/offsets1.d: New file.
* testsuite/ld-or1k/offsets1.s: New file.
* testsuite/ld-or1k/or1k.exp: New file.

opcodes/ChangeLog:

yyyy-mm-dd Richard Henderson <[email protected]>

* or1k-asm.c: Regenerate.

---
 bfd/bfd-in2.h                                 |   7 +-
 bfd/elf32-or1k.c                              | 360 +++++++++++--
 bfd/libbfd.h                                  |   7 +-
 bfd/reloc.c                                   |  12 +-
 cpu/or1k.opc                                  | 475 +++++++-----------
 cpu/or1korbis.cpu                             |   4 +-
 gas/testsuite/gas/or1k/allinsn.d              |  19 +-
 gas/testsuite/gas/or1k/allinsn.s              |   2 +
 .../gas/or1k/{allinsn.exp => or1k.exp}        |   1 +
 gas/testsuite/gas/or1k/reloc-1.d              |  56 +++
 gas/testsuite/gas/or1k/reloc-1.s              |  56 +++
 gas/testsuite/gas/or1k/reloc-2.l              |  10 +
 gas/testsuite/gas/or1k/reloc-2.s              |  12 +
 include/elf/or1k.h                            |   7 +
 ld/testsuite/ld-or1k/offsets1.d               | 212 ++++++++
 ld/testsuite/ld-or1k/offsets1.s               |  14 +
 ld/testsuite/ld-or1k/or1k.exp                 |  69 +++
 opcodes/or1k-asm.c                            | 439 ++++++----------
 18 files changed, 1149 insertions(+), 613 deletions(-)
 rename gas/testsuite/gas/or1k/{allinsn.exp => or1k.exp} (83%)
 create mode 100644 gas/testsuite/gas/or1k/reloc-1.d
 create mode 100644 gas/testsuite/gas/or1k/reloc-1.s
 create mode 100644 gas/testsuite/gas/or1k/reloc-2.l
 create mode 100644 gas/testsuite/gas/or1k/reloc-2.s
 create mode 100644 ld/testsuite/ld-or1k/offsets1.d
 create mode 100644 ld/testsuite/ld-or1k/offsets1.s
 create mode 100644 ld/testsuite/ld-or1k/or1k.exp
bfd/bfd-in2.h +5 -2
index 58afff24c9..a51ead9273 100644
@@ -5467,12 +5467,12 @@ then it may be truncated to 8 bits.  */
 
 /* OpenRISC 1000 Relocations.  */
   BFD_RELOC_OR1K_REL_26,
+  BFD_RELOC_OR1K_SLO16,
   BFD_RELOC_OR1K_GOTPC_HI16,
   BFD_RELOC_OR1K_GOTPC_LO16,
   BFD_RELOC_OR1K_GOT16,
   BFD_RELOC_OR1K_PLT26,
-  BFD_RELOC_OR1K_GOTOFF_HI16,
-  BFD_RELOC_OR1K_GOTOFF_LO16,
+  BFD_RELOC_OR1K_GOTOFF_SLO16,
   BFD_RELOC_OR1K_COPY,
   BFD_RELOC_OR1K_GLOB_DAT,
   BFD_RELOC_OR1K_JMP_SLOT,
@@ -5484,9 +5484,12 @@ then it may be truncated to 8 bits.  */
   BFD_RELOC_OR1K_TLS_LDO_HI16,
   BFD_RELOC_OR1K_TLS_LDO_LO16,
   BFD_RELOC_OR1K_TLS_IE_HI16,
+  BFD_RELOC_OR1K_TLS_IE_AHI16,
   BFD_RELOC_OR1K_TLS_IE_LO16,
   BFD_RELOC_OR1K_TLS_LE_HI16,
+  BFD_RELOC_OR1K_TLS_LE_AHI16,
   BFD_RELOC_OR1K_TLS_LE_LO16,
+  BFD_RELOC_OR1K_TLS_LE_SLO16,
   BFD_RELOC_OR1K_TLS_TPOFF,
   BFD_RELOC_OR1K_TLS_DTPOFF,
   BFD_RELOC_OR1K_TLS_DTPMOD,
bfd/elf32-or1k.c +326 -34

528 lines not on this page · raw message

bfd/libbfd.h +5 -2
index 6c1e1ea9a5..f887e516ae 100644
@@ -2642,12 +2642,12 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_CRIS_DTPMOD",
   "BFD_RELOC_CRIS_32_IE",
   "BFD_RELOC_OR1K_REL_26",
+  "BFD_RELOC_OR1K_SLO16",
   "BFD_RELOC_OR1K_GOTPC_HI16",
   "BFD_RELOC_OR1K_GOTPC_LO16",
   "BFD_RELOC_OR1K_GOT16",
   "BFD_RELOC_OR1K_PLT26",
-  "BFD_RELOC_OR1K_GOTOFF_HI16",
-  "BFD_RELOC_OR1K_GOTOFF_LO16",
+  "BFD_RELOC_OR1K_GOTOFF_SLO16",
   "BFD_RELOC_OR1K_COPY",
   "BFD_RELOC_OR1K_GLOB_DAT",
   "BFD_RELOC_OR1K_JMP_SLOT",
@@ -2659,9 +2659,12 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_OR1K_TLS_LDO_HI16",
   "BFD_RELOC_OR1K_TLS_LDO_LO16",
   "BFD_RELOC_OR1K_TLS_IE_HI16",
+  "BFD_RELOC_OR1K_TLS_IE_AHI16",
   "BFD_RELOC_OR1K_TLS_IE_LO16",
   "BFD_RELOC_OR1K_TLS_LE_HI16",
+  "BFD_RELOC_OR1K_TLS_LE_AHI16",
   "BFD_RELOC_OR1K_TLS_LE_LO16",
+  "BFD_RELOC_OR1K_TLS_LE_SLO16",
   "BFD_RELOC_OR1K_TLS_TPOFF",
   "BFD_RELOC_OR1K_TLS_DTPOFF",
   "BFD_RELOC_OR1K_TLS_DTPMOD",
bfd/reloc.c +9 -3
index aaf3a801fd..de870441df 100644
@@ -6134,6 +6134,8 @@ ENUMDOC
 
 ENUM
   BFD_RELOC_OR1K_REL_26
+ENUMX
+  BFD_RELOC_OR1K_SLO16
 ENUMX
   BFD_RELOC_OR1K_GOTPC_HI16
 ENUMX
@@ -6143,9 +6145,7 @@ ENUMX
 ENUMX
   BFD_RELOC_OR1K_PLT26
 ENUMX
-  BFD_RELOC_OR1K_GOTOFF_HI16
-ENUMX
-  BFD_RELOC_OR1K_GOTOFF_LO16
+  BFD_RELOC_OR1K_GOTOFF_SLO16
 ENUMX
   BFD_RELOC_OR1K_COPY
 ENUMX
@@ -6168,12 +6168,18 @@ ENUMX
   BFD_RELOC_OR1K_TLS_LDO_LO16
 ENUMX
   BFD_RELOC_OR1K_TLS_IE_HI16
+ENUMX
+  BFD_RELOC_OR1K_TLS_IE_AHI16
 ENUMX
   BFD_RELOC_OR1K_TLS_IE_LO16
 ENUMX
   BFD_RELOC_OR1K_TLS_LE_HI16
+ENUMX
+  BFD_RELOC_OR1K_TLS_LE_AHI16
 ENUMX
   BFD_RELOC_OR1K_TLS_LE_LO16
+ENUMX
+  BFD_RELOC_OR1K_TLS_LE_SLO16
 ENUMX
   BFD_RELOC_OR1K_TLS_TPOFF
 ENUMX
cpu/or1k.opc +185 -290

516 lines not on this page · raw message

cpu/or1korbis.cpu +2 -2
index 408a135fa0..535bd28bff 100644
@@ -335,7 +335,7 @@
   (attrs (MACH ORBIS-MACHS) SIGN-OPT)
   (type h-simm16)
   (index f-simm16-split)
-  (handlers (parse "simm16"))
+  (handlers (parse "simm16_split"))
 )
 
 (define-operand
@@ -344,7 +344,7 @@
   (attrs (MACH ORBIS-MACHS))
   (type h-uimm16)
   (index f-uimm16-split)
-  (handlers (parse "uimm16"))
+  (handlers (parse "uimm16_split"))
 )
 
 ; Instructions.
gas/testsuite/gas/or1k/allinsn.d +11 -8
index 27884fe82d..1b36cce1bc 100644
@@ -679,11 +679,14 @@ Disassembly of section \.text:
 00000824 <l_hi>:
  824:	18 20 de ad 	l\.movhi r1,0xdead
 
-00000828 <l_mac>:
- 828:	c4 01 10 01 	l.mac r1,r2
-
-0000082c <l_maci>:
- 82c:	4c 01 00 00 	l\.maci r1,0
- 830:	4c 02 ff ff 	l\.maci r2,-1
- 834:	4c 02 7f ff 	l\.maci r2,32767
- 838:	4c 02 80 00 	l\.maci r2,-32768
+00000828 <l_ha>:
+ 828:	18 20 de ae 	l\.movhi r1,0xdeae
+
+0000082c <l_mac>:
+ 82c:	c4 01 10 01 	l.mac r1,r2
+
+00000830 <l_maci>:
+ 830:	4c 01 00 00 	l\.maci r1,0
+ 834:	4c 02 ff ff 	l\.maci r2,-1
+ 838:	4c 02 7f ff 	l\.maci r2,32767
+ 83c:	4c 02 80 00 	l\.maci r2,-32768
gas/testsuite/gas/or1k/allinsn.s +2 -0
index 05647f2ffd..321aea3036 100644
@@ -667,6 +667,8 @@ l_lo:
 	l.addi	r1, r1, lo(0xdeadbeef)
 l_hi:	
 	l.movhi	r1, hi(0xdeadbeef)
+l_ha:	
+	l.movhi	r1, ha(0xdeadbeef)
 
 l_mac:
 	l.mac r1,r2
gas/testsuite/gas/or1k/or1k.exp renamed from gas/testsuite/gas/or1k/allinsn.exp +1 -0
similarity index 83%
rename from gas/testsuite/gas/or1k/allinsn.exp
rename to gas/testsuite/gas/or1k/or1k.exp
index 11eacd766e..e0e0515f42 100644
@@ -2,4 +2,5 @@
 
 if [istarget or1k*-*-*] {
         run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+	run_list_test "reloc-2" ""
 }
gas/testsuite/gas/or1k/reloc-1.d new file +56 -0

56 lines not on this page · raw message

gas/testsuite/gas/or1k/reloc-1.s new file +56 -0

56 lines not on this page · raw message

gas/testsuite/gas/or1k/reloc-2.l new file +10 -0
new file mode 100644
index 0000000000..7a32a7dc14
@@ -0,0 +1,10 @@
+.*: Assembler messages:
+.*:2: Error: relocation invalid for store .*
+.*:3: Error: relocation invalid for store .*
+.*:4: Error: relocation invalid for store .*
+.*:6: Error: relocation invalid for store .*
+.*:7: Error: relocation invalid for store .*
+.*:8: Error: relocation invalid for store .*
+.*:9: Error: relocation invalid for store .*
+.*:11: Error: relocation invalid for store .*
+.*:12: Error: relocation invalid for store .*
gas/testsuite/gas/or1k/reloc-2.s new file +12 -0
new file mode 100644
index 0000000000..835dd1c84b
@@ -0,0 +1,12 @@
+	l.sw	lo(x)(r4),r3
+	l.sw	hi(x)(r4),r3
+	l.sw	ha(x)(r4),r3
+	l.sw	got(x)(r4),r3
+	l.sw	gotofflo(x)(r4),r3
+	l.sw	gotoffhi(x)(r4),r3
+	l.sw	gotoffha(x)(r4),r3
+	l.sw	dtpoffhi(x)(r4),r3
+	l.sw	gottpoffhi(x)(r4),r3
+	l.sw	tpofflo(x)(r4),r3
+	l.sw	tpoffhi(x)(r4),r3
+	l.sw	tpoffha(x)(r4),r3
include/elf/or1k.h +7 -0
index 0c5e15bcc8..e3291d31d3 100644
@@ -58,6 +58,13 @@ START_RELOC_NUMBERS (elf_or1k_reloc_type)
   RELOC_NUMBER (R_OR1K_TLS_TPOFF,     32)
   RELOC_NUMBER (R_OR1K_TLS_DTPOFF,    33)
   RELOC_NUMBER (R_OR1K_TLS_DTPMOD,    34)
+  RELOC_NUMBER (R_OR1K_AHI16,         35)
+  RELOC_NUMBER (R_OR1K_GOTOFF_AHI16,  36)
+  RELOC_NUMBER (R_OR1K_TLS_IE_AHI16,  37)
+  RELOC_NUMBER (R_OR1K_TLS_LE_AHI16,  38)
+  RELOC_NUMBER (R_OR1K_SLO16,         39)
+  RELOC_NUMBER (R_OR1K_GOTOFF_SLO16,  40)
+  RELOC_NUMBER (R_OR1K_TLS_LE_SLO16,  41)
 END_RELOC_NUMBERS (R_OR1K_max)
 
 #define EF_OR1K_NODELAY (1UL << 0)
ld/testsuite/ld-or1k/offsets1.d new file +212 -0

212 lines not on this page · raw message

ld/testsuite/ld-or1k/offsets1.s new file +14 -0
new file mode 100644
index 0000000000..94cb06887d
@@ -0,0 +1,14 @@
+	.data
+	.p2align 16
+x:	.skip	10000
+
+	.text
+	.globl	_start
+_start:
+
+	.set	i, 0
+.rept 100
+	l.movhi	r3, ha(x+i)
+	l.sw	lo(x+i)(r3), r0
+	.set	i, i+1000
+.endr
ld/testsuite/ld-or1k/or1k.exp new file +69 -0

69 lines not on this page · raw message

opcodes/or1k-asm.c +167 -272

511 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/4 or1k: Fix messages for relocations in shared libraries

In reply to Stafford Horne

Added checks include:

- Do not allow relocations to global symbols using relocations which are meant for local symbol relocations.
- Require the use of -fpic when compiling shared libraries.
- Require zero addend for plt relocations.

yyyy-mm-dd Richard Henderson <[email protected]>

bfd/ChangeLog:

* elf32-or1k.c (or1k_elf_relocate_section): Add error for unknown relocations. Add error for non zero addend with plt and got relocations. Add error for got and plt references against dynamic, non local, symbols. Add error when linking non shared liraries with flag_pic.

---
 bfd/elf32-or1k.c | 148 ++++++++++++++++++++++++++++-------------------
 1 file changed, 90 insertions(+), 58 deletions(-)
bfd/elf32-or1k.c +90 -58
index 9f3f6a6dd8..f3119e4dff 100644
@@ -1063,7 +1063,9 @@ or1k_elf_relocate_section (bfd *output_bfd,
   bfd *dynobj;
   asection *sreloc;
   bfd_vma *local_got_offsets;
-  asection *sgot;
+  asection *sgot, *splt;
+  bfd_vma plt_base, got_base;
+  bfd_boolean ret_val = TRUE;
 
   if (htab == NULL)
     return FALSE;
@@ -1073,7 +1075,15 @@ or1k_elf_relocate_section (bfd *output_bfd,
 
   sreloc = elf_section_data (input_section)->sreloc;
 
+  splt = htab->root.splt;
+  plt_base = 0;
+  if (splt != NULL)
+    plt_base = splt->output_section->vma + splt->output_offset;
+
   sgot = htab->root.sgot;
+  got_base = 0;
+  if (sgot != NULL)
+    got_base = sgot->output_section->vma + sgot->output_offset;
 
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
@@ -1100,8 +1110,12 @@ or1k_elf_relocate_section (bfd *output_bfd,
 
       if (r_type < 0 || r_type >= (int) R_OR1K_max)
 	{
+	  _bfd_error_handler
+	    (_("%pB: unknown relocation type %d"),
+	     input_bfd, (int) r_type);
 	  bfd_set_error (bfd_error_bad_value);
-	  return FALSE;
+	  ret_val = FALSE;
+	  continue;
 	}
 
       howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
@@ -1127,6 +1141,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
 				   r_symndx, symtab_hdr, sym_hashes,
 				   h, sec, relocation,
 				   unresolved_reloc, warned, ignored);
+	  name = h->root.root.string;
 	}
 
       if (sec != NULL && discarded_section (sec))
@@ -1139,16 +1154,24 @@ or1k_elf_relocate_section (bfd *output_bfd,
       switch (howto->type)
 	{
 	case R_OR1K_PLT26:
-	  {
-	    if (htab->root.splt != NULL && h != NULL
-		&& h->plt.offset != (bfd_vma) -1)
-	      {
-		relocation = (htab->root.splt->output_section->vma
-			      + htab->root.splt->output_offset
-			      + h->plt.offset);
-	      }
-	    break;
-	  }
+	  /* If the call is not local, redirect the branch to the PLT.
+	     Otherwise do nothing to send the branch to the symbol direct.  */
+	  if (!SYMBOL_CALLS_LOCAL (info, h))
+	    {
+	      BFD_ASSERT (h->plt.offset != (bfd_vma) -1);
+	      relocation = plt_base + h->plt.offset;
+	    }
+
+	  /* Addend should be zero.  */
+	  if (rel->r_addend != 0)
+	    {
+	      _bfd_error_handler
+		(_("%pB: addend should be zero for plt relocations"),
+		 input_bfd);
+	      bfd_set_error (bfd_error_bad_value);
+	      ret_val = FALSE;
+	    }
+	  break;
 
 	case R_OR1K_GOT16:
 	  /* Relocation is to the entry for this symbol in the global
@@ -1225,9 +1248,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
 		      srelgot = htab->root.srelgot;
 		      BFD_ASSERT (srelgot != NULL);
 
-		      outrel.r_offset = (sgot->output_section->vma
-					 + sgot->output_offset
-					 + off);
+		      outrel.r_offset = got_base + off;
 		      outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
 		      outrel.r_addend = relocation;
 		      loc = srelgot->contents;
@@ -1243,10 +1264,13 @@ or1k_elf_relocate_section (bfd *output_bfd,
 
 	  /* Addend should be zero.  */
 	  if (rel->r_addend != 0)
-	    _bfd_error_handler
-	      (_("internal error: addend should be zero for %s"),
-	       "R_OR1K_GOT16");
-
+	    {
+	      _bfd_error_handler
+		(_("%pB: addend should be zero for got relocations"),
+		 input_bfd);
+	      bfd_set_error (bfd_error_bad_value);
+	      ret_val = FALSE;
+	    }
 	  break;
 
 	case R_OR1K_GOTOFF_LO16:
@@ -1255,17 +1279,44 @@ or1k_elf_relocate_section (bfd *output_bfd,
 	case R_OR1K_GOTOFF_SLO16:
 	  /* Relocation is offset from GOT.  */
 	  BFD_ASSERT (sgot != NULL);
-	  relocation
-	    -= (htab->root.hgot->root.u.def.value
-		+ htab->root.hgot->root.u.def.section->output_offset
-		+ htab->root.hgot->root.u.def.section->output_section->vma);
+	  if (!SYMBOL_REFERENCES_LOCAL (info, h))
+	    {
+	      _bfd_error_handler
+		(_("%pB: gotoff relocation against dynamic symbol %s"),
+		 input_bfd, h->root.root.string);
+	      ret_val = FALSE;
+	      bfd_set_error (bfd_error_bad_value);
+	    }
+	  relocation -= got_base;
 	  break;
 
 	case R_OR1K_INSN_REL_26:
+	  /* For a non-shared link, these will reference either the plt
+	     or a .dynbss copy of the symbol.  */
+	  if (bfd_link_pic (info) && !SYMBOL_REFERENCES_LOCAL (info, h))
+	    {
+	      _bfd_error_handler
+		(_("%pB: pc-relative relocation against dynamic symbol %s"),
+		 input_bfd, name);
+	      ret_val = FALSE;
+	      bfd_set_error (bfd_error_bad_value);
+	    }
+	  break;
+
 	case R_OR1K_HI_16_IN_INSN:
 	case R_OR1K_LO_16_IN_INSN:
 	case R_OR1K_AHI16:
 	case R_OR1K_SLO16:
+	  if (bfd_link_pic (info))
+	    {
+	      _bfd_error_handler
+		(_("%pB: non-pic relocation against symbol %s"),
+		 input_bfd, name);
+	      ret_val = FALSE;
+	      bfd_set_error (bfd_error_bad_value);
+	    }
+	  break;
+
 	case R_OR1K_32:
 	  /* R_OR1K_16? */
 	  {
@@ -1276,18 +1327,17 @@ or1k_elf_relocate_section (bfd *output_bfd,
 		|| (input_section->flags & SEC_ALLOC) == 0)
 	      break;
 
-	    if ((bfd_link_pic (info)
-		 && (h == NULL
+	    /* Emit a direct relocation if the symbol is dynamic,
+	       or a RELATIVE reloc for shared objects.  We can omit
+	       RELATIVE relocs to local undefweak symbols.  */
+	    if (bfd_link_pic (info)
+		? (h == NULL
 		     || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
 		     || h->root.type != bfd_link_hash_undefweak)
-		 && (howto->type != R_OR1K_INSN_REL_26
-		     || !SYMBOL_CALLS_LOCAL (info, h)))
-		|| (!bfd_link_pic (info)
-		    && h != NULL
+		: (h != NULL
 		    && h->dynindx != -1
 		    && !h->non_got_ref
-		    && ((h->def_dynamic
-			 && !h->def_regular)
+		   && ((h->def_dynamic && !h->def_regular)
 			|| h->root.type == bfd_link_hash_undefweak
 			|| h->root.type == bfd_link_hash_undefined)))
 	      {
@@ -1315,32 +1365,16 @@ or1k_elf_relocate_section (bfd *output_bfd,
 
 		if (skip)
 		  memset (&outrel, 0, sizeof outrel);
-		/* h->dynindx may be -1 if the symbol was marked to
-		   become local.  */
-		else if (h != NULL
-			 && ((! info->symbolic && h->dynindx != -1)
-			     || !h->def_regular))
+		else if (SYMBOL_REFERENCES_LOCAL (info, h))
 		  {
-		    BFD_ASSERT (h->dynindx != -1);
-		    outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
-		    outrel.r_addend = rel->r_addend;
+		    outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
+		    outrel.r_addend = relocation + rel->r_addend;
 		  }
 		else
 		  {
-		    if (r_type == R_OR1K_32)
-		      {
-			outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
-			outrel.r_addend = relocation + rel->r_addend;
-		      }
-		    else
-		      {
-			BFD_FAIL ();
-			_bfd_error_handler
-			  (_("%pB: probably compiled without -fPIC?"),
-			   input_bfd);
-			bfd_set_error (bfd_error_bad_value);
-			return FALSE;
-		      }
+		    BFD_ASSERT (h->dynindx != -1);
+		    outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+		    outrel.r_addend = rel->r_addend;
 		  }
 
 		loc = sreloc->contents;
@@ -1416,8 +1450,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
 		/* Add DTPMOD and DTPOFF GOT and rela entries.  */
 		for (i = 0; i < 2; ++i)
 		  {
-		    rela.r_offset = sgot->output_section->vma +
-		      sgot->output_offset + gotoff + i*4;
+		    rela.r_offset = got_base + gotoff + i*4;
 		    if (h != NULL && h->dynindx != -1)
 		      {
 			rela.r_info = ELF32_R_INFO (h->dynindx,
@@ -1451,8 +1484,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
 	    else if (dynamic)
 	      {
 		/* Add TPOFF GOT and rela entries.  */
-		rela.r_offset = sgot->output_section->vma +
-		  sgot->output_offset + gotoff;
+		rela.r_offset = got_base + gotoff;
 		if (h != NULL && h->dynindx != -1)
 		  {
 		    rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
@@ -1547,7 +1579,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
 	}
     }
 
-  return TRUE;
+  return ret_val;
 }
 
 /* Return the section that should be marked against GC for a given
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/4 or1k: Add the l.adrp insn and supporting relocations

In reply to Stafford Horne

This patch adds the new instruction and relocation as per proposal:
https://openrisc.io/proposals/ladrp

This is to be added to the spec in an upcoming revision. The new instruction l.adrp loads the page offset of the current instruction offset by a 21-bit immediate shifted left 13-bits. This is meant to be used with a 13-bit lower bit page offset. This allows us to free up the got register r16.

  l.adrp  r3, foo
  l.ori   r4, r3, po(foo)
  l.lbz   r5, po(foo)(r3)
  l.sb    po(foo)(r3), r6

The relocations we add are:

- BFD_RELOC_OR1K_PLTA26 For PLT jump relocation with PLT entry
asm: plta() implemented using l.ardp, meaning
no need for r16 (the GOT reg)

- BFD_RELOC_OR1K_GOT_PG21 Upper 21-bit Page offset got address
asm: got()
- BFD_RELOC_OR1K_TLS_GD_PG21 Upper 21-bit Page offset with TLS General
asm: tlsgd() Dynamic calculation
- BFD_RELOC_OR1K_TLS_LDM_PG21 Upper 21-bit Page offset with TLS local
asm: tlsldm() dynamic calculation
- BFD_RELOC_OR1K_TLS_IE_PG21 Upper 21-bit Page offset with TLS Initial
asm: gottp() Executable calculation
- BFD_RELOC_OR1K_PCREL_PG21 Default relocation for disp21 (l.adrp
instructions)

- BFD_RELOC_OR1K_LO13 low 13-bit page offset relocation
asm: po() i.e. mem loads, addi etc
- BFD_RELOC_OR1K_SLO13 low 13-bit page offset relocation
asm: po() i.e. mem stores, with split immediate
- BFD_RELOC_OR1K_GOT_LO13, low 13-bit page offset with GOT calcs
asm: gotpo()
- BFD_RELOC_OR1K_TLS_GD_LO13 Lower 13-bit offset with TLS GD calcs
asm: tlsgdpo()
- BFD_RELOC_OR1K_TLS_LDM_LO13 Lower 13-bit offset with TLS LD calcs
asm: tlsldmpo()
- BFD_RELOC_OR1K_TLS_IE_LO13 Lower 13-bit offset with TLS IE calcs
asm: gottppo()

yyyy-mm-dd Richard Henderson <[email protected]>

bfd/ChangeLog:

	* bfd-in2.h: Regenerated.
	* elf32-or1k.c: (or1k_elf_howto_table): Fix formatting for
	R_OR1K_PLT26, Add R_OR1K_PCREL_PG21, R_OR1K_GOT_PG21,
	R_OR1K_TLS_GD_PG21, R_OR1K_TLS_LDM_PG21, R_OR1K_TLS_IE_PG21,
	R_OR1K_LO13, R_OR1K_GOT_LO13, R_OR1K_TLS_GD_LO13, R_OR1K_TLS_LDM_LO13,
	R_OR1K_TLS_IE_LO13, R_OR1K_SLO13, R_OR1K_PLTA26.
	(or1k_reloc_map): Add BFD_RELOC_OR1K_PCREL_PG21,
	BFD_RELOC_OR1K_GOT_PG21, BFD_RELOC_OR1K_TLS_GD_PG21,
	BFD_RELOC_OR1K_TLS_LDM_PG21, BFD_RELOC_OR1K_TLS_IE_PG21,
	BFD_RELOC_OR1K_LO13, BFD_RELOC_OR1K_GOT_LO13,
	BFD_RELOC_OR1K_TLS_GD_LO13, BFD_RELOC_OR1K_TLS_GD_LO13,
	BFD_RELOC_OR1K_TLS_LDM_LO13, BFD_RELOC_OR1K_TLS_IE_LO13,
	BFD_RELOC_OR1K_SLO13, BFD_RELOC_OR1K_PLTA26.
	(elf_or1k_link_hash_table): Add field saw_plta.
	(or1k_final_link_relocate): Add value calculations for new relocations.
	(or1k_elf_relocate_section): Add section relocations for new
	relocations.
	(or1k_write_plt_entry): New function.
	(or1k_elf_finish_dynamic_sections): Add support for PLTA relocations
	using new l.adrp instruction.  Cleanup PLT relocation code generation.
	* libbfd.h: Regenerated.
	* reloc.c: Add BFD_RELOC_OR1K_PCREL_PG21, BFD_RELOC_OR1K_LO13,
	BFD_RELOC_OR1K_SLO13, BFD_RELOC_OR1K_GOT_PG21, BFD_RELOC_OR1K_GOT_LO13,
	BFD_RELOC_OR1K_PLTA26, BFD_RELOC_OR1K_TLS_GD_PG21,
	BFD_RELOC_OR1K_TLS_GD_LO13, BFD_RELOC_OR1K_TLS_LDM_PG21,
	BFD_RELOC_OR1K_TLS_LDM_LO13, BFD_RELOC_OR1K_TLS_IE_PG21,
	BFD_RELOC_OR1K_TLS_IE_LO13.

cpu/ChangeLog:

* or1k.opc (parse_disp26): Add support for plta() relocations. (parse_disp21): New function.
(or1k_rclass): New enum.
(or1k_rtype): New enum.
(or1k_imm16_relocs): Define new PO and SPO relocation mappings. (parse_reloc): Add new po(), gotpo() and gottppo() for LO13 relocations. (parse_imm16): Add support for the new 21bit and 13bit relocations.
* or1korbis.cpu (f-disp26): Don't assume SI.
(f-disp21): New pc-relative 21-bit 13 shifted to right. (insn-opcode): Add ADRP.
(l-adrp): New instruction.

gas/ChangeLog:

	* config/tc-or1k.c (or1k_apply_fix): Add BFD_RELOC_OR1K_TLS_GD_PG21,
	BFD_RELOC_OR1K_TLS_GD_LO13, BFD_RELOC_OR1K_TLS_LDM_PG21,
	BFD_RELOC_OR1K_TLS_LDM_LO13, BFD_RELOC_OR1K_TLS_IE_PG21,
	BFD_RELOC_OR1K_TLS_IE_LO13.
	* testsuite/gas/or1k/allinsn.s: Add test for l.adrp.
	* testsuite/gas/or1k/allinsn.d: Add test results for new
	instructions.
	* testsuite/gas/or1k/reloc-1.s: Add tests to generate
	R_OR1K_PLTA26, R_OR1K_GOT_PG21, R_OR1K_TLS_GD_PG21, R_OR1K_TLS_LDM_PG21,
	R_OR1K_TLS_IE_PG21, R_OR1K_LO13, R_OR1K_GOT_LO13, R_OR1K_TLS_GD_LO13,
	R_OR1K_TLD_LDM_LO13, R_OR1K_TLS_IE_LO13, R_OR1K_LO13, R_OR1K_SLO13
	relocations.
	* testsuite/gas/or1k/reloc-1.d: Add relocation results for
	tests.
	* testsuite/gas/or1k/reloc-2.s: Add negative tests for store to
	gotpo().
	* testsuite/gas/or1k/reloc-2.l: Add expected error test results.

ld/ChangeLog:

* testsuite/ld-or1k/or1k.exp: Add test cases for plt generation.
* testsuite/ld-or1k/plt1.dd: New file.
* testsuite/ld-or1k/plt1.s: New file.
* testsuite/ld-or1k/plt1.x.dd: New file.
* testsuite/ld-or1k/plta1.dd: New file.
* testsuite/ld-or1k/plta1.s: New file.
* testsuite/ld-or1k/pltlib.s: New file.

include/ChangeLog:

	* elf/or1k.h (elf_or1k_reloc_type): Add R_OR1K_PCREL_PG21,
	R_OR1K_GOT_PG21, R_OR1K_TLS_GD_PG21, R_OR1K_TLS_LDM_PG21,
	R_OR1K_TLS_IE_PG21, R_OR1K_LO13, R_OR1K_GOT_LO13,
	R_OR1K_TLS_GD_LO13, R_OR1K_TLS_LDM_LO13, R_OR1K_TLS_IE_LO13,
	R_OR1K_SLO13, R_OR1K_PLTA26.

opcodes/ChangeLog:

* or1k-asm.c: Regenerated.
* or1k-desc.c: Regenerated.
* or1k-desc.h: Regenerated.
* or1k-dis.c: Regenerated.
* or1k-ibld.c: Regenerated.
* or1k-opc.c: Regenerated.
* or1k-opc.h: Regenerated.
* or1k-opinst.c: Regenerated.

---
 bfd/bfd-in2.h                    |  12 +
 bfd/elf32-or1k.c                 | 526 +++++++++++++++++++++++--------
 bfd/libbfd.h                     |  12 +
 bfd/reloc.c                      |  24 ++
 cpu/or1k.opc                     | 225 +++++++++----
 cpu/or1korbis.cpu                |  35 +-
 gas/config/tc-or1k.c             |   6 +
 gas/testsuite/gas/or1k/allinsn.d |   6 +
 gas/testsuite/gas/or1k/allinsn.s |   3 +
 gas/testsuite/gas/or1k/reloc-1.d |  16 +
 gas/testsuite/gas/or1k/reloc-1.s |  20 ++
 gas/testsuite/gas/or1k/reloc-2.l |   1 +
 gas/testsuite/gas/or1k/reloc-2.s |   1 +
 include/elf/or1k.h               |  12 +
 ld/testsuite/ld-or1k/or1k.exp    |  22 ++
 ld/testsuite/ld-or1k/plt1.dd     |  27 ++
 ld/testsuite/ld-or1k/plt1.s      |  11 +
 ld/testsuite/ld-or1k/plt1.x.dd   |  27 ++
 ld/testsuite/ld-or1k/plta1.dd    |  27 ++
 ld/testsuite/ld-or1k/plta1.s     |  11 +
 ld/testsuite/ld-or1k/pltlib.s    |  12 +
 opcodes/or1k-asm.c               | 282 ++++++++++++-----
 opcodes/or1k-desc.c              |  10 +
 opcodes/or1k-desc.h              |  37 +--
 opcodes/or1k-dis.c               |   3 +
 opcodes/or1k-ibld.c              |  29 +-
 opcodes/or1k-opc.c               |  10 +
 opcodes/or1k-opc.h               |  64 ++--
 opcodes/or1k-opinst.c            |   7 +
 29 files changed, 1154 insertions(+), 324 deletions(-)
 create mode 100644 ld/testsuite/ld-or1k/plt1.dd
 create mode 100644 ld/testsuite/ld-or1k/plt1.s
 create mode 100644 ld/testsuite/ld-or1k/plt1.x.dd
 create mode 100644 ld/testsuite/ld-or1k/plta1.dd
 create mode 100644 ld/testsuite/ld-or1k/plta1.s
 create mode 100644 ld/testsuite/ld-or1k/pltlib.s
bfd/bfd-in2.h +12 -0
index a51ead9273..a714c3601d 100644
@@ -5468,10 +5468,16 @@ then it may be truncated to 8 bits.  */
 /* OpenRISC 1000 Relocations.  */
   BFD_RELOC_OR1K_REL_26,
   BFD_RELOC_OR1K_SLO16,
+  BFD_RELOC_OR1K_PCREL_PG21,
+  BFD_RELOC_OR1K_LO13,
+  BFD_RELOC_OR1K_SLO13,
   BFD_RELOC_OR1K_GOTPC_HI16,
   BFD_RELOC_OR1K_GOTPC_LO16,
   BFD_RELOC_OR1K_GOT16,
+  BFD_RELOC_OR1K_GOT_PG21,
+  BFD_RELOC_OR1K_GOT_LO13,
   BFD_RELOC_OR1K_PLT26,
+  BFD_RELOC_OR1K_PLTA26,
   BFD_RELOC_OR1K_GOTOFF_SLO16,
   BFD_RELOC_OR1K_COPY,
   BFD_RELOC_OR1K_GLOB_DAT,
@@ -5479,13 +5485,19 @@ then it may be truncated to 8 bits.  */
   BFD_RELOC_OR1K_RELATIVE,
   BFD_RELOC_OR1K_TLS_GD_HI16,
   BFD_RELOC_OR1K_TLS_GD_LO16,
+  BFD_RELOC_OR1K_TLS_GD_PG21,
+  BFD_RELOC_OR1K_TLS_GD_LO13,
   BFD_RELOC_OR1K_TLS_LDM_HI16,
   BFD_RELOC_OR1K_TLS_LDM_LO16,
+  BFD_RELOC_OR1K_TLS_LDM_PG21,
+  BFD_RELOC_OR1K_TLS_LDM_LO13,
   BFD_RELOC_OR1K_TLS_LDO_HI16,
   BFD_RELOC_OR1K_TLS_LDO_LO16,
   BFD_RELOC_OR1K_TLS_IE_HI16,
   BFD_RELOC_OR1K_TLS_IE_AHI16,
   BFD_RELOC_OR1K_TLS_IE_LO16,
+  BFD_RELOC_OR1K_TLS_IE_PG21,
+  BFD_RELOC_OR1K_TLS_IE_LO13,
   BFD_RELOC_OR1K_TLS_LE_HI16,
   BFD_RELOC_OR1K_TLS_LE_AHI16,
   BFD_RELOC_OR1K_TLS_LE_LO16,
bfd/elf32-or1k.c +400 -126

802 lines not on this page · raw message

bfd/libbfd.h +12 -0
index f887e516ae..709fc09824 100644
@@ -2643,10 +2643,16 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_CRIS_32_IE",
   "BFD_RELOC_OR1K_REL_26",
   "BFD_RELOC_OR1K_SLO16",
+  "BFD_RELOC_OR1K_PCREL_PG21",
+  "BFD_RELOC_OR1K_LO13",
+  "BFD_RELOC_OR1K_SLO13",
   "BFD_RELOC_OR1K_GOTPC_HI16",
   "BFD_RELOC_OR1K_GOTPC_LO16",
   "BFD_RELOC_OR1K_GOT16",
+  "BFD_RELOC_OR1K_GOT_PG21",
+  "BFD_RELOC_OR1K_GOT_LO13",
   "BFD_RELOC_OR1K_PLT26",
+  "BFD_RELOC_OR1K_PLTA26",
   "BFD_RELOC_OR1K_GOTOFF_SLO16",
   "BFD_RELOC_OR1K_COPY",
   "BFD_RELOC_OR1K_GLOB_DAT",
@@ -2654,13 +2660,19 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_OR1K_RELATIVE",
   "BFD_RELOC_OR1K_TLS_GD_HI16",
   "BFD_RELOC_OR1K_TLS_GD_LO16",
+  "BFD_RELOC_OR1K_TLS_GD_PG21",
+  "BFD_RELOC_OR1K_TLS_GD_LO13",
   "BFD_RELOC_OR1K_TLS_LDM_HI16",
   "BFD_RELOC_OR1K_TLS_LDM_LO16",
+  "BFD_RELOC_OR1K_TLS_LDM_PG21",
+  "BFD_RELOC_OR1K_TLS_LDM_LO13",
   "BFD_RELOC_OR1K_TLS_LDO_HI16",
   "BFD_RELOC_OR1K_TLS_LDO_LO16",
   "BFD_RELOC_OR1K_TLS_IE_HI16",
   "BFD_RELOC_OR1K_TLS_IE_AHI16",
   "BFD_RELOC_OR1K_TLS_IE_LO16",
+  "BFD_RELOC_OR1K_TLS_IE_PG21",
+  "BFD_RELOC_OR1K_TLS_IE_LO13",
   "BFD_RELOC_OR1K_TLS_LE_HI16",
   "BFD_RELOC_OR1K_TLS_LE_AHI16",
   "BFD_RELOC_OR1K_TLS_LE_LO16",
bfd/reloc.c +24 -0
index de870441df..0a9324be7b 100644
@@ -6136,14 +6136,26 @@ ENUM
   BFD_RELOC_OR1K_REL_26
 ENUMX
   BFD_RELOC_OR1K_SLO16
+ENUMX
+  BFD_RELOC_OR1K_PCREL_PG21
+ENUMX
+  BFD_RELOC_OR1K_LO13
+ENUMX
+  BFD_RELOC_OR1K_SLO13
 ENUMX
   BFD_RELOC_OR1K_GOTPC_HI16
 ENUMX
   BFD_RELOC_OR1K_GOTPC_LO16
 ENUMX
   BFD_RELOC_OR1K_GOT16
+ENUMX
+  BFD_RELOC_OR1K_GOT_PG21
+ENUMX
+  BFD_RELOC_OR1K_GOT_LO13
 ENUMX
   BFD_RELOC_OR1K_PLT26
+ENUMX
+  BFD_RELOC_OR1K_PLTA26
 ENUMX
   BFD_RELOC_OR1K_GOTOFF_SLO16
 ENUMX
@@ -6158,10 +6170,18 @@ ENUMX
   BFD_RELOC_OR1K_TLS_GD_HI16
 ENUMX
   BFD_RELOC_OR1K_TLS_GD_LO16
+ENUMX
+  BFD_RELOC_OR1K_TLS_GD_PG21
+ENUMX
+  BFD_RELOC_OR1K_TLS_GD_LO13
 ENUMX
   BFD_RELOC_OR1K_TLS_LDM_HI16
 ENUMX
   BFD_RELOC_OR1K_TLS_LDM_LO16
+ENUMX
+  BFD_RELOC_OR1K_TLS_LDM_PG21
+ENUMX
+  BFD_RELOC_OR1K_TLS_LDM_LO13
 ENUMX
   BFD_RELOC_OR1K_TLS_LDO_HI16
 ENUMX
@@ -6172,6 +6192,10 @@ ENUMX
   BFD_RELOC_OR1K_TLS_IE_AHI16
 ENUMX
   BFD_RELOC_OR1K_TLS_IE_LO16
+ENUMX
+  BFD_RELOC_OR1K_TLS_IE_PG21
+ENUMX
+  BFD_RELOC_OR1K_TLS_IE_LO13
 ENUMX
   BFD_RELOC_OR1K_TLS_LE_HI16
 ENUMX
cpu/or1k.opc +164 -61

355 lines not on this page · raw message

cpu/or1korbis.cpu +34 -1
index 535bd28bff..6fbf40ad99 100644
@@ -74,10 +74,25 @@
     25
     26
     INT
-    ((value pc) (sra SI (sub IAI value pc) (const 2)))
+    ((value pc) (sra IAI (sub IAI value pc) (const 2)))
     ((value pc) (add IAI (sll IAI value (const 2)) pc))
     )
 
+; PC relative, 21-bit, 13 shifted to right, aligned.
+; Note that the alignment means that we can't simplify relocations in the
+; same way as we do for pc-relative, so we use ABS-ADDR instead of PCREL-ADDR.
+(df f-disp21
+    "disp21"
+    ((MACH ORBIS-MACHS) ABS-ADDR)
+    20
+    21
+    INT
+    ((value pc)
+     (sub IAI (sra IAI value (const 13)) (sra IAI pc (const 13))))
+    ((value pc)
+     (sll IAI (add IAI value (sra IAI pc (const 13))) (const 13)))
+    )
+
 ; Immediates.
 (dnf f-uimm16    "uimm16"                      ((MACH ORBIS-MACHS))          15 16)
 (df  f-simm16    "simm16"                      ((MACH ORBIS-MACHS) SIGN-OPT) 15 16 INT #f #f)
@@ -134,6 +149,7 @@
   insn-opcode "insn main opcode enums" ((MACH ORBIS-MACHS)) OPC_ f-opcode
   (("J"            #x00)
    ("JAL"          #x01)
+   ("ADRP"	   #x02)
    ("BNF"          #x03)
    ("BF"           #x04)
    ("NOP"          #x05)
@@ -311,6 +327,15 @@
   (handlers (parse "disp26"))
   )
 
+(define-operand
+  (name disp21)
+  (comment "pc-rel 21 bit")
+  (attrs (MACH ORBIS-MACHS))
+  (type h-iaddr)
+  (index f-disp21)
+  (handlers (parse "disp21"))
+  )
+
 (define-operand
   (name simm16)
   (comment "16-bit signed immediate")
@@ -403,6 +428,14 @@
            )
   )
 
+(dni l-adrp "adrp reg/disp21"
+    ((MACH ORBIS-MACHS))
+    "l.adrp $rD,${disp21}"
+    (+ OPC_ADRP rD disp21)
+    (set UWI rD disp21)
+    ()
+  )
+
 (define-cti
   l-jal
   "jump and link (pc-relative iaddr)"
gas/config/tc-or1k.c +6 -0
index 8862c35480..c7dd457c36 100644
@@ -362,12 +362,18 @@ or1k_apply_fix (struct fix *f, valueT *t, segT s)
     {
     case BFD_RELOC_OR1K_TLS_GD_HI16:
     case BFD_RELOC_OR1K_TLS_GD_LO16:
+    case BFD_RELOC_OR1K_TLS_GD_PG21:
+    case BFD_RELOC_OR1K_TLS_GD_LO13:
     case BFD_RELOC_OR1K_TLS_LDM_HI16:
     case BFD_RELOC_OR1K_TLS_LDM_LO16:
+    case BFD_RELOC_OR1K_TLS_LDM_PG21:
+    case BFD_RELOC_OR1K_TLS_LDM_LO13:
     case BFD_RELOC_OR1K_TLS_LDO_HI16:
     case BFD_RELOC_OR1K_TLS_LDO_LO16:
     case BFD_RELOC_OR1K_TLS_IE_HI16:
     case BFD_RELOC_OR1K_TLS_IE_LO16:
+    case BFD_RELOC_OR1K_TLS_IE_PG21:
+    case BFD_RELOC_OR1K_TLS_IE_LO13:
     case BFD_RELOC_OR1K_TLS_LE_HI16:
     case BFD_RELOC_OR1K_TLS_LE_LO16:
       S_SET_THREAD_LOCAL (f->fx_addsy);
gas/testsuite/gas/or1k/allinsn.d +6 -0
index 1b36cce1bc..a4ffe43f0b 100644
@@ -690,3 +690,9 @@ Disassembly of section \.text:
  834:	4c 02 ff ff 	l\.maci r2,-1
  838:	4c 02 7f ff 	l\.maci r2,32767
  83c:	4c 02 80 00 	l\.maci r2,-32768
+
+00000840 <l_adrp>:
+ 840:	08 60 00 00 	l\.adrp r3,0 <localtext>
+			840: R_OR1K_PCREL_PG21	globaldata
+ 844:	08 60 00 00 	l\.adrp r3,0 <localtext>
+			844: R_OR1K_PCREL_PG21	\.data
gas/testsuite/gas/or1k/allinsn.s +3 -0
index 321aea3036..55d703734e 100644
@@ -677,3 +677,6 @@ l_maci:
 	l.maci r2,-1
 	l.maci r2,32767
 	l.maci r2,-32768
+l_adrp:
+	l.adrp r3,globaldata
+	l.adrp r3,localdata
gas/testsuite/gas/or1k/reloc-1.d +16 -0
index f90a1ae269..d1bcf5608b 100644
@@ -52,5 +52,21 @@ OFFSET   TYPE              VALUE
 000000ac R_OR1K_TLS_LE_AHI16  x
 000000b0 R_OR1K_TLS_LE_LO16  x
 000000b4 R_OR1K_TLS_LE_SLO16  x
+000000b8 R_OR1K_PLTA26     x
+000000bc R_OR1K_PLTA26     x
+000000c0 R_OR1K_PLTA26     x
+000000c4 R_OR1K_PLTA26     x
+000000c8 R_OR1K_GOT_PG21   x
+000000cc R_OR1K_TLS_GD_PG21  x
+000000d0 R_OR1K_TLS_LDM_PG21  x
+000000d4 R_OR1K_TLS_IE_PG21  x
+000000d8 R_OR1K_LO13       x
+000000dc R_OR1K_GOT_LO13   x
+000000e0 R_OR1K_TLS_GD_LO13  x
+000000e4 R_OR1K_TLD_LDM_LO13  x
+000000e8 R_OR1K_TLS_IE_LO13  x
+000000ec R_OR1K_LO13       x
+000000f0 R_OR1K_GOT_LO13   x
+000000f4 R_OR1K_SLO13      x
 
 
gas/testsuite/gas/or1k/reloc-1.s +20 -0
index 4966dc56be..e76abef653 100644
@@ -54,3 +54,23 @@
 	l.movhi	r3,tpoffha(x)
 	l.lwz	r3,tpofflo(x)(r3)
 	l.sw	tpofflo(x)(r3),r3
+
+	l.j	plta(x)
+	l.jal	plta(x)
+	l.bf	plta(x)
+	l.bnf	plta(x)
+
+	l.adrp	r3,got(x)
+	l.adrp	r3,tlsgd(x)
+	l.adrp	r3,tlsldm(x)
+	l.adrp	r3,gottp(x)
+
+	l.ori	r4,r3,po(x)
+	l.ori	r4,r3,gotpo(x)
+	l.ori	r4,r3,tlsgdpo(x)
+	l.ori	r4,r3,tlsldmpo(x)
+	l.ori	r4,r3,gottppo(x)
+
+	l.lbz	r5,po(x)(r3)
+	l.lbz	r5,gotpo(x)(r3)
+	l.sb	po(x)(r3),r6
gas/testsuite/gas/or1k/reloc-2.l +1 -0
index 7a32a7dc14..c104fd9d6e 100644
@@ -8,3 +8,4 @@
 .*:9: Error: relocation invalid for store .*
 .*:11: Error: relocation invalid for store .*
 .*:12: Error: relocation invalid for store .*
+.*:13: Error: relocation invalid for store .*
gas/testsuite/gas/or1k/reloc-2.s +1 -0
index 835dd1c84b..4d20aa7ba0 100644
@@ -10,3 +10,4 @@
 	l.sw	tpofflo(x)(r4),r3
 	l.sw	tpoffhi(x)(r4),r3
 	l.sw	tpoffha(x)(r4),r3
+	l.sw	gotpo(x)(r4),r3
include/elf/or1k.h +12 -0
index e3291d31d3..4369e6250d 100644
@@ -65,6 +65,18 @@ START_RELOC_NUMBERS (elf_or1k_reloc_type)
   RELOC_NUMBER (R_OR1K_SLO16,         39)
   RELOC_NUMBER (R_OR1K_GOTOFF_SLO16,  40)
   RELOC_NUMBER (R_OR1K_TLS_LE_SLO16,  41)
+  RELOC_NUMBER (R_OR1K_PCREL_PG21,    42)
+  RELOC_NUMBER (R_OR1K_GOT_PG21,      43)
+  RELOC_NUMBER (R_OR1K_TLS_GD_PG21,   44)
+  RELOC_NUMBER (R_OR1K_TLS_LDM_PG21,  45)
+  RELOC_NUMBER (R_OR1K_TLS_IE_PG21,   46)
+  RELOC_NUMBER (R_OR1K_LO13,          47)
+  RELOC_NUMBER (R_OR1K_GOT_LO13,      48)
+  RELOC_NUMBER (R_OR1K_TLS_GD_LO13,   49)
+  RELOC_NUMBER (R_OR1K_TLS_LDM_LO13,  50)
+  RELOC_NUMBER (R_OR1K_TLS_IE_LO13,   51)
+  RELOC_NUMBER (R_OR1K_SLO13,         52)
+  RELOC_NUMBER (R_OR1K_PLTA26,        53)
 END_RELOC_NUMBERS (R_OR1K_max)
 
 #define EF_OR1K_NODELAY (1UL << 0)
ld/testsuite/ld-or1k/or1k.exp +22 -0
index 8f09a7c40e..540ca29ed4 100644
@@ -38,6 +38,23 @@ set or1ktests {
      "offsets1"}
 }
 
+set or1kplttests {
+    {"PLTA -fpic -shared" "-fpic -shared" ""
+     "" {plta1.s}
+     {{objdump -dr plta1.dd}}
+     "libplta1.so"}
+    {"PLT -fpic -shared" "-fpic -shared" ""
+     "" {plt1.s}
+     {{objdump -dr plt1.dd}}
+     "libplt1.so"}
+    {"Helper shared library" "-fpic -shared" ""
+     "" {pltlib.s} {} "libpltlib.so"}
+    {"PLT -fno-pic exec -relax" "-relax tmpdir/libpltlib.so" ""
+     "" {plt1.s}
+     {{objdump -dr plt1.x.dd}}
+     "plt1.x"}
+}
+
 # Not implemented yet
 #   {"TLS -fpic -shared" "-shared -melf64alpha" ""
 #    "" {align.s tlspic1.s tlspic2.s}
@@ -66,4 +83,9 @@ set or1ktests {
 #    "" {tlsg.s}
 #    {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
 
+# Shared objects not supported on newlib
 run_ld_link_tests $or1ktests
+if { ![istarget "or1k*-*-elf*"] } {
+    run_ld_link_tests $or1kplttests
+    return
+}
ld/testsuite/ld-or1k/plt1.dd new file +27 -0
new file mode 100644
index 0000000000..a982530fa9
@@ -0,0 +1,27 @@
+
+.*\.so:     file format elf32-or1k
+
+
+Disassembly of section \.plt:
+
+[0-9a-f]+ <\.plt>:
+ [0-9a-f]+:	85 f0 00 08 	l\.lwz r15,8\(r16\)
+ [0-9a-f]+:	44 00 78 00 	l\.jr r15
+ [0-9a-f]+:	85 90 00 04 	l\.lwz r12,4\(r16\)
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
+ [0-9a-f]+:	85 90 00 0c 	l\.lwz r12,12\(r16\)
+ [0-9a-f]+:	44 00 60 00 	l\.jr r12
+ [0-9a-f]+:	a9 60 00 00 	l\.ori r11,r0,0x0
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
+ [0-9a-f]+:	85 90 00 10 	l\.lwz r12,16\(r16\)
+ [0-9a-f]+:	44 00 60 00 	l\.jr r12
+ [0-9a-f]+:	a9 60 00 0c 	l\.ori r11,r0,0xc
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <_start>:
+ [0-9a-f]+:	03 ff ff f8 	l\.j [0-9a-f]+ <.plt\+0x10>
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
+ [0-9a-f]+:	03 ff ff fa 	l\.j [0-9a-f]+ <.plt\+0x20>
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
ld/testsuite/ld-or1k/plt1.s new file +11 -0
new file mode 100644
index 0000000000..a5573bdc2f
@@ -0,0 +1,11 @@
+	.data
+	.p2align 16
+
+	.text
+	.globl	_start
+_start:
+
+	l.j plt(x)
+	 l.nop
+	l.j plt(y)
+	 l.nop
ld/testsuite/ld-or1k/plt1.x.dd new file +27 -0
new file mode 100644
index 0000000000..d2f47a1257
@@ -0,0 +1,27 @@
+
+.*\.x:     file format elf32-or1k
+
+
+Disassembly of section \.plt:
+
+[0-9a-f]+ <\.plt>:
+ +[0-9a-f]+:	19 80 00 00 	l\.movhi r12,0x0
+ +[0-9a-f]+:	85 ec [0-9a-f]+ [0-9a-f]+ 	l\.lwz r15,[0-9]+\(r12\)
+ +[0-9a-f]+:	44 00 78 00 	l\.jr r15
+ +[0-9a-f]+:	85 8c [0-9a-f]+ [0-9a-f]+ 	l\.lwz r12,[0-9]+\(r12\)
+ +[0-9a-f]+:	19 80 00 00 	l\.movhi r12,0x0
+ +[0-9a-f]+:	85 8c [0-9a-f]+ [0-9a-f]+ 	l\.lwz r12,[0-9]+\(r12\)
+ +[0-9a-f]+:	44 00 60 00 	l\.jr r12
+ +[0-9a-f]+:	a9 60 00 00 	l\.ori r11,r0,0x0
+ +[0-9a-f]+:	19 80 00 00 	l\.movhi r12,0x0
+ +[0-9a-f]+:	85 8c [0-9a-f]+ [0-9a-f]+ 	l\.lwz r12,[0-9]+\(r12\)
+ +[0-9a-f]+:	44 00 60 00 	l\.jr r12
+ +[0-9a-f]+:	a9 60 00 0c 	l\.ori r11,r0,0xc
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <_start>:
+ +[0-9a-f]+:	03 ff ff f8 	l\.j [0-9a-f]+ <.plt\+0x10>
+ +[0-9a-f]+:	15 00 00 00 	l\.nop 0x0
+ +[0-9a-f]+:	03 ff ff fa 	l\.j [0-9a-f]+ <.plt\+0x20>
+ +[0-9a-f]+:	15 00 00 00 	l\.nop 0x0
ld/testsuite/ld-or1k/plta1.dd new file +27 -0
new file mode 100644
index 0000000000..6767c41607
@@ -0,0 +1,27 @@
+
+.*\.so:     file format elf32-or1k
+
+
+Disassembly of section .plt:
+
+[0-9a-f]+ <.plt>:
+ [0-9a-f]+:	09 80 00 01 	l\.adrp r12,2000 <.*>
+ [0-9a-f]+:	85 ec 02 10 	l\.lwz r15,528\(r12\)
+ [0-9a-f]+:	44 00 78 00 	l\.jr r15
+ [0-9a-f]+:	85 8c 02 0c 	l\.lwz r12,524\(r12\)
+ [0-9a-f]+:	09 80 00 01 	l\.adrp r12,2000 <.*>
+ [0-9a-f]+:	85 8c 02 14 	l\.lwz r12,532\(r12\)
+ [0-9a-f]+:	44 00 60 00 	l\.jr r12
+ [0-9a-f]+:	a9 60 00 00 	l\.ori r11,r0,0x0
+ [0-9a-f]+:	09 80 00 01 	l\.adrp r12,2000 <.*>
+ [0-9a-f]+:	85 8c 02 18 	l\.lwz r12,536\(r12\)
+ [0-9a-f]+:	44 00 60 00 	l\.jr r12
+ [0-9a-f]+:	a9 60 00 0c 	l\.ori r11,r0,0xc
+
+Disassembly of section .text:
+
+[0-9a-f]+ <_start>:
+ [0-9a-f]+:	03 ff ff f8 	l\.j [0-9a-f]+ <.plt\+0x10>
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
+ [0-9a-f]+:	03 ff ff fa 	l\.j [0-9a-f]+ <.plt\+0x20>
+ [0-9a-f]+:	15 00 00 00 	l\.nop 0x0
ld/testsuite/ld-or1k/plta1.s new file +11 -0
new file mode 100644
index 0000000000..82f8175b16
@@ -0,0 +1,11 @@
+	.data
+	.p2align 16
+
+	.text
+	.globl	_start
+_start:
+
+	l.j plta(x)
+	 l.nop
+	l.j plta(y)
+	 l.nop
ld/testsuite/ld-or1k/pltlib.s new file +12 -0
new file mode 100644
index 0000000000..baf76ca1af
@@ -0,0 +1,12 @@
+	.section .data
+	.globl x, y
+x:	.long 33
+y:	.long 44
+
+	.section .text
+	.align 4
+	.global	func
+	.type	func, @function
+func:
+	l.jr	r9
+	 l.nop
opcodes/or1k-asm.c +196 -86

394 lines not on this page · raw message

opcodes/or1k-desc.c +10 -0
index f1c0768e9c..91c2fbd73d 100644
@@ -967,6 +967,7 @@ const CGEN_IFLD or1k_cgen_ifld_table[] =
   { OR1K_F_IMM16_25_5, "f-imm16-25-5", 0, 32, 25, 5, { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
   { OR1K_F_IMM16_10_11, "f-imm16-10-11", 0, 32, 10, 11, { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
   { OR1K_F_DISP26, "f-disp26", 0, 32, 25, 26, { 0|A(PCREL_ADDR), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
+  { OR1K_F_DISP21, "f-disp21", 0, 32, 20, 21, { 0|A(ABS_ADDR), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
   { OR1K_F_UIMM16, "f-uimm16", 0, 32, 15, 16, { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
   { OR1K_F_SIMM16, "f-simm16", 0, 32, 15, 16, { 0|A(SIGN_OPT), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
   { OR1K_F_UIMM6, "f-uimm6", 0, 32, 5, 6, { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
@@ -1091,6 +1092,10 @@ const CGEN_OPERAND or1k_cgen_operand_table[] =
   { "disp26", OR1K_OPERAND_DISP26, HW_H_IADDR, 25, 26,
     { 0, { (const PTR) &or1k_cgen_ifld_table[OR1K_F_DISP26] } },
     { 0|A(PCREL_ADDR), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
+/* disp21: pc-rel 21 bit */
+  { "disp21", OR1K_OPERAND_DISP21, HW_H_IADDR, 20, 21,
+    { 0, { (const PTR) &or1k_cgen_ifld_table[OR1K_F_DISP21] } },
+    { 0|A(ABS_ADDR), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }  },
 /* simm16: 16-bit signed immediate */
   { "simm16", OR1K_OPERAND_SIMM16, HW_H_SIMM16, 15, 16,
     { 0, { (const PTR) &or1k_cgen_ifld_table[OR1K_F_SIMM16] } },
@@ -1156,6 +1161,11 @@ static const CGEN_IBASE or1k_cgen_insn_table[MAX_INSNS] =
     OR1K_INSN_L_J, "l-j", "l.j", 32,
     { 0|A(UNCOND_CTI)|A(NOT_IN_DELAY_SLOT)|A(DELAYED_CTI)|A(SKIP_CTI)|A(DELAY_SLOT), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
   },
+/* l.adrp $rD,${disp21} */
+  {
+    OR1K_INSN_L_ADRP, "l-adrp", "l.adrp", 32,
+    { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
+  },
 /* l.jal ${disp26} */
   {
     OR1K_INSN_L_JAL, "l-jal", "l.jal", 32,
opcodes/or1k-desc.h +19 -18
index 894a8bb462..d84f0fa52a 100644
@@ -279,18 +279,18 @@ typedef enum spr_field_masks {
 
 /* Enum declaration for insn main opcode enums.  */
 typedef enum insn_opcode {
-  OPC_J = 0, OPC_JAL = 1, OPC_BNF = 3, OPC_BF = 4
- , OPC_NOP = 5, OPC_MOVHIMACRC = 6, OPC_SYSTRAPSYNCS = 8, OPC_RFE = 9
- , OPC_VECTOR = 10, OPC_JR = 17, OPC_JALR = 18, OPC_MACI = 19
- , OPC_LWA = 27, OPC_CUST1 = 28, OPC_CUST2 = 29, OPC_CUST3 = 30
- , OPC_CUST4 = 31, OPC_LD = 32, OPC_LWZ = 33, OPC_LWS = 34
- , OPC_LBZ = 35, OPC_LBS = 36, OPC_LHZ = 37, OPC_LHS = 38
- , OPC_ADDI = 39, OPC_ADDIC = 40, OPC_ANDI = 41, OPC_ORI = 42
- , OPC_XORI = 43, OPC_MULI = 44, OPC_MFSPR = 45, OPC_SHROTI = 46
- , OPC_SFI = 47, OPC_MTSPR = 48, OPC_MAC = 49, OPC_FLOAT = 50
- , OPC_SWA = 51, OPC_SD = 52, OPC_SW = 53, OPC_SB = 54
- , OPC_SH = 55, OPC_ALU = 56, OPC_SF = 57, OPC_CUST5 = 60
- , OPC_CUST6 = 61, OPC_CUST7 = 62, OPC_CUST8 = 63
+  OPC_J = 0, OPC_JAL = 1, OPC_ADRP = 2, OPC_BNF = 3
+ , OPC_BF = 4, OPC_NOP = 5, OPC_MOVHIMACRC = 6, OPC_SYSTRAPSYNCS = 8
+ , OPC_RFE = 9, OPC_VECTOR = 10, OPC_JR = 17, OPC_JALR = 18
+ , OPC_MACI = 19, OPC_LWA = 27, OPC_CUST1 = 28, OPC_CUST2 = 29
+ , OPC_CUST3 = 30, OPC_CUST4 = 31, OPC_LD = 32, OPC_LWZ = 33
+ , OPC_LWS = 34, OPC_LBZ = 35, OPC_LBS = 36, OPC_LHZ = 37
+ , OPC_LHS = 38, OPC_ADDI = 39, OPC_ADDIC = 40, OPC_ANDI = 41
+ , OPC_ORI = 42, OPC_XORI = 43, OPC_MULI = 44, OPC_MFSPR = 45
+ , OPC_SHROTI = 46, OPC_SFI = 47, OPC_MTSPR = 48, OPC_MAC = 49
+ , OPC_FLOAT = 50, OPC_SWA = 51, OPC_SD = 52, OPC_SW = 53
+ , OPC_SB = 54, OPC_SH = 55, OPC_ALU = 56, OPC_SF = 57
+ , OPC_CUST5 = 60, OPC_CUST6 = 61, OPC_CUST7 = 62, OPC_CUST8 = 63
 } INSN_OPCODE;
 
 /* Enum declaration for systrapsync insn opcode enums.  */
@@ -401,8 +401,8 @@ typedef enum ifield_type {
  , OR1K_F_RESV_20_5, OR1K_F_RESV_20_4, OR1K_F_RESV_15_8, OR1K_F_RESV_15_6
  , OR1K_F_RESV_10_11, OR1K_F_RESV_10_7, OR1K_F_RESV_10_3, OR1K_F_RESV_10_1
  , OR1K_F_RESV_7_4, OR1K_F_RESV_5_2, OR1K_F_IMM16_25_5, OR1K_F_IMM16_10_11
- , OR1K_F_DISP26, OR1K_F_UIMM16, OR1K_F_SIMM16, OR1K_F_UIMM6
- , OR1K_F_UIMM16_SPLIT, OR1K_F_SIMM16_SPLIT, OR1K_F_MAX
+ , OR1K_F_DISP26, OR1K_F_DISP21, OR1K_F_UIMM16, OR1K_F_SIMM16
+ , OR1K_F_UIMM6, OR1K_F_UIMM16_SPLIT, OR1K_F_SIMM16_SPLIT, OR1K_F_MAX
 } IFIELD_TYPE;
 
 #define MAX_IFLD ((int) OR1K_F_MAX)
@@ -622,13 +622,14 @@ typedef enum cgen_operand_type {
  , OR1K_OPERAND_SYS_SR_OVE, OR1K_OPERAND_SYS_CPUCFGR_OB64S, OR1K_OPERAND_SYS_CPUCFGR_ND, OR1K_OPERAND_SYS_FPCSR_RM
  , OR1K_OPERAND_MAC_MACHI, OR1K_OPERAND_MAC_MACLO, OR1K_OPERAND_ATOMIC_RESERVE, OR1K_OPERAND_ATOMIC_ADDRESS
  , OR1K_OPERAND_UIMM6, OR1K_OPERAND_RD, OR1K_OPERAND_RA, OR1K_OPERAND_RB
- , OR1K_OPERAND_DISP26, OR1K_OPERAND_SIMM16, OR1K_OPERAND_UIMM16, OR1K_OPERAND_SIMM16_SPLIT
- , OR1K_OPERAND_UIMM16_SPLIT, OR1K_OPERAND_RDSF, OR1K_OPERAND_RASF, OR1K_OPERAND_RBSF
- , OR1K_OPERAND_RDDF, OR1K_OPERAND_RADF, OR1K_OPERAND_RBDF, OR1K_OPERAND_MAX
+ , OR1K_OPERAND_DISP26, OR1K_OPERAND_DISP21, OR1K_OPERAND_SIMM16, OR1K_OPERAND_UIMM16
+ , OR1K_OPERAND_SIMM16_SPLIT, OR1K_OPERAND_UIMM16_SPLIT, OR1K_OPERAND_RDSF, OR1K_OPERAND_RASF
+ , OR1K_OPERAND_RBSF, OR1K_OPERAND_RDDF, OR1K_OPERAND_RADF, OR1K_OPERAND_RBDF
+ , OR1K_OPERAND_MAX
 } CGEN_OPERAND_TYPE;
 
 /* Number of operands types.  */
-#define MAX_OPERANDS 31
+#define MAX_OPERANDS 32
 
 /* Maximum number of operands referenced by any insn.  */
 #define MAX_OPERAND_INSTANCES 9
opcodes/or1k-dis.c +3 -0
index f54b6b411f..6f8001a2be 100644
@@ -90,6 +90,9 @@ or1k_cgen_print_operand (CGEN_CPU_DESC cd,
 
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      print_address (cd, info, fields->f_disp21, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
+      break;
     case OR1K_OPERAND_DISP26 :
       print_address (cd, info, fields->f_disp26, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
       break;
opcodes/or1k-ibld.c +28 -1
index 139457c080..acfede7639 100644
@@ -573,10 +573,17 @@ or1k_cgen_insert_operand (CGEN_CPU_DESC cd,
 
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      {
+        long value = fields->f_disp21;
+        value = ((((DI) (value) >> (13))) - (((DI) (pc) >> (13))));
+        errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, buffer);
+      }
+      break;
     case OR1K_OPERAND_DISP26 :
       {
         long value = fields->f_disp26;
-        value = ((SI) (((value) - (pc))) >> (2));
+        value = ((DI) (((value) - (pc))) >> (2));
         errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 25, 26, 32, total_length, buffer);
       }
       break;
@@ -688,6 +695,14 @@ or1k_cgen_extract_operand (CGEN_CPU_DESC cd,
 
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      {
+        long value;
+        length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, pc, & value);
+        value = ((((value) + (((DI) (pc) >> (13))))) << (13));
+        fields->f_disp21 = value;
+      }
+      break;
     case OR1K_OPERAND_DISP26 :
       {
         long value;
@@ -789,6 +804,9 @@ or1k_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
 
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      value = fields->f_disp21;
+      break;
     case OR1K_OPERAND_DISP26 :
       value = fields->f_disp26;
       break;
@@ -855,6 +873,9 @@ or1k_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
 
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      value = fields->f_disp21;
+      break;
     case OR1K_OPERAND_DISP26 :
       value = fields->f_disp26;
       break;
@@ -928,6 +949,9 @@ or1k_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
 {
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      fields->f_disp21 = value;
+      break;
     case OR1K_OPERAND_DISP26 :
       fields->f_disp26 = value;
       break;
@@ -991,6 +1015,9 @@ or1k_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
 {
   switch (opindex)
     {
+    case OR1K_OPERAND_DISP21 :
+      fields->f_disp21 = value;
+      break;
     case OR1K_OPERAND_DISP26 :
       fields->f_disp26 = value;
       break;
opcodes/or1k-opc.c +10 -0
index 0352bc3ebf..ba820a4c57 100644
@@ -52,6 +52,10 @@ static const CGEN_IFMT ifmt_l_j ATTRIBUTE_UNUSED = {
   32, 32, 0xfc000000, { { F (F_OPCODE) }, { F (F_DISP26) }, { 0 } }
 };
 
+static const CGEN_IFMT ifmt_l_adrp ATTRIBUTE_UNUSED = {
+  32, 32, 0xfc000000, { { F (F_OPCODE) }, { F (F_R1) }, { F (F_DISP21) }, { 0 } }
+};
+
 static const CGEN_IFMT ifmt_l_jr ATTRIBUTE_UNUSED = {
   32, 32, 0xffff07ff, { { F (F_OPCODE) }, { F (F_RESV_25_10) }, { F (F_R3) }, { F (F_RESV_10_11) }, { 0 } }
 };
@@ -189,6 +193,12 @@ static const CGEN_OPCODE or1k_cgen_insn_opcode_table[MAX_INSNS] =
     { { MNEM, ' ', OP (DISP26), 0 } },
     & ifmt_l_j, { 0x0 }
   },
+/* l.adrp $rD,${disp21} */
+  {
+    { 0, 0, 0, 0 },
+    { { MNEM, ' ', OP (RD), ',', OP (DISP21), 0 } },
+    & ifmt_l_adrp, { 0x8000000 }
+  },
 /* l.jal ${disp26} */
   {
     { 0, 0, 0, 0 },
opcodes/or1k-opc.h +33 -31

76 lines not on this page · raw message

opcodes/or1k-opinst.c +7 -0
index 936ed67f1b..c267efb6c4 100644
@@ -49,6 +49,12 @@ static const CGEN_OPINST sfmt_l_j_ops[] ATTRIBUTE_UNUSED = {
   { END, (const char *)0, (enum cgen_hw_type)0, (enum cgen_mode)0, (enum cgen_operand_type)0, 0, 0 }
 };
 
+static const CGEN_OPINST sfmt_l_adrp_ops[] ATTRIBUTE_UNUSED = {
+  { INPUT, "disp21", HW_H_IADDR, CGEN_MODE_UDI, OP_ENT (DISP21), 0, 0 },
+  { OUTPUT, "rD", HW_H_GPR, CGEN_MODE_UDI, OP_ENT (RD), 0, 0 },
+  { END, (const char *)0, (enum cgen_hw_type)0, (enum cgen_mode)0, (enum cgen_operand_type)0, 0, 0 }
+};
+
 static const CGEN_OPINST sfmt_l_jal_ops[] ATTRIBUTE_UNUSED = {
   { INPUT, "disp26", HW_H_IADDR, CGEN_MODE_UDI, OP_ENT (DISP26), 0, 0 },
   { INPUT, "pc", HW_H_PC, CGEN_MODE_UDI, 0, 0, 0 },
@@ -453,6 +459,7 @@ static const CGEN_OPINST sfmt_lf_madd_d_ops[] ATTRIBUTE_UNUSED = {
 static const CGEN_OPINST *or1k_cgen_opinst_table[MAX_INSNS] = {
   0,
   & sfmt_l_j_ops[0],
+  & sfmt_l_adrp_ops[0],
   & sfmt_l_jal_ops[0],
   & sfmt_l_jr_ops[0],
   & sfmt_l_jalr_ops[0],
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/4 or1k: Add the l.muld, l.muldu, l.macu, l.msbu insns

In reply to Stafford Horne

From: Richard Henderson <[email protected]>

Also fix the incorrect definitions of multiply and divide carry and overflow float.

Changes to the instructions are made in the .cpu file, then we regenerate the binutils and sim files.

The changes also required a few fixups for tests and additional sim helpers.

yyyy-mm-dd Richard Henderson <[email protected]>
Stafford Horne <[email protected]>

cpu/ChangeLog:

* or1korbis.cpu (insn-opcode-mac): Add opcodes for MACU and MSBU. (insn-opcode-alu-regreg): Add opcodes for MULD and MULDU. (l-mul): Fix overflow support and indentation. (l-mulu): Fix overflow support and indentation. (l-muld, l-muldu, l-msbu, l-macu): New instructions. (l-div); Remove incorrect carry behavior.
(l-divu): Fix carry and overflow behavior.
(l-mac): Add overflow support.
(l-msb, l-msbu): Add carry and overflow support.

opcodes/ChangeLog:

* or1k-desc.c: Regenerate.
* or1k-desc.h: Regenerate.
* or1k-opc.c: Regenerate.
* or1k-opc.h: Regenerate.
* or1k-opinst.c: Regenerate.

sim/common/ChangeLog:

* cgen-ops.h (ADDCFDI): New function, add carry flag DI variant. (ADDOFDI): New function, add overflow flag DI variant. (SUBCFDI): New function, subtract carry flag DI variant. (SUBOFDI): New function, subtract overflow flag DI variant.

sim/or1k/ChangeLog:

* or1k/cpu.h: Regenerate.
* or1k/decode.c: Regenerate.
* or1k/decode.h: Regenerate.
* or1k/model.c: Regenerate.
* or1k/sem-switch.c: Regenerate.
* or1k/sem.c: Regenerate:

sim/testsuite/sim/or1k/ChangeLog:

* div.S: Fix tests to match correct overflow/carry semantics.
* mul.S: Likewise.

yyyy-mm-dd Stafford Horne <[email protected]>

gas/ChangeLog:

* testsuite/gas/or1k/allinsn.s: Add instruction tests for l.muld, l.muldu, l.macu, l.msb, l.msbu.
* testsuite/gas/or1k/allinsn.d: Add test results for new instructions.

---
 cpu/or1korbis.cpu                | 261 +++++++++++++++++----------
 gas/testsuite/gas/or1k/allinsn.d |  25 +++
 gas/testsuite/gas/or1k/allinsn.s |  20 +++
 opcodes/or1k-desc.c              |  24 ++-
 opcodes/or1k-desc.h              |  11 +-
 opcodes/or1k-opc.c               |  34 +++-
 opcodes/or1k-opc.h               |  23 +--
 opcodes/or1k-opinst.c            |  91 +++++++++-
 sim/common/cgen-ops.h            |  36 ++++
 sim/or1k/cpu.h                   |  32 ++++
 sim/or1k/decode.c                | 239 +++++++++++++++++++++++--
 sim/or1k/decode.h                |  82 ++++-----
 sim/or1k/model.c                 | 186 +++++++++++++++++++-
 sim/or1k/sem-switch.c            | 281 +++++++++++++++++++++++------
 sim/or1k/sem.c                   | 293 +++++++++++++++++++++++++------
 sim/testsuite/sim/or1k/div.S     |  12 +-
 sim/testsuite/sim/or1k/mul.S     | 109 ++++++------
 17 files changed, 1404 insertions(+), 355 deletions(-)
cpu/or1korbis.cpu +168 -93
index 6fbf40ad99..094f0185a7 100644
@@ -220,8 +220,10 @@
 (define-normal-insn-enum insn-opcode-mac
   "multiply/accumulate insn opcode enums" ((MACH ORBIS-MACHS))
   OPC_MAC_ f-op-3-4
-  (("MAC" #x1)
-   ("MSB" #x2)
+  (("MAC"   #x1)
+   ("MSB"   #x2)
+   ("MACU"  #x3)
+   ("MSBU"  #x4)
    )
   )
 
@@ -263,12 +265,14 @@
    ("OR"    #x4)
    ("XOR"   #x5)
    ("MUL"   #x6)
+   ("MULD"  #x7)
    ("SHROT" #x8)
    ("DIV"   #x9)
    ("DIVU"  #xA)
    ("MULU"  #xB)
    ("EXTBH" #xC)
    ("EXTW"  #xD)
+   ("MULDU" #xD)
    ("CMOV"  #xE)
    ("FFL1"  #xF)
    )
@@ -595,7 +599,7 @@
                (set UWI mac-machi 0)
                )
      ()
-     )
+)
 
 
 ; System releated instructions
@@ -816,77 +820,93 @@
 )
 
 (dni (l-mul) "l.mul reg/reg/reg"
-          ((MACH ORBIS-MACHS))
-          ("l.mul $rD,$rA,$rB")
-          (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MUL)
-          (sequence ()
-                    (sequence ()
-                              ; 2's complement overflow
-                              (set BI sys-sr-ov (mul-o2flag WI rA rB))
-                              ; 1's complement overflow
-                              (set BI sys-sr-cy (mul-o1flag WI rA rB))
-                              (set rD (mul WI rA rB))
-                              )
-                    (if (andif sys-sr-ov sys-sr-ove)
-                        (raise-exception EXCEPT-RANGE))
-                    )
-          ()
+     ((MACH ORBIS-MACHS))
+     ("l.mul $rD,$rA,$rB")
+     (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MUL)
+     (sequence ()
+	(sequence ()
+	   (set BI sys-sr-ov (mul-o2flag WI rA rB))
+	   (set rD (mul WI rA rB))
+	)
+	(if (andif sys-sr-ov sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
+     )
+     ()
+)
+
+(dni (l-muld) "l.muld reg/reg"
+     ((MACH ORBIS-MACHS))
+     ("l.muld $rA,$rB")
+     (+ OPC_ALU (f-resv-25-5 0) rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULD)
+     (sequence ((DI result))
+	(set DI result (mul DI (ext DI rA) (ext DI rB)))
+	(set SI mac-machi (subword SI result 0))
+	(set SI mac-maclo (subword SI result 1))
+     )
+     ()
 )
 
 (dni (l-mulu) "l.mulu reg/reg/reg"
-          ((MACH ORBIS-MACHS))
-          ("l.mulu $rD,$rA,$rB")
-          (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULU)
-          (sequence ()
-                    (sequence ()
-                              ; 2's complement overflow
-                              (set BI sys-sr-ov 0)
-                              ; 1's complement overflow
-                              (set BI sys-sr-cy (mul-o1flag UWI rA rB))
-                              (set rD (mul UWI rA rB))
-                              )
-                    (if (andif sys-sr-ov sys-sr-ove)
-                        (raise-exception EXCEPT-RANGE))
-                    )
-          ()
+     ((MACH ORBIS-MACHS))
+     ("l.mulu $rD,$rA,$rB")
+     (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULU)
+     (sequence ()
+	(sequence ()
+	   (set BI sys-sr-cy (mul-o1flag UWI rA rB))
+	   (set rD (mul UWI rA rB))
+	)
+	(if (andif sys-sr-cy sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
+     )
+     ()
+)
+
+(dni (l-muldu) "l.muld reg/reg"
+     ((MACH ORBIS-MACHS))
+     ("l.muldu $rA,$rB")
+     (+ OPC_ALU (f-resv-25-5 0) rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULDU)
+     (sequence ((DI result))
+	(set DI result (mul DI (zext DI rA) (zext DI rB)))
+	(set SI mac-machi (subword SI result 0))
+	(set SI mac-maclo (subword SI result 1))
+     )
+     ()
 )
 
 (dni l-div "divide (signed)"
-          ((MACH ORBIS-MACHS))
-          "l.div $rD,$rA,$rB"
-          (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIV)
-          (sequence ()
-                    (if (ne rB 0)
-                        (sequence ()
-                                  (set BI sys-sr-cy 0)
-                                  (set WI rD (div WI rA rB))
-                                  )
-                        (set BI sys-sr-cy 1)
-                        )
-                    (set BI sys-sr-ov 0)
-                    (if (andif sys-sr-cy sys-sr-ove)
-                        (raise-exception EXCEPT-RANGE))
-                    )
-          ()
+     ((MACH ORBIS-MACHS))
+     "l.div $rD,$rA,$rB"
+     (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIV)
+     (if (ne rB 0)
+	(sequence ()
+	   (set BI sys-sr-ov 0)
+	   (set WI rD (div WI rA rB))
+	)
+	(sequence ()
+	   (set BI sys-sr-ov 1)
+	   (if sys-sr-ove
+	      (raise-exception EXCEPT-RANGE))
+	)
+     )
+     ()
 )
 
 (dni l-divu "divide (unsigned)"
-          ((MACH ORBIS-MACHS))
-          "l.divu $rD,$rA,$rB"
-          (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIVU)
-          (sequence ()
-                    (if (ne rB 0)
-                        (sequence ()
-                                  (set BI sys-sr-cy 0)
-                                  (set rD (udiv UWI rA rB))
-                                  )
-                        (set BI sys-sr-cy 1)
-                        )
-                    (set BI sys-sr-ov 0)
-                    (if (andif sys-sr-cy sys-sr-ove)
-                        (raise-exception EXCEPT-RANGE))
-                    )
-          ()
+     ((MACH ORBIS-MACHS))
+     "l.divu $rD,$rA,$rB"
+     (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIVU)
+     (if (ne rB 0)
+	(sequence ()
+	   (set BI sys-sr-cy 0)
+	   (set rD (udiv UWI rA rB))
+	)
+	(sequence ()
+	   (set BI sys-sr-cy 1)
+	   (if sys-sr-ove
+	       (raise-exception EXCEPT-RANGE))
+	)
+     )
+     ()
 )
 
 (dni l-ff1 "find first '1'"
@@ -984,17 +1004,14 @@
      (+ OPC_MULI rD rA simm16)
      (sequence ()
                (sequence ()
-                         ; 2's complement overflow
                          (set sys-sr-ov (mul-o2flag WI rA (ext WI simm16)))
-                         ; 1's complement overflow
-                         (set sys-sr-cy (mul-o1flag UWI rA (ext UWI simm16)))
                          (set rD (mul WI rA (ext WI simm16)))
                          )
                (if (andif sys-sr-ov sys-sr-ove)
                    (raise-exception EXCEPT-RANGE))
                )
      ()
-     )
+)
 
 (define-pmacro (extbh-insn mnemonic extop extmode truncmode)
   (begin
@@ -1118,42 +1135,100 @@
      ((MACH ORBIS-MACHS))
      "l.mac $rA,$rB"
      (+  OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MAC)
-     (sequence ((WI prod) (DI result))
-               (set WI prod (mul WI rA rB))
-               (set DI result (add (join DI SI mac-machi mac-maclo) (ext DI prod)))
-               (set SI mac-machi (subword SI result 0))
-               (set SI mac-maclo (subword SI result 1))
-               )
+     (sequence ()
+	(sequence ((DI prod) (DI mac) (DI result))
+	   (set DI prod (mul DI (ext DI rA) (ext DI rB)))
+	   (set DI mac (join DI SI mac-machi mac-maclo))
+	   (set DI result (add prod mac))
+	   (set SI mac-machi (subword SI result 0))
+	   (set SI mac-maclo (subword SI result 1))
+	   (set BI sys-sr-ov (addc-oflag prod mac 0))
+	)
+	(if (andif sys-sr-ov sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
+     )
      ()
+)
+
+(dni l-maci
+     "l.maci reg/simm16"
+     ((MACH ORBIS-MACHS))
+     "l.maci $rA,${simm16}"
+     (+ OPC_MACI (f-resv-25-5 0) rA simm16)
+     (sequence ()
+	(sequence ((DI prod) (DI mac) (DI result))
+	   (set DI prod (mul DI (ext DI rA) (ext DI simm16)))
+	   (set DI mac (join DI SI mac-machi mac-maclo))
+	   (set DI result (add mac prod))
+	   (set SI mac-machi (subword SI result 0))
+	   (set SI mac-maclo (subword SI result 1))
+	   (set BI sys-sr-ov (addc-oflag prod mac 0))
+	)
+	(if (andif sys-sr-ov sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
      )
+     ()
+)
+
+(dni l-macu
+     "l.macu reg/reg"
+     ((MACH ORBIS-MACHS))
+     "l.macu $rA,$rB"
+     (+  OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MACU)
+     (sequence ()
+	(sequence ((DI prod) (DI mac) (DI result))
+	   (set DI prod (mul DI (zext DI rA) (zext DI rB)))
+	   (set DI mac (join DI SI mac-machi mac-maclo))
+	   (set DI result (add prod mac))
+	   (set SI mac-machi (subword SI result 0))
+	   (set SI mac-maclo (subword SI result 1))
+	   (set BI sys-sr-cy (addc-cflag prod mac 0))
+	)
+	(if (andif sys-sr-cy sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
+     )
+     ()
+)
 
 (dni l-msb
      "l.msb reg/reg"
      ((MACH ORBIS-MACHS))
      "l.msb $rA,$rB"
      (+  OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MSB)
-     (sequence ((WI prod) (DI result))
-               (set WI prod (mul WI rA rB))
-               (set DI result (sub (join DI SI mac-machi mac-maclo) (ext DI prod)))
-               (set SI mac-machi (subword SI result 0))
-               (set SI mac-maclo (subword SI result 1))
-               )
-     ()
+     (sequence ()
+	(sequence ((DI prod) (DI mac) (DI result))
+	   (set DI prod (mul DI (ext DI rA) (ext DI rB)))
+	   (set DI mac (join DI SI mac-machi mac-maclo))
+	   (set DI result (sub mac prod))
+	   (set SI mac-machi (subword SI result 0))
+	   (set SI mac-maclo (subword SI result 1))
+	   (set BI sys-sr-ov (subc-oflag mac result 0))
+	)
+	(if (andif sys-sr-ov sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
      )
+     ()
+)
 
-(dni l-maci
-     "l.maci reg/simm16"
+(dni l-msbu
+     "l.msbu reg/reg"
      ((MACH ORBIS-MACHS))
-     "l.maci $rA,${simm16}"
-     (+ OPC_MACI (f-resv-25-5 0) rA simm16)
-     (sequence ((WI prod) (DI result))
-               (set WI prod (mul WI (ext WI simm16) rA))
-               (set DI result (add (join DI SI mac-machi mac-maclo) (ext DI prod)))
-               (set SI mac-machi (subword SI result 0))
-               (set SI mac-maclo (subword SI result 1))
-               )
-     ()
+     "l.msbu $rA,$rB"
+     (+  OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MSBU)
+     (sequence ()
+	(sequence ((DI prod) (DI mac) (DI result))
+	   (set DI prod (mul DI (zext DI rA) (zext DI rB)))
+	   (set DI mac (join DI SI mac-machi mac-maclo))
+	   (set DI result (sub mac prod))
+	   (set SI mac-machi (subword SI result 0))
+	   (set SI mac-maclo (subword SI result 1))
+	   (set BI sys-sr-cy (subc-cflag mac result 0))
+	)
+	(if (andif sys-sr-cy sys-sr-ove)
+	    (raise-exception EXCEPT-RANGE))
      )
+     ()
+)
 
 (define-pmacro (cust-insn cust-num)
   (begin
gas/testsuite/gas/or1k/allinsn.d +25 -0
index a4ffe43f0b..4260498fdb 100644
@@ -696,3 +696,28 @@ Disassembly of section \.text:
 			840: R_OR1K_PCREL_PG21	globaldata
  844:	08 60 00 00 	l\.adrp r3,0 <localtext>
 			844: R_OR1K_PCREL_PG21	\.data
+
+00000848 <l_muld>:
+ 848:	e0 00 03 07 	l\.muld r0,r0
+ 84c:	e0 1f fb 07 	l\.muld r31,r31
+ 850:	e0 03 23 07 	l\.muld r3,r4
+
+00000854 <l_muldu>:
+ 854:	e0 00 03 0d 	l\.muldu r0,r0
+ 858:	e0 1f fb 0d 	l\.muldu r31,r31
+ 85c:	e0 03 23 0d 	l\.muldu r3,r4
+
+00000860 <l_macu>:
+ 860:	c4 00 00 03 	l\.macu r0,r0
+ 864:	c4 1f f8 03 	l\.macu r31,r31
+ 868:	c4 03 20 03 	l\.macu r3,r4
+
+0000086c <l_msb>:
+ 86c:	c4 00 00 02 	l\.msb r0,r0
+ 870:	c4 1f f8 02 	l\.msb r31,r31
+ 874:	c4 03 20 02 	l\.msb r3,r4
+
+00000878 <l_msbu>:
+ 878:	c4 00 00 04 	l\.msbu r0,r0
+ 87c:	c4 1f f8 04 	l\.msbu r31,r31
+ 880:	c4 03 20 04 	l\.msbu r3,r4
gas/testsuite/gas/or1k/allinsn.s +20 -0
index 55d703734e..e5a7906464 100644
@@ -680,3 +680,23 @@ l_maci:
 l_adrp:
 	l.adrp r3,globaldata
 	l.adrp r3,localdata
+l_muld:
+	l.muld r0,r0
+	l.muld r31,r31
+	l.muld r3,r4
+l_muldu:
+	l.muldu r0,r0
+	l.muldu r31,r31
+	l.muldu r3,r4
+l_macu:
+	l.macu r0,r0
+	l.macu r31,r31
+	l.macu r3,r4
+l_msb:
+	l.msb r0,r0
+	l.msb r31,r31
+	l.msb r3,r4
+l_msbu:
+	l.msbu r0,r0
+	l.msbu r31,r31
+	l.msbu r3,r4
opcodes/or1k-desc.c +22 -2
index 91c2fbd73d..f3c4e9ee23 100644
@@ -1381,11 +1381,21 @@ static const CGEN_IBASE or1k_cgen_insn_table[MAX_INSNS] =
     OR1K_INSN_L_MUL, "l-mul", "l.mul", 32,
     { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
   },
+/* l.muld $rA,$rB */
+  {
+    OR1K_INSN_L_MULD, "l-muld", "l.muld", 32,
+    { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
+  },
 /* l.mulu $rD,$rA,$rB */
   {
     OR1K_INSN_L_MULU, "l-mulu", "l.mulu", 32,
     { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
   },
+/* l.muldu $rA,$rB */
+  {
+    OR1K_INSN_L_MULDU, "l-muldu", "l.muldu", 32,
+    { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
+  },
 /* l.div $rD,$rA,$rB */
   {
     OR1K_INSN_L_DIV, "l-div", "l.div", 32,
@@ -1576,14 +1586,24 @@ static const CGEN_IBASE or1k_cgen_insn_table[MAX_INSNS] =
     OR1K_INSN_L_MAC, "l-mac", "l.mac", 32,
     { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
   },
+/* l.maci $rA,${simm16} */
+  {
+    OR1K_INSN_L_MACI, "l-maci", "l.maci", 32,
+    { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
+  },
+/* l.macu $rA,$rB */
+  {
+    OR1K_INSN_L_MACU, "l-macu", "l.macu", 32,
+    { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
+  },
 /* l.msb $rA,$rB */
   {
     OR1K_INSN_L_MSB, "l-msb", "l.msb", 32,
     { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
   },
-/* l.maci $rA,${simm16} */
+/* l.msbu $rA,$rB */
   {
-    OR1K_INSN_L_MACI, "l-maci", "l.maci", 32,
+    OR1K_INSN_L_MSBU, "l-msbu", "l.msbu", 32,
     { 0, { { { (1<<MACH_OR32)|(1<<MACH_OR32ND)|(1<<MACH_OR64)|(1<<MACH_OR64ND), 0 } } } }
   },
 /* l.cust1 */
opcodes/or1k-desc.h +6 -5
index d84f0fa52a..040bd926c5 100644
@@ -306,7 +306,7 @@ typedef enum insn_opcode_movehimacrc {
 
 /* Enum declaration for multiply/accumulate insn opcode enums.  */
 typedef enum insn_opcode_mac {
-  OPC_MAC_MAC = 1, OPC_MAC_MSB = 2
+  OPC_MAC_MAC = 1, OPC_MAC_MSB = 2, OPC_MAC_MACU = 3, OPC_MAC_MSBU = 4
 } INSN_OPCODE_MAC;
 
 /* Enum declaration for shift/rotate insn opcode enums.  */
@@ -327,9 +327,10 @@ typedef enum insn_opcode_extws {
 /* Enum declaration for alu reg/reg insn opcode enums.  */
 typedef enum insn_opcode_alu_regreg {
   OPC_ALU_REGREG_ADD = 0, OPC_ALU_REGREG_ADDC = 1, OPC_ALU_REGREG_SUB = 2, OPC_ALU_REGREG_AND = 3
- , OPC_ALU_REGREG_OR = 4, OPC_ALU_REGREG_XOR = 5, OPC_ALU_REGREG_MUL = 6, OPC_ALU_REGREG_SHROT = 8
- , OPC_ALU_REGREG_DIV = 9, OPC_ALU_REGREG_DIVU = 10, OPC_ALU_REGREG_MULU = 11, OPC_ALU_REGREG_EXTBH = 12
- , OPC_ALU_REGREG_EXTW = 13, OPC_ALU_REGREG_CMOV = 14, OPC_ALU_REGREG_FFL1 = 15
+ , OPC_ALU_REGREG_OR = 4, OPC_ALU_REGREG_XOR = 5, OPC_ALU_REGREG_MUL = 6, OPC_ALU_REGREG_MULD = 7
+ , OPC_ALU_REGREG_SHROT = 8, OPC_ALU_REGREG_DIV = 9, OPC_ALU_REGREG_DIVU = 10, OPC_ALU_REGREG_MULU = 11
+ , OPC_ALU_REGREG_EXTBH = 12, OPC_ALU_REGREG_EXTW = 13, OPC_ALU_REGREG_MULDU = 13, OPC_ALU_REGREG_CMOV = 14
+ , OPC_ALU_REGREG_FFL1 = 15
 } INSN_OPCODE_ALU_REGREG;
 
 /* Enum declaration for setflag insn opcode enums.  */
@@ -632,7 +633,7 @@ typedef enum cgen_operand_type {
 #define MAX_OPERANDS 32
 
 /* Maximum number of operands referenced by any insn.  */
-#define MAX_OPERAND_INSTANCES 9
+#define MAX_OPERAND_INSTANCES 10
 
 /* Insn attribute indices.  */
 
opcodes/or1k-opc.c +31 -3
index ba820a4c57..337dda5306 100644
@@ -116,6 +116,10 @@ static const CGEN_IFMT ifmt_l_and ATTRIBUTE_UNUSED = {
   32, 32, 0xfc0007ff, { { F (F_OPCODE) }, { F (F_R1) }, { F (F_R2) }, { F (F_R3) }, { F (F_RESV_10_7) }, { F (F_OP_3_4) }, { 0 } }
 };
 
+static const CGEN_IFMT ifmt_l_muld ATTRIBUTE_UNUSED = {
+  32, 32, 0xffe007ff, { { F (F_OPCODE) }, { F (F_RESV_25_5) }, { F (F_R2) }, { F (F_R3) }, { F (F_RESV_10_7) }, { F (F_OP_3_4) }, { 0 } }
+};
+
 static const CGEN_IFMT ifmt_l_exths ATTRIBUTE_UNUSED = {
   32, 32, 0xfc00ffff, { { F (F_OPCODE) }, { F (F_R1) }, { F (F_R2) }, { F (F_RESV_15_6) }, { F (F_OP_9_4) }, { F (F_RESV_5_2) }, { F (F_OP_3_4) }, { 0 } }
 };
@@ -457,12 +461,24 @@ static const CGEN_OPCODE or1k_cgen_insn_opcode_table[MAX_INSNS] =
     { { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
     & ifmt_l_and, { 0xe0000306 }
   },
+/* l.muld $rA,$rB */
+  {
+    { 0, 0, 0, 0 },
+    { { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
+    & ifmt_l_muld, { 0xe0000307 }
+  },
 /* l.mulu $rD,$rA,$rB */
   {
     { 0, 0, 0, 0 },
     { { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
     & ifmt_l_and, { 0xe000030b }
   },
+/* l.muldu $rA,$rB */
+  {
+    { 0, 0, 0, 0 },
+    { { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
+    & ifmt_l_muld, { 0xe000030d }
+  },
 /* l.div $rD,$rA,$rB */
   {
     { 0, 0, 0, 0 },
@@ -691,17 +707,29 @@ static const CGEN_OPCODE or1k_cgen_insn_opcode_table[MAX_INSNS] =
     { { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
     & ifmt_l_mac, { 0xc4000001 }
   },
+/* l.maci $rA,${simm16} */
+  {
+    { 0, 0, 0, 0 },
+    { { MNEM, ' ', OP (RA), ',', OP (SIMM16), 0 } },
+    & ifmt_l_maci, { 0x4c000000 }
+  },
+/* l.macu $rA,$rB */
+  {
+    { 0, 0, 0, 0 },
+    { { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
+    & ifmt_l_mac, { 0xc4000003 }
+  },
 /* l.msb $rA,$rB */
   {
     { 0, 0, 0, 0 },
     { { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
     & ifmt_l_mac, { 0xc4000002 }
   },
-/* l.maci $rA,${simm16} */
+/* l.msbu $rA,$rB */
   {
     { 0, 0, 0, 0 },
-    { { MNEM, ' ', OP (RA), ',', OP (SIMM16), 0 } },
-    & ifmt_l_maci, { 0x4c000000 }
+    { { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
+    & ifmt_l_mac, { 0xc4000004 }
   },
 /* l.cust1 */
   {
opcodes/or1k-opc.h +12 -11
index d2a377257f..66d077361f 100644
@@ -51,17 +51,18 @@ typedef enum cgen_insn_type {
  , OR1K_INSN_L_SLLI, OR1K_INSN_L_SRL, OR1K_INSN_L_SRLI, OR1K_INSN_L_SRA
  , OR1K_INSN_L_SRAI, OR1K_INSN_L_ROR, OR1K_INSN_L_RORI, OR1K_INSN_L_AND
  , OR1K_INSN_L_OR, OR1K_INSN_L_XOR, OR1K_INSN_L_ADD, OR1K_INSN_L_SUB
- , OR1K_INSN_L_ADDC, OR1K_INSN_L_MUL, OR1K_INSN_L_MULU, OR1K_INSN_L_DIV
- , OR1K_INSN_L_DIVU, OR1K_INSN_L_FF1, OR1K_INSN_L_FL1, OR1K_INSN_L_ANDI
- , OR1K_INSN_L_ORI, OR1K_INSN_L_XORI, OR1K_INSN_L_ADDI, OR1K_INSN_L_ADDIC
- , OR1K_INSN_L_MULI, OR1K_INSN_L_EXTHS, OR1K_INSN_L_EXTBS, OR1K_INSN_L_EXTHZ
- , OR1K_INSN_L_EXTBZ, OR1K_INSN_L_EXTWS, OR1K_INSN_L_EXTWZ, OR1K_INSN_L_CMOV
- , OR1K_INSN_L_SFGTS, OR1K_INSN_L_SFGTSI, OR1K_INSN_L_SFGTU, OR1K_INSN_L_SFGTUI
- , OR1K_INSN_L_SFGES, OR1K_INSN_L_SFGESI, OR1K_INSN_L_SFGEU, OR1K_INSN_L_SFGEUI
- , OR1K_INSN_L_SFLTS, OR1K_INSN_L_SFLTSI, OR1K_INSN_L_SFLTU, OR1K_INSN_L_SFLTUI
- , OR1K_INSN_L_SFLES, OR1K_INSN_L_SFLESI, OR1K_INSN_L_SFLEU, OR1K_INSN_L_SFLEUI
- , OR1K_INSN_L_SFEQ, OR1K_INSN_L_SFEQI, OR1K_INSN_L_SFNE, OR1K_INSN_L_SFNEI
- , OR1K_INSN_L_MAC, OR1K_INSN_L_MSB, OR1K_INSN_L_MACI, OR1K_INSN_L_CUST1
+ , OR1K_INSN_L_ADDC, OR1K_INSN_L_MUL, OR1K_INSN_L_MULD, OR1K_INSN_L_MULU
+ , OR1K_INSN_L_MULDU, OR1K_INSN_L_DIV, OR1K_INSN_L_DIVU, OR1K_INSN_L_FF1
+ , OR1K_INSN_L_FL1, OR1K_INSN_L_ANDI, OR1K_INSN_L_ORI, OR1K_INSN_L_XORI
+ , OR1K_INSN_L_ADDI, OR1K_INSN_L_ADDIC, OR1K_INSN_L_MULI, OR1K_INSN_L_EXTHS
+ , OR1K_INSN_L_EXTBS, OR1K_INSN_L_EXTHZ, OR1K_INSN_L_EXTBZ, OR1K_INSN_L_EXTWS
+ , OR1K_INSN_L_EXTWZ, OR1K_INSN_L_CMOV, OR1K_INSN_L_SFGTS, OR1K_INSN_L_SFGTSI
+ , OR1K_INSN_L_SFGTU, OR1K_INSN_L_SFGTUI, OR1K_INSN_L_SFGES, OR1K_INSN_L_SFGESI
+ , OR1K_INSN_L_SFGEU, OR1K_INSN_L_SFGEUI, OR1K_INSN_L_SFLTS, OR1K_INSN_L_SFLTSI
+ , OR1K_INSN_L_SFLTU, OR1K_INSN_L_SFLTUI, OR1K_INSN_L_SFLES, OR1K_INSN_L_SFLESI
+ , OR1K_INSN_L_SFLEU, OR1K_INSN_L_SFLEUI, OR1K_INSN_L_SFEQ, OR1K_INSN_L_SFEQI
+ , OR1K_INSN_L_SFNE, OR1K_INSN_L_SFNEI, OR1K_INSN_L_MAC, OR1K_INSN_L_MACI
+ , OR1K_INSN_L_MACU, OR1K_INSN_L_MSB, OR1K_INSN_L_MSBU, OR1K_INSN_L_CUST1
  , OR1K_INSN_L_CUST2, OR1K_INSN_L_CUST3, OR1K_INSN_L_CUST4, OR1K_INSN_L_CUST5
  , OR1K_INSN_L_CUST6, OR1K_INSN_L_CUST7, OR1K_INSN_L_CUST8, OR1K_INSN_LF_ADD_S
  , OR1K_INSN_LF_ADD_D, OR1K_INSN_LF_SUB_S, OR1K_INSN_LF_SUB_D, OR1K_INSN_LF_MUL_S
opcodes/or1k-opinst.c +83 -8

149 lines not on this page · raw message

sim/common/cgen-ops.h +36 -0
index 87ca4836ba..0ce7e58bba 100644
@@ -647,6 +647,38 @@ MUL1OFSI (USI a, USI b)
   return res;
 }
 
+SEMOPS_INLINE BI
+ADDCFDI (DI a, DI b, BI c)
+{
+  DI tmp = ADDDI (a, ADDDI (b, c));
+  BI res = ((UDI) tmp < (UDI) a) || (c && tmp == a);
+  return res;
+}
+
+SEMOPS_INLINE BI
+ADDOFDI (DI a, DI b, BI c)
+{
+  DI tmp = ADDDI (a, ADDDI (b, c));
+  BI res = (((a < 0) == (b < 0))
+	    && ((a < 0) != (tmp < 0)));
+  return res;
+}
+
+SEMOPS_INLINE BI
+SUBCFDI (DI a, DI b, BI c)
+{
+  BI res = ((UDI) a < (UDI) b) || (c && a == b);
+  return res;
+}
+
+SEMOPS_INLINE BI
+SUBOFDI (DI a, DI b, BI c)
+{
+  DI tmp = SUBDI (a, ADDSI (b, c));
+  BI res = (((a < 0) != (b < 0))
+	    && ((a < 0) != (tmp < 0)));
+  return res;
+}
 #else
 
 SI ADDCSI (SI, SI, BI);
@@ -669,6 +701,10 @@ UBI SUBCFQI (QI, QI, BI);
 UBI SUBOFQI (QI, QI, BI);
 BI MUL1OFSI (SI a, SI b);
 BI MUL2OFSI (SI a, SI b);
+BI ADDCFDI (DI a, DI b, BI c);
+BI ADDOFDI (DI a, DI b, BI c);
+BI SUBCFDI (DI a, DI b, BI c);
+BI SUBOFDI (DI a, DI b, BI c);
 
 #endif
 
sim/or1k/cpu.h +32 -0
index 9646c33df6..b847f53032 100644
@@ -4515,6 +4515,10 @@ union sem_fields {
   struct { /*  */
     IADDR i_disp26;
   } sfmt_l_j;
+  struct { /*  */
+    IADDR i_disp21;
+    UINT f_r1;
+  } sfmt_l_adrp;
   struct { /*  */
     UINT f_r1;
     UINT f_r2;
@@ -4614,6 +4618,17 @@ struct scache {
   f_opcode = EXTRACT_LSB0_UINT (insn, 32, 31, 6); \
   f_disp26 = ((((EXTRACT_LSB0_SINT (insn, 32, 25, 26)) << (2))) + (pc)); \
 
+#define EXTRACT_IFMT_L_ADRP_VARS \
+  UINT f_opcode; \
+  UINT f_r1; \
+  USI f_disp21; \
+  unsigned int length;
+#define EXTRACT_IFMT_L_ADRP_CODE \
+  length = 4; \
+  f_opcode = EXTRACT_LSB0_UINT (insn, 32, 31, 6); \
+  f_r1 = EXTRACT_LSB0_UINT (insn, 32, 25, 5); \
+  f_disp21 = ((((EXTRACT_LSB0_SINT (insn, 32, 20, 21)) + (((SI) (pc) >> (13))))) << (13)); \
+
 #define EXTRACT_IFMT_L_JR_VARS \
   UINT f_opcode; \
   UINT f_resv_25_10; \
@@ -4831,6 +4846,23 @@ struct scache {
   f_resv_10_7 = EXTRACT_LSB0_UINT (insn, 32, 10, 7); \
   f_op_3_4 = EXTRACT_LSB0_UINT (insn, 32, 3, 4); \
 
+#define EXTRACT_IFMT_L_MULD_VARS \
+  UINT f_opcode; \
+  UINT f_resv_25_5; \
+  UINT f_r2; \
+  UINT f_r3; \
+  UINT f_resv_10_7; \
+  UINT f_op_3_4; \
+  unsigned int length;
+#define EXTRACT_IFMT_L_MULD_CODE \
+  length = 4; \
+  f_opcode = EXTRACT_LSB0_UINT (insn, 32, 31, 6); \
+  f_resv_25_5 = EXTRACT_LSB0_UINT (insn, 32, 25, 5); \
+  f_r2 = EXTRACT_LSB0_UINT (insn, 32, 20, 5); \
+  f_r3 = EXTRACT_LSB0_UINT (insn, 32, 15, 5); \
+  f_resv_10_7 = EXTRACT_LSB0_UINT (insn, 32, 10, 7); \
+  f_op_3_4 = EXTRACT_LSB0_UINT (insn, 32, 3, 4); \
+
 #define EXTRACT_IFMT_L_EXTHS_VARS \
   UINT f_opcode; \
   UINT f_r1; \
sim/or1k/decode.c +226 -13

340 lines not on this page · raw message

sim/or1k/decode.h +42 -40

92 lines not on this page · raw message

sim/or1k/model.c +178 -8

300 lines not on this page · raw message

sim/or1k/sem-switch.c +228 -53

450 lines not on this page · raw message

sim/or1k/sem.c +239 -54

461 lines not on this page · raw message

sim/testsuite/sim/or1k/div.S +6 -6
index e1e28d5621..a3202e9f8c 100644
@@ -75,30 +75,30 @@
 # output: report(0x0000000c);\n
 # output: report(0x00000000);\n
 # output: report(0xfffffffd);\n
-# output: report(0x00000001);\n
 # output: report(0x00000000);\n
+# output: report(0x00000001);\n
 # output: report(0x00000000);\n
 # output: \n
 # output: report(0xfffffff4);\n
 # output: report(0x00000000);\n
 # output: report(0xfffffffd);\n
-# output: report(0x00000001);\n
 # output: report(0x00000000);\n
+# output: report(0x00000001);\n
 # output: report(0x00000000);\n
 # output: \n
 # output: report(0x0000000c);\n
 # output: report(0x00000000);\n
 # output: report(0xfffffffd);\n
-# output: report(0x00000001);\n
 # output: report(0x00000000);\n
 # output: report(0x00000001);\n
+# output: report(0x00000001);\n
 # output: \n
 # output: report(0xfffffff4);\n
 # output: report(0x00000000);\n
 # output: report(0xfffffffd);\n
-# output: report(0x00000001);\n
 # output: report(0x00000000);\n
 # output: report(0x00000001);\n
+# output: report(0x00000001);\n
 # output: \n
 # output: report(0x0000000c);\n
 # output: report(0x00000003);\n
@@ -233,7 +233,7 @@ start_tests:
 	TEST_INST_I32_I32 l.div, 0x0000000c, 0xfffffffd
 	TEST_INST_I32_I32 l.div, 0x0000000b, 0xfffffffd
 
-	/* Divide by zero.  This will set the carry flag.  */
+	/* Divide by zero.  This will set the overflow flag.  */
 	TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
 	TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
 
@@ -241,7 +241,7 @@ start_tests:
 
 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
 
-	/* Divide by zero.  This will set the carry flag and trigger an
+	/* Divide by zero.  This will set the overflow flag and trigger an
 	   exception.  */
 	TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
 	TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
sim/testsuite/sim/or1k/mul.S +50 -59

315 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

cover OpenRISC binutils updates and new relocs

In reply to Stafford Horne

Hello,

Does anyone have concerns with these patches? Mostly they are for openrisc parts only.

Thoughts; We have new relocations here, maybe I need to add documentation?

Other than that I think it looks ok.

-Stafford

Quoted 85 lines · Stafford Horne

Hello,

This series contains a lot of updates for OpenRISC binutils. Including:
- Definitions for missing instructions.
- New relocations used in the new GCC OpenRISC port
- A new instruction l.adrp

The patches were for the most part written by Richard Henderson, I have fixed a few bugs, added additional tests and wrote the ChangeLogs.

These patches have been tested and used in the new OpenRISC GCC clean-room rewrite done by Richard and Me.

http://stffrdhrn.github.io/software/embedded/openrisc/2018/02/03/openrisc_gcc_rewrite.html

-Stafford

Richard Henderson (2):
or1k: Add relocations for high-signed and low-stores
or1k: Add the l.muld, l.muldu, l.macu, l.msbu insns

Stafford Horne (2):
or1k: Fix messages for relocations in shared libraries
or1k: Add the l.adrp insn and supporting relocations

 bfd/bfd-in2.h                                 |   19 +-
 bfd/elf32-or1k.c                              | 1002 +++++++++++++----
 bfd/libbfd.h                                  |   19 +-
 bfd/reloc.c                                   |   34 +-
 cpu/or1k.opc                                  |  582 +++++-----
 cpu/or1korbis.cpu                             |  300 +++--
 gas/config/tc-or1k.c                          |    6 +
 gas/testsuite/gas/or1k/allinsn.d              |   50 +-
 gas/testsuite/gas/or1k/allinsn.s              |   25 +
 .../gas/or1k/{allinsn.exp => or1k.exp}        |    1 +
 gas/testsuite/gas/or1k/reloc-1.d              |   72 ++
 gas/testsuite/gas/or1k/reloc-1.s              |   76 ++
 gas/testsuite/gas/or1k/reloc-2.l              |   11 +
 gas/testsuite/gas/or1k/reloc-2.s              |   13 +
 include/elf/or1k.h                            |   19 +
 ld/testsuite/ld-or1k/offsets1.d               |  212 ++++
 ld/testsuite/ld-or1k/offsets1.s               |   14 +
 ld/testsuite/ld-or1k/or1k.exp                 |   91 ++
 ld/testsuite/ld-or1k/plt1.dd                  |   27 +
 ld/testsuite/ld-or1k/plt1.s                   |   11 +
 ld/testsuite/ld-or1k/plt1.x.dd                |   27 +
 ld/testsuite/ld-or1k/plta1.dd                 |   27 +
 ld/testsuite/ld-or1k/plta1.s                  |   11 +
 ld/testsuite/ld-or1k/pltlib.s                 |   12 +
 opcodes/or1k-asm.c                            |  587 +++++-----
 opcodes/or1k-desc.c                           |   34 +-
 opcodes/or1k-desc.h                           |   48 +-
 opcodes/or1k-dis.c                            |    3 +
 opcodes/or1k-ibld.c                           |   29 +-
 opcodes/or1k-opc.c                            |   44 +-
 opcodes/or1k-opc.h                            |   65 +-
 opcodes/or1k-opinst.c                         |   98 +-
 sim/common/cgen-ops.h                         |   36 +
 sim/or1k/cpu.h                                |   32 +
 sim/or1k/decode.c                             |  239 +++-
 sim/or1k/decode.h                             |   82 +-
 sim/or1k/model.c                              |  186 ++-
 sim/or1k/sem-switch.c                         |  281 ++++-
 sim/or1k/sem.c                                |  293 ++++-
 sim/testsuite/sim/or1k/div.S                  |   12 +-
 sim/testsuite/sim/or1k/mul.S                  |  109 +-
 41 files changed, 3643 insertions(+), 1196 deletions(-)
 rename gas/testsuite/gas/or1k/{allinsn.exp => or1k.exp} (83%)
 create mode 100644 gas/testsuite/gas/or1k/reloc-1.d
 create mode 100644 gas/testsuite/gas/or1k/reloc-1.s
 create mode 100644 gas/testsuite/gas/or1k/reloc-2.l
 create mode 100644 gas/testsuite/gas/or1k/reloc-2.s
 create mode 100644 ld/testsuite/ld-or1k/offsets1.d
 create mode 100644 ld/testsuite/ld-or1k/offsets1.s
 create mode 100644 ld/testsuite/ld-or1k/or1k.exp
 create mode 100644 ld/testsuite/ld-or1k/plt1.dd
 create mode 100644 ld/testsuite/ld-or1k/plt1.s
 create mode 100644 ld/testsuite/ld-or1k/plt1.x.dd
 create mode 100644 ld/testsuite/ld-or1k/plta1.dd
 create mode 100644 ld/testsuite/ld-or1k/plta1.s
 create mode 100644 ld/testsuite/ld-or1k/pltlib.s
Signature · 1 line
2.17.1
#6 lore raw

cover OpenRISC binutils updates and new relocs

Hi Stafford,

Quoted 2 lines

Does anyone have concerns with these patches? Mostly they are for openrisc parts only.

Sorry for the long silence - I have been very busy of late.

The patch series looks basically fine to me, so I have no concerns there. There are a few minor formatting glitches, but nothing serious.

I do not see any need to add extra document for the new relocs, unless you have created new assembler pseudo-ops to generate them. (I did not see any code to add such operators, but I may have missed something).

I do have one question though. Is there a need to be able to distinguish between binaries that use the new l.adrp instruction and those that don't. For example if a library is built using the new instruction but then it is linked into an executable which is supposed to run on silicon which does not support the new instruction, should the linker issue an error ? If so, how does it detect this situation ?

Cheers
Nick

#7 lore raw

cover OpenRISC binutils updates and new relocs

Quoted 3 lines · Nick Clifton

I do not see any need to add extra document for the new relocs, unless you have created new assembler pseudo-ops to generate them. (I did not see any code to add such operators, but I may have missed something).

There is new syntax for these new relocs, in the form of function-like markup.

E.g:

l.ori r3,r4, at lo(foo) # an existing reloc
l.ori r3,r4, at po(foo) # a new reloc added here

Quoted 6 lines

I do have one question though. Is there a need to be able to distinguish between binaries that use the new l.adrp instruction and those that don't. For example if a library is built using the new instruction but then it is linked into an executable which is supposed to run on silicon which does not support the new instruction, should the linker issue an error ? If so, how does it detect this situation ?

I have never been a fan of how this is handled e.g. for mips. To that end, I have done nothing at all. This is more in line with how we (do not) handle this situation for x86.

r~

#8 lore raw

cover OpenRISC binutils updates and new relocs

In reply to Nick Clifton
Quoted 9 lines · Nick Clifton

Hi Stafford,

Quoted 2 lines

Does anyone have concerns with these patches? Mostly they are for openrisc parts only.

Sorry for the long silence - I have been very busy of late.

The patch series looks basically fine to me, so I have no concerns there. There are a few minor formatting glitches, but nothing serious.

Will you be able to point them out? Even just some hints? We have tried to follow conventions, but there might be some missed spots. I will go over everything again just in case and run any formatting tools I have, but any tips will be helpful.

Quoted 3 lines

I do not see any need to add extra document for the new relocs, unless you have created new assembler pseudo-ops to generate them. (I did not see any code to add such operators, but I may have missed something).

As Richard mentioned we have added a few, see PATCH 3/4 in cpu/or1k.opc the change:

(parse_reloc): Add new po(), gotpo() and gottppo() for LO13 relocations.

Is this what you mean? I will look into adding the documentation for these.

Quoted 6 lines

I do have one question though. Is there a need to be able to distinguish between binaries that use the new l.adrp instruction and those that don't. For example if a library is built using the new instruction but then it is linked into an executable which is supposed to run on silicon which does not support the new instruction, should the linker issue an error ? If so, how does it detect this situation ?

As Richard mentioned we don't handle this.

We have cases like this right now as well, i.e. binaries generated with l.mul or l.div instructions will link fine into an executable that assume those instrunctions should be emulated. That doesn't throw an error and I don't think it has been a problem.

-Stafford

#9 lore raw

cover OpenRISC binutils updates and new relocs

Hi Stafford,

Quoted 3 lines
Quoted 1 line

There are a few minor formatting glitches, but nothing serious.

Will you be able to point them out? Even just some hints?

Sure...

So for example in patch 1/4 there is:

+enum {
+ RTYPE_LO = 0,

when really it should be:

+enum
+{
+ RTYPE_LO = 0,

(And similarly in other places. Basically, try to avoid ending a line with an opening curly brace, unless that brace is the only character on the line).

Then there is:

+static int
+parse_reloc(const char **strp)

Which ought to be:

+static int
+parse_reloc (const char **strp)

Ie - a single space between the function name and its parameters. (I did say that these were minor formatting nits...) In a similar vein there is:

+ return parse_imm16(cd, strp, opindex, (long *) valuep, 0); +}

which also needs a space between the function name and its arguments.

There are a few other cases of the above issues in the other patches, but nothing else of note.

One other thing: There are several places where you add calls to abort(). Now this is not wrong, and certainly not a reason to reject the patch, but I consider it to be unhelpful. To my mind a library, or tool, should generate an error message when something goes wrong and not leave the user wondering why they have suddenly got a segmentation fault.

Plus if you have a call to abort() in the code you can bet that some enterprising person with a binary fuzzer will find a way to trigger it, and then file a CVE about it. (Fixing CVEs is the bane of my life as they involve lots of extra administrivia).

Quoted 9 lines
Quoted 2 lines

I do not see any need to add extra document for the new relocs, unless you have created new assembler pseudo-ops to generate them.

As Richard mentioned we have added a few, see PATCH 3/4 in cpu/or1k.opc the change:

(parse_reloc): Add new po(), gotpo() and gottppo() for LO13 relocations.

Is this what you mean? I will look into adding the documentation for these.

Please do. Most likely you will want to create a gas/doc/c-or1k.c file, (copying the contents from another, similar file and modifying as needed), and then patch the gas/doc/as.texi file to include it and the gas/doc/all.texi file to define a macro for it.

Quoted 9 lines
Quoted 2 lines

I do have one question though. Is there a need to be able to distinguish between binaries that use the new l.adrp instruction and those that don't.

As Richard mentioned we don't handle this.

We have cases like this right now as well, i.e. binaries generated with l.mul or l.div instructions will link fine into an executable that assume those instrunctions should be emulated. That doesn't throw an error and I don't think it has been a problem.

OK, well it is your target, so if you are OK with this then so be it. I would recommend however thinking about a solution for the future, should the openRISC architecture gain more variants. My suggestion would be to make use of ELF notes, as has been done with other ports.

Cheers
Nick

#10 lore raw

cover OpenRISC binutils updates and new relocs

Quoted 95 lines · Nick Clifton

Hi Stafford,

Quoted 3 lines
Quoted 1 line

There are a few minor formatting glitches, but nothing serious.

Will you be able to point them out? Even just some hints?

Sure...

So for example in patch 1/4 there is:

+enum {
+ RTYPE_LO = 0,

when really it should be:

+enum
+{
+ RTYPE_LO = 0,

(And similarly in other places. Basically, try to avoid ending a line with an opening curly brace, unless that brace is the only character on the line).

Then there is:

+static int
+parse_reloc(const char **strp)

Which ought to be:

+static int
+parse_reloc (const char **strp)

Ie - a single space between the function name and its parameters. (I did say that these were minor formatting nits...) In a similar vein there is:

+ return parse_imm16(cd, strp, opindex, (long *) valuep, 0); +}

which also needs a space between the function name and its arguments.

There are a few other cases of the above issues in the other patches, but nothing else of note.

One other thing: There are several places where you add calls to abort(). Now this is not wrong, and certainly not a reason to reject the patch, but I consider it to be unhelpful. To my mind a library, or tool, should generate an error message when something goes wrong and not leave the user wondering why they have suddenly got a segmentation fault.

Plus if you have a call to abort() in the code you can bet that some enterprising person with a binary fuzzer will find a way to trigger it, and then file a CVE about it. (Fixing CVEs is the bane of my life as they involve lots of extra administrivia).

Quoted 1 line
Quoted 1 line

I do not see any need to add extra document for the new relocs, unless

you

Quoted 3 lines
Quoted 1 line

have created new assembler pseudo-ops to generate them.

As Richard mentioned we have added a few, see PATCH 3/4 in cpu/or1k.opc

the

Quoted 3 lines

change:

(parse_reloc): Add new po(), gotpo() and gottppo() for LO13

relocations.

Quoted 2 lines

Is this what you mean? I will look into adding the documentation for

these.

Please do. Most likely you will want to create a gas/doc/c-or1k.c file, (copying the contents from another, similar file and modifying as needed), and
then patch the gas/doc/as.texi file to include it and the gas/doc/all.texi file
to define a macro for it.

Quoted 1 line
Quoted 1 line

I do have one question though. Is there a need to be able to

distinguish

Quoted 1 line
Quoted 1 line

between binaries that use the new l.adrp instruction and those that

don't.

Quoted 3 lines

As Richard mentioned we don't handle this.

We have cases like this right now as well, i.e. binaries generated with

l.mul

Quoted 1 line

or l.div instructions will link fine into an executable that assume

those

Quoted 1 line

instrunctions should be emulated. That doesn't throw an error and I

don't think

Quoted 9 lines
Quoted 1 line

it has been a problem.

OK, well it is your target, so if you are OK with this then so be it. I would recommend however thinking about a solution for the future, should the
openRISC architecture gain more variants. My suggestion would be to make use
of ELF notes, as has been done with other ports.

Is there a way to avoid these instructions with GCC? As a general rule, for RTEMS we assume the code is properly generated for the target CPU and don't emulate missing instructions.

Also for these cases, is there a flag implicitly set by GCC based on CPU specific flags to let assembly code.know not to use them.

And are there mulilibs which do and do not use them?

In the deeply embedded space, we assume the tools and user can generate code which doesn't need emulation traps. There is some responsibility on the toolchain to.make it possible.

Thanks.

--joel

Quoted 6 lines

Cheers
Nick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.librecores.org/pipermail/openrisc/attachments/20180918/3f16dea6/attachment-0001.html>

#11 lore raw

cover OpenRISC binutils updates and new relocs

Hi Joel,

Quoted 23 lines · Joel Sherrill
Quoted 9 lines · Nick Clifton
Quoted 4 lines

As Richard mentioned we don't handle this.

We have cases like this right now as well, i.e. binaries generated with

l.mul

Quoted 1 line

or l.div instructions will link fine into an executable that assume

those

Quoted 1 line

instrunctions should be emulated. That doesn't throw an error and I

don't think

Quoted 9 lines
Quoted 1 line

it has been a problem.

OK, well it is your target, so if you are OK with this then so be it. I would recommend however thinking about a solution for the future, should the
openRISC architecture gain more variants. My suggestion would be to make use
of ELF notes, as has been done with other ports.

Quoted 9 lines

Is there a way to avoid these instructions with GCC? As a general rule, for RTEMS we assume the code is properly generated for the target CPU and don't emulate missing instructions.

Also for these cases, is there a flag implicitly set by GCC based on CPU specific flags to let assembly code.know not to use them.

And are there mulilibs which do and do not use them?

To answer all, yes. There were some recent openrisc mailing list discussions on this. I have decided to add a new multilib flag -mclass1 -mclass2 (default is mclass1 instructions only) to stop gcc from using any class2 instructions.

Quoted 4 lines

In the deeply embedded space, we assume the tools and user can generate code which doesn't need emulation traps. There is some responsibility on the toolchain to.make it possible.

Yes, We did think about this when we were writing the new port, but we are only just implementing it now. Check the GCC docs in the next patch version I submit.

-Stafford
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.librecores.org/pipermail/openrisc/attachments/20180921/c56779cd/attachment.html>

#12 lore raw

cover OpenRISC binutils updates and new relocs

In reply to Nick Clifton
Quoted 37 lines · Nick Clifton

Hi Stafford,

Quoted 3 lines
Quoted 1 line

There are a few minor formatting glitches, but nothing serious.

Will you be able to point them out? Even just some hints?

Sure...

So for example in patch 1/4 there is:

+enum {
+ RTYPE_LO = 0,

when really it should be:

+enum
+{
+ RTYPE_LO = 0,

(And similarly in other places. Basically, try to avoid ending a line with an opening curly brace, unless that brace is the only character on the line).

Then there is:

+static int
+parse_reloc(const char **strp)

Which ought to be:

+static int
+parse_reloc (const char **strp)

Ie - a single space between the function name and its parameters. (I did say that these were minor formatting nits...) In a similar vein there is:

Quoted 7 lines

+ return parse_imm16(cd, strp, opindex, (long *) valuep, 0); +}

which also needs a space between the function name and its arguments.

There are a few other cases of the above issues in the other patches, but nothing else of note.

Ack on the braces and function spaces. I will clean those up.

Quoted 11 lines

One other thing: There are several places where you add calls to abort(). Now this is not wrong, and certainly not a reason to reject the patch, but I consider it to be unhelpful. To my mind a library, or tool, should generate an error message when something goes wrong and not leave the user wondering why they have suddenly got a segmentation fault.

Plus if you have a call to abort() in the code you can bet that some enterprising person with a binary fuzzer will find a way to trigger it, and then file a CVE about it. (Fixing CVEs is the bane of my life as they involve lots of extra administrivia).

OK, I will fix those too.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I do not see any need to add extra document for the new relocs, unless you have created new assembler pseudo-ops to generate them.

As Richard mentioned we have added a few, see PATCH 3/4 in cpu/or1k.opc the change:

Quoted 8 lines
Quoted 3 lines

(parse_reloc): Add new po(), gotpo() and gottppo() for LO13 relocations.

Is this what you mean? I will look into adding the documentation for these.

Please do. Most likely you will want to create a gas/doc/c-or1k.c file, (copying the contents from another, similar file and modifying as needed), and then patch the gas/doc/as.texi file to include it and the gas/doc/all.texi file to define a macro for it.

Sure I will do that.

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

I do have one question though. Is there a need to be able to distinguish between binaries that use the new l.adrp instruction and those that don't.

As Richard mentioned we don't handle this.

We have cases like this right now as well, i.e. binaries generated with l.mul or l.div instructions will link fine into an executable that assume those instrunctions should be emulated. That doesn't throw an error and I don't think it has been a problem.

Quoted 4 lines

OK, well it is your target, so if you are OK with this then so be it. I would recommend however thinking about a solution for the future, should the openRISC architecture gain more variants. My suggestion would be to make use of ELF notes, as has been done with other ports.

Thanks, I will keep that in mind.

-Stafford

#13 lore raw

cover OpenRISC binutils updates and new relocs

In reply to Nick Clifton

Hi Nick,

Quoted 11 lines · Nick Clifton

One other thing: There are several places where you add calls to abort(). Now this is not wrong, and certainly not a reason to reject the patch, but I consider it to be unhelpful. To my mind a library, or tool, should generate an error message when something goes wrong and not leave the user wondering why they have suddenly got a segmentation fault.

Plus if you have a call to abort() in the code you can bet that some enterprising person with a binary fuzzer will find a way to trigger it, and then file a CVE about it. (Fixing CVEs is the bane of my life as they involve lots of extra administrivia).

I have been away the last week and am just getting to fixing these abort()'s now. However, I have a question.

The aborts I see are:

bfd/elf32-or1k.c (or1k_final_link_relocate) - 2 places cpu/or1k-asm.c (parse_imm16) - 1 place

In these cases we call abort if a switch statement falls through to the default case. If we get an abort its definitely a bug.

To produce these errors I need to change the code, Using abort we see:

   /home/shorne/work/gnu-toolchain/local/lib/gcc/or1k-elf/9.0.0/../../../../or1k-elf/bin/ld: \
      BFD (GNU Binutils) 2.31.51.20180927 internal error, \
      aborting at ../../binutils-gdb/bfd/elf32-or1k.c:1152 in or1k_final_link_relocate

/home/shorne/work/gnu-toolchain/local/lib/gcc/or1k-elf/9.0.0/../../../../or1k-elf/bin/ld: \
Please report this bug.

collect2: error: ld returned 1 exit status

There is no segmentation fault. I agree, it is more nice to create a message inform which error triggered the issue.

Is something like this ok?

    default:
      _bfd_error_handler
	(_("%pB: Unknown complain on overflow value on howto specified %d"),
	 input_bfd, (int) howto->complain_on_overflow);
      abort();

i.e. _bfd_error_handler() followed by abort(). I couldn't really see a way to _bfd_error_handler() to actually cause the program to exit.

-Stafford

#14 lore raw

cover OpenRISC binutils updates and new relocs

Hi Stafford,

Quoted 7 lines

To produce these errors I need to change the code, Using abort we see:

   /home/shorne/work/gnu-toolchain/local/lib/gcc/or1k-elf/9.0.0/../../../../or1k-elf/bin/ld: \
      BFD (GNU Binutils) 2.31.51.20180927 internal error, \
      aborting at ../../binutils-gdb/bfd/elf32-or1k.c:1152 in or1k_final_link_relocate

There is no segmentation fault.

Sorry, you are right - the abort does not trigger a segmentation fault.

Quoted 5 lines

I agree, it is more nice to create a message
inform which error triggered the issue.

Is something like this ok?

Quoted 8 lines
    default:
      _bfd_error_handler
	(_("%pB: Unknown complain on overflow value on howto specified %d"),
	 input_bfd, (int) howto->complain_on_overflow);
      abort();

i.e. _bfd_error_handler() followed by abort(). I couldn't really see a way to _bfd_error_handler() to actually cause the program to exit.

Depending upon where you are in your code, if you have access to the link_info structure you can use its einfo() routine instead of bfd_error_handler. This has the advantage that it allows a %X formatting directive, which causes the program to terminate with an error exit code.

But otherwise, if there is no reasonable way to return to the caller, then caryr on using abort. Adding the error messages still helps though.

Cheers
Nick

#15 lore raw

cover OpenRISC binutils updates and new relocs

Quoted 7 lines · Nick Clifton
Quoted 6 lines

To produce these errors I need to change the code, Using abort we see:

   /home/shorne/work/gnu-toolchain/local/lib/gcc/or1k-elf/9.0.0/../../../../or1k-elf/bin/ld: \
      BFD (GNU Binutils) 2.31.51.20180927 internal error, \
      aborting at ../../binutils-gdb/bfd/elf32-or1k.c:1152 in or1k_final_link_relocate

[...]

Quoted 4 lines

Depending upon where you are in your code, if you have access to the link_info structure you can use its einfo() routine instead of bfd_error_handler. This has the advantage that it allows a %X formatting directive, which causes the program to terminate with an error exit code.

OK, thanks for the info. I tested it out using einfo(), it does exit with an error code, but it doesn't produce the line numbers and function name that abort() gives us. I am sure I could make it do it, but for now I will use the error message + abort() as it gives me what I would want to see in a bug report :).

V2 of the patch should be coming up soon.

-Stafford