Rev 394 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
388 | serge | 1 | |
2 | MEM_WC equ 1 ;write combined memory |
||
3 | MEM_UC equ 0 ;uncached memory |
||
4 | |||
5 | |||
6 | |||
7 | |||
8 | proc mem_test |
||
9 | |||
10 | |||
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 | |||
17 | mov ebx, 'TEST' |
||
18 | @@: |
||
19 | add edi, 0x400000 |
||
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 | |||
27 | mov cr0, eax |
||
28 | mov eax, edi |
||
29 | ret |
||
30 | endp |
||
31 | |||
32 | |||
33 | proc init_mem |
||
34 | mov eax, [MEM_AMOUNT-OS_BASE] |
||
35 | mov [pg_data.mem_amount-OS_BASE], eax |
||
36 | mov [pg_data.kernel_max-OS_BASE], eax |
||
37 | |||
38 | |||
39 | mov edx, eax |
||
40 | mov [pg_data.pages_count-OS_BASE], eax |
||
41 | mov [pg_data.kernel_pages-OS_BASE], eax |
||
42 | |||
43 | |||
44 | mov [pg_data.pagemap_size-OS_BASE], eax |
||
45 | |||
46 | |||
47 | cmp edx, 3 |
||
48 | ja @f |
||
49 | inc edx ;at least 4Mb for kernel heap |
||
50 | @@: |
||
51 | mov [pg_data.kernel_tables-OS_BASE], edx |
||
52 | |||
53 | |||
54 | mov edi, sys_pgdir-OS_BASE |
||
55 | mov ecx, 2048 |
||
56 | cld |
||
57 | rep stosd |
||
58 | |||
59 | |||
60 | ; bt [cpu_caps], CAPS_PSE |
||
61 | ; jnc .no_PSE |
||
62 | |||
63 | |||
64 | or ebx, CR4_PSE |
||
65 | mov eax, PG_LARGE+PG_SW |
||
66 | bt [cpu_caps-OS_BASE], CAPS_PGE |
||
67 | jnc @F |
||
68 | or eax, PG_GLOBAL |
||
69 | or ebx, CR4_PGE |
||
70 | @@: |
||
71 | mov cr4, ebx |
||
72 | sub [pg_data.kernel_tables-OS_BASE], 2 |
||
73 | |||
74 | |||
75 | mov [edx+(OS_BASE shr 20)], eax |
||
394 | serge | 76 | add eax, 0x00400000 |
388 | serge | 77 | |
78 | |||
79 | mov [edx+(OS_BASE shr 20)+4], eax |
||
394 | serge | 80 | add eax, 0x00400000 |
388 | serge | 81 | |
82 | |||
83 | mov [edx+(OS_BASE shr 20)+8], eax |
||
394 | serge | 84 | add eax, 0x00400000 |
388 | serge | 85 | |
86 | |||
87 | mov [edx+(OS_BASE shr 20)+12], eax |
||
394 | serge | 88 | add edx, (OS_BASE shr 20)+16 |
89 | add eax, 0x00400000 |
||
388 | serge | 90 | |
91 | |||
92 | ; mov ecx, (HEAP_BASE-0x800000)/4096 |
||
93 | ; jmp .map_low |
||
94 | ;.no_PSE: |
||
95 | ; mov eax, PG_SW |
||
96 | ; mov ecx, HEAP_BASE/4096 |
||
97 | ;.map_low: |
||
98 | mov edi, tmp_page_tab |
||
99 | ;@@: ; |
||
100 | ; stosd |
||
101 | ; add eax, 0x1000 |
||
102 | ; dec ecx |
||
103 | ; jnz @B |
||
104 | |||
105 | |||
106 | shl ecx, 10 |
||
107 | xor eax, eax |
||
108 | rep stosd |
||
109 | |||
110 | |||
111 | mov eax, tmp_page_tab+PG_SW |
||
112 | mov edi, edx |
||
113 | |||
114 | |||
115 | |||
116 | |||
117 | add eax, 0x1000 |
||
118 | dec ecx |
||
119 | jnz .map_kernel_tabs |
||
120 | |||
121 | |||
122 | ret |
||
123 | endp |
||
124 | |||
125 | |||
126 | proc init_page_map |
||
127 | |||
128 | |||
129 | mov ecx, ((HEAP_BASE-OS_BASE)/4096)/32 ;384/4 |
||
394 | serge | 130 | mov ebx, ecx |
388 | serge | 131 | xor eax,eax |
132 | cld |
||
133 | rep stosd |
||
134 | |||
135 | |||
136 | mov ecx, [pg_data.pagemap_size-OS_BASE] |
||
137 | sub ecx, ebx |
||
138 | shr ecx, 2 |
||
139 | rep stosd |
||
140 | |||
141 | |||
142 | mov edx, [pg_data.pages_count-OS_BASE] |
||
143 | mov ecx, [pg_data.kernel_tables-OS_BASE] |
||
144 | add ecx, ((HEAP_BASE-OS_BASE)/4096) and 31 |
||
394 | serge | 145 | sub edx, (HEAP_BASE-OS_BASE)/4096 |
146 | sub edx, ecx |
||
388 | serge | 147 | mov [pg_data.pages_free-OS_BASE], edx |
148 | |||
149 | |||
150 | mov ebx, ecx |
||
151 | shr ecx, 5 |
||
152 | rep stosd |
||
153 | |||
154 | |||
155 | mov ecx, ebx |
||
156 | and ecx, 31 |
||
157 | shl eax, cl |
||
158 | mov [edi], eax |
||
397 | serge | 159 | add edi, OS_BASE |
388 | serge | 160 | mov [page_start-OS_BASE], edi; sys_pgmap+384 |
161 | |||
162 | |||
163 | add ebx, [pg_data.pagemap_size-OS_BASE] |
||
164 | mov [page_end-OS_BASE], ebx |
||
165 | |||
166 | |||
167 | |||
168 | |||
169 | endp |
||
170 | |||
171 | |||
172 | proc test_cpu |
||
173 | locals |
||
174 | cpu_type dd ? |
||
175 | cpu_id dd ? |
||
176 | cpu_Intel dd ? |
||
177 | cpu_AMD dd ? |
||
178 | endl |
||
179 | |||
180 | |||
181 | xor eax, eax |
||
182 | mov [cpu_caps-OS_BASE], eax |
||
183 | mov [cpu_caps+4-OS_BASE], eax |
||
184 | |||
185 | |||
186 | pop eax |
||
187 | mov ecx, eax |
||
188 | xor eax, 0x40000 |
||
189 | push eax |
||
190 | popfd |
||
191 | pushfd |
||
192 | pop eax |
||
193 | xor eax, ecx |
||
194 | mov [cpu_type], CPU_386 |
||
195 | jz .end_cpuid |
||
196 | push ecx |
||
197 | popfd |
||
198 | |||
199 | |||
200 | mov eax, ecx |
||
201 | xor eax, 0x200000 |
||
202 | push eax |
||
203 | popfd |
||
204 | pushfd |
||
205 | pop eax |
||
206 | xor eax, ecx |
||
207 | je .end_cpuid |
||
208 | mov [cpu_id], 1 |
||
209 | |||
210 | |||
211 | cpuid |
||
212 | |||
213 | |||
214 | mov [cpu_vendor+4-OS_BASE], edx |
||
215 | mov [cpu_vendor+8-OS_BASE], ecx |
||
216 | cmp ebx, dword [intel_str-OS_BASE] |
||
217 | jne .check_AMD |
||
218 | cmp edx, dword [intel_str+4-OS_BASE] |
||
219 | jne .check_AMD |
||
220 | cmp ecx, dword [intel_str+8-OS_BASE] |
||
221 | jne .check_AMD |
||
222 | mov [cpu_Intel], 1 |
||
223 | cmp eax, 1 |
||
224 | jl .end_cpuid |
||
225 | mov eax, 1 |
||
226 | cpuid |
||
227 | mov [cpu_sign-OS_BASE], eax |
||
228 | mov [cpu_info-OS_BASE], ebx |
||
229 | mov [cpu_caps-OS_BASE], edx |
||
230 | mov [cpu_caps+4-OS_BASE],ecx |
||
231 | |||
232 | |||
233 | and eax, 0x0f |
||
234 | ret |
||
235 | .end_cpuid: |
||
236 | mov eax, [cpu_type] |
||
237 | ret |
||
238 | |||
239 | |||
240 | cmp ebx, dword [AMD_str-OS_BASE] |
||
241 | jne .unknown |
||
242 | cmp edx, dword [AMD_str+4-OS_BASE] |
||
243 | jne .unknown |
||
244 | cmp ecx, dword [AMD_str+8-OS_BASE] |
||
245 | jne .unknown |
||
246 | mov [cpu_AMD], 1 |
||
247 | cmp eax, 1 |
||
248 | jl .unknown |
||
249 | mov eax, 1 |
||
250 | cpuid |
||
251 | mov [cpu_sign-OS_BASE], eax |
||
252 | mov [cpu_info-OS_BASE], ebx |
||
253 | mov [cpu_caps-OS_BASE], edx |
||
254 | mov [cpu_caps+4-OS_BASE],ecx |
||
255 | shr eax, 8 |
||
256 | and eax, 0x0f |
||
257 | ret |
||
258 | .unknown: |
||
259 | mov eax, 1 |
||
260 | cpuid |
||
261 | mov [cpu_sign-OS_BASE], eax |
||
262 | mov [cpu_info-OS_BASE], ebx |
||
263 | mov [cpu_caps-OS_BASE], edx |
||
264 | mov [cpu_caps+4-OS_BASE],ecx |
||
265 | shr eax, 8 |
||
266 | and eax, 0x0f |
||
267 | ret |
||
268 | endp |
||
269 |