homebrew RISC-V · a kernel in scribble · a disk in your browser

A computer, from the processor up.

The processor is pico-v, a RISC-V emulator. The language is scribble. The operating system, its shell and every program on its disk are written in scribble, compiled to RISC-V in this page a moment ago, and booted. Click the screen and type help.


          
        

What is in it

The processor

pico-v runs RV32IMFD: the RISC-V base set, multiply and divide, floating point, machine and user mode, interrupts. A timer, a keyboard, an 80 by 25 text screen, a pixel display and a 1 MiB disk sit at memory addresses. Time is counted in instructions, so every run repeats exactly.

The kernel

kernel.sb, about a thousand lines of scribble, plus 114 instructions of assembly that save and restore a program on every trap. It runs up to seven programs, each in user mode in a 128 KiB slot, and takes the processor back from each with a timer interrupt every 16,384 instructions. Programs ask it for everything with ecall: 28 system calls for the screen, keys, files and other programs.

The disk

hbfs: a directory of 64 files and a table chaining each file's 512-byte sectors. It lives in this browser, so what you write is still there after a reload. cat kernel.sb shows the kernel's own source, read off the disk by the kernel.

What it does not do. There is no memory protection: user mode keeps a program away from the processor's control registers, not from any address, so a program can overwrite the kernel. The compiler runs in the page, not on the machine; programs reach the disk as machine code before it boots. The processor has not been run against the official RISC-V compliance suite.