boot.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. .code16
  2. main:
  3. ljmp $0x0,$0x7c05
  4. main2:
  5. mov $0x0, %ax
  6. mov %ax, %ds
  7. mov %ax, %ss
  8. mov $0x7b00, %ax
  9. mov %ax, %sp
  10. mov $0x500, %ax
  11. mov %ax, %es
  12. clc
  13. int $0x12
  14. mov %ax, (lower_mem)
  15. mov $0x0, %di
  16. call do_e820
  17. jc hang
  18. cli
  19. in $0x92, %al
  20. or $2, %al
  21. out %al, $0x92
  22. xor %eax, %eax
  23. mov %ds, %ax
  24. shl $4, %eax
  25. add $gdt_base, %eax
  26. mov %eax, gdtr+2
  27. mov $gdt_end, %eax
  28. sub $gdt_base, %eax
  29. mov %ax, gdtr
  30. lgdtw gdtr
  31. mov %cr0, %eax
  32. or $1, %eax
  33. mov %eax, %cr0
  34. mov $0x10, %ax
  35. mov %ax, %ds
  36. mov %ax, %es
  37. mov %ax, %fs
  38. mov %ax, %gs
  39. mov %ax, %ss
  40. .global kmain
  41. ljmp $0x08,$kmain
  42. hang:
  43. jmp hang
  44. do_e820:
  45. xor %ebx, %ebx
  46. xor %bp, %bp
  47. mov $0x534D4150, %edx
  48. mov $0xe820, %eax
  49. movl $0x1,%es:20(%di)
  50. mov $24, %ecx
  51. int $0x15
  52. jb do_e820.failed
  53. mov $0x534D4150, %edx
  54. cmp %edx, %eax
  55. jne do_e820.failed
  56. test %ebx, %ebx
  57. je do_e820.failed
  58. jmp do_e820.jmpin
  59. do_e820.e820lp:
  60. mov $0xe820, %eax
  61. movl $0x1,%es:20(%di)
  62. mov $24, %ecx
  63. int $0x15
  64. jb do_e820.e820f
  65. mov $0x534D4150, %edx
  66. do_e820.jmpin:
  67. jcxz do_e820.skipent
  68. cmp $20, %cl
  69. jbe do_e820.notext
  70. testb $0x1, %es:20(%di)
  71. je do_e820.skipent
  72. do_e820.notext:
  73. mov %es:8(%di), %ecx
  74. or %es:12(%di), %ecx
  75. jz do_e820.skipent
  76. inc %bp
  77. add $24, %di
  78. do_e820.skipent:
  79. test %ebx, %ebx
  80. jne do_e820.e820lp
  81. do_e820.e820f:
  82. mov %bp, mmap_ent
  83. clc
  84. ret
  85. do_e820.failed:
  86. stc
  87. ret
  88. .align 8
  89. gdtr:
  90. .word 0
  91. .long 0
  92. gdt_base:
  93. .quad 0
  94. .word 0xFFFF
  95. .word 0
  96. .byte 0
  97. .byte 0x9a
  98. .byte 0xcf
  99. .byte 0
  100. .word 0xffff
  101. .word 0
  102. .byte 0
  103. .byte 0x92
  104. .byte 0xcf
  105. .byte 0
  106. gdt_end:
  107. .global mmap_ent
  108. mmap_ent:
  109. .byte 0
  110. .byte 0
  111. .global lower_mem
  112. lower_mem:
  113. .byte 0
  114. .byte 0