bits 32 global start ; multiboot header MODULEALIGN equ 1<<0 MEMINFO equ 1<<1 VIDEOINFO equ 1<<2 FLAGS equ MODULEALIGN | MEMINFO | VIDEOINFO MAGIC equ 0x1BADB002 CHECKSUM equ -(MAGIC + FLAGS) align 4 section .__mbHeader MultiBootHeader: dd MAGIC dd FLAGS dd CHECKSUM section .text STACKSIZE equ 0x4000 ; that's 16k. start: XCHG BX, BX ; magic breakpoint mov ecx, eax ; lgdt [trickgdt] ; mov ax, 0x10; ; mov ds, ax ; mov es, ax ; mov fs, ax ; mov gs, ax ; mov ss, ax ; jmp 0x08:HigherHalf ; NOTE: Must be absolute jump! HigherHalf: ; Verify booted with multiboot compliant bootloader mov esp, stack+STACKSIZE cmp ecx, 0x2BADB002 jne .bad push ebx extern k_main call k_main ; Show error message, and halt system .bad: extern ConsoleClear extern ConsoleWrite extern CommandOsver call ConsoleClear call CommandOsver mov eax, [ErrorColor] push eax push ErrorString call ConsoleWrite cli hlt ; some variables ErrorString db 0xA, "%#! Fatal error: Not booted with multiboot compliant bootloader (e.g. GRUB).", 0x0 ErrorColor db 0x0C ; tells the assembler to include this data in the '.setup' section section .setup trickgdt: dw gdt_end - gdt - 1 ; size of the GDT dd gdt ; linear address of GDT gdt: dd 0, 0 ; null gate db 0xFF, 0xFF, 0, 0, 0, 10011010b, 11001111b, 0x40 ; code selector 0x08: base 0x40000000, limit 0xFFFFFFFF, type 0x9A, granularity 0xCF db 0xFF, 0xFF, 0, 0, 0, 10010010b, 11001111b, 0x40 ; data selector 0x10: base 0x40000000, limit 0xFFFFFFFF, type 0x92, granularity 0xCF gdt_end: ; stack section .bss align 32 stack: resb STACKSIZE ; This reserves 64KBytes of memory here