source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm @ 32

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

Correct number of drives is now returned from AH=08h even when it is redirected to foreign BIOS.

File size: 6.7 KB
RevLine 
[3]1; File name     :   RamVars.asm
2; Project name  :   IDE BIOS
3; Created date  :   14.3.2010
[32]4; Last update   :   3.8.2010
[3]5; Author        :   Tomi Tilli
6; Description   :   Functions for accessings RAMVARS.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Initializes RAMVARS.
13; Drive detection can be started after this function returns.
14;
15; RamVars_Initialize
16;   Parameters:
17;       Nothing
18;   Returns:
19;       Nothing
20;   Corrupts registers:
21;       AX, CX, DI, DS, ES
22;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24RamVars_Initialize:
25    call    RamVars_StealBaseMemory ; Get RAMVARS segment to DS even if no stealing
26    call    RamVars_ClearToZero
27    jmp     DriveXlate_Reset
28
29
30;--------------------------------------------------------------------
31; Steals base memory to be used for RAMVARS.
32;
33; RamVars_StealBaseMemory
34;   Parameters:
35;       Nothing
36;   Returns:
37;       DS:     RAMVARS segment
38;   Corrupts registers:
39;       AX
40;--------------------------------------------------------------------
41ALIGN JUMP_ALIGN
42RamVars_StealBaseMemory:
43    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
44    jz      SHORT RamVars_GetSegmentToDS    ; No need to steal
45
46    LOAD_BDA_SEGMENT_TO ds, ax              ; Zero AX
47    mov     al, [cs:ROMVARS.bStealSize]
48    sub     [BDA.wBaseMem], ax              ; Steal one or more kilobytes
49    mov     ax, [BDA.wBaseMem]              ; Load base memory left
50    eSHL_IM ax, 6                           ; Shift for segment address
51    mov     ds, ax                          ; Copy RAMVARS segment to DS
52    ret
53
54
55;--------------------------------------------------------------------
56; Returns segment to RAMVARS.
57; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
58; or at the top of system base RAM.
59;
60; RamVars_GetSegmentToDS
61;   Parameters:
62;       Nothing
63;   Returns:
64;       DS:     RAMVARS segment
65;   Corrupts registers:
66;       DI
67;--------------------------------------------------------------------
68ALIGN JUMP_ALIGN
69RamVars_GetSegmentToDS:
70    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
71    jnz     SHORT RamVars_GetStolenSegmentToDS
72    mov     di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
73    mov     ds, di
74    ret
75
76ALIGN JUMP_ALIGN
77RamVars_GetStolenSegmentToDS:
78    LOAD_BDA_SEGMENT_TO ds, di
79    mov     di, [BDA.wBaseMem]      ; Load available base memory size in kB
80    eSHL_IM di, 6                   ; Segment to first stolen kB
81ALIGN JUMP_ALIGN
82.LoopStolenKBs:
83    mov     ds, di                  ; EBDA segment to DS
84    add     di, BYTE 64             ; DI to next stolen kB
85    cmp     WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
86    jne     SHORT .LoopStolenKBs    ; Loop until sign found (always found eventually)
87    ret
88
89
90;--------------------------------------------------------------------
91; Clears RAMVARS variables to zero.
92; FULLRAMVARS sign will be saved if available.
93;
94; RamVars_ClearToZero
95;   Parameters:
96;       DS:     RAMVARS segment
97;   Returns:
98;       Nothing
99;   Corrupts registers:
100;       AX, CX, DI, ES
101;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103RamVars_ClearToZero:
104    call    FindDPT_PointToFirstDPT ; Get RAMVARS/FULLRAMVARS size to DI
105    mov     cx, di                  ; Copy byte count to CX
106    push    ds
107    pop     es
108    xor     di, di                  ; ES:DI now points to RAMVARS/FULLRAMVARS
109    xor     ax, ax                  ; Store zeroes
110    rep stosb
111    mov     WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
112    ret
113
114
115;--------------------------------------------------------------------
116; Checks if INT 13h function is handled by this BIOS.
117;
118; RamVars_IsFunctionHandledByThisBIOS
119;   Parameters:
120;       AH:     INT 13h function number
121;       DL:     Drive number
122;       DS:     RAMVARS segment
123;   Returns:
124;       CF:     Set if function is handled by this BIOS
125;               Cleared if function belongs to some other BIOS
126;   Corrupts registers:
127;       DI
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130RamVars_IsFunctionHandledByThisBIOS:
131    test    ah, ah          ; Reset for all floppy and hard disk drives?
[32]132    jz      SHORT .FunctionIsHandledByOurBIOS
133    cmp     ah, 08h         ; Read Disk Drive Parameters?
134    jne     SHORT RamVars_IsDriveHandledByThisBIOS
135    test    dl, 80h         ; We dot not handle floppy drives
136    jz      SHORT .FunctionIsNotHandledByOurBIOS
137ALIGN JUMP_ALIGN
138.FunctionIsHandledByOurBIOS:
[3]139    stc
[32]140.FunctionIsNotHandledByOurBIOS:
[3]141    ret
142
143;--------------------------------------------------------------------
144; Checks if drive is handled by this BIOS.
145;
146; RamVars_IsDriveHandledByThisBIOS
147;   Parameters:
148;       DL:     Drive number
149;       DS:     RAMVARS segment
150;   Returns:
151;       CF:     Set if drive is handled by this BIOS
152;               Cleared if drive belongs to some other BIOS
153;   Corrupts registers:
154;       DI
155;--------------------------------------------------------------------
156ALIGN JUMP_ALIGN
157RamVars_IsDriveHandledByThisBIOS:
158    xchg    di, ax                              ; Backup AX
159    mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AL, First number to AH
160    add     al, ah                              ; One past last drive to AL
161    cmp     dl, al                              ; Above last supported?
162    jae     SHORT .DriveNotHandledByThisBIOS
163    cmp     dl, ah                              ; Below first supported?
164    jb      SHORT .DriveNotHandledByThisBIOS
165    xchg    ax, di
166    stc
167    ret
168ALIGN JUMP_ALIGN
169.DriveNotHandledByThisBIOS:
170    xchg    ax, di
171    clc
172    ret
173
174
175;--------------------------------------------------------------------
176; Increments hard disk count to RAMVARS.
177;
178; RamVars_IncrementHardDiskCount
179;   Parameters:
180;       DL:     Drive number for new drive
181;       DS:     RAMVARS segment
182;   Returns:
183;       Nothing
184;   Corrupts registers:
185;       Nothing
186;--------------------------------------------------------------------
187ALIGN JUMP_ALIGN
188RamVars_IncrementHardDiskCount:
189    inc     BYTE [RAMVARS.bDrvCnt]      ; Increment drive count to RAMVARS
190    cmp     BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
191    ja      SHORT .Return               ;  If so, return
192    mov     [RAMVARS.bFirstDrv], dl     ; Store first drive number
193ALIGN JUMP_ALIGN
194.Return:
195    ret
196
197
198;--------------------------------------------------------------------
[32]199; RamVars_GetHardDiskCountFromBDAtoCX
[3]200;   Parameters:
201;       DS:     RAMVARS segment
202;   Returns:
[32]203;       CX:     Total hard disk count
[3]204;   Corrupts registers:
[32]205;       Nothing
206;--------------------------------------------------------------------   
[3]207ALIGN JUMP_ALIGN
[32]208RamVars_GetHardDiskCountFromBDAtoCX:
[3]209    push    es
[32]210    push    dx
211
[3]212    LOAD_BDA_SEGMENT_TO es, cx          ; Zero CX
[32]213    call    RamVars_GetCountOfKnownDrivesToDL
214    MAX_U   dl, [es:BDA.bHDCount]
215    mov     cl, dl
216
217    pop     dx
[3]218    pop     es
219    ret
[32]220
221;--------------------------------------------------------------------
222; RamVars_GetCountOfKnownDrivesToDL
223;   Parameters:
224;       DS:     RAMVARS segment
225;   Returns:
226;       DL:     Total hard disk count
227;   Corrupts registers:
228;       Nothing
229;--------------------------------------------------------------------   
230ALIGN JUMP_ALIGN
231RamVars_GetCountOfKnownDrivesToDL:
232    mov     dl, [RAMVARS.bFirstDrv]     ; Number for our first drive
233    add     dl, [RAMVARS.bDrvCnt]       ; Our drives
234    and     dl, 7Fh                     ; Clear HD bit for drive count
235    ret
Note: See TracBrowser for help on using the repository browser.