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

Last change on this file since 387 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

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