bios_disk_load.S 1.3 KB

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