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

Last change on this file since 26 was 26, checked in by aitotat, 14 years ago

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

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   :   26.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;       Nothing
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45AHDh_ResetDrive:
46    push    di
47    push    dx
48    push    cx
49    push    bx
50    push    ax
51
52    call    FindDPT_ForDriveNumber      ; DS:DI now points to DPT
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    pop     di
67    ret
68
69
70;--------------------------------------------------------------------
71; Resets Master and Slave drives at wanted port.
72; Both IDE drives will be reset. It is not possible to reset
73; Master or Slave only.
74;
75; AHDh_ResetMasterAndSlave
76;   Parameters:
77;       DS:DI:  Ptr to DPT for Master or Slave drive
78;   Returns:
79;       CF:     0 if reset succesfull
80;               1 if any error
81;   Corrupts registers:
82;       AX, BX, CX, DX
83;--------------------------------------------------------------------
84ALIGN JUMP_ALIGN
85AHDh_ResetMasterAndSlave:
86    ; Reset controller
87    ; HSR0: Set_SRST
88    mov     al, [di+DPT.bDrvCtrl]       ; Load value for ACR
89    or      al, FLG_IDE_CTRL_SRST       ; Set Reset bit
90    call    HDrvSel_OutputDeviceControlByte
91    mov     cx, 5                       ; Delay at least 5us
92    call    SoftDelay_us
93
94    ; HSR1: Clear_wait
95    and     al, ~FLG_IDE_CTRL_SRST      ; Clear Reset bit
96    out     dx, al                      ; End Reset
97    mov     cx, 2000                    ; Delay at least 2ms
98    call    SoftDelay_us
99
100    ; HSR2: Check_status
101    mov     cl, B_TIMEOUT_RESET         ; Reset timeout delay
102    mov     dx, [RAMVARS.wIdeBase]      ; Load base port address
103    jmp     HStatus_WaitBsyBase
104
105
106;--------------------------------------------------------------------
107; Initializes Master and Slave drive.
108;
109; AHDh_InitializeMasterAndSlave
110;   Parameters:
111;       DX:     IDE Base Port address
112;   Returns:
113;       AH:     Error code
114;       CF:     0 if initialization succesfull
115;               1 if any error
116;   Corrupts registers:
117;       AL, BX, CX, DX, DI
118;--------------------------------------------------------------------
119ALIGN JUMP_ALIGN
120AHDh_InitializeMasterAndSlave:
121    push    dx                          ; Store base port address
122    xor     cx, cx                      ; Assume no errors
123    call    FindDPT_ForIdeMasterAtPort
124    jnc     SHORT .InitializeSlave      ; Master drive not present
125    call    AH9h_InitializeDriveForUse
126    mov     cl, ah                      ; Copy error code to CL
127ALIGN JUMP_ALIGN
128.InitializeSlave:
129    pop     dx                          ; Restore base port address
130    call    FindDPT_ForIdeSlaveAtPort
131    jnc     SHORT .CombineErrors        ; Slave drive not present
132    call    AH9h_InitializeDriveForUse
133    mov     ch, ah                      ; Copy error code to CH
134ALIGN JUMP_ALIGN
135.CombineErrors:
136    or      cl, ch                      ; OR error codes, clear CF
137    jnz     SHORT .ReturnError
138    ret
139.ReturnError:
140    mov     ah, RET_HD_RESETFAIL        ; Load Reset Failed error code
141    stc
142    ret
Note: See TracBrowser for help on using the repository browser.