%define MAGIC 0x1BADB002 %define FLAGS 0x0 section .multiboot dd MAGIC dd FLAGS dd -(MAGIC + FLAGS) section .text global _start _start: cli ; Check if EAX contains this magic value that our bootloader should've set cmp eax, 0x2BADB002 jne halt ; Load GDT lgdt [gdtp] ; Offset to kernel data descriptor mov ax, 0x10 mov es, ax mov ds, ax mov fs, ax mov gs, ax mov ss, ax ; Offset to kernel code descriptor jmp 0x8:.use_code_seg .use_code_seg: mov esp, stack_bottom mov ebp, esp push ebx and esp, 0xfffffff0 extern kernel call kernel cli halt: hlt jmp halt section .data ; GDT for a flat memory layout ; We get access to all memory and can utilize paging global gdt gdt: gdt_null: dq 0 gdt_kern_code: dw 0xffff dw 0x0000 db 0x00 db 0b10011010 db 0b11001111 db 0x00 gdt_kern_data: dw 0xffff dw 0x0000 db 0x00 db 0b10010010 db 0b11001111 db 0x00 gdt_end: gdtp: dw gdt_end - gdt - 1 dd gdt section .bss align 16 stack_top: resb 16384 stack_bottom: