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