Custom BIOS and init
A computer boots in two stages, like a Lua one:
- The EEPROM runs first. The stock BIOS binds the GPU to the screen,
finds a disk with
/init.wasm(trying the remembered boot disk first), beeps, and hands over to it. /init.wasmruns from then on. On the shell floppy, that’s the shell.
Replacing the shell
Section titled “Replacing the shell”Put your program on a disk as /init.wasm. There’s no 4 KiB limit here,
only the computer’s RAM, and it can be either kind of program:
- a WASI program (
wasm32-wasip1, with amain). As the first process it has no terminal: stdin is at end of file, and its output goes to the machine’s log file on the server (see Configuration). Draw on the GPU withwackasm-opencomputersinstead; - an
oc_mainprogram, like the shell (crates/wackasm-oc-guest).
Either kind can run other programs with the process API, and is then their terminal.
Writing EEPROM code
Section titled “Writing EEPROM code”EEPROM code must fit in 4096 bytes. In practice that means:
#![no_std], built forwasm32-unknown-unknown;- exporting
oc_main, and calling theocimports directly; opt-level = "z", LTO,panic = "abort", no allocator if you can help it.
The stock BIOS,
crates/wackasm-oc-bios,
is a working example at 3959 bytes. The smallest possible BIOS, in WAT:
Flash it with flash. To boot a disk the way the
stock BIOS does, read the file and call oc.exec(image, len), which replaces
the running program with that one.