From b2230bacf95e519f990b5dfff3d77069707799ab 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: Mon, 24 Sep 2018 09:26:39 +0100 Subject: [PATCH] gem5 semihosting --- README.adoc | 16 +++------------- .../arch/aarch64/no_bootloader/semihost_exit.S | 10 ++++++++++ baremetal/interactive/README.adoc | 1 + baremetal/interactive/exit1.c | 6 ++++++ build-baremetal | 8 ++++++++ patches/manual/gem5-semihost.patch | 12 ++++++++++++ 6 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 baremetal/arch/aarch64/no_bootloader/semihost_exit.S create mode 100644 baremetal/interactive/README.adoc create mode 100644 baremetal/interactive/exit1.c create mode 100644 patches/manual/gem5-semihost.patch diff --git a/README.adoc b/README.adoc index 3b1baf3..ec62170 100644 --- a/README.adoc +++ b/README.adoc @@ -747,6 +747,7 @@ Alternatively, for the sake of tab completion, we also accept full paths inside To use gem5 instead of QEMU do: .... +patch -d "$(./getvar gem5_src_dir)" -p 1 < patches/manual/gem5-semihost.patch && \ ./configure --baremetal --gem5 && \ ./build-gem5 --arch arm && \ ./build-crosstool-ng --arch arm && \ @@ -761,10 +762,9 @@ and then <> open a shell with: ./gem5-shell .... -TODO: +TODO: the carriage returns are a bit different than in QEMU, see: <>. -* the carriage returns are a bit different than in QEMU, see: <>. -* semihosting is disabled, and all examples that rely on it fail, including how to enable it? See <> +The semihosting patch is required to enable <>, on which base functionality such as `exit()` depends, see also: https://stackoverflow.com/questions/52475268/how-to-enable-arm-semihosting-in-gem5/52475269#52475269 Note that `./build-baremetal` requires the `--gem5` option, and generates separate executable images for both, as can be seen from: @@ -9821,16 +9821,6 @@ Bibliography: * https://stackoverflow.com/questions/31990487/how-to-cleanly-exit-qemu-after-executing-bare-metal-program-without-user-interve/40957928#40957928 * https://balau82.wordpress.com/2010/11/04/qemu-arm-semihosting/ -==== gem5 semihosting - -TODO how to enable it? <> contains: - -.... -root.system.semihosting=Null -.... - -and there are no hits under `configs/`. - === gem5 baremetal carriage return TODO: our example is printing newlines without automatic carriage return `\r` as in: diff --git a/baremetal/arch/aarch64/no_bootloader/semihost_exit.S b/baremetal/arch/aarch64/no_bootloader/semihost_exit.S new file mode 100644 index 0000000..b0e1d88 --- /dev/null +++ b/baremetal/arch/aarch64/no_bootloader/semihost_exit.S @@ -0,0 +1,10 @@ +.global mystart +mystart: + mov x1, #0x26 + movk x1, #2, lsl #16 + str x1, [sp,#0] + mov x0, #0 + str x0, [sp,#8] + mov x1, sp + mov w0, #0x18 + hlt 0xf000 diff --git a/baremetal/interactive/README.adoc b/baremetal/interactive/README.adoc new file mode 100644 index 0000000..74158eb --- /dev/null +++ b/baremetal/interactive/README.adoc @@ -0,0 +1 @@ +This folder contains examples that are not very testable: either are supposed to return 0, or are interactive, etc. diff --git a/baremetal/interactive/exit1.c b/baremetal/interactive/exit1.c new file mode 100644 index 0000000..35a9780 --- /dev/null +++ b/baremetal/interactive/exit1.c @@ -0,0 +1,6 @@ +#include +#include + +void main(void) { + exit(1); +} diff --git a/build-baremetal b/build-baremetal index f7b7410..3dc5887 100755 --- a/build-baremetal +++ b/build-baremetal @@ -119,6 +119,14 @@ def main(args, extra_args=None): bootloader_obj=bootloader_obj, common_obj=common_obj, ) + build_dir( + 'interactive', + gcc=gcc, + cflags=cflags, + entry_address=entry_address, + bootloader_obj=bootloader_obj, + common_obj=common_obj, + ) arch_dir = os.path.join('arch', args.arch) if os.path.isdir(os.path.join(common.baremetal_src_dir, arch_dir)): build_dir( diff --git a/patches/manual/gem5-semihost.patch b/patches/manual/gem5-semihost.patch new file mode 100644 index 0000000..3f02a31 --- /dev/null +++ b/patches/manual/gem5-semihost.patch @@ -0,0 +1,12 @@ +diff --git a/configs/example/fs.py b/configs/example/fs.py +index 3997ed76c..43bebcd66 100644 +--- a/configs/example/fs.py ++++ b/configs/example/fs.py +@@ -376,5 +376,7 @@ if buildEnv['TARGET_ISA'] == "arm" and options.generate_dtb: + sys = getattr(root, sysname) + sys.dtb_filename = create_dtb_for_system(sys, '%s.dtb' % sysname) + ++from m5.objects import ArmSemihosting ++test_sys.semihosting = ArmSemihosting() + Simulation.setWorkCountOptions(test_sys, options) + Simulation.run(options, root, test_sys, FutureClass)