Rev 519 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
465 | serge | 1 | $Revision: 519 $ |
2 | |||
3 | MEM_WB equ 6 ;write-back memory |
||
4 | MEM_WC equ 1 ;write combined memory |
||
5 | MEM_UC equ 0 ;uncached memory |
||
6 | |||
7 | align 4 |
||
8 | proc mem_test |
||
9 | |||
10 | mov eax, cr0 |
||
11 | and eax, not (CR0_CD+CR0_NW) |
||
12 | or eax, CR0_CD ;disable caching |
||
13 | mov cr0, eax |
||
14 | wbinvd ;invalidate cache |
||
15 | |||
16 | xor edi, edi |
||
17 | mov ebx, 'TEST' |
||
18 | @@: |
||
19 | add edi, 0x100000 |
||
20 | xchg ebx, dword [edi] |
||
21 | cmp dword [edi], 'TEST' |
||
22 | xchg ebx, dword [edi] |
||
23 | je @b |
||
24 | mov [MEM_AMOUNT-OS_BASE], edi |
||
25 | |||
26 | and eax, not (CR0_CD+CR0_NW) ;enable caching |
||
27 | mov cr0, eax |
||
28 | mov eax, edi |
||
29 | ret |
||
30 | endp |
||
31 | |||
32 | align 4 |
||
33 | proc init_mem |
||
34 | mov eax, [MEM_AMOUNT-OS_BASE] |
||
35 | mov [pg_data.mem_amount-OS_BASE], eax |
||
36 | |||
37 | shr eax, 12 |
||
38 | mov edx, eax |
||
39 | mov [pg_data.pages_count-OS_BASE], eax |
||
40 | shr eax, 3 |
||
41 | mov [pg_data.pagemap_size-OS_BASE], eax |
||
42 | |||
513 | serge | 43 | add eax, (sys_pgmap-OS_BASE)+4095 |
44 | and eax, not 4095 |
||
45 | mov [tmp_page_tabs], eax |
||
46 | |||
465 | serge | 47 | cmp edx, (OS_BASE/4096) |
48 | jbe @F |
||
49 | mov edx, (OS_BASE/4096) |
||
50 | jmp .set |
||
51 | @@: |
||
52 | cmp edx, (HEAP_MIN_SIZE/4096) |
||
53 | jae .set |
||
54 | mov edx, (HEAP_MIN_SIZE/4096) |
||
55 | .set: |
||
56 | mov [pg_data.kernel_pages-OS_BASE], edx |
||
57 | shr edx, 10 |
||
58 | mov [pg_data.kernel_tables-OS_BASE], edx |
||
59 | |||
60 | xor eax, eax |
||
61 | mov edi, sys_pgdir-OS_BASE |
||
62 | mov ecx, 4096/4 |
||
63 | cld |
||
64 | rep stosd |
||
65 | |||
66 | mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20) |
||
67 | bt [cpu_caps-OS_BASE], CAPS_PSE |
||
68 | jnc .no_PSE |
||
69 | |||
70 | mov ebx, cr4 |
||
71 | or ebx, CR4_PSE |
||
72 | mov eax, PG_LARGE+PG_SW |
||
73 | |||
519 | serge | 74 | ; bt [cpu_caps-OS_BASE], CAPS_PGE |
75 | ; jnc @F |
||
465 | serge | 76 | |
519 | serge | 77 | ; or eax, PG_GLOBAL |
78 | ; or ebx, CR4_PGE |
||
79 | ; |
||
80 | ;@@: |
||
465 | serge | 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 |
||
171 | proc test_cpu |
||
172 | locals |
||
173 | cpu_type dd ? |
||
174 | cpu_id dd ? |
||
175 | cpu_Intel dd ? |
||
176 | cpu_AMD dd ? |
||
177 | endl |
||
178 | |||
179 | mov [cpu_type], 0 |
||
180 | xor eax, eax |
||
181 | mov [cpu_caps-OS_BASE], eax |
||
182 | mov [cpu_caps+4-OS_BASE], eax |
||
183 | |||
184 | pushfd |
||
185 | pop eax |
||
186 | mov ecx, eax |
||
187 | xor eax, 0x40000 |
||
188 | push eax |
||
189 | popfd |
||
190 | pushfd |
||
191 | pop eax |
||
192 | xor eax, ecx |
||
193 | mov [cpu_type], CPU_386 |
||
194 | jz .end_cpuid |
||
195 | push ecx |
||
196 | popfd |
||
197 | |||
198 | mov [cpu_type], CPU_486 |
||
199 | mov eax, ecx |
||
200 | xor eax, 0x200000 |
||
201 | push eax |
||
202 | popfd |
||
203 | pushfd |
||
204 | pop eax |
||
205 | xor eax, ecx |
||
206 | je .end_cpuid |
||
207 | mov [cpu_id], 1 |
||
208 | |||
209 | xor eax, eax |
||
210 | cpuid |
||
211 | |||
212 | mov [cpu_vendor-OS_BASE], ebx |
||
213 | mov [cpu_vendor+4-OS_BASE], edx |
||
214 | mov [cpu_vendor+8-OS_BASE], ecx |
||
215 | cmp ebx, dword [intel_str-OS_BASE] |
||
216 | jne .check_AMD |
||
217 | cmp edx, dword [intel_str+4-OS_BASE] |
||
218 | jne .check_AMD |
||
219 | cmp ecx, dword [intel_str+8-OS_BASE] |
||
220 | jne .check_AMD |
||
221 | mov [cpu_Intel], 1 |
||
222 | cmp eax, 1 |
||
223 | jl .end_cpuid |
||
224 | mov eax, 1 |
||
225 | cpuid |
||
226 | mov [cpu_sign-OS_BASE], eax |
||
227 | mov [cpu_info-OS_BASE], ebx |
||
228 | mov [cpu_caps-OS_BASE], edx |
||
229 | mov [cpu_caps+4-OS_BASE],ecx |
||
230 | |||
231 | shr eax, 8 |
||
232 | and eax, 0x0f |
||
233 | ret |
||
234 | .end_cpuid: |
||
235 | mov eax, [cpu_type] |
||
236 | ret |
||
237 | |||
238 | .check_AMD: |
||
239 | cmp ebx, dword [AMD_str-OS_BASE] |
||
240 | jne .unknown |
||
241 | cmp edx, dword [AMD_str+4-OS_BASE] |
||
242 | jne .unknown |
||
243 | cmp ecx, dword [AMD_str+8-OS_BASE] |
||
244 | jne .unknown |
||
245 | mov [cpu_AMD], 1 |
||
246 | cmp eax, 1 |
||
247 | jl .unknown |
||
248 | mov eax, 1 |
||
249 | cpuid |
||
250 | mov [cpu_sign-OS_BASE], eax |
||
251 | mov [cpu_info-OS_BASE], ebx |
||
252 | mov [cpu_caps-OS_BASE], edx |
||
253 | mov [cpu_caps+4-OS_BASE],ecx |
||
254 | shr eax, 8 |
||
255 | and eax, 0x0f |
||
256 | ret |
||
257 | .unknown: |
||
258 | mov eax, 1 |
||
259 | cpuid |
||
260 | mov [cpu_sign-OS_BASE], eax |
||
261 | mov [cpu_info-OS_BASE], ebx |
||
262 | mov [cpu_caps-OS_BASE], edx |
||
263 | mov [cpu_caps+4-OS_BASE],ecx |
||
264 | shr eax, 8 |
||
265 | and eax, 0x0f |
||
266 | ret |
||
267 | endp |
||
268 |