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