boot.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. .set MB_MAGIC, 0x1BADB002
  2. .set MB_FLAG_PAGE_ALIGN, 1 << 0
  3. .set MB_FLAG_MEMORY_INFO, 1 << 1
  4. .set MB_FLAG_GRAPHICS, 1 << 2
  5. .set MB_FLAGS, MB_FLAG_PAGE_ALIGN | MB_FLAG_MEMORY_INFO | MB_FLAG_GRAPHICS
  6. .set MB_CHECKSUM, -(MB_MAGIC + MB_FLAGS)
  7. .section .multiboot
  8. .align 4
  9. /* Multiboot section */
  10. .long MB_MAGIC
  11. .long MB_FLAGS
  12. .long MB_CHECKSUM
  13. .long 0x00000000 /* header_addr */
  14. .long 0x00000000 /* load_addr */
  15. .long 0x00000000 /* load_end_addr */
  16. .long 0x00000000 /* bss_end_addr */
  17. .long 0x00000000 /* entry_addr */
  18. /* Request linear graphics mode */
  19. .long 0x00000000
  20. .long 0
  21. .long 0
  22. .long 32
  23. /* .stack resides in .bss */
  24. .section .stack, "aw", @nobits
  25. stack_bottom:
  26. .skip 32768 /* 32KiB */
  27. stack_top:
  28. .section .text
  29. .global start
  30. .type start, @function
  31. .extern kmain
  32. .type kmain, @function
  33. start:
  34. /* Setup our stack */
  35. mov $stack_top, %esp
  36. /* Make sure our stack is 16-byte aligned */
  37. and $-16, %esp
  38. pushl %esp
  39. pushl %eax /* Multiboot header magic */
  40. pushl %ebx /* Multiboot header pointer */
  41. /* Disable interrupts and call kernel proper */
  42. cli
  43. call kmain
  44. /* Clear interrupts and hang if we return from kmain */
  45. cli
  46. hang:
  47. hlt
  48. jmp hang