Subversion Repositories Kolibri OS

Rev

Rev 513 | Rev 581 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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