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

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

Changes to XTIDE Universal BIOS:

  • Even quicker optimization to previous fix.
File size: 7.0 KB
RevLine 
[128]1; Project name : XTIDE Universal BIOS
[3]2; Description : Int 13h function AH=0h, Disk Controller Reset.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h function AH=0h, Disk Controller Reset.
25;
[271]26; Note: We handle all AH=0h calls, even for drives handled by other
27; BIOSes!
28;
[3]29; AH0h_HandlerForDiskControllerReset
30; Parameters:
[148]31; DL: Translated Drive number (ignored so all drives are reset)
[3]32; If bit 7 is set all hard disks and floppy disks reset.
[275]33; DS:DI: Ptr to DPT (or Null if foreign drive)
[150]34; SS:BP: Ptr to IDEPACK
35; Returns with INTPACK:
[23]36; AH: Int 13h return status (from drive requested in DL)
[294]37; CF: 0 if successful, 1 if error
[3]38;--------------------------------------------------------------------
39AH0h_HandlerForDiskControllerReset:
[433]40 ; Reset Floppy Drives with INT 40h
41 xor bx, bx ; Zero BH to assume no errors
42 or bl, dl ; Copy requested drive to BL
[434]43 eCMOVS dl, bh ; Reset Floppy Drive(s) with 00h since DL has Hard Drive number
[259]44
[433]45 xor ah, ah ; Disk Controller Reset
46 int BIOS_DISKETTE_INTERRUPT_40h
47 call BackupErrorCodeFromTheRequestedDriveToBH
48 ; We do not reset Hard Drives if DL was 0xh on entry
49
50
[259]51%ifdef MODULE_SERIAL_FLOPPY
52;
[294]53; "Reset" emulated serial floppy drives, if any. There is nothing to actually do for this reset,
[259]54; but record the proper error return code if one of these floppy drives is the drive requested.
55;
56 call RamVars_UnpackFlopCntAndFirstToAL
57 cbw ; Clears AH (there are flop drives) or ffh (there are not)
58 ; Either AH has success code (flop drives are present)
59 ; or it doesn't matter because we won't match drive ffh
60
61 cwd ; clears DX (there are flop drives) or ffffh (there are not)
62
63 adc dl, al ; second drive (CF set) if present
[294]64 ; If no drive is present, this will result in ffh which
[259]65 ; won't match a drive
66 call BackupErrorCodeFromTheRequestedDriveToBH
67 mov dl, al ; We may end up doing the first drive twice (if there is
68 call BackupErrorCodeFromTheRequestedDriveToBH ; only one drive), but doing it again is not harmful.
69%endif
70
[433]71 ; Reset foreign Hard Drives (those handled by other BIOSes)
[259]72 test bl, bl ; If we were called with a floppy disk, then we are done,
73 jns SHORT .SkipHardDiskReset ; don't do hard disks.
[26]74 call ResetForeignHardDisks
[264]75
[294]76 ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based,
[275]77 ; such that this call must be the last in the list of reset routines called.
78 ;
[282]79 ; This needs to happen after ResetForeignHardDisks, as that call may have set the error code for 80h,
80 ; and we need to override that value if we are xlate'd into 80h with one of our drives.
81 ;
[294]82 call ResetHardDisksHandledByOurBIOS
[264]83
[26]84.SkipHardDiskReset:
[148]85 mov ah, bh
86 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[3]87
88
89;--------------------------------------------------------------------
[26]90; ResetForeignHardDisks
[23]91; Parameters:
[434]92; BL: Requested Hard Drive (DL when entering AH=00h)
[3]93; DS: RAMVARS segment
94; Returns:
[23]95; BH: Error code from requested drive (if available)
[3]96; Corrupts registers:
[433]97; AX, DL
[128]98;--------------------------------------------------------------------
[26]99ResetForeignHardDisks:
[433]100 ; If there are drives after our drives, those are already reset
101 ; since our INT 13h was called by some other BIOS.
102 ; We only need to reset drives from the previous INT 13h handler.
103 ; There could be more in chain but let the previous one handle them.
[435]104 mov dl, [RAMVARS.bFirstDrv]
105 or dl, 80h ; We may not have our drives at all!
106 MIN_U dl, bl ; BL is always Hard Drive number
[433]107
108 xor ah, ah ; Disk Controller Reset
[32]109 call Int13h_CallPreviousInt13hHandler
[258]110;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
[23]111
[26]112
[3]113;--------------------------------------------------------------------
[258]114; BackupErrorCodeFromTheRequestedDriveToBH
115; Parameters:
116; AH: Error code from the last resetted drive
117; DL: Drive last resetted
118; BL: Requested drive (DL when entering AH=00h)
119; Returns:
120; BH: Backuped error code
121; Corrupts registers:
122; Nothing
123;--------------------------------------------------------------------
124BackupErrorCodeFromTheRequestedDriveToBH:
125 cmp dl, bl ; Requested drive?
126 eCMOVE bh, ah
127 ret
128
[271]129
[27]130
[433]131; This defines what is called when resetting our drives at the end of drive detection.
[275]132AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed
[27]133
134;--------------------------------------------------------------------
[271]135; ResetHardDisksHandledByOurBIOS
136; Parameters:
137; DS:DI: Ptr to DPT for requested drive
[294]138; If DPT pointer is not available, or error result in BH won't be used anyway,
[282]139; enter through .ErrorCodeNotUsed.
[271]140; SS:BP: Ptr to IDEPACK
141; Returns:
[23]142; BH: Error code from requested drive (if available)
143; Corrupts registers:
[275]144; AX, BX, CX, DX, SI, DI
[23]145;--------------------------------------------------------------------
[271]146ResetHardDisksHandledByOurBIOS:
[294]147 xor bl, bl ; Assume Null IdevarsOffset for now, assuming foreign drive
[282]148 test di, di
[433]149 jz SHORT .ErrorCodeNotUsed
[264]150 mov bl, [di+DPT.bIdevarsOffset] ; replace drive number with Idevars pointer for cmp with dl
[294]151
152.ErrorCodeNotUsed: ; BH will be garbage on exit if this entry point is used,
[275]153 ; but reset of all drives will still happen
154
[264]155 mov dl, ROMVARS.ideVars0 ; starting Idevars offset
156
[316]157 ; Get count of ALL Idevars structures, not just the ones that are configured. This may seem odd,
158 ; but it catches the .ideVarsSerialAuto structure, which would not be scanned if the count from
159 ; RamVars_GetIdeControllerCountToCX was used. Unused controllers won't make a difference, since no DPT
160 ; will point to them. Performance isn't an issue, as this is a reset operation.
161 ;
162 mov cx, (ROMVARS.ideVarsEnd - ROMVARS.ideVarsBegin) / IDEVARS_size
163
[262]164.loop:
[271]165 call FindDPT_ForIdevarsOffsetInDL ; look for the first drive on this controller, if any
[433]166 jc SHORT .notFound
[264]167
[262]168 call AHDh_ResetDrive ; reset master and slave on that controller
[264]169 call BackupErrorCodeFromTheRequestedDriveToBH ; save error code if same controller as drive from entry
170
[262]171.notFound:
[264]172 add dl, IDEVARS_size ; move Idevars pointer forward
173 loop .loop
174
175.done:
[433]176NoForeignDrivesToReset:
[259]177 ret
Note: See TracBrowser for help on using the repository browser.