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

Last change on this file since 402 was 395, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

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