A tiny Forth kernel for RV64: Linux and QEMU virt builds, linked from handwritten assembly.
1// virt.S: the board for QEMU virt, bare metal.
2//
3// -bios loads the flat image at 0x80000000 and starts every hart there in
4// M-mode. Hart 0 runs Forth; the others wait in wfi for good.
5//
6// qemu-system-riscv64 -machine virt -nographic -bios build/forth.bin
8 .equ UART, 0x10000000 // NS16550A
9 .equ UART_LSR, 5 // line status register
10 .equ LSR_THRE, 0x20 // transmit holding register empty
11 .equ LSR_DR, 0x01 // data ready
12 .equ TEST, 0x100000 // SiFive test device
13 .equ TEST_PASS, 0x5555 // power off, exit status 0
15 .section .text.init, "ax"
17_start:
18 csrr t0, mhartid
21 j forth_start
22park:
23 wfi
26 .text
27 .p2align 2
29putc: // a0 = byte
30 li t0, UART
311: lbu t1, UART_LSR(t0)
32 andi t1, t1, LSR_THRE
34 sb a0, 0(t0)
35 ret
37getc: // returns a0 = byte
38 li t0, UART
391: lbu t1, UART_LSR(t0)
40 andi t1, t1, LSR_DR
42 lbu a0, 0(t0)
43 ret
45halt:
46 li t0, TEST
47 li t1, TEST_PASS
48 sw t1, 0(t0)
51 .section .bss
52 .p2align 4
53 .space 4096
54stack_top: