/asm/boot/test/disk.s

http://github.com/dennis-gemini/tests · Assembly · 64 lines · 50 code · 8 blank · 6 comment · 0 complexity · 9cc071dd6338d16a885a1ac454aa6184 MD5 · raw file

  1. .code16
  2. .text
  3. #############################################
  4. #
  5. # read sectors
  6. #
  7. # input:
  8. # %ax = sector number
  9. # %cx = count
  10. # %es:%bx = buffer
  11. #
  12. # output:
  13. # %ax = result code
  14. # %cx = count
  15. #
  16. #############################################
  17. .global read_sectors
  18. read_sectors:
  19. /******************************************************
  20. * LBA to CHS
  21. * Sector = (LBA % BPB_SecPerTrk) + 1
  22. * Head = (LBA / BPB_SecPerTrk) % BPB_NumHeads
  23. * Cylinder = (LBA / BPB_SecPerTrk) / BPB_NumHeads
  24. ******************************************************/
  25. push %dx
  26. push %si
  27. push %cx
  28. xor %dx, %dx
  29. divw (BPB_SecPerTrk)
  30. inc %dl
  31. mov %dl, %cl # cl = sector
  32. xor %dx, %dx
  33. divw (BPB_NumHeads)
  34. mov %al, %ch # ch = cylinder(track)
  35. mov %dl, %dh # dh = head
  36. movb (BS_DrvNum), %dl # dl = drive
  37. pop %ax
  38. mov $0x02, %ah #INPUT al: number of sectors, ch: track, cl: sector, dh: head, dl: drive, es:bx: buffer
  39. int $0x13 #OUTPUT ah: return code, al: number of sectors read
  40. mov %ax, %cx
  41. jc 1f
  42. #reset drive
  43. xor %ah, %ah
  44. int $0x13
  45. jmp 2f
  46. 1:
  47. #let it fail immediately
  48. mov $'!', %ax
  49. call putchar
  50. int $0x18
  51. 2:
  52. mov %ch, %al
  53. xor %ch, %ch
  54. pop %si
  55. pop %dx
  56. ret