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

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

Changes to XTIDE Universal BIOS:

  • Large changes to prepare full XT-CF support (DMA not yet implemented and memory mapped transfers are not working).
File size: 5.3 KB
RevLine 
[88]1; Project name : XTIDE Universal BIOS
[3]2; Description : Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
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
16; GNU General Public License for more details.
[445]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
[376]19
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
25;
26; AHDh_HandlerForResetHardDisk
27; Parameters:
[148]28; DL: Translated Drive number
29; DS:DI: Ptr to DPT (in RAMVARS segment)
[150]30; SS:BP: Ptr to IDEPACK
31; Returns with INTPACK:
[3]32; AH: Int 13h return status
[294]33; CF: 0 if successful, 1 if error
[3]34;--------------------------------------------------------------------
35AHDh_HandlerForResetHardDisk:
[84]36%ifndef USE_186
[3]37 call AHDh_ResetDrive
[148]38 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[84]39%else
[148]40 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[162]41 ; Fall to AHDh_ResetDrive
[84]42%endif
[3]43
44
45;--------------------------------------------------------------------
46; Resets hard disk.
47;
48; AHDh_ResetDrive
49; Parameters:
[271]50; DS:DI: Ptr to DPT
[150]51; SS:BP: Ptr to IDEPACK
[3]52; Returns:
53; AH: Int 13h return status
[294]54; CF: 0 if successful, 1 if error
[3]55; Corrupts registers:
[271]56; AL, SI
[3]57;--------------------------------------------------------------------
58AHDh_ResetDrive:
[26]59 push dx
[271]60 push cx
[26]61 push bx
[262]62 push di
[26]63
[398]64%ifdef MODULE_IRQ
[33]65 call Interrupts_UnmaskInterruptControllerForDriveInDSDI
[398]66%endif
[150]67 call Device_ResetMasterAndSlaveController
[262]68 ;jc SHORT .ReturnError ; CF would be set if slave drive present without master
69 ; (error register has special values after reset)
[3]70
71 ; Initialize Master and Slave drives
[473]72 call AccessDPT_GetIdevarsToCSBX
73 xchg ax, bx ; (AL) pointer to controller we are looking to reset
[294]74 ; (AH) initialize error code, assume success
75
[363]76 mov si, IterateAndResetDrives ; Callback function for FindDPT_IterateAllDPTs
[271]77 call FindDPT_IterateAllDPTs
[26]78
[262]79 shr ah, 1 ; Move error code and CF into proper position
80
81 pop di
[26]82 pop bx
[271]83 pop cx
[26]84 pop dx
[3]85 ret
86
87;--------------------------------------------------------------------
[262]88; IterateAndResetDrives: Iteration routine for use with IterateAllDPTs.
89;
[294]90; When a drive on the controller is found, it is reset, and the error code
[262]91; merged into overall error code for this controller. Master will be reset
92; first. Note that the iteration will go until the end of the DPT list.
[363]93;
94; Parameters:
95; AL: Offset to IDEVARS for drives to initialize
96; AH: Error status from previous initialization
97; DS:DI: Ptr to DPT to examine
98; Returns:
99; AH: Error status from initialization
100; CF: Set to iterate all DPTs
101; Corrupts registers:
102; AL, BX, DX
[3]103;--------------------------------------------------------------------
[262]104IterateAndResetDrives:
105 cmp al, [di+DPT.bIdevarsOffset] ; The right controller?
[370]106 jne .Done
107 push cx
[262]108 push ax
[445]109 call AHDh_WaitUntilDriveMotorHasReachedFullSpeed
[428]110 call AH9h_InitializeDriveForUse ; Initialize Master or Slave (Master will come first in DPT list)
[363]111
112%ifdef MODULE_ADVANCED_ATA
113 jc SHORT .SkipControllerInitSinceError
[370]114 ; Here we initialize the more advanced controllers (VLB and PCI) to get better performance for systems with 32-bit bus.
115 ; This step is optional since the controllers use slowest possible settings by default if they are not initialized.
116
117 pop ax
118 push ax
119 cmp al, [di+LARGEST_DPT_SIZE+DPT.bIdevarsOffset] ; We check if next DPT is for the same IDE controller.
120 je SHORT .SkipInitializationUntilNextDrive ; If it is, we skip the initialization.
121 call AdvAtaInit_InitializeControllerForDPTinDSDI ; Done after drive init so drives are first set to advanced PIO mode, then the controller
122.SkipInitializationUntilNextDrive:
[363]123.SkipControllerInitSinceError:
[370]124%endif ; MODULE_ADVANCED_ATA
[363]125
[370]126 pop ax
[363]127 pop cx
[370]128 jnc .Done
[262]129 or ah, (RET_HD_RESETFAIL << 1) | 1 ; OR in Reset Failed error code and CF, will SHR into position later
[370]130.Done:
[271]131 stc ; From IterateAllDPTs perspective, the DPT is never found (continue iteration)
[3]132 ret
[363]133
[428]134
135;--------------------------------------------------------------------
[445]136; AHDh_WaitUntilDriveMotorHasReachedFullSpeed
[428]137; Parameters:
138; DS:DI: Ptr to DPT
139; Returns:
140; AH: Int 13h return status
141; CF: 0 if successful, 1 if error
142; Corrupts registers:
143; AL, BX, CX, DX
144;--------------------------------------------------------------------
[445]145AHDh_WaitUntilDriveMotorHasReachedFullSpeed:
[428]146%ifdef MODULE_SERIAL
147 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
148 jz SHORT .WaitSinceRealHardDisk
149 ret
150.WaitSinceRealHardDisk:
151%endif
152
[429]153 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_DRDY)
[428]154 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
Note: See TracBrowser for help on using the repository browser.