
首先在线仿真地址: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/
离线
太有趣了, 可以用 html 单步调试, 挺直观的.
离线
牛逼, 在线修改汇编代码, 在线单步调试, 刚试了一下, 太爽了.
离线
离线
https://whycan.com/files/members/3907/-273389d73bc96341.png
lui 指令貌似有bug,
再 请教一个小问题,
lui x1, 0xa000
指令执行之后 x1应该是 0xa000000,
而模拟器是 0xa000
cat plus.S
.text
.global plus, shift
plus:
        add     a0,a1,a0
        ret
shift:
        lui     a0,0xa000
        ret#include <stdio.h>
extern int plus(int a, int b);
extern int shift();
int main(void)
{
        //printf("hello, %d\n", plus(111, 222));
        printf("hello, 0x%X\n", shift());
}结果确实是:
$ QEMU_LD_PREFIX=/usr/riscv64-linux-gnu/ qemu-riscv64 hello
hello, 0xA000000一个非常简单的RISC-V C调用使用ABI规则ASM汇编的demo, 使用qemu-riscv64虚拟机测试.
https://whycan.com/t_6685.html
离线

模拟器右下角,可以给作者提个issue。这么大个bug,应该会修复
离线
模拟器右下角,可以给作者提个issue。这么大个bug,应该会修复
https://whycan.com/files/members/1315/Screenshot144436.png
https://github.com/Guillaume-Savaton-ESEO/emulsiV/issues/21
"lui x1, 0xA" Unacceptable?
"lui x1, 0x1000" run result 0x1000000, but not 0x1000用汇编学习risc-v指令集,并在线仿真,点亮led
https://whycan.com/t_6593.html#p64755
作者回复:
According to the RISC-V specification, LUI is a U-type instruction where the immediate field contains 20 bits identified as imm[31:12].
If we take the instruction lui x1, 0x1000, I think there are two possible interpretations:
imm is 0x1000 (and so imm[31:12] is 0x1)
imm[31:12] is 0x1000 (imm is 0x1000000)
I honestly don't know which interpretation is right. As far as I remember, this is not explicitly defined in the RISC-V spec.
emulsiV follows the first, and I personally find it easier to understand for beginners. But I know that the GNU toolchain uses the second.
自动翻译:
根据 RISC-V 规范,LUI 是 U 型指令,其中立即字段包含 20 位标识为imm[31:12].
如果我们接受指令lui x1, 0x1000,我认为有两种可能的解释:
imm是0x1000(imm[31:12]也是0x1)
imm[31:12]是0x1000(imm是0x1000000)
老实说,我不知道哪种解释是正确的。据我所知,这在 RISC-V 规范中没有明确定义。
emulsiV遵循第一个,我个人觉得对于初学者来说更容易理解。但我知道 GNU 工具链使用第二个。
离线

作者说,这不算bug,最多算对标准解读不同,哈哈哈哈。
开发juicevm的时候好像没遇到这么个标准上的解读问题。
离线
这个有源码吗,好东西、。
离线
有没有 arm的模拟
离线