binutils-gdb/cpu
Jose E. Marchesi e9bffec9af opcodes: discriminate endianness and insn-endianness in CGEN ports
The CGEN support code in opcodes accesses instruction contents using a
couple of functions defined in cgen-opc.c: cgen_get_insn_value and
cgen_put_insn_value.  These functions use the "instruction endianness"
in the CPU description to order the read/written bytes.

The process of writing an instruction to the object file is:

  a) cgen_put_insn_value        ;; Writes out the opcodes.
  b) ARCH_cgen_insert_operand
       insert_normal
         insert_1
           cgen_put_insn_value  ;; Writes out the bytes of the
                                ;; operand.

Likewise, the process of reading an instruction from the object file
is:

  a) cgen_get_insn_value        ;; Reads the opcodes.
  b) ARCH_cgen_extract_operand
       extract_normal
         extract_1
           cgen_get_insn_value  ;; Reads in the bytes of the
                                ;; operand.

As can be seen above, cgen_{get,put}_insn_value are used to both
process the instruction opcodes (the constant fields conforming the
base instruction) and also the values of the instruction operands,
such as immediates.

This is problematic for architectures in which the endianness of
instructions is different to the endianness of data.  An example is
BPF, where instructions are always encoded big-endian but the data may
be either big or little.

This patch changes the cgen_{get,put}_insn_value functions in order to
get an extra argument with the endianness to use, and adapts the
existin callers to these functions in order to provide cd->endian or
cd->insn_endian, whatever appropriate.  Callers like extract_1 and
insert_1 pass cd->endian (since they are reading/writing operand
values) while callers reading/writing the base instruction pass
cd->insn_endian instead.

A few little adjustments have been needed in some existing CGEN based
ports:
* The BPF assembler uses cgen_put_insn_value.  It has been adapted to
  pass the new endian argument.
* The mep port has code in mep.opc that uses cgen_{get,put}_insn_value.
  It has been adapted to pass the new endianargument.  Ditto for a
  call in the assembler.

Tested with --enable-targets=all.
Regested in all supported targets.
No regressions.

include/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* opcode/cgen.h: Get an `endian' argument in both
	cgen_get_insn_value and cgen_put_insn_value.

opcodes/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* cgen-opc.c (cgen_get_insn_value): Get an `endian' argument.
	(cgen_put_insn_value): Likewise.
	(cgen_lookup_insn): Pass endianness to cgen_{get,put}_insn_value.
	* cgen-dis.in (print_insn): Likewise.
	* cgen-ibld.in (insert_1): Likewise.
	(insert_1): Likewise.
	(insert_insn_normal): Likewise.
	(extract_1): Likewise.
	* bpf-dis.c: Regenerate.
	* bpf-ibld.c: Likewise.
	* bpf-ibld.c: Likewise.
	* cgen-dis.in: Likewise.
	* cgen-ibld.in: Likewise.
	* cgen-opc.c: Likewise.
	* epiphany-dis.c: Likewise.
	* epiphany-ibld.c: Likewise.
	* fr30-dis.c: Likewise.
	* fr30-ibld.c: Likewise.
	* frv-dis.c: Likewise.
	* frv-ibld.c: Likewise.
	* ip2k-dis.c: Likewise.
	* ip2k-ibld.c: Likewise.
	* iq2000-dis.c: Likewise.
	* iq2000-ibld.c: Likewise.
	* lm32-dis.c: Likewise.
	* lm32-ibld.c: Likewise.
	* m32c-dis.c: Likewise.
	* m32c-ibld.c: Likewise.
	* m32r-dis.c: Likewise.
	* m32r-ibld.c: Likewise.
	* mep-dis.c: Likewise.
	* mep-ibld.c: Likewise.
	* mt-dis.c: Likewise.
	* mt-ibld.c: Likewise.
	* or1k-dis.c: Likewise.
	* or1k-ibld.c: Likewise.
	* xc16x-dis.c: Likewise.
	* xc16x-ibld.c: Likewise.
	* xstormy16-dis.c: Likewise.
	* xstormy16-ibld.c: Likewise.

gas/ChangeLog:

2020-06-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* cgen.c (gas_cgen_finish_insn): Pass the endianness to
	cgen_put_insn_value.
	(gas_cgen_md_apply_fix): Likewise.
	(gas_cgen_md_apply_fix): Likewise.
	* config/tc-bpf.c (md_apply_fix): Pass data endianness to
	cgen_put_insn_value.
	* config/tc-mep.c (mep_check_ivc2_scheduling): Pass endianness to
	cgen_put_insn_value.

cpu/ChangeLog:

2020-06-02  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* mep.opc (print_slot_insn): Pass the insn endianness to
	cgen_get_insn_value.
2020-06-04 16:17:42 +02:00
..
ChangeLog opcodes: discriminate endianness and insn-endianness in CGEN ports 2020-06-04 16:17:42 +02:00
bpf.cpu cpu,opcodes: add instruction semantics to bpf.cpu and minor fixes 2020-05-28 21:52:31 +02:00
bpf.opc cpu,opcodes: add instruction semantics to bpf.cpu and minor fixes 2020-05-28 21:52:31 +02:00
cris.cpu update copyright dates 2009-09-02 07:25:43 +00:00
epiphany.cpu Remove more shifts for sign/zero extension 2019-12-11 21:14:19 +10:30
epiphany.opc epiphany/disassembler: Improve alignment of output. 2016-02-02 11:09:17 +00:00
fr30.cpu ubsan: fr30: left shift of negative value 2020-01-13 12:12:05 +10:30
fr30.opc Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
frv.cpu ubsan: frv: left shift of negative value 2020-02-01 23:23:18 +10:30
frv.opc opcodes error messages 2018-03-03 11:34:26 +10:30
ip2k.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
ip2k.opc Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
iq10.cpu update copyright dates 2009-09-02 07:25:43 +00:00
iq2000.cpu ubsan: iq2000: left shift of negative value 2019-12-23 18:04:12 +10:30
iq2000.opc update copyright dates 2009-09-02 07:25:43 +00:00
iq2000m.cpu update copyright dates 2009-09-02 07:25:43 +00:00
lm32.cpu Remove more shifts for sign/zero extension 2019-12-11 21:14:19 +10:30
lm32.opc update copyright dates 2009-09-02 07:25:43 +00:00
m32c.cpu ubsan: m32c: left shift of negative value 2020-02-03 15:59:08 +10:30
m32c.opc * m32c.opc (parse_signed16): Fix typo. 2010-01-02 18:37:59 +00:00
m32r.cpu ubsan: m32r: left shift of negative value 2020-01-04 19:20:33 +10:30
m32r.opc * m32r.cpu (HASH-PREFIX): Delete. 2010-02-12 04:38:21 +00:00
mep-avc.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-avc2.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-c5.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-core.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-default.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-ext-cop.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-fmax.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-h1.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-ivc2.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-rhcop.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep-sample-ucidsp.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep.cpu Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00
mep.opc opcodes: discriminate endianness and insn-endianness in CGEN ports 2020-06-04 16:17:42 +02:00
mt.cpu update copyright dates 2009-09-02 07:25:43 +00:00
mt.opc cpu/ 2012-02-27 06:57:57 +00:00
or1k.cpu or1k: Remove 64-bit support, it's not used and it breaks 32-bit hosts 2020-05-19 20:40:27 +09:00
or1k.opc cpu/or1k: Add support for orfp64a32 spec 2019-06-13 06:16:18 +09:00
or1kcommon.cpu or1k: Remove 64-bit support, it's not used and it breaks 32-bit hosts 2020-05-19 20:40:27 +09:00
or1korbis.cpu ubsan: or1k: left shift of negative value 2019-12-20 17:57:58 +10:30
or1korfpx.cpu or1k: Remove 64-bit support, it's not used and it breaks 32-bit hosts 2020-05-19 20:40:27 +09:00
sh.cpu update copyright dates 2009-09-02 07:25:43 +00:00
sh.opc update copyright dates 2009-09-02 07:25:43 +00:00
sh64-compact.cpu update copyright dates 2009-09-02 07:25:43 +00:00
sh64-media.cpu update copyright dates 2009-09-02 07:25:43 +00:00
simplify.inc * cpu/simplify.inc (*): One line doc strings don't need \n. 2009-07-16 17:53:25 +00:00
xc16x.cpu * m32r.cpu (HASH-PREFIX): Delete. 2010-02-12 04:38:21 +00:00
xc16x.opc * m32r.cpu (HASH-PREFIX): Delete. 2010-02-12 04:38:21 +00:00
xstormy16.cpu ubsan: xstormy16: left shift of negative value 2019-12-16 17:35:13 +10:30
xstormy16.opc Move cpu files from cgen/cpu to top level cpu directory. 2011-08-22 15:25:07 +00:00