NKLegacy targets the classic x86 real-mode / protected-mode physical memory map. Everything below 640 KB (0xA0000) is available for bootloader code, stacks, and temporary buffers; the region from 0xA0000 to 0xFFFFF is reserved for video memory and BIOS ROM. The kernel itself is linked and loaded at exactly 1 MB (0x100000), safely above the reserved zone, and its section layout is fixed at build time byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pastaboy12345/NKLegacy/llms.txt
Use this file to discover all available pages before exploring further.
ntoskrnl/linker.ld.
Physical Memory Map
0xB8000 is mapped directly by vga_clear() and vga_print() as a bare pointer; no memory-management layer is involved.
Linker Script — ntoskrnl/linker.ld
The linker script sets the virtual-address origin to 0x100000 and lays out five sections, each aligned to a 4-byte or 4 KB boundary:
Section Descriptions
| Section | Alignment | Contents |
|---|---|---|
.multiboot | 4 bytes | Multiboot magic, flags, checksum — must be within the first 8 KB of the image |
.text | 4 KB | All executable code (*(.text) and *(.text.*)) |
.rodata | 4 KB | Read-only data: string literals, const globals |
.data | 4 KB | Initialized read/write globals |
.bss | 4 KB | Zero-initialized globals and COMMON symbols; not stored in the ELF file |
.multiboot section is placed before .text and given only 4-byte alignment rather than 4 KB so that the three-dword Multiboot header (12 bytes) lands within the first 8 KB of the image, satisfying the Multiboot specification. The _kernel_start and _kernel_end symbols bracket the entire image and can be used for size calculations.
The /DISCARD/ block strips .comment (GCC version strings), .note.* (build ID notes), and .eh_frame (C++ exception unwinding data) from the output — none of these are needed in a freestanding kernel.
NKFS Data Pool (.bss)
The NKFS in-memory filesystem allocates all its storage as static arrays, which the linker places in .bss:
.bss and occupy no space in the ELF file on disk. The bootloader or GRUB zeroes the BSS range between _bss_start and _bss_end before calling _start, so nkfs_init() sees clean storage and merely sets its allocation counters to zero before creating the root node.
The kernel is compiled with
-m32 -ffreestanding -nostdlib -nostdinc. There is no heap and no malloc; every data structure in NKLegacy uses static allocation. All memory management is resolved entirely at link time — the linker script and section sizes determine the complete memory footprint before the kernel ever runs.Stack Placement
Two distinct stacks exist during the boot sequence:- Real-mode stack (Stage 1 / Stage 2):
SPis initialized to0x7C00in Stage 1, growing downward into low conventional memory. Stage 2 temporarily setsESPto0x90000after entering protected mode. - Kernel stack (Multiboot path):
boot.asmdeclares a 16 KBresb 16384buffer in.bsslabelledstack_bottom/stack_top._startsetsESP = stack_topbefore callingkmain, so the kernel stack sits entirely within the kernel image’s.bsssection above 0x100000.