2023年10月22日星期日

run riscv on qemu-system-riscv32

Sightly modify riscv.ld (download riscv.ld):

  1. Ensure the rom starts from 0x80000000. (matched with virt machine type)
  2. Set _init as entry function, place .text.init at 0x80000000.
  3. Add stack pointer initial location
In start.S, add _init function to setup sp and gp register:

.extern _start
.section .text.init
        .globl _init
_init:
        lui gp, %hi(ROM_START)     #_rom_start = 0x80000000 in linker script
        addi gp, gp, %lo(ROM_START)
        lui sp, %hi(init_sp)
        addi  sp, sp, %lo(init_sp)
        j  _start

riscv-none-elf-gcc -o helloworld.elf -march=rv32imad start.S helloworld.c -T riscv.ld

riscv-none-elf-objdump -D helloworld.elf > helloworld.S

qemu-system-riscv32 --machine virt -bios helloworld.elf -m 128M -nographic -singlestep -d exec,int,cpu 2>&1 | tee ins.log

Add cpu option above can dump the register value per step.

printf(...) require override _write() which could be found in newlib/libgross library.



2023年10月15日星期日

Increase swap size in WSL

In windows command prompt,

cd ~

notepad .wslconfig

[wsl2]
memory=16GB
swap=64GB
swapFile=D:\\swap.vhdx

Then, type

wsl --shutdown

to shutdown the Linux and wait for at least 8 seconds.

Remove Windows paths in WSL

In WSL,

sudo vi /etc/wsl.conf

[interop]
appendWindowsPath = false

In windows command prompt,

wsl --shutdown to restart the Linux

echo $PATH

to verify the path is correct