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

Last change on this file since 27 was 27, checked in by Tomi Tilli, 14 years ago
  • v1.1.1 broke booting from foreign drives, it is now fixed.
  • Fixed a bug where Disk Parameter Table was accessed with wrong pointer register after writing last block.
  • Cleaned AH=00h, Disk Controller Reset a bit.
  • Timeout errors might now get translated for better error codes on certain situations.
File size: 3.8 KB
Line 
1; File name : AHDh_HReset.asm
2; Project name : IDE BIOS
3; Created date : 9.12.2007
4; Last update : 28.7.2010
5; Author : Tomi Tilli
6; Description : Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
13;
14; AHDh_HandlerForResetHardDisk
15; Parameters:
16; AH: Bios function Dh
17; DL: Drive number
18; Returns:
19; AH: Int 13h return status
20; CF: 0 if succesfull, 1 if error
21; IF: 1
22; Corrupts registers:
23; Flags
24;--------------------------------------------------------------------
25ALIGN JUMP_ALIGN
26AHDh_HandlerForResetHardDisk:
27 call AHDh_ResetDrive
28 jmp Int13h_PopDiDsAndReturn
29
30
31;--------------------------------------------------------------------
32; Resets hard disk.
33;
34; AHDh_ResetDrive
35; Parameters:
36; DL: Drive number
37; DS: RAMVARS segment
38; Returns:
39; AH: Int 13h return status
40; CF: 0 if succesfull, 1 if error
41; Corrupts registers:
42; DI
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45AHDh_ResetDrive:
46 push dx
47 push cx
48 push bx
49 push ax
50
51 call FindDPT_ForDriveNumber ; DS:DI now points to DPT
52 call AHDh_ResetMasterAndSlave
53 ;jc SHORT .ReturnError ; CF would be set if slave drive present without master
54 ; (error register has special values after reset)
55
56 ; Initialize Master and Slave drives
57 mov dx, [RAMVARS.wIdeBase] ; Load base port address
58 call AHDh_InitializeMasterAndSlave
59
60 pop bx ; Pop old AX
61 mov al, bl ; Restore AL
62 pop bx
63 pop cx
64 pop dx
65 ret
66
67
68;--------------------------------------------------------------------
69; Resets Master and Slave drives at wanted port.
70; Both IDE drives will be reset. It is not possible to reset
71; Master or Slave only.
72;
73; AHDh_ResetMasterAndSlave
74; Parameters:
75; DS:DI: Ptr to DPT for Master or Slave drive
76; Returns:
77; CF: 0 if reset succesfull
78; 1 if any error
79; Corrupts registers:
80; AX, BX, CX, DX
81;--------------------------------------------------------------------
82ALIGN JUMP_ALIGN
83AHDh_ResetMasterAndSlave:
84 ; Reset controller
85 ; HSR0: Set_SRST
86 mov al, [di+DPT.bDrvCtrl] ; Load value for ACR
87 or al, FLG_IDE_CTRL_SRST ; Set Reset bit
88 call HDrvSel_OutputDeviceControlByte
89 mov cx, 5 ; Delay at least 5us
90 call SoftDelay_us
91
92 ; HSR1: Clear_wait
93 and al, ~FLG_IDE_CTRL_SRST ; Clear Reset bit
94 out dx, al ; End Reset
95 mov cx, 2000 ; Delay at least 2ms
96 call SoftDelay_us
97
98 ; HSR2: Check_status
99 mov cl, B_TIMEOUT_RESET ; Reset timeout delay
100 mov dx, [RAMVARS.wIdeBase] ; Load base port address
101 jmp HStatus_WaitBsyBase
102
103
104;--------------------------------------------------------------------
105; Initializes Master and Slave drive.
106;
107; AHDh_InitializeMasterAndSlave
108; Parameters:
109; DX: IDE Base Port address
110; Returns:
111; AH: Error code
112; CF: 0 if initialization succesfull
113; 1 if any error
114; Corrupts registers:
115; AL, BX, CX, DX, DI
116;--------------------------------------------------------------------
117ALIGN JUMP_ALIGN
118AHDh_InitializeMasterAndSlave:
119 push dx ; Store base port address
120 xor cx, cx ; Assume no errors
121 call FindDPT_ForIdeMasterAtPort
122 jnc SHORT .InitializeSlave ; Master drive not present
123 call AH9h_InitializeDriveForUse
124 mov cl, ah ; Copy error code to CL
125ALIGN JUMP_ALIGN
126.InitializeSlave:
127 pop dx ; Restore base port address
128 call FindDPT_ForIdeSlaveAtPort
129 jnc SHORT .CombineErrors ; Slave drive not present
130 call AH9h_InitializeDriveForUse
131 mov ch, ah ; Copy error code to CH
132ALIGN JUMP_ALIGN
133.CombineErrors:
134 or cl, ch ; OR error codes, clear CF
135 jnz SHORT .ReturnError
136 ret
137.ReturnError:
138 mov ah, RET_HD_RESETFAIL ; Load Reset Failed error code
139 stc
140 ret
Note: See TracBrowser for help on using the repository browser.