(c) 2025, 2026 Jens Kallup – paule32 Alle Rechte vorbehalten.
- Real-Mode Bootsektor
- INT 13h Extensions (EDD) Tests
- LBA-Read Tests
- Laden von Stage2
- BIOS Debug-Ausgabe
- Läuft bei 0x0000:0500
- Setzen der Segmente
- Laden des Kernels via LBA
- A20 aktiv
- GDT aufgebaut
- Protected Mode aktiviert
- Kernelstart bei 0x00010000
- Makefile für 32-Bit Cross-Compilation
- kernel.ld erzeugt Flat Binary
- VGA-Ausgabe funktioniert
- PM32 stabil
- Identity Mapping der unteren 4 MiB
- Page Directory + Page Tables
- CR3/CR0 korrekt gesetzt
- Grundstruktur implementiert
- Alignment-Fixes
- Vorbereitung auf malloc/free
- GDT vollständig
- TSS korrekt initialisiert
- ltr erfolgreich
- IDT voll aufgebaut
- Exceptions, IRQs
- PIC remapped
- Syscalls vorbereitet
- enter_usermode funktioniert bis ASM
- Direkter Funktionsaufruf klappt
- Ring 3 via iret in Arbeit
- Boot ohne boot-info-table
- ISO bootet korrekt
- LBA geprüft
WelcomeBackOS now includes all foundational components of a modern 32-bit operating system.
The following subsystems are fully implemented and functional:
- Stage1 loads Stage2 via LBA from CD/ISO.
- Stage2 enables A20, loads the kernel to physical address 0x0010 0000, sets up a minimal GDT, and switches to Protected Mode.
- Control is transferred safely to the 32-bit kernel.
- 32-bit Global Descriptor Table (GDT)
- Fully operational Paging initialization
- Identity-mapped kernel region
- Stable VGA text output
- Clean kernel execution loop using
hlt
-
Page Frame Allocator
Bitmap-based management of physical memory pages. -
Kernel Heap (KHeap)
With pointer-safe alignment usinguintptr_t. -
Paging
Page Directory + Page Tables with identity mapping of the kernel region.
This provides a stable memory foundation for higher-level kernels subsystems, such as tasking, usermode, and ELF loading.
- Complete IDT with 256 entries
- Exception handlers (0–31) implemented
- Unified
regs_tframe passed to C handler - All Exceptions display debugging output
- All Interrupt Stubs implemented in clean, structured 32-bit Assembly
- IDT entry 0x80 with DPL=3, accessible from usermode
- Syscall dispatcher implemented
- First syscall operational (VGA output test)
- Kernel successfully handles software interrupts via a unified interface
This is the groundwork for a full system call layer and later usermode programs.
The next milestone is implementing hardware interrupts, specifically:
These enable:
- Preemptive Kernel Scheduling
- Task Switching
- Usermode transitions
- A real multitasking operating system
Dieses Projekt zeigt Schritt für Schritt, wie man:
- einen El-Torito CD-Bootloader (Stage1 & Stage2) schreibt
- einen 32-Bit Protected-Mode Kernel lädt
- A20 aktiviert, GDT setzt und PM startet
- die Tools NASM, MinGW-w64, LD, OBJCOPY, xorriso installiert und nutzt
- ein komplettes Build-System aus Makefile und ISO-Erstellungs-Script aufsetzt
Damit können Entwickler ein vollständiges eigenes Betriebssystem booten – auf echten PCs, QEMU, VirtualBox usw.
0.1 Boot Flow Diagram
+----------------+ | BIOS | | (real mode) | +--------+-------+ | V +--------+-------+ | Stage 1 | | (0000:0000) | +--------+-------+ | V +--------+-------+ | Stage 2 | | (0000:0500) | +--------+-------+ | V +------------+----------------+ | Load Kernel via INT 13h | | Enable A20, Setup GDT | | Enter Protected Mode | +------------+----------------+ | V +--------+-------+ | Kernel | | (PM: 0x10000) | +----------------+
0.2 Memory Layout Diagram
Real Mode (1 MB Address Space)
0000:0000 +---------------------------+
| Stage 1 |
| Loaded by BIOS (2048 B) |
+---------------------------+
0000:0500 | Stage 2 |
| Loaded by Stage 1 |
+---------------------------+
0050:0000 | Free real-mode region |
+---------------------------+
Protected Mode (32-bit linear memory)
0x00010000 +---------------------------+
| Kernel .text |
| Entry: KernelStart |
+---------------------------+
0x00020000 | Kernel .rodata |
+---------------------------+
0x00030000 | Kernel .data |
+---------------------------+
0x00040000 | Kernel .bss |
+---------------------------+
| Heap, Paging, etc. |
+---------------------------+
0.3 Protected Mode Transition Diagram
Real Mode | | Enable A20 V +--------------------+ | Load GDT | +--------------------+ | | mov eax, cr0 | or eax, 1 ; PE bit | mov cr0, eax V +--------------------+ | PE active (PM) | +--------------------+ | | Far jump to selector:offset | jmp 0x08:pm_entry V +---------------------------+ | pm_entry (32-bit code) | +---------------------------+ | | Jump to kernel entry V +---------------------------+ | KernelStart @ 0x10000 | +---------------------------+
NASM ist der Assembler für Stage1 & Stage2.
Download (Win64):
https://www.nasm.us/pub/nasm/releasebuilds/
Installation:
- ZIP herunterladen
- nach
C:\Tools\nasm\entpacken - PATH erweitern:
set PATH=C:\Tools\nasm;%PATH%
Download:
https://www.mingw-w64.org/downloads/
Empfohlen: Variante “posix-seh”.
Unter MSYS2:
pacman -S xorriso
BIOS → Stage1 → Stage2 → Protected Mode → 32-Bit Kernel
Stage1: lädt Stage2
Stage2: lädt Kernel, aktiviert A20, wechselt in Protected Mode
Kernel: läuft im 32-Bit Modus
Nach ISO-Erstellung:
xorriso -indev bootcd.iso -find /kernel.bin -exec report_lba --
Beispiel:
File data lba: 0 , 38 , 23 , ... , '/kernel.bin'
→ LBA = 38
→ SECTORS = 23
| Komponente | BIOS-Adresse | ORG | Kommentar |
|---|---|---|---|
| Stage1 | 0000:0000 | 0x0000 | El Torito lädt hier |
| Stage2 | 0000:0500 | 0x0500 | Stage1 lädt Stage2 hierhin |
| VESA-Video | 0000:0A00 | 0x0A00 | VESA Video Mode Info Table |
| Kernel | phys 0x10000 | 0x0000 | Stage2 lädt Kernel → PM Jump |
Hier die Offsets des VESA VBE Mode Info Blocks INT 10h, AX=4F01h
------------------------------------------------------- 00h uint16 ModeAttributes 02h uint8 WinAAttributes 03h uint8 WinBAttributes 04h uint16 WinGranularity ; in KB 06h uint16 WinSize ; in KB 08h uint16 WinASegment 0Ah uint16 WinBSegment 0Ch uint32 WinFuncPtr ; Real-Mode Callbacks 10h uint16 BytesPerScanLine ; Direct Color (optional / abhängig vom Modus) ------------------------------------------------------- 12h uint16 XResolution 14h uint16 YResolution 16h uint8 XCharSize 17h uint8 YCharSize 18h uint8 NumberOfPlanes 19h uint8 BitsPerPixel 1Ah uint8 NumberOfBanks 1Bh uint8 MemoryModel 1Ch uint8 BankSize 1Dh uint8 NumberOfImagePages 1Eh uint8 Reserved1 ; Color mask info (für Direct Color / True Color) ------------------------------------------------------- 1Fh uint8 RedMaskSize 20h uint8 RedFieldPosition 21h uint8 GreenMaskSize 22h uint8 GreenFieldPosition 23h uint8 BlueMaskSize 24h uint8 BlueFieldPosition 25h uint8 RsvdMaskSize 26h uint8 RsvdFieldPosition 27h uint8 DirectColorModeInfo ; Physische Linear Framebuffer-Adresse ------------------------------------------------------- 28h uint32 PhysBasePtr ; LFB-Adresse 2Ch uint32 OffScreenMemOffset ; (optional) 30h uint16 OffScreenMemSize ; in KB ; VBE 3.0+ (optional, oft 0 wenn nicht unterstützt) ------------------------------------------------------- 32h uint16 LinBytesPerScanLine 34h uint8 BnkNumberOfImagePages 35h uint8 LinNumberOfImagePages 36h uint8 LinRedMaskSize 37h uint8 LinRedFieldPosition 38h uint8 LinGreenMaskSize 39h uint8 LinGreenFieldPosition 3Ah uint8 LinBlueMaskSize 3Bh uint8 LinBlueFieldPosition 3Ch uint8 LinRsvdMaskSize 3Dh uint8 LinRsvdFieldPosition 3Eh uint32 MaxPixelClock ; in Hz ; 3Fh–FFh: reserviert für VBE, OEM, padding bis 256 Bytes
Stage2:
- Kernel per LBA laden
- A20 aktivieren
- GDT laden (
lgdt) - CR0.PE setzen
- Far-Jump zu 32-Bit Code
- Sprung zu Kernel bei physisch
0x00010000
Dieses Projekt verwendet ein umfangreiches Makefile (siehe Repository).
Script create_iso.sh:
xorriso -as mkisofs -o bootcd.iso -b boot1.bin -no-emul-boot -boot-load-size 4 .
Wichtig: Kein -boot-info-table, sonst wird boot1.bin beschädigt.
Ein vollständiger Bootprozess:
- Stage1 → Stage2 → Protected Mode → Kernel
- Vollständiger 32-Bit Systemstart
- Debug-/LBA-Erkennung
- Reproduzierbar auf jedem System
(c) 2025 Jens Kallup – paule32.
