Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
465 serge 1
$Revision: 586 $
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
586 serge 163
 
164
init_BIOS32:
165
           mov edi, 0xE0000
166
.pcibios_nxt:
167
           cmp dword[edi], '_32_' ; "magic" word
168
           je .BIOS32_found
169
.pcibios_nxt2:
170
           add edi, 0x10
171
           cmp edi, 0xFFFF0
172
           je .BIOS32_not_found
173
           jmp .pcibios_nxt
174
.BIOS32_found:			; magic word found, check control summ
175
 
176
           movzx ecx, byte[edi + 9]
177
           shl ecx, 4
178
           mov esi, edi
179
           xor eax, eax
180
           cld   ; paranoia
181
@@:	lodsb
182
           add ah, al
183
           loop @b
184
           jnz .pcibios_nxt2 ; control summ must be zero
185
    ; BIOS32 service found !
186
           mov ebp, [edi + 4]
187
           mov [bios32_entry], ebp
188
    ; check PCI BIOS present
189
           mov eax, '$PCI'
190
           xor ebx, ebx
191
           push cs  ; special for 'ret far' from  BIOS
192
           call ebp
193
           test al, al
194
           jnz .PCI_BIOS32_not_found
195
 
196
 ; здесь создаются дискрипторы для PCI BIOS
197
 
198
           add ebx, OS_BASE
199
           dec ecx
200
           mov [(pci_code_32-OS_BASE)], cx    ;limit 0-15
201
           mov [(pci_data_32-OS_BASE)], cx    ;limit 0-15
202
 
203
           mov [(pci_code_32-OS_BASE)+2], bx  ;base  0-15
204
           mov [(pci_data_32-OS_BASE)+2], bx  ;base  0-15
205
 
206
           shr ebx, 16
207
           mov [(pci_code_32-OS_BASE)+4], bl  ;base  16-23
208
           mov [(pci_data_32-OS_BASE)+4], bl  ;base  16-23
209
 
210
           shr ecx, 16
211
           and cl, 0x0F
212
           mov ch, bh
213
           add cx, D32
214
           mov [(pci_code_32-OS_BASE)+6], cx  ;lim   16-19 &
215
           mov [(pci_data_32-OS_BASE)+6], cx  ;base  24-31
216
 
217
           mov [(pci_bios_entry-OS_BASE)], edx
218
         ; jmp .end
219
.PCI_BIOS32_not_found:
220
	; здесь должна заполнятся pci_emu_dat
221
.BIOS32_not_found:
222
.end:
223
 
224
 
225
align 4
465 serge 226
proc test_cpu
227
           locals
228
              cpu_type   dd ?
229
              cpu_id     dd ?
230
              cpu_Intel  dd ?
231
              cpu_AMD    dd ?
232
           endl
233
 
234
           mov [cpu_type], 0
235
           xor eax, eax
236
           mov [cpu_caps-OS_BASE], eax
237
           mov [cpu_caps+4-OS_BASE], eax
238
 
239
           pushfd
240
           pop eax
241
           mov ecx, eax
242
           xor eax, 0x40000
243
           push eax
244
           popfd
245
           pushfd
246
           pop eax
247
           xor eax, ecx
248
           mov [cpu_type], CPU_386
249
           jz .end_cpuid
250
           push ecx
251
           popfd
252
 
253
           mov [cpu_type], CPU_486
254
           mov eax, ecx
255
           xor eax, 0x200000
256
           push eax
257
           popfd
258
           pushfd
259
           pop eax
260
           xor eax, ecx
261
           je .end_cpuid
262
           mov [cpu_id], 1
263
 
264
           xor eax, eax
265
           cpuid
266
 
267
           mov [cpu_vendor-OS_BASE], ebx
268
           mov [cpu_vendor+4-OS_BASE], edx
269
           mov [cpu_vendor+8-OS_BASE], ecx
270
           cmp ebx, dword [intel_str-OS_BASE]
271
           jne .check_AMD
272
           cmp edx, dword [intel_str+4-OS_BASE]
273
           jne .check_AMD
274
           cmp ecx, dword [intel_str+8-OS_BASE]
275
           jne .check_AMD
276
           mov [cpu_Intel], 1
277
           cmp eax, 1
278
           jl .end_cpuid
279
           mov eax, 1
280
           cpuid
281
           mov [cpu_sign-OS_BASE], eax
282
           mov [cpu_info-OS_BASE],  ebx
283
           mov [cpu_caps-OS_BASE],  edx
284
           mov [cpu_caps+4-OS_BASE],ecx
285
 
286
           shr eax, 8
287
           and eax, 0x0f
288
           ret
289
.end_cpuid:
290
           mov eax, [cpu_type]
291
           ret
292
 
293
.check_AMD:
294
           cmp ebx, dword [AMD_str-OS_BASE]
295
           jne .unknown
296
           cmp edx, dword [AMD_str+4-OS_BASE]
297
           jne .unknown
298
           cmp ecx, dword [AMD_str+8-OS_BASE]
299
           jne .unknown
300
           mov [cpu_AMD], 1
301
           cmp eax, 1
302
           jl .unknown
303
           mov eax, 1
304
           cpuid
305
           mov [cpu_sign-OS_BASE], eax
306
           mov [cpu_info-OS_BASE],  ebx
307
           mov [cpu_caps-OS_BASE],  edx
308
           mov [cpu_caps+4-OS_BASE],ecx
309
           shr eax, 8
310
           and eax, 0x0f
311
           ret
312
.unknown:
313
           mov eax, 1
314
           cpuid
315
           mov [cpu_sign-OS_BASE], eax
316
           mov [cpu_info-OS_BASE],  ebx
317
           mov [cpu_caps-OS_BASE],  edx
318
           mov [cpu_caps+4-OS_BASE],ecx
319
           shr eax, 8
320
           and eax, 0x0f
321
           ret
322
endp
323