Subversion Repositories Kolibri OS

Rev

Rev 996 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
928 serge 1
 
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
8
 
9
include "../proc32.inc"
10
include "../const.inc"
11
12
 
13
14
 
15
16
 
17
sel_os_stack    equ  0x18
18
19
 
20
sel_app_data    equ  0x2B
21
22
 
23
sel_srv_stack   equ  0x39
24
25
 
26
27
 
28
29
 
30
31
 
32
public _pg_balloc
33
34
 
35
 
36
37
 
38
39
 
40
41
 
42
public cpu_sign
43
public cpu_info
44
public cpu_caps
45
46
 
47
48
 
49
extrn _16bit_end
50
extrn _enter_bootscreen
51
52
 
53
extrn init_idt
54
extrn _init_mm
55
extrn _slab_cache_init
56
extrn @init_heap@8
57
extrn init_malloc
58
extrn _init_core_dll
59
extrn _init_threads
60
extrn init_mtrr
61
extrn system_init
62
63
 
64
extrn syscall_entry
65
66
 
67
 
68
69
 
70
extrn _current_thread
71
extrn _k_reenter:dword
72
73
 
74
extrn LFBAddress:dword
75
extrn LFBSize:dword
76
77
 
78
79
 
80
81
 
82
           mov dx, sel_app_data
83
           mov ss, ax
84
           mov esp, __os_stack
85
86
 
87
           mov es, dx
88
           mov fs, dx
89
           mov gs, dx
90
91
 
92
 
93
         ;  jnc @F
94
95
 
96
97
 
98
         ;  or ebx, CR4_PGE
99
         ;  mov cr4, ebx
100
@@:
101
         ;  mov eax, cr3
102
         ;  mov cr3, eax           ; flush TLB
103
104
 
105
           mov eax, 3
106
           out dx, al
107
108
 
109
           call _parse_mbi
110
111
 
112
        ;   mov [_copy_pg_balloc], eax
113
114
 
115
116
 
117
           mov ecx, _16bit_end
118
           shr ecx, 2
119
           mov edi, _16BIT_BASE
120
           cld
121
           rep movsd
122
123
 
124
125
 
126
core_init:
127
           cld
128
129
 
130
           mov dx, sel_app_data
131
           mov ss, ax
132
           mov esp, __os_stack
133
134
 
135
           mov es, dx
136
           mov fs, dx
137
           mov gs, dx
138
139
 
140
           mov [tss._esp0], __os_stack
141
           mov [tss._esp], __os_stack
142
           mov [tss._cs], sel_os_code
143
           mov [tss._ss], sel_os_stack
144
           mov [tss._ds], sel_app_data
145
           mov [tss._es], sel_app_data
146
           mov [tss._fs], sel_app_data
147
           mov [tss._gs], sel_app_data
148
           mov [tss._io], 128
149
;Add IO access table - bit array of permitted ports
150
           mov edi, tss._io_map_0
151
           xor eax, eax
152
       ;    not eax
153
           mov ecx, 8192/4
154
           rep stosd             ; access to 4096*8=65536 ports
155
156
 
157
           ltr ax
158
159
 
160
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
161
	   bt [cpu_caps], CAPS_SEP
162
	   jnc .SEnP   ; SysEnter not Present
163
164
 
165
	   mov ecx, MSR_SYSENTER_CS
166
       mov eax, sel_os_code
167
	   wrmsr
168
	   mov ecx, MSR_SYSENTER_ESP
169
;           mov eax, sysenter_stack ; Check it
170
	   xor	   eax, eax
171
	   wrmsr
172
	   mov ecx, MSR_SYSENTER_EIP
173
	   mov eax, sysenter_entry
174
	   wrmsr
175
176
 
177
; AMD SYSCALL/SYSRET
178
	   cmp byte[cpu_vendor], 'A'
179
	   jne .noSYSCALL
180
	   mov eax, 0x80000001
181
	   cpuid
182
	   test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
183
	   jz .noSYSCALL
184
	   mov ecx, MSR_AMD_EFER
185
	   rdmsr
186
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
187
	   wrmsr
188
189
 
190
; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
191
;  and the contents of this field, plus 8, are copied into the SS register.
192
; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
193
;  and the contents of this field, plus 8, are copied into the SS register.
194
195
 
196
197
 
198
	   mov ecx, MSR_AMD_STAR
199
	   wrmsr
200
.noSYSCALL:
201
202
 
203
204
 
205
206
 
207
208
 
209
           call _slab_cache_init
210
211
 
212
           mov edx, 0x40000000
213
           call @init_heap@8
214
215
 
216
           call _init_threads
217
218
 
219
220
 
221
           xor esi, esi
222
           mov   edi,BOOT_VAR
223
           mov   ecx,0x10000 / 4
224
           rep   movsd
225
226
 
227
           xor eax, eax
228
           mov   ecx,0x10000 / 4
229
           rep   stosd
230
231
 
232
           mov ecx, (0x90000-0x40000)/4
233
           rep stosd
234
235
 
236
           mov dword [_sys_pdbr+4], eax
237
238
 
239
240
 
241
           mov   [scr_mode],eax
242
243
 
244
           call map_LFB
245
246
 
247
           mov cr3, eax
248
249
 
250
 
251
252
 
253
           mov ecx, system_init
254
           call @create_systhread@4
255
256
 
257
258
 
259
260
 
261
           mov ecx, cr3
262
           cmp ebx, ecx
263
           je .skip
264
           mov cr3, ebx
265
.skip:
266
           mov esp, [_current_thread]
267
        ;   lea eax, [esp+THR.pl0_stack]
268
        ;   mov [tss._esp0], eax
269
restart1:
270
           dec [_k_reenter]
271
           popad
272
           add esp, 4                 ; skip return adr
273
           iretd                      ; continue process
274
end if
275
276
 
277
map_LFB:
278
           cmp eax, -1
279
           jne @f
280
281
 
282
@@:
283
           test [scr_mode], 0100000000000000b
284
           jnz @f
285
           mov [BOOT_VAR+0x901c],byte 2
286
           ret
287
@@:
288
           mov [LFBAddress], eax
289
           mov [LFBSize], 0x800000
290
           call init_mtrr
291
292
 
293
           or eax, PG_LARGE+PG_UW
294
           mov [_sys_pdbr+(LFB_BASE shr 20)], eax
295
           add eax, 0x00400000
296
           mov [_sys_pdbr+4+(LFB_BASE shr 20)], eax
297
if SHADOWFB
298
           mov ecx, 11
299
           call @core_alloc@4
300
           or eax, PG_LARGE+PG_UW
301
           mov [_sys_pdbr+(SHADOWFB shr 20)], eax
302
           add eax, 0x00400000
303
           mov [_sys_pdbr+4+(SHADOWFB shr 20)], eax
304
end if
305
306
 
307
           jnc @F
308
           or dword [_sys_pdbr+(LFB_BASE shr 20)], PG_GLOBAL
309
@@:
310
           mov dword [LFBAddress], LFB_BASE
311
           ret
312
313
 
314
 
315
proc test_cpu
316
           locals
317
              cpu_type   dd ?
318
              cpu_id     dd ?
319
              cpu_Intel  dd ?
320
              cpu_AMD    dd ?
321
           endl
322
323
 
324
           xor eax, eax
325
           mov [cpu_caps], eax
326
           mov [cpu_caps+4], eax
327
328
 
329
           cpuid
330
331
 
332
           mov [cpu_vendor+4], edx
333
           mov [cpu_vendor+8], ecx
334
           cmp ebx, dword [intel_str]
335
           jne .check_AMD
336
           cmp edx, dword [intel_str+4]
337
           jne .check_AMD
338
           cmp ecx, dword [intel_str+8]
339
           jne .check_AMD
340
           mov [cpu_Intel], 1
341
           cmp eax, 1
342
           jl .end_cpuid
343
           mov eax, 1
344
           cpuid
345
           mov [cpu_sign], eax
346
           mov [cpu_info],  ebx
347
           mov [cpu_caps],  edx
348
           mov [cpu_caps+4],ecx
349
350
 
351
           and eax, 0x0f
352
           ret
353
.end_cpuid:
354
           mov eax, [cpu_type]
355
           ret
356
357
 
358
           cmp ebx, dword [AMD_str]
359
           jne .unknown
360
           cmp edx, dword [AMD_str+4]
361
           jne .unknown
362
           cmp ecx, dword [AMD_str+8]
363
           jne .unknown
364
           mov [cpu_AMD], 1
365
           cmp eax, 1
366
           jl .unknown
367
           mov eax, 1
368
           cpuid
369
           mov [cpu_sign], eax
370
           mov [cpu_info],  ebx
371
           mov [cpu_caps],  edx
372
           mov [cpu_caps+4],ecx
373
           shr eax, 8
374
           and eax, 0x0f
375
           ret
376
.unknown:
377
           mov eax, 1
378
           cpuid
379
           mov [cpu_sign], eax
380
           mov [cpu_info],  ebx
381
           mov [cpu_caps],  edx
382
           mov [cpu_caps+4],ecx
383
           shr eax, 8
384
           and eax, 0x0f
385
           ret
386
endp
387
388
 
389
AMD_str    db "AuthenticAMD",0
390
391
 
392
 
393
 
394
align 4
395
396
 
397
           mov edi, 0xE0000
398
.pcibios_nxt:
399
           cmp dword[edi], '_32_' ; "magic" word
400
           je .BIOS32_found
401
.pcibios_nxt2:
402
           add edi, 0x10
403
           cmp edi, 0xFFFF0
404
           je .BIOS32_not_found
405
           jmp .pcibios_nxt
406
.BIOS32_found:			; magic word found, check control summ
407
408
 
409
           shl ecx, 4
410
           mov esi, edi
411
           xor eax, eax
412
           cld   ; paranoia
413
@@:	lodsb
414
           add ah, al
415
           loop @b
416
           jnz .pcibios_nxt2 ; control summ must be zero
417
    ; BIOS32 service found !
418
           mov ebp, [edi + 4]
419
           mov [bios32_entry], ebp
420
    ; check PCI BIOS present
421
           mov eax, '$PCI'
422
           xor ebx, ebx
423
           push cs  ; special for 'ret far' from  BIOS
424
           call ebp
425
           test al, al
426
           jnz .PCI_BIOS32_not_found
427
428
 
429
430
 
431
           dec ecx
432
           mov [(pci_code_32-OS_BASE)], cx    ;limit 0-15
433
           mov [(pci_data_32-OS_BASE)], cx    ;limit 0-15
434
435
 
436
           mov [(pci_data_32-OS_BASE)+2], bx  ;base  0-15
437
438
 
439
           mov [(pci_code_32-OS_BASE)+4], bl  ;base  16-23
440
           mov [(pci_data_32-OS_BASE)+4], bl  ;base  16-23
441
442
 
443
           and cl, 0x0F
444
           mov ch, bh
445
           add cx, D32
446
           mov [(pci_code_32-OS_BASE)+6], cx  ;lim   16-19 &
447
           mov [(pci_data_32-OS_BASE)+6], cx  ;base  24-31
448
449
 
450
         ; jmp .end
451
.PCI_BIOS32_not_found:
452
	; здесь должна заполнятся pci_emu_dat
453
.BIOS32_not_found:
454
.end:
455
           ret
456
457
 
458
459
 
460
461
 
462
463
 
464
465
 
466
467
 
468
469
 
470
471
 
472
cpu_sign          rd 1
473
cpu_info          rd 1
474
cpu_caps          rd 4
475