Subversion Repositories Kolibri OS

Rev

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