Project

General

Profile

Getting Started

In this chapter the main features of QEMU for RISC-V tool are demonstrated. It is supposed that the following tools are successfully installed in your system:

- QEMU for RISC-V itself (can be downloaded from here );
- Toolchain for RISC-V assembler programs compilation, linking, etc. (the source code and the installation guide are available here).

  1. First of all, let's write a simple RISC-V program (it is called sample.s and is attached below) that does nothing but puts 0x18 value to t1 register and puts 0x21 value to t2 register. Here it is:
    .text
    .globl _start
    _start:
     addi t1, zero, 0x18
     addi t2, zero, 0x21
    
  2. To compile the RISC-V assembler program called sample.s, do the following:
    aarch64-linux-gnu-as sample.s -o sample.o
    aarch64-linux-gnu-ld sample.o -Ttext 0x1000 -o sample.elf
    
  3. Finally, run QEMU for RISC-V emulator with enabled option of microprocessor execution trace logging (0x1000 value was used by linker because of QEMU-related features):
    qemu-system-riscv64 -M spike -cpu any -d unimp,nochain,in_asm -nographic -singlestep -trace-log -kernel sample.elf
    
  4. Wait for a while, then stop QEMU by hands (NOTE: neither Ctrl-C nor Ctrl-Z works, use 'kill <process-id>' or 'killall qemu-system*', for example). The following trace should be generated:
    0 clk 0 IT (0) 0000000000001000 01800313 A svc_ns : li t1,24
    1 clk R t1 0000000000000018
    1 clk 0 IT (1) 0000000000001004 02100393 A svc_ns : li t2,33
    2 clk R t2 0000000000000021
    2 clk 0 IT (2) 0000000000001008 00000000 A svc_ns : unimp
    3 clk 0 IT (3) 0000000000001010 00000000 A svc_ns : unimp