208 lines
5.2 KiB
Markdown
208 lines
5.2 KiB
Markdown
# NT-Lite -- an x86-64 kernel
|
||
|
||
“Not only is UNIX dead, it’s starting to smell really bad.” - Rob Pike
|
||
|
||
“UNIX has three operations: read, write, and lie through ioctl.”
|
||
|
||
## what is it?
|
||
|
||
NT-Lite is a 64-bit operating system kernel written from scratch.
|
||
|
||
It boots into a shell, launches programs, runs Doom, talks TCP/IP, and occasionally reminds you that it is still a hobby kernel.
|
||
|
||
## features
|
||
|
||
- UEFI bootloader
|
||
- real SMP
|
||
- VAD-based virtual memory, file-backed and anonymous mmap, CoW, reclaim
|
||
- single address-space design with user/supervisor page permissions
|
||
- preemptive priority scheduler
|
||
- capability-style handles with rights checks, derivation, and revocation
|
||
- rich synchronization primitives
|
||
- IRQL, DPCs, kernel APCs, and user APCs
|
||
- user exception handling with structured and vectored handlers
|
||
- async file I/O with events, IOSBs, APC callbacks, and cancellation
|
||
- capability-relative VFS with IRPs
|
||
- refcounted mounted volumes with partition arrival/removal
|
||
- page cache with dirty writeback and invalidation
|
||
- USB bus, xHCI, mass storage, hubs, hotplug, and HID
|
||
- audio
|
||
- VMware SVGA display driver
|
||
- dynamic driver loading
|
||
- native BSD-ish socket syscalls
|
||
- DNS resolver syscall
|
||
- four-register syscall ABI with sized request structs for larger calls
|
||
- partial Win32 personality
|
||
- partial (microsoft-level) POSIX personality
|
||
- Doom
|
||
- video playback
|
||
- fully GDPR-compliant
|
||
- everything but the kitchen sink
|
||
|
||
## paths
|
||
|
||
You thought it would be easy, would you?
|
||
|
||
```text
|
||
"apps/shell_native.exe" -> current working directory, resolved in userspace
|
||
"/SystemRoot/apps/shell_native.exe" -> system volume through the resource namespace
|
||
"/Device/HarddiskVolume1/boot.ini" -> system volume through the resource namespace
|
||
"C:\apps\doom.exe" -> /SystemRoot/apps/doom.exe through win32.dll
|
||
"\apps\doom.exe" -> /SystemRoot/apps/doom.exe through win32.dll
|
||
"/apps/video.exe" -> /SystemRoot/apps/video.exe through posix.dll
|
||
```
|
||
|
||
Kernel filesystem syscalls are capability-relative; userspace owns the current working directory and resolves named resources through `rssrv`.
|
||
|
||
`/SystemRoot` is the configured boot volume. Other mounted volumes are discovered through the volume manager and opened by capability.
|
||
|
||
## networking
|
||
|
||
The socket syscalls are BSD-shaped, not BSD-compatible. Same nouns (AF_INET, SOCK_STREAM, IPPROTO_TCP), none of the baggage:
|
||
one fixed-size tagged address struct instead of the sockaddr_in/sockaddr_storage casting dance,
|
||
no htons/ntohl conversions, and DNS resolution is a syscall rather than a userspace library call.
|
||
That's right microkernel purists, cry some more. Ergonomics.
|
||
Async is first-class here too, same machinery as the filesystem. Except the DNS resolver. Ergonomics, am I right?
|
||
|
||
## how to build
|
||
|
||
- get mtools
|
||
- open the VS x64 build tools
|
||
- change into this directory
|
||
- run `build.bat`
|
||
- use one of:
|
||
- `run.bat` — IDE
|
||
- `rund.bat` — IDE, debug
|
||
- `runa.bat` — AHCI
|
||
- `runad.bat` — AHCI, debug
|
||
|
||
## how it looks when built
|
||
|
||
The ESP is just the boot anchor:
|
||
|
||
```text
|
||
efi/boot/
|
||
bootx64.efi
|
||
efi/ntlite/fs/
|
||
...
|
||
boot.ini
|
||
```
|
||
|
||
The configured system volume carries the OS:
|
||
|
||
```text
|
||
system/
|
||
colonel.exe
|
||
hal.dll
|
||
init.exe
|
||
rssrv.exe
|
||
syscall.dll
|
||
win32.dll
|
||
posix.dll
|
||
settings.ini
|
||
drivers/
|
||
drivers.ini
|
||
ahci.sys
|
||
ata.sys
|
||
fat.sys
|
||
hda.sys
|
||
lwip.sys
|
||
ntfs.sys
|
||
ext4.sys
|
||
pci.sys
|
||
ps2.sys
|
||
rtl816x.sys
|
||
rtl8139.sys
|
||
cereal.sys
|
||
usb.sys
|
||
vmwaresvga.sys
|
||
apps/
|
||
shell_native.exe
|
||
shell_win32.exe
|
||
shell_posix.exe
|
||
doom.exe
|
||
video.exe
|
||
edit.exe
|
||
httpget.exe
|
||
tcpserve.exe
|
||
udp.exe
|
||
resolve.exe
|
||
ping.exe
|
||
memtop.exe
|
||
```
|
||
|
||
## screenshots
|
||
|
||

|
||
|
||
## faq
|
||
|
||
Q: Is it secure?
|
||
A: Don't connect to the internet with it.
|
||
|
||
Q: Who is this for?
|
||
A: Me.
|
||
|
||
Q: What's next?
|
||
A: Whatever I fixate on next.
|
||
|
||
Q: Does it run Doom?
|
||
A: `doom.exe`
|
||
|
||
Q: Can it play Crysis?
|
||
A: Into the bucket list.
|
||
|
||
Q: Does USB work?
|
||
A: It did for everything I threw at it.
|
||
|
||
Q: If I write a program now, will it run in the future?
|
||
A: WE DO, in fact, BREAK USERSPACE.
|
||
|
||
Q: Can you read and write files?
|
||
A: As far as I'm aware.
|
||
|
||
Q: Does it have async I/O?
|
||
A: The best you'll get.
|
||
|
||
Q: Does the networking actually work?
|
||
A: It didn't crash yet.
|
||
|
||
Q: Does it really have SMP?
|
||
A: Watch out. It bites.
|
||
|
||
Q: Is the Win32 layer real?
|
||
A: API wise, yes. Binary compatibility wise, close but no.
|
||
|
||
Q: Are processes isolated?
|
||
A: No. But IPC is free. And you can't steal handles. Is this how a serious modern OS should isolate processes? No.
|
||
Are we a serious OS? No. Is it very convenient? Absolutely.
|
||
|
||
Q: How often does it crash?
|
||
A: It doesn't if you don't touch it.
|
||
|
||
Q: Can it recover from a crash?
|
||
A: Works on my machine.
|
||
|
||
Q: Is this finished?
|
||
A: Does it look finished?
|
||
|
||
Q: Will it corrupt my data?
|
||
A: It shouldn't.
|
||
|
||
Q: Why is the path syntax so weird?
|
||
A: It makes sense to me.
|
||
|
||
Q: Why are the logs so verbose?
|
||
A: Try debugging an interrupt path with vibes.
|
||
|
||
Q: What should I read first?
|
||
A: This document.
|
||
|
||
Q: How do I contribute?
|
||
A: `maksw@maksw.pl`
|
||
|
||
Q: Can I use this in production?
|
||
A: Don't.
|
||
|
||
#### Project dedicated to the honorable, esteemed Professor Leszek Wójcik through whom I came to hate Unix.
|