* [PATCH v3] sim: riscv: Fix some compatibility issues with gcc
@ 2024-04-15 8:41 Bernd Edlinger
2024-06-21 15:00 ` Andrew Burgess
0 siblings, 1 reply; 2+ messages in thread
From: Bernd Edlinger @ 2024-04-15 8:41 UTC (permalink / raw)
To: gdb-patches, Andrew Burgess
This makes the riscv simulator able to execute a simple
"hello world" program when gcc is configured
with:
.../gcc-trunk/configure --target=riscv-unknown-elf
The first problem is that gcc generates rv32
code by default in this configuration, while
riscv64-unknown-elf generates rv64 code by default.
Note that using the command line argument
--architecture riscv:rv32 is not really working,
because compile-time constants like
WITH_TARGET_WORD_BITSIZE and architecture dependent
types like unsigned_word are used everywhere.
So change the riscv/acinclude.m4 to use the same
logic here, and disable selecting non-working
architectures per command line argument.
The second issue is that gcc does by default
generate instructions in INSN_CLASS_C, so move
the M(GC) to top of list, in riscv/model_list.def.
This changes the default cpu-model to include the
class c instructions when no --model command line
argument is used.
With these changes a simple C-program can be executed,
however there is still work to do, since when the
program does floating point operations, gcc starts to
generate hardware floating point instructions, with no
obvious opt-out option.
Note the gcc test suite can be used to test the
simulator in this way:
make check-gcc RUNTESTFLAGS="--target_board=multi-sim SIM=riscv-unknown-elf-run"
Now many tests are passed, except those which use
floating point instructions.
To work around the not supported float instructions the
following gcc configuration can be used, which makes
most of the gcc test cases successfully executed:
.../gcc-trunk/configure --prefix=... --target=riscv-unknown-elf
--disable-multilib --with-arch=rv32imac --with-abi=ilp32
Note: binutils are installed at prefix path and newlib/libgloss in-tree.
---
sim/configure | 6 +++---
sim/riscv/acinclude.m4 | 4 ++--
sim/riscv/machs.c | 2 +-
sim/riscv/model_list.def | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
v2: updated the commit message, with some hints
how to compile a compatible gcc toolchain.
v3: addressed review commments, disable non-working
--architecture command line options, split out the fix
for class-c instructions.
diff --git a/sim/configure b/sim/configure
index 1ebef377973..fdc0a86d524 100755
--- a/sim/configure
+++ b/sim/configure
@@ -17479,10 +17479,10 @@ $as_echo "$sim_ppc_xor_endian" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking riscv bitsize" >&5
$as_echo_n "checking riscv bitsize... " >&6; }
-SIM_RISCV_BITSIZE=64
+SIM_RISCV_BITSIZE=32
case $target in #(
- riscv32*) :
- SIM_RISCV_BITSIZE=32 ;; #(
+ riscv64*) :
+ SIM_RISCV_BITSIZE=64 ;; #(
*) :
;;
esac
diff --git a/sim/riscv/acinclude.m4 b/sim/riscv/acinclude.m4
index 0c6290c9c08..e9953c1017d 100644
--- a/sim/riscv/acinclude.m4
+++ b/sim/riscv/acinclude.m4
@@ -15,8 +15,8 @@ dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
dnl
dnl NB: This file is included in sim/configure, so keep settings namespaced.
AC_MSG_CHECKING([riscv bitsize])
-SIM_RISCV_BITSIZE=64
+SIM_RISCV_BITSIZE=32
AS_CASE([$target],
- [riscv32*], [SIM_RISCV_BITSIZE=32])
+ [riscv64*], [SIM_RISCV_BITSIZE=64])
AC_MSG_RESULT([$SIM_RISCV_BITSIZE])
AC_SUBST(SIM_RISCV_BITSIZE)
diff --git a/sim/riscv/machs.c b/sim/riscv/machs.c
index 77ae000e7a5..98b790e8a52 100644
--- a/sim/riscv/machs.c
+++ b/sim/riscv/machs.c
@@ -120,7 +120,7 @@ const SIM_MACH * const riscv_sim_machs[] =
#if WITH_TARGET_WORD_BITSIZE >= 64
&rv64i_mach,
#endif
-#if WITH_TARGET_WORD_BITSIZE >= 32
+#if WITH_TARGET_WORD_BITSIZE == 32
&rv32i_mach,
#endif
NULL
diff --git a/sim/riscv/model_list.def b/sim/riscv/model_list.def
index b83557e5539..df9ec897126 100644
--- a/sim/riscv/model_list.def
+++ b/sim/riscv/model_list.def
@@ -1,9 +1,9 @@
+M(GC)
M(G)
M(I)
M(IM)
M(IMA)
M(IA)
-M(GC)
M(IC)
M(IMC)
M(IMAC)
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3] sim: riscv: Fix some compatibility issues with gcc
2024-04-15 8:41 [PATCH v3] sim: riscv: Fix some compatibility issues with gcc Bernd Edlinger
@ 2024-06-21 15:00 ` Andrew Burgess
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2024-06-21 15:00 UTC (permalink / raw)
To: Bernd Edlinger, gdb-patches
Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> This makes the riscv simulator able to execute a simple
> "hello world" program when gcc is configured
> with:
>
> .../gcc-trunk/configure --target=riscv-unknown-elf
>
> The first problem is that gcc generates rv32
> code by default in this configuration, while
> riscv64-unknown-elf generates rv64 code by default.
> Note that using the command line argument
> --architecture riscv:rv32 is not really working,
> because compile-time constants like
> WITH_TARGET_WORD_BITSIZE and architecture dependent
> types like unsigned_word are used everywhere.
>
> So change the riscv/acinclude.m4 to use the same
> logic here, and disable selecting non-working
> architectures per command line argument.
I've read your reply here[1], I don't think my position has changed.
I think the problems you're running into simulating RV32 code should be
fixed in the simulator using masking or sign extension as needed.
I don't think we should change the default to RV32 only.
[1] https://inbox.sourceware.org/gdb-patches/AS8P193MB1285D90C8EE298DF19F958D9E4042@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM
>
> The second issue is that gcc does by default
> generate instructions in INSN_CLASS_C, so move
> the M(GC) to top of list, in riscv/model_list.def.
>
> This changes the default cpu-model to include the
> class c instructions when no --model command line
> argument is used.
If you wanted to split this second issue out then I'll be happy to
approve this as I agree that this change makes sense.
Thanks,
Andrew
>
> With these changes a simple C-program can be executed,
> however there is still work to do, since when the
> program does floating point operations, gcc starts to
> generate hardware floating point instructions, with no
> obvious opt-out option.
>
> Note the gcc test suite can be used to test the
> simulator in this way:
>
> make check-gcc RUNTESTFLAGS="--target_board=multi-sim SIM=riscv-unknown-elf-run"
>
> Now many tests are passed, except those which use
> floating point instructions.
>
> To work around the not supported float instructions the
> following gcc configuration can be used, which makes
> most of the gcc test cases successfully executed:
>
> .../gcc-trunk/configure --prefix=... --target=riscv-unknown-elf
> --disable-multilib --with-arch=rv32imac --with-abi=ilp32
>
> Note: binutils are installed at prefix path and newlib/libgloss in-tree.
> ---
> sim/configure | 6 +++---
> sim/riscv/acinclude.m4 | 4 ++--
> sim/riscv/machs.c | 2 +-
> sim/riscv/model_list.def | 2 +-
> 4 files changed, 7 insertions(+), 7 deletions(-)
>
> v2: updated the commit message, with some hints
> how to compile a compatible gcc toolchain.
>
> v3: addressed review commments, disable non-working
> --architecture command line options, split out the fix
> for class-c instructions.
>
> diff --git a/sim/configure b/sim/configure
> index 1ebef377973..fdc0a86d524 100755
> --- a/sim/configure
> +++ b/sim/configure
> @@ -17479,10 +17479,10 @@ $as_echo "$sim_ppc_xor_endian" >&6; }
>
> { $as_echo "$as_me:${as_lineno-$LINENO}: checking riscv bitsize" >&5
> $as_echo_n "checking riscv bitsize... " >&6; }
> -SIM_RISCV_BITSIZE=64
> +SIM_RISCV_BITSIZE=32
> case $target in #(
> - riscv32*) :
> - SIM_RISCV_BITSIZE=32 ;; #(
> + riscv64*) :
> + SIM_RISCV_BITSIZE=64 ;; #(
> *) :
> ;;
> esac
> diff --git a/sim/riscv/acinclude.m4 b/sim/riscv/acinclude.m4
> index 0c6290c9c08..e9953c1017d 100644
> --- a/sim/riscv/acinclude.m4
> +++ b/sim/riscv/acinclude.m4
> @@ -15,8 +15,8 @@ dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
> dnl
> dnl NB: This file is included in sim/configure, so keep settings namespaced.
> AC_MSG_CHECKING([riscv bitsize])
> -SIM_RISCV_BITSIZE=64
> +SIM_RISCV_BITSIZE=32
> AS_CASE([$target],
> - [riscv32*], [SIM_RISCV_BITSIZE=32])
> + [riscv64*], [SIM_RISCV_BITSIZE=64])
> AC_MSG_RESULT([$SIM_RISCV_BITSIZE])
> AC_SUBST(SIM_RISCV_BITSIZE)
> diff --git a/sim/riscv/machs.c b/sim/riscv/machs.c
> index 77ae000e7a5..98b790e8a52 100644
> --- a/sim/riscv/machs.c
> +++ b/sim/riscv/machs.c
> @@ -120,7 +120,7 @@ const SIM_MACH * const riscv_sim_machs[] =
> #if WITH_TARGET_WORD_BITSIZE >= 64
> &rv64i_mach,
> #endif
> -#if WITH_TARGET_WORD_BITSIZE >= 32
> +#if WITH_TARGET_WORD_BITSIZE == 32
> &rv32i_mach,
> #endif
> NULL
> diff --git a/sim/riscv/model_list.def b/sim/riscv/model_list.def
> index b83557e5539..df9ec897126 100644
> --- a/sim/riscv/model_list.def
> +++ b/sim/riscv/model_list.def
> @@ -1,9 +1,9 @@
> +M(GC)
> M(G)
> M(I)
> M(IM)
> M(IMA)
> M(IA)
> -M(GC)
> M(IC)
> M(IMC)
> M(IMAC)
> --
> 2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-21 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 8:41 [PATCH v3] sim: riscv: Fix some compatibility issues with gcc Bernd Edlinger
2024-06-21 15:00 ` Andrew Burgess
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).