source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm@ 265

Last change on this file since 265 was 263, checked in by gregli@…, 13 years ago

Oops, forgot to check if it still compiled without floppy support, fixed up a couple of typos and put an ifdef back into place.

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