bios_disk_load.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples#bios-disk-load */
  2. #include "common.h"
  3. BEGIN
  4. CLEAR
  5. /* Reset disk. TODO is this really needed?
  6. * Was suggested in one tutorial.
  7. */
  8. /*mov $0, %ah
  9. *mov $0x80, %dl
  10. *int $0x13
  11. */
  12. /* Read sectors into memory */
  13. mov $2, %ah
  14. /* Number of sectors to read. */
  15. mov $1, %al
  16. /* Drive number. Starts at 0x80, second one is 0x81. TODO why not from 0?
  17. *
  18. * The BIOS stores the right number on dl as an initial state,
  19. * but we may be destroying it before, and are lazy to properly store it somewhere.
  20. * http://stackoverflow.com/a/19387093/895245
  21. */
  22. mov $0x80, %dl
  23. /* cylinder number */
  24. mov $0, %ch
  25. /* Head number */
  26. mov $0, %dh
  27. /* Starting sector number. 2 because 1 was already loaded. */
  28. mov $2, %cl
  29. /* Where to load to.
  30. * Must coincide with our stage2 for the linking to work.
  31. *
  32. * The address is calculated as:
  33. *
  34. * ....
  35. * 16 * ES + BX
  36. * ....
  37. */
  38. mov $stage2, %bx
  39. int $0x13
  40. jmp stage2
  41. /* Our linker script will put this section on the right place in memory:
  42. * just after the magic bytes.
  43. */
  44. .section .stage2
  45. stage2:
  46. PUTC $'a
  47. hlt
  48. /* We could use `.org` here to fill up the second sector to a multiple of 512 bytes.
  49. * But the linker does that beautifully with `. = ALIGN(512)` for any size of stage2,
  50. * so we use that instead.
  51. */
  52. /*.org 512*/