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