Subversion Repositories Kolibri OS

Rev

Rev 519 | Rev 586 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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