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.


          
        

Inside, live

Read straight out of the machine's memory as it runs. The page knows where the kernel keeps its process table because it compiled the kernel; the kernel reports nothing. Start life & and spin & and watch them share the processor.

Processes the kernel's table

pidnamestatecpuranmemorykeys

Processor

running

Who has the processor each column a tenth of a second, the last 12 s

System calls

    Memory a 128 KiB slot each

    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: 30 system calls for the screen, keys, files, the clock 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.

    The programs

    A shell, a text editor, a paint program, a game, and a few small ones, each written in scribble with its source on the disk beside it. Change one with edit life.sb, press Power cycle, and the page compiles your version before the machine boots. Even kernel.sb.

    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.