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

Last change on this file since 369 was 369, checked in by gregli@…, 12 years ago

Removed align directives for initalization code and added define for align in boot-time calls to the assembly library (defaulting to 1), resulting in a significant savings for the AT and 386 builds. Fixed a bug with switch command line handling in the serial server. Put in CR characters in licesnse.txt, so that it properly displays on Windows. In the configurator, added default values for user supplied CHS and LBA values, defaulting to values within range when those features are enabled. Updated the copyright message in the configurator as the literal word Copyright is important.

File size: 4.4 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 IDEPACK
15;   Returns with INTPACK:
16;       AH:     Int 13h return status
17;       CF:     0 if successful, 1 if error
18;--------------------------------------------------------------------
19AHDh_HandlerForResetHardDisk:
20%ifndef USE_186
21    call    AHDh_ResetDrive
22    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
23%else
24    push    Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
25    ; Fall to AHDh_ResetDrive
26%endif
27
28
29;--------------------------------------------------------------------
30; Resets hard disk.
31;
32; AHDh_ResetDrive
33;   Parameters:
34;       DS:DI:  Ptr to DPT
35;       SS:BP:  Ptr to IDEPACK
36;   Returns:
37;       AH:     Int 13h return status
38;       CF:     0 if successful, 1 if error
39;   Corrupts registers:
40;       AL, SI
41;--------------------------------------------------------------------
42AHDh_ResetDrive:
43    push    dx
44    push    cx
45    push    bx
46    push    di
47
48    call    Interrupts_UnmaskInterruptControllerForDriveInDSDI
49    call    Device_ResetMasterAndSlaveController
50    ;jc     SHORT .ReturnError                  ; CF would be set if slave drive present without master
51                                                ; (error register has special values after reset)
52
53    ; Initialize Master and Slave drives
54    eMOVZX  ax, BYTE [di+DPT.bIdevarsOffset]    ; (AL) pointer to controller we are looking to reset
55                                                ; (AH) initialize error code, assume success
56
57    mov     si, IterateAndResetDrives           ; Callback function for FindDPT_IterateAllDPTs
58    call    FindDPT_IterateAllDPTs
59
60    shr     ah, 1                               ; Move error code and CF into proper position
61
62    pop     di
63    pop     bx
64    pop     cx
65    pop     dx
66    ret
67
68;--------------------------------------------------------------------
69; IterateAndResetDrives: Iteration routine for use with IterateAllDPTs.
70;
71; When a drive on the controller is found, it is reset, and the error code
72; merged into overall error code for this controller.  Master will be reset
73; first.  Note that the iteration will go until the end of the DPT list.
74;
75;   Parameters:
76;       AL:     Offset to IDEVARS for drives to initialize
77;       AH:     Error status from previous initialization
78;       DS:DI:  Ptr to DPT to examine
79;   Returns:
80;       AH:     Error status from initialization
81;       CF:     Set to iterate all DPTs
82;   Corrupts registers:
83;       AL, BX, DX
84;--------------------------------------------------------------------
85IterateAndResetDrives:
86    cmp     al, [di+DPT.bIdevarsOffset]         ; The right controller?
87    jne     .done
88    push    ax
89    push    cx
90    call    AH9h_InitializeDriveForUse          ; Reset Master and Slave (Master will come first in DPT list)
91
92%ifdef MODULE_ADVANCED_ATA
93    jc      SHORT .SkipControllerInitSinceError
94    call    InitializeAdvancedIdeControllers    ; Done after drive init so drives are first set to advanced PIO mode, then the controller
95.SkipControllerInitSinceError:
96%endif
97
98    pop     cx
99    pop     ax
100    jnc     .done
101    or      ah, (RET_HD_RESETFAIL << 1) | 1     ; OR in Reset Failed error code and CF, will SHR into position later
102.done:
103    stc                                         ; From IterateAllDPTs perspective, the DPT is never found (continue iteration)
104    ret
105
106
107%ifdef MODULE_ADVANCED_ATA
108;--------------------------------------------------------------------
109; Here we initialize the more advanced controllers (VLB and PCI)
110; to get better performance for systems with 32-bit bus.
111;
112; This step is optional since the controllers use slowest possible
113; settings by default if they are not initialized.
114;
115; InitializeAdvancedIdeController
116;   Parameters:
117;       DS:DI:  Ptr to DPT
118;   Returns:
119;       CF:     Cleared if success or no controller to initialize
120;               Set if error
121;   Corrupts registers:
122;       AX, BX, CX, DX
123;--------------------------------------------------------------------
124InitializeAdvancedIdeControllers:
125    ; We want to initialize the advanced controller only after both
126    ; Master and Slave drive are initialized to correct PIO mode.
127    ; We check if next DPT is for the same IDE controller. If it is,
128    ; we skip the initialization.
129    mov     al, [di+DPT.bIdevarsOffset]
130    cmp     al, [di++LARGEST_DPT_SIZE+DPT.bIdevarsOffset]
131    je      SHORT .SkipInitializationUntilNextDrive ; CF cleared
132
133    jmp     AdvAtaInit_InitializeControllerForDPTinDSDI
134.SkipInitializationUntilNextDrive:
135    clc
136    ret
137
138%endif  ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.