> On 21/04/2018, at 3:20 PM, Eva Chen <
debby...@gmail.com> wrote:
>
> Thanks for your replies!!
>
> Now I understand the error is after finishing the execution of test binary file.
> Is there any way to avoid this error?
>
> What if I want to conduct a hello word binary file which crosses compiled by riscv64-unknown-elf-gcc
> How to link this hello.c file to linker.ld? Is there any method to run it on the bare metal version of RISCV QEMU (qemu-riscv64)?
Here is an example program that runs in the spike_v1.9.1 or spike_v1.10 machines.
-
https://github.com/michaeljclark/riscv-probe
riscv-probe is a minimal bare-metal example derived from riscv-pk/bbl but does not include S-mode support and includes a much smaller library for console via HTIF (Host Target Interface). You could easily add uart support by using uart.c from riscv-pk. Take a look at the Makefile and linker script. You can run it as follows (it compiles and runs on riscv32 and riscv64 assuming you have the toolchains installed).
$ qemu-system-riscv32 -nographic -machine spike_v1.10 -kernel bin/riscv32/probe-htif
$ qemu-system-riscv64 -nographic -machine spike_v1.10 -kernel bin/riscv64/probe-htif
The HTIF interface in the spike machine has a shutdown method so that writing a command to a specific IO address, tells qemu to exit.
The virt machine on the other hand implements a SiFive Test device in device-tree which is used for finishing verification tests in simulators. riscv-linux can already detect this in device-tree and uses this for shutdown support in the ‘virt’ machine. The ‘virt’ machine does not use HTIF and instead has a NS16550A UART console. This is why we needed a different mechanism to “power off” the simulation. See the memory map here:
-
https://github.com/riscv/riscv-qemu/blob/riscv-all/hw/riscv/virt.c#L46-L55
We have plans to add generic GPIO shutdown and reset support to some of the boards which is already supported by Linux. This is essentially a special MMIO address that in real life would be connected to the reset line or power/sleep function of the device. The reality is that each board usually has its own GPIO device and you need to know while GPIO lines are wired to reset and to the power management unit for power off or sleep.
There are also bare metal examples in the freedom-e-sdk that target the ’sifive_e’ machine which emulates parts of the HiFive1. The e31 examples run on the ’sifive_e’ machine.
-
https://github.com/sifive/freedom-e-sdk
The ’sifive_e’ machine in QEMU and HiFive1 has no shutdown mechanism so after performing IOs and printing results to the console, at the end of the program one simply enters a busy loop. e.g.
loop: wfi
j loop
You may also like to look at ZephrOS. It is a bare metal realtime OS. It requires you download an SDK with an older version of QEMU. The the arty_fe310 examples run unmodified in the latest version of QEMU sing the ’sifive_e’ machine which models the E31/E51 Series processors, which includes SiFive’s FE310G000. The emulation is not complete but it is enough to run the ‘bsp’ (board support package) and several of the examples:
-
https://github.com/fractalclone/zephyr-riscv
Each machine has its own memory map. QEMU tries to emulate the distinct memory map of each system. i.e. spike binaries will run in the ‘spike’ machine, HiFive1 binaries run in the ’sifive_e’ machine and we are working towards getting the HiFive Unleashed binaries to run in the ’sifive_u’ machine (currently folk are using the ‘virt’ machine to run Linux)
-
https://github.com/riscv/riscv-qemu/blob/riscv-all/hw/riscv/spike.c#L48-L52
-
https://github.com/riscv/riscv-qemu/blob/riscv-all/hw/riscv/virt.c#L46-L55
-
https://github.com/riscv/riscv-qemu/blob/riscv-all/hw/riscv/sifive_e.c#L55-L75
Some notes:
- You can inspect the reset vector code and linker scripts to see where the board ROM jumps to after reset. Look for reset_vec in the files above.
- The ROMs in the current boards are at 0x1000.
- The Spike board and virt boards jump to 0x80000000 which is the base address of the RAM.
- The SiFive E Series board jumps to 0x20400000 which is a location in XIP EEPROM non volatile memory. The E Series only has a small scratchpad at 0x80000000
- The SiFive U Series board needs more work, i.e. we need to add an emulated Cadence Ethernet controller and various other devices
The wiki has a high level overview of the 5 machines that are there now:
-
https://github.com/riscv/riscv-qemu/wiki
> --
> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
sw-dev+un...@groups.riscv.org.
> To post to this group, send email to
sw-...@groups.riscv.org.
> Visit this group at
https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/f1cd2867-4abe-46da-975d-f803cd445445%40groups.riscv.org.