Commit Graph

5173 Commits

Author SHA1 Message Date
Dimitar Dimitrov
c412d3f5d9 sim: pru: Fix test case assembly with latest GAS
After the recent change in GAS [1], macro arguments must be quoted or
grouped with parenthesis.  Add the necessary parenthesis in order to fix
assembly errors like:
    mul.s:31: Error: too many positional arguments

[1] https://sourceware.org/pipermail/binutils/2024-July/136053.html

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2024-08-12 23:33:59 +03:00
Alan Modra
7a4c00599c regen sim/frv files for copyright update 2024-06-10 08:25:56 +09:30
Matthieu Longo
c22e3e25de autoupdate: replace obsolete macros AC_HELP_STRING
- AC_HELP_STRING by AS_HELP_STRING
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fHELP_005fSTRING-1
Except for the ifdef in lib-prefix.m4, make the defun of AC_LIB_ARG_WITH
unconditional.
2024-06-10 08:25:55 +09:30
Bernd Edlinger
b75187cd94 sim: riscv: Fix build issue due to recent binutils commit
The commit c144f63833 removed INSN_CLASS_A and
added INSN_CLASS_ZAAMO and INSN_CLASS_ZALRSC instead,
which broke the build of the sim for riscv targets.

Fix that by using the new INSN_CLASS types.

Fixes: c144f63833 ("RISC-V: Support B, Zaamo and Zalrsc extensions.")

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-09 17:04:14 +02:00
Bernd Edlinger
d8e753b791 sim: riscv: Fix confusion with c.jal vs. c.addiw
There was apparently a confusion which cpu model uses
compressed JAL and which ADDIW.  Fixed that in execute_c,
case MATCH_C_JAL | MATCH_C_ADDIW.

Fixes 3224e32fb8 ("sim: riscv: Add support for compressed integer instructions")

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-04-15 11:04:07 +02:00
Bernd Edlinger
a73073dc7f sim: riscv: Make stack 16-byte aligned
Various gcc test cases fail due to the stack
alignment of 16 bytes is expected by gcc,
causing issues mostly with vararg functions,
e.g.

FAIL: gcc.c-torture/execute/nest-align-1.c   -O0  execution test
FAIL: gcc.c-torture/execute/nest-stdar-1.c   -O0  execution test
FAIL: gcc.c-torture/execute/va-arg-12.c   -O0  execution test
FAIL: gcc.c-torture/execute/va-arg-15.c   -O0  execution test
FAIL: gcc.c-torture/execute/va-arg-16.c   -O0  execution test
FAIL: gcc.c-torture/execute/va-arg-17.c   -O0  execution test
FAIL: gcc.c-torture/execute/va-arg-20.c   -O0  execution test
FAIL: gcc.c-torture/execute/va-arg-26.c   -O0  execution test
...

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-04-15 10:22:56 +02:00
Bernd Edlinger
ae14cde6fd sim: riscv: Fix PC at gdb breakpoints
The uncompressed EBREAK instruction does not work
correctly this way, and the comment saying that
GDB expects us to step over EBREAK is just wrong.
The PC was always 4 bytes too high, which skips one
instruction at break and step over commands, and
causes complete chaos.  The compressed EBREAK was
already implemented correctly.

Tested by using gdb's "target sim" and single-stepping.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-04-15 10:20:50 +02:00
Orgad Shaneh
acaf48b921 sim/erc32: Rename EVENT_MAX -> MAX_EVENTS
EVENT_MAX is defined as 0x7FFFFFFF (INT_MAX) in winuser.h, so when
building on Windows, the value is overridden and compilation fails
because the array size of evbuf is too large.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28476
Approved-By: Tom Tromey <tom@tromey.com>
2024-03-21 10:46:23 -06:00
Alan Modra
93f83dcc94 sim: no rule to make sim/ppc/Makefile.in
Seen with --enable-maintainer-mode.
make[3]: *** No rule to make target '.../sim/ppc/Makefile.in', needed
by 'ppc/stamp-pk'.  Stop.

	* sim/ppc/local.mk (stamp-pk): Depend on local.mk not
	Makefile.in.
	* Makefile.in: Regenerate.

Approved-By: Tom Tromey <tom@tromey.com>
2024-02-24 11:52:10 +10:30
Jaydeep Patil
3224e32fb8 sim: riscv: Add support for compressed integer instructions
Added support for simulation of compressed integer instruction set ("c").
Added test file sim/testsuite/riscv/c-ext.s to test compressed instructions.
The compressed instructions are available for models implementing C extension.
Such as RV32IC, RV64IC, RV32GC, RV64GC etc.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-13 11:04:04 +00:00
Jose E. Marchesi
920d9f0b39 sim: bpf: remove support for ldinddw and ldabsdw instructions
This patch removes support for the two instructions above from the GNU
simulator, including the corresponding tests.  These instructions do
not really exist in BPF and are not recognized as such by the kernel
verifier.  This has now been pointed out during the standardization of
the BPF ISA.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
2024-01-29 22:25:19 +01:00
Mike Frysinger
047fa8cc1c sim: sh: fix nested braces in struct init
The op struct includes an array of strings, but doesn't use braces
around that array when initializing.  This causes a ton of warnings
when using -Wmissing-braces.  Add them to fix.

The code this tool generates is the same before & after.
2024-01-23 03:15:02 -05:00
Jaydeep Patil
b783d068d9 sim: riscv: Fix crash during instruction decoding
The match_never() function has been removed and thus step_once() crashes
during instruction decoding. Fixed it by checking for null pointer before
invoking function attached to match_func member of riscv_opcode structure
2024-01-22 20:16:27 -05:00
Mike Frysinger
8fed036bef sim: frv: fix -Wincompatible-function-pointer-types warnings [PR sim/29752]
Some compilers warn in the frv code:
sem.c:24343:41: error: incompatible function pointer types passing
  'void (SIM_CPU *, UINT, UDI)' (aka 'void (struct _sim_cpu *, unsigned int, unsigned long)')
  to parameter of type
  'void (*)(SIM_CPU *, UINT, DI)' (aka 'void (*)(struct _sim_cpu *, unsigned int, long)') [-Wincompatible-function-pointer-types]

This is due to frvbf_h_acc40U_set using UDI for setting the new value,
but using the common sim_queue_fn_di_write API which uses DI.  The same
size, but different sign.  We could change frvbf_h_acc40U_set to take a
DI without changing behavior in practice: the UDI is already passed via
the queue function which accepts a DI, and frvbf_h_acc40U_set already
casts the input to UDI before running any operations on it.  However,
these files are all generated, so manual changes here would be reverted.

Seems like we can only change the register type for all APIs in the cpu
definition.  This builds cleanly, and passes sim unittests.  Not sure if
it's 100% the answer, but seems to be the best we have currently.

Bug: https://sourceware.org/PR29752
2024-01-22 20:12:08 -05:00
Mark Wielaard
cbbcd7fd10 sim: Fix -Werror=shadow=local by changing mem to addr in sim_{read,write}
m32c/cpu.h defines mem as enum value, which causes GCC 14 to emit

sim/m32c/gdb-if.c: In function ‘sim_read’:
sim/m32c/gdb-if.c:162:33: error: declaration of ‘mem’ shadows a previous local [-Werror=shadow=local]
  162 | sim_read (SIM_DESC sd, uint64_t mem, void *buf, uint64_t length)
      |                        ~~~~~~~~~^~~
In file included from ../../binutils-gdb/sim/m32c/gdb-if.c:38:
sim/m32c/cpu.h:83:3: note: shadowed declaration is here
   83 |   mem,
      |   ^~~

Fix this by renaming mem to addr in all sim_read and sim_write functions.
Most already used addr instead of mem. In one file, sim/rx/gdb-if.c, this
also meant renaming the local addr variable to vma.
2024-01-22 14:22:30 +01:00
Mark Wielaard
c2625a463f sim: Fix some -Werror=shadow=compatible-local issues in aarch64/simulator.c
With GCC 14 -Werror=shadow=compatible-local flags the reuse of single
capital letters used in aarch64/cpustate.h enums

   88 | expand_logical_immediate (uint32_t S, uint32_t R, uint32_t N)
      |                                                   ~~~~~~~~~^
In file included from ../../binutils-gdb/sim/aarch64/aarch64-sim.h:27,
                 from ../../binutils-gdb/sim/aarch64/simulator.c:33:
  217 |   N = 1 << N_IDX
      |   ^

sim/aarch64/simulator.c: In function ‘expand_logical_immediate’:
sim/aarch64/simulator.c:88:60: error: declaration of ‘N’ shadows a previous local [-Werror=shadow=compatible-local]
sim/aarch64/cpustate.h:217:3: note: shadowed declaration is here
2024-01-22 12:10:23 +01:00
Mark Wielaard
865e469c60 sim: Fix cc -Werror=shadow=local in cr16/simops.c
include/opcode/cr16.h defines cc as an enum value, which causes GCC 14
to warn

sim/cr16/simops.c: In function ‘cond_stat’:
sim/cr16/simops.c:138:26: error: declaration of ‘cc’ shadows a previous local [-Werror=shadow=local]
  138 | static int cond_stat(int cc)
      |                      ~~~~^~
In file included from ../../binutils-gdb/sim/cr16/cr16-sim.h:26,
                 from ../../binutils-gdb/sim/cr16/simops.c:39:
sim/../include/opcode/cr16.h:149:3: note: shadowed declaration is here
  149 |   cc,
      |   ^~

Fix this by renaming cc in cr16/simops.c to cond.
2024-01-22 12:04:49 +01:00
Mike Frysinger
48157d30b6 sim: ppc: implement 128-bit register read/writes with sim-endian APIs
We have APIs in sim-endian for working with 128-bit values like this code
is already doing for 8/16/32/64-bit values.  Switch over to that to make
it a bit simpler, and drop the WITH_ALTIVEC check.  The code probably is
only used when altivec is enabled, but it doesn't add much to always
compile it in, and avoids #ifdef rot by not actually compiling it.
2024-01-18 01:49:56 -05:00
Mike Frysinger
dcc6c863ed sim: ppc: switch register read/writes to union to avoid aliasing issues
This code creates a small buffer on the stack w/alloca, then proceeds to
write to it with a cast to a pointer type based on the register type, then
reads from it with a cast to a pointer type based on the register size.
gcc will flags only one of these lines as "maybe used uninitialized", but
it seems to track back to this memory abuse.

Create a large union with all the possible types that this code will read
or write as, and then use those.  It's a bit ugly, but is probably better
than using raw memcpy's everywhere.
2024-01-18 01:46:27 -05:00
Mark Wielaard
9fbb73edb1 Regenerate two Makefile.in files to update Copyright headers
commit 1d506c26d9
Update copyright year range in header of all files managed by GDB
updated gnulib/Makefile.am but didn't regenerate gnulib/Makefile.in
also sim/Makefile.in was updated, but the Copyright hunks/years
were off. The first hunk comes from automake 1.15.1 header-vars.am
and so should have 2017 as last year, the second hunk does come from
sim/Makefile.am and so should have 2024 as last year.

	* gnulib/Makefile.in: Regenerate.
	* sim/Makefile.in: Likewise.
2024-01-15 15:44:25 +01:00
Dimitar Dimitrov
b83808a8a2 sim: Fix compile errors
The following change broke simulator testsuite with host GCC 13:
  commit 435ad222b3
  sim: warnings: compile build tools with -Werror too

Host GCC13 complains about missing function prototypes:

binutils/sim/testsuite/common/bits-gen.c:26:1: error: no previous prototype for ‘gen_struct’ [-Werror=missing-prototypes]
   26 | gen_struct (void)
      | ^~~~~~~~~~

Fix by making the functions static, which instructs the compiler that
there is no need for a prototype.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2024-01-12 21:48:25 +02:00
Andrew Burgess
1d506c26d9 Update copyright year range in header of all files managed by GDB
This commit is the result of the following actions:

  - Running gdb/copyright.py to update all of the copyright headers to
    include 2024,

  - Manually updating a few files the copyright.py script told me to
    update, these files had copyright headers embedded within the
    file,

  - Regenerating gdbsupport/Makefile.in to refresh it's copyright
    date,

  - Using grep to find other files that still mentioned 2023.  If
    these files were updated last year from 2022 to 2023 then I've
    updated them this year to 2024.

I'm sure I've probably missed some dates.  Feel free to fix them up as
you spot them.
2024-01-12 15:49:57 +00:00
Mike Frysinger
20617191e4 sim: ppc: return register error when unhandled
We don't want to fallthru and use cooked_buf when we haven't initialized
it to anything.  Returning 0 indicates the register wasn't recognized.
2024-01-11 00:49:56 -05:00
Mike Frysinger
c3c79ac5c4 sim: m32r: enable warnings in traps.c
File should be clean now!
2024-01-10 22:37:04 -05:00
Mike Frysinger
08a7937f3a sim: m32r: fixup some of the int<->pointer casts
The m32r trap code was written for a 32-bit Linux host (and really, one
whose Linux ABI matched pretty exactly).  This has lead to conversions
between integers and pointers which breaks down hard on 64-bit hosts.

Clean up some of the functions where possible to avoid unnecessary
conversions, use uintptr_t to cast 32-bit target pointers to host
pointers in some places, and just stub out a few functions that can't
easily be salvaged currently when sizeof(void*) is not 32-bits.  This
is a bit ugly, but lets us enable warnings for the whole file.
2024-01-10 22:37:03 -05:00
Mike Frysinger
dbd4aebe5b sim: m32r: fix missing break statement
The ftime syscall should not fallthrough to the sync syscall.
Clearly the code was missing a break statement.
2024-01-10 22:31:56 -05:00
Mike Frysinger
b1f974faeb sim: m32r: migrate ftime() to clock_gettime()
The ftime() function has been deprecated since POSIX-1-2004, and
removed in POSIX.1-2008.  It's also been deprecated/removed in glibc
since 2.33.  POSIX has always said the function is not portable, and
its return value, timezone, and dstflag fields are unspecified.  Even
if Linux/glibc & m32r had defined behavior, those aren't the host for
the sim runtime.

So let's stop using the function and switch to clock_gettime.  gnulib
already has detection support for it, and it's been around since at
least POSIX-1-2004.
2024-01-10 22:31:54 -05:00
Mike Frysinger
c66061f403 sim: m32r: cleanup unused variables
We've been building this file with -Wno-error, so clean up unused
variable warnings.
2024-01-10 22:31:53 -05:00
Mike Frysinger
f0f0b063f0 sim: igen: add printf attributes to the prototypes too
While gcc propagates the printf attribute via the typedef, clang
doesn't seem to, so add it to the prototypes themselves too.  We
still keep it on the prototype for cases where it's used as a
variable.
2024-01-10 22:30:58 -05:00
Mike Frysinger
761ed61e7b gdbsupport: tighten up libiberty code a bit with dnl
No functional change here, just touch up generated output slightly.

Approved-By: Tom Tromey <tom@tromey.com>
2024-01-10 19:53:14 -05:00
Mike Frysinger
72d711c155 sim: build: switch to gdbsupport/libiberty.m4
Leverage this common logic to find all the libiberty settings rather
than duplicate it ourselves.
2024-01-10 19:53:10 -05:00
Mike Frysinger
0846ae35a1 sim: ppc: rework defines.h to handle HAVE symbols defined to 0
The HAVE_DECL_xxx defines are always defined to 0 or 1.  The current
defines.h logic assumes every HAVE_xxx symbol is only defined iff it's
defined to 1 which causes this to break.  Tweak the sed logic to only
match defines of 1.
2024-01-10 19:53:10 -05:00
Mike Frysinger
435ad222b3 sim: warnings: compile build tools with -Werror too
Add support for compiling build tools with various -Werror settings.
Since the tools don't compile cleanly with the same set of flags as
the rest of the sim code, we need to maintain & test a separate list.

Only bother when not cross-compiling so we don't have to test all the
flags against the build compiler.  This should be good enough for our
actual development flows.
2024-01-08 21:36:44 -05:00
Mike Frysinger
5048cb28f4 sim: igen: fix format-zero-length warnings
Fix warnings from calling printf functions with "" which normally
is useless.
2024-01-08 21:25:55 -05:00
Mike Frysinger
c6352113d2 sim: m68hc11: gencode: add printf markings 2024-01-08 21:25:22 -05:00
Mike Frysinger
916791c745 sim: m32c: fix declaration-after-statement warnings 2024-01-08 21:24:08 -05:00
Mike Frysinger
d2704ed59b sim: warnings: fix unused variable warnings
Leave the igen code in place as it's meant to be used with newer
(to-be-written) code ported from the ppc version.

The sh code isn't really necessary as the opcodes enums have been
maintained independently from here, and the lists are out-of-sync
already.
2024-01-08 21:21:58 -05:00
Mike Frysinger
f64e47a22c sim: warnings: mark local funcs/vars as static
These are only used in the respective files, so mark them as static.
This fixes missing prototype warnings at build time.
2024-01-08 21:20:05 -05:00
Mike Frysinger
7531822f10 sim: build: clean more generated outputs 2024-01-08 20:33:14 -05:00
Mike Frysinger
4c68f4e386 sim: mips: drop old clean workaround
This logic dates back to the original import, and seems to be for
handling systems where `rm -f` (i.e. no files) would error out.
None of that is relevant for us with current automake, so drop it.
2024-01-08 20:20:59 -05:00
Mike Frysinger
92bdeb2888 sim: ppc: workaround uninitialized variable compiler warnings
Some compilers don't understand the semctl API and think it's an input
argument even when it's used as an output, and then complains that it
is being used uninitialized.  Zero it out explicitly to workaround it.
This adds some runtime overhead, but should be fairly minor as it's a
small stack buffer, and shouldn't be that relevant relative to all the
other logic in these functions.
2024-01-08 20:13:22 -05:00
Mike Frysinger
9f17cdda31 sim: warnings: enable -Wshift-negative-value
Now that all the relevant sources are fixed, enable the warning.
2024-01-08 20:02:44 -05:00
Mike Frysinger
4223df94e0 sim: sh: avoid left shifting negative values
We just want to create a bitmask here, so cast the mask to unsigned
to avoid left shifting a negative value which is undefined behavior.
2024-01-08 20:02:29 -05:00
Mike Frysinger
b0c687b2ca sim: bfin: avoid left shifting negative values
We just want to create a bitmask here, so cast the mask to unsigned
to avoid left shifting a negative value which is undefined behavior.
2024-01-08 20:01:45 -05:00
Mike Frysinger
b2ea48df92 sim: cgen: rework DI macros to avoid signed left shifts
The cgen code uses DI as int64_t and UDI as uint64_t.  The DI macros
are used to construct 64-bit values from 32-bit values (for the low
and high parts).  The MAKEDI macro casts the high 32-bit value to a
signed 32-bit value before shifting.  If this created a negative
value, this would be undefined behavior according to the C standard.
All we care about is shifting the 32-bits as they are to the high
32-bits, not caring about sign extension (since there's nothing left
to shift into), and the low 32-bits being empty.  This is what we
get from shifting an unsigned value, so cast it to unsigned 32-bit
to avoid undefined behavior.

While we're here, change the SETLODI macro to truncate the lower
value to 32-bits before we set it.  If it was passing in a 64-bit
value, those high bits would get included too, and that's not what
we want.

Similarly, tweak the SETHIDI macro to cast the value to an unsigned
64-bit instead of a signed 64-bit.  If the value was only 32-bits,
the behavior would be the same.  If it happened to be signed 64-bit,
it would trigger the undefined behavior too.
2024-01-08 20:01:05 -05:00
Mike Frysinger
f6c714d65b sim: warnings: enable -Wshadow=local
This brings us in sync with current set of gdb warnings (for C).
2024-01-06 23:30:43 -05:00
Mike Frysinger
199b67ca04 sim: cris: change temp var name slightly to avoid shadowing
Rename the temp var to avoid shadowing another one:

.../sim/cris/semcrisv10f-switch.c:11032:22: error: declaration of ‘tmp_tmpb’ shadows a previous local [-Werror=shadow=compatible-local]
11032 |   tmp_tmpb = ({   SI tmp_tmpb;
      |                      ^~~~~~~~
.../sim/cris/semcrisv10f-switch.c:11031:24: note: shadowed declaration is here
11031 |   tmp_tmpres = ({   SI tmp_tmpb;
      |                        ^~~~~~~~
2024-01-06 23:30:43 -05:00
Mike Frysinger
012c1f072f sim: cris: add error fallbacks when decoding condition & swap codes
The condition & swap code decoder only checks known bits and sets
based on that.  If the variable is out of range, it ends up returning
uninitialized data.  Turn that case into a hard error.

This fixes build warnings like:
sim/cris/semcrisv10f-switch.c:13115:11: error:
	variable 'tmp_condres' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
2024-01-06 23:30:43 -05:00
Mike Frysinger
086d7dbb2e sim: ppc: unify igen filter modules
The common igen code was forked from the ppc long ago.  The filter
module is still pretty similar in API, so we can unfork them with
a little bit of effort.

The filter.c module is still here because of the unique it_is API.
The common igen code doesn't seem to have an equiv API as this only
operates on two strings and not an actual filter object, and it's
easy enough to leave behind to unfork the rest.
2024-01-03 03:37:13 -05:00
Mike Frysinger
7811c75893 sim: ppc: unify igen line number output modules
The common igen code was forked from the ppc long ago.  The lf module
is still pretty similar in API, so we can unfork them with a little
bit of effort.

Some of the generated ppc code is now slightly different, but that's
because of fixes the common igen code has gained, but not the ppc igen
code (e.g. fixing of #line numbers).

The ppc code retains lf_print__c_code because the common igen code
rewrote the logic to a new table.c API.  Let's delay that in the ppc
code to at least unfork all this code.
2024-01-03 03:32:08 -05:00