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

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

Changes to XTIDE Universal BIOS:

  • Commented out the FS and GS segment registers from INTPACK since we never touch them anyway.
  • Minor changes to improve speed in the Int13h handler.
  • Changed Prepare_ByValidatingSectorsInALforOldInt13h so it really doesn't corrupt anything.
  • Changed the makefile so 'make strings' now works even if StringsCompressed.asm is missing or empty.
File size: 13.1 KB
Line 
1; Project name : XTIDE Universal BIOS
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;
11; Note to developers: Do not make recursive INT 13h calls!
12;
13; Int13h_DiskFunctionsHandler
14; Parameters:
15; AH: Bios function
16; DL: Drive number
17; Other: Depends on function
18; Returns:
19; Depends on function
20;--------------------------------------------------------------------
21ALIGN JUMP_ALIGN
22Int13h_DiskFunctionsHandler:
23 sti ; Enable interrupts
24 cld ; String instructions to increment pointers
25 CREATE_FRAME_INTPACK_TO_SSBP EXTRA_BYTES_FOR_INTPACK
26
27 call RamVars_GetSegmentToDS
28
29 call DriveXlate_ToOrBack
30 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
31
32 call FindDPT_ForDriveNumberInDL ; DS:DI points to our DPT, or NULL if not our drive
33 jc SHORT .NotOurDrive ; DPT not found so this is not one of our drives
34
35.OurFunction:
36 ; Jump to correct BIOS function
37 eMOVZX bx, ah
38 shl bx, 1
39 cmp ah, 25h ; Possible EBIOS function?
40%ifdef MODULE_EBIOS
41 ja SHORT .JumpToEbiosFunction
42%else
43 ja SHORT Int13h_UnsupportedFunction
44%endif
45 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
46
47%ifdef MODULE_EBIOS
48 ; Jump to correct EBIOS function
49ALIGN JUMP_ALIGN
50.JumpToEbiosFunction:
51 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
52 jz SHORT Int13h_UnsupportedFunction ; No eINT 13h for CHS drives
53 sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table
54 jb SHORT Int13h_UnsupportedFunction
55 cmp ah, 48h
56 ja SHORT Int13h_UnsupportedFunction
57 jmp [cs:bx+g_rgwEbiosFunctionJumpTable]
58%endif
59
60ALIGN JUMP_ALIGN
61.NotOurDrive:
62 test ah, ah
63 jz SHORT .OurFunction ; We handle all function 0h requests (resets)
64
65%ifndef MODULE_SERIAL_FLOPPY
66; Without floppy support, we handle only hard disk traffic for function 08h.
67 test dl, dl
68 jns SHORT Int13h_DirectCallToAnotherBios
69%endif
70; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
71 cmp ah, 8
72 je SHORT .OurFunction
73 ; Fall to Int13h_DirectCallToAnotherBios
74
75;--------------------------------------------------------------------
76; Int13h_UnsupportedFunction
77; Int13h_DirectCallToAnotherBios
78; Parameters:
79; DL: Translated drive number
80; DS: RAMVARS segment
81; SS:BP: Ptr to IDEPACK
82; BX, DI: Corrupted on Int13h_DiskFunctionsHandler
83; Other: Function specific INT 13h parameters
84; Returns:
85; Depends on function
86; Corrupts registers:
87; Flags
88;--------------------------------------------------------------------
89ALIGN JUMP_ALIGN
90Int13h_UnsupportedFunction:
91Int13h_DirectCallToAnotherBios:
92 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
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]
97 popf
98 push bp
99 mov bp, [bp+IDEPACK.intpack+INTPACK.bp]
100 int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
101
102 ; Store returned values to INTPACK
103 pop bp ; Standard INT 13h functions never uses BP as return register
104%ifdef USE_386
105; mov [bp+IDEPACK.intpack+INTPACK.gs], gs
106; mov [bp+IDEPACK.intpack+INTPACK.fs], fs
107%endif
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
116 pushf
117 pop WORD [bp+IDEPACK.intpack+INTPACK.flags]
118 call RamVars_GetSegmentToDS
119 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]
120 je SHORT .ExchangeInt13hHandlers
121 mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
122ALIGN JUMP_ALIGN
123.ExchangeInt13hHandlers:
124%ifdef USE_186
125 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
126 jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
127%else
128 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
129 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
130%endif
131
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
143 xor ah, ah
144 jmp short Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
145%endif
146
147;--------------------------------------------------------------------
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;--------------------------------------------------------------------
162; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
163; Int13h_ReturnFromHandlerWithoutStoringErrorCode
164; Parameters:
165; AH: BIOS Error code
166; SS:BP: Ptr to IDEPACK
167; Returns:
168; All registers are loaded from INTPACK
169;--------------------------------------------------------------------
170ALIGN JUMP_ALIGN
171Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
172%ifdef MODULE_SERIAL_FLOPPY
173 mov al, [bp+IDEPACK.intpack+INTPACK.dl]
174Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
175 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
176%else
177 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
178%endif
179Int13h_ReturnFromHandlerWithoutStoringErrorCode:
180 or WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF ; Return with interrupts enabled
181 mov sp, bp ; Now we can exit anytime
182 RESTORE_FRAME_INTPACK_FROM_SSBP EXTRA_BYTES_FOR_INTPACK
183
184
185;--------------------------------------------------------------------
186; Int13h_CallPreviousInt13hHandler
187; Parameters:
188; AH: INT 13h function to call
189; DL: Drive number
190; DS: RAMVARS segment
191; Returns:
192; Depends on function
193; NOTE: ES:DI needs to be returned from the previous interrupt
194; handler, for floppy DPT in function 08h
195; Corrupts registers:
196; None
197;--------------------------------------------------------------------
198ALIGN JUMP_ALIGN
199Int13h_CallPreviousInt13hHandler:
200 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
201 int BIOS_DISK_INTERRUPT_13h
202;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
203
204;--------------------------------------------------------------------
205; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
206; Parameters:
207; DS: RAMVARS segment
208; Returns:
209; Nothing
210; Corrupts registers:
211; Nothing
212; Note: Flags are preserved
213;--------------------------------------------------------------------
214ALIGN JUMP_ALIGN
215ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
216 push es
217 push si
218 LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si
219 mov si, [RAMVARS.fpOldI13h]
220 cli
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]
225 sti
226 mov [RAMVARS.fpOldI13h+2], si
227 pop si
228 pop es
229 ret
230
231
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
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
253 mov [bx], ah
254%else
255Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
256 ; Store error code to BDA
257 LOAD_BDA_SEGMENT_TO ds, di
258 mov [BDA.bHDLastSt], ah
259%endif
260
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
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)
281%ifdef MODULE_SERIAL_FLOPPY
282 dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA)
283%else
284 dw Int13h_UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA)
285%endif
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)
300 dw Int13h_UnsupportedFunction ; 14h, Controller Internal Diagnostic (All)
301 dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+)
302 dw Int13h_UnsupportedFunction ; 16h,
303 dw Int13h_UnsupportedFunction ; 17h,
304 dw Int13h_UnsupportedFunction ; 18h,
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)
309 dw Int13h_UnsupportedFunction ; 1Dh,
310 dw Int13h_UnsupportedFunction ; 1Eh,
311 dw Int13h_UnsupportedFunction ; 1Fh,
312 dw Int13h_UnsupportedFunction ; 20h,
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)
318
319%ifdef MODULE_EBIOS
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)*
329; dw Int13h_UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)***
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)
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
339%endif
Note: See TracBrowser for help on using the repository browser.