Kernel loads Go program into memory and call initialize function of Golang Runtime.(For Linux, ELF header’s entrypoint defines it) ❖ Initialization stage is huge. ❖ Init goroutine ❖ Get args passed by OS ❖ Init scheduler(stack, mm, GC, etc…) ❖ Runtime needs kernel!
bootloader to load runtime!(Runtime loads kernel main function) ❖ How initialize goroutine, memory, some low level stuff(Interrupt, I/O)? ❖ Replace system call with own system call ❖ Get memory map from BIOS and set it. ❖ WRITE LOW LEVEL CODE IN ASSEMBLY(ಀ͛ͪΌͩΊͩ)
golang:1.5, most of runtime code is written in Go rather than C) ❖ You can see commits related to biscuit by command below ❖ git log --author="Cody Cutler" —reverse ❖ I forked and minimzed biscuit ❖ https://github.com/morimolymoly/biscuit ❖ I focused on commits before c14beb90191e74163c20c48596a5eed576fbc664(It is so primitive but there is goroutine, interface, collections…)
ELF binary from kernel code ❖ biscuit/kernel/chentry.c changes entrypoint of main.gobin to _rt0_hack ❖ _rt0_hack is like a _rt0_amd64_linux which is used when you launch Go program in Linux AMD64 arch ❖ _rt0_hack calls runtime·rt0_go_hack in src/runtime/asm_amd64.s ❖ runtime·rt0_go_hack init segment, interrupt, syscall table, first goroutine
main function is also goroutine(created by runtime·newproc in rt0_go_hack) ❖ After setting up Virtual Memory(Paging, Segment), you can free to fire it! ❖ Set M(Machine), P(Processor) up.(M(Machine) and P is used in Golang runtime internal)
us new perspective of next generation Operating System ❖ e.g. Keyboard driver uses goroutine in biscuit ❖ Reading runtime is absolutely fun!(Try it ! Fork and read it for free!) ❖ Read code and hack it!
Morris. “The benefits and costs of writing a POSIX kernel in a high-level language”. In: 13th USENIX Symposium on Operating Systems Design and Implementation (OSDI 18). ❖ Yoshiki Shibukawa, “Biscuit Code Reading”. In: GoCon2018 Autumn ❖ Achilleas Anagnostopoulos, “Bare Metal Gophers: can you write an OS Kernel in Go?”. In: GolangUK2017