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

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

Changes to XTIDE Universal BIOS:

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