Sightly modify riscv.ld (download riscv.ld):
- Ensure the rom starts from 0x80000000. (matched with virt machine type)
- Set _init as entry function, place .text.init at 0x80000000.
- Add stack pointer initial location
.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.
沒有留言:
發佈留言