Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NyxOS, rebuilt from scratch in Haskell — a freestanding 64-bit kernel that boots on bare metal

     


About

Part of the NyxOS family — the same OS, rebuilt from zero in a different language each time. This is the Haskell cut, compiled with GHC.

Haskell is the hardest of the family: it is lazy and garbage-collected, and its runtime system (the STG machine, the heap, the scheduler) is enormous. The trick here is to skip the runtime entirely. The kernel is written so GHC compiles it, at -O2, to a straight-line native loop — the counters live in registers, the banner is a static byte table, and the only outside calls are an unsafe foreign import that stores one VGA cell. That compiled code touches its runtime in only two places: one stack-limit check (against register r15) and the return address on the STG stack. So a ten-line assembly stub (hs_boot.s) sets r15 = 0 — every check passes, so the runtime's overflow/GC path is never reached — points the STG stack at a buffer whose top returns into a halt, and jumps straight into the module's entry. No RTS, no hs_init, no GC is linked at all.

NyxOS-Haskell booting in QEMU

NyxOS-Haskell booting in QEMU (GRUB → long mode → GHC native code, no runtime) on the VGA text buffer

Why Haskell: it has been taken to bare metal before — House and the HaLVM ran Haskell as an operating system — so a runtime-free GHC kernel belongs in the family.

Build & run

Needs ghc, gcc, nasm, ld, grub-mkrescue + xorriso, and qemu.

make        # -> nyxos-haskell.iso  (64-bit ELF booted via GRUB)
make run    # boot the ISO in QEMU

Because the kernel is a 64-bit ELF, it boots from a GRUB ISO (qemu -cdrom) rather than qemu -kernel.

Layout

  • kernel.hs — the freestanding Haskell kernel; a no-allocation loop that stores VGA cells via an unsafe FFI import
  • hs_boot.s — sets up the minimal STG state (r15/Sp) and jumps into the module entry, bypassing the runtime
  • hs_shim.c — the VGA store plus the few ghc-prim data symbols the compiled code address-loads
  • boot64.asm — Multiboot header + the 32-bit → long-mode trampoline that calls kmain
  • linker64.ld — links the 64-bit kernel at 1 MiB, Multiboot header first
  • grub.cfg / Makefile — ISO packaging and boot

Status

Early — it boots and paints the screen. Next up: a GDT/IDT, interrupts, and a VGA console.

About

NyxOS, rebuilt from scratch in Haskell — a freestanding x86_64 OS. Part of the NyxOS family.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages