Subversion Repositories Kolibri OS

Rev

Rev 5032 | Rev 5039 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5032 Rev 5033
Line 69... Line 69...
69
format binary as "mnt"
69
format binary as "mnt"
Line 70... Line 70...
70
 
70
 
71
include 'macros.inc'
71
include 'macros.inc'
Line 72... Line 72...
72
include 'struct.inc'
72
include 'struct.inc'
Line 73... Line 73...
73
 
73
 
74
$Revision: 5032 $
74
$Revision: 5033 $
Line 307... Line 307...
307
 
307
 
308
use16
308
use16
309
org $-0x10000
309
org $-0x10000
310
include "boot/shutdown.inc" ; shutdown or restart
310
include "boot/shutdown.inc" ; shutdown or restart
-
 
311
org $+0x10000
-
 
312
 
-
 
313
ap_init16:
-
 
314
        cli
-
 
315
        lgdt    [cs:gdts_ap-ap_init16]
-
 
316
        mov     eax, [cs:cr3_ap-ap_init16]
-
 
317
        mov     cr3, eax
-
 
318
        mov     eax, [cs:cr4_ap-ap_init16]
-
 
319
        mov     cr4, eax
-
 
320
        mov     eax, CR0_PE+CR0_PG+CR0_WP
-
 
321
        mov     cr0, eax
-
 
322
        jmp     pword os_code:ap_init_high
-
 
323
align 16
-
 
324
gdts_ap:
-
 
325
        dw     gdte-gdts-1
-
 
326
        dd     gdts
-
 
327
        dw     0
-
 
328
cr3_ap  dd     ?
-
 
329
cr4_ap  dd     ?
311
org $+0x10000
330
ap_init16_size = $ - ap_init16
Line 312... Line 331...
312
use32
331
use32
313
 
332
 
314
__DEBUG__ fix 1
333
__DEBUG__ fix 1
Line 676... Line 695...
676
        mov     dword [CURRENT_TASK], 2
695
        mov     dword [CURRENT_TASK], 2
677
        mov     dword [TASK_COUNT], 2
696
        mov     dword [TASK_COUNT], 2
678
        mov     dword [current_slot], SLOT_BASE + 256*2
697
        mov     dword [current_slot], SLOT_BASE + 256*2
679
        mov     dword [TASK_BASE], CURRENT_TASK + 32*2
698
        mov     dword [TASK_BASE], CURRENT_TASK + 32*2
Line -... Line 699...
-
 
699
 
-
 
700
; Move other CPUs to deep sleep, if it is useful
-
 
701
uglobal
-
 
702
use_mwait_for_idle db 0
-
 
703
endg
-
 
704
        cmp     [cpu_vendor+8], 'ntel'
-
 
705
        jnz     .no_wake_cpus
-
 
706
        bt      [cpu_caps+4], CAPS_MONITOR-32
-
 
707
        jnc     .no_wake_cpus
-
 
708
        dbgstr 'using mwait for idle loop'
-
 
709
        inc     [use_mwait_for_idle]
-
 
710
        mov     ebx, [cpu_count]
-
 
711
        cmp     ebx, 1
-
 
712
        jbe     .no_wake_cpus
-
 
713
        call    create_trampoline_pgmap
-
 
714
        mov     [cr3_ap+OS_BASE], eax
-
 
715
        mov     eax, cr4
-
 
716
        mov     [cr4_ap+OS_BASE], eax
-
 
717
        mov     esi, OS_BASE + ap_init16
-
 
718
        mov     edi, OS_BASE + 8000h
-
 
719
        mov     ecx, (ap_init16_size + 3) / 4
-
 
720
        rep movsd
-
 
721
        stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_SW+PG_NOCACHE
-
 
722
        mov     [LAPIC_BASE], eax
-
 
723
        lea     edi, [eax+300h]
-
 
724
        mov     esi, smpt+4
-
 
725
        dec     ebx
-
 
726
.wake_cpus_loop:
-
 
727
        lodsd
-
 
728
        shl     eax, 24
-
 
729
        mov     [edi+10h], eax
-
 
730
; assert INIT IPI
-
 
731
        mov     dword [edi], 0C500h
-
 
732
@@:
-
 
733
        test    dword [edi], 1000h
-
 
734
        jnz     @b
-
 
735
; deassert INIT IPI
-
 
736
        mov     dword [edi], 8500h
-
 
737
@@:
-
 
738
        test    dword [edi], 1000h
-
 
739
        jnz     @b
-
 
740
; send STARTUP IPI
-
 
741
        mov     dword [edi], 600h + (8000h shr 12)
-
 
742
@@:
-
 
743
        test    dword [edi], 1000h
-
 
744
        jnz     @b
-
 
745
        dec     ebx
-
 
746
        jnz     .wake_cpus_loop
-
 
747
        mov     eax, [cpu_count]
-
 
748
        dec     eax
-
 
749
@@:
-
 
750
        cmp     [ap_initialized], eax
-
 
751
        jnz     @b
-
 
752
        mov     eax, [cr3_ap+OS_BASE]
-
 
753
        call    free_page
-
 
754
.no_wake_cpus:
Line 680... Line 755...
680
 
755
 
681
 
756
 
682
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
757
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
683
        mov     esi, boot_initirq
758
        mov     esi, boot_initirq
Line 1028... Line 1103...
1028
        jmp     osloop
1103
        jmp     osloop
Line 1029... Line 1104...
1029
 
1104
 
Line -... Line 1105...
-
 
1105
 
-
 
1106
        ; Fly :)
-
 
1107
 
-
 
1108
uglobal
-
 
1109
align 4
-
 
1110
ap_initialized  dd      0
-
 
1111
endg
-
 
1112
 
-
 
1113
ap_init_high:
-
 
1114
        mov     ax, os_stack
-
 
1115
        mov     bx, app_data
-
 
1116
        mov     cx, app_tls
-
 
1117
        mov     ss, ax
-
 
1118
        mov     ds, bx
-
 
1119
        mov     es, bx
-
 
1120
        mov     fs, cx
-
 
1121
        mov     gs, bx
-
 
1122
        xor     esp, esp
-
 
1123
        mov     eax, sys_pgdir-OS_BASE
-
 
1124
        mov     cr3, eax
-
 
1125
        lock inc [ap_initialized]
1030
 
1126
        jmp     idle_loop
Line 1031... Line 1127...
1031
        ; Fly :)
1127
 
1032
 
1128
 
1033
include 'unpacker.inc'
1129
include 'unpacker.inc'
Line 1162... Line 1258...
1162
uglobal
1258
uglobal
1163
align 4
1259
align 4
1164
osloop_nonperiodic_work dd      ?
1260
osloop_nonperiodic_work dd      ?
1165
endg
1261
endg
Line -... Line 1262...
-
 
1262
 
1166
 
1263
uglobal
-
 
1264
align 64
-
 
1265
idle_addr       rb      64
-
 
1266
endg
1167
align 4
1267
 
1168
idle_thread:
1268
idle_thread:
-
 
1269
        sti
-
 
1270
 
-
 
1271
; The following code can be executed by all CPUs in the system.
-
 
1272
; All other parts of the kernel do not expect multi-CPU.
-
 
1273
; Also, APs don't even have a stack here.
1169
        sti
1274
; Beware. Don't do anything here. Anything at all.
-
 
1275
idle_loop:
-
 
1276
        cmp     [use_mwait_for_idle], 0
-
 
1277
        jnz     idle_loop_mwait
-
 
1278
 
1170
idle_loop:
1279
idle_loop_hlt:
1171
        hlt
1280
        hlt
Line -... Line 1281...
-
 
1281
        jmp     idle_loop_hlt
-
 
1282
 
-
 
1283
idle_loop_mwait:
-
 
1284
        mov     eax, idle_addr
-
 
1285
        xor     ecx, ecx
-
 
1286
        xor     edx, edx
-
 
1287
        monitor
-
 
1288
        xor     ecx, ecx
-
 
1289
        mov     eax, 20h        ; or 10h
Line 1172... Line 1290...
1172
        jmp     idle_loop
1290
        mwait
1173
 
1291
        jmp     idle_loop_mwait
1174
 
1292
 
Line 5427... Line 5545...
5427
        ret
5545
        ret
5428
@@:
5546
@@:
5429
        call    stop_all_services
5547
        call    stop_all_services
Line 5430... Line 5548...
5430
 
5548
 
-
 
5549
yes_shutdown_param:
-
 
5550
; Shutdown other CPUs, if initialized
-
 
5551
        cmp     [ap_initialized], 0
-
 
5552
        jz      .no_shutdown_cpus
-
 
5553
        mov     edi, [LAPIC_BASE]
-
 
5554
        add     edi, 300h
-
 
5555
        mov     esi, smpt+4
-
 
5556
        mov     ebx, [cpu_count]
-
 
5557
        dec     ebx
-
 
5558
.shutdown_cpus_loop:
-
 
5559
        lodsd
-
 
5560
        shl     eax, 24
-
 
5561
        mov     [edi+10h], eax
-
 
5562
; assert INIT IPI
-
 
5563
        mov     dword [edi], 0C500h
-
 
5564
@@:
-
 
5565
        test    dword [edi], 1000h
-
 
5566
        jnz     @b
-
 
5567
; deassert INIT IPI
-
 
5568
        mov     dword [edi], 8500h
-
 
5569
@@:
-
 
5570
        test    dword [edi], 1000h
-
 
5571
        jnz     @b
-
 
5572
; don't send STARTUP IPI: let other CPUs be in wait-for-startup state
-
 
5573
        dec     ebx
-
 
5574
        jnz     .shutdown_cpus_loop
-
 
5575
.no_shutdown_cpus:
5431
yes_shutdown_param:
5576
 
Line 5432... Line 5577...
5432
        cli
5577
        cli
5433
 
5578
 
5434
if ~ defined extended_primary_loader
5579
if ~ defined extended_primary_loader