116 lines
2.8 KiB
Markdown
116 lines
2.8 KiB
Markdown
# NT-Lite -- an x86-64 kernel
|
||
|
||
Boots. Runs processes. Mimics Windows to some extent.
|
||
|
||
## what is it?
|
||
|
||
A 64-bit operating system kernel written from scratch.
|
||
UEFI bootloader, physical and virtual memory managers, preemptive scheduler, HAL, VFS, PE loader, partial Win32 layer.
|
||
It boots into a shell.
|
||
~20k lines of C and assembly.
|
||
|
||
## features
|
||
|
||
- UEFI bootloader
|
||
- physical memory manager
|
||
- virtual memory manager with kernel pool
|
||
- HAL (screen, keyboard, timer, disk, PCI, APIC)
|
||
- preemptive scheduler with priority levels
|
||
- processes and threads
|
||
- VFS with IRPs
|
||
- drive-letter paths (`0:\apps\shell.exe`)
|
||
- INI-based boot and driver configuration
|
||
- partial Win32 layer (kernel32 and user32, capable of running simple windows apps)
|
||
- PE import resolution and dynamic driver loading
|
||
|
||
## how 2 build
|
||
|
||
* open env variables
|
||
* set `NTLITE_DRIVE` as your thumbdrive (ex. `G:`)
|
||
* set `NTLITE_NTPATH` as your thumbdrive (ex. `\\.\PhysicalDrive7`)
|
||
* open vs x64 build tools
|
||
* cd into this directory
|
||
* `build.bat`
|
||
* `run.bat`(ide)/`rund.bat`(ide, debug)/`runa.bat`(ahci)/`runad.bat`(ahci, debug)
|
||
* enjoy
|
||
|
||
## how it looks when built
|
||
|
||
I have some strong opinions on OS design.
|
||
|
||
```
|
||
efi/boot/
|
||
bootx64.efi
|
||
boot.ini
|
||
hal.dll
|
||
colonel.exe
|
||
drivers/
|
||
drivers.ini
|
||
ide.sys
|
||
ahci.sys
|
||
fat32.sys
|
||
syscall.dll
|
||
win32.dll
|
||
posix.dll
|
||
shell.exe
|
||
video.exe
|
||
```
|
||
|
||
## driver model
|
||
|
||
drivers are PE32+ `.sys` files with an entry point preferably named DriverEntry accepting a constant pointer to HAL_API.
|
||
|
||
drivers to be loaded have their path stored in `drivers.ini`, split into essential for boot (loaded by bootloader) and not required for boot (loaded by kernel).
|
||
|
||
a disk driver fills in a `DISK_DRIVER` vtable and calls `IoRegisterDisk(index, &driver)`.
|
||
a filesystem driver fills in an `IO_FILESYSTEM` vtable and calls `IoRegisterFilesystem(index, &fs, &vol)`.
|
||
|
||
currently shipping: AHCI (interrupts), IDE (PIO/DMA), FAT32 (read-only).
|
||
|
||
## how it boots
|
||
|
||
1. UEFI loads `boot.ini`, reads `drivers.ini`
|
||
2. bootloader maps kernel, HAL, and boot drivers into the upper half
|
||
3. direct physical window at `0xFFFF880000000000`
|
||
4. jumps to `KernelMain`
|
||
5. PMM, VMM, GDT, IDT, HAL, IRQs, scheduler
|
||
6. loads runtime drivers from disk
|
||
7. launches `shell.exe`
|
||
|
||
## paths
|
||
|
||
```
|
||
"apps\shell.exe" -> drive 0
|
||
"0:\apps\shell.exe" -> drive 0
|
||
"2:\data\config.ini" -> drive 2
|
||
```
|
||
|
||
drives 0–7. a drive only works if a filesystem registered on it.
|
||
|
||
## screenshots
|
||
|
||

|
||
|
||
## faq
|
||
|
||
Q: Why?
|
||
A: Why not?
|
||
|
||
Q: Does it run Doom?
|
||
A: Not yet.
|
||
|
||
Q: Is the Win32 layer real?
|
||
A: Real enough to load binaries that expect it. Not real enough to run Notepad.
|
||
|
||
Q: Is the scheduler preemptive?
|
||
A: As much as it will ever be.
|
||
|
||
Q: Will it corrupt my data?
|
||
A: How would it? It's read-only.
|
||
|
||
Q: Is this finished?
|
||
A: Not in the slightest.
|
||
|
||
Q: Can I use this in production?
|
||
A: Don't.
|