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

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

Changes to XTIDE Universal BIOS:

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