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

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


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



































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

Has anyone solved this problem?