mbr.S 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. .section .text.bootsect
  2. .code16
  3. .globl mbr_start
  4. mbr_start:
  5. movw %cs, %ax
  6. movw %ax, %ds
  7. movw %ax, %es
  8. movw %ax, %ss
  9. # perform a temporary stack
  10. movw $stack_base, %ax
  11. movw %ax, %bp
  12. movw %ax, %sp
  13. # read the first 64k
  14. call read_data
  15. # read the rest
  16. addw $(0x100 * 16), read_data_segment
  17. addl $(8 * 16), read_data_lba
  18. call read_data
  19. # loader start
  20. jmp 0x7e00
  21. read_data:
  22. movw $read_data_pack, %si
  23. mov $0x42, %ah
  24. mov $0x80, %dl
  25. int $0x13
  26. jc read_data_error
  27. ret
  28. read_data_error:
  29. hlt
  30. jmp read_data_error
  31. .align 4
  32. read_data_pack:
  33. .byte 0x10, 0
  34. read_data_count:
  35. .word 128 # sector count (read 64k)
  36. read_data_offset:
  37. .word 0x0000 # offset address
  38. read_data_segment:
  39. .word 0x07e0 # segment address
  40. read_data_lba:
  41. .long 1 # lower 4 bytes of the LBA to read
  42. .long 0 # higher 2 bytes of the LBA to read
  43. __mbr_code_border__:
  44. .long 0xffffffff
  45. .align 16
  46. stack_edge:
  47. .space 128
  48. stack_base:
  49. . = 510
  50. .byte 0x55, 0xaa