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

Last change on this file since 319 was 294, checked in by krille_n_@…, 13 years ago

Commit 2/2 (BIOS):

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