A tiny Forth kernel for RV64: Linux and QEMU virt builds, linked from handwritten assembly.
First runnable RV64 Forth kernelOct 11
1// linux.S: the board for a Linux process. The kernel has already set up sp,
2// and every byte goes through an ecall.
3//
4// ./build/forth-linux on RV64 Linux, or under qemu-riscv64
6 .equ SYS_read, 63
7 .equ SYS_write, 64
8 .equ SYS_exit_group, 94
10 .text
11 .p2align 2
13_start:
14 j forth_start
16putc: // a0 = byte
17 addi sp, sp, -16
18 sb a0, 0(sp)
19 li a0, 1 // stdout
20 mv a1, sp
21 li a2, 1
22 li a7, SYS_write
23 ecall
24 addi sp, sp, 16
25 ret
27getc: // returns a0 = byte, or -1 at end of input
28 addi sp, sp, -16
29 li a0, 0 // stdin
30 mv a1, sp
31 li a2, 1
32 li a7, SYS_read
33 ecall
35 lbu a0, 0(sp)
36 addi sp, sp, 16
37 ret
381: li a0, -1
39 addi sp, sp, 16
40 ret
42halt:
43 li a0, 0
44 li a7, SYS_exit_group
45 ecall