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

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

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 6.3 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%ifndef USE_186
96 mov di, LITE_MODE_RAMVARS_SEGMENT
97 mov ds, di
98%else
99 push LITE_MODE_RAMVARS_SEGMENT
100 pop ds
101%endif
102 ret
103
104ALIGN JUMP_ALIGN
105.GetStolenSegmentToDS:
106 LOAD_BDA_SEGMENT_TO ds, di
107 mov di, [BDA.wBaseMem] ; Load available base memory size in kB
108 eSHL_IM di, 6 ; Segment to first stolen kB (*=40h)
109ALIGN JUMP_ALIGN
110.LoopStolenKBs:
111 mov ds, di ; EBDA segment to DS
112 add di, BYTE 64 ; DI to next stolen kB
113 cmp WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
114 jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually)
115 ret
116
117
118;--------------------------------------------------------------------
119; Checks if INT 13h function is handled by this BIOS.
120;
121; RamVars_IsFunctionHandledByThisBIOS
122; Parameters:
123; AH: INT 13h function number
124; DL: Drive number
125; DS: RAMVARS segment
126; Returns:
127; CF: Set if function is handled by this BIOS
128; Cleared if function belongs to some other BIOS
129; Corrupts registers:
130; Nothing
131;--------------------------------------------------------------------
132ALIGN JUMP_ALIGN
133RamVars_IsFunctionHandledByThisBIOS:
134 test ah, ah ; Reset for all floppy and hard disk drives?
135 jz SHORT .FunctionIsHandledByOurBIOS
136 cmp ah, 08h ; Read Disk Drive Parameters?
137 jne SHORT RamVars_IsDriveHandledByThisBIOS
138 test dl, dl ; We do not handle floppy drives
139 jns SHORT .FunctionIsNotHandledByOurBIOS
140ALIGN JUMP_ALIGN
141.FunctionIsHandledByOurBIOS:
142 stc
143.FunctionIsNotHandledByOurBIOS:
144 ret
145
146;--------------------------------------------------------------------
147; Checks if drive is handled by this BIOS.
148;
149; RamVars_IsDriveHandledByThisBIOS
150; Parameters:
151; DL: Drive number
152; DS: RAMVARS segment
153; Returns:
154; CF: Set if drive is handled by this BIOS
155; Cleared if drive belongs to some other BIOS
156; Corrupts registers:
157; Nothing
158;--------------------------------------------------------------------
159ALIGN JUMP_ALIGN
160RamVars_IsDriveHandledByThisBIOS:
161 push ax
162 mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AL, First number to AH
163 add al, ah ; One past last drive to AL
164 cmp dl, al ; Above last supported?
165 jae SHORT .DriveNotHandledByThisBIOS
166 cmp ah, dl ; Below first supported?
167 ja SHORT .DriveNotHandledByThisBIOS
168 stc
169.DriveNotHandledByThisBIOS:
170 pop ax
171 ret
172
173
174;--------------------------------------------------------------------
175; RamVars_GetHardDiskCountFromBDAtoCX
176; Parameters:
177; DS: RAMVARS segment
178; Returns:
179; CX: Total hard disk count
180; Corrupts registers:
181; Nothing
182;--------------------------------------------------------------------
183ALIGN JUMP_ALIGN
184RamVars_GetHardDiskCountFromBDAtoCX:
185 push es
186 push dx
187
188 LOAD_BDA_SEGMENT_TO es, cx, ! ; Zero CX
189 call RamVars_GetCountOfKnownDrivesToDL
190 mov cl, [es:BDA.bHDCount]
191 MAX_U cl, dl
192
193 pop dx
194 pop es
195 ret
196
197;--------------------------------------------------------------------
198; RamVars_GetCountOfKnownDrivesToDL
199; Parameters:
200; DS: RAMVARS segment
201; Returns:
202; DL: Total hard disk count
203; Corrupts registers:
204; Nothing
205;--------------------------------------------------------------------
206ALIGN JUMP_ALIGN
207RamVars_GetCountOfKnownDrivesToDL:
208 mov dl, [RAMVARS.bFirstDrv] ; Number for our first drive
209 add dl, [RAMVARS.bDrvCnt] ; Our drives
210 and dl, 7Fh ; Clear HD bit for drive count
211 ret
212
213
214;--------------------------------------------------------------------
215; RamVars_GetIdeControllerCountToCX
216; Parameters:
217; Nothing
218; Returns:
219; CX: Number of IDE controllers to handle
220; Corrupts registers:
221; Nothing
222;--------------------------------------------------------------------
223RamVars_GetIdeControllerCountToCX:
224 eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt]
225 ret
Note: See TracBrowser for help on using the repository browser.