首先在线仿真地址:http://tice.sea.eseo.fr/riscv/,选择这个主要是因为比较好玩直观。
这个模拟器是支持gnu的编译器的,所以先安装编译器:
sudo apt install gcc-riscv64-unknown-elf
模拟器gpio寄存器:
点灯程序:
/*
* Configure the GPIO with:
* - Byte 0: 8 LEDs
* - Byte 1: 8 toggle switches
*/
.text
.global __reset
__reset:
j start
start:
li x1, 0xd0000000
/* Set first GPIO byte as outputs */
sb x0, (x1)
li x3, 0xff
sb x3, 0x10(x1)
j .
.section gpio_config, "a"
leds: .byte 3, 3, 3, 3, 3, 3, 3, 3
sws: .byte 2, 2, 2, 2, 2, 2, 2, 2
编译文件:
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c -o led.o led.s
连接成elf文件:
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -nostdlib -T rv32e.ld -o led.elf led.o
连接文件rv32e.ld
ENTRY(__reset)
MEM_SIZE = 4K;
STACK_SIZE = 512;
BITMAP_SIZE = 1K;
SECTIONS {
. = 0x0;
.text : {
*(vectors)
*(.text)
__text_end = .;
}
.data : { *(.data) }
.rodata : { *(.rodata) }
__global_pointer = ALIGN(4);
.bss ALIGN(4) : {
__bss_start = .;
*(.bss COMMON)
__bss_end = ALIGN(4);
}
. = MEM_SIZE - STACK_SIZE - BITMAP_SIZE;
.stack ALIGN(4) : {
__stack_start = .;
. += STACK_SIZE;
__stack_pointer = .;
}
.bitmap ALIGN(4) : {
__bitmap_start = .;
*(bitmap)
}
__bitmap_end = __bitmap_start + BITMAP_SIZE;
}
生成intel格式hex:
riscv64-unknown-elf-objcopy -O ihex led.elf led.hex
最后附上在线仿真器的文档说明:http://tice.sea.eseo.fr/riscv/doc/
离线
模拟器右下角,可以给作者提个issue。这么大个bug,应该会修复
离线