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

Last change on this file since 613 was 596, checked in by Krister Nordvall, 6 years ago

Changes:

  • Made changes to HotkeyBar.asm to give the Boot Menu and Hotkey Bar a more consistent look. It will probably seem a bit strange at first to people used to the classic theme.
  • Added the missing parts of USE_NEC_V that should have been committed with the rest in r593.
  • Removed DEFINES_ALL_FEATURES from the BIOS makefile. It didn't work anymore and never really made sense anyway. Added all the official builds to 'make unused' instead which actually uncovered some unused code in the Tiny build.
  • XTIDECFG will no longer load color themes from unrecognized versions of the BIOS.
  • Other fixes in comments and some minor optimizations.
File size: 16.4 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
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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:
[525]39 sti ; Enable interrupts
40 ; TODO: Maybe we need to save Flags (DF) as well?
41 push ds ; Save DS:DI on the original stack
[417]42 push di
43 call RamVars_GetSegmentToDS
44
45 ; Store entry registers to RAMVARS
[525]46%ifdef USE_386
47 pop DWORD [RAMVARS.dwStackChangeDSDI]
48%else
49 pop WORD [RAMVARS.wStackChangeDI] ; Pop DS:DI to the top of what
50 pop WORD [RAMVARS.wStackChangeDS] ; is to become the new stack
51%endif
[417]52 mov [RAMVARS.fpInt13hEntryStack], sp
53 mov [RAMVARS.fpInt13hEntryStack+2], ss
54
55 ; Load new stack and restore DS and DI
[525]56 mov di, ds ; We can save 2 bytes by using PUSH/POP but it's slower
57 mov ss, di ; No need to wrap with CLI/STI since this is for AT only (286+)
58 mov sp, RAMVARS.rgbTopOfStack-4
59 pop di ; DI before stack change
60 pop ds ; DS before stack change
[417]61
62 ; Call INT 13h
63 pushf
64 push cs
65 call Int13h_DiskFunctionsHandler
66
67 ; Restore stack (we must not corrupt FLAGS!)
68%ifdef USE_386
69 lss sp, [ss:RAMVARS.fpInt13hEntryStack]
70%else
[525]71 cli
[417]72 mov sp, [ss:RAMVARS.fpInt13hEntryStack]
73 mov ss, [ss:RAMVARS.fpInt13hEntryStack+2]
[525]74 sti
[417]75%endif
76 retf 2 ; Skip FLAGS from stack
77%endif ; RELOCATE_INT13H_STACK
78
79
80;--------------------------------------------------------------------
81; Int 13h software interrupt handler.
[3]82; Jumps to specific function defined in AH.
83;
[148]84; Note to developers: Do not make recursive INT 13h calls!
85;
86; Int13h_DiskFunctionsHandler
[3]87; Parameters:
88; AH: Bios function
89; DL: Drive number
[148]90; Other: Depends on function
[3]91; Returns:
92; Depends on function
93;--------------------------------------------------------------------
94ALIGN JUMP_ALIGN
[148]95Int13h_DiskFunctionsHandler:
[525]96%ifndef RELOCATE_INT13H_STACK
[3]97 sti ; Enable interrupts
[556]98%endif
[592]99%ifdef CLD_NEEDED
[150]100 cld ; String instructions to increment pointers
[592]101%endif
[589]102 ePUSHA
103 push ds
104 push es
105%ifdef USE_386
106; push fs
107; push gs
108%endif
109 sub sp, BYTE SIZE_OF_IDEPACK_WITHOUT_INTPACK
110 mov bp, sp
[3]111 call RamVars_GetSegmentToDS
[294]112
[493]113%ifdef MODULE_DRIVEXLATE
[148]114 call DriveXlate_ToOrBack
[395]115%endif
[322]116 call FindDPT_ForDriveNumberInDL ; DS:DI points to our DPT, or NULL if not our drive
117 jc SHORT .NotOurDrive ; DPT not found so this is not one of our drives
[258]118
[294]119.OurFunction:
[3]120 ; Jump to correct BIOS function
[148]121 eMOVZX bx, ah
[445]122 eSHL_IM bx, 1
[165]123 cmp ah, 25h ; Possible EBIOS function?
[417]124%ifndef MODULE_EBIOS
125 ja SHORT UnsupportedFunction
126 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
127
128%else ; If using MODULE_EBIOS
[165]129 ja SHORT .JumpToEbiosFunction
[148]130 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function
[3]131
[165]132ALIGN JUMP_ALIGN
133.JumpToEbiosFunction:
[542]134 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA
[417]135 jz SHORT UnsupportedFunction ; No eINT 13h for CHS drives
[322]136 sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table
[417]137 jb SHORT UnsupportedFunction
[167]138 cmp ah, 48h
[417]139 ja SHORT UnsupportedFunction
[165]140 jmp [cs:bx+g_rgwEbiosFunctionJumpTable]
[417]141%endif ; MODULE_EBIOS
[3]142
[417]143
[322]144ALIGN JUMP_ALIGN
145.NotOurDrive:
146 test ah, ah
147 jz SHORT .OurFunction ; We handle all function 0h requests (resets)
[260]148
[556]149%ifndef MODULE_SERIAL_FLOPPY
150; Without floppy support, we handle only hard disk traffic for function 08h.
151 test dl, dl
152 jns SHORT Int13h_DirectCallToAnotherBios
153%endif
154; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
155 cmp ah, GET_DRIVE_PARAMETERS
[322]156 je SHORT .OurFunction
157 ; Fall to Int13h_DirectCallToAnotherBios
158
[417]159
[3]160;--------------------------------------------------------------------
[417]161; UnsupportedFunction
[3]162; Int13h_DirectCallToAnotherBios
163; Parameters:
[148]164; DL: Translated drive number
[3]165; DS: RAMVARS segment
[150]166; SS:BP: Ptr to IDEPACK
[148]167; BX, DI: Corrupted on Int13h_DiskFunctionsHandler
[161]168; Other: Function specific INT 13h parameters
[3]169; Returns:
170; Depends on function
171; Corrupts registers:
172; Flags
173;--------------------------------------------------------------------
174ALIGN JUMP_ALIGN
[417]175UnsupportedFunction:
[3]176Int13h_DirectCallToAnotherBios:
[557]177%ifdef MODULE_DRIVEXLATE
178 ; Disable drive number translations in case of recursive INT 13h calls
179 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
180 push WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
[558]181 call DriveXlate_Reset ; No translation
[557]182%endif
183
184 push bp ; Store offset to IDEPACK (SS:SP now points it)
185
186 ; Simulate INT by pushing flags and return address
187 push WORD [bp+IDEPACK.intpack+INTPACK.flags]
[561]188%if 0
189 ; No standard INT 13h function uses FLAGS as parameters so no need to restore them
[557]190 popf
[561]191 pushf
192%endif
[557]193 push cs
194 ePUSH_T di, .ReturnFromAnotherBios ; Can not corrupt flags
195
196 ; Push old INT 13h handler and restore registers
[592]197%ifdef USE_386
198 push DWORD [RAMVARS.fpOldI13h]
199%else
[557]200 push WORD [RAMVARS.fpOldI13h+2]
201 push WORD [RAMVARS.fpOldI13h]
[592]202%endif
[150]203 mov bx, [bp+IDEPACK.intpack+INTPACK.bx]
204 mov di, [bp+IDEPACK.intpack+INTPACK.di]
205 mov ds, [bp+IDEPACK.intpack+INTPACK.ds]
206 mov bp, [bp+IDEPACK.intpack+INTPACK.bp]
[557]207 retf ; "Return" to old INT 13h
208.ReturnFromAnotherBios:
[3]209
[557]210%if 0
211 ; We need to restore our pointer to IDEPACK but we cannot corrupt any register
212 push ax ; Dummy WORD
213 cli
214 xchg bp, sp
215 mov [bp], sp ; Replace dummy WORD with returned BP
216 mov sp, [bp+2] ; Load offset to IDEPACK
217 xchg sp, bp
218 sti ; We would have set IF anyway when exiting INT 13h
219 pop WORD [bp+IDEPACK.intpack+INTPACK.bp]
220%endif
221 ; Actually we can corrupt BP since no standard INT 13h function uses it as return
222 ; register. Above code is kept here just in case if there is some non-standard function.
223 ; POP BP below also belongs to the above code.
224 pop bp ; Clean IDEPACK offset from stack
[556]225
[557]226 ; Store remaining returned values to INTPACK
[148]227%ifdef USE_386
[557]228; We do not use GS or FS at the moment
[322]229; mov [bp+IDEPACK.intpack+INTPACK.gs], gs
230; mov [bp+IDEPACK.intpack+INTPACK.fs], fs
[148]231%endif
[150]232 mov [bp+IDEPACK.intpack+INTPACK.es], es
233 mov [bp+IDEPACK.intpack+INTPACK.ds], ds
234 mov [bp+IDEPACK.intpack+INTPACK.di], di
235 mov [bp+IDEPACK.intpack+INTPACK.si], si
236 mov [bp+IDEPACK.intpack+INTPACK.bx], bx
[493]237%ifdef MODULE_DRIVEXLATE
[150]238 mov [bp+IDEPACK.intpack+INTPACK.dh], dh
[414]239%else
240 mov [bp+IDEPACK.intpack+INTPACK.dx], dx
241%endif
[150]242 mov [bp+IDEPACK.intpack+INTPACK.cx], cx
243 mov [bp+IDEPACK.intpack+INTPACK.ax], ax
[148]244 pushf
[150]245 pop WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]246 call RamVars_GetSegmentToDS
[414]247
[493]248%ifdef MODULE_DRIVEXLATE
[557]249 ; Restore drive number translation back to what it was
250 pop WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
[414]251 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] ; DL is still drive number?
[557]252 je SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[414]253 mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
254%endif
[249]255 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[3]256
[417]257
[260]258%ifdef MODULE_SERIAL_FLOPPY
259;--------------------------------------------------------------------
260; Int13h_ReturnSuccessForFloppy
261;
262; Some operations, such as format of a floppy disk track, should just
263; return success, while for hard disks it should be treated as unsupported.
264;--------------------------------------------------------------------
265ALIGN JUMP_ALIGN
266Int13h_ReturnSuccessForFloppy:
267 test dl, dl
[417]268 js SHORT UnsupportedFunction
[294]269 xor ah, ah
[417]270 jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[260]271%endif
[3]272
[417]273
[3]274;--------------------------------------------------------------------
[249]275; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
276; Parameters:
277; AH: BIOS Error code
278; CL: Number of sectors actually transferred
279; SS:BP: Ptr to IDEPACK
280; Returns:
281; All registers are loaded from INTPACK
282;--------------------------------------------------------------------
283ALIGN JUMP_ALIGN
284Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
285 mov [bp+IDEPACK.intpack+INTPACK.al], cl
286 ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
287
[417]288
[249]289;--------------------------------------------------------------------
[148]290; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
291; Int13h_ReturnFromHandlerWithoutStoringErrorCode
[32]292; Parameters:
[148]293; AH: BIOS Error code
[150]294; SS:BP: Ptr to IDEPACK
[32]295; Returns:
[148]296; All registers are loaded from INTPACK
[32]297;--------------------------------------------------------------------
298ALIGN JUMP_ALIGN
[148]299Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
[258]300%ifdef MODULE_SERIAL_FLOPPY
301 mov al, [bp+IDEPACK.intpack+INTPACK.dl]
[294]302Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
[258]303 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
[414]304
[258]305%else
[150]306 call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
[258]307%endif
[414]308
[148]309Int13h_ReturnFromHandlerWithoutStoringErrorCode:
[417]310 ; Always return with interrupts enabled since there are programs that rely
311 ; on INT 13h to enable interrupts.
312 or BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
[32]313
[589]314 lea sp, [bp+SIZE_OF_IDEPACK_WITHOUT_INTPACK]
315%ifdef USE_386
316; pop gs
317; pop fs
318%endif
319 pop es
320 pop ds
321 ePOPA
322 iret
[32]323
[589]324
[32]325;--------------------------------------------------------------------
[148]326; Int13h_CallPreviousInt13hHandler
[3]327; Parameters:
[148]328; AH: INT 13h function to call
329; DL: Drive number
330; DS: RAMVARS segment
[3]331; Returns:
332; Depends on function
[567]333; NOTE: ES:DI needs to be returned from the previous interrupt
334; handler, for floppy DPT in function 08h
[3]335; Corrupts registers:
[258]336; None
[3]337;--------------------------------------------------------------------
338ALIGN JUMP_ALIGN
[148]339Int13h_CallPreviousInt13hHandler:
[557]340 pushf ; Simulate INT by pushing flags
[596]341 call FAR [RAMVARS.fpOldI13h]
[148]342 ret
[28]343
[35]344
[150]345;--------------------------------------------------------------------
[568]346; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
[150]347; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
348; Int13h_SetErrorCodeToIntpackInSSBPfromAH
349; Parameters:
350; AH: BIOS error code (00h = no error)
351; SS:BP: Ptr to IDEPACK
352; Returns:
353; SS:BP: Ptr to IDEPACK with error condition set
354; Corrupts registers:
[568]355; DS, BX, DI
[150]356;--------------------------------------------------------------------
357ALIGN JUMP_ALIGN
[258]358%ifdef MODULE_SERIAL_FLOPPY
359Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
360 ; Store error code to BDA
361 mov bx, BDA.bHDLastSt
362 test al, al
[414]363 js SHORT .HardDisk
[258]364 mov bl, BDA.bFDRetST & 0xff
365.HardDisk:
366 LOAD_BDA_SEGMENT_TO ds, di
[294]367 mov [bx], ah
[417]368 ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
369
[258]370%else
[150]371Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
372 ; Store error code to BDA
[294]373 LOAD_BDA_SEGMENT_TO ds, di
[150]374 mov [BDA.bHDLastSt], ah
[417]375 ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
[258]376%endif
[35]377
[150]378 ; Store error code to INTPACK
379Int13h_SetErrorCodeToIntpackInSSBPfromAH:
380 mov [bp+IDEPACK.intpack+INTPACK.ah], ah
381 test ah, ah
382 jnz SHORT .SetCFtoIntpack
383 and BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
384 ret
385.SetCFtoIntpack:
386 or BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
387 ret
388
389
[3]390; Jump table for correct BIOS function
391ALIGN WORD_ALIGN
392g_rgw13hFuncJump:
[417]393 dw AH0h_HandlerForDiskControllerReset ; 00h, Disk Controller Reset (All)
394 dw AH1h_HandlerForReadDiskStatus ; 01h, Read Disk Status (All)
395 dw AH2h_HandlerForReadDiskSectors ; 02h, Read Disk Sectors (All)
396 dw AH3h_HandlerForWriteDiskSectors ; 03h, Write Disk Sectors (All)
397 dw AH4h_HandlerForVerifyDiskSectors ; 04h, Verify Disk Sectors (All)
[260]398%ifdef MODULE_SERIAL_FLOPPY
[417]399 dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA)
[260]400%else
[417]401 dw UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA)
[260]402%endif
[417]403 dw UnsupportedFunction ; 06h, Format Disk Track with Bad Sectors (XT)
404 dw UnsupportedFunction ; 07h, Format Multiple Cylinders (XT)
405 dw AH8h_HandlerForReadDiskDriveParameters ; 08h, Read Disk Drive Parameters (All)
406 dw AH9h_HandlerForInitializeDriveParameters ; 09h, Initialize Drive Parameters (All)
407 dw UnsupportedFunction ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
408 dw UnsupportedFunction ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
409 dw AHCh_HandlerForSeek ; 0Ch, Seek (All)
[507]410 dw AH9h_HandlerForInitializeDriveParameters ; 0Dh, Alternate Disk Reset (All)
[417]411 dw UnsupportedFunction ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
412 dw UnsupportedFunction ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
413 dw AH10h_HandlerForCheckDriveReady ; 10h, Check Drive Ready (All)
414 dw AH11h_HandlerForRecalibrate ; 11h, Recalibrate (All)
415 dw UnsupportedFunction ; 12h, Controller RAM Diagnostic (XT)
416 dw UnsupportedFunction ; 13h, Drive Diagnostic (XT)
[540]417 dw AH10h_HandlerForCheckDriveReady ; 14h, Controller Internal Diagnostic (All)
[417]418 dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+)
419 dw UnsupportedFunction ; 16h,
420 dw UnsupportedFunction ; 17h,
421 dw UnsupportedFunction ; 18h,
422 dw UnsupportedFunction ; 19h, Park Heads (PS/2)
423 dw UnsupportedFunction ; 1Ah, Format ESDI Drive (PS/2)
424 dw UnsupportedFunction ; 1Bh, Get ESDI Manufacturing Header (PS/2)
425 dw UnsupportedFunction ; 1Ch, ESDI Special Functions (PS/2)
426 dw UnsupportedFunction ; 1Dh,
[493]427%ifdef MODULE_8BIT_IDE_ADVANCED
[471]428 dw AH1Eh_HandlerForXTCFfeatures ; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
429%else
[525]430 dw UnsupportedFunction ; 1Eh,
[471]431%endif
[417]432 dw UnsupportedFunction ; 1Fh,
433 dw UnsupportedFunction ; 20h,
434 dw UnsupportedFunction ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
435 dw UnsupportedFunction ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
436 dw AH23h_HandlerForSetControllerFeatures ; 23h, Set Controller Features Register (PS/1)
437 dw AH24h_HandlerForSetMultipleBlocks ; 24h, Set Multiple Blocks (PS/1)
438 dw AH25h_HandlerForGetDriveInformation ; 25h, Get Drive Information (PS/1)
[165]439
[176]440%ifdef MODULE_EBIOS
[165]441g_rgwEbiosFunctionJumpTable:
[417]442 dw AH41h_HandlerForCheckIfExtensionsPresent ; 41h, Check if Extensions Present (EBIOS)*
443 dw AH42h_HandlerForExtendedReadSectors ; 42h, Extended Read Sectors (EBIOS)*
444 dw AH43h_HandlerForExtendedWriteSectors ; 43h, Extended Write Sectors (EBIOS)*
445 dw AH44h_HandlerForExtendedVerifySectors ; 44h, Extended Verify Sectors (EBIOS)*
446 dw UnsupportedFunction ; 45h, Lock and Unlock Drive (EBIOS)***
447 dw UnsupportedFunction ; 46h, Eject Media Request (EBIOS)***
448 dw AH47h_HandlerForExtendedSeek ; 47h, Extended Seek (EBIOS)*
449 dw AH48h_HandlerForGetExtendedDriveParameters ; 48h, Get Extended Drive Parameters (EBIOS)*
450; dw UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)***
451; dw UnsupportedFunction ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
452; dw UnsupportedFunction ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
453; dw UnsupportedFunction ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
454; dw UnsupportedFunction ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
455; dw UnsupportedFunction ; 4Eh, Set Hardware Configuration (EBIOS)**
[150]456;
457; * = Enhanced Drive Access Support (minimum required EBIOS functions)
458; ** = Enhanced Disk Drive (EDD) Support
459; *** = Drive Locking and Ejecting Support
[181]460%endif
Note: See TracBrowser for help on using the repository browser.