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

Last change on this file since 145 was 145, checked in by krille_n_@…, 13 years ago

Minor size optimizations to all parts of the project (even the old Configurator).
Also added a new 'release' option to the makefiles of both versions of the Configurator. It invokes UPX and makes the Configurator programs ridiculously tiny.

File size: 6.8 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 [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
43    ; Fall to .InitializeRamvarsFromDS
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    ; Fall to .InitializeDriveTranslationAndReturn
62
63;--------------------------------------------------------------------
64; .InitializeDriveTranslationAndReturn
65;   Parameters:
66;       DS:     RAMVARS segment
67;   Returns:
68;       Nothing
69;   Corrupts registers:
70;       AX
71;--------------------------------------------------------------------
72.InitializeDriveTranslationAndReturn:
73    pop     es
74    jmp     DriveXlate_Reset
75
76
77;--------------------------------------------------------------------
78; Returns segment to RAMVARS.
79; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
80; or at the top of system base RAM.
81;
82; RamVars_GetSegmentToDS
83;   Parameters:
84;       Nothing
85;   Returns:
86;       DS:     RAMVARS segment
87;   Corrupts registers:
88;       DI
89;--------------------------------------------------------------------
90ALIGN JUMP_ALIGN
91RamVars_GetSegmentToDS:
92    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
93    jnz     SHORT .GetStolenSegmentToDS
94    mov     di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
95    mov     ds, di
96    ret
97
98ALIGN JUMP_ALIGN
99.GetStolenSegmentToDS:
100    LOAD_BDA_SEGMENT_TO ds, di
101    mov     di, [BDA.wBaseMem]      ; Load available base memory size in kB
102    eSHL_IM di, 6                   ; Segment to first stolen kB (*=40h)
103ALIGN JUMP_ALIGN
104.LoopStolenKBs:
105    mov     ds, di                  ; EBDA segment to DS
106    add     di, BYTE 64             ; DI to next stolen kB
107    cmp     WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
108    jne     SHORT .LoopStolenKBs    ; Loop until sign found (always found eventually)
109    ret
110
111
112;--------------------------------------------------------------------
113; Checks if INT 13h function is handled by this BIOS.
114;
115; RamVars_IsFunctionHandledByThisBIOS
116;   Parameters:
117;       AH:     INT 13h function number
118;       DL:     Drive number
119;       DS:     RAMVARS segment
120;   Returns:
121;       CF:     Set if function is handled by this BIOS
122;               Cleared if function belongs to some other BIOS
123;   Corrupts registers:
124;       DI
125;--------------------------------------------------------------------
126ALIGN JUMP_ALIGN
127RamVars_IsFunctionHandledByThisBIOS:
128    test    ah, ah          ; Reset for all floppy and hard disk drives?
129    jz      SHORT .FunctionIsHandledByOurBIOS
130    cmp     ah, 08h         ; Read Disk Drive Parameters?
131    jne     SHORT RamVars_IsDriveHandledByThisBIOS
132    test    dl, dl          ; We do not handle floppy drives
133    jns     SHORT .FunctionIsNotHandledByOurBIOS
134ALIGN JUMP_ALIGN
135.FunctionIsHandledByOurBIOS:
136    stc
137.FunctionIsNotHandledByOurBIOS:
138    ret
139
140;--------------------------------------------------------------------
141; Checks if drive is handled by this BIOS.
142;
143; RamVars_IsDriveHandledByThisBIOS
144;   Parameters:
145;       DL:     Drive number
146;       DS:     RAMVARS segment
147;   Returns:
148;       CF:     Set if drive is handled by this BIOS
149;               Cleared if drive belongs to some other BIOS
150;   Corrupts registers:
151;       DI
152;--------------------------------------------------------------------
153ALIGN JUMP_ALIGN
154RamVars_IsDriveHandledByThisBIOS:
155    xchg    di, ax                              ; Backup AX
156    mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AL, First number to AH
157    add     al, ah                              ; One past last drive to AL
158    cmp     dl, al                              ; Above last supported?
159    jae     SHORT .DriveNotHandledByThisBIOS
160    cmp     ah, dl                              ; Below first supported?
161    ja      SHORT .DriveNotHandledByThisBIOS
162    stc
163ALIGN JUMP_ALIGN
164.DriveNotHandledByThisBIOS:
165    xchg    ax, di
166    ret
167
168
169;--------------------------------------------------------------------
170; RamVars_IncrementHardDiskCount
171;   Parameters:
172;       DL:     Drive number for new drive
173;       DS:     RAMVARS segment
174;   Returns:
175;       Nothing
176;   Corrupts registers:
177;       Nothing
178;--------------------------------------------------------------------
179RamVars_IncrementHardDiskCount:
180    inc     BYTE [RAMVARS.bDrvCnt]      ; Increment drive count to RAMVARS
181    cmp     BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
182    ja      SHORT .Return               ;  If so, return
183    mov     [RAMVARS.bFirstDrv], dl     ; Store first drive number
184.Return:
185    ret
186
187
188;--------------------------------------------------------------------
189; RamVars_GetHardDiskCountFromBDAtoCX
190;   Parameters:
191;       DS:     RAMVARS segment
192;   Returns:
193;       CX:     Total hard disk count
194;   Corrupts registers:
195;       Nothing
196;--------------------------------------------------------------------
197ALIGN JUMP_ALIGN
198RamVars_GetHardDiskCountFromBDAtoCX:
199    push    es
200    push    dx
201
202    LOAD_BDA_SEGMENT_TO es, cx, !       ; Zero CX
203    call    RamVars_GetCountOfKnownDrivesToDL
204    MAX_U   dl, [es:BDA.bHDCount]
205    mov     cl, dl
206
207    pop     dx
208    pop     es
209    ret
210
211;--------------------------------------------------------------------
212; RamVars_GetCountOfKnownDrivesToDL
213;   Parameters:
214;       DS:     RAMVARS segment
215;   Returns:
216;       DL:     Total hard disk count
217;   Corrupts registers:
218;       Nothing
219;--------------------------------------------------------------------
220ALIGN JUMP_ALIGN
221RamVars_GetCountOfKnownDrivesToDL:
222    mov     dl, [RAMVARS.bFirstDrv]     ; Number for our first drive
223    add     dl, [RAMVARS.bDrvCnt]       ; Our drives
224    and     dl, 7Fh                     ; Clear HD bit for drive count
225    ret
226
227
228;--------------------------------------------------------------------
229; RamVars_GetIdeControllerCountToCX
230;   Parameters:
231;       Nothing
232;   Returns:
233;       CX:     Number of IDE controllers to handle
234;   Corrupts registers:
235;       Nothing
236;--------------------------------------------------------------------
237RamVars_GetIdeControllerCountToCX:
238    eMOVZX  cx, BYTE [cs:ROMVARS.bIdeCnt]
239    ret
Note: See TracBrowser for help on using the repository browser.