Commit Graph

4180 Commits

Author SHA1 Message Date
Mike Frysinger
8ea881d9e3 sim: mips: fix build w/out dv-sockser
Make sure we don't fail to build when dv-socker is unavailable.
2021-05-29 15:29:54 -04:00
Mike Frysinger
67514280fc sim: frv: fix up a bunch of prototype warnings
Some were missing, some were unused, and some were partially renamed.
2021-05-29 13:10:42 -04:00
Mike Frysinger
fc12ae4215 sim: frv: fix compiler parentheses suggestions warnings
Newer gcc warns when writing statements like (a && b || c && d),
so add more parentheses to make it (and the reader) happy.
2021-05-29 13:07:34 -04:00
Mike Frysinger
cd7caae651 sim: sh: fix a few compiler warnings 2021-05-29 13:06:26 -04:00
Mike Frysinger
80e61ea097 sim: m32c: rename open symbol to avoid collisions
If the header files define open(), make sure our local open var
doesn't shadow it.
2021-05-29 12:03:27 -04:00
Mike Frysinger
5c9e84c2d8 sim: leverage gnulib
We use getline, so leverage gnulib to provide fallback implementation.
2021-05-29 11:56:43 -04:00
Mike Frysinger
f006d9e205 sim: bfin: fix the otp fix fix
Need to shift the upper 32-bits and not just combine directly with
the lower 32-bits.
2021-05-28 23:31:24 -04:00
Yoshinori Sato
9d7c4ba5e5 sim: h8300 add special case test.
* addb.s: Add special case reg,<@reg+ / @reg- / @+reg / @-reg>.
* andb.s: Likewise.
* cmpb.s: Likewise.
* orb.s: Likewise.
* subb.s: Likewise.
* xorb.s: Likewise.
* movb.s: Add special case reg,<@reg+ / @reg- / @+reg / @-reg>
          @reg+,@reg+ / @-reg,@-reg.
* movw.s: Likewise.
* movl.s: Likewise.
2021-05-28 21:14:24 +09:00
Yoshinori Sato
0ef4c3f83b sim: h8300 Fixed different behavior in preinc/predec.
* sim-main.h (h8_typecodes): Add operand type OP_REG_DEC, OP_REG_INC.
* compile.c (decode): Rewrite oprand type for specific case.
(fetch_1): Add handling OP_REG_DEC and OP_REG_INC.
(step_once): Fix operand fetch order.
2021-05-28 21:14:24 +09:00
Mike Frysinger
5471128011 opcodes: cris: move desc & opc files from sim/
All other cgen ports keep their generated desc & opc files under
opcodes/, so move the cris files over too.  The cris-opc.c file,
while not generated, is already here to complement.
2021-05-24 18:42:34 -04:00
Mike Frysinger
d16ce6e4d5 sim: cris: fix memory setup typos
The cleanup to use BFD_VMA_FMT also adjusted this line, but used the
incorrect format: while BFD_VMA_FMT needs an explicit "x", PRIx32 does
not, so the spurious "x" here confused the parser and broke execution.
2021-05-23 23:43:37 -04:00
Mike Frysinger
d699be882b sim: bfin: fix the otp fix
I misread the code and thought data0/... were bu64 when they were
actually bu32.  Fix the call to assemble the 2 64-bit values instead
of passing the 2 halves of the first 64-bit value.
2021-05-23 22:16:13 -04:00
Mike Frysinger
3cc4ee83ad sim: bfin: fix build warnings w/newer gcc
The bfin_otp_write_page_val func wants a pointer to an bu64[2] array,
but this code passes it a pointer to a single bu64.  It's in a struct
with a known compatible layout:
	bu64 data0, data1, data2, data3;
But gcc doesn't allow these kinds of tricks anymore.  Use the more
verbose form to make the compiler happy since this is not performance
sensitive code.
2021-05-23 21:37:31 -04:00
Mike Frysinger
9a28444faa sim: rl78: rename open symbol to avoid collisions
If the header files define open(), make sure our local open var
doesn't shadow it.
2021-05-23 17:40:32 -04:00
Mike Frysinger
e82a36be9a sim: cris: add unistd.h for environ decl
We include environ.h for the fallback, but we still need to include
unistd.h in case it provides it as gnulib will detect.
2021-05-23 17:39:16 -04:00
Mike Frysinger
01d3ae40df sim: bfin: add strings.h for ffs() 2021-05-23 17:36:29 -04:00
Faraz Shahbazker
168671c14c sim: mips: Add shadow mappings for 32-bit memory address space
32-bit MIPS programs run on the 64-bit simulator model in 64-bit
sign-extended space. The mapping from 64-bit sign-extended addresses to
32-bit addresses was removed by commit
26f8bf63bf, breaking the 64-bit simulator
model. Add shadow mappings from 64-bit sign extended address space to
32-bit address spaces, in lieu of the AddressTranslation function.

2021-05-04  Faraz Shahbazker  <fshahbazker@wavecomp.com>

sim/mips/ChangeLog:
	* interp.c (sim_open): Add shadow mappings from 32-bit
	address space to 64-bit sign-extended address space.
2021-05-22 11:32:35 +05:30
Faraz Shahbazker
b312488f10 sim: mips: Only truncate sign extension bits for 32-bit target models
64-bit BFD for MIPS applies a standard sign extension on all addresses
assuming 64-bit target.  These bits are required for 64-bit and can only
be safely truncated for 32-bit target models. This partially reverts commit
b36d953bce

The sign-extension logic modeled by BFD is an integral part of the
MIPS64 architecture spec. It appears in the virtual address map, where
sign extension allows for 32-bit compatibility segments [1] with 64-bit
addressing. Truncating these addresses prematurely (commit
models (-DWITH_TARGET_WORD_BITSIZE=64).

In the ISA itself, direct addressing (Load-Upper-Immediate) and indirect
addressing (Load-Word) both automatically sign-extend their results. These
instructions regenerate the sign-extended addresses even if we don't start
with one (see pr gdb/19447).

Moreover, some instructions like ADD*/SUB* have unpredictable behaviour when
an operand is not correctly sign extended [3]. This affects PC-relative
addressing in particular, so arithmetic on the link-address generated in the
return address register by a jump-and-link is no longer possible, neither is
the use of the PC-relative addressing instructions provided by MIPSR6.

[1] "MIPS64 Architecture for Programmers Volume III: The MIPS64
    Privileged Resource Architecture", Document Number: MD00091,
    Revision 6.02, December 10, 2015, Section 4.3 "Virtual Address
    Spaces", pp. 29-31
https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00091-2B-MIPS64PRA-AFP-06.03.pdf

[2] "MIPS64 Architecture for Programmers Volume II-A: The MIPS64
    Instruction Set Reference Manual", Document Number: MD00087,
    Revision 6.06, December 15, 2016, Section 3.2 "Alphabetical
    List of Instructions", pp. 321
https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00087-2B-MIPS64BIS-AFP-6.06.pdf

[3] "MIPS64 Architecture for Programmers Volume II-A: The MIPS64
    Instruction Set Reference Manual", Document Number: MD00087,
    Revision 6.06, December 15, 2016, Section 3.2 "Alphabetical
    List of Instructions", pp. 56
https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00087-2B-MIPS64BIS-AFP-6.06.pdf

2021-04-23  Faraz Shahbazker  <fshahbazker@wavecomp.com>

sim/mips/ChangeLog:
	* interp.c (sim_create_inferior): Only truncate sign extension
	bits for 32-bit target models
.
2021-05-22 11:30:57 +05:30
John Baldwin
39549caef4 sim/d10v: Use offsetof in a static assertion about structure layout.
clang 11 fails to compile the static assertion as it cannot compute
the pointer value at a compile time:

gdb/sim/d10v/interp.c:1149:37: error: static_assert expression is not an integral constant expression
  static_assert ((uintptr_t) &State == (uintptr_t) &State.regs,
                 ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Instead, assert that the offset of State.regs is 0.

sim/d10v/ChangeLog:

	* interp.c (sim_create_inferior): Use offsetof in static
	assertion.
2021-05-21 17:27:05 -07:00
Tom de Vries
8baee38bfe sim: ppc: fix Wpointer-sign warning
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
src/sim/ppc/hw_memory.c: In function 'hw_memory_init_address':
src/sim/ppc/hw_memory.c:194:75: error: pointer targets in passing \
  argument 4 of 'device_find_integer_array_property' differ in signedness \
  [-Werror=pointer-sign]
     int nr_cells
       = device_find_integer_array_property(me, "available", 0, &dummy);
                                                                ^
...

Fix this by changing the type of dummy.
2021-05-20 13:58:35 +02:00
Tom de Vries
17bb1d80f5 sim: ppc: fix some Wenum-compare warnings
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
src/sim/ppc/hw_phb.c: In function 'hw_phb_attach_address':
src/sim/ppc/hw_phb.c:315:12: error: comparison between \
  'attach_type {aka enum _attach_type}' and \
  'enum <anonymous>' [-Werror=enum-compare]
   if (type != hw_phb_normal_decode
            ^~
...

Fix this by casting type to hw_phb_decode.
2021-05-19 19:08:53 +02:00
Tom de Vries
bfff0efb3d sim: ppc: fix Wnonnull warning
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
src/sim/ppc/emul_netbsd.c: In function 'do_gettimeofday':
src/sim/ppc/emul_netbsd.c:770:16: error: null argument where non-null \
  required (argument 1) [-Werror=nonnull]
   int status = gettimeofday((t_addr != 0 ? &t : NULL),
                ^~~~~~~~~~~~
...

Fix this by unconditionally passing &t as first argument.
2021-05-19 18:42:59 +02:00
Tom de Vries
4156e38676 sim: ppc: fix some more Wunused-function warnings
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
In file included from src/sim/ppc/cpu.h:26:0,
                 from src/sim/ppc/mon.c:25,
                 from src/sim/ppc/inline.c:64,
                 from idecode.c:26:
src/sim/ppc/device.h:788:8: error: 'device_event_queue_deschedule' \
  declared 'static' but never defined [-Werror=unused-function]
 (void) device_event_queue_deschedule
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

This seems to be caused by the fact that the function is declared using
INLINE_EVENT instead of INLINE_DEVICE.

Fix this and a similar error in the same file.
2021-05-19 17:46:24 +02:00
Tom de Vries
8f09aa5ba8 sim: ppc: fix some Wunused-function warnings
When compiling with --enable-werror and CFLAGS="-O0 -g -Wall", we run into:
...
In file included from src/sim/ppc/cpu.h:251:0,
                 from src/sim/ppc/emul_generic.h:24,
                 from src/sim/ppc/emul_generic.c:24:
src/sim/ppc/cpu.c:76:1: error: 'cpu_create' defined but not used \
  [-Werror=unused-function]
 cpu_create(psim *system,
 ^~~~~~~~~~
...

The function is defined as:
...
INLINE_CPU\
(cpu *)
cpu_create(psim *system,
...
which expands to:
...
static cpu * __attribute__((__unused__))
cpu_create(psim *system,
...

The problem is that gcc does not associate the attribute to the function.
I've filed a PR about this ( PR gcc/100670 ), which may or may not be valid.

Work around/fix this by modifying the INLINE_* definitions in inline.h to move
UNUSED to the start such that we have:
...
__attribute__((__unused__)) static cpu *
cpu_create(psim *system,
...
2021-05-19 17:46:24 +02:00
Mike Frysinger
f4fdd84587 sim: fully merge sim_state_base into sim_state
Now that all ports have migrated to the new framework, drop support
for the old sim_state_base layout.
2021-05-17 01:05:08 -04:00
Mike Frysinger
10c23a2c6f sim: riscv: invert sim_state storage 2021-05-17 01:02:09 -04:00
Mike Frysinger
2ad10cb222 sim: h8300: invert sim_state storage 2021-05-17 01:01:08 -04:00
Mike Frysinger
8ea7241cf3 sim: mips: invert sim_state storage 2021-05-17 01:00:08 -04:00
Mike Frysinger
937af0fde5 sim: avr: invert sim_state storage 2021-05-17 00:58:32 -04:00
Mike Frysinger
e106fc358c sim: cgen: invert sim_state storage for cgen ports 2021-05-17 00:46:32 -04:00
Mike Frysinger
85d93de3d8 sim: bfin: invert sim_state storage 2021-05-17 00:43:45 -04:00
Mike Frysinger
383861bd08 sim: invert sim_state storage
Currently all ports have to declare sim_state themselves in their
sim-main.h and then embed the common sim_state_base & sim_cpu in it.
This dynamic makes it impossible to share common object code among
multiple ports because the core data structure is always different.

Let's invert this relationship: common code declares sim_state, and
if the port actually needs state on a per-instance basis, it can use
the new arch_data field for it.  Most ports don't actually use it,
so they don't need to declare anything at all.

This is the first in a series of changes: it adds a define to select
between the old & new layouts, then converts all the ports that don't
need custom state over to the new layout.
2021-05-17 00:42:55 -04:00
Mike Frysinger
92bc001e1f sim: install library header files
We install libsim.a for people to link against, but haven't been
installing the header files to for its API.  Export them!
2021-05-16 22:42:02 -04:00
Mike Frysinger
6df01ab8ab sim: switch config.h usage to defs.h
The defs.h header will take care of including the various config.h
headers.  For now, it's just config.h, but we'll add more when we
integrate gnulib in.

This header should be used instead of config.h, and should be the
first include in every .c file.  We won't rely on the old behavior
where we expected files to include the port's sim-main.h which then
includes the common sim-basics.h which then includes config.h.  We
have a ton of code that includes things before sim-main.h, and it
sometimes needs to be that way.  Creating a dedicated header avoids
the ordering mess and implicit inclusion that shows up otherwise.
2021-05-16 22:38:41 -04:00
Mike Frysinger
79633c125e sim: riscv: move __int128 check to configure 2021-05-16 00:04:17 -04:00
Mike Frysinger
be2bc30f9c sim: ppc: clean up various warnings
A random grab bag of minor fixes to enable -Werror for this port.

Cast address vars to long when the format was using %l.
Use %zu with sizeof operations.
Add const to a bunch of strings.
Trim unused variables.
Fix sizeof call to calculate target storage and not the pointer itself.
2021-05-15 11:00:00 -04:00
Mike Frysinger
c5a2e0123b sim: switch to libiberty environ.h
Drop our compat code and assume environ exists to simplify.
2021-05-15 10:59:19 -04:00
Mike Frysinger
2fbe9507bf sim: callback: convert FS interfaces to 64-bit
Rather than rely on off_t being the right size between the host &
target, have the interface always be 64-bit.  We can figure out if
we need to truncate when actually outputting it to the right target.
2021-05-14 21:16:40 -04:00
Mike Frysinger
00330cd18a sim: callback: convert time interface to 64-bit
PR sim/27705
Rather than rely on time_t being the right size between the host &
target, have the interface always be 64-bit.  We can figure out if
we need to truncate when actually outputting it to the right target.
2021-05-14 21:05:36 -04:00
Mike Frysinger
64654371d6 sim: callback: inline PTR define
We require C11 now, so no need for these pre-ANSI C hacks.
PTR is simply void*, so use that directly.
2021-05-14 01:23:06 -04:00
Mike Frysinger
df68e12b3b sim: create header namespace
The gdb/callback.h & gdb/remote-sim.h headers have nothing to do with
gdb and are really definitions for the libsim API under the sim/ tree.
While gdb uses those headers as a client, it's not specific to it.  So
create a new sim/ namespace and move the headers there.
2021-05-14 00:41:05 -04:00
Mike Frysinger
425b0b1a98 sim: clean up explicit environment build calls
This was enabled by default for all targets, but a few ports still
include an explicit call.  Clean that up, and update the docs.
2021-05-12 00:47:49 -04:00
Luis Machado
e7e40cedbb Fix build failure in d10v sim
While building all targets on Ubuntu 20.04/aarch64, I ran into the following
build error:

In file included from /usr/include/string.h:495,
                 from ../../bfd/bfd.h:48,
                 from ../../../../repos/binutils-gdb/sim/d10v/interp.c:4:
In function memset,
    inlined from sim_create_inferior at ../../../../repos/binutils-gdb/sim/d10v/interp.c:1146:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:71:10: error: __builtin_memset offset [33, 616] from the object at State is out of the bounds of referenced subobject regs with type reg_t[16] {aka short unsigned int[16]} at offset 0 [-Werror=array-bounds]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:558: interp.o] Error 1

The following patch fixes this.

sim/ChangeLog:

2021-05-12  Luis Machado  <luis.machado@linaro.org>

	* d10v/interp.c (sim_create_inferior): Fix memset call.
2021-05-12 00:57:46 -03:00
Mike Frysinger
bb608f811b sim: h8300: clean up various warnings
A random grab bag of minor fixes to enable -Werror for this port.

Disable h8_set_macS for now as it's unused.
Initialize trace & intMask before using them.
Mark local set_h8300h function static.
2021-05-08 12:43:06 -04:00
Mike Frysinger
b50a658ac1 sim: touch modules target
If there are no updates to the file, touch the result so we don't
keep trying to regenerate it.
2021-05-08 12:35:08 -04:00
Mike Frysinger
532497fe6f sim: cgen: tweak trace format
Fixes build warnings when the address size isn't an integer.
2021-05-08 12:33:08 -04:00
Mike Frysinger
1227922933 sim: cgen: namespace mode_names a bit
These are exported in the library linkage, so add a cgen_ prefix.
2021-05-08 12:29:00 -04:00
Mike Frysinger
6ae9091ab0 sim: cgen: tweak cgen_rtx_error to fix warnings
The function was missing a prototype, and passing a constant string
as the format string instead of going through a %s format.
2021-05-08 12:27:45 -04:00
Mike Frysinger
aac7ce3c87 sim: cgen: tweak initializers to avoid warnings
Use {} instead of {0} to avoid warnings:

common/cgen-utils.c:59:1: warning: missing braces around initializer [-Wmissing-braces]
   59 | {
      | ^
   60 |   {
   61 |     VIRTUAL_INSN_X_INVALID, "--invalid--", NULL, 0, { V, { 0 } }
      |                                                            {{}}

Generated code should be the same.
2021-05-08 12:10:27 -04:00
Mike Frysinger
0d0878d72e sim: add html & pdf stubs
We stub out the info targets already since we don't provide any.
2021-05-08 11:55:22 -04:00