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

Last change on this file since 555 was 555, checked in by aitotat@…, 11 years ago

Changes to XTIDE Universal BIOS:

  • Short timeouts for drive detection work again.
  • All drives are now reset before booting (instead of XTIDE Universal BIOS controlled drives only).
  • Windows 98 now works without tricks (Floppy Drive accesses are redirected from INT 13h to 40h).
File size: 16.6 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-2013 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; This handler changes stack to top of stolen conventional memory
26; and then calls the actual INT 13h handler (Int13h_DiskFunctionsHandler).
27;
28; Int13h_DiskFunctionsHandlerWithStackChange
29; Parameters:
30; AH: Bios function
31; DL: Drive number
32; Other: Depends on function
33; Returns:
34; Depends on function
35;--------------------------------------------------------------------
36%ifdef RELOCATE_INT13H_STACK
37ALIGN JUMP_ALIGN
38Int13h_DiskFunctionsHandlerWithStackChange:
39 sti ; Enable interrupts
40 ; TODO: Maybe we need to save Flags (DF) as well?
41 push ds ; Save DS:DI on the original stack
42 push di
43 call RamVars_GetSegmentToDS
44
45 ; Store entry registers to RAMVARS
46%ifdef USE_386
47 pop DWORD [RAMVARS.dwStackChangeDSDI]
48%else
49 pop WORD [RAMVARS.wStackChangeDI] ; Pop DS:DI to the top of what
50 pop WORD [RAMVARS.wStackChangeDS] ; is to become the new stack
51%endif
52 mov [RAMVARS.fpInt13hEntryStack], sp
53 mov [RAMVARS.fpInt13hEntryStack+2], ss
54
55 ; Load new stack and restore DS and DI
56 mov di, ds ; We can save 2 bytes by using PUSH/POP but it's slower
57 mov ss, di ; No need to wrap with CLI/STI since this is for AT only (286+)
58 mov sp, RAMVARS.rgbTopOfStack-4
59 pop di ; DI before stack change
60 pop ds ; DS before stack change
61
62 ; Call INT 13h
63 pushf
64 push cs
65 call Int13h_DiskFunctionsHandler
66
67 ; Restore stack (we must not corrupt FLAGS!)
68%ifdef USE_386
69 lss sp, [ss:RAMVARS.fpInt13hEntryStack]
70%else
71 cli
72 mov sp, [ss:RAMVARS.fpInt13hEntryStack]
73 mov ss, [ss:RAMVARS.fpInt13hEntryStack+2]
74 sti
75%endif
76 retf 2 ; Skip FLAGS from stack
77%endif ; RELOCATE_INT13H_STACK
78
79
80;--------------------------------------------------------------------
81; Int 13h (Hard Drive) to Int 40h (Floppy Drive)
82; We must not call previous INT 13h for floppy drives since it
83; does not work on Windows 98 (when using HSFLOP.PDR driver) for some reason.
84;
85; DirectCallToFloppyHandler40h
86; Parameters:
87; AH: Bios function
88; DL: Drive number
89; Other: Depends on function
90; Returns:
91; Depends on function
92;--------------------------------------------------------------------
93DirectCallToFloppyHandler40h:
94; With serial floppy support, we handle all traffic for function 08h,
95; as we need to wrap both hard disk and floppy drive counts.
96%ifdef MODULE_SERIAL_FLOPPY
97 cmp ah, GET_DRIVE_PARAMETERS ; 08h
98 je SHORT WeHandleTheFloppyFunction
99%endif
100
101 int BIOS_DISKETTE_INTERRUPT_40h
102 retf 2 ; Skip FLAGS from stack
103
104
105;--------------------------------------------------------------------
106; Int 13h software interrupt handler.
107; Jumps to specific function defined in AH.
108;
109; Note to developers: Do not make recursive INT 13h calls!
110;
111; Int13h_DiskFunctionsHandler
112; Parameters:
113; AH: Bios function
114; DL: Drive number
115; Other: Depends on function
116; Returns:
117; Depends on function
118;--------------------------------------------------------------------
119ALIGN JUMP_ALIGN
120Int13h_DiskFunctionsHandler:
121 test dl, dl ; Floppy Drive?
122 jns SHORT DirectCallToFloppyHandler40h
123WeHandleTheFloppyFunction:
124
125%ifndef RELOCATE_INT13H_STACK
126 sti ; Enable interrupts
127%endif
128 cld ; String instructions to increment pointers
129 CREATE_FRAME_INTPACK_TO_SSBP SIZE_OF_IDEPACK_WITHOUT_INTPACK
130 call RamVars_GetSegmentToDS
131
132%ifdef MODULE_DRIVEXLATE
133 call DriveXlate_ToOrBack
134 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
135%endif
136 call FindDPT_ForDriveNumberInDL ; DS:DI points to our DPT, or NULL if not our drive
137 jc SHORT .NotOurDrive ; DPT not found so this is not one of our drives
138
139.OurFunction:
140 ; Jump to correct BIOS function
141 eMOVZX bx, ah
142 eSHL_IM bx, 1
143 cmp ah, 25h ; Possible EBIOS function?
144%ifndef MODULE_EBIOS
145 ja SHORT UnsupportedFunction
146 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
147
148%else ; If using MODULE_EBIOS
149 ja SHORT .JumpToEbiosFunction
150 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
151
152ALIGN JUMP_ALIGN
153.JumpToEbiosFunction:
154 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA
155 jz SHORT UnsupportedFunction ; No eINT 13h for CHS drives
156 sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table
157 jb SHORT UnsupportedFunction
158 cmp ah, 48h
159 ja SHORT UnsupportedFunction
160 jmp [cs:bx+g_rgwEbiosFunctionJumpTable]
161%endif ; MODULE_EBIOS
162
163
164ALIGN JUMP_ALIGN
165.NotOurDrive:
166 test ah, ah
167 jz SHORT .OurFunction ; We handle all function 0h requests (resets)
168
169; We handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
170 cmp ah, GET_DRIVE_PARAMETERS ; 08h
171 je SHORT .OurFunction
172 ; Fall to Int13h_DirectCallToAnotherBios
173
174
175;--------------------------------------------------------------------
176; UnsupportedFunction
177; Int13h_DirectCallToAnotherBios
178; Parameters:
179; DL: Translated drive number
180; DS: RAMVARS segment
181; SS:BP: Ptr to IDEPACK
182; BX, DI: Corrupted on Int13h_DiskFunctionsHandler
183; Other: Function specific INT 13h parameters
184; Returns:
185; Depends on function
186; Corrupts registers:
187; Flags
188;--------------------------------------------------------------------
189ALIGN JUMP_ALIGN
190UnsupportedFunction:
191Int13h_DirectCallToAnotherBios:
192 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
193 mov bx, [bp+IDEPACK.intpack+INTPACK.bx]
194 mov di, [bp+IDEPACK.intpack+INTPACK.di]
195 mov ds, [bp+IDEPACK.intpack+INTPACK.ds]
196 push WORD [bp+IDEPACK.intpack+INTPACK.flags]
197 popf
198 push bp
199 mov bp, [bp+IDEPACK.intpack+INTPACK.bp]
200 int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
201
202 ; Store returned values to INTPACK
203 pop bp ; Standard INT 13h functions never uses BP as return register
204%ifdef USE_386
205; mov [bp+IDEPACK.intpack+INTPACK.gs], gs
206; mov [bp+IDEPACK.intpack+INTPACK.fs], fs
207%endif
208 mov [bp+IDEPACK.intpack+INTPACK.es], es
209 mov [bp+IDEPACK.intpack+INTPACK.ds], ds
210 mov [bp+IDEPACK.intpack+INTPACK.di], di
211 mov [bp+IDEPACK.intpack+INTPACK.si], si
212 mov [bp+IDEPACK.intpack+INTPACK.bx], bx
213%ifdef MODULE_DRIVEXLATE
214 mov [bp+IDEPACK.intpack+INTPACK.dh], dh
215%else
216 mov [bp+IDEPACK.intpack+INTPACK.dx], dx
217%endif
218 mov [bp+IDEPACK.intpack+INTPACK.cx], cx
219 mov [bp+IDEPACK.intpack+INTPACK.ax], ax
220 pushf
221 pop WORD [bp+IDEPACK.intpack+INTPACK.flags]
222 call RamVars_GetSegmentToDS
223
224%ifdef MODULE_DRIVEXLATE
225 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] ; DL is still drive number?
226 je SHORT .ExchangeInt13hHandlers
227 mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
228ALIGN JUMP_ALIGN
229.ExchangeInt13hHandlers:
230%endif
231
232%ifdef USE_186
233 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
234 jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
235%else
236 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
237 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
238%endif
239
240
241%ifdef MODULE_SERIAL_FLOPPY
242;--------------------------------------------------------------------
243; Int13h_ReturnSuccessForFloppy
244;
245; Some operations, such as format of a floppy disk track, should just
246; return success, while for hard disks it should be treated as unsupported.
247;--------------------------------------------------------------------
248ALIGN JUMP_ALIGN
249Int13h_ReturnSuccessForFloppy:
250 test dl, dl
251 js SHORT UnsupportedFunction
252 xor ah, ah
253 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
254%endif
255
256
257;--------------------------------------------------------------------
258; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
259; Parameters:
260; AH: BIOS Error code
261; CL: Number of sectors actually transferred
262; SS:BP: Ptr to IDEPACK
263; Returns:
264; All registers are loaded from INTPACK
265;--------------------------------------------------------------------
266ALIGN JUMP_ALIGN
267Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
268 mov [bp+IDEPACK.intpack+INTPACK.al], cl
269 ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
270
271
272;--------------------------------------------------------------------
273; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
274; Int13h_ReturnFromHandlerWithoutStoringErrorCode
275; Parameters:
276; AH: BIOS Error code
277; SS:BP: Ptr to IDEPACK
278; Returns:
279; All registers are loaded from INTPACK
280;--------------------------------------------------------------------
281ALIGN JUMP_ALIGN
282Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
283%ifdef MODULE_SERIAL_FLOPPY
284 mov al, [bp+IDEPACK.intpack+INTPACK.dl]
285Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
286 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
287
288%else
289 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
290%endif
291
292Int13h_ReturnFromHandlerWithoutStoringErrorCode:
293 ; Always return with interrupts enabled since there are programs that rely
294 ; on INT 13h to enable interrupts.
295 or BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
296 mov sp, bp ; This makes possible to exit anytime, no matter what is on stack
297 RESTORE_FRAME_INTPACK_FROM_SSBP SIZE_OF_IDEPACK_WITHOUT_INTPACK
298
299
300;--------------------------------------------------------------------
301; Int13h_CallPreviousInt13hHandler
302; Parameters:
303; AH: INT 13h function to call
304; DL: Drive number
305; DS: RAMVARS segment
306; Returns:
307; Depends on function
308; NOTE: ES:DI needs to be returned from the previous interrupt
309; handler, for floppy DPT in function 08h
310; Corrupts registers:
311; None
312;--------------------------------------------------------------------
313ALIGN JUMP_ALIGN
314Int13h_CallPreviousInt13hHandler:
315 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
316 int BIOS_DISK_INTERRUPT_13h
317;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
318
319;--------------------------------------------------------------------
320; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
321; Parameters:
322; DS: RAMVARS segment
323; Returns:
324; Nothing
325; Corrupts registers:
326; Nothing
327; Note: Flags are preserved
328;--------------------------------------------------------------------
329ALIGN JUMP_ALIGN
330ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
331 push es
332 push si
333 LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si
334 mov si, [RAMVARS.fpOldI13h]
335 cli
336 xchg si, [es:BIOS_DISK_INTERRUPT_13h*4]
337 mov [RAMVARS.fpOldI13h], si
338 mov si, [RAMVARS.fpOldI13h+2]
339 xchg si, [es:BIOS_DISK_INTERRUPT_13h*4+2]
340 sti
341 mov [RAMVARS.fpOldI13h+2], si
342 pop si
343 pop es
344 ret
345
346
347;--------------------------------------------------------------------
348; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
349; Int13h_SetErrorCodeToIntpackInSSBPfromAH
350; Parameters:
351; AH: BIOS error code (00h = no error)
352; SS:BP: Ptr to IDEPACK
353; Returns:
354; SS:BP: Ptr to IDEPACK with error condition set
355; Corrupts registers:
356; DS, DI
357;--------------------------------------------------------------------
358ALIGN JUMP_ALIGN
359%ifdef MODULE_SERIAL_FLOPPY
360Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
361 ; Store error code to BDA
362 mov bx, BDA.bHDLastSt
363 test al, al
364 js SHORT .HardDisk
365 mov bl, BDA.bFDRetST & 0xff
366.HardDisk:
367 LOAD_BDA_SEGMENT_TO ds, di
368 mov [bx], ah
369 ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
370
371%else
372Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
373 ; Store error code to BDA
374 LOAD_BDA_SEGMENT_TO ds, di
375 mov [BDA.bHDLastSt], ah
376 ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
377%endif
378
379 ; Store error code to INTPACK
380Int13h_SetErrorCodeToIntpackInSSBPfromAH:
381 mov [bp+IDEPACK.intpack+INTPACK.ah], ah
382 test ah, ah
383 jnz SHORT .SetCFtoIntpack
384 and BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
385 ret
386.SetCFtoIntpack:
387 or BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
388 ret
389
390
391; Jump table for correct BIOS function
392ALIGN WORD_ALIGN
393g_rgw13hFuncJump:
394 dw AH0h_HandlerForDiskControllerReset ; 00h, Disk Controller Reset (All)
395 dw AH1h_HandlerForReadDiskStatus ; 01h, Read Disk Status (All)
396 dw AH2h_HandlerForReadDiskSectors ; 02h, Read Disk Sectors (All)
397 dw AH3h_HandlerForWriteDiskSectors ; 03h, Write Disk Sectors (All)
398 dw AH4h_HandlerForVerifyDiskSectors ; 04h, Verify Disk Sectors (All)
399%ifdef MODULE_SERIAL_FLOPPY
400 dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA)
401%else
402 dw UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA)
403%endif
404 dw UnsupportedFunction ; 06h, Format Disk Track with Bad Sectors (XT)
405 dw UnsupportedFunction ; 07h, Format Multiple Cylinders (XT)
406 dw AH8h_HandlerForReadDiskDriveParameters ; 08h, Read Disk Drive Parameters (All)
407 dw AH9h_HandlerForInitializeDriveParameters ; 09h, Initialize Drive Parameters (All)
408 dw UnsupportedFunction ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
409 dw UnsupportedFunction ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
410 dw AHCh_HandlerForSeek ; 0Ch, Seek (All)
411 dw AH9h_HandlerForInitializeDriveParameters ; 0Dh, Alternate Disk Reset (All)
412 dw UnsupportedFunction ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
413 dw UnsupportedFunction ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
414 dw AH10h_HandlerForCheckDriveReady ; 10h, Check Drive Ready (All)
415 dw AH11h_HandlerForRecalibrate ; 11h, Recalibrate (All)
416 dw UnsupportedFunction ; 12h, Controller RAM Diagnostic (XT)
417 dw UnsupportedFunction ; 13h, Drive Diagnostic (XT)
418 dw AH10h_HandlerForCheckDriveReady ; 14h, Controller Internal Diagnostic (All)
419 dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+)
420 dw UnsupportedFunction ; 16h,
421 dw UnsupportedFunction ; 17h,
422 dw UnsupportedFunction ; 18h,
423 dw UnsupportedFunction ; 19h, Park Heads (PS/2)
424 dw UnsupportedFunction ; 1Ah, Format ESDI Drive (PS/2)
425 dw UnsupportedFunction ; 1Bh, Get ESDI Manufacturing Header (PS/2)
426 dw UnsupportedFunction ; 1Ch, ESDI Special Functions (PS/2)
427 dw UnsupportedFunction ; 1Dh,
428%ifdef MODULE_8BIT_IDE_ADVANCED
429 dw AH1Eh_HandlerForXTCFfeatures ; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
430%else
431 dw UnsupportedFunction ; 1Eh,
432%endif
433 dw UnsupportedFunction ; 1Fh,
434 dw UnsupportedFunction ; 20h,
435 dw UnsupportedFunction ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
436 dw UnsupportedFunction ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
437 dw AH23h_HandlerForSetControllerFeatures ; 23h, Set Controller Features Register (PS/1)
438 dw AH24h_HandlerForSetMultipleBlocks ; 24h, Set Multiple Blocks (PS/1)
439 dw AH25h_HandlerForGetDriveInformation ; 25h, Get Drive Information (PS/1)
440
441%ifdef MODULE_EBIOS
442g_rgwEbiosFunctionJumpTable:
443 dw AH41h_HandlerForCheckIfExtensionsPresent ; 41h, Check if Extensions Present (EBIOS)*
444 dw AH42h_HandlerForExtendedReadSectors ; 42h, Extended Read Sectors (EBIOS)*
445 dw AH43h_HandlerForExtendedWriteSectors ; 43h, Extended Write Sectors (EBIOS)*
446 dw AH44h_HandlerForExtendedVerifySectors ; 44h, Extended Verify Sectors (EBIOS)*
447 dw UnsupportedFunction ; 45h, Lock and Unlock Drive (EBIOS)***
448 dw UnsupportedFunction ; 46h, Eject Media Request (EBIOS)***
449 dw AH47h_HandlerForExtendedSeek ; 47h, Extended Seek (EBIOS)*
450 dw AH48h_HandlerForGetExtendedDriveParameters ; 48h, Get Extended Drive Parameters (EBIOS)*
451; dw UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)***
452; dw UnsupportedFunction ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
453; dw UnsupportedFunction ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
454; dw UnsupportedFunction ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
455; dw UnsupportedFunction ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
456; dw UnsupportedFunction ; 4Eh, Set Hardware Configuration (EBIOS)**
457;
458; * = Enhanced Drive Access Support (minimum required EBIOS functions)
459; ** = Enhanced Disk Drive (EDD) Support
460; *** = Drive Locking and Ejecting Support
461%endif
Note: See TracBrowser for help on using the repository browser.