Subversion Repositories Kolibri OS

Rev

Rev 1066 | Details | Compare with Previous | 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
1066 serge 217
928 serge 218
 
219
220
 
221
           mov dword [_sys_pdbr+4], eax
222
223
 
224
           mov   [scr_mode],eax
225
226
 
227
           call map_LFB
228
229
 
230
           mov cr3, eax
231
232
 
233
234
 
235
           mov ecx, system_init
236
           call @create_systhread@4
237
238
 
239
240
 
241
           mov ecx, cr3
242
           cmp ebx, ecx
243
           je .skip
244
           mov cr3, ebx
245
.skip:
246
           mov esp, [_current_thread]
247
        ;   lea eax, [esp+THR.pl0_stack]
248
        ;   mov [tss._esp0], eax
249
restart1:
250
           dec [_k_reenter]
251
           popad
252
           add esp, 4                 ; skip return adr
253
           iretd                      ; continue process
254
end if
255
256
 
257
map_LFB:
258
           cmp eax, -1
259
           jne @f
260
261
 
262
@@:
263
           test [scr_mode], 0100000000000000b
264
           jnz @f
265
           mov [BOOT_VAR+0x901c],byte 2
266
           ret
267
@@:
268
           mov [LFBAddress], eax
269
           mov [LFBSize], 0x800000
270
           call init_mtrr
271
272
 
273
           or eax, PG_LARGE+PG_UW
274
           mov [_sys_pdbr+(LFB_BASE shr 20)], eax
275
           add eax, 0x00400000
276
           mov [_sys_pdbr+4+(LFB_BASE shr 20)], eax
277
if SHADOWFB
278
           mov ecx, 1 shl 11
1066 serge 279
           call @frame_alloc@4
280
           or eax, PG_LARGE+PG_UW
928 serge 281
           mov [_sys_pdbr+(SHADOWFB shr 20)], eax
282
           add eax, 0x00400000
283
           mov [_sys_pdbr+4+(SHADOWFB shr 20)], eax
284
end if
285
286
 
287
           jnc @F
288
           or dword [_sys_pdbr+(LFB_BASE shr 20)], PG_GLOBAL
289
@@:
290
           mov dword [LFBAddress], LFB_BASE
291
           ret
292
293
 
294
 
295
proc test_cpu
296
           locals
297
              cpu_type   dd ?
298
              cpu_id     dd ?
299
              cpu_Intel  dd ?
300
              cpu_AMD    dd ?
301
           endl
302
303
 
304
           xor eax, eax
305
           mov [cpu_caps], eax
306
           mov [cpu_caps+4], eax
307
308
 
309
           cpuid
310
311
 
312
           mov [cpu_vendor+4], edx
313
           mov [cpu_vendor+8], ecx
314
           cmp ebx, dword [intel_str]
315
           jne .check_AMD
316
           cmp edx, dword [intel_str+4]
317
           jne .check_AMD
318
           cmp ecx, dword [intel_str+8]
319
           jne .check_AMD
320
           mov [cpu_Intel], 1
321
           cmp eax, 1
322
           jl .end_cpuid
323
           mov eax, 1
324
           cpuid
325
           mov [cpu_sign], eax
326
           mov [cpu_info],  ebx
327
           mov [cpu_caps],  edx
328
           mov [cpu_caps+4],ecx
329
330
 
331
           and eax, 0x0f
332
           ret
333
.end_cpuid:
334
           mov eax, [cpu_type]
335
           ret
336
337
 
338
           cmp ebx, dword [AMD_str]
339
           jne .unknown
340
           cmp edx, dword [AMD_str+4]
341
           jne .unknown
342
           cmp ecx, dword [AMD_str+8]
343
           jne .unknown
344
           mov [cpu_AMD], 1
345
           cmp eax, 1
346
           jl .unknown
347
           mov eax, 1
348
           cpuid
349
           mov [cpu_sign], eax
350
           mov [cpu_info],  ebx
351
           mov [cpu_caps],  edx
352
           mov [cpu_caps+4],ecx
353
           shr eax, 8
354
           and eax, 0x0f
355
           ret
356
.unknown:
357
           mov eax, 1
358
           cpuid
359
           mov [cpu_sign], eax
360
           mov [cpu_info],  ebx
361
           mov [cpu_caps],  edx
362
           mov [cpu_caps+4],ecx
363
           shr eax, 8
364
           and eax, 0x0f
365
           ret
366
endp
367
368
 
369
AMD_str    db "AuthenticAMD",0
370
371
 
372
 
373
 
374
align 4
375
376
 
377
           mov edi, 0xE0000
378
.pcibios_nxt:
379
           cmp dword[edi], '_32_' ; "magic" word
380
           je .BIOS32_found
381
.pcibios_nxt2:
382
           add edi, 0x10
383
           cmp edi, 0xFFFF0
384
           je .BIOS32_not_found
385
           jmp .pcibios_nxt
386
.BIOS32_found:			; magic word found, check control summ
387
388
 
389
           shl ecx, 4
390
           mov esi, edi
391
           xor eax, eax
392
           cld   ; paranoia
393
@@:	lodsb
394
           add ah, al
395
           loop @b
396
           jnz .pcibios_nxt2 ; control summ must be zero
397
    ; BIOS32 service found !
398
           mov ebp, [edi + 4]
399
           mov [bios32_entry], ebp
400
    ; check PCI BIOS present
401
           mov eax, '$PCI'
402
           xor ebx, ebx
403
           push cs  ; special for 'ret far' from  BIOS
404
           call ebp
405
           test al, al
406
           jnz .PCI_BIOS32_not_found
407
408
 
409
410
 
411
           dec ecx
412
           mov [(pci_code_32-OS_BASE)], cx    ;limit 0-15
413
           mov [(pci_data_32-OS_BASE)], cx    ;limit 0-15
414
415
 
416
           mov [(pci_data_32-OS_BASE)+2], bx  ;base  0-15
417
418
 
419
           mov [(pci_code_32-OS_BASE)+4], bl  ;base  16-23
420
           mov [(pci_data_32-OS_BASE)+4], bl  ;base  16-23
421
422
 
423
           and cl, 0x0F
424
           mov ch, bh
425
           add cx, D32
426
           mov [(pci_code_32-OS_BASE)+6], cx  ;lim   16-19 &
427
           mov [(pci_data_32-OS_BASE)+6], cx  ;base  24-31
428
429
 
430
         ; jmp .end
431
.PCI_BIOS32_not_found:
432
	; здесь должна заполнятся pci_emu_dat
433
.BIOS32_not_found:
434
.end:
435
           ret
436
437
 
438
439
 
440
441
 
442
443
 
444
445
 
446
447
 
448
449
 
450
451
 
452
cpu_sign          rd 1
453
cpu_info          rd 1
454
cpu_caps          rd 4
455