1 | ; Project name : XTIDE Universal BIOS |
---|
2 | ; Description : Int 13h BIOS functions (Floppy and Hard disk). |
---|
3 | |
---|
4 | ; Section containing code |
---|
5 | SECTION .text |
---|
6 | |
---|
7 | ;-------------------------------------------------------------------- |
---|
8 | ; Int 13h software interrupt handler. |
---|
9 | ; Jumps to specific function defined in AH. |
---|
10 | ; |
---|
11 | ; Note to developers: Do not make recursive INT 13h calls! |
---|
12 | ; |
---|
13 | ; Int13h_DiskFunctionsHandler |
---|
14 | ; Parameters: |
---|
15 | ; AH: Bios function |
---|
16 | ; DL: Drive number |
---|
17 | ; Other: Depends on function |
---|
18 | ; Returns: |
---|
19 | ; Depends on function |
---|
20 | ;-------------------------------------------------------------------- |
---|
21 | ALIGN JUMP_ALIGN |
---|
22 | Int13h_DiskFunctionsHandler: |
---|
23 | sti ; Enable interrupts |
---|
24 | cld ; String instructions to increment pointers |
---|
25 | CREATE_FRAME_INTPACK_TO_SSBP EXTRA_BYTES_FOR_INTPACK |
---|
26 | |
---|
27 | call RamVars_GetSegmentToDS |
---|
28 | call DriveXlate_ToOrBack |
---|
29 | mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl |
---|
30 | call RamVars_IsFunctionHandledByThisBIOS |
---|
31 | jc SHORT Int13h_DirectCallToAnotherBios |
---|
32 | |
---|
33 | call FindDPT_ForDriveNumber ; DS:DI now points to DPT |
---|
34 | |
---|
35 | ; Jump to correct BIOS function |
---|
36 | eMOVZX bx, ah |
---|
37 | shl bx, 1 |
---|
38 | cmp ah, 25h ; Possible EBIOS function? |
---|
39 | %ifdef MODULE_EBIOS |
---|
40 | ja SHORT .JumpToEbiosFunction |
---|
41 | %else |
---|
42 | ja SHORT Int13h_UnsupportedFunction |
---|
43 | %endif |
---|
44 | jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function |
---|
45 | |
---|
46 | %ifdef MODULE_EBIOS |
---|
47 | ; Jump to correct EBIOS function |
---|
48 | ALIGN JUMP_ALIGN |
---|
49 | .JumpToEbiosFunction: |
---|
50 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA |
---|
51 | jz SHORT Int13h_UnsupportedFunction ; No eINT 13h for CHS drives |
---|
52 | cmp ah, 48h |
---|
53 | ja SHORT Int13h_UnsupportedFunction |
---|
54 | sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table |
---|
55 | jb SHORT Int13h_UnsupportedFunction |
---|
56 | jmp [cs:bx+g_rgwEbiosFunctionJumpTable] |
---|
57 | %endif |
---|
58 | |
---|
59 | ;-------------------------------------------------------------------- |
---|
60 | ; Int13h_UnsupportedFunction |
---|
61 | ; Int13h_DirectCallToAnotherBios |
---|
62 | ; Parameters: |
---|
63 | ; DL: Translated drive number |
---|
64 | ; DS: RAMVARS segment |
---|
65 | ; SS:BP: Ptr to IDEPACK |
---|
66 | ; BX, DI: Corrupted on Int13h_DiskFunctionsHandler |
---|
67 | ; Other: Function specific INT 13h parameters |
---|
68 | ; Returns: |
---|
69 | ; Depends on function |
---|
70 | ; Corrupts registers: |
---|
71 | ; Flags |
---|
72 | ;-------------------------------------------------------------------- |
---|
73 | ALIGN JUMP_ALIGN |
---|
74 | Int13h_UnsupportedFunction: |
---|
75 | Int13h_DirectCallToAnotherBios: |
---|
76 | call ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
77 | mov bx, [bp+IDEPACK.intpack+INTPACK.bx] |
---|
78 | mov di, [bp+IDEPACK.intpack+INTPACK.di] |
---|
79 | mov ds, [bp+IDEPACK.intpack+INTPACK.ds] |
---|
80 | push WORD [bp+IDEPACK.intpack+INTPACK.flags] |
---|
81 | popf |
---|
82 | push bp |
---|
83 | mov bp, [bp+IDEPACK.intpack+INTPACK.bp] |
---|
84 | int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants |
---|
85 | |
---|
86 | ; Store returned values to INTPACK |
---|
87 | pop bp ; Standard INT 13h functions never uses BP as return register |
---|
88 | %ifdef USE_386 |
---|
89 | mov [bp+IDEPACK.intpack+INTPACK.gs], gs |
---|
90 | mov [bp+IDEPACK.intpack+INTPACK.fs], fs |
---|
91 | %endif |
---|
92 | mov [bp+IDEPACK.intpack+INTPACK.es], es |
---|
93 | mov [bp+IDEPACK.intpack+INTPACK.ds], ds |
---|
94 | mov [bp+IDEPACK.intpack+INTPACK.di], di |
---|
95 | mov [bp+IDEPACK.intpack+INTPACK.si], si |
---|
96 | mov [bp+IDEPACK.intpack+INTPACK.bx], bx |
---|
97 | mov [bp+IDEPACK.intpack+INTPACK.dh], dh |
---|
98 | mov [bp+IDEPACK.intpack+INTPACK.cx], cx |
---|
99 | mov [bp+IDEPACK.intpack+INTPACK.ax], ax |
---|
100 | pushf |
---|
101 | pop WORD [bp+IDEPACK.intpack+INTPACK.flags] |
---|
102 | call RamVars_GetSegmentToDS |
---|
103 | cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] |
---|
104 | je SHORT .ExchangeInt13hHandlers |
---|
105 | mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL |
---|
106 | ALIGN JUMP_ALIGN |
---|
107 | .ExchangeInt13hHandlers: |
---|
108 | %ifdef USE_186 |
---|
109 | push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
110 | jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
111 | %else |
---|
112 | call ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
113 | jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
114 | %endif |
---|
115 | |
---|
116 | |
---|
117 | ;-------------------------------------------------------------------- |
---|
118 | ; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL |
---|
119 | ; Parameters: |
---|
120 | ; AH: BIOS Error code |
---|
121 | ; CL: Number of sectors actually transferred |
---|
122 | ; SS:BP: Ptr to IDEPACK |
---|
123 | ; Returns: |
---|
124 | ; All registers are loaded from INTPACK |
---|
125 | ;-------------------------------------------------------------------- |
---|
126 | ALIGN JUMP_ALIGN |
---|
127 | Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL: |
---|
128 | mov [bp+IDEPACK.intpack+INTPACK.al], cl |
---|
129 | ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
130 | |
---|
131 | ;-------------------------------------------------------------------- |
---|
132 | ; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
133 | ; Int13h_ReturnFromHandlerWithoutStoringErrorCode |
---|
134 | ; Parameters: |
---|
135 | ; AH: BIOS Error code |
---|
136 | ; SS:BP: Ptr to IDEPACK |
---|
137 | ; Returns: |
---|
138 | ; All registers are loaded from INTPACK |
---|
139 | ;-------------------------------------------------------------------- |
---|
140 | ALIGN JUMP_ALIGN |
---|
141 | Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH: |
---|
142 | %ifdef MODULE_SERIAL_FLOPPY |
---|
143 | mov al, [bp+IDEPACK.intpack+INTPACK.dl] |
---|
144 | Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber: |
---|
145 | call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber |
---|
146 | %else |
---|
147 | call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH |
---|
148 | %endif |
---|
149 | Int13h_ReturnFromHandlerWithoutStoringErrorCode: |
---|
150 | or WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF ; Return with interrupts enabled |
---|
151 | mov sp, bp ; Now we can exit anytime |
---|
152 | RESTORE_FRAME_INTPACK_FROM_SSBP EXTRA_BYTES_FOR_INTPACK |
---|
153 | |
---|
154 | |
---|
155 | ;-------------------------------------------------------------------- |
---|
156 | ; Int13h_CallPreviousInt13hHandler |
---|
157 | ; Parameters: |
---|
158 | ; AH: INT 13h function to call |
---|
159 | ; DL: Drive number |
---|
160 | ; DS: RAMVARS segment |
---|
161 | ; Returns: |
---|
162 | ; Depends on function |
---|
163 | ; NOTE: ES:DI needs to be returned from the previous interrupt |
---|
164 | ; handler, for floppy DPT in function 08h |
---|
165 | ; Corrupts registers: |
---|
166 | ; None |
---|
167 | ;-------------------------------------------------------------------- |
---|
168 | ALIGN JUMP_ALIGN |
---|
169 | Int13h_CallPreviousInt13hHandler: |
---|
170 | call ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
171 | int BIOS_DISK_INTERRUPT_13h |
---|
172 | ;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
173 | |
---|
174 | ;-------------------------------------------------------------------- |
---|
175 | ; ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
176 | ; Parameters: |
---|
177 | ; DS: RAMVARS segment |
---|
178 | ; Returns: |
---|
179 | ; Nothing |
---|
180 | ; Corrupts registers: |
---|
181 | ; Nothing |
---|
182 | ; Note: Flags are preserved |
---|
183 | ;-------------------------------------------------------------------- |
---|
184 | ALIGN JUMP_ALIGN |
---|
185 | ExchangeCurrentInt13hHandlerWithOldInt13hHandler: |
---|
186 | push es |
---|
187 | push si |
---|
188 | LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si |
---|
189 | mov si, [RAMVARS.fpOldI13h] |
---|
190 | cli |
---|
191 | xchg si, [es:BIOS_DISK_INTERRUPT_13h*4] |
---|
192 | mov [RAMVARS.fpOldI13h], si |
---|
193 | mov si, [RAMVARS.fpOldI13h+2] |
---|
194 | xchg si, [es:BIOS_DISK_INTERRUPT_13h*4+2] |
---|
195 | sti |
---|
196 | mov [RAMVARS.fpOldI13h+2], si |
---|
197 | pop si |
---|
198 | pop es |
---|
199 | ret |
---|
200 | |
---|
201 | |
---|
202 | ;-------------------------------------------------------------------- |
---|
203 | ; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH |
---|
204 | ; Int13h_SetErrorCodeToIntpackInSSBPfromAH |
---|
205 | ; Parameters: |
---|
206 | ; AH: BIOS error code (00h = no error) |
---|
207 | ; SS:BP: Ptr to IDEPACK |
---|
208 | ; Returns: |
---|
209 | ; SS:BP: Ptr to IDEPACK with error condition set |
---|
210 | ; Corrupts registers: |
---|
211 | ; DS, DI |
---|
212 | ;-------------------------------------------------------------------- |
---|
213 | ALIGN JUMP_ALIGN |
---|
214 | %ifdef MODULE_SERIAL_FLOPPY |
---|
215 | Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber: |
---|
216 | ; Store error code to BDA |
---|
217 | mov bx, BDA.bHDLastSt |
---|
218 | test al, al |
---|
219 | js .HardDisk |
---|
220 | mov bl, BDA.bFDRetST & 0xff |
---|
221 | .HardDisk: |
---|
222 | LOAD_BDA_SEGMENT_TO ds, di |
---|
223 | mov [bx], ah |
---|
224 | %else |
---|
225 | Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH: |
---|
226 | ; Store error code to BDA |
---|
227 | LOAD_BDA_SEGMENT_TO ds, di |
---|
228 | mov [BDA.bHDLastSt], ah |
---|
229 | %endif |
---|
230 | |
---|
231 | ; Store error code to INTPACK |
---|
232 | Int13h_SetErrorCodeToIntpackInSSBPfromAH: |
---|
233 | mov [bp+IDEPACK.intpack+INTPACK.ah], ah |
---|
234 | test ah, ah |
---|
235 | jnz SHORT .SetCFtoIntpack |
---|
236 | and BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF |
---|
237 | ret |
---|
238 | .SetCFtoIntpack: |
---|
239 | or BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF |
---|
240 | ret |
---|
241 | |
---|
242 | |
---|
243 | ; Jump table for correct BIOS function |
---|
244 | ALIGN WORD_ALIGN |
---|
245 | g_rgw13hFuncJump: |
---|
246 | dw AH0h_HandlerForDiskControllerReset ; 00h, Disk Controller Reset (All) |
---|
247 | dw AH1h_HandlerForReadDiskStatus ; 01h, Read Disk Status (All) |
---|
248 | dw AH2h_HandlerForReadDiskSectors ; 02h, Read Disk Sectors (All) |
---|
249 | dw AH3h_HandlerForWriteDiskSectors ; 03h, Write Disk Sectors (All) |
---|
250 | dw AH4h_HandlerForVerifyDiskSectors ; 04h, Verify Disk Sectors (All) |
---|
251 | dw Int13h_UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA) |
---|
252 | dw Int13h_UnsupportedFunction ; 06h, Format Disk Track with Bad Sectors (XT) |
---|
253 | dw Int13h_UnsupportedFunction ; 07h, Format Multiple Cylinders (XT) |
---|
254 | dw AH8h_HandlerForReadDiskDriveParameters ; 08h, Read Disk Drive Parameters (All) |
---|
255 | dw AH9h_HandlerForInitializeDriveParameters ; 09h, Initialize Drive Parameters (All) |
---|
256 | dw Int13h_UnsupportedFunction ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA) |
---|
257 | dw Int13h_UnsupportedFunction ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA) |
---|
258 | dw AHCh_HandlerForSeek ; 0Ch, Seek (All) |
---|
259 | dw AHDh_HandlerForResetHardDisk ; 0Dh, Alternate Disk Reset (All) |
---|
260 | dw Int13h_UnsupportedFunction ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2) |
---|
261 | dw Int13h_UnsupportedFunction ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2) |
---|
262 | dw AH10h_HandlerForCheckDriveReady ; 10h, Check Drive Ready (All) |
---|
263 | dw AH11h_HandlerForRecalibrate ; 11h, Recalibrate (All) |
---|
264 | dw Int13h_UnsupportedFunction ; 12h, Controller RAM Diagnostic (XT) |
---|
265 | dw Int13h_UnsupportedFunction ; 13h, Drive Diagnostic (XT) |
---|
266 | dw Int13h_UnsupportedFunction ; 14h, Controller Internal Diagnostic (All) |
---|
267 | dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+) |
---|
268 | dw Int13h_UnsupportedFunction ; 16h, |
---|
269 | dw Int13h_UnsupportedFunction ; 17h, |
---|
270 | dw Int13h_UnsupportedFunction ; 18h, |
---|
271 | dw Int13h_UnsupportedFunction ; 19h, Park Heads (PS/2) |
---|
272 | dw Int13h_UnsupportedFunction ; 1Ah, Format ESDI Drive (PS/2) |
---|
273 | dw Int13h_UnsupportedFunction ; 1Bh, Get ESDI Manufacturing Header (PS/2) |
---|
274 | dw Int13h_UnsupportedFunction ; 1Ch, ESDI Special Functions (PS/2) |
---|
275 | dw Int13h_UnsupportedFunction ; 1Dh, |
---|
276 | dw Int13h_UnsupportedFunction ; 1Eh, |
---|
277 | dw Int13h_UnsupportedFunction ; 1Fh, |
---|
278 | dw Int13h_UnsupportedFunction ; 20h, |
---|
279 | dw Int13h_UnsupportedFunction ; 21h, Read Disk Sectors, Multiple Blocks (PS/1) |
---|
280 | dw Int13h_UnsupportedFunction ; 22h, Write Disk Sectors, Multiple Blocks (PS/1) |
---|
281 | dw AH23h_HandlerForSetControllerFeatures ; 23h, Set Controller Features Register (PS/1) |
---|
282 | dw AH24h_HandlerForSetMultipleBlocks ; 24h, Set Multiple Blocks (PS/1) |
---|
283 | dw AH25h_HandlerForGetDriveInformation ; 25h, Get Drive Information (PS/1) |
---|
284 | |
---|
285 | %ifdef MODULE_EBIOS |
---|
286 | g_rgwEbiosFunctionJumpTable: |
---|
287 | dw AH41h_HandlerForCheckIfExtensionsPresent ; 41h, Check if Extensions Present (EBIOS)* |
---|
288 | dw AH42h_HandlerForExtendedReadSectors ; 42h, Extended Read Sectors (EBIOS)* |
---|
289 | dw AH43h_HandlerForExtendedWriteSectors ; 43h, Extended Write Sectors (EBIOS)* |
---|
290 | dw AH44h_HandlerForExtendedVerifySectors ; 44h, Extended Verify Sectors (EBIOS)* |
---|
291 | dw Int13h_UnsupportedFunction ; 45h, Lock and Unlock Drive (EBIOS)*** |
---|
292 | dw Int13h_UnsupportedFunction ; 46h, Eject Media Request (EBIOS)*** |
---|
293 | dw AH47h_HandlerForExtendedSeek ; 47h, Extended Seek (EBIOS)* |
---|
294 | dw AH48h_HandlerForGetExtendedDriveParameters ; 48h, Get Extended Drive Parameters (EBIOS)* |
---|
295 | ; dw Int13h_UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)*** |
---|
296 | ; dw Int13h_UnsupportedFunction ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM) |
---|
297 | ; dw Int13h_UnsupportedFunction ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM) |
---|
298 | ; dw Int13h_UnsupportedFunction ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM) |
---|
299 | ; dw Int13h_UnsupportedFunction ; 4Dh, Return Boot Catalog (Bootable CD-ROM) |
---|
300 | ; dw Int13h_UnsupportedFunction ; 4Eh, Set Hardware Configuration (EBIOS)** |
---|
301 | ; |
---|
302 | ; * = Enhanced Drive Access Support (minimum required EBIOS functions) |
---|
303 | ; ** = Enhanced Disk Drive (EDD) Support |
---|
304 | ; *** = Drive Locking and Ejecting Support |
---|
305 | %endif |
---|