Rev 593 | Rev 756 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
750 | victor | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
593 | mikedld | 7 | |
465 | serge | 8 | $Revision: 750 $ |
9 | |||
593 | mikedld | 10 | |
465 | serge | 11 | MEM_WB equ 6 ;write-back memory |
12 | MEM_WC equ 1 ;write combined memory |
||
13 | MEM_UC equ 0 ;uncached memory |
||
14 | |||
15 | align 4 |
||
16 | proc mem_test |
||
17 | |||
18 | mov eax, cr0 |
||
19 | and eax, not (CR0_CD+CR0_NW) |
||
20 | or eax, CR0_CD ;disable caching |
||
21 | mov cr0, eax |
||
22 | wbinvd ;invalidate cache |
||
23 | |||
24 | xor edi, edi |
||
25 | mov ebx, 'TEST' |
||
26 | @@: |
||
27 | add edi, 0x100000 |
||
28 | xchg ebx, dword [edi] |
||
29 | cmp dword [edi], 'TEST' |
||
30 | xchg ebx, dword [edi] |
||
31 | je @b |
||
32 | mov [MEM_AMOUNT-OS_BASE], edi |
||
33 | |||
34 | and eax, not (CR0_CD+CR0_NW) ;enable caching |
||
35 | mov cr0, eax |
||
36 | mov eax, edi |
||
37 | ret |
||
38 | endp |
||
39 | |||
40 | align 4 |
||
41 | proc init_mem |
||
42 | mov eax, [MEM_AMOUNT-OS_BASE] |
||
43 | mov [pg_data.mem_amount-OS_BASE], eax |
||
44 | |||
45 | shr eax, 12 |
||
46 | mov edx, eax |
||
47 | mov [pg_data.pages_count-OS_BASE], eax |
||
48 | shr eax, 3 |
||
49 | mov [pg_data.pagemap_size-OS_BASE], eax |
||
50 | |||
513 | serge | 51 | add eax, (sys_pgmap-OS_BASE)+4095 |
52 | and eax, not 4095 |
||
53 | mov [tmp_page_tabs], eax |
||
54 | |||
465 | serge | 55 | cmp edx, (OS_BASE/4096) |
56 | jbe @F |
||
57 | mov edx, (OS_BASE/4096) |
||
58 | jmp .set |
||
59 | @@: |
||
60 | cmp edx, (HEAP_MIN_SIZE/4096) |
||
61 | jae .set |
||
62 | mov edx, (HEAP_MIN_SIZE/4096) |
||
63 | .set: |
||
64 | mov [pg_data.kernel_pages-OS_BASE], edx |
||
65 | shr edx, 10 |
||
66 | mov [pg_data.kernel_tables-OS_BASE], edx |
||
67 | |||
68 | xor eax, eax |
||
69 | mov edi, sys_pgdir-OS_BASE |
||
70 | mov ecx, 4096/4 |
||
71 | cld |
||
72 | rep stosd |
||
73 | |||
74 | mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20) |
||
75 | bt [cpu_caps-OS_BASE], CAPS_PSE |
||
76 | jnc .no_PSE |
||
77 | |||
78 | mov ebx, cr4 |
||
79 | or ebx, CR4_PSE |
||
80 | mov eax, PG_LARGE+PG_SW |
||
81 | mov cr4, ebx |
||
513 | serge | 82 | dec [pg_data.kernel_tables-OS_BASE] |
465 | serge | 83 | |
84 | mov [edx], eax |
||
85 | add eax, 0x00400000 |
||
86 | add edx, 4 |
||
87 | |||
88 | mov eax, 0x400000+PG_SW |
||
513 | serge | 89 | mov ecx, [tmp_page_tabs] |
90 | sub ecx, 0x400000 |
||
91 | shr ecx, 12 ;ecx/=4096 |
||
465 | serge | 92 | jmp .map_low |
93 | .no_PSE: |
||
94 | mov eax, PG_SW |
||
513 | serge | 95 | mov ecx, [tmp_page_tabs] |
96 | shr ecx, 12 |
||
465 | serge | 97 | .map_low: |
513 | serge | 98 | mov edi, [tmp_page_tabs] |
465 | serge | 99 | @@: ; |
100 | stosd |
||
101 | add eax, 0x1000 |
||
102 | dec ecx |
||
103 | jnz @B |
||
104 | |||
105 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
||
106 | shl ecx, 10 |
||
107 | xor eax, eax |
||
108 | rep stosd |
||
109 | |||
110 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
||
513 | serge | 111 | mov eax, [tmp_page_tabs] |
112 | or eax, PG_SW |
||
465 | serge | 113 | mov edi, edx |
114 | |||
115 | .map_kernel_tabs: |
||
116 | |||
117 | stosd |
||
118 | add eax, 0x1000 |
||
119 | dec ecx |
||
120 | jnz .map_kernel_tabs |
||
121 | |||
122 | mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE |
||
123 | |||
124 | mov edi, (sys_pgdir-OS_BASE) |
||
125 | lea esi, [edi+(OS_BASE shr 20)] |
||
519 | serge | 126 | movsd |
127 | movsd |
||
465 | serge | 128 | ret |
129 | endp |
||
130 | |||
131 | align 4 |
||
132 | proc init_page_map |
||
133 | |||
134 | mov edi, sys_pgmap-OS_BASE |
||
135 | mov ecx, [pg_data.pagemap_size-OS_BASE] |
||
136 | shr ecx, 2 |
||
513 | serge | 137 | or eax, -1 |
138 | cld |
||
465 | serge | 139 | rep stosd |
140 | |||
513 | serge | 141 | mov ecx, [tmp_page_tabs] |
465 | serge | 142 | mov edx, [pg_data.pages_count-OS_BASE] |
513 | serge | 143 | shr ecx, 12 |
144 | add ecx, [pg_data.kernel_tables-OS_BASE] |
||
465 | serge | 145 | sub edx, ecx |
146 | mov [pg_data.pages_free-OS_BASE], edx |
||
147 | |||
513 | serge | 148 | mov edi, sys_pgmap-OS_BASE |
465 | serge | 149 | mov ebx, ecx |
150 | shr ecx, 5 |
||
513 | serge | 151 | xor eax, eax |
465 | serge | 152 | rep stosd |
153 | |||
154 | not eax |
||
155 | mov ecx, ebx |
||
156 | and ecx, 31 |
||
157 | shl eax, cl |
||
158 | mov [edi], eax |
||
159 | add edi, OS_BASE |
||
160 | mov [page_start-OS_BASE], edi; |
||
161 | |||
162 | mov ebx, sys_pgmap |
||
163 | add ebx, [pg_data.pagemap_size-OS_BASE] |
||
164 | mov [page_end-OS_BASE], ebx |
||
165 | |||
166 | mov [pg_data.pg_mutex-OS_BASE], 0 |
||
167 | ret |
||
168 | endp |
||
169 | |||
170 | align 4 |
||
586 | serge | 171 | |
172 | init_BIOS32: |
||
173 | mov edi, 0xE0000 |
||
174 | .pcibios_nxt: |
||
175 | cmp dword[edi], '_32_' ; "magic" word |
||
176 | je .BIOS32_found |
||
177 | .pcibios_nxt2: |
||
178 | add edi, 0x10 |
||
179 | cmp edi, 0xFFFF0 |
||
180 | je .BIOS32_not_found |
||
181 | jmp .pcibios_nxt |
||
182 | .BIOS32_found: ; magic word found, check control summ |
||
183 | |||
184 | movzx ecx, byte[edi + 9] |
||
185 | shl ecx, 4 |
||
186 | mov esi, edi |
||
187 | xor eax, eax |
||
188 | cld ; paranoia |
||
189 | @@: lodsb |
||
190 | add ah, al |
||
191 | loop @b |
||
192 | jnz .pcibios_nxt2 ; control summ must be zero |
||
193 | ; BIOS32 service found ! |
||
194 | mov ebp, [edi + 4] |
||
195 | mov [bios32_entry], ebp |
||
196 | ; check PCI BIOS present |
||
197 | mov eax, '$PCI' |
||
198 | xor ebx, ebx |
||
199 | push cs ; special for 'ret far' from BIOS |
||
200 | call ebp |
||
201 | test al, al |
||
202 | jnz .PCI_BIOS32_not_found |
||
203 | |||
204 | ; здесь создаются дискрипторы для PCI BIOS |
||
205 | |||
206 | add ebx, OS_BASE |
||
207 | dec ecx |
||
208 | mov [(pci_code_32-OS_BASE)], cx ;limit 0-15 |
||
209 | mov [(pci_data_32-OS_BASE)], cx ;limit 0-15 |
||
210 | |||
211 | mov [(pci_code_32-OS_BASE)+2], bx ;base 0-15 |
||
212 | mov [(pci_data_32-OS_BASE)+2], bx ;base 0-15 |
||
213 | |||
214 | shr ebx, 16 |
||
215 | mov [(pci_code_32-OS_BASE)+4], bl ;base 16-23 |
||
216 | mov [(pci_data_32-OS_BASE)+4], bl ;base 16-23 |
||
217 | |||
218 | shr ecx, 16 |
||
219 | and cl, 0x0F |
||
220 | mov ch, bh |
||
221 | add cx, D32 |
||
222 | mov [(pci_code_32-OS_BASE)+6], cx ;lim 16-19 & |
||
223 | mov [(pci_data_32-OS_BASE)+6], cx ;base 24-31 |
||
224 | |||
225 | mov [(pci_bios_entry-OS_BASE)], edx |
||
226 | ; jmp .end |
||
227 | .PCI_BIOS32_not_found: |
||
228 | ; здесь должна заполнятся pci_emu_dat |
||
229 | .BIOS32_not_found: |
||
230 | .end: |
||
231 | |||
232 | |||
233 | align 4 |
||
465 | serge | 234 | proc test_cpu |
235 | locals |
||
236 | cpu_type dd ? |
||
237 | cpu_id dd ? |
||
238 | cpu_Intel dd ? |
||
239 | cpu_AMD dd ? |
||
240 | endl |
||
241 | |||
242 | mov [cpu_type], 0 |
||
243 | xor eax, eax |
||
244 | mov [cpu_caps-OS_BASE], eax |
||
245 | mov [cpu_caps+4-OS_BASE], eax |
||
246 | |||
247 | pushfd |
||
248 | pop eax |
||
249 | mov ecx, eax |
||
250 | xor eax, 0x40000 |
||
251 | push eax |
||
252 | popfd |
||
253 | pushfd |
||
254 | pop eax |
||
255 | xor eax, ecx |
||
256 | mov [cpu_type], CPU_386 |
||
257 | jz .end_cpuid |
||
258 | push ecx |
||
259 | popfd |
||
260 | |||
261 | mov [cpu_type], CPU_486 |
||
262 | mov eax, ecx |
||
263 | xor eax, 0x200000 |
||
264 | push eax |
||
265 | popfd |
||
266 | pushfd |
||
267 | pop eax |
||
268 | xor eax, ecx |
||
269 | je .end_cpuid |
||
270 | mov [cpu_id], 1 |
||
271 | |||
272 | xor eax, eax |
||
273 | cpuid |
||
274 | |||
275 | mov [cpu_vendor-OS_BASE], ebx |
||
276 | mov [cpu_vendor+4-OS_BASE], edx |
||
277 | mov [cpu_vendor+8-OS_BASE], ecx |
||
278 | cmp ebx, dword [intel_str-OS_BASE] |
||
279 | jne .check_AMD |
||
280 | cmp edx, dword [intel_str+4-OS_BASE] |
||
281 | jne .check_AMD |
||
282 | cmp ecx, dword [intel_str+8-OS_BASE] |
||
283 | jne .check_AMD |
||
284 | mov [cpu_Intel], 1 |
||
285 | cmp eax, 1 |
||
286 | jl .end_cpuid |
||
287 | mov eax, 1 |
||
288 | cpuid |
||
289 | mov [cpu_sign-OS_BASE], eax |
||
290 | mov [cpu_info-OS_BASE], ebx |
||
291 | mov [cpu_caps-OS_BASE], edx |
||
292 | mov [cpu_caps+4-OS_BASE],ecx |
||
293 | |||
294 | shr eax, 8 |
||
295 | and eax, 0x0f |
||
296 | ret |
||
297 | .end_cpuid: |
||
298 | mov eax, [cpu_type] |
||
299 | ret |
||
300 | |||
301 | .check_AMD: |
||
302 | cmp ebx, dword [AMD_str-OS_BASE] |
||
303 | jne .unknown |
||
304 | cmp edx, dword [AMD_str+4-OS_BASE] |
||
305 | jne .unknown |
||
306 | cmp ecx, dword [AMD_str+8-OS_BASE] |
||
307 | jne .unknown |
||
308 | mov [cpu_AMD], 1 |
||
309 | cmp eax, 1 |
||
310 | jl .unknown |
||
311 | mov eax, 1 |
||
312 | cpuid |
||
313 | mov [cpu_sign-OS_BASE], eax |
||
314 | mov [cpu_info-OS_BASE], ebx |
||
315 | mov [cpu_caps-OS_BASE], edx |
||
316 | mov [cpu_caps+4-OS_BASE],ecx |
||
317 | shr eax, 8 |
||
318 | and eax, 0x0f |
||
319 | ret |
||
320 | .unknown: |
||
321 | mov eax, 1 |
||
322 | cpuid |
||
323 | mov [cpu_sign-OS_BASE], eax |
||
324 | mov [cpu_info-OS_BASE], ebx |
||
325 | mov [cpu_caps-OS_BASE], edx |
||
326 | mov [cpu_caps+4-OS_BASE],ecx |
||
327 | shr eax, 8 |
||
328 | and eax, 0x0f |
||
329 | ret |
||
330 | endp |
||
331 |