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

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

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