RV1 Verilated WASM Demo
This page runs the copied RV1 RTL as a Verilated model compiled to WebAssembly.
Detailed build steps and workarounds are documented in RV1 Verilator->WASM Build Notes.
Looking for the effect variant? Open RV1 Verilated WASM Twister.
Pipeline used:
- C demo program (
fb_demo_rv32.c) -> RV32IM binary (program.bin) - RV1 RTL -> Verilator C++ model -> WASM (
rv1_verilated.wasm) - Browser loads program/data into IMEM/DMEM, runs cycles, then blits DMEM framebuffer to canvas
Framebuffer target:
- 320x240
- ARGB words from CPU, converted to RGBA for HTML canvas
- pattern: R=Y, G=X^Y, B=X
RV32 Disassembly
The executable loaded into IMEM is shown below, with source interleaved where debug lines are available.
../sw/build/fb_demo_rv32.elf: file format elf32-littleriscv
Disassembly of section .text:
00000000 <_start>:
/* Minimal RV32 startup for bare-metal C programs on rv1 */
.section .text.init
.global _start
_start:
la sp, _stack_top
0: 00004117 auipc sp,0x4
4: 00010113 mv sp,sp
call main
8: 008000ef jal 10 <main>
1:
j 1b
c: 0000006f j c <_start+0xc>
00000010 <main>:
static volatile u32 *const framebuffer = (volatile u32 *)0x00000000u;
int main(void) {
for (u32 y = 0; y < FB_HEIGHT; y++) {
for (u32 x = 0; x < FB_WIDTH; x++) {
10: 00000313 li t1,0
for (u32 y = 0; y < FB_HEIGHT; y++) {
14: 00000593 li a1,0
framebuffer[y * FB_WIDTH + x] =
0xFF000000u |
((y & 0xFFu) << 16) |
(((x ^ y) & 0xFFu) << 8) |
18: ff0008b7 lui a7,0xff000
for (u32 x = 0; x < FB_WIDTH; x++) {
1c: 14000813 li a6,320
for (u32 y = 0; y < FB_HEIGHT; y++) {
20: 0f000e13 li t3,240
for (u32 x = 0; x < FB_WIDTH; x++) {
24: 01059513 slli a0,a1,0x10
28: 00231693 slli a3,t1,0x2
2c: 00000713 li a4,0
(((x ^ y) & 0xFFu) << 8) |
30: 00e5c7b3 xor a5,a1,a4
34: 0ff7f793 zext.b a5,a5
38: 00879793 slli a5,a5,0x8
((y & 0xFFu) << 16) |
3c: 00a7e7b3 or a5,a5,a0
(x & 0xFFu);
40: 0ff77613 zext.b a2,a4
(((x ^ y) & 0xFFu) << 8) |
44: 00c7e7b3 or a5,a5,a2
48: 0117e7b3 or a5,a5,a7
framebuffer[y * FB_WIDTH + x] =
4c: 00f6a023 sw a5,0(a3)
for (u32 x = 0; x < FB_WIDTH; x++) {
50: 00170713 addi a4,a4,1
54: 00468693 addi a3,a3,4
58: fd071ce3 bne a4,a6,30 <main+0x20>
for (u32 y = 0; y < FB_HEIGHT; y++) {
5c: 00158593 addi a1,a1,1
60: 14030313 addi t1,t1,320
64: fdc590e3 bne a1,t3,24 <main+0x14>
}
}
for (;;) {
68: 0000006f j 68 <main+0x58>
RV32 Sections
Section layout from the same ELF:
../sw/build/fb_demo_rv32.elf: file format elf32-littleriscv
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000006c 00000000 00000000 00001000 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .stack 00004000 00000000 00000000 00002000 2**0
ALLOC
2 .riscv.attributes 0000002a 00000000 00000000 0000106c 2**0
CONTENTS, READONLY
3 .comment 00000019 00000000 00000000 00001096 2**0
CONTENTS, READONLY
4 .debug_line 00000156 00000000 00000000 000010af 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
5 .debug_line_str 00000084 00000000 00000000 00001205 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
6 .debug_info 000000d4 00000000 00000000 00001289 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
7 .debug_abbrev 000000bd 00000000 00000000 0000135d 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
8 .debug_aranges 00000040 00000000 00000000 00001420 2**3
CONTENTS, READONLY, DEBUGGING, OCTETS
9 .debug_str 000000ff 00000000 00000000 00001460 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
10 .debug_loclists 0000002c 00000000 00000000 0000155f 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
11 .debug_rnglists 00000016 00000000 00000000 0000158b 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
12 .debug_frame 00000020 00000000 00000000 000015a4 2**2
CONTENTS, READONLY, DEBUGGING, OCTETS
RV32 Imports and Exports
Undefined symbols (imports) and defined global symbols (exports):
Imports (undefined global symbols)
----------------------------------
(none)
Exports (defined global symbols)
-------------------------------
00004000 B _stack_top
00000000 T _start
00000010 T main