When in the virtual environment, have brki 8 trigger libgloss syscalls
like other ports. This also matches the ABI that Linux uses for its
syscalls (ignoring the syscall table differences).
This updates the various "mloop.in" files to emit an include of
stdlib.h, to avoid warnings about 'abort' being undeclared.
One such warning now remains, in mn10300.igen. I don't know offhand
the best way to fix this one.
2021-05-04 Tom Tromey <tromey@adacore.com>
* mloop.in: Include <stdlib.h>.
sim/iq2000/ChangeLog
2021-05-04 Tom Tromey <tromey@adacore.com>
* mloop.in: Include <stdlib.h>.
sim/lm32/ChangeLog
2021-05-04 Tom Tromey <tromey@adacore.com>
* mloop.in: Include <stdlib.h>.
sim/m32r/ChangeLog
2021-05-04 Tom Tromey <tromey@adacore.com>
* mloop.in: Include <stdlib.h>.
sim/or1k/ChangeLog
2021-05-04 Tom Tromey <tromey@adacore.com>
* mloop.in: Include <stdlib.h>.
The igen build fails for me like:
gcc -g -O2 -c ../../binutils-gdb/sim/igen/igen.c -o igen/igen.o
In file included from ../../binutils-gdb/sim/igen/igen.c:26:
../../binutils-gdb/sim/igen/lf.h:22:10: fatal error: ansidecl.h: No such file or directory
This patch fixes the problem by arranging for igen to find the
libiberty includes.
This seems slightly hacky to me, because libiberty is not a "build"
library, so it can't be linked against. However, since igen currently
only includes the header, it seems relatively safe.
2021-05-04 Tom Tromey <tromey@adacore.com>
* Makefile.in: Rebuild.
* Makefile.am (AM_CPPFLAGS): New variable.
I noticed that config.h isn't in 'generated_files' in the sim
subdirectories. This causes it to sometimes be rebuilt too late.
2021-05-04 Tom Tromey <tromey@adacore.com>
* Make-common.in (generated_files): Add config.h.
This is needed when building for a target whose ar & ranlib are
incompatible with the current build system. For example, building
for Windows on a Linux system.
Then manually import the automake rule for libigen.a, but tweak the
tool variables to use the FOR_BUILD variants.
A lot of this code predates the bfd_vma format define, so we have a
random mix of casts to known types so we can printf the value. Use
the BFD_VMA_FMT that now exists to simplify and reliability output
across different build configs.
I finally got the all-targets sim building with Clang, these are all the
instances where an ATTRIBUTE_PRINTF or ATTRIBUTE_NULL_PRINTF attribute
needed to be added to avoid errors like:
/home/simark/src/binutils-gdb/sim/aarch64/../common/sim-profile.c:464:19: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
vfprintf (fp, fmt, ap);
^~~
There are more fixes needed to get everything building, but adding these
attributes is trivial enough, so I send them all in a single patch.
Adding the format attributes introduces some format string errors when
building with GCC (because now format strings are checked), so
corresponding changes are needed to avoid breaking the build. Other
than simple format string specified changes, there is this one:
/home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c: In function 'hw_event_queue_schedule':
/home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c:95:15: error: too many arguments for format [-Werror=format-extra-args]
95 | NULL, dummy);
| ^~~~~
We can fix it and avoid using a dummy variable by simply calling
hw_event_queue_schedule_tracef instead of
hw_event_queue_schedule_vtracef.
sim/arm/ChangeLog:
* armdefs.h (ARMul_ConsolePrint): Use format attribute.
* wrapper.c (op_printf): Likewise.
sim/bfin/ChangeLog:
* interp.c (sim_open): Adjust format string specifier.
sim/common/ChangeLog:
* hw-events.h (hw_event_queue_schedule_tracef): Use format attribute.
(hw_event_queue_schedule_vtracef): Likewise.
* hw-tree.h (hw_tree_vparse): Likewise.
* sim-profile.c (profile_vprintf): Likewise.
* sim-trace.c (dis_printf): Likewise.
* sim-trace.h (trace_printf): Likewise.
(trace_vprintf): Likewise.
* sim-utils.h (sim_do_commandf): Likewise.
* hw-events.c (hw_event_queue_schedule): Use
hw_event_queue_schedule_tracef.
sim/rx/ChangeLog:
* trace.c (op_printf): Likewise.
sim/v850/ChangeLog:
* interp.c (sim_open): Adjust format string specifier.
Change-Id: I1445115ce57db15bb8e35dca93014555e7555794
This is the next compilation error I hit when I build all targets with
Clang:
/home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:234:12: error: no case matching constant switch condition '0' [-Werror] switch (WITH_ENVIRONMENT)
^~~~~~~~~~~~~~~~ ./config.h:215:26: note: expanded from macro 'WITH_ENVIRONMENT'
#define WITH_ENVIRONMENT ALL_ENVIRONMENT ^~~~~~~~~~~~~~~
/home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:276:15: error: no case matching constant switch condition '0' [-Werror] switch (WITH_ALIGNMENT)
^~~~~~~~~~~~~~ /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-config.h:220:24: note: expanded from macro 'WITH_ALIGNMENT'
#define WITH_ALIGNMENT 0
^
This is a little bit special because these are switches on compile-time
value. But regardless, the idea is that we logically can't reach the
switches if WITH_ENVIRONMENT == 0 or WITH_ALIGNMENT == 0, so the code is
correct.
In addition to getting rid of the compiler warning, adding default cases
to these switches ensure that if we do get in an unexpected situation,
it is caught. In GDB, I'd use gdb_assert_not_reached, I don't know if
there is something similar in sim so I went with abort.
sim/common/ChangeLog:
* sim-options.c (standard_option_handler): Add default cases to
switches.
Change-Id: Ie237d67a201caa6b72de0d17cc815193417156b6
A lot of this code predates the common attributes. We had already
started migrating over piece by piece, so just do a pass across all
the attributes and replace most of them.
Now that modules can self declare their own init funcs, change the mmu
and mach logic to use it. We don't need to export the option symbols
or specifically call this logic from the sim_open function anymore.
The hash table rewrite broke --help output due to subtle behavior:
calling dup_arg_p(NULL) will create & clear the table, not just
create it. The --help output relies on this to clear the table
before it shows things.
To facilitate decentralized module initialization/registration with an
eye towards multi-target support, add a framework to detect init calls
declared in the source and automatically call them. This is akin to
gdb's _initialize_xxx framework for letting modules autodiscover.
While libiberty provides a definition for this for systems that lack
the function (e.g. Windows), it doesn't provide a prototype. So add
our own local copy in the one file that uses the func.
This is annoying as it requires inlining boiler plate, but we don't
have much choice: the wrap helper assumes the return value is always
an int, but that's already not the case with some of the callbacks
which use long. GCC has extensions to define macros-as-functions,
but we can't assume GCC.
Since libgloss provides a default syscall table for arches, use that
to provide the default syscall table for ports. Only the exceptions
need to be enumerated now with the common logic as the default.
Force this on for all ports. We have a few common models that can
be used, so make them generally available. If the port doesn't use
any hardware (the default), then behavior is unchanged.
A rebuild showed that an earlier change of mine missed a built header
file -- cris/engv32.h. This patch fixes the problem.
sim/cris/ChangeLog
2021-04-25 Tom Tromey <tom@tromey.com>
* Makefile.in (SIM_EXTRA_DEPS): Add engv32.h.
This changes sim-options.c to use the libiberty hash table, rather
than its own custom hash table.
sim/common/ChangeLog
2021-04-25 Tom Tromey <tom@tromey.com>
* sim-options.c (compare_strings): New function.
(ARG_HASH_SIZE, ARG_HASH): Remove.
(dup_arg_p): Use htab_t.
(sim_parse_args): Remove assert.
As we turn on more modules by default for all ports, the number of
options has been increasing. The sim-options module has a limit on
the number of options it can support, and if it's exceeded, it likes
to go into an infinite loop. Increase the ceiling and add an assert
so we abort right away instead of hanging.
This will be needed to turn on hw support for v850 as it will then
exceed the current limit.
Every port using this sets the 1st arg to yes and the 2nd arg to "".
These are the defaults we probably want anyways in order to unify the
codebase, so move them to the macro and only allow ports to declare
extra hardware models.
A couple of sim Makefiles define LIBS, but don't use it. This removes
these.
sim/m32c/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (LIBS): Remove
sim/rx/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (LIBS): Remove.
Some Makefiles in sim define INCLUDE but don't use it. This removes
these instances.
sim/bfin/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (INCLUDE): Remove.
sim/m68hc11/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (INCLUDE): Remove.
sim/mn10300/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (INCLUDE): Remove.
sim/v850/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (INCLUDE): Remove.
This changes the sim/ppc Makefile to use the stamp file idiom for a
couple of generated files, avoiding extra rebuilds.
sim/ppc/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Makefile.in (stamp-vals, stamp-map): New targets.
(targ-vals.h, targ-map.c): Update.
(clean): Remove files.
This adds a stamp file for hw-config.h, to avoid unnecessary rebuilds.
It also arranges to remove hw-config.h in "mostlyclean", because the
file is created by "make".
sim/common/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Make-common.in (stamp-hw): New target.
(hw-config.h): Depend on stamp-hw.
(mostlyclean): Remove stamp-hw and hw-config.h.
I found out by accident that "mostlyclean" in a sim subdir removes all
the configure artifacts. The usual rule is:
* If the maintainer built it, maintainer-clean should remove it;
* If configure built it, distclean should remove it;
* If make built it, "clean" should remove it;
* If there is a handy subset of "clean" that is "easy" to rebuild,
"mostlyclean" should remove it; otherwise mostlyclean should be an
alias for clean
This patch makes mostlyclean an alias for clean.
sim/common/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* Make-common.in (mostlyclean): Now an alias for clean, not
distclean.
On x86-64 Fedora 32, the sim was failing to build.
sim_events_schedule was passing a 'dummy' argument to
sim_events_schedule_vtracef, which caused an error because the format
parameter was NULL. However, removing this dummy argument caused an
error because too few arguments were being passed -- catch 22.
This patch fixes the build problem by using sim_events_schedule_tracef
instead.
sim/common/ChangeLog
2021-04-22 Tom Tromey <tom@tromey.com>
* sim-events.c (sim_events_schedule): Use
sim_events_schedule_tracef.
Add some ATTRIBUTE_PRINTF attributes to functions that take a format
string, to fix a few -Wformat-nonliteral warnings. Use the
ATTRIBUTE_PRINTF macro like we use in GDB, instead of spelling out
__attribute__((format...)). Use ATTRIBUTE_NULL_PRINTF at one place,
because callers expect to be able to pass NULL.
sim/common/ChangeLog:
* callback.c (os_printf_filtered, os_vprintf_filtered,
os_evprintf_filtered, os_error): Use ATTRIBUTE_PRINTF.
* sim-engine.h (sim_engine_abort, sim_engine_vabort): Likewise.
* sim-events.h (sim_events_schedule_tracef,
sim_events_schedule_vtracef): Use ATTRIBUTE_NULL_PRINTF.
Change-Id: Icd206f7b2c325e8b144f72eb129fb2a6b5af2fa3
When building with clang, we get:
error: unknown warning option '-Wmissing-parameter-type' [-Werror,-Wunknown-warning-option]
This is because clang only warns by default when encountering an unknown
warning option, and the probe for supported warning flags is done
without -Werror. All flags are therefore accepted by configure, but
then it breaks when actually compiling a source file with -Werror.
This is equivalent to this commit in gdb:
3e019bdc20
gdb: Use -Werror when checking for (un)supported warning flags
We then see some other compilation errors when building with clang and
-Werror, they can be dealt with later.
Since getopt.h is provided by libiberty, there's no need to probe for
a system version of it. Plus we already assume it exists in other
parts of the sim.
Rather than hand duplicate the syscall constants, switch to the
common nltvals framework. I made sure the constants have the
same values before & after too :).
Rather than hand duplicate the syscall table, switch to the common
nltvals framework. We have to tweak the constant names, but we get
everything else for free. I made sure the constants have the same
values before & after too :).
Rather than hand duplicate the syscall table, switch to the common
nltvals framework. We have to tweak the constant names, but we get
everything else for free. I made sure the constants have the same
values before & after too :).
Rather than hand duplicate the syscall table, switch to the common
nltvals framework. We have to tweak the constant names, but we get
everything else for free. I made sure the constants have the same
values before & after too :).
Rather than hand duplicate the syscall table, switch to the common
nltvals framework. We have to tweak the constant names, but we get
everything else for free. I made sure the constants have the same
values before & after too :).
This avoids duplicate tests for functions between common m4, arches,
and any other sources that would trigger func tests.
Also manually delete known duplicate function tests between the m4,
bfin, and v850 ports.
The printf fix uses our PRIxTA for our sim address type.
Then cast away the const (since the underlying code safely treats it
as such) even if it's ugly.
Finally touch up the argv iterator pointer to match the new func arg.
With this tidied up, we can delete the SIM_AC_OPTION_WARNINGS(no) call
to get the default common behavior where -Werror is enabled.
The printf fix is obvious enough, but the hash one is a real bug:
cr16/interp.c: In function 'sim_open':
cr16/interp.c:560:17: error: 'h' may be used uninitialized in this function [-Werror=maybe-uninitialized]
560 | h = h->next;
| ~~^~~~~~~~~
It happens to not cause a problem currently because the first entry in
the generated table that this loop operates matches a codepath where h
is initialized. Then when later entries don't match, the previous value
is pointing at the end of a valid hash table already, and the rest of
the code does nothing.
With this tidied up, we can delete the SIM_AC_OPTION_WARNINGS(no) call
to get the default common behavior where -Werror is enabled.
Add a READLINE_CFLAGS variable which adds the include path to the
in-tree readline when using the in-tree readline library.
sim/erc32/ChangeLog:
* Makefile.in (READLINE_SRC, READLINE_CFLAGS): Add.
(SIM_EXTRA_CFLAGS): Add READLINE_CFLAGS.
* configure: Rebuild.
* configure.ac (READLINE_CFLAGS): Add.
Only pass the top-level instruction decode table (mn10300.igen) to
igen via -i. The additional files passed previously caused igen to
exit its getopt loop in main and exit silently without generating any
output. In addition, when am33-2.igen was added, it was not included
from mn10300.igen, so was never used.
sim/mn10300/ChangeLog:
* Makefile.in: (tmp-igen) Only pass mn10300.igen to igen.
* mn10300.igen: Include am33-2.igen.
Explicitly use a known-good shell found by autoconf for executing
additional scripts in genmloop.sh rather than the building user's
shell.
sim/lm32/ChangeLog:
* Makefile.in: Pass -shell to genmloop.sh.
Claim that the accumulator indices are out of range without raising an
exception if the CPU doesn't support media instructions.
sim/frv/ChangeLog:
* traps.c (frvbf_check_acc_range): Add missing return value.
The bfin sim adds include paths for the SDL libraries. These include
paths might include headers for different version of binutils. Move
SIM_EXTRA_CFLAGS after CSEARCH to ensure local includes are always
preferred to external includes.
sim/common/ChangeLog:
* Make-common.in (CONFIG_CFLAGS): Remove SIM_EXTRA_CFLAGS.
(ALL_CLAGS, COMMON_DEP_CFLAGS): Add SIM_EXTRA_CFLAGS after
CSEARCH.
On a 32-bit build, I ran into the following:
sim/rx/fpu.c:789:6: error: "*((void *)&a+8)" may be used uninitialized in this function [-Werror=maybe-uninitialized]
rv = fp_implode (&a);
To silence this, just initialize the struct with 0's.
sim/rx/ChangeLog:
2021-04-09 Luis Machado <luis.machado@linaro.org>
* fpu.c (rxfp_itof): Initialize structure.
GCC gives a -Wsequence-point warning for this code in the h8300 sim.
The bug is that memory_size is both assigned and used in the same
expression. The fix is to assign after the print.
sim/h8300/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* compile.c (init_pointers): Fix sequence point warning.
This updates various parts of the sim to include missing system
headers. I made the includes unconditional, because other parts of
the tree are already doing this.
2021-04-08 Tom Tromey <tom@tromey.com>
* traps.c: Include stdlib.h.
* cris-tmpl.c: Include stdlib.h.
sim/erc32/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* func.c: Include sys/time.h.
sim/frv/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* traps.c: Include stdlib.h.
* registers.c: Include stdlib.h.
* profile.c: Include stdlib.h.
* memory.c: Include stdlib.h.
* interrupts.c: Include stdlib.h.
* frv.c: Include stdlib.h.
* cache.c: Include stdlib.h.
sim/iq2000/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* iq2000.c: Include stdlib.h.
sim/m32r/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* traps.c: Include stdlib.h.
* m32r.c: Include stdlib.h.
sim/ppc/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* emul_unix.c: Include time.h.
I ran into a build failure with --enable-targets=all due to the fact that
the moxie sim expects to be able to use the dtc tool. If it isn't available,
the builds fails.
The following patch adds a prebuilt dtb file to the tree. That file is the one
that is used for installations.
The patch also enables (re-)generation of the dtb file through maintainer
mode, if it needs to be updated due to a change in the dts file.
Tested on aarch64-linux/x86_64-linux.
sim/moxie/ChangeLog:
2021-04-08 Luis Machado <luis.machado@linaro.org>
* Makefile.in (moxie-gdb.dtb): Add maintainer mode dependency.
(install-dtb): Install prebuilt dtb file.
* moxie-gdb.dtb: New prebuilt file.
The igen/dgen and opc2c tools leak their heap-allocated memory (on
purpose) at program exit, which makes AddressSanitizer fail the tool
execution. This breaks the build, as it makes the tool return a
non-zero exit code.
Fix that by disabling leak detection through the setting of that
environment variable.
I also changed the opc2c rules for m32c to go through a temporary file.
What happened is that the failing opc2c would produce an incomplete file
(probably because ASan exits the process before stdout is flushed).
This meant that further make attempts didn't try to re-create the file,
as it already existed. A "clean" was therefore necessary. This can
also happen in regular builds if the user interrupts the build (^C) in
the middle of the opc2c execution and tries to resume it. Going to a
temporary file avoids this issue.
sim/m32c/ChangeLog:
* Makefile.in: Set ASAN_OPTIONS when running opc2c.
sim/mips/ChangeLog:
* Makefile.in: Set ASAN_OPTIONS when running igen.
sim/mn10300/ChangeLog:
* Makefile.in: Set ASAN_OPTIONS when running igen.
sim/ppc/ChangeLog:
* Makefile.in: Set ASAN_OPTIONS when running igen.
sim/v850/ChangeLog:
* Makefile.in: Set ASAN_OPTIONS when running igen.
Change-Id: I00f21d4dc1aff0ef73471925d41ce7c23e83e082
Exit status 77 is common (including the autotools world) to indicate
"skip this test". Add support for mapping that to "unsupported" as
that's the closest in the dejagnu world.
If the port hasn't been enabled, don't try to run its tests. Making
this dynamic simplifies the test harnesses and avoids duplicating a
bunch of target tuple checks.
This fixes a problem that occurs when compiled by gcc-10, as the code
is relying on undefined overflow behavior. This is fixed by replacing
compares between 32-bit and 64-bit results with compares that just use
the 64-bit results with a cast.
PR sim/27483
* simulator.c (set_flags_for_add32): Compare uresult against
itself. Compare sresult against itself.
When building with AddressSanitizer, sim/m32c fails with:
./opc2c -l r8c.out /home/simark/src/binutils-gdb/sim/m32c/r8c.opc > r8c.c
sim_log: r8c.out
=================================================================
==3919390==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4 byte(s) in 1 object(s) allocated from:
#0 0x7ffff7677459 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x55555555b3df in main /home/simark/src/binutils-gdb/sim/m32c/opc2c.c:658
#2 0x7ffff741fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
Fix the leak in main by removing the vlist variable, which seems unused.
sim/erc32 uses an obsolete path to the in-tree build of readline.
readline was moved into a subdirectory some time ago. This patch
fixes the problem. Tested by rebuilding.
sim/erc32/ChangeLog
2021-04-05 Tom Tromey <tromey@adacore.com>
* configure: Rebuild.
* configure.ac (READLINE): Adjust in-tree value.
sim/mips/ChangeLog
* interp.c (sim_monitor): Add switch entries for unlink (13),
lseek (14), and stat (15).
Derived from patch authored by Steve Ellcey <sellcey@mips.com>
Provide a simple example simulator for people porting to new targets
to use as a reference. This one has the advantage of being used by
people and having a fun program available for it.
It doesn't require a special target -- the example simulators can be
built for any existing port.
Now that we have the common automake build with support for build-time
programs working, we can integrate the common tests into the default
`make check` flow.
This doesn't actually create one `run` program like other projects,
but creates multiple `run-$arch` targets. While it might not seem
that useful initially, this has some nice properties:
- Allows us to quickly build all sim targets in a single tree.
- Positions us better for converting targets over to a proper
multitarget build+install.
We don't have the ability to actually run tests against them, but
that's due to a limitation in gas: it doesn't support multitarget.
If that ever changes, we should be able to turn on our tests too.
We can improve the test framework to fallback to a system toolchain
if available to help mitigate that.
This simplifies the build a bit (especially for deps in port subdirs),
and avoids recursive make. This in turn speeds up the build, and sets
us up for multi-target.
I see the following error for --target=microblaze-elf:
../../../sim/microblaze/interp.c: In function 'sim_engine_run':
../../../sim/microblaze/interp.c:147:39: error: passing argument 2 of 'get_insn_microblaze' from incompatible pointer type [-Werror=incompatible-pointer-types]
147 | op = get_insn_microblaze (inst, &imm_unsigned, &insn_type,
| ^~~~~~~~~~~~~
| |
| int *
In file included from ../../bfd/bfd.h:45,
from ../../../sim/microblaze/interp.c:24:
../../../sim/microblaze/../../opcodes/microblaze-dis.h:34:57: note: expected '_Bool *' but argument is of type 'int *'
34 | extern enum microblaze_instr get_insn_microblaze (long, bool *,
| ^
sim/microblaze/ChangeLog:
* interp.c (sim_engine_run): Use bool instead of int.
These use the same pattern as seen in the opcodes/ dir and in automake
in general (ish). This helps simplify the boilerplate for building and
linking build-time code, and fixes some inconsistency in flag usage.
For rules that were compiling+linking in a single step, split them into
separate steps so we can apply the correct set of options. This matches
automake behavior too.
The sim's recently switch to using Automake caused a build failure for
me, because I didn't have the correct auto* tools in my path.
However, the rule in the tree is that this is not needed in general.
This patch adds a call to AM_MAINTAINER_MODE, to align the sim with
the way the rest of the tree works here.
sim/ChangeLog
2021-03-08 Tom Tromey <tromey@adacore.com>
* aclocal.m4, configure, Makefile.in: Rebuild.
* configure.ac: Use AM_MAINTAINER_MODE.
This hasn't been initialized anywhere for years. It used to be for
passing in the path to libiberty, but that stopped happening long ago.
Delete it to simplify the build logic.
This local macro doesn't take any args, so adjust the API to match.
No one really noticed as this is behind code that is not normally
built, only when a dev specifically tries to compile it.
While the configure script was checking for a bunch of headers, only
one of them was conditionally included in the source (unistd.h). The
rest were always included. Based on those usage this whole time, we
can reasonably assume that the build also has unistd.h.
All the other files including config.h never actually used any defines
from the header.
Rather than require $AR be set and then default to `ar`, use the
standard AC_CHECK_TOOL helper to find a good prefixed tool. In
practice this shouldn't change much as we seem to have macros in
the tree that were already setting it up, but we shouldn't rely
on that implicitly.
All the scripts were using this implicitly already, so there's no real
change for them, but we want to call it explicitly as the CPP tool is
used to generate nltvals.def.
We don't need a variable to add a dependency to the "all" target, and
having one doesn't really add value. Switch to the target directly for
the few ports that actually use this.
This file is quite large and is getting unmanageable. Split it apart
to follow aclocal best practices by putting one-macro-per-file. There
shouldn't be any real functional changes here as can be seen in the
configure script regens.
This is needed to move to automake & its dejagnu-provided logic,
and eventually by the unified sim logic. The $arch is used only
to figure out which `run` program to use when running tests, and
as we move to a single top-level build, we can delete this and
use sim/run directly.
Current toolchains warn about unused result from fread, so mitigate
the edge case if fread returns short data. It's not great, but it
gets things building again.
Rather than hand maintain m4 includes in various autotool files,
use AC_CONFIG_MACRO_DIRS to declare the relevant search paths.
This simplifies the code, makes it more robust, and cleans out
unused logic from configure.
The rx simulator now has no build warnings. Delete the call to
SIM_AC_OPTION_WARNINGS in configure.ac, the default yes will be
provided by SIM_AC_OUTPUT.
sim/rx/ChangeLog:
* configure: Regenerate.
* configure.ac (SIM_AC_OPTION_WARNINGS): Delete call.
Pointer arithmetic on void * pointers results in a GCC warning. Avoid
the warning by casting the pointer to its actual type earlier in the
function.
sim/rx/ChangeLog:
* mem.c (mem_put_blk): Rename parameter, add cast from parameter
type to local type. Remove cast later in the function.
(mem_get_blk): Likewise.
* mem.h (mem_put_blk): Rename parameter to match definition.
(mem_get_blk): Likewise.
In load.c there's some GCC warnings about undefined
functions (bfd_get_elf_phdr_upper_bound and bfd_get_elf_phdrs). To
get the declarations of these functions include 'elf-bfd.h'. This
headers also pulls in other elf related headers, like 'elf/internal.h'
and 'elf/common.h', so these no longer need to be explicitly included
from load.c.
In trace.c and include for trace.h is missing, again this results in
GCC warnings for missing function declarations.
sim/rx/ChangeLog:
* load.c: Replace 'elf/internal.h' and 'elf/common.h' includes
with 'elf-bfd.h' include.
* trace.c: Add 'trace.h' include.
Silence a GCC compiler warning by using PRIx64 in printf format string
instead of hard coded "llx".
sim/rx/ChangeLog:
* reg.c (trace_register_changes): Use PRIx64 in printf format
string.
For sim code variables still need to be declared at the start of the
enclosing block. This silences a few GCC warnings.
sim/rx/ChangeLog:
* syscalls.c (rx_syscall): Move declaration of some variables to
the start of the enclosing block.
* trace.c (load_file_and_line): Likewise.
Calling printf with the format being a non constant string results in
a GCC warning:
warning: format not a string literal and no format arguments [-Wformat-nonliteral]
Provide a constant format string to printf in the few places this
warning is triggered.
sim/rx/ChangeLog:
* reg.c (fpsw2str): Provide a format string to printf.
(trace_register_changes): Likewise.
Some functions that should be marked static.
sim/rx/ChangeLog:
* fpu.c (check_exceptions): Make static.
* gdb-if.c (handle_step): Likewise.
* mem.c (mem_put_byte): Likewise.
While experimenting with switching on warnings for the rx simulator I
discovered this bug. In sim_do_command we get passed a 'const char *'
argument. We create a copy of this string to work with locally, but
then while processing this we accidentally switch back to reference
the original string.
sim/rx/ChangeLog:
* gdb-if.c (sim_do_command): Work with a copy of the command.
The rx simulator doesn't define sim_memory_map and so fails to link
with GDB. Define it now to return NULL, this can be extended later to
return an actual memory map if anyone wants this functionality.
sim/rx/ChangeLog:
* gdb-if.c (sim_memory_map): New function.
These ports don't use the common sim core, so they weren't providing
a sim_memory_map for gdb, so they failed to link with the new memory
map logic added for the sim. Add stubs to fix.
Few arches implement STATE_WATCHPOINTS()->pc while all of them implement
sim_pc_get. Lets switch the sim-watch core for monitoring pc events to
the sim_pc_get API so this module works for all ports, and then we can
delete this old back channel of snooping in the port's cpu state -- the
code needs the pointer to the pc storage so that it can read out bytes
and compare them to the watchrange.
This also fixes the logic on multi-cpu sims by removing the limitation
of only being able to watch CPU0's state.
The AC_CONFIG_HEADER macro is long deprecated, so switch to the
newer form. This also gets rid of the position limitation, and
drops support for an argument to SIM_AC_COMMON which we haven't
used anywhere.
These settings might have made sense in darker compiler times, but I
think they're largely obsolete now. Looking through the values that
get used in HDEFINES, it's quite limited, and configure itself should
handle them. If we still need something, we can leverage standard
autoconf macros instead, after we get a clear user report.
TDEFINES was never set anywhere and was always empty, so prune that.
This is a hand-written implementation that should have fairly complete
coverage for the base integer instruction set ("i"), and for the atomic
("a") and integer multiplication+division ("m") extensions. It also
covers 32-bit & 64-bit targets.
The unittest coverage is a bit weak atm, but should get better.
We renamed these years ago, but it looks like the cgen core missed the
TRACE_EXTRACT function, so these new ports still used the incompatible
common name. Fix those ports to use the right func.
When compiling we get the following warnings:
common/cgen-accfp.c: In function 'fixsfsi':
common/cgen-accfp.c:370:18: warning: pointer targets in passing argument 1 of 'sim_fpu_to32i' differ in signedness [-Wpointer-sign]
sim_fpu_to32i (&res, &op1, sim_fpu_round_near);
^
common/cgen-accfp.c: In function 'fixdfsi':
common/cgen-accfp.c:381:18: warning: pointer targets in passing argument 1 of 'sim_fpu_to32i' differ in signedness [-Wpointer-sign]
sim_fpu_to32i (&res, &op1, sim_fpu_round_near);
^
This port only had one minor warning left in it, so fix it and then
enable -Werror behavior by deleting the macro call. We'll use the
common default now (which is -Werror).
My recent rewrite of the nltvals generator fixed a bug where SYS_times
was not being exported for v850. But that in turn uncovered this bug
where the SYS_times codepath had a compile error.
This port only had one minor warning left in it, so fix it and then
enable -Werror behavior by deleting the macro call. We'll use the
common default now (which is -Werror).
Existing ports already have sizeof_pc set to the same size as sim_cia,
so simply make that part of the core code. We already assume this in
places by way of sim_pc_{get,set}, and this is how it's documented in
the sim-base.h API.
There is code to allow sims to pick different register word sizes from
address sizes, but most ports use the defaults for both (32-bits), and
the few that support multiple register sizes never change the address
size (so address defaults to register). I can't think of any machine
where the register hardware size would be larger than the address word
size either. We have ABIs that behave that way (e.g. x32), but the
hardware is still equivalent register sized.
When the target's PC is 64-bits, this shift expands into a range of
8 * 8 - 1 which doesn't work with 32-bit constants. Force it to be
a 64-bit value all the time and let the compiler truncate it.
This port doesn't build if these hardware modules are omitted, and
there's no reason we need to make it conditional at build time, so
always enable it. The hardware devices only get turned on if the
user requests it at runtime via hardware settings.
This wasn't supposed to be in here when it was first merged as we
had specifically disabled it for all the tests (and ADI has papers
in place w/the FSF). Clean up this one.
This was mostly orphaned a while back, but left behind so people could
still run `make headers`. Merge that one target to the top sim dir and
delete all the build logic. This should avoid confusing people further.
It's not 1996 anymore, so stop writing shell code like it is, and
rewrite it with modern POSIX shell standards. This makes it much
more user friendly.
Then regenerate the file with latest newlib sources to verify.
Now that all port tests live under testsuite/sim/*/, and none live
in testsuite/ directly, flatten the structure by moving all of the
dirs under testsuite/sim/ to testsuite/ directly.
We need to stop passing --tool to dejagnu so that it searches all
dirs and not just ones that start with "sim". Since we have no
other dirs in this tree, and no plans to add any, should be fine.
Now that we've moved all ports to dejagnu & testsuite/sim/, the only
thing the testsuite/configure script has been doing is filling in the
sim_arch field in the testsuite/Makefile. We can simply let the top
sim/configure script do that for us now. This simplifies & speeds up
the build a bit by killing an entire configure script.
This is the only target using a dir directly under testsuite/. All
others use sim/<arch>/ instead. Relocate it so all targets look the
same, and so we can leverage the common test harness.
We drop loop.s in the process because it was never referenced and
was just 2 lines of code.
All other test files are moved & have directives added to the top so
that the test harness can invoke them correctly.
No tests were ever added in here in the ~22 years since it was first
created. Seems unlikely any tests will be added at this rate, and
the sim/mips/ testdir already has some (light) coverage for this
target. So punt the tree.
The frv-elf subdir contained five tests:
* cache: A cache test of some sort.
* exit47: A program to test exit status of 47 from sim.
* grloop: Some basic limited loop test program.
* hello: Standard "hello world" output program.
* loop: An infinite loop program.
The loop.s test is never referenced anywhere, and is all of 2 lines.
Anyone who really needs a while(1); test case and re-implement it
themselves locally.
The cache.s code isn't referenced anywhere because it requires some
custom args to the run program, and when this testcase was added, we
didn't have any support for that. We do now, so we can add a header
to enable that. Turns out the code crashes even with those, so turn
around and mark it xfail. Maybe someone someday will care.
That leaves the small exit47, grloop, and hello tests. Now that the
sim test harness supports testing for custom exit status, we can move
them all to sim/frv/ to maintain test coverage.
The remaining differences between frv-elf & sim/frv are:
* frv-elf/ runs for frv-*-elf while sim/frv/ runs for frv*-*-*.
* frv-elf/ runs "*.s" files while sim/frv/ only has .cgs and such.
On closer inspection, these are also meaningless distinctions:
* There is nothing specific to the tests that require an *-elf
target. Normally that would mean newlib+libgloss type stuff,
but there's no such requirement in frv-elf/.
* The ".s" suffix is the standard "this is an assembly file" suffix.
Since FRV is a CGEN target, we can reuse the existing convention of
".ms" to mean "miscellaneous .s" as in "this is an assembly file,
and run/bucket its test results in the miscellaneous category".
So moving frv-elf/{cache,exit47,grloop,hello}.s to sim/frv/*.ms makes
sense and simplifies things quite a bit for the target while also
slightly increasing the coverage for some tuples.
The m32r-elf subdir contained three tests:
* exit47: A program to test exit status of 47 from sim.
* hello: Standard "hello world" output program.
* loop: An infinite loop program.
There's already a sim/m32r/hello.ms test that does exactly the same
thing as m32r-elf/hello.s, so we can delete that.
The loop.s test is never referenced anywhere, and is all of 2 lines.
Anyone who really needs a while(1); test case and re-implement it
themselves locally.
That leaves the single exit47 test. Now that the sim test harness
supports testing for custom exit status, we can easily move that to
sim/m32r/exit47.ms to maintain test coverage.
The remaining differences between m32r-elf & sim/m32r are:
* m32r-elf/ runs for m32r-*-elf while sim/m32r/ runs for m32r*-*-*.
* m32r-elf/ runs "*.s" files while sim/m32r/ runs "*.ms" files.
On closer inspection, these are also meaningless distinctions:
* There is nothing specific to the tests that require an *-elf
target. Normally that would mean newlib+libgloss type stuff,
but there's no such requirement in m32r-elf/.
* The ".s" suffix is the standard "this is an assembly file"
suffix. Turns out ".ms" is just how sim/m32r/ (and a few other
CGEN based targets) categorize/bucket test cases. It simply
means "miscellaneous .s" as in "this is an assembly file, and
run/bucket its test results in the miscellaneous category".
So moving m32r-elf/exit47.s to sim/m32r/exit47.ms makes sense and
simplifies things quite a bit for the target while also slightly
increasing the coverage for some tuples.
Some tests want to verify they can control the exit status, and
allowing any non-zero value would allow tests to silently fail:
if it crashed & exited 1, or forced all non-zero to 1, then we
wouldn't be able to differentiate with a test exiting with a
status like 47.
Extend the test harness to allow tests to declare their expected
exit status that would be defined as a "pass". This requires a
small tweak to the sim_run API to return the status directly, but
that shouldn't be a big deal as it's only used by sim code.
The h8300 sim has its own implementation for memory handling that I'd
like to replace with the common sim memory code. However, it's got a
weird bit of code it calls "eightbit mem" that makes this not as easy
as it would otherwise be. The code has this comment:
/* These define the size of main memory for the simulator.
Note the size of main memory for the H8/300H is only 256k. Keeping it
small makes the simulator run much faster and consume less memory.
The linker knows about the limited size of the simulator's main memory
on the H8/300H (via the h8300h.sc linker script). So if you change
H8300H_MSIZE, be sure to fix the linker script too.
Also note that there's a separate "eightbit" area aside from main
memory. For simplicity, the simulator assumes any data memory reference
outside of main memory refers to the eightbit area (in theory, this
can only happen when simulating H8/300H programs). We make no attempt
to catch overlapping addresses, wrapped addresses, etc etc. */
I've read the H8/300 Programming Manual and the H8/300H Software Manual
and can't find documentation on it. The closest I can find is the bits
about the exception vectors, but that sounds like a convention where the
first 256 bytes of memory are used for a special purpose. The sim will
actually allocate a sep memory buffer of 256 bytes and you address it by
accessing anywhere outside of main memory. e.g. I would expect code to
access it like:
uint32_t *data = (void *)0;
data[0] = reset_exception_vector;
not like the sim expects like:
uint8_t *data = (void *)0x1000000;
data[0] = ...;
The gcc manual has an "eightbit_data" attribute:
Use this attribute on the H8/300, H8/300H, and H8S to indicate that
the specified variable should be placed into the eight-bit data
section. The compiler generates more efficient code for certain
operations on data in the eight-bit data area. Note the eight-bit
data area is limited to 256 bytes of data.
And the gcc code implies that it's accessed via special addressing:
eightbit_data: This variable lives in the 8-bit data area and can
be referenced with 8-bit absolute memory addresses.
I'm fairly certain these are referring to the 8-bit addressing modes
that allow access to 0xff00 - 0xffff with only an 8-bit immediate.
They aren't completely separate address spaces which this eightbit
memory buffer occupies.
But the sim doesn't access its eightbit memory based on specific insns,
it does it purely on the addresses requested.
Unfortunately, much of this code was authored by Michael Snyder, so I
can't ask him :(. I asked Renesas support and they didn't know:
https://renesasrulz.com/the_vault/f/archive-forum/6952/question-about-eightbit-memory
So I've come to the conclusion that this was a little sim-specific hack
done for <some convenience> and has no relation to real hardware. And
as such, let's drop it until someone notices and can provide a reason
for why we need to support it.
The default watchpoint handler is NULL. That means any port that
sets the STATE_WATCHPOINTS->pc field will crash if you try to use
the --watch options but don't configure the interrupt handler. In
the past, you had to setup STATE_WATCHPOINTS->pc if you wanted to
support PC profiling, and while that was fixed a while ago, we have
a lot of ports who still configure it.
We already add a default set of interrupts (just "int") if the port
doesn't define any. Let's also add a default handler that raises a
SIGTRAP. When connected to gdb, this is a breakpoint which is what
people would expect. When running standalone, it'll abort the sim,
but it's unclear whether there's anything better to do there. This
really is just to make the watchpoint module more usable out of the
box for most ports with very little setup, at least inside of gdb.
The code supports a <start>[,<end>] syntax, but the logic for handling
the <end> check was broken: it would detect the first byte was ",", but
then include that in the strtoul call meaning the result is always 0.
Further, it (re)assigned to arg0 when it meant arg1 which means this
code always processed a range expression as 0,0. Oops.
My change 1ac72f0659 ("sim: convert to
bfd_endian") subtly broke the watchpoint module on little endian host
systems. The old code used 0 to mean "whatever the host endian is",
and while that was changed to use BFD_ENDIAN_UNKNOWN, this caller was
missed. Since its API used an int instead of an enum, the coercion
from 0 to the BFD endian enum was silently missed, and 0 happens to
be BFD_ENDIAN_BIG.
Instead of restoring the old logic by passing in BFD_ENDIAN_UNKNOWN,
we know the right host endian at compile time, so use that directly.
These were written with 32-bit host assumptions baked into it.
Simplify the printf formats to use ll length modifier as it's
in C11 rather than trying to manually break it up into two,
and cleanup some of the casts to stop assuming sizeof(long) is
the same as sizeof(int).
We also have to add a few more includes for the various funcs
used in here.
The tests aren't compiled automatically still. We can figure
that out later with more work.
Now that all ports have opted in to this, we can require it in the
core. It guarantees that new ports have them turned on, and defaults
to -Werror in the hopes that new ports keep their code clean from the
start. We do this as a sep commit to make it clear that there are no
changes to existing ports as they've all explicitly called it already.
We want all ports to opt into extra warnings as the default compiler
settings lets a lot slide. Opt all the ports that haven't already in
to the warning system. None of them build with -Werror, so disable
that by default. Hopefully someone finds these important enough to
start fixing at some point.
Make sure config.h is included before C library headers otherwise the
later libiberty.h include gets confused about asprintf state leading
to warnings like:
common/sim-utils.c:330:9:
warning: implicit declaration of function 'vasprintf';
did you mean 'xvasprintf'? [-Wimplicit-function-declaration]
For 32-bit targets, %x happens to work for unsigned_word. But for
64-bit targets, it's too small, and gcc throws an error. Use the
right printf format define for them.
This port declares its pc variable in a header and then includes
it multiple times. This causes linker errors with newer gcc due
to the change in -fno-common behavior. Move the storage to a C
file so we only have one instance of it in the final program.
Since we require C11 now, we can assume many headers exist, and
clean up all of the conditional includes. It's not like any of
this code actually accounted for the headers not existing, just
whether we could include them.
The strings.h cleanup is a little nuanced: it isn't in C11, but
every use of it in the codebase will include strings.h only if
string.h doesn't exist. Since we now assume the C11 string.h
exists, we'll never include strings.h, so we can delete it.
These ports declare their State variable in a header and then include
multiple times. This causes linker errors with newer gcc due to the
change in -fno-common behavior. Move the storage to a C file so we
only have one instance of it in the final program.
We've had this off for a long time because the sim code was way too
full of warnings for it to be feasible. However, I've cleaned things
up significantly from when this was first merged, and we can start to
turn this around.
Change the macro to enable -Werror by default, and allow ports to opt
out. New ports will get it automatically (and we can push back on
them if they try to turn it off).
Also turn it off for the few ports that still hit warnings for me.
All the rest will get the new default, and we'll wait for feedback
if/when new issues come up.
Make sure config.h is included before C library headers otherwise the
later libiberty.h include gets confused about asprintf state leading
to warnings like:
common/sim-utils.c:330:9:
warning: implicit declaration of function 'vasprintf';
did you mean 'xvasprintf'? [-Wimplicit-function-declaration]
Newer gcc thinks we might return a pointer to a stack buffer, but
we don't -- we strdup it before returning. Rework the code to just
malloc the buffer from the start and avoid the stack+strdup.
With GDB requiring a C++11 compiler now, this hopefully shouldn't
be a big deal. It's been 10 years since C11 came out, so should
be plenty of time to upgrade.
This will allow us to start cleaning up random header logic and
many of our non-standard custom types.
We don't want arch-specific entries in the common ChangeLog files.
Most arches do this already, so clean up the recent additions, and
move some older entries down to help avoid confusing newcomers.
PR ld/13900
Linking this test crashes the linker, so disable it. The crash
was reported about 9 years ago but haven't made progress, so lets
avoid the failures in test runs.
Building the C tests with a cris-elf toolchain (gcc-10.2 &
newlib-4.1.0) currently fail due to warnings it emits:
cris-elf-ld: libc.a(lib_a-closer.o): in function `_close_r':
newlib/libc/reent/closer.c:47: warning: _close is not implemented and will always fail
This is because the default target for cris-elf is bare metal, not
the simulator. For that, we need -sim. So add it for elf targets.
We don't add it for all targets as the simulator (and testsuite)
run both libgloss programs as well as Linux userspace programs.
This is in preparation for converting h8300 over to the common memory
framework. It's not clear how much of a speed gain this was providing
in the first place -- a naive test of ~400k insns (using shlr.s) shows
that this code actually slowed things down a bit.
If anyone really cares about h8300 anymore, they can migrate to the
common insn caching logic.
This allows gdb to quickly dump & process the memory map that the sim
knows about. This isn't fully accurate, but is largely limited by the
gdb memory map format. While the sim supports RWX bits, gdb can only
handle RW or RO regions.
Make sure we include unistd.h for getpid prototypes to fix build
warnings/errors with newer compilers & C libraries.
Doing that for close in openpf highlights these were using the
wrong function -- need to use fclose on FILE*, not close.
These tests pass again with a cris-elf toolchain.
Looking through the history, it doesn't seem like the fr30 port was
ever merged. There used to be a testsuite/fr30-elf/ dir, but that
was punted back in 2005 as being dead too. Since there's no refs
and the dir hasn't been touched since 1999, lets assume no one will
ever notice or care.
These tests all fail to assemble when targeting the h8300 or h8300h
cpu variants with errors like:
rotl.s:242: Warning: Opcode `rotl.b' with these operand types not available in H8/300H mode
rotl.s:242: Error: invalid operands
It's been this way for years and no one seems to care, so disable
them for those targets since the assembler thinks it's impossible.
We don't need to manually enumerate every test. Use a glob function
like every other port and rely on the (already existing) #mach headers
in each file to filter out targets we don't care about.
Make sure the files using atoi() include stdlib.h for its prototype.
These files were relying on it being included implicitly by others
which isn't guaranteed, and newer toolchains produce warnings.
Make sure the files using abs() include stdlib.h for its prototype.
These files were relying on it being included implicitly by others
which isn't guaranteed, and newer toolchains produce warnings.
This mirrors gdb behavior of dumping extra info when being run in
interactive mode. It also gives us an excuse to use the otherwise
unused sim_print_config.
We have ALIGN_{8,16,PAGE} and FLOOR_PAGE macros (where PAGE is defined as
4k) which were imported from the ppc sim. But no other sim utilizes these
and hardcoding the sizes in the name is a bit limiting.
Let's delete these and import the two general macros that gdb uses:
align_up(addr, bytes)
align_down(addr, bytes)
This in turn allows us to cut over the Blackfin code immediately.