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