Advertisement
Guest User

Disk driver and port driver in asm

a guest
Jun 15th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. [bits 32]
  2. ; BX: sector count, CX: drive, EDX: address
  3. ; 0x1F0: Data
  4. ; 0x1F1: Error/Features
  5. ; 0x1F2: Sector Count
  6. ; 0x1F3: Sector Number
  7. ; 0x1F4: Cyl LOW
  8. ; 0x1F5: Cyl HIGH
  9. ; 0x1F6: Drive select
  10. ; 0x1F7: Status/Command
  11. ; 0x3F6: Alt status
  12. disk_op:
  13. ; push used params onto the stack
  14. push ax
  15. push edx
  16. ; Select drive
  17. mov dx, 0x1F6
  18. mov ax, cx
  19. call portbout
  20. ; Select Features
  21. mov dx, 0x1F1
  22. mov ax, 0x00
  23. call portbout
  24. ; Set sector count
  25. mov dx, 0x1F2
  26. movzx ax, bh
  27. call portbout
  28. ; Select start sector
  29. pop edx
  30. mov eax, edx
  31. push edx
  32. mov dx, 0x1F3
  33. call portbout
  34. ; Set cyl low
  35. pop edx
  36. mov eax, edx
  37. push edx
  38. shr eax, 8
  39. mov dx, 0x1F4
  40. call portbout
  41. ; Set cyl high
  42. pop edx
  43. mov eax, edx
  44. push edx
  45. shr eax, 16
  46. mov dx, 0x1F4
  47. call portbout
  48. ; pop used params off the stack
  49. pop edx
  50. pop ax
  51. jmp select_read
  52. mov dx, 0x3F6
  53. handled:
  54. ; return to caller
  55. ret
  56.  
  57.  
  58. drq_set:
  59. call portbin
  60. call portbin
  61. call portbin
  62. call portbin
  63. call portbin
  64. and al, 0x01
  65. cmp al, 0x01
  66. jne read_data
  67. push ebx
  68. mov ebx, ERR_BLOCK
  69. call print_string_pm
  70. pop ebx
  71. jmp handled
  72.  
  73. no_drq:
  74. call portbin
  75. call portbin
  76. call portbin
  77. call portbin
  78. call portbin
  79. call portbin
  80. call portbin
  81. call portbin
  82. call portbin
  83. and al, 0x01
  84. cmp al, 0x01
  85. je error_both
  86. push ebx
  87. mov ebx, ERR_CYCLE
  88. call print_string_pm
  89. pop ebx
  90. jmp handled
  91.  
  92. error_both:
  93. push ebx
  94. mov ebx, ERR_BOTH
  95. call print_string_pm
  96. pop ebx
  97. jmp handled
  98.  
  99. read_data:
  100. push ecx
  101. push ebx
  102. push eax
  103. mov ecx, 0x0
  104. mov ebx, 0xEFFFFF
  105. jmp read_loop
  106. return_label:
  107.  
  108.  
  109. read_loop:
  110. mov dx, 0x1F0
  111. call portwin
  112. mov [ebx], ax
  113. add ecx, 0x2
  114. add ebx, 0x2
  115. cmp ecx, 0x200
  116. je inc_sector_count
  117.  
  118.  
  119. inc_sector_count:
  120. pop eax
  121. inc eax
  122. pop ebx
  123. cmp bx, ax
  124. je handled
  125. push ebx
  126. push eax
  127. jmp read_loop
  128.  
  129. select_read:
  130. push ax
  131. push dx
  132. mov dx, 0x1F7
  133. mov ax, 0x20
  134. call portbout
  135. pop dx
  136. pop ax
  137. mov ecx, 0
  138. jmp check_drq
  139.  
  140. check_drq:
  141. call portbin ; reading ports for delay
  142. call portbin
  143. call portbin
  144. call portbin
  145. call portbin
  146. and al, 0x88
  147. cmp al, 0x08
  148. je drq_set
  149. inc ecx
  150. cmp ecx, 1000
  151. jne check_drq
  152. jne no_drq
  153.  
  154. WRITE db "Write selected ", 0
  155. READ db "Read selected ", 0
  156. ERR_CYCLE db "Bad Cycle!",0
  157. ERR_BLOCK db "Bad block!",0
  158. ERR_BOTH db "Bad Block! Bad Cycle!",0
  159.  
  160.  
  161.  
  162.  
  163.  
  164. ; Port driver
  165. [bits 32]
  166. ; D is port, A is data
  167. portbout:
  168. out dx, al
  169. ret
  170. portbin:
  171. in al, dx
  172. ret
  173. portwout:
  174. out dx, ax
  175. ret
  176. portwin:
  177. in ax, dx
  178. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement