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 | 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 | ;--------------------------------------------------------------------
|
---|
91 | ALIGN JUMP_ALIGN
|
---|
92 | RamVars_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 |
|
---|
104 | ALIGN 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)
|
---|
109 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
132 | ALIGN JUMP_ALIGN
|
---|
133 | RamVars_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
|
---|
140 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
159 | ALIGN JUMP_ALIGN
|
---|
160 | RamVars_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 | ;--------------------------------------------------------------------
|
---|
183 | ALIGN JUMP_ALIGN
|
---|
184 | RamVars_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 | ;--------------------------------------------------------------------
|
---|
206 | ALIGN JUMP_ALIGN
|
---|
207 | RamVars_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 | ;--------------------------------------------------------------------
|
---|
223 | RamVars_GetIdeControllerCountToCX:
|
---|
224 | eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt]
|
---|
225 | ret
|
---|