.set MBALIGN, 1<<0 # align loaded modules on page boundaries .set MEMINFO, 1<<1 # provide memory map .set FLAGS, MBALIGN | MEMINFO # this is the Multiboot 'flag' field .set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header .set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot .section .multiboot .align 4 .long MAGIC .long FLAGS .long CHECKSUM .section .bootstrap_stack, "aw", @nobits .align 16 stack_bottom: .skip 16384 # 16 KiB stack_top: .section .bss, "aw", @nobits .align 4096 boot_pagedir: .skip 4096 boot_pagetab1: .skip 4096 .section .text .global _start .type _start, @function _start: mov $(boot_pagetab1 - 0xC0000000), %edi mov $0, %esi mov $1023, %ecx 1: cmp $(_kernel_start - 0xC0000000), %esi jl 2f cmp $(_kernel_end - 0xC0000000), %esi jge 3f mov %esi, %edx or $0x003, %edx mov %edx, (%edi) 2: add $4096, %esi add $4, %edi loop 1b 3: movl $(boot_pagetab1 - 0xC0000000 + 0x003), boot_pagedir - 0xC0000000 + 0 movl $(boot_pagetab1 - 0xC0000000 + 0x003), boot_pagedir - 0xC0000000 + 768 * 4 movl $(boot_pagedir - 0xC0000000), %ecx mov %ecx, %cr3 mov %cr0, %ecx or $0x80010000, %ecx mov %ecx, %cr0 lea 4f, %ecx jmp *%ecx 4: movl $0, boot_pagedir + 0 mov %cr3, %ecx mov %ecx, %cr3 mov $stack_top, %esp call kernel_main cli .hang: hlt jmp .hang .end: .size _start, . - _start