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

Last change on this file since 148 was 148, checked in by aitotat, 13 years ago

Changes to XTIDE Universal BIOS:

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