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

Last change on this file since 47 was 35, checked in by Tomi Tilli, 14 years ago

Cleaned recent changes a bit to save few bytes.

File size: 3.9 KB
Line 
1; File name : AHDh_HReset.asm
2; Project name : IDE BIOS
3; Created date : 9.12.2007
4; Last update : 24.8.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 Interrupts_UnmaskInterruptControllerForDriveInDSDI
53 call AHDh_ResetMasterAndSlave
54 ;jc SHORT .ReturnError ; CF would be set if slave drive present without master
55 ; (error register has special values after reset)
56
57 ; Initialize Master and Slave drives
58 mov dx, [RAMVARS.wIdeBase] ; Load base port address
59 call AHDh_InitializeMasterAndSlave
60
61 pop bx ; Pop old AX
62 mov al, bl ; Restore AL
63 pop bx
64 pop cx
65 pop dx
66 ret
67
68
69;--------------------------------------------------------------------
70; Resets Master and Slave drives at wanted port.
71; Both IDE drives will be reset. It is not possible to reset
72; Master or Slave only.
73;
74; AHDh_ResetMasterAndSlave
75; Parameters:
76; DS:DI: Ptr to DPT for Master or Slave drive
77; Returns:
78; CF: 0 if reset succesfull
79; 1 if any error
80; Corrupts registers:
81; AX, BX, CX, DX
82;--------------------------------------------------------------------
83ALIGN JUMP_ALIGN
84AHDh_ResetMasterAndSlave:
85 ; Reset controller
86 ; HSR0: Set_SRST
87 mov al, [di+DPT.bDrvCtrl] ; Load value for ACR
88 or al, FLG_IDE_CTRL_SRST ; Set Reset bit
89 call HDrvSel_OutputDeviceControlByte
90 mov cx, 5 ; Delay at least 5us
91 call SoftDelay_us
92
93 ; HSR1: Clear_wait
94 and al, ~FLG_IDE_CTRL_SRST ; Clear Reset bit
95 out dx, al ; End Reset
96 mov cx, 2000 ; Delay at least 2ms
97 call SoftDelay_us
98
99 ; HSR2: Check_status
100 mov cl, B_TIMEOUT_RESET ; Reset timeout delay
101 mov dx, [RAMVARS.wIdeBase] ; Load base port address
102 jmp HStatus_WaitBsyBase
103
104
105;--------------------------------------------------------------------
106; Initializes Master and Slave drive.
107;
108; AHDh_InitializeMasterAndSlave
109; Parameters:
110; DX: IDE Base Port address
111; Returns:
112; AH: Error code
113; CF: 0 if initialization succesfull
114; 1 if any error
115; Corrupts registers:
116; AL, BX, CX, DX, DI
117;--------------------------------------------------------------------
118ALIGN JUMP_ALIGN
119AHDh_InitializeMasterAndSlave:
120 push dx ; Store base port address
121 xor cx, cx ; Assume no errors
122 call FindDPT_ForIdeMasterAtPort
123 jnc SHORT .InitializeSlave ; Master drive not present
124 call AH9h_InitializeDriveForUse
125 mov cl, ah ; Copy error code to CL
126ALIGN JUMP_ALIGN
127.InitializeSlave:
128 pop dx ; Restore base port address
129 call FindDPT_ForIdeSlaveAtPort
130 jnc SHORT .CombineErrors ; Slave drive not present
131 call AH9h_InitializeDriveForUse
132 mov ch, ah ; Copy error code to CH
133ALIGN JUMP_ALIGN
134.CombineErrors:
135 or cl, ch ; OR error codes, clear CF
136 jnz SHORT .ReturnError
137 ret
138.ReturnError:
139 mov ah, RET_HD_RESETFAIL ; Load Reset Failed error code
140 stc
141 ret
Note: See TracBrowser for help on using the repository browser.