Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .global boot
- # multiboot header fields
- .set MB_ALIGN, 1 << 0
- .set MB_MEMINFO, 1 << 1
- .set MB_FLAGS, (MB_ALIGN + MB_MEMINFO)
- .set MB_MAGIC, 0x1BADB002
- .set MB_CHECKSUM, -(MB_FLAGS + MB_MAGIC)
- # kernel virtual address
- .set KERNEL_VIRTBASE, 0xC0000000
- .set KERNEL_PAGENUM, (KERNEL_VIRTBASE >> 22)
- .section .data
- .align 0x1000
- # page directory
- boot_pgdir:
- # temporary entry for while paging is being set up
- .long 0x00000083
- # space before kernel
- .rept (KERNEL_PAGENUM - 1)
- .long 0x00000000
- .endr
- # page containing kernel
- .long 0x00000083
- # space after kernel
- .rept (1023 - KERNEL_PAGENUM)
- .long 0x00000000
- .endr
- .section .text
- # multiboot header
- .align 4
- .long MB_MAGIC
- .long MB_FLAGS
- .long MB_CHECKSUM
- # reserve space for kernel stack
- .set STACK_SIZE, 0x4000
- .comm stack, STACK_SIZE, 32
- boot:
- # load address of page directory into cr3
- mov $(boot_pgdir - KERNEL_VIRTBASE), %ecx
- mov %ecx, %cr3
- # enable 4mb pages
- mov %cr4, %ecx
- or $0x00000010, %ecx
- mov %ecx, %cr4
- # enable paging
- mov %cr0, %ecx
- or $0x80000000, %ecx
- mov %ecx, %cr0
- # jump to higher half
- lea (higher_half), %ecx
- jmp *%ecx
- higher_half:
- # unmap the first page directory entry
- movl $0, (boot_pgdir)
- invlpg (0)
- # set up the stack
- mov $(stack + STACK_SIZE), %esp
- # pass multiboot information to kernel
- push %eax
- push %ebx
- # jump to kernel
- call kinit
- # kernel returned, halt the machine
- cli
- hang:
- hlt
- jmp hang
Advertisement
Add Comment
Please, Sign In to add comment