boot.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Boot sector: load contiguous kernel sectors 1..N to 0x7E00,
  2. then jump to 0x7E00 in real mode (VESA stage handles the rest). */
  3. .code16
  4. .section .text
  5. .globl _start
  6. _start:
  7. .byte 0xEB, 0x3E, 0x90
  8. .space 0x3E - 3, 0
  9. .org 0x3E
  10. kernel_sectors:
  11. .word 1
  12. .org 0x40
  13. loader_start:
  14. xorw %ax, %ax
  15. movw %ax, %ds
  16. movw %ax, %ss
  17. movw $0x7c00, %sp
  18. movb %dl, boot_drive
  19. movw $0x0003, %ax
  20. int $0x10
  21. load_kernel:
  22. movw kernel_sectors, %cx
  23. movw $1, %si
  24. movw $0x07e0, %ax
  25. movw %ax, %es
  26. xorw %bx, %bx
  27. load_loop:
  28. cmpw $0, %cx
  29. jz load_done
  30. pushw %cx
  31. pushw %si
  32. movb boot_drive, %dl
  33. cmpb $0x80, %dl
  34. jb read_chs
  35. xorw %ax, %ax
  36. movw %ax, 0x50a
  37. movw %ax, 0x50c
  38. movw %ax, 0x50e
  39. movb $0x10, 0x500
  40. movb %al, 0x501
  41. incw %ax
  42. movw %ax, 0x502
  43. movw %bx, 0x504
  44. movw %es, 0x506
  45. movw %si, 0x508
  46. movw $0x500, %si
  47. movb $0x42, %ah
  48. jmp do_int13
  49. read_chs:
  50. movw %si, %ax
  51. xorw %dx, %dx
  52. movw $18, %di
  53. divw %di
  54. movb %dl, %cl
  55. incb %cl
  56. xorw %dx, %dx
  57. movw $2, %di
  58. divw %di
  59. movb %dl, %dh
  60. movb %al, %ch
  61. movb boot_drive, %dl
  62. movb $0x02, %ah
  63. movb $1, %al
  64. do_int13:
  65. int $0x13
  66. popw %si
  67. popw %cx
  68. jc halt
  69. addw $0x200, %bx
  70. jnc 1f
  71. movw %es, %ax
  72. addw $0x1000, %ax
  73. movw %ax, %es
  74. 1: incw %si
  75. decw %cx
  76. jnz load_loop
  77. load_done:
  78. /* Jump to VESA stage at 0x7E00 (real mode). */
  79. ljmp $0x0000, $0x7E00
  80. boot_drive:
  81. .byte 0
  82. halt:
  83. cli
  84. 1: hlt
  85. jmp 1b
  86. .section .bootsig
  87. .byte 0x55, 0xaa