Subversion Repositories Kolibri OS

Rev

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, 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
           movsd
117
           movsd
118
           movsd
119
           ret
388 serge 120
endp
121
122
 
400 serge 123
 
124
 
388 serge 125
proc init_page_map
126
127
 
128
           mov ecx, ((HEAP_BASE-OS_BASE)/4096)/32      ;384/4
394 serge 129
           mov ebx, ecx
388 serge 130
           xor eax,eax
131
           cld
132
           rep stosd
133
134
 
135
           mov ecx, [pg_data.pagemap_size-OS_BASE]
136
           sub ecx, ebx
137
           shr ecx, 2
138
           rep stosd
139
140
 
141
           mov edx, [pg_data.pages_count-OS_BASE]
142
           mov ecx, [pg_data.kernel_tables-OS_BASE]
143
           add ecx, ((HEAP_BASE-OS_BASE)/4096) and 31
394 serge 144
           sub edx, (HEAP_BASE-OS_BASE)/4096
145
           sub edx, ecx
388 serge 146
           mov [pg_data.pages_free-OS_BASE], edx
147
148
 
149
           mov ebx, ecx
150
           shr ecx, 5
151
           rep stosd
152
153
 
154
           mov ecx, ebx
155
           and ecx, 31
156
           shl eax, cl
157
           mov [edi], eax
397 serge 158
           add edi, OS_BASE
388 serge 159
           mov [page_start-OS_BASE], edi;
400 serge 160
388 serge 161
 
162
           add ebx, [pg_data.pagemap_size-OS_BASE]
163
           mov [page_end-OS_BASE], ebx
164
165
 
166
167
 
168
endp
169
170
 
171
proc test_cpu
172
           locals
173
              cpu_type   dd ?
174
              cpu_id     dd ?
175
              cpu_Intel  dd ?
176
              cpu_AMD    dd ?
177
           endl
178
179
 
180
           xor eax, eax
181
           mov [cpu_caps-OS_BASE], eax
182
           mov [cpu_caps+4-OS_BASE], eax
183
184
 
185
           pop eax
186
           mov ecx, eax
187
           xor eax, 0x40000
188
           push eax
189
           popfd
190
           pushfd
191
           pop eax
192
           xor eax, ecx
193
           mov [cpu_type], CPU_386
194
           jz .end_cpuid
195
           push ecx
196
           popfd
197
198
 
199
           mov eax, ecx
200
           xor eax, 0x200000
201
           push eax
202
           popfd
203
           pushfd
204
           pop eax
205
           xor eax, ecx
206
           je .end_cpuid
207
           mov [cpu_id], 1
208
209
 
210
           cpuid
211
212
 
213
           mov [cpu_vendor+4-OS_BASE], edx
214
           mov [cpu_vendor+8-OS_BASE], ecx
215
           cmp ebx, dword [intel_str-OS_BASE]
216
           jne .check_AMD
217
           cmp edx, dword [intel_str+4-OS_BASE]
218
           jne .check_AMD
219
           cmp ecx, dword [intel_str+8-OS_BASE]
220
           jne .check_AMD
221
           mov [cpu_Intel], 1
222
           cmp eax, 1
223
           jl .end_cpuid
224
           mov eax, 1
225
           cpuid
226
           mov [cpu_sign-OS_BASE], eax
227
           mov [cpu_info-OS_BASE],  ebx
228
           mov [cpu_caps-OS_BASE],  edx
229
           mov [cpu_caps+4-OS_BASE],ecx
230
231
 
232
           and eax, 0x0f
233
           ret
234
.end_cpuid:
235
           mov eax, [cpu_type]
236
           ret
237
238
 
239
           cmp ebx, dword [AMD_str-OS_BASE]
240
           jne .unknown
241
           cmp edx, dword [AMD_str+4-OS_BASE]
242
           jne .unknown
243
           cmp ecx, dword [AMD_str+8-OS_BASE]
244
           jne .unknown
245
           mov [cpu_AMD], 1
246
           cmp eax, 1
247
           jl .unknown
248
           mov eax, 1
249
           cpuid
250
           mov [cpu_sign-OS_BASE], eax
251
           mov [cpu_info-OS_BASE],  ebx
252
           mov [cpu_caps-OS_BASE],  edx
253
           mov [cpu_caps+4-OS_BASE],ecx
254
           shr eax, 8
255
           and eax, 0x0f
256
           ret
257
.unknown:
258
           mov eax, 1
259
           cpuid
260
           mov [cpu_sign-OS_BASE], eax
261
           mov [cpu_info-OS_BASE],  ebx
262
           mov [cpu_caps-OS_BASE],  edx
263
           mov [cpu_caps+4-OS_BASE],ecx
264
           shr eax, 8
265
           and eax, 0x0f
266
           ret
267
endp
268