moonshot

technical

knekt

knekt is the kernel core. most of what the kernel does lives in the named parts around it, and knekt is the piece that wires them together.

boot

GRUB boots the kernel through Multiboot into a short piece of hand-written assembly, which sets up just enough of the machine to call knekt's main. main wakes the machine a piece at a time, the serial port, the framebuffer (punkt), the keyboard, memory (jenna), the interrupt table and the timer. then it tiles the screen into windows (kakel), starts a shell in each (skalman) along with the scheduler (chrone), and brings up the filesystem (jakel).

when things go wrong

a fault in a ring-3 program ends that program and nothing else. a fault in the kernel prints the vector, the error code, the faulting address and the instruction pointer over serial and halts. a fixed capacity in the kernel that fills up says so on the serial port rather than dropping work without a word.

ring 3

programs are static elf64 executables, usually read from jakel. each runs in ring 3 with page tables, a kernel stack and a heap of its own, and talks to the kernel through the syscall instruction. in coff's --elf mode a program reaches them through builtins such as win_info() and readfile().

system calls

numnameargsreturns
0SYS_EXITnonedoes not return
1SYS_DEBUG_PRINTstrnone, the text goes to the program's window
2SYS_WIN_INFOnonewidth * 65536 + height
3SYS_FILLx, y, w, h, colornone
4SYS_KEY_POLLnonemake_code * 2 + is_break or -1
5SYS_BLITbuf, x, y, w, hnone
6SYS_ALLOCsizeaddress of zeroed memory, or 0 if exhausted
7SYS_TICKSnonethe kernel's monotonic ~100hz pit tick count
8SYS_READFILEname, buf, maxbytes read, or the size when buf is 0, or -1
9SYS_PRESENTbuf0, or -1 with no window
10SYS_WIN_MAXnonewidth * 65536 + height
11SYS_MOUSE_POLLnone(x * 1024 + y) * 8 + buttons, window-relative, or -1 when the pointer is not over the window
12SYS_GLYPHch, bufcell width * 65536 + cell height, and the glyph's rows written to buf
13SYS_DEALLOCptr0, or -1 when ptr is not the start of a live block
14SYS_SOUNDbuf, lenbytes queued for oljud, or the bytes still waiting when buf is 0, or with len -1 as well, stops all sound and returns what was dropped, and -1 with no sound card
15SYS_WRITEFILEname, buf, lenlen, or -1
16SYS_SLEEPticks0, after the ticks have passed
17SYS_ARGCnonehow many arguments the task was started with
18SYS_ARGViargument i in the task's own memory, or 0
19SYS_LISTDIRpath, buf, maxhow many entries were written, or -1 when the path is not a directory
20SYS_SPAWNlinethe new task's id, or a negative error
21SYS_PROTECTaddr, pages, mode0, or -1 when a page is not the task's own heap

the drawing calls take coordinates relative to the program's own window. a program draws a whole frame into its own buffer and shows it with one SYS_PRESENT, which is also why SYS_GLYPH hands over a font bitmap instead of drawing text. keys reach a program only while its tavla has focus, through a queue of its own.