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

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

Changes to XTIDE Universal BIOS:

  • MEMPIOVARS no longer overflow when not building MODULE_EBIOS.
File size: 13.9 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 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
48%endif
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%ifdef MODULE_HOTKEYS
132 mov [bp+IDEPACK.intpack+INTPACK.dh], dh
133%else
134 mov [bp+IDEPACK.intpack+INTPACK.dx], dx
135%endif
136 mov [bp+IDEPACK.intpack+INTPACK.cx], cx
137 mov [bp+IDEPACK.intpack+INTPACK.ax], ax
138 pushf
139 pop WORD [bp+IDEPACK.intpack+INTPACK.flags]
140 call RamVars_GetSegmentToDS
141
142%ifdef MODULE_HOTKEYS
143 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] ; DL is still drive number?
144 je SHORT .ExchangeInt13hHandlers
145 mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
146ALIGN JUMP_ALIGN
147.ExchangeInt13hHandlers:
148%endif
149
150%ifdef USE_186
151 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
152 jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
153%else
154 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
155 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
156%endif
157
158%ifdef MODULE_SERIAL_FLOPPY
159;--------------------------------------------------------------------
160; Int13h_ReturnSuccessForFloppy
161;
162; Some operations, such as format of a floppy disk track, should just
163; return success, while for hard disks it should be treated as unsupported.
164;--------------------------------------------------------------------
165ALIGN JUMP_ALIGN
166Int13h_ReturnSuccessForFloppy:
167 test dl, dl
168 js short Int13h_UnsupportedFunction
169 xor ah, ah
170 jmp short Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
171%endif
172
173;--------------------------------------------------------------------
174; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
175; Parameters:
176; AH: BIOS Error code
177; CL: Number of sectors actually transferred
178; SS:BP: Ptr to IDEPACK
179; Returns:
180; All registers are loaded from INTPACK
181;--------------------------------------------------------------------
182ALIGN JUMP_ALIGN
183Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
184 mov [bp+IDEPACK.intpack+INTPACK.al], cl
185 ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
186
187;--------------------------------------------------------------------
188; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
189; Int13h_ReturnFromHandlerWithoutStoringErrorCode
190; Parameters:
191; AH: BIOS Error code
192; SS:BP: Ptr to IDEPACK
193; Returns:
194; All registers are loaded from INTPACK
195;--------------------------------------------------------------------
196ALIGN JUMP_ALIGN
197Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
198%ifdef MODULE_SERIAL_FLOPPY
199 mov al, [bp+IDEPACK.intpack+INTPACK.dl]
200Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
201 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
202
203%else
204 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
205%endif
206
207Int13h_ReturnFromHandlerWithoutStoringErrorCode:
208 or WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF ; Return with interrupts enabled
209 mov sp, bp ; Now we can exit anytime
210 RESTORE_FRAME_INTPACK_FROM_SSBP EXTRA_BYTES_FOR_INTPACK
211
212
213;--------------------------------------------------------------------
214; Int13h_CallPreviousInt13hHandler
215; Parameters:
216; AH: INT 13h function to call
217; DL: Drive number
218; DS: RAMVARS segment
219; Returns:
220; Depends on function
221; NOTE: ES:DI needs to be returned from the previous interrupt
222; handler, for floppy DPT in function 08h
223; Corrupts registers:
224; None
225;--------------------------------------------------------------------
226ALIGN JUMP_ALIGN
227Int13h_CallPreviousInt13hHandler:
228 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
229 int BIOS_DISK_INTERRUPT_13h
230;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
231
232;--------------------------------------------------------------------
233; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
234; Parameters:
235; DS: RAMVARS segment
236; Returns:
237; Nothing
238; Corrupts registers:
239; Nothing
240; Note: Flags are preserved
241;--------------------------------------------------------------------
242ALIGN JUMP_ALIGN
243ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
244 push es
245 push si
246 LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si
247 mov si, [RAMVARS.fpOldI13h]
248 cli
249 xchg si, [es:BIOS_DISK_INTERRUPT_13h*4]
250 mov [RAMVARS.fpOldI13h], si
251 mov si, [RAMVARS.fpOldI13h+2]
252 xchg si, [es:BIOS_DISK_INTERRUPT_13h*4+2]
253 sti
254 mov [RAMVARS.fpOldI13h+2], si
255 pop si
256 pop es
257 ret
258
259
260;--------------------------------------------------------------------
261; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
262; Int13h_SetErrorCodeToIntpackInSSBPfromAH
263; Parameters:
264; AH: BIOS error code (00h = no error)
265; SS:BP: Ptr to IDEPACK
266; Returns:
267; SS:BP: Ptr to IDEPACK with error condition set
268; Corrupts registers:
269; DS, DI
270;--------------------------------------------------------------------
271ALIGN JUMP_ALIGN
272%ifdef MODULE_SERIAL_FLOPPY
273Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
274 ; Store error code to BDA
275 mov bx, BDA.bHDLastSt
276 test al, al
277 js SHORT .HardDisk
278 mov bl, BDA.bFDRetST & 0xff
279.HardDisk:
280 LOAD_BDA_SEGMENT_TO ds, di
281 mov [bx], ah
282%else
283Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
284 ; Store error code to BDA
285 LOAD_BDA_SEGMENT_TO ds, di
286 mov [BDA.bHDLastSt], ah
287%endif
288
289 ; Store error code to INTPACK
290Int13h_SetErrorCodeToIntpackInSSBPfromAH:
291 mov [bp+IDEPACK.intpack+INTPACK.ah], ah
292 test ah, ah
293 jnz SHORT .SetCFtoIntpack
294 and BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
295 ret
296.SetCFtoIntpack:
297 or BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
298 ret
299
300
301; Jump table for correct BIOS function
302ALIGN WORD_ALIGN
303g_rgw13hFuncJump:
304 dw AH0h_HandlerForDiskControllerReset ; 00h, Disk Controller Reset (All)
305 dw AH1h_HandlerForReadDiskStatus ; 01h, Read Disk Status (All)
306 dw AH2h_HandlerForReadDiskSectors ; 02h, Read Disk Sectors (All)
307 dw AH3h_HandlerForWriteDiskSectors ; 03h, Write Disk Sectors (All)
308 dw AH4h_HandlerForVerifyDiskSectors ; 04h, Verify Disk Sectors (All)
309%ifdef MODULE_SERIAL_FLOPPY
310 dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA)
311%else
312 dw Int13h_UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA)
313%endif
314 dw Int13h_UnsupportedFunction ; 06h, Format Disk Track with Bad Sectors (XT)
315 dw Int13h_UnsupportedFunction ; 07h, Format Multiple Cylinders (XT)
316 dw AH8h_HandlerForReadDiskDriveParameters ; 08h, Read Disk Drive Parameters (All)
317 dw AH9h_HandlerForInitializeDriveParameters ; 09h, Initialize Drive Parameters (All)
318 dw Int13h_UnsupportedFunction ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
319 dw Int13h_UnsupportedFunction ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
320 dw AHCh_HandlerForSeek ; 0Ch, Seek (All)
321 dw AHDh_HandlerForResetHardDisk ; 0Dh, Alternate Disk Reset (All)
322 dw Int13h_UnsupportedFunction ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
323 dw Int13h_UnsupportedFunction ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
324 dw AH10h_HandlerForCheckDriveReady ; 10h, Check Drive Ready (All)
325 dw AH11h_HandlerForRecalibrate ; 11h, Recalibrate (All)
326 dw Int13h_UnsupportedFunction ; 12h, Controller RAM Diagnostic (XT)
327 dw Int13h_UnsupportedFunction ; 13h, Drive Diagnostic (XT)
328 dw Int13h_UnsupportedFunction ; 14h, Controller Internal Diagnostic (All)
329 dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+)
330 dw Int13h_UnsupportedFunction ; 16h,
331 dw Int13h_UnsupportedFunction ; 17h,
332 dw Int13h_UnsupportedFunction ; 18h,
333 dw Int13h_UnsupportedFunction ; 19h, Park Heads (PS/2)
334 dw Int13h_UnsupportedFunction ; 1Ah, Format ESDI Drive (PS/2)
335 dw Int13h_UnsupportedFunction ; 1Bh, Get ESDI Manufacturing Header (PS/2)
336 dw Int13h_UnsupportedFunction ; 1Ch, ESDI Special Functions (PS/2)
337 dw Int13h_UnsupportedFunction ; 1Dh,
338 dw Int13h_UnsupportedFunction ; 1Eh,
339 dw Int13h_UnsupportedFunction ; 1Fh,
340 dw Int13h_UnsupportedFunction ; 20h,
341 dw Int13h_UnsupportedFunction ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
342 dw Int13h_UnsupportedFunction ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
343 dw AH23h_HandlerForSetControllerFeatures ; 23h, Set Controller Features Register (PS/1)
344 dw AH24h_HandlerForSetMultipleBlocks ; 24h, Set Multiple Blocks (PS/1)
345 dw AH25h_HandlerForGetDriveInformation ; 25h, Get Drive Information (PS/1)
346
347%ifdef MODULE_EBIOS
348g_rgwEbiosFunctionJumpTable:
349 dw AH41h_HandlerForCheckIfExtensionsPresent ; 41h, Check if Extensions Present (EBIOS)*
350 dw AH42h_HandlerForExtendedReadSectors ; 42h, Extended Read Sectors (EBIOS)*
351 dw AH43h_HandlerForExtendedWriteSectors ; 43h, Extended Write Sectors (EBIOS)*
352 dw AH44h_HandlerForExtendedVerifySectors ; 44h, Extended Verify Sectors (EBIOS)*
353 dw Int13h_UnsupportedFunction ; 45h, Lock and Unlock Drive (EBIOS)***
354 dw Int13h_UnsupportedFunction ; 46h, Eject Media Request (EBIOS)***
355 dw AH47h_HandlerForExtendedSeek ; 47h, Extended Seek (EBIOS)*
356 dw AH48h_HandlerForGetExtendedDriveParameters ; 48h, Get Extended Drive Parameters (EBIOS)*
357; dw Int13h_UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)***
358; dw Int13h_UnsupportedFunction ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
359; dw Int13h_UnsupportedFunction ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
360; dw Int13h_UnsupportedFunction ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
361; dw Int13h_UnsupportedFunction ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
362; dw Int13h_UnsupportedFunction ; 4Eh, Set Hardware Configuration (EBIOS)**
363;
364; * = Enhanced Drive Access Support (minimum required EBIOS functions)
365; ** = Enhanced Disk Drive (EDD) Support
366; *** = Drive Locking and Ejecting Support
367%endif
Note: See TracBrowser for help on using the repository browser.