// virt.S: the board for QEMU virt, bare metal. // // -bios loads the flat image at 0x80000000 and starts every hart there in // M-mode. Hart 0 runs Forth; the others wait in wfi for good. // // qemu-system-riscv64 -machine virt -nographic -bios build/forth.bin .equ UART, 0x10000000 // NS16550A .equ UART_LSR, 5 // line status register .equ LSR_THRE, 0x20 // transmit holding register empty .equ LSR_DR, 0x01 // data ready .equ TEST, 0x100000 // SiFive test device .equ TEST_PASS, 0x5555 // power off, exit status 0 .section .text.init, "ax" .global _start _start: csrr t0, mhartid bnez t0, park la sp, stack_top j forth_start park: wfi j park .text .p2align 2 .global putc, getc, halt putc: // a0 = byte li t0, UART 1: lbu t1, UART_LSR(t0) andi t1, t1, LSR_THRE beqz t1, 1b sb a0, 0(t0) ret getc: // returns a0 = byte li t0, UART 1: lbu t1, UART_LSR(t0) andi t1, t1, LSR_DR beqz t1, 1b lbu a0, 0(t0) ret halt: li t0, TEST li t1, TEST_PASS sw t1, 0(t0) j park // only reached if there is no test device .section .bss .p2align 4 .space 4096 stack_top: