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

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

Oops, forgot to check if it still compiled without floppy support, fixed up a couple of typos and put an ifdef back into place.

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