Full System emulation using bare metal option

Hi everyone, I would need to run a simulation of gem5 in Full System emulation with RISCV architecture with a simple C program. I therefore tried to use the --bare-metal option.

So, I tried to run the following command:
./gem5/build/RISCV/gem5.opt ./gem5/configs/example/riscv/fs_linux.py --kernel=test —bare-metal

where “test” is a compiled program written in C:

#include <stdio.h>
int main(void){
unsigned int r = 1337;
printf(“Hello World! %d\n”, r);
while (1) { }
}

and compiled with the following command: riscv64-unknown-linux-gnu-gcc --static test.c -o test

but gem5 returns me the following error:

gem5 Simulator System. https://www.gem5.org

gem5 is copyrighted software; use the --copyright option for details.

gem5 version 23.0.1.0

gem5 compiled Dec 15 2023 12:35:45

gem5 started Jan 8 2024 12:55:50

gem5 executing on 46f410d0d38b, pid 1704898

command line: ./gem5/build/RISCV/gem5.opt ./gem5/configs/example/riscv/fs_linux.py --kernel=test —bare-metal

warn: The get_runtime_isa function is deprecated. Please migrate away from using this function.

warn: The get_runtime_isa function is deprecated. Please migrate away from using this function.

Global frequency set at 1000000000000 ticks per second

warn: No dot file generated. Please install pydot to generate the dot file and pdf.

src/mem/dram_interface.cc:690: warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)

src/base/statistics.hh:279: warn: One of the stats is a legacy stat. Legacy stat is a stat that does not belong to any statistics::Group. Legacy stat is deprecated.

   0: system.platform.rtc: Real-time clock set to Sun Jan  1 00:00:00 2012

system.platform.terminal: Listening for connections on port 3456

system.remote_gdb: Listening for connections on port 7000

**** REAL SIMULATION ****

src/sim/simulate.cc:194: info: Entering event queue @ 0. Starting simulation…

src/cpu/simple/atomic.cc:753: panic: panic condition pkt.isError() occurred: Instruction fetch ([0x10420:0x10424]) failed: BadAddressError [10420:10423] IF

Memory Usage: 626284 KBytes

Program aborted at tick 0

— BEGIN LIBC BACKTRACE —

gem5.opt(+0x63c370)[0x56510fbd8370]

gem5.opt(+0x66b7ac)[0x56510fc077ac]

/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f32bd310520]

/lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7f32bd3649fc]

/lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7f32bd310476]

/lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f32bd2f67f3]

gem5.opt(+0x654825)[0x56510fbf0825]

gem5.opt(+0xb92873)[0x56511012e873]

gem5.opt(+0xb91920)[0x56511012d920]

gem5.opt(+0x657612)[0x56510fbf3612]

gem5.opt(+0x6953b8)[0x56510fc313b8]

gem5.opt(+0x6959ab)[0x56510fc319ab]

gem5.opt(+0x132e8f0)[0x5651108ca8f0]

gem5.opt(+0x5d0b74)[0x56510fb6cb74]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x128023)[0x7f32bde0f023]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(_PyObject_Call+0x5c)[0x7f32bddc8fec]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x4b16)[0x7f32bdd5d776]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1c23af)[0x7f32bdea93af]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x9d68)[0x7f32bdd629c8]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1c23af)[0x7f32bdea93af]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x69de)[0x7f32bdd5f63e]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1c23af)[0x7f32bdea93af]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x9d68)[0x7f32bdd629c8]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1c23af)[0x7f32bdea93af]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(PyEval_EvalCode+0xbe)[0x7f32bdea43de]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1bd96d)[0x7f32bdea496d]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1287b3)[0x7f32bde0f7b3]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x69de)[0x7f32bdd5f63e]

/lib/x86_64-linux-gnu/libpython3.10.so.1.0(+0x1c23af)[0x7f32bdea93af]

gem5.opt(+0x66e2f7)[0x56510fc0a2f7]

gem5.opt(+0x3cff1b)[0x56510f96bf1b]

/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f32bd2f7d90]

— END LIBC BACKTRACE —

For more info on how to address this issue, please visit gem5: Common errors within gem5

Aborted (core dumped)

How can I fix it?

Is it correct to use the bare-metal option? Or can I do it some other way?

Does the C program need any dependencies?

I know nothing about gem5, but I think I can help you a tiny bit.

  • main() defines where the code execution begins.
  • printf() calls external code to output a string usually via libc and the output device is provided by the linux kernel.

In baremetal programing there is no libc and no kernel to manage authorization, access and auditing for the desired output device. You need to write code to provide the function you require and that could even mean asynchronisly bit banging the data over GPIO (General Purpose Input Output) pins, to emulate a serial port.

The baremetal programing “Hello World!” equivalent in the embedded world is usually to toggle a GPIO pin, usually to blink a LED (Light Emitting Diode). The program is usually called blinky.

Thank you for your response.

Actually I am trying to run any program, I have also tried to run a program without printf, with only while(1){}, however the error persists.

Maybe ask on the gem5 users mailing list or search the gem5 users mailing list archive ? My guess, knowing absolutely nothing about gem5, would be that it is might a compiler option, maybe.

EDIT: Another option might be gem5 bootcamp videos https://www.youtube.com/playlist?list=PL_hVbFs_loVSaSDPr1RJXP5RRFWjBMqq3 (from 2022) that may have the answers you seek (possibly “gem5 bootcamp 2022: Getting started developing” or “gem5 bootcamp 2022: Getting started with gem5” video).

1 Like