userland/freestanding/gem5_* work on baremetal

Remove all the duplicates of those present throughout the tree.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-03-26 00:00:01 +00:00
parent 05a07fc0a8
commit e1d0a2fafb
9 changed files with 27 additions and 32 deletions

View File

@@ -11321,13 +11321,13 @@ since boot has already happened, and the parameters are already in the RAM of th
==== gem5 checkpoint userland minimal example ==== gem5 checkpoint userland minimal example
In order to debug checkpoint restore bugs, this minimal setup using link:userland/freestanding/gem5_checkpoint_restore.S[] can be handy: In order to debug checkpoint restore bugs, this minimal setup using link:userland/freestanding/gem5_checkpoint.S[] can be handy:
.... ....
./build-userland --arch aarch64 --static ./build-userland --arch aarch64 --static
./run --arch aarch64 --emulator gem5 --static --userland userland/freestanding/gem5_checkpoint_restore.S --trace-insts-stdout ./run --arch aarch64 --emulator gem5 --static --userland userland/freestanding/gem5_checkpoint.S --trace-insts-stdout
./run --arch aarch64 --emulator gem5 --static --userland userland/freestanding/gem5_checkpoint_restore.S --trace-insts-stdout --gem5-restore 1 ./run --arch aarch64 --emulator gem5 --static --userland userland/freestanding/gem5_checkpoint.S --trace-insts-stdout --gem5-restore 1
./run --arch aarch64 --emulator gem5 --static --userland userland/freestanding/gem5_checkpoint_restore.S --trace-insts-stdout --gem5-restore 1 -- --cpu-type=DerivO3CPU --restore-with-cpu=DerivO3CPU --caches ./run --arch aarch64 --emulator gem5 --static --userland userland/freestanding/gem5_checkpoint.S --trace-insts-stdout --gem5-restore 1 -- --cpu-type=DerivO3CPU --restore-with-cpu=DerivO3CPU --caches
.... ....
On the initial run, we see that all instructions are executed and the checkpoint is taken: On the initial run, we see that all instructions are executed and the checkpoint is taken:
@@ -11512,7 +11512,7 @@ And then restore the checkpoint with a different slower CPU:
And now you will notice that everything happens much slower in the guest terminal! And now you will notice that everything happens much slower in the guest terminal!
One even more direct and minimal way to observe this is with link:userland/freestanding/gem5_checkpoint_restore.S[] which was mentioned at <<gem5-checkpoint-userland-minimal-example>> plus some logging: One even more direct and minimal way to observe this is with link:userland/freestanding/gem5_checkpoint.S[] which was mentioned at <<gem5-checkpoint-userland-minimal-example>> plus some logging:
.... ....
./run \ ./run \
@@ -11520,7 +11520,7 @@ One even more direct and minimal way to observe this is with link:userland/frees
--emulator gem5 \ --emulator gem5 \
--static \ --static \
--trace ExecAll,FmtFlag,O3CPU,SimpleCPU \ --trace ExecAll,FmtFlag,O3CPU,SimpleCPU \
--userland userland/freestanding/gem5_checkpoint_restore.S \ --userland userland/freestanding/gem5_checkpoint.S \
; ;
cat "$(./getvar --arch aarch64 --emulator gem5 trace_txt_file)" cat "$(./getvar --arch aarch64 --emulator gem5 trace_txt_file)"
./run \ ./run \
@@ -11529,7 +11529,7 @@ cat "$(./getvar --arch aarch64 --emulator gem5 trace_txt_file)"
--gem5-restore 1 \ --gem5-restore 1 \
--static \ --static \
--trace ExecAll,FmtFlag,O3CPU,SimpleCPU \ --trace ExecAll,FmtFlag,O3CPU,SimpleCPU \
--userland userland/freestanding/gem5_checkpoint_restore.S \ --userland userland/freestanding/gem5_checkpoint.S \
-- \ -- \
--caches \ --caches \
--cpu-type DerivO3CPU \ --cpu-type DerivO3CPU \
@@ -11584,7 +11584,7 @@ This is generally useless compared to checkpoint restoring because:
* checkpoint restore allows to run multiple contents after the restore, and restoring to multiple different system states, which you almost always want to do * checkpoint restore allows to run multiple contents after the restore, and restoring to multiple different system states, which you almost always want to do
* we generally don't know the exact tick at which the region of interest will start, especially as the binaries change. It is much easier to just instrument the content with a checkoint <<m5ops,m5op>> * we generally don't know the exact tick at which the region of interest will start, especially as the binaries change. It is much easier to just instrument the content with a checkoint <<m5ops,m5op>>
But let's give it a try anyways with link:userland/freestanding/gem5_checkpoint_restore.S[] which was mentioned at <<gem5-checkpoint-userland-minimal-example>> But let's give it a try anyways with link:userland/freestanding/gem5_checkpoint.S[] which was mentioned at <<gem5-checkpoint-userland-minimal-example>>
.... ....
./run \ ./run \
@@ -11592,7 +11592,7 @@ But let's give it a try anyways with link:userland/freestanding/gem5_checkpoint_
--emulator gem5 \ --emulator gem5 \
--static \ --static \
--trace ExecAll,FmtFlag,O3CPU,SimpleCPU \ --trace ExecAll,FmtFlag,O3CPU,SimpleCPU \
--userland userland/freestanding/gem5_checkpoint_restore.S \ --userland userland/freestanding/gem5_checkpoint.S \
-- \ -- \
--caches --caches
--cpu-type DerivO3CPU \ --cpu-type DerivO3CPU \
@@ -17003,6 +17003,7 @@ The C standard library infrastructure is implemented in the common userland / ba
Unlike most our other assembly examples, which use the C standard library for portability, examples under `freestanding/` directories don't link to the C standard library: Unlike most our other assembly examples, which use the C standard library for portability, examples under `freestanding/` directories don't link to the C standard library:
* link:userland/freestanding/[]: freestanding programs that work on any ISA
* link:userland/arch/x86_64/freestanding/[] * link:userland/arch/x86_64/freestanding/[]
* link:userland/arch/arm/freestanding/[] * link:userland/arch/arm/freestanding/[]
* link:userland/arch/aarch64/freestanding/[] * link:userland/arch/aarch64/freestanding/[]

View File

@@ -1,5 +0,0 @@
#include <lkmc/m5ops.h>
.global _start
_start:
LKMC_M5OPS_EXIT_ASM

View File

@@ -1,3 +0,0 @@
.global _start
_start:
mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x21 << 16);

View File

@@ -7,6 +7,7 @@
* void _exit(int status) * void _exit(int status)
* *
* If only there was a GCC attribute to create such a function! * If only there was a GCC attribute to create such a function!
* https://stackoverflow.com/questions/43310704/creating-a-c-function-without-compiler-generated-prologue-epilogue-ret-instruc
*/ */
.text .text
.global _exit .global _exit

View File

@@ -1716,10 +1716,16 @@ after configure, e.g. SCons. Usually contains specific targets or other build fl
if extra_objs is None: if extra_objs is None:
extra_objs= [] extra_objs= []
if link: if link:
if self.env['mode'] == 'baremetal' or my_path_properties['extra_objs_lkmc_common']: # Baremetal builds cannot add their usual syscall objects, as those
# rely on standard library symbols.
if my_path_properties['freestanding']:
extra_objs = []
if (self.env['mode'] == 'baremetal' and not my_path_properties['freestanding']) \
or my_path_properties['extra_objs_lkmc_common']:
extra_objs.extend(extra_objs_lkmc_common) extra_objs.extend(extra_objs_lkmc_common)
if ( if (
self.env['mode'] == 'baremetal' and self.env['mode'] == 'baremetal' and
not my_path_properties['freestanding'] and
not my_path_properties['extra_objs_disable_baremetal_bootloader'] not my_path_properties['extra_objs_disable_baremetal_bootloader']
): ):
extra_objs.extend(extra_objs_baremetal_bootloader) extra_objs.extend(extra_objs_baremetal_bootloader)

View File

@@ -50,6 +50,7 @@ class PathProperties:
'extra_objs_disable_baremetal_bootloader': False, 'extra_objs_disable_baremetal_bootloader': False,
# We should get rid of this if we ever properly implement dependency graphs. # We should get rid of this if we ever properly implement dependency graphs.
'extra_objs_lkmc_common': False, 'extra_objs_lkmc_common': False,
'freestanding': True,
'gem5_unimplemented_instruction': False, 'gem5_unimplemented_instruction': False,
# Fully, or partially unimplemented. # Fully, or partially unimplemented.
'gem5_unimplemented_syscall': False, 'gem5_unimplemented_syscall': False,
@@ -374,13 +375,18 @@ freestanding_properties = {
'-static', LF, '-static', LF,
], ],
'extra_objs_lkmc_common': False, 'extra_objs_lkmc_common': False,
'freestanding': True,
} }
# https://cirosantilli.com/linux-kernel-module-cheat#nostartfiles-programs # https://cirosantilli.com/linux-kernel-module-cheat#nostartfiles-programs
nostartfiles_properties = { nostartfiles_properties = {
# The baremetal bootloader sets up the stack to a valid value.
# Therefore, without it, C code may not be called, and so this is very restrictive in general.
# Programs that don't call C code nor use stack can still work.
'baremetal': False, 'baremetal': False,
'cc_flags': [ 'cc_flags': [
'-nostartfiles', LF, '-nostartfiles', LF,
], ],
'extra_objs_disable_baremetal_bootloader': True,
} }
# See: https://cirosantilli.com/linux-kernel-module-cheat#path-properties # See: https://cirosantilli.com/linux-kernel-module-cheat#path-properties
path_properties_tuples = ( path_properties_tuples = (
@@ -406,7 +412,6 @@ path_properties_tuples = (
'no_bootloader': ( 'no_bootloader': (
{'extra_objs_disable_baremetal_bootloader': True}, {'extra_objs_disable_baremetal_bootloader': True},
{ {
'gem5_exit.S': {'requires_m5ops': True},
'multicore_asm.S': {'test_run_args': {'cpus': 2}}, 'multicore_asm.S': {'test_run_args': {'cpus': 2}},
'semihost_exit.S': {'requires_semihosting': True}, 'semihost_exit.S': {'requires_semihosting': True},
} }
@@ -423,7 +428,6 @@ path_properties_tuples = (
'no_bootloader': ( 'no_bootloader': (
{'extra_objs_disable_baremetal_bootloader': True}, {'extra_objs_disable_baremetal_bootloader': True},
{ {
'gem5_exit.S': {'requires_m5ops': True},
'multicore_asm.S': {'test_run_args': {'cpus': 2}}, 'multicore_asm.S': {'test_run_args': {'cpus': 2}},
'semihost_exit.S': {'requires_semihosting': True}, 'semihost_exit.S': {'requires_semihosting': True},
'wfe_loop.S': {'more_than_1s': True}, 'wfe_loop.S': {'more_than_1s': True},
@@ -685,9 +689,9 @@ path_properties_tuples = (
}, },
), ),
'freestanding': ( 'freestanding': (
freestanding_properties, {**freestanding_properties, **{'baremetal': True}},
{ {
'gem5_checkpoint_restore.S': {'allowed_emulators': {'gem5'}}, 'gem5_checkpoint.S': {'allowed_emulators': {'gem5'}},
'gem5_exit.S': {'allowed_emulators': {'gem5'}}, 'gem5_exit.S': {'allowed_emulators': {'gem5'}},
} }
), ),

View File

@@ -1,10 +0,0 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#benchmark-emulators-on-userland-executables */
#define LKMC_M5OPS_ENABLE 1
#include "lkmc/m5ops.h"
.text
.global _start
_start:
asm_main_after_prologue:
LKMC_M5OPS_EXIT_ASM

View File

@@ -0,0 +1 @@
https://cirosantilli.com/linux-kernel-module-cheat#freestanding-programs