Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
593 mikedld 1
 
465 serge 2
3
 
593 mikedld 4
 
465 serge 5
MEM_WC     equ 1               ;write combined memory
6
MEM_UC     equ 0               ;uncached memory
7
8
 
9
proc mem_test
10
11
 
12
           and eax, not (CR0_CD+CR0_NW)
13
           or eax, CR0_CD         ;disable caching
14
           mov cr0, eax
15
           wbinvd                 ;invalidate cache
16
17
 
18
           mov ebx, 'TEST'
19
@@:
20
           add edi, 0x100000
21
           xchg ebx, dword [edi]
22
           cmp dword [edi], 'TEST'
23
           xchg ebx, dword [edi]
24
           je @b
25
           mov [MEM_AMOUNT-OS_BASE], edi
26
27
 
28
           mov cr0, eax
29
           mov eax, edi
30
           ret
31
endp
32
33
 
34
proc init_mem
35
           mov eax, [MEM_AMOUNT-OS_BASE]
36
           mov [pg_data.mem_amount-OS_BASE], eax
37
38
 
39
           mov edx, eax
40
           mov [pg_data.pages_count-OS_BASE], eax
41
           shr eax, 3
42
           mov [pg_data.pagemap_size-OS_BASE], eax
43
44
 
513 serge 45
           and eax, not 4095
46
           mov [tmp_page_tabs], eax
47
48
 
465 serge 49
           jbe @F
50
           mov edx, (OS_BASE/4096)
51
           jmp .set
52
@@:
53
           cmp edx, (HEAP_MIN_SIZE/4096)
54
           jae .set
55
           mov edx, (HEAP_MIN_SIZE/4096)
56
.set:
57
           mov [pg_data.kernel_pages-OS_BASE], edx
58
           shr edx, 10
59
           mov [pg_data.kernel_tables-OS_BASE], edx
60
61
 
62
           mov edi, sys_pgdir-OS_BASE
63
           mov ecx, 4096/4
64
           cld
65
           rep stosd
66
67
 
68
           bt [cpu_caps-OS_BASE], CAPS_PSE
69
           jnc .no_PSE
70
71
 
72
           or ebx, CR4_PSE
73
           mov eax, PG_LARGE+PG_SW
74
           mov cr4, ebx
75
           dec [pg_data.kernel_tables-OS_BASE]
513 serge 76
465 serge 77
 
78
           add eax, 0x00400000
79
           add edx, 4
80
81
 
82
           mov ecx, [tmp_page_tabs]
513 serge 83
           sub ecx, 0x400000
84
           shr ecx, 12          ;ecx/=4096
85
           jmp .map_low
465 serge 86
.no_PSE:
87
           mov eax, PG_SW
88
           mov ecx, [tmp_page_tabs]
513 serge 89
           shr ecx, 12
90
.map_low:
465 serge 91
           mov edi, [tmp_page_tabs]
513 serge 92
@@:                                   ;
465 serge 93
           stosd
94
           add eax, 0x1000
95
           dec ecx
96
           jnz @B
97
98
 
99
           shl ecx, 10
100
           xor eax, eax
101
           rep stosd
102
103
 
104
           mov eax, [tmp_page_tabs]
513 serge 105
           or eax, PG_SW
106
           mov edi, edx
465 serge 107
108
 
109
110
 
111
           add eax, 0x1000
112
           dec ecx
113
           jnz .map_kernel_tabs
114
115
 
116
117
 
118
           lea esi, [edi+(OS_BASE shr 20)]
119
           movsd
519 serge 120
           movsd
121
           ret
465 serge 122
endp
123
124
 
125
proc init_page_map
126
127
 
128
           mov ecx, [pg_data.pagemap_size-OS_BASE]
129
           shr ecx, 2
130
           or eax, -1
513 serge 131
           cld
132
           rep stosd
465 serge 133
134
 
513 serge 135
           mov edx, [pg_data.pages_count-OS_BASE]
465 serge 136
           shr ecx, 12
513 serge 137
           add ecx, [pg_data.kernel_tables-OS_BASE]
138
           sub edx, ecx
465 serge 139
           mov [pg_data.pages_free-OS_BASE], edx
140
141
 
513 serge 142
           mov ebx, ecx
465 serge 143
           shr ecx, 5
144
           xor eax, eax
513 serge 145
           rep stosd
465 serge 146
147
 
148
           mov ecx, ebx
149
           and ecx, 31
150
           shl eax, cl
151
           mov [edi], eax
152
           add edi, OS_BASE
153
           mov [page_start-OS_BASE], edi;
154
155
 
156
           add ebx, [pg_data.pagemap_size-OS_BASE]
157
           mov [page_end-OS_BASE], ebx
158
159
 
160
           ret
161
endp
162
163
 
164
586 serge 165
 
166
           mov edi, 0xE0000
167
.pcibios_nxt:
168
           cmp dword[edi], '_32_' ; "magic" word
169
           je .BIOS32_found
170
.pcibios_nxt2:
171
           add edi, 0x10
172
           cmp edi, 0xFFFF0
173
           je .BIOS32_not_found
174
           jmp .pcibios_nxt
175
.BIOS32_found:			; magic word found, check control summ
176
177
 
178
           shl ecx, 4
179
           mov esi, edi
180
           xor eax, eax
181
           cld   ; paranoia
182
@@:	lodsb
183
           add ah, al
184
           loop @b
185
           jnz .pcibios_nxt2 ; control summ must be zero
186
    ; BIOS32 service found !
187
           mov ebp, [edi + 4]
188
           mov [bios32_entry], ebp
189
    ; check PCI BIOS present
190
           mov eax, '$PCI'
191
           xor ebx, ebx
192
           push cs  ; special for 'ret far' from  BIOS
193
           call ebp
194
           test al, al
195
           jnz .PCI_BIOS32_not_found
196
197
 
198
199
 
200
           dec ecx
201
           mov [(pci_code_32-OS_BASE)], cx    ;limit 0-15
202
           mov [(pci_data_32-OS_BASE)], cx    ;limit 0-15
203
204
 
205
           mov [(pci_data_32-OS_BASE)+2], bx  ;base  0-15
206
207
 
208
           mov [(pci_code_32-OS_BASE)+4], bl  ;base  16-23
209
           mov [(pci_data_32-OS_BASE)+4], bl  ;base  16-23
210
211
 
212
           and cl, 0x0F
213
           mov ch, bh
214
           add cx, D32
215
           mov [(pci_code_32-OS_BASE)+6], cx  ;lim   16-19 &
216
           mov [(pci_data_32-OS_BASE)+6], cx  ;base  24-31
217
218
 
219
         ; jmp .end
220
.PCI_BIOS32_not_found:
221
	; здесь должна заполнятся pci_emu_dat
222
.BIOS32_not_found:
223
.end:
224
225
 
226
 
227
proc test_cpu
465 serge 228
           locals
229
              cpu_type   dd ?
230
              cpu_id     dd ?
231
              cpu_Intel  dd ?
232
              cpu_AMD    dd ?
233
           endl
234
235
 
236
           xor eax, eax
237
           mov [cpu_caps-OS_BASE], eax
238
           mov [cpu_caps+4-OS_BASE], eax
239
240
 
241
           pop eax
242
           mov ecx, eax
243
           xor eax, 0x40000
244
           push eax
245
           popfd
246
           pushfd
247
           pop eax
248
           xor eax, ecx
249
           mov [cpu_type], CPU_386
250
           jz .end_cpuid
251
           push ecx
252
           popfd
253
254
 
255
           mov eax, ecx
256
           xor eax, 0x200000
257
           push eax
258
           popfd
259
           pushfd
260
           pop eax
261
           xor eax, ecx
262
           je .end_cpuid
263
           mov [cpu_id], 1
264
265
 
266
           cpuid
267
268
 
269
           mov [cpu_vendor+4-OS_BASE], edx
270
           mov [cpu_vendor+8-OS_BASE], ecx
271
           cmp ebx, dword [intel_str-OS_BASE]
272
           jne .check_AMD
273
           cmp edx, dword [intel_str+4-OS_BASE]
274
           jne .check_AMD
275
           cmp ecx, dword [intel_str+8-OS_BASE]
276
           jne .check_AMD
277
           mov [cpu_Intel], 1
278
           cmp eax, 1
279
           jl .end_cpuid
280
           mov eax, 1
281
           cpuid
282
           mov [cpu_sign-OS_BASE], eax
283
           mov [cpu_info-OS_BASE],  ebx
284
           mov [cpu_caps-OS_BASE],  edx
285
           mov [cpu_caps+4-OS_BASE],ecx
286
287
 
288
           and eax, 0x0f
289
           ret
290
.end_cpuid:
291
           mov eax, [cpu_type]
292
           ret
293
294
 
295
           cmp ebx, dword [AMD_str-OS_BASE]
296
           jne .unknown
297
           cmp edx, dword [AMD_str+4-OS_BASE]
298
           jne .unknown
299
           cmp ecx, dword [AMD_str+8-OS_BASE]
300
           jne .unknown
301
           mov [cpu_AMD], 1
302
           cmp eax, 1
303
           jl .unknown
304
           mov eax, 1
305
           cpuid
306
           mov [cpu_sign-OS_BASE], eax
307
           mov [cpu_info-OS_BASE],  ebx
308
           mov [cpu_caps-OS_BASE],  edx
309
           mov [cpu_caps+4-OS_BASE],ecx
310
           shr eax, 8
311
           and eax, 0x0f
312
           ret
313
.unknown:
314
           mov eax, 1
315
           cpuid
316
           mov [cpu_sign-OS_BASE], eax
317
           mov [cpu_info-OS_BASE],  ebx
318
           mov [cpu_caps-OS_BASE],  edx
319
           mov [cpu_caps+4-OS_BASE],ecx
320
           shr eax, 8
321
           and eax, 0x0f
322
           ret
323
endp
324