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

Last change on this file since 411 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
RevLine 
[90]1; Project name : XTIDE Universal BIOS
[3]2; Description : Int 13h BIOS functions (Floppy and Hard disk).
3
[376]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
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h software interrupt handler.
25; Jumps to specific function defined in AH.
26;
[148]27; Note to developers: Do not make recursive INT 13h calls!
28;
29; Int13h_DiskFunctionsHandler
[3]30; Parameters:
31; AH: Bios function
32; DL: Drive number
[148]33; Other: Depends on function
[3]34; Returns:
35; Depends on function
36;--------------------------------------------------------------------
37ALIGN JUMP_ALIGN
[148]38Int13h_DiskFunctionsHandler:
[3]39 sti ; Enable interrupts
[150]40 cld ; String instructions to increment pointers
[155]41 CREATE_FRAME_INTPACK_TO_SSBP EXTRA_BYTES_FOR_INTPACK
[3]42
43 call RamVars_GetSegmentToDS
[294]44
[395]45%ifdef MODULE_HOTKEYS
[148]46 call DriveXlate_ToOrBack
[395]47%endif
[148]48 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
[294]49
[322]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
[258]52
[294]53.OurFunction:
[3]54 ; Jump to correct BIOS function
[148]55 eMOVZX bx, ah
56 shl bx, 1
[165]57 cmp ah, 25h ; Possible EBIOS function?
[176]58%ifdef MODULE_EBIOS
[165]59 ja SHORT .JumpToEbiosFunction
[176]60%else
61 ja SHORT Int13h_UnsupportedFunction
62%endif
[148]63 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
[3]64
[176]65%ifdef MODULE_EBIOS
[165]66 ; Jump to correct EBIOS function
67ALIGN JUMP_ALIGN
68.JumpToEbiosFunction:
[167]69 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
70 jz SHORT Int13h_UnsupportedFunction ; No eINT 13h for CHS drives
[322]71 sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table
72 jb SHORT Int13h_UnsupportedFunction
[167]73 cmp ah, 48h
[165]74 ja SHORT Int13h_UnsupportedFunction
75 jmp [cs:bx+g_rgwEbiosFunctionJumpTable]
[176]76%endif
[3]77
[322]78ALIGN JUMP_ALIGN
79.NotOurDrive:
80 test ah, ah
81 jz SHORT .OurFunction ; We handle all function 0h requests (resets)
[260]82
[322]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
[3]93;--------------------------------------------------------------------
[148]94; Int13h_UnsupportedFunction
[3]95; Int13h_DirectCallToAnotherBios
96; Parameters:
[148]97; DL: Translated drive number
[3]98; DS: RAMVARS segment
[150]99; SS:BP: Ptr to IDEPACK
[148]100; BX, DI: Corrupted on Int13h_DiskFunctionsHandler
[161]101; Other: Function specific INT 13h parameters
[3]102; Returns:
103; Depends on function
104; Corrupts registers:
105; Flags
106;--------------------------------------------------------------------
107ALIGN JUMP_ALIGN
108Int13h_UnsupportedFunction:
109Int13h_DirectCallToAnotherBios:
[148]110 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[150]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]
[148]115 popf
116 push bp
[150]117 mov bp, [bp+IDEPACK.intpack+INTPACK.bp]
[148]118 int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
[3]119
[148]120 ; Store returned values to INTPACK
121 pop bp ; Standard INT 13h functions never uses BP as return register
122%ifdef USE_386
[322]123; mov [bp+IDEPACK.intpack+INTPACK.gs], gs
124; mov [bp+IDEPACK.intpack+INTPACK.fs], fs
[148]125%endif
[150]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
[148]134 pushf
[150]135 pop WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]136 call RamVars_GetSegmentToDS
137 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]
138 je SHORT .ExchangeInt13hHandlers
[150]139 mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
[148]140ALIGN JUMP_ALIGN
141.ExchangeInt13hHandlers:
[249]142%ifdef USE_186
143 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
144 jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
145%else
[148]146 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[249]147 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
148%endif
[3]149
[260]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
[294]161 xor ah, ah
[260]162 jmp short Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
163%endif
[3]164
165;--------------------------------------------------------------------
[249]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;--------------------------------------------------------------------
[148]180; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
181; Int13h_ReturnFromHandlerWithoutStoringErrorCode
[32]182; Parameters:
[148]183; AH: BIOS Error code
[150]184; SS:BP: Ptr to IDEPACK
[32]185; Returns:
[148]186; All registers are loaded from INTPACK
[32]187;--------------------------------------------------------------------
188ALIGN JUMP_ALIGN
[148]189Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
[258]190%ifdef MODULE_SERIAL_FLOPPY
191 mov al, [bp+IDEPACK.intpack+INTPACK.dl]
[294]192Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
[258]193 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
194%else
[150]195 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
[258]196%endif
[148]197Int13h_ReturnFromHandlerWithoutStoringErrorCode:
[150]198 or WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF ; Return with interrupts enabled
[148]199 mov sp, bp ; Now we can exit anytime
[155]200 RESTORE_FRAME_INTPACK_FROM_SSBP EXTRA_BYTES_FOR_INTPACK
[32]201
202
203;--------------------------------------------------------------------
[148]204; Int13h_CallPreviousInt13hHandler
[3]205; Parameters:
[148]206; AH: INT 13h function to call
207; DL: Drive number
208; DS: RAMVARS segment
[3]209; Returns:
210; Depends on function
[294]211; NOTE: ES:DI needs to be returned from the previous interrupt
[258]212; handler, for floppy DPT in function 08h
[3]213; Corrupts registers:
[258]214; None
[3]215;--------------------------------------------------------------------
216ALIGN JUMP_ALIGN
[148]217Int13h_CallPreviousInt13hHandler:
218 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
219 int BIOS_DISK_INTERRUPT_13h
[258]220;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[35]221
[3]222;--------------------------------------------------------------------
[148]223; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[3]224; Parameters:
225; DS: RAMVARS segment
226; Returns:
[148]227; Nothing
[3]228; Corrupts registers:
[258]229; Nothing
230; Note: Flags are preserved
[3]231;--------------------------------------------------------------------
232ALIGN JUMP_ALIGN
[148]233ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
234 push es
[258]235 push si
236 LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si
237 mov si, [RAMVARS.fpOldI13h]
[150]238 cli
[258]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]
[181]243 sti
[258]244 mov [RAMVARS.fpOldI13h+2], si
245 pop si
[148]246 pop es
247 ret
[28]248
[35]249
[150]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
[258]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
[294]271 mov [bx], ah
[258]272%else
[150]273Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
274 ; Store error code to BDA
[294]275 LOAD_BDA_SEGMENT_TO ds, di
[150]276 mov [BDA.bHDLastSt], ah
[258]277%endif
[35]278
[150]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
[3]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)
[260]299%ifdef MODULE_SERIAL_FLOPPY
300 dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA)
301%else
[90]302 dw Int13h_UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA)
[260]303%endif
[3]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)
[90]318 dw Int13h_UnsupportedFunction ; 14h, Controller Internal Diagnostic (All)
[3]319 dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+)
[161]320 dw Int13h_UnsupportedFunction ; 16h,
321 dw Int13h_UnsupportedFunction ; 17h,
322 dw Int13h_UnsupportedFunction ; 18h,
[3]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)
[161]327 dw Int13h_UnsupportedFunction ; 1Dh,
328 dw Int13h_UnsupportedFunction ; 1Eh,
329 dw Int13h_UnsupportedFunction ; 1Fh,
330 dw Int13h_UnsupportedFunction ; 20h,
[3]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)
[165]336
[176]337%ifdef MODULE_EBIOS
[165]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)*
[150]347; dw Int13h_UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)***
[3]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)
[150]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
[181]357%endif
Note: See TracBrowser for help on using the repository browser.