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