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

Last change on this file since 87 was 84, checked in by krille_n_@…, 14 years ago

Minor size optimizations in various files.

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