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

Last change on this file since 515 was 507, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Reduced minimum time to display hotkeys. Now it is 2 seconds.
  • Brought back IDE controller reset.
  • Space savings by merging AH=Dh to AH=0h. AH=Dh is now redirected to AH=9h.
File size: 15.6 KB
RevLine 
[90]1; Project name : XTIDE Universal BIOS
[3]2; Description : Int 13h BIOS functions (Floppy and Hard disk).
3
[376]4;
[445]5; XTIDE Universal BIOS and Associated Tools
[376]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.
[445]12;
[376]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
[445]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[445]18;
[376]19
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h software interrupt handler.
[417]25; This handler changes stack to top of stolen conventional memory
26; and then calls the actual INT 13h handler (Int13h_DiskFunctionsHandler).
27;
28; Int13h_DiskFunctionsHandlerWithStackChange
29; Parameters:
30; AH: Bios function
31; DL: Drive number
32; Other: Depends on function
33; Returns:
34; Depends on function
35;--------------------------------------------------------------------
36%ifdef RELOCATE_INT13H_STACK
37ALIGN JUMP_ALIGN
38Int13h_DiskFunctionsHandlerWithStackChange:
39 push ds
40 push di
41 call RamVars_GetSegmentToDS
42
43 ; Store entry registers to RAMVARS
44 mov [RAMVARS.fpInt13hEntryStack], sp
45 mov [RAMVARS.fpInt13hEntryStack+2], ss
46 pop WORD [RAMVARS.wStackChangeDI]
47 pop WORD [RAMVARS.wStackChangeDS]
48
49 ; Load new stack and restore DS and DI
50 mov di, ds ; We do not want to overwrite DS and DI in stack
51 mov ss, di
52 mov sp, [RAMVARS.wNewStackOffset]
53 lds di, [RAMVARS.dwStackChangeDSDI]
54
55 ; Call INT 13h
56 pushf
57 push cs
58 call Int13h_DiskFunctionsHandler
59
60 ; Restore stack (we must not corrupt FLAGS!)
61 cli
62%ifdef USE_386
63 lss sp, [ss:RAMVARS.fpInt13hEntryStack]
64%else
65 mov sp, [ss:RAMVARS.fpInt13hEntryStack]
66 mov ss, [ss:RAMVARS.fpInt13hEntryStack+2]
67%endif
68 pop di ; DI before stack change
69 pop ds ; DS before stack change
70 retf 2 ; Skip FLAGS from stack
71%endif ; RELOCATE_INT13H_STACK
72
73
74;--------------------------------------------------------------------
75; Int 13h software interrupt handler.
[3]76; Jumps to specific function defined in AH.
77;
[148]78; Note to developers: Do not make recursive INT 13h calls!
79;
80; Int13h_DiskFunctionsHandler
[3]81; Parameters:
82; AH: Bios function
83; DL: Drive number
[148]84; Other: Depends on function
[3]85; Returns:
86; Depends on function
87;--------------------------------------------------------------------
88ALIGN JUMP_ALIGN
[148]89Int13h_DiskFunctionsHandler:
[3]90 sti ; Enable interrupts
[150]91 cld ; String instructions to increment pointers
[443]92 CREATE_FRAME_INTPACK_TO_SSBP SIZE_OF_IDEPACK_WITHOUT_INTPACK
[3]93 call RamVars_GetSegmentToDS
[294]94
[493]95%ifdef MODULE_DRIVEXLATE
[148]96 call DriveXlate_ToOrBack
[414]97 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
[395]98%endif
[322]99 call FindDPT_ForDriveNumberInDL ; DS:DI points to our DPT, or NULL if not our drive
100 jc SHORT .NotOurDrive ; DPT not found so this is not one of our drives
[258]101
[294]102.OurFunction:
[3]103 ; Jump to correct BIOS function
[148]104 eMOVZX bx, ah
[445]105 eSHL_IM bx, 1
[165]106 cmp ah, 25h ; Possible EBIOS function?
[417]107%ifndef MODULE_EBIOS
108 ja SHORT UnsupportedFunction
109 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
110
111%else ; If using MODULE_EBIOS
[165]112 ja SHORT .JumpToEbiosFunction
[148]113 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
[3]114
[165]115ALIGN JUMP_ALIGN
116.JumpToEbiosFunction:
[421]117 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
[417]118 jz SHORT UnsupportedFunction ; No eINT 13h for CHS drives
[322]119 sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table
[417]120 jb SHORT UnsupportedFunction
[167]121 cmp ah, 48h
[417]122 ja SHORT UnsupportedFunction
[165]123 jmp [cs:bx+g_rgwEbiosFunctionJumpTable]
[417]124%endif ; MODULE_EBIOS
[3]125
[417]126
[322]127ALIGN JUMP_ALIGN
128.NotOurDrive:
129 test ah, ah
130 jz SHORT .OurFunction ; We handle all function 0h requests (resets)
[260]131
[322]132%ifndef MODULE_SERIAL_FLOPPY
133; Without floppy support, we handle only hard disk traffic for function 08h.
134 test dl, dl
135 jns SHORT Int13h_DirectCallToAnotherBios
136%endif
137; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
138 cmp ah, 8
139 je SHORT .OurFunction
140 ; Fall to Int13h_DirectCallToAnotherBios
141
[417]142
[3]143;--------------------------------------------------------------------
[417]144; UnsupportedFunction
[3]145; Int13h_DirectCallToAnotherBios
146; Parameters:
[148]147; DL: Translated drive number
[3]148; DS: RAMVARS segment
[150]149; SS:BP: Ptr to IDEPACK
[148]150; BX, DI: Corrupted on Int13h_DiskFunctionsHandler
[161]151; Other: Function specific INT 13h parameters
[3]152; Returns:
153; Depends on function
154; Corrupts registers:
155; Flags
156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
[417]158UnsupportedFunction:
[3]159Int13h_DirectCallToAnotherBios:
[148]160 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[150]161 mov bx, [bp+IDEPACK.intpack+INTPACK.bx]
162 mov di, [bp+IDEPACK.intpack+INTPACK.di]
163 mov ds, [bp+IDEPACK.intpack+INTPACK.ds]
164 push WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]165 popf
166 push bp
[150]167 mov bp, [bp+IDEPACK.intpack+INTPACK.bp]
[148]168 int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
[3]169
[148]170 ; Store returned values to INTPACK
171 pop bp ; Standard INT 13h functions never uses BP as return register
172%ifdef USE_386
[322]173; mov [bp+IDEPACK.intpack+INTPACK.gs], gs
174; mov [bp+IDEPACK.intpack+INTPACK.fs], fs
[148]175%endif
[150]176 mov [bp+IDEPACK.intpack+INTPACK.es], es
177 mov [bp+IDEPACK.intpack+INTPACK.ds], ds
178 mov [bp+IDEPACK.intpack+INTPACK.di], di
179 mov [bp+IDEPACK.intpack+INTPACK.si], si
180 mov [bp+IDEPACK.intpack+INTPACK.bx], bx
[493]181%ifdef MODULE_DRIVEXLATE
[150]182 mov [bp+IDEPACK.intpack+INTPACK.dh], dh
[414]183%else
184 mov [bp+IDEPACK.intpack+INTPACK.dx], dx
185%endif
[150]186 mov [bp+IDEPACK.intpack+INTPACK.cx], cx
187 mov [bp+IDEPACK.intpack+INTPACK.ax], ax
[148]188 pushf
[150]189 pop WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]190 call RamVars_GetSegmentToDS
[414]191
[493]192%ifdef MODULE_DRIVEXLATE
[414]193 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] ; DL is still drive number?
[148]194 je SHORT .ExchangeInt13hHandlers
[414]195 mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
[148]196ALIGN JUMP_ALIGN
197.ExchangeInt13hHandlers:
[414]198%endif
199
[249]200%ifdef USE_186
201 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
202 jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
203%else
[148]204 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[249]205 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
206%endif
[3]207
[417]208
[260]209%ifdef MODULE_SERIAL_FLOPPY
210;--------------------------------------------------------------------
211; Int13h_ReturnSuccessForFloppy
212;
213; Some operations, such as format of a floppy disk track, should just
214; return success, while for hard disks it should be treated as unsupported.
215;--------------------------------------------------------------------
216ALIGN JUMP_ALIGN
217Int13h_ReturnSuccessForFloppy:
218 test dl, dl
[417]219 js SHORT UnsupportedFunction
[294]220 xor ah, ah
[417]221 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[260]222%endif
[3]223
[417]224
[3]225;--------------------------------------------------------------------
[249]226; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
227; Parameters:
228; AH: BIOS Error code
229; CL: Number of sectors actually transferred
230; SS:BP: Ptr to IDEPACK
231; Returns:
232; All registers are loaded from INTPACK
233;--------------------------------------------------------------------
234ALIGN JUMP_ALIGN
235Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
236 mov [bp+IDEPACK.intpack+INTPACK.al], cl
237 ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
238
[417]239
[249]240;--------------------------------------------------------------------
[148]241; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
242; Int13h_ReturnFromHandlerWithoutStoringErrorCode
[32]243; Parameters:
[148]244; AH: BIOS Error code
[417]245; DS: RAMVARS segment
[150]246; SS:BP: Ptr to IDEPACK
[32]247; Returns:
[148]248; All registers are loaded from INTPACK
[32]249;--------------------------------------------------------------------
250ALIGN JUMP_ALIGN
[148]251Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
[258]252%ifdef MODULE_SERIAL_FLOPPY
253 mov al, [bp+IDEPACK.intpack+INTPACK.dl]
[294]254Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
[258]255 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
[414]256
[258]257%else
[150]258 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
[258]259%endif
[414]260
[148]261Int13h_ReturnFromHandlerWithoutStoringErrorCode:
[417]262 ; Always return with interrupts enabled since there are programs that rely
263 ; on INT 13h to enable interrupts.
264 or BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
265 mov sp, bp ; This makes possible to exit anytime, no matter what is on stack
[443]266 RESTORE_FRAME_INTPACK_FROM_SSBP SIZE_OF_IDEPACK_WITHOUT_INTPACK
[32]267
268
269;--------------------------------------------------------------------
[148]270; Int13h_CallPreviousInt13hHandler
[3]271; Parameters:
[148]272; AH: INT 13h function to call
273; DL: Drive number
274; DS: RAMVARS segment
[3]275; Returns:
276; Depends on function
[294]277; NOTE: ES:DI needs to be returned from the previous interrupt
[258]278; handler, for floppy DPT in function 08h
[3]279; Corrupts registers:
[258]280; None
[3]281;--------------------------------------------------------------------
282ALIGN JUMP_ALIGN
[148]283Int13h_CallPreviousInt13hHandler:
284 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler
285 int BIOS_DISK_INTERRUPT_13h
[258]286;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[35]287
[3]288;--------------------------------------------------------------------
[148]289; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[3]290; Parameters:
291; DS: RAMVARS segment
292; Returns:
[148]293; Nothing
[3]294; Corrupts registers:
[258]295; Nothing
296; Note: Flags are preserved
[3]297;--------------------------------------------------------------------
298ALIGN JUMP_ALIGN
[148]299ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
300 push es
[258]301 push si
302 LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si
303 mov si, [RAMVARS.fpOldI13h]
[150]304 cli
[258]305 xchg si, [es:BIOS_DISK_INTERRUPT_13h*4]
306 mov [RAMVARS.fpOldI13h], si
307 mov si, [RAMVARS.fpOldI13h+2]
308 xchg si, [es:BIOS_DISK_INTERRUPT_13h*4+2]
[181]309 sti
[258]310 mov [RAMVARS.fpOldI13h+2], si
311 pop si
[148]312 pop es
313 ret
[28]314
[35]315
[150]316;--------------------------------------------------------------------
317; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
318; Int13h_SetErrorCodeToIntpackInSSBPfromAH
319; Parameters:
320; AH: BIOS error code (00h = no error)
321; SS:BP: Ptr to IDEPACK
322; Returns:
323; SS:BP: Ptr to IDEPACK with error condition set
324; Corrupts registers:
325; DS, DI
326;--------------------------------------------------------------------
327ALIGN JUMP_ALIGN
[258]328%ifdef MODULE_SERIAL_FLOPPY
329Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
330 ; Store error code to BDA
331 mov bx, BDA.bHDLastSt
332 test al, al
[414]333 js SHORT .HardDisk
[258]334 mov bl, BDA.bFDRetST & 0xff
335.HardDisk:
336 LOAD_BDA_SEGMENT_TO ds, di
[294]337 mov [bx], ah
[417]338 ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
339
[258]340%else
[150]341Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
342 ; Store error code to BDA
[294]343 LOAD_BDA_SEGMENT_TO ds, di
[150]344 mov [BDA.bHDLastSt], ah
[417]345 ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
[258]346%endif
[35]347
[150]348 ; Store error code to INTPACK
349Int13h_SetErrorCodeToIntpackInSSBPfromAH:
350 mov [bp+IDEPACK.intpack+INTPACK.ah], ah
351 test ah, ah
352 jnz SHORT .SetCFtoIntpack
353 and BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
354 ret
355.SetCFtoIntpack:
356 or BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
357 ret
358
359
[3]360; Jump table for correct BIOS function
361ALIGN WORD_ALIGN
362g_rgw13hFuncJump:
[417]363 dw AH0h_HandlerForDiskControllerReset ; 00h, Disk Controller Reset (All)
364 dw AH1h_HandlerForReadDiskStatus ; 01h, Read Disk Status (All)
365 dw AH2h_HandlerForReadDiskSectors ; 02h, Read Disk Sectors (All)
366 dw AH3h_HandlerForWriteDiskSectors ; 03h, Write Disk Sectors (All)
367 dw AH4h_HandlerForVerifyDiskSectors ; 04h, Verify Disk Sectors (All)
[260]368%ifdef MODULE_SERIAL_FLOPPY
[417]369 dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA)
[260]370%else
[417]371 dw UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA)
[260]372%endif
[417]373 dw UnsupportedFunction ; 06h, Format Disk Track with Bad Sectors (XT)
374 dw UnsupportedFunction ; 07h, Format Multiple Cylinders (XT)
375 dw AH8h_HandlerForReadDiskDriveParameters ; 08h, Read Disk Drive Parameters (All)
376 dw AH9h_HandlerForInitializeDriveParameters ; 09h, Initialize Drive Parameters (All)
377 dw UnsupportedFunction ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
378 dw UnsupportedFunction ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
379 dw AHCh_HandlerForSeek ; 0Ch, Seek (All)
[507]380 dw AH9h_HandlerForInitializeDriveParameters ; 0Dh, Alternate Disk Reset (All)
[417]381 dw UnsupportedFunction ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
382 dw UnsupportedFunction ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
383 dw AH10h_HandlerForCheckDriveReady ; 10h, Check Drive Ready (All)
384 dw AH11h_HandlerForRecalibrate ; 11h, Recalibrate (All)
385 dw UnsupportedFunction ; 12h, Controller RAM Diagnostic (XT)
386 dw UnsupportedFunction ; 13h, Drive Diagnostic (XT)
387 dw UnsupportedFunction ; 14h, Controller Internal Diagnostic (All)
388 dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+)
389 dw UnsupportedFunction ; 16h,
390 dw UnsupportedFunction ; 17h,
391 dw UnsupportedFunction ; 18h,
392 dw UnsupportedFunction ; 19h, Park Heads (PS/2)
393 dw UnsupportedFunction ; 1Ah, Format ESDI Drive (PS/2)
394 dw UnsupportedFunction ; 1Bh, Get ESDI Manufacturing Header (PS/2)
395 dw UnsupportedFunction ; 1Ch, ESDI Special Functions (PS/2)
396 dw UnsupportedFunction ; 1Dh,
[493]397%ifdef MODULE_8BIT_IDE_ADVANCED
[471]398 dw AH1Eh_HandlerForXTCFfeatures ; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
399%else
400 dw UnsupportedFunction ; 1Eh,
401%endif
[417]402 dw UnsupportedFunction ; 1Fh,
403 dw UnsupportedFunction ; 20h,
404 dw UnsupportedFunction ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
405 dw UnsupportedFunction ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
406 dw AH23h_HandlerForSetControllerFeatures ; 23h, Set Controller Features Register (PS/1)
407 dw AH24h_HandlerForSetMultipleBlocks ; 24h, Set Multiple Blocks (PS/1)
408 dw AH25h_HandlerForGetDriveInformation ; 25h, Get Drive Information (PS/1)
[165]409
[176]410%ifdef MODULE_EBIOS
[165]411g_rgwEbiosFunctionJumpTable:
[417]412 dw AH41h_HandlerForCheckIfExtensionsPresent ; 41h, Check if Extensions Present (EBIOS)*
413 dw AH42h_HandlerForExtendedReadSectors ; 42h, Extended Read Sectors (EBIOS)*
414 dw AH43h_HandlerForExtendedWriteSectors ; 43h, Extended Write Sectors (EBIOS)*
415 dw AH44h_HandlerForExtendedVerifySectors ; 44h, Extended Verify Sectors (EBIOS)*
416 dw UnsupportedFunction ; 45h, Lock and Unlock Drive (EBIOS)***
417 dw UnsupportedFunction ; 46h, Eject Media Request (EBIOS)***
418 dw AH47h_HandlerForExtendedSeek ; 47h, Extended Seek (EBIOS)*
419 dw AH48h_HandlerForGetExtendedDriveParameters ; 48h, Get Extended Drive Parameters (EBIOS)*
420; dw UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)***
421; dw UnsupportedFunction ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
422; dw UnsupportedFunction ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
423; dw UnsupportedFunction ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
424; dw UnsupportedFunction ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
425; dw UnsupportedFunction ; 4Eh, Set Hardware Configuration (EBIOS)**
[150]426;
427; * = Enhanced Drive Access Support (minimum required EBIOS functions)
428; ** = Enhanced Disk Drive (EDD) Support
429; *** = Drive Locking and Ejecting Support
[181]430%endif
Note: See TracBrowser for help on using the repository browser.