Subversion Repositories Kolibri OS

Rev

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