Guest User

Untitled

a guest
Jun 16th, 2010
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .global boot
  2.  
  3. # multiboot header fields
  4. .set MB_ALIGN,    1 << 0
  5. .set MB_MEMINFO,  1 << 1
  6. .set MB_FLAGS,    (MB_ALIGN + MB_MEMINFO)
  7. .set MB_MAGIC,    0x1BADB002
  8. .set MB_CHECKSUM, -(MB_FLAGS + MB_MAGIC)
  9.  
  10. # kernel virtual address
  11. .set KERNEL_VIRTBASE, 0xC0000000
  12. .set KERNEL_PAGENUM,  (KERNEL_VIRTBASE >> 22)
  13.  
  14. .section .data
  15. .align 0x1000
  16.  
  17. # page directory
  18. boot_pgdir:
  19. # temporary entry for while paging is being set up
  20. .long 0x00000083
  21. # space before kernel
  22. .rept (KERNEL_PAGENUM - 1)
  23. .long 0x00000000
  24. .endr
  25. # page containing kernel
  26. .long 0x00000083
  27. # space after kernel
  28. .rept (1023 - KERNEL_PAGENUM)
  29. .long 0x00000000
  30. .endr
  31.  
  32. .section .text
  33. # multiboot header
  34. .align 4
  35. .long MB_MAGIC
  36. .long MB_FLAGS
  37. .long MB_CHECKSUM
  38.  
  39. # reserve space for kernel stack
  40. .set STACK_SIZE, 0x4000
  41. .comm stack, STACK_SIZE, 32
  42.  
  43. boot:
  44.     # load address of page directory into cr3
  45.     mov $(boot_pgdir - KERNEL_VIRTBASE), %ecx
  46.     mov %ecx, %cr3
  47.  
  48.     # enable 4mb pages
  49.     mov %cr4, %ecx
  50.     or $0x00000010, %ecx
  51.     mov %ecx, %cr4
  52.  
  53.     # enable paging
  54.     mov %cr0, %ecx
  55.     or $0x80000000, %ecx
  56.     mov %ecx, %cr0
  57.  
  58.     # jump to higher half
  59.     lea (higher_half), %ecx
  60.     jmp *%ecx
  61.  
  62. higher_half:
  63.     # unmap the first page directory entry
  64.     movl $0, (boot_pgdir)
  65.     invlpg (0)
  66.  
  67.     # set up the stack
  68.     mov $(stack + STACK_SIZE), %esp
  69.  
  70.     # pass multiboot information to kernel
  71.     push %eax
  72.     push %ebx
  73.  
  74.     # jump to kernel
  75.     call kinit
  76.  
  77.     # kernel returned, halt the machine
  78.     cli
  79. hang:
  80.     hlt
  81.     jmp hang
Advertisement
Add Comment
Please, Sign In to add comment