Advertisement
MichaelPetch

SO78264246

Apr 2nd, 2024 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. org 0x7C00
  2. bits 16
  3.  
  4. mov ax, 0
  5. mov es, ax
  6. mov ds, ax
  7. mov ss, ax
  8. mov sp, 0x7c00 ; Stack will grow down below the bootloader.
  9. mov [bdv], dl
  10.  
  11. jmp main
  12.  
  13.  
  14. ; lbaRead
  15. ; Reads sectors using LBA
  16. ; bx: LBA Address
  17. ; ax: Number of sectors
  18. ; dl: Drive number
  19. lbaRead:
  20. ; Save AX and BX
  21. mov [snm], ax
  22. push bx
  23.  
  24. ; Read the Disk Geometry
  25. mov ah, 8
  26. mov di, 0
  27. int 0x13
  28. ; Error Handling
  29. jc err
  30. ; continue
  31. ; Int 0x13/ah=8 can set ES to non zero segment
  32. ; set ES back to 0
  33. mov ax, 0
  34. mov es, ax
  35.  
  36. inc dh
  37. mov [hct], dh
  38. and cl, 0x3F
  39. mov [spt], cl
  40.  
  41. ; Restore BX clobbered by previous int 13h
  42. pop bx
  43.  
  44. ; Convert LBA to CHS
  45. ; Calculate temporary value (tmp) and sector
  46. mov dx, 0
  47. mov ax, bx
  48. mov bx, [spt]
  49. div bx
  50. inc dl
  51. mov [sct], dl
  52. ; Calculate Head and Cylinder
  53. mov dx, 0
  54. mov bx, [hct]
  55. div bx
  56. mov [hed], dl
  57. mov [cyl], ax
  58.  
  59. ; Read the disk
  60. mov ah, 0x02
  61. mov al, [snm]
  62. mov ch, [cyl]
  63. mov cl, [sct]
  64. mov dh, [hed]
  65. mov dl, [bdv]
  66. mov bx, 0x7E00
  67. int 0x13
  68. ; Error handling
  69. jc err
  70. ret
  71.  
  72. main:
  73. pusha
  74. mov bx, 1
  75. mov ax, 1
  76. call lbaRead
  77. popa
  78.  
  79. mov ah, 0x0E
  80. mov al, [0x7E00]
  81. int 0x10
  82. jmp $
  83.  
  84. err:
  85. mov ah, 0x0B
  86. mov bl, 0x4
  87. int 0x10
  88. jmp $
  89.  
  90. ; Variables for CHS conversion
  91. tmp: dw 0
  92. sct: db 0
  93. hed: db 0
  94. cyl: dw 0
  95. spt: dw 0
  96. hct: dw 0
  97. bdv: db 0
  98. snm: dw 0
  99.  
  100. ; Pad to 512 bytes and add 0x55AA cap
  101. times 510-($-$$) db 0
  102. db 0x55, 0xaa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement