From 7d32b26fdee26852b832e41b8e59f0f21b5926c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 16 Jun 2020 01:00:00 +0000 Subject: [PATCH] gem5 arm cli args not working --- README.adoc | 6 ++++++ baremetal/lib/arm.S | 11 +++++++++++ common.py | 4 +++- run | 7 ++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 0dbde6b..aac2287 100644 --- a/README.adoc +++ b/README.adoc @@ -22095,6 +22095,12 @@ This works by: It is worth noting that e.g. ARM has a <> mechanism for loading CLI arguments through `SYS_GET_CMDLINE`, but our mechanism works in principle for any ISA. +==== gem5 baremetal arm CLI args + +Currently not supported, so we just hardcode argc 0 on the <>. + +I think we have to keep the CLI args below 32 GiB, otherwise argc cannot be correctly setup. But currently the gem5 text segment is exactly at 32 GiB, and we always place the CLI args higher in the <>. + === Semihosting Semihosting is a publicly documented interface specified by ARM Holdings that allows us to do some magic operations very useful in development, such as writting to the terminal or reading and writing host files. diff --git a/baremetal/lib/arm.S b/baremetal/lib/arm.S index 8fd7345..b8c365d 100644 --- a/baremetal/lib/arm.S +++ b/baremetal/lib/arm.S @@ -29,6 +29,17 @@ _start: /* Run main. */ mov r0, 0 + +#if 0 + /* Just turn CLI args off for now since not supported. + * https://cirosantilli.com/linux-kernel-module-cheat#gem5-baremetal-arm-cli-args */ + ldr r0, =lkmc_argc + ldr r0, [r0] + ldr r1, =lkmc_argv +#else + /* Run main. */ + mov r0, 0 +#endif bl main /* If main returns, exit. */ diff --git a/common.py b/common.py index f9f3bb0..e96b1c9 100644 --- a/common.py +++ b/common.py @@ -790,7 +790,9 @@ Incompatible archs are skipped. # just too many, and gem5 does not allow selecting lower feature in general. env['int_size'] = 4 if env['arch'] == 'arm': - env['address_size'] = 4 + # TODO this shoud be 4. But that blows up running all gem5 arm 32-bit examples. + # https://cirosantilli.com/linux-kernel-module-cheat#gem5-baremetal-arm-cli-args + env['address_size'] = 8 env['armv'] = 7 env['buildroot_toolchain_prefix'] = 'arm-buildroot-linux-gnueabihf' env['crosstool_ng_toolchain_prefix'] = 'arm-unknown-eabi' diff --git a/run b/run index 98cd9b9..518c532 100755 --- a/run +++ b/run @@ -494,7 +494,12 @@ Extra options to append at the end of the emulator command line. argv_addr_data = [] argv_addr_cur = argv_data_addr for arg in cli_args: - argv_addr_data.append(struct.pack('<{}'.format(self.python_struct_int_format(self.env['address_size'])), argv_addr_cur)) + argv_addr_data.append(struct.pack( + '<{}'.format( + self.python_struct_int_format(self.env['address_size']) + ), + argv_addr_cur + )) argv_addr_cur += len(arg) + 1 baremetal_cli_path = os.path.join(self.env['run_dir'], 'baremetal_cli.raw') with open(baremetal_cli_path, 'wb') as f: