mbr.S 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 following 128k
  16. addw $(0x100 * 16), read_data_segment
  17. addl $(8 * 16), read_data_lba
  18. call read_data
  19. addw $(0x100 * 16), read_data_segment
  20. addl $(8 * 16), read_data_lba
  21. call read_data
  22. # loader start
  23. jmp 0x8000
  24. read_data:
  25. movw $read_data_pack, %si
  26. mov $0x42, %ah
  27. mov $0x80, %dl
  28. int $0x13
  29. jc read_data_error
  30. ret
  31. read_data_error:
  32. hlt
  33. jmp read_data_error
  34. .align 4
  35. read_data_pack:
  36. .byte 0x10, 0
  37. read_data_count:
  38. .word 128 # sector count (read 64k)
  39. read_data_offset:
  40. .word 0x0000 # offset address
  41. read_data_segment:
  42. .word 0x0800 # segment address
  43. read_data_lba:
  44. .long 1 # lower 4 bytes of the LBA to read
  45. .long 0 # higher 2 bytes of the LBA to read
  46. __mbr_code_border__:
  47. .long 0xffffffff
  48. .align 16
  49. stack_edge:
  50. .space 128
  51. stack_base:
  52. . = 510
  53. .byte 0x55, 0xaa