Rev 1332 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1332 | Rev 1376 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 1332 $ |
8 | $Revision: 1376 $ |
9 | 9 | ||
10 | 10 | ||
11 | MEM_WB equ 6 ;write-back memory |
11 | MEM_WB equ 6 ;write-back memory |
12 | MEM_WC equ 1 ;write combined memory |
12 | MEM_WC equ 1 ;write combined memory |
13 | MEM_UC equ 0 ;uncached memory |
13 | MEM_UC equ 0 ;uncached memory |
14 | 14 | ||
15 | align 4 |
15 | align 4 |
16 | proc mem_test |
16 | proc mem_test |
17 | ; if we have BIOS with fn E820, skip the test |
17 | ; if we have BIOS with fn E820, skip the test |
18 | cmp dword [BOOT_VAR-OS_BASE + 0x9100], 0 |
18 | cmp dword [BOOT_VAR-OS_BASE + 0x9100], 0 |
19 | jnz .ret |
19 | jnz .ret |
20 | 20 | ||
21 | mov eax, cr0 |
21 | mov eax, cr0 |
22 | and eax, not (CR0_CD+CR0_NW) |
22 | and eax, not (CR0_CD+CR0_NW) |
23 | or eax, CR0_CD ;disable caching |
23 | or eax, CR0_CD ;disable caching |
24 | mov cr0, eax |
24 | mov cr0, eax |
25 | wbinvd ;invalidate cache |
25 | wbinvd ;invalidate cache |
26 | 26 | ||
27 | xor edi, edi |
27 | xor edi, edi |
28 | mov ebx, 'TEST' |
28 | mov ebx, 'TEST' |
29 | @@: |
29 | @@: |
30 | add edi, 0x100000 |
30 | add edi, 0x100000 |
31 | xchg ebx, dword [edi] |
31 | xchg ebx, dword [edi] |
32 | cmp dword [edi], 'TEST' |
32 | cmp dword [edi], 'TEST' |
33 | xchg ebx, dword [edi] |
33 | xchg ebx, dword [edi] |
34 | je @b |
34 | je @b |
35 | 35 | ||
36 | and eax, not (CR0_CD+CR0_NW) ;enable caching |
36 | and eax, not (CR0_CD+CR0_NW) ;enable caching |
37 | mov cr0, eax |
37 | mov cr0, eax |
38 | inc dword [BOOT_VAR-OS_BASE + 0x9100] |
38 | inc dword [BOOT_VAR-OS_BASE + 0x9100] |
39 | xor eax, eax |
39 | xor eax, eax |
40 | mov [BOOT_VAR-OS_BASE + 0x9104], eax |
40 | mov [BOOT_VAR-OS_BASE + 0x9104], eax |
41 | mov [BOOT_VAR-OS_BASE + 0x9108], eax |
41 | mov [BOOT_VAR-OS_BASE + 0x9108], eax |
42 | mov [BOOT_VAR-OS_BASE + 0x910C], edi |
42 | mov [BOOT_VAR-OS_BASE + 0x910C], edi |
43 | mov [BOOT_VAR-OS_BASE + 0x9110], eax |
43 | mov [BOOT_VAR-OS_BASE + 0x9110], eax |
44 | .ret: |
44 | .ret: |
45 | ret |
45 | ret |
46 | endp |
46 | endp |
47 | 47 | ||
48 | align 4 |
48 | align 4 |
49 | proc init_mem |
49 | proc init_mem |
50 | ; calculate maximum allocatable address and number of allocatable pages |
50 | ; calculate maximum allocatable address and number of allocatable pages |
51 | mov edi, BOOT_VAR-OS_BASE + 0x9104 |
51 | mov edi, BOOT_VAR-OS_BASE + 0x9104 |
52 | mov ecx, [edi-4] |
52 | mov ecx, [edi-4] |
53 | xor esi, esi ; esi will hold total amount of memory |
53 | xor esi, esi ; esi will hold total amount of memory |
54 | xor edx, edx ; edx will hold maximum allocatable address |
54 | xor edx, edx ; edx will hold maximum allocatable address |
55 | .calcmax: |
55 | .calcmax: |
56 | ; round all to pages |
56 | ; round all to pages |
57 | mov eax, [edi] |
57 | mov eax, [edi] |
58 | test eax, 0xFFF |
58 | test eax, 0xFFF |
59 | jz @f |
59 | jz @f |
60 | neg eax |
60 | neg eax |
61 | and eax, 0xFFF |
61 | and eax, 0xFFF |
62 | add [edi], eax |
62 | add [edi], eax |
63 | adc dword [edi+4], 0 |
63 | adc dword [edi+4], 0 |
64 | sub [edi+8], eax |
64 | sub [edi+8], eax |
65 | sbb dword [edi+12], 0 |
65 | sbb dword [edi+12], 0 |
66 | jc .unusable |
66 | jc .unusable |
67 | @@: |
67 | @@: |
68 | and dword [edi+8], not 0xFFF |
68 | and dword [edi+8], not 0xFFF |
69 | jz .unusable |
69 | jz .unusable |
70 | ; ignore memory after 4 Gb |
70 | ; ignore memory after 4 Gb |
71 | cmp dword [edi+4], 0 |
71 | cmp dword [edi+4], 0 |
72 | jnz .unusable |
72 | jnz .unusable |
73 | mov eax, [edi] |
73 | mov eax, [edi] |
74 | cmp dword [edi+12], 0 |
74 | cmp dword [edi+12], 0 |
75 | jnz .overflow |
75 | jnz .overflow |
76 | add eax, [edi+8] |
76 | add eax, [edi+8] |
77 | jnc @f |
77 | jnc @f |
78 | .overflow: |
78 | .overflow: |
79 | mov eax, 0xFFFFF000 |
79 | mov eax, 0xFFFFF000 |
80 | @@: |
80 | @@: |
81 | cmp edx, eax |
81 | cmp edx, eax |
82 | jae @f |
82 | jae @f |
83 | mov edx, eax |
83 | mov edx, eax |
84 | @@: |
84 | @@: |
85 | sub eax, [edi] |
85 | sub eax, [edi] |
86 | mov [edi+8], eax |
86 | mov [edi+8], eax |
87 | add esi, eax |
87 | add esi, eax |
88 | jmp .usable |
88 | jmp .usable |
89 | .unusable: |
89 | .unusable: |
90 | and dword [edi+8], 0 |
90 | and dword [edi+8], 0 |
91 | .usable: |
91 | .usable: |
92 | add edi, 20 |
92 | add edi, 20 |
93 | loop .calcmax |
93 | loop .calcmax |
94 | .calculated: |
94 | .calculated: |
95 | mov [MEM_AMOUNT-OS_BASE], esi |
95 | mov [MEM_AMOUNT-OS_BASE], esi |
96 | mov [pg_data.mem_amount-OS_BASE], esi |
96 | mov [pg_data.mem_amount-OS_BASE], esi |
97 | shr esi, 12 |
97 | shr esi, 12 |
98 | mov [pg_data.pages_count-OS_BASE], esi |
98 | mov [pg_data.pages_count-OS_BASE], esi |
99 | 99 | ||
100 | shr edx, 12 |
100 | shr edx, 12 |
101 | add edx, 31 |
101 | add edx, 31 |
102 | and edx, not 31 |
102 | and edx, not 31 |
103 | shr edx, 3 |
103 | shr edx, 3 |
104 | mov [pg_data.pagemap_size-OS_BASE], edx |
104 | mov [pg_data.pagemap_size-OS_BASE], edx |
105 | 105 | ||
106 | add edx, (sys_pgmap-OS_BASE)+4095 |
106 | add edx, (sys_pgmap-OS_BASE)+4095 |
107 | and edx, not 4095 |
107 | and edx, not 4095 |
108 | mov [tmp_page_tabs], edx |
108 | mov [tmp_page_tabs], edx |
109 | 109 | ||
110 | mov edx, esi |
110 | mov edx, esi |
111 | and edx, -1024 |
111 | and edx, -1024 |
112 | cmp edx, (OS_BASE/4096) |
112 | cmp edx, (OS_BASE/4096) |
113 | jbe @F |
113 | jbe @F |
114 | mov edx, (OS_BASE/4096) |
114 | mov edx, (OS_BASE/4096) |
115 | jmp .set |
115 | jmp .set |
116 | @@: |
116 | @@: |
117 | cmp edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096 |
117 | cmp edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096 |
118 | jae .set |
118 | jae .set |
119 | mov edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096 |
119 | mov edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096 |
120 | .set: |
120 | .set: |
121 | mov [pg_data.kernel_pages-OS_BASE], edx |
121 | mov [pg_data.kernel_pages-OS_BASE], edx |
122 | shr edx, 10 |
122 | shr edx, 10 |
123 | mov [pg_data.kernel_tables-OS_BASE], edx |
123 | mov [pg_data.kernel_tables-OS_BASE], edx |
124 | 124 | ||
125 | xor eax, eax |
125 | xor eax, eax |
126 | mov edi, sys_pgdir-OS_BASE |
126 | mov edi, sys_pgdir-OS_BASE |
127 | mov ecx, 4096/4 |
127 | mov ecx, 4096/4 |
128 | cld |
128 | cld |
129 | rep stosd |
129 | rep stosd |
130 | 130 | ||
131 | mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20) |
131 | mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20) |
132 | bt [cpu_caps-OS_BASE], CAPS_PSE |
132 | bt [cpu_caps-OS_BASE], CAPS_PSE |
133 | jnc .no_PSE |
133 | jnc .no_PSE |
134 | 134 | ||
135 | mov ebx, cr4 |
135 | mov ebx, cr4 |
136 | or ebx, CR4_PSE |
136 | or ebx, CR4_PSE |
137 | mov eax, PG_LARGE+PG_SW |
137 | mov eax, PG_LARGE+PG_SW |
138 | mov cr4, ebx |
138 | mov cr4, ebx |
139 | dec [pg_data.kernel_tables-OS_BASE] |
139 | dec [pg_data.kernel_tables-OS_BASE] |
140 | 140 | ||
141 | mov [edx], eax |
141 | mov [edx], eax |
142 | add eax, 0x00400000 |
142 | add eax, 0x00400000 |
143 | add edx, 4 |
143 | add edx, 4 |
144 | 144 | ||
145 | mov eax, 0x400000+PG_SW |
145 | mov eax, 0x400000+PG_SW |
146 | mov ecx, [tmp_page_tabs] |
146 | mov ecx, [tmp_page_tabs] |
147 | sub ecx, 0x400000 |
147 | sub ecx, 0x400000 |
148 | shr ecx, 12 ;ecx/=4096 |
148 | shr ecx, 12 ;ecx/=4096 |
149 | jmp .map_low |
149 | jmp .map_low |
150 | .no_PSE: |
150 | .no_PSE: |
151 | mov eax, PG_SW |
151 | mov eax, PG_SW |
152 | mov ecx, [tmp_page_tabs] |
152 | mov ecx, [tmp_page_tabs] |
153 | shr ecx, 12 |
153 | shr ecx, 12 |
154 | .map_low: |
154 | .map_low: |
155 | mov edi, [tmp_page_tabs] |
155 | mov edi, [tmp_page_tabs] |
156 | @@: ; |
156 | @@: ; |
157 | stosd |
157 | stosd |
158 | add eax, 0x1000 |
158 | add eax, 0x1000 |
159 | dec ecx |
159 | dec ecx |
160 | jnz @B |
160 | jnz @B |
161 | 161 | ||
162 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
162 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
163 | shl ecx, 10 |
163 | shl ecx, 10 |
164 | xor eax, eax |
164 | xor eax, eax |
165 | rep stosd |
165 | rep stosd |
166 | 166 | ||
167 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
167 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
168 | mov eax, [tmp_page_tabs] |
168 | mov eax, [tmp_page_tabs] |
169 | or eax, PG_SW |
169 | or eax, PG_SW |
170 | mov edi, edx |
170 | mov edi, edx |
171 | 171 | ||
172 | .map_kernel_tabs: |
172 | .map_kernel_tabs: |
173 | 173 | ||
174 | stosd |
174 | stosd |
175 | add eax, 0x1000 |
175 | add eax, 0x1000 |
176 | dec ecx |
176 | dec ecx |
177 | jnz .map_kernel_tabs |
177 | jnz .map_kernel_tabs |
178 | 178 | ||
179 | mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE |
179 | mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE |
180 | 180 | ||
181 | mov edi, (sys_pgdir-OS_BASE) |
181 | mov edi, (sys_pgdir-OS_BASE) |
182 | lea esi, [edi+(OS_BASE shr 20)] |
182 | lea esi, [edi+(OS_BASE shr 20)] |
183 | movsd |
183 | movsd |
184 | movsd |
184 | movsd |
185 | ret |
185 | ret |
186 | endp |
186 | endp |
187 | 187 | ||
188 | align 4 |
188 | align 4 |
189 | proc init_page_map |
189 | proc init_page_map |
190 | ; mark all memory as unavailable |
190 | ; mark all memory as unavailable |
191 | mov edi, sys_pgmap-OS_BASE |
191 | mov edi, sys_pgmap-OS_BASE |
192 | mov ecx, [pg_data.pagemap_size-OS_BASE] |
192 | mov ecx, [pg_data.pagemap_size-OS_BASE] |
193 | shr ecx, 2 |
193 | shr ecx, 2 |
194 | xor eax, eax |
194 | xor eax, eax |
195 | cld |
195 | cld |
196 | rep stosd |
196 | rep stosd |
197 | 197 | ||
198 | ; scan through memory map and mark free areas as available |
198 | ; scan through memory map and mark free areas as available |
199 | mov ebx, BOOT_VAR-OS_BASE + 0x9104 |
199 | mov ebx, BOOT_VAR-OS_BASE + 0x9104 |
200 | mov edx, [ebx-4] |
200 | mov edx, [ebx-4] |
201 | .scanmap: |
201 | .scanmap: |
202 | mov ecx, [ebx+8] |
202 | mov ecx, [ebx+8] |
203 | shr ecx, 12 ; ecx = number of pages |
203 | shr ecx, 12 ; ecx = number of pages |
204 | jz .next |
204 | jz .next |
205 | mov edi, [ebx] |
205 | mov edi, [ebx] |
206 | shr edi, 12 ; edi = first page |
206 | shr edi, 12 ; edi = first page |
207 | mov eax, edi |
207 | mov eax, edi |
208 | shr edi, 5 |
208 | shr edi, 5 |
209 | shl edi, 2 |
209 | shl edi, 2 |
210 | add edi, sys_pgmap-OS_BASE |
210 | add edi, sys_pgmap-OS_BASE |
211 | and eax, 31 |
211 | and eax, 31 |
212 | jz .startok |
212 | jz .startok |
213 | add ecx, eax |
213 | add ecx, eax |
214 | sub ecx, 32 |
214 | sub ecx, 32 |
215 | jbe .onedword |
215 | jbe .onedword |
216 | push ecx |
216 | push ecx |
217 | mov ecx, eax |
217 | mov ecx, eax |
218 | or eax, -1 |
218 | or eax, -1 |
219 | shl eax, cl |
219 | shl eax, cl |
220 | or [edi], eax |
220 | or [edi], eax |
221 | add edi, 4 |
221 | add edi, 4 |
222 | pop ecx |
222 | pop ecx |
223 | .startok: |
223 | .startok: |
224 | push ecx |
224 | push ecx |
225 | shr ecx, 5 |
225 | shr ecx, 5 |
226 | or eax, -1 |
226 | or eax, -1 |
227 | rep stosd |
227 | rep stosd |
228 | pop ecx |
228 | pop ecx |
229 | and ecx, 31 |
229 | and ecx, 31 |
230 | neg eax |
230 | neg eax |
231 | shl eax, cl |
231 | shl eax, cl |
232 | dec eax |
232 | dec eax |
233 | or [edi], eax |
233 | or [edi], eax |
234 | jmp .next |
234 | jmp .next |
235 | .onedword: |
235 | .onedword: |
236 | add ecx, 32 |
236 | add ecx, 32 |
237 | sub ecx, eax |
237 | sub ecx, eax |
238 | @@: |
238 | @@: |
239 | bts [edi], eax |
239 | bts [edi], eax |
240 | inc eax |
240 | inc eax |
241 | loop @b |
241 | loop @b |
242 | .next: |
242 | .next: |
243 | add ebx, 20 |
243 | add ebx, 20 |
244 | dec edx |
244 | dec edx |
245 | jnz .scanmap |
245 | jnz .scanmap |
246 | 246 | ||
247 | ; mark kernel memory as allocated (unavailable) |
247 | ; mark kernel memory as allocated (unavailable) |
248 | mov ecx, [tmp_page_tabs] |
248 | mov ecx, [tmp_page_tabs] |
249 | mov edx, [pg_data.pages_count-OS_BASE] |
249 | mov edx, [pg_data.pages_count-OS_BASE] |
250 | shr ecx, 12 |
250 | shr ecx, 12 |
251 | add ecx, [pg_data.kernel_tables-OS_BASE] |
251 | add ecx, [pg_data.kernel_tables-OS_BASE] |
252 | sub edx, ecx |
252 | sub edx, ecx |
253 | mov [pg_data.pages_free-OS_BASE], edx |
253 | mov [pg_data.pages_free-OS_BASE], edx |
254 | 254 | ||
255 | mov edi, sys_pgmap-OS_BASE |
255 | mov edi, sys_pgmap-OS_BASE |
256 | mov ebx, ecx |
256 | mov ebx, ecx |
257 | shr ecx, 5 |
257 | shr ecx, 5 |
258 | xor eax, eax |
258 | xor eax, eax |
259 | rep stosd |
259 | rep stosd |
260 | 260 | ||
261 | not eax |
261 | not eax |
262 | mov ecx, ebx |
262 | mov ecx, ebx |
263 | and ecx, 31 |
263 | and ecx, 31 |
264 | shl eax, cl |
264 | shl eax, cl |
265 | and [edi], eax |
265 | and [edi], eax |
266 | add edi, OS_BASE |
266 | add edi, OS_BASE |
267 | mov [page_start-OS_BASE], edi; |
267 | mov [page_start-OS_BASE], edi; |
268 | 268 | ||
269 | mov ebx, sys_pgmap |
269 | mov ebx, sys_pgmap |
270 | add ebx, [pg_data.pagemap_size-OS_BASE] |
270 | add ebx, [pg_data.pagemap_size-OS_BASE] |
271 | mov [page_end-OS_BASE], ebx |
271 | mov [page_end-OS_BASE], ebx |
272 | 272 | ||
273 | mov [pg_data.pg_mutex-OS_BASE], 0 |
273 | mov [pg_data.pg_mutex-OS_BASE], 0 |
274 | ret |
274 | ret |
275 | endp |
275 | endp |
276 | 276 | ||
277 | align 4 |
277 | align 4 |
278 | 278 | ||
279 | init_BIOS32: |
279 | init_BIOS32: |
280 | mov edi, 0xE0000 |
280 | mov edi, 0xE0000 |
281 | .pcibios_nxt: |
281 | .pcibios_nxt: |
282 | cmp dword[edi], '_32_' ; "magic" word |
282 | cmp dword[edi], '_32_' ; "magic" word |
283 | je .BIOS32_found |
283 | je .BIOS32_found |
284 | .pcibios_nxt2: |
284 | .pcibios_nxt2: |
285 | add edi, 0x10 |
285 | add edi, 0x10 |
286 | cmp edi, 0xFFFF0 |
286 | cmp edi, 0xFFFF0 |
287 | je .BIOS32_not_found |
287 | je .BIOS32_not_found |
288 | jmp .pcibios_nxt |
288 | jmp .pcibios_nxt |
289 | .BIOS32_found: ; magic word found, check control summ |
289 | .BIOS32_found: ; magic word found, check control summ |
290 | 290 | ||
291 | movzx ecx, byte[edi + 9] |
291 | movzx ecx, byte[edi + 9] |
292 | shl ecx, 4 |
292 | shl ecx, 4 |
293 | mov esi, edi |
293 | mov esi, edi |
294 | xor eax, eax |
294 | xor eax, eax |
295 | cld ; paranoia |
295 | cld ; paranoia |
296 | @@: lodsb |
296 | @@: lodsb |
297 | add ah, al |
297 | add ah, al |
298 | loop @b |
298 | loop @b |
299 | jnz .pcibios_nxt2 ; control summ must be zero |
299 | jnz .pcibios_nxt2 ; control summ must be zero |
300 | ; BIOS32 service found ! |
300 | ; BIOS32 service found ! |
301 | mov ebp, [edi + 4] |
301 | mov ebp, [edi + 4] |
302 | mov [bios32_entry], ebp |
302 | mov [bios32_entry], ebp |
303 | ; check PCI BIOS present |
303 | ; check PCI BIOS present |
304 | mov eax, '$PCI' |
304 | mov eax, '$PCI' |
305 | xor ebx, ebx |
305 | xor ebx, ebx |
306 | push cs ; special for 'ret far' from BIOS |
306 | push cs ; special for 'ret far' from BIOS |
307 | call ebp |
307 | call ebp |
308 | test al, al |
308 | test al, al |
309 | jnz .PCI_BIOS32_not_found |
309 | jnz .PCI_BIOS32_not_found |
310 | 310 | ||
311 | ; çäåñü ñîçäàþòñÿ äèñêðèïòîðû äëÿ PCI BIOS |
311 | ; çäåñü ñîçäàþòñÿ äèñêðèïòîðû äëÿ PCI BIOS |
312 | 312 | ||
313 | add ebx, OS_BASE |
313 | add ebx, OS_BASE |
314 | dec ecx |
314 | dec ecx |
315 | mov [(pci_code_32-OS_BASE)], cx ;limit 0-15 |
315 | mov [(pci_code_32-OS_BASE)], cx ;limit 0-15 |
316 | mov [(pci_data_32-OS_BASE)], cx ;limit 0-15 |
316 | mov [(pci_data_32-OS_BASE)], cx ;limit 0-15 |
317 | 317 | ||
318 | mov [(pci_code_32-OS_BASE)+2], bx ;base 0-15 |
318 | mov [(pci_code_32-OS_BASE)+2], bx ;base 0-15 |
319 | mov [(pci_data_32-OS_BASE)+2], bx ;base 0-15 |
319 | mov [(pci_data_32-OS_BASE)+2], bx ;base 0-15 |
320 | 320 | ||
321 | shr ebx, 16 |
321 | shr ebx, 16 |
322 | mov [(pci_code_32-OS_BASE)+4], bl ;base 16-23 |
322 | mov [(pci_code_32-OS_BASE)+4], bl ;base 16-23 |
323 | mov [(pci_data_32-OS_BASE)+4], bl ;base 16-23 |
323 | mov [(pci_data_32-OS_BASE)+4], bl ;base 16-23 |
324 | 324 | ||
325 | shr ecx, 16 |
325 | shr ecx, 16 |
326 | and cl, 0x0F |
326 | and cl, 0x0F |
327 | mov ch, bh |
327 | mov ch, bh |
328 | add cx, D32 |
328 | add cx, D32 |
329 | mov [(pci_code_32-OS_BASE)+6], cx ;lim 16-19 & |
329 | mov [(pci_code_32-OS_BASE)+6], cx ;lim 16-19 & |
330 | mov [(pci_data_32-OS_BASE)+6], cx ;base 24-31 |
330 | mov [(pci_data_32-OS_BASE)+6], cx ;base 24-31 |
331 | 331 | ||
332 | mov [(pci_bios_entry-OS_BASE)], edx |
332 | mov [(pci_bios_entry-OS_BASE)], edx |
333 | ; jmp .end |
333 | ; jmp .end |
334 | .PCI_BIOS32_not_found: |
334 | .PCI_BIOS32_not_found: |
335 | ; çäåñü äîëæíà çàïîëíÿòñÿ pci_emu_dat |
335 | ; çäåñü äîëæíà çàïîëíÿòñÿ pci_emu_dat |
336 | .BIOS32_not_found: |
336 | .BIOS32_not_found: |
337 | .end: |
337 | .end: |
338 | ret |
338 | ret |
339 | 339 | ||
340 | align 4 |
340 | align 4 |
341 | proc test_cpu |
341 | proc test_cpu |
342 | locals |
342 | locals |
343 | cpu_type dd ? |
343 | cpu_type dd ? |
344 | cpu_id dd ? |
344 | cpu_id dd ? |
345 | cpu_Intel dd ? |
345 | cpu_Intel dd ? |
346 | cpu_AMD dd ? |
346 | cpu_AMD dd ? |
347 | endl |
347 | endl |
348 | 348 | ||
349 | xor eax, eax |
349 | xor eax, eax |
350 | mov [cpu_type], eax |
350 | mov [cpu_type], eax |
351 | mov [cpu_caps-OS_BASE], eax |
351 | mov [cpu_caps-OS_BASE], eax |
352 | mov [cpu_caps+4-OS_BASE], eax |
352 | mov [cpu_caps+4-OS_BASE], eax |
353 | 353 | ||
354 | pushfd |
354 | pushfd |
355 | pop eax |
355 | pop eax |
356 | mov ecx, eax |
356 | mov ecx, eax |
357 | xor eax, 0x40000 |
357 | xor eax, 0x40000 |
358 | push eax |
358 | push eax |
359 | popfd |
359 | popfd |
360 | pushfd |
360 | pushfd |
361 | pop eax |
361 | pop eax |
362 | xor eax, ecx |
362 | xor eax, ecx |
363 | mov [cpu_type], CPU_386 |
363 | mov [cpu_type], CPU_386 |
364 | jz .end_cpuid |
364 | jz .end_cpuid |
365 | push ecx |
365 | push ecx |
366 | popfd |
366 | popfd |
367 | 367 | ||
368 | mov [cpu_type], CPU_486 |
368 | mov [cpu_type], CPU_486 |
369 | mov eax, ecx |
369 | mov eax, ecx |
370 | xor eax, 0x200000 |
370 | xor eax, 0x200000 |
371 | push eax |
371 | push eax |
372 | popfd |
372 | popfd |
373 | pushfd |
373 | pushfd |
374 | pop eax |
374 | pop eax |
375 | xor eax, ecx |
375 | xor eax, ecx |
376 | je .end_cpuid |
376 | je .end_cpuid |
377 | mov [cpu_id], 1 |
377 | mov [cpu_id], 1 |
378 | 378 | ||
379 | xor eax, eax |
379 | xor eax, eax |
380 | cpuid |
380 | cpuid |
381 | 381 | ||
382 | mov [cpu_vendor-OS_BASE], ebx |
382 | mov [cpu_vendor-OS_BASE], ebx |
383 | mov [cpu_vendor+4-OS_BASE], edx |
383 | mov [cpu_vendor+4-OS_BASE], edx |
384 | mov [cpu_vendor+8-OS_BASE], ecx |
384 | mov [cpu_vendor+8-OS_BASE], ecx |
385 | cmp ebx, dword [intel_str-OS_BASE] |
385 | cmp ebx, dword [intel_str-OS_BASE] |
386 | jne .check_AMD |
386 | jne .check_AMD |
387 | cmp edx, dword [intel_str+4-OS_BASE] |
387 | cmp edx, dword [intel_str+4-OS_BASE] |
388 | jne .check_AMD |
388 | jne .check_AMD |
389 | cmp ecx, dword [intel_str+8-OS_BASE] |
389 | cmp ecx, dword [intel_str+8-OS_BASE] |
390 | jne .check_AMD |
390 | jne .check_AMD |
391 | mov [cpu_Intel], 1 |
391 | mov [cpu_Intel], 1 |
392 | cmp eax, 1 |
392 | cmp eax, 1 |
393 | jl .end_cpuid |
393 | jl .end_cpuid |
394 | mov eax, 1 |
394 | mov eax, 1 |
395 | cpuid |
395 | cpuid |
396 | mov [cpu_sign-OS_BASE], eax |
396 | mov [cpu_sign-OS_BASE], eax |
397 | mov [cpu_info-OS_BASE], ebx |
397 | mov [cpu_info-OS_BASE], ebx |
398 | mov [cpu_caps-OS_BASE], edx |
398 | mov [cpu_caps-OS_BASE], edx |
399 | mov [cpu_caps+4-OS_BASE],ecx |
399 | mov [cpu_caps+4-OS_BASE],ecx |
400 | 400 | ||
401 | shr eax, 8 |
401 | shr eax, 8 |
402 | and eax, 0x0f |
402 | and eax, 0x0f |
403 | ret |
403 | ret |
404 | .end_cpuid: |
404 | .end_cpuid: |
405 | mov eax, [cpu_type] |
405 | mov eax, [cpu_type] |
406 | ret |
406 | ret |
407 | 407 | ||
408 | .check_AMD: |
408 | .check_AMD: |
409 | cmp ebx, dword [AMD_str-OS_BASE] |
409 | cmp ebx, dword [AMD_str-OS_BASE] |
410 | jne .unknown |
410 | jne .unknown |
411 | cmp edx, dword [AMD_str+4-OS_BASE] |
411 | cmp edx, dword [AMD_str+4-OS_BASE] |
412 | jne .unknown |
412 | jne .unknown |
413 | cmp ecx, dword [AMD_str+8-OS_BASE] |
413 | cmp ecx, dword [AMD_str+8-OS_BASE] |
414 | jne .unknown |
414 | jne .unknown |
415 | mov [cpu_AMD], 1 |
415 | mov [cpu_AMD], 1 |
416 | cmp eax, 1 |
416 | cmp eax, 1 |
417 | jl .unknown |
417 | jl .unknown |
418 | mov eax, 1 |
418 | mov eax, 1 |
419 | cpuid |
419 | cpuid |
420 | mov [cpu_sign-OS_BASE], eax |
420 | mov [cpu_sign-OS_BASE], eax |
421 | mov [cpu_info-OS_BASE], ebx |
421 | mov [cpu_info-OS_BASE], ebx |
422 | mov [cpu_caps-OS_BASE], edx |
422 | mov [cpu_caps-OS_BASE], edx |
423 | mov [cpu_caps+4-OS_BASE],ecx |
423 | mov [cpu_caps+4-OS_BASE],ecx |
424 | shr eax, 8 |
424 | shr eax, 8 |
425 | and eax, 0x0f |
425 | and eax, 0x0f |
426 | ret |
426 | ret |
427 | .unknown: |
427 | .unknown: |
428 | mov eax, 1 |
428 | mov eax, 1 |
429 | cpuid |
429 | cpuid |
430 | mov [cpu_sign-OS_BASE], eax |
430 | mov [cpu_sign-OS_BASE], eax |
431 | mov [cpu_info-OS_BASE], ebx |
431 | mov [cpu_info-OS_BASE], ebx |
432 | mov [cpu_caps-OS_BASE], edx |
432 | mov [cpu_caps-OS_BASE], edx |
433 | mov [cpu_caps+4-OS_BASE],ecx |
433 | mov [cpu_caps+4-OS_BASE],ecx |
434 | shr eax, 8 |
434 | shr eax, 8 |
435 | and eax, 0x0f |
435 | and eax, 0x0f |
436 | ret |
436 | ret |
437 | endp |
437 | endp |