1 | ; Project name : XTIDE Universal BIOS |
---|
2 | ; Description : Functions for accessings RAMVARS. |
---|
3 | |
---|
4 | ; Section containing code |
---|
5 | SECTION .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 | ;-------------------------------------------------------------------- |
---|
19 | RamVars_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 | mov ax, LITE_MODE_RAMVARS_SEGMENT |
---|
34 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE |
---|
35 | jz SHORT .InitializeRamvars ; No need to steal RAM |
---|
36 | |
---|
37 | LOAD_BDA_SEGMENT_TO ds, ax, ! ; Zero AX |
---|
38 | mov al, [cs:ROMVARS.bStealSize] |
---|
39 | sub [BDA.wBaseMem], ax |
---|
40 | mov ax, [BDA.wBaseMem] |
---|
41 | eSHL_IM ax, 6 ; Segment to first stolen kB (*=40h) |
---|
42 | ; Fall to .InitializeRamvars |
---|
43 | |
---|
44 | ;-------------------------------------------------------------------- |
---|
45 | ; .InitializeRamvars |
---|
46 | ; Parameters: |
---|
47 | ; AX: RAMVARS segment |
---|
48 | ; Returns: |
---|
49 | ; DS: RAMVARS segment |
---|
50 | ; Corrupts registers: |
---|
51 | ; AX, CX, DI, ES |
---|
52 | ;-------------------------------------------------------------------- |
---|
53 | .InitializeRamvars: |
---|
54 | mov ds, ax |
---|
55 | mov es, ax |
---|
56 | mov cx, RAMVARS_size |
---|
57 | xor di, di |
---|
58 | call Memory_ZeroESDIwithSizeInCX |
---|
59 | mov WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE |
---|
60 | ; Fall to .InitializeDriveTranslationAndReturn |
---|
61 | |
---|
62 | ;-------------------------------------------------------------------- |
---|
63 | ; .InitializeDriveTranslationAndReturn |
---|
64 | ; Parameters: |
---|
65 | ; DS: RAMVARS segment |
---|
66 | ; Returns: |
---|
67 | ; Nothing |
---|
68 | ; Corrupts registers: |
---|
69 | ; AX |
---|
70 | ;-------------------------------------------------------------------- |
---|
71 | .InitializeDriveTranslationAndReturn: |
---|
72 | pop es |
---|
73 | jmp DriveXlate_Reset |
---|
74 | |
---|
75 | |
---|
76 | ;-------------------------------------------------------------------- |
---|
77 | ; Returns segment to RAMVARS. |
---|
78 | ; RAMVARS might be located at the top of interrupt vectors (0030:0000h) |
---|
79 | ; or at the top of system base RAM. |
---|
80 | ; |
---|
81 | ; RamVars_GetSegmentToDS |
---|
82 | ; Parameters: |
---|
83 | ; Nothing |
---|
84 | ; Returns: |
---|
85 | ; DS: RAMVARS segment |
---|
86 | ; Corrupts registers: |
---|
87 | ; DI |
---|
88 | ;-------------------------------------------------------------------- |
---|
89 | ALIGN JUMP_ALIGN |
---|
90 | RamVars_GetSegmentToDS: |
---|
91 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE |
---|
92 | jnz SHORT .GetStolenSegmentToDS |
---|
93 | %ifndef USE_186 |
---|
94 | mov di, LITE_MODE_RAMVARS_SEGMENT |
---|
95 | mov ds, di |
---|
96 | %else |
---|
97 | push LITE_MODE_RAMVARS_SEGMENT |
---|
98 | pop ds |
---|
99 | %endif |
---|
100 | ret |
---|
101 | |
---|
102 | ALIGN JUMP_ALIGN |
---|
103 | .GetStolenSegmentToDS: |
---|
104 | LOAD_BDA_SEGMENT_TO ds, di |
---|
105 | mov di, [BDA.wBaseMem] ; Load available base memory size in kB |
---|
106 | eSHL_IM di, 6 ; Segment to first stolen kB (*=40h) |
---|
107 | ALIGN JUMP_ALIGN |
---|
108 | .LoopStolenKBs: |
---|
109 | mov ds, di ; EBDA segment to DS |
---|
110 | add di, BYTE 64 ; DI to next stolen kB |
---|
111 | cmp WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE |
---|
112 | jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually) |
---|
113 | ret |
---|
114 | |
---|
115 | |
---|
116 | ;-------------------------------------------------------------------- |
---|
117 | ; Checks if INT 13h function is handled by this BIOS. |
---|
118 | ; |
---|
119 | ; RamVars_IsFunctionHandledByThisBIOS |
---|
120 | ; Parameters: |
---|
121 | ; AH: INT 13h function number |
---|
122 | ; DL: Drive number |
---|
123 | ; DS: RAMVARS segment |
---|
124 | ; Returns: |
---|
125 | ; CF: Cleared if function is handled by this BIOS |
---|
126 | ; Set if function belongs to some other BIOS |
---|
127 | ; Corrupts registers: |
---|
128 | ; Nothing |
---|
129 | ;-------------------------------------------------------------------- |
---|
130 | ALIGN JUMP_ALIGN |
---|
131 | RamVars_IsFunctionHandledByThisBIOS: |
---|
132 | test ah, ah ; Reset for all floppy and hard disk drives? |
---|
133 | jz SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS |
---|
134 | cmp ah, 08h |
---|
135 | %ifdef MODULE_SERIAL_FLOPPY |
---|
136 | ; we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts |
---|
137 | je SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS |
---|
138 | %else |
---|
139 | ; we handle all *hard disk* traffic for function 08h, as we need to wrap the hard disk drive count |
---|
140 | je SHORT RamVars_IsDriveHandledByThisBIOS.IsDriveAHardDisk |
---|
141 | %endif |
---|
142 | ;;; fall-through |
---|
143 | |
---|
144 | ;-------------------------------------------------------------------- |
---|
145 | ; Checks if drive is handled by this BIOS. |
---|
146 | ; |
---|
147 | ; RamVars_IsDriveHandledByThisBIOS |
---|
148 | ; Parameters: |
---|
149 | ; DL: Drive number |
---|
150 | ; DS: RAMVARS segment |
---|
151 | ; Returns: |
---|
152 | ; CF: Cleared if drive is handled by this BIOS |
---|
153 | ; Set if drive belongs to some other BIOS |
---|
154 | ; Corrupts registers: |
---|
155 | ; Nothing |
---|
156 | ;-------------------------------------------------------------------- |
---|
157 | ALIGN JUMP_ALIGN |
---|
158 | RamVars_IsDriveHandledByThisBIOS: |
---|
159 | push ax |
---|
160 | |
---|
161 | mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AH, First number to AL |
---|
162 | add ah, al ; One past last drive to AH |
---|
163 | cmp dl, ah ; Above last supported? |
---|
164 | jae SHORT .HardDiskIsNotHandledByThisBIOS |
---|
165 | .TestLowLimit: |
---|
166 | cmp dl, al ; Below first supported? |
---|
167 | jae SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX ; note that CF is clear if the branch is taken |
---|
168 | |
---|
169 | .HardDiskIsNotHandledByThisBIOS: |
---|
170 | %ifdef MODULE_SERIAL_FLOPPY |
---|
171 | call RamVars_UnpackFlopCntAndFirstToAL |
---|
172 | cbw ; normally 0h, could be ffh if no drives present |
---|
173 | adc ah, al ; if no drives present, still ffh (ffh + ffh + 1 = ffh) |
---|
174 | js SHORT .DiskIsNotHandledByThisBIOS |
---|
175 | cmp ah, dl |
---|
176 | jz SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX |
---|
177 | cmp al, dl |
---|
178 | jz SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX |
---|
179 | .DiskIsNotHandledByThisBIOS: |
---|
180 | %endif |
---|
181 | |
---|
182 | stc ; Is not supported by our BIOS |
---|
183 | |
---|
184 | .CFAlreadyClear_IsHandledByOurBIOS_PopAX: |
---|
185 | pop ax |
---|
186 | .CFAlreadyClear_IsHandledByOurBIOS: |
---|
187 | ret |
---|
188 | |
---|
189 | %ifndef MODULE_SERIAL_FLOPPY |
---|
190 | ; |
---|
191 | ; Note that we could have just checked for the high order bit in dl, but with the needed STC and jumps, |
---|
192 | ; leveraging the code above resulted in space savings. |
---|
193 | ; |
---|
194 | .IsDriveAHardDisk: |
---|
195 | push ax ; match stack at the top of routine |
---|
196 | mov al, 80h ; to catch all hard disks, lower limit is 80h vs. bFirstDrv |
---|
197 | jmp .TestLowLimit ; and there is no need to test a high limit |
---|
198 | %endif |
---|
199 | |
---|
200 | ;-------------------------------------------------------------------- |
---|
201 | ; RamVars_GetHardDiskCountFromBDAtoAX |
---|
202 | ; Parameters: |
---|
203 | ; DS: RAMVARS segment |
---|
204 | ; Returns: |
---|
205 | ; AX: Total hard disk count |
---|
206 | ; Corrupts registers: |
---|
207 | ; CX |
---|
208 | ;-------------------------------------------------------------------- |
---|
209 | ALIGN JUMP_ALIGN |
---|
210 | RamVars_GetHardDiskCountFromBDAtoAX: |
---|
211 | push es |
---|
212 | |
---|
213 | LOAD_BDA_SEGMENT_TO es, ax |
---|
214 | call RamVars_GetCountOfKnownDrivesToAX |
---|
215 | mov cl, [es:BDA.bHDCount] |
---|
216 | MAX_U al, cl |
---|
217 | |
---|
218 | pop es |
---|
219 | ret |
---|
220 | |
---|
221 | ;-------------------------------------------------------------------- |
---|
222 | ; RamVars_GetCountOfKnownDrivesToAX |
---|
223 | ; Parameters: |
---|
224 | ; DS: RAMVARS segment |
---|
225 | ; Returns: |
---|
226 | ; AX: Total hard disk count |
---|
227 | ; Corrupts registers: |
---|
228 | ; None |
---|
229 | ;-------------------------------------------------------------------- |
---|
230 | ALIGN JUMP_ALIGN |
---|
231 | RamVars_GetCountOfKnownDrivesToAX: |
---|
232 | mov ax, [RAMVARS.wDrvCntAndFirst] |
---|
233 | add al, ah |
---|
234 | and al, 7fh |
---|
235 | cbw |
---|
236 | ret |
---|
237 | |
---|
238 | ;-------------------------------------------------------------------- |
---|
239 | ; RamVars_GetIdeControllerCountToCX |
---|
240 | ; Parameters: |
---|
241 | ; Nothing |
---|
242 | ; Returns: |
---|
243 | ; CX: Number of IDE controllers to handle |
---|
244 | ; Corrupts registers: |
---|
245 | ; Nothing |
---|
246 | ;-------------------------------------------------------------------- |
---|
247 | ALIGN JUMP_ALIGN |
---|
248 | RamVars_GetIdeControllerCountToCX: |
---|
249 | eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt] |
---|
250 | ret |
---|
251 | |
---|
252 | %ifdef MODULE_SERIAL_FLOPPY |
---|
253 | ;-------------------------------------------------------------------- |
---|
254 | ; RamVars_UnpackFlopCntAndFirstToAL |
---|
255 | ; Parameters: |
---|
256 | ; Nothing |
---|
257 | ; Returns: |
---|
258 | ; AL: First floppy drive number supported |
---|
259 | ; CF: Number of floppy drives supported (clear = 1, set = 2) |
---|
260 | ; Corrupts registers: |
---|
261 | ; Nothing |
---|
262 | ;-------------------------------------------------------------------- |
---|
263 | ALIGN JUMP_ALIGN |
---|
264 | RamVars_UnpackFlopCntAndFirstToAL: |
---|
265 | mov al, [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst] |
---|
266 | sar al, 1 |
---|
267 | ret |
---|
268 | %endif |
---|