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

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

Changes to XTIDE Universal BIOS:

  • AH=4h again uses VERIFY command (copy-pasting had changed it to WRITE).
  • Timeout should now work on all overflow situations.
  • Cleaned code a bit.
File size: 6.2 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Functions for accessings RAMVARS.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Initializes RAMVARS.
9; Drive detection can be started after this function returns.
10;
11; RamVars_Initialize
12;   Parameters:
13;       Nothing
14;   Returns:
15;       DS:     RAMVARS segment
16;   Corrupts registers:
17;       AX, CX, DI
18;--------------------------------------------------------------------
19RamVars_Initialize:
20    push    es
21    ; Fall to .StealMemoryForRAMVARS
22
23;--------------------------------------------------------------------
24; .StealMemoryForRAMVARS
25;   Parameters:
26;       Nothing
27;   Returns:
28;       DS:     RAMVARS segment
29;   Corrupts registers:
30;       AX
31;--------------------------------------------------------------------
32.StealMemoryForRAMVARS:
33    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
34    jz      SHORT .InitializeRamvars    ; No need to steal RAM
35
36    LOAD_BDA_SEGMENT_TO ds, ax, !       ; Zero AX
37    mov     al, [cs:ROMVARS.bStealSize]
38    sub     [BDA.wBaseMem], ax
39    mov     ax, [BDA.wBaseMem]
40    eSHL_IM ax, 6                       ; Segment to first stolen kB (*=40h)
41    mov     ds, ax
42    mov     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
43    ; Fall to .InitializeRamvars
44
45;--------------------------------------------------------------------
46; .InitializeRamvars
47;   Parameters:
48;       Nothing
49;   Returns:
50;       DS:     RAMVARS segment
51;   Corrupts registers:
52;       AX, CX, DI, ES
53;--------------------------------------------------------------------
54.InitializeRamvars:
55    call    RamVars_GetSegmentToDS
56    mov     cx, RAMVARS_size
57    xor     di, di
58    push    ds
59    pop     es
60    call    Memory_ZeroESDIwithSizeInCX
61    mov     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
62    ; Fall to .InitializeDriveTranslationAndReturn
63
64;--------------------------------------------------------------------
65; .InitializeDriveTranslationAndReturn
66;   Parameters:
67;       DS:     RAMVARS segment
68;   Returns:
69;       Nothing
70;   Corrupts registers:
71;       AX
72;--------------------------------------------------------------------
73.InitializeDriveTranslationAndReturn:
74    pop     es
75    jmp     DriveXlate_Reset
76
77
78;--------------------------------------------------------------------
79; Returns segment to RAMVARS.
80; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
81; or at the top of system base RAM.
82;
83; RamVars_GetSegmentToDS
84;   Parameters:
85;       Nothing
86;   Returns:
87;       DS:     RAMVARS segment
88;   Corrupts registers:
89;       DI
90;--------------------------------------------------------------------
91ALIGN JUMP_ALIGN
92RamVars_GetSegmentToDS:
93    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
94    jnz     SHORT .GetStolenSegmentToDS
95    mov     di, LITE_MODE_RAMVARS_SEGMENT
96    mov     ds, di
97    ret
98
99ALIGN JUMP_ALIGN
100.GetStolenSegmentToDS:
101    LOAD_BDA_SEGMENT_TO ds, di
102    mov     di, [BDA.wBaseMem]      ; Load available base memory size in kB
103    eSHL_IM di, 6                   ; Segment to first stolen kB (*=40h)
104ALIGN JUMP_ALIGN
105.LoopStolenKBs:
106    mov     ds, di                  ; EBDA segment to DS
107    add     di, BYTE 64             ; DI to next stolen kB
108    cmp     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
109    jne     SHORT .LoopStolenKBs    ; Loop until sign found (always found eventually)
110    ret
111
112
113;--------------------------------------------------------------------
114; Checks if INT 13h function is handled by this BIOS.
115;
116; RamVars_IsFunctionHandledByThisBIOS
117;   Parameters:
118;       AH:     INT 13h function number
119;       DL:     Drive number
120;       DS:     RAMVARS segment
121;   Returns:
122;       CF:     Set if function is handled by this BIOS
123;               Cleared if function belongs to some other BIOS
124;   Corrupts registers:
125;       Nothing
126;--------------------------------------------------------------------
127ALIGN JUMP_ALIGN
128RamVars_IsFunctionHandledByThisBIOS:
129    test    ah, ah          ; Reset for all floppy and hard disk drives?
130    jz      SHORT .FunctionIsHandledByOurBIOS
131    cmp     ah, 08h         ; Read Disk Drive Parameters?
132    jne     SHORT RamVars_IsDriveHandledByThisBIOS
133    test    dl, dl          ; We do not handle floppy drives
134    jns     SHORT .FunctionIsNotHandledByOurBIOS
135ALIGN JUMP_ALIGN
136.FunctionIsHandledByOurBIOS:
137    stc
138.FunctionIsNotHandledByOurBIOS:
139    ret
140
141;--------------------------------------------------------------------
142; Checks if drive is handled by this BIOS.
143;
144; RamVars_IsDriveHandledByThisBIOS
145;   Parameters:
146;       DL:     Drive number
147;       DS:     RAMVARS segment
148;   Returns:
149;       CF:     Set if drive is handled by this BIOS
150;               Cleared if drive belongs to some other BIOS
151;   Corrupts registers:
152;       Nothing
153;--------------------------------------------------------------------
154ALIGN JUMP_ALIGN
155RamVars_IsDriveHandledByThisBIOS:
156    push    ax
157    mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AL, First number to AH
158    add     al, ah                              ; One past last drive to AL
159    cmp     dl, al                              ; Above last supported?
160    jae     SHORT .DriveNotHandledByThisBIOS
161    cmp     ah, dl                              ; Below first supported?
162    ja      SHORT .DriveNotHandledByThisBIOS
163    stc
164.DriveNotHandledByThisBIOS:
165    pop     ax
166    ret
167
168
169;--------------------------------------------------------------------
170; RamVars_GetHardDiskCountFromBDAtoCX
171;   Parameters:
172;       DS:     RAMVARS segment
173;   Returns:
174;       CX:     Total hard disk count
175;   Corrupts registers:
176;       Nothing
177;--------------------------------------------------------------------
178ALIGN JUMP_ALIGN
179RamVars_GetHardDiskCountFromBDAtoCX:
180    push    es
181    push    dx
182
183    LOAD_BDA_SEGMENT_TO es, cx, !       ; Zero CX
184    call    RamVars_GetCountOfKnownDrivesToDL
185    MAX_U   dl, [es:BDA.bHDCount]
186    mov     cl, dl
187
188    pop     dx
189    pop     es
190    ret
191
192;--------------------------------------------------------------------
193; RamVars_GetCountOfKnownDrivesToDL
194;   Parameters:
195;       DS:     RAMVARS segment
196;   Returns:
197;       DL:     Total hard disk count
198;   Corrupts registers:
199;       Nothing
200;--------------------------------------------------------------------
201ALIGN JUMP_ALIGN
202RamVars_GetCountOfKnownDrivesToDL:
203    mov     dl, [RAMVARS.bFirstDrv]     ; Number for our first drive
204    add     dl, [RAMVARS.bDrvCnt]       ; Our drives
205    and     dl, 7Fh                     ; Clear HD bit for drive count
206    ret
207
208
209;--------------------------------------------------------------------
210; RamVars_GetIdeControllerCountToCX
211;   Parameters:
212;       Nothing
213;   Returns:
214;       CX:     Number of IDE controllers to handle
215;   Corrupts registers:
216;       Nothing
217;--------------------------------------------------------------------
218RamVars_GetIdeControllerCountToCX:
219    eMOVZX  cx, BYTE [cs:ROMVARS.bIdeCnt]
220    ret
Note: See TracBrowser for help on using the repository browser.