Subversion Repositories Kolibri OS

Rev

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

Rev 6122 Rev 6244
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: 6122 $
74
$Revision: 6244 $
Line 251... Line 251...
251
        mov     ds, ax
251
        mov     ds, ax
252
        mov     es, ax
252
        mov     es, ax
253
        mov     fs, ax
253
        mov     fs, ax
254
        mov     gs, ax
254
        mov     gs, ax
255
        mov     ss, ax
255
        mov     ss, ax
256
        mov     esp, 0x006CC00       ; Set stack
256
        mov     esp, TMP_STACK_TOP       ; Set stack
Line 257... Line 257...
257
 
257
 
Line 258... Line 258...
258
; CLEAR 0x280000 - HEAP_BASE
258
; CLEAR 0x280000 - HEAP_BASE
259
 
259
 
Line 303... Line 303...
303
        jmp     pword os_code:high_code
303
        jmp     pword os_code:high_code
Line 304... Line 304...
304
 
304
 
305
align 4
305
align 4
306
bios32_entry    dd ?
306
bios32_entry    dd ?
307
tmp_page_tabs   dd ?
-
 
308
 
307
tmp_page_tabs   dd ?
309
use16
-
 
310
org $-0x10000
-
 
311
include "boot/shutdown.inc" ; shutdown or restart
-
 
312
org $+0x10000
-
 
313
 
308
use16
314
ap_init16:
309
ap_init16:
315
        cli
310
        cli
316
        lgdt    [cs:gdts_ap-ap_init16]
311
        lgdt    [cs:gdts_ap-ap_init16]
317
        mov     eax, [cs:cr3_ap-ap_init16]
312
        mov     eax, [cs:cr3_ap-ap_init16]
Line 5720... Line 5715...
5720
 
5715
 
5721
undefined_syscall:                      ; Undefined system call
5716
undefined_syscall:                      ; Undefined system call
5722
        mov     [esp + 32], dword -1
5717
        mov     [esp + 32], dword -1
Line 5723... Line -...
5723
        ret
-
 
5724
 
-
 
5725
align 4
-
 
5726
system_shutdown:          ; shut down the system
-
 
5727
 
-
 
5728
        cmp     byte [BOOT_VARS+0x9030], 1
-
 
5729
        jne     @F
-
 
5730
        ret
-
 
5731
@@:
-
 
5732
        call    stop_all_services
-
 
5733
 
-
 
5734
yes_shutdown_param:
-
 
5735
; Shutdown other CPUs, if initialized
-
 
5736
        cmp     [ap_initialized], 0
-
 
5737
        jz      .no_shutdown_cpus
-
 
5738
        mov     edi, [LAPIC_BASE]
-
 
5739
        add     edi, 300h
-
 
5740
        mov     esi, smpt+4
-
 
5741
        mov     ebx, [cpu_count]
-
 
5742
        dec     ebx
-
 
5743
.shutdown_cpus_loop:
-
 
5744
        lodsd
-
 
5745
        push    esi
-
 
5746
        xor     esi, esi
-
 
5747
        inc     esi
-
 
5748
        shl     eax, 24
-
 
5749
        mov     [edi+10h], eax
-
 
5750
; assert INIT IPI
-
 
5751
        mov     dword [edi], 0C500h
-
 
5752
        call    delay_ms
-
 
5753
@@:
-
 
5754
        test    dword [edi], 1000h
-
 
5755
        jnz     @b
-
 
5756
; deassert INIT IPI
-
 
5757
        mov     dword [edi], 8500h
-
 
5758
        call    delay_ms
-
 
5759
@@:
-
 
5760
        test    dword [edi], 1000h
-
 
5761
        jnz     @b
-
 
5762
; don't send STARTUP IPI: let other CPUs be in wait-for-startup state
-
 
5763
        pop     esi
-
 
5764
        dec     ebx
-
 
5765
        jnz     .shutdown_cpus_loop
-
 
5766
.no_shutdown_cpus:
-
 
5767
 
-
 
5768
        cli
-
 
5769
 
-
 
5770
if ~ defined extended_primary_loader
-
 
5771
; load kernel.mnt to 0x7000:0
-
 
5772
        mov     ebx, kernel_file_load
-
 
5773
        pushad
-
 
5774
        call    file_system_lfn
-
 
5775
        popad
-
 
5776
 
-
 
5777
        mov     esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
-
 
5778
        mov     edi, OS_BASE+0x40000
-
 
5779
        mov     ecx, 1000
-
 
5780
        rep movsb
-
 
5781
end if
-
 
5782
 
-
 
5783
;        mov     esi, BOOT_VAR    ; restore 0x0 - 0xffff
-
 
5784
;        mov     edi, OS_BASE
-
 
5785
;        mov     ecx, 0x10000/4
-
 
5786
;        cld
-
 
5787
;        rep movsd
-
 
5788
 
-
 
5789
        call    IRQ_mask_all
-
 
5790
 
-
 
5791
        cmp     byte [OS_BASE + 0x9030], 2
-
 
5792
        jnz     no_acpi_power_off
-
 
5793
 
-
 
5794
; scan for RSDP
-
 
5795
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
-
 
5796
        movzx   eax, word [OS_BASE + 0x40E]
-
 
5797
        shl     eax, 4
-
 
5798
        jz      @f
-
 
5799
        mov     ecx, 1024/16
-
 
5800
        call    scan_rsdp
-
 
5801
        jnc     .rsdp_found
-
 
5802
@@:
-
 
5803
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
-
 
5804
        mov     eax, 0xE0000
-
 
5805
        mov     ecx, 0x2000
-
 
5806
        call    scan_rsdp
-
 
5807
        jc      no_acpi_power_off
-
 
5808
.rsdp_found:
-
 
5809
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
-
 
5810
        mov     ebp, [ipc_tmp]
-
 
5811
        stdcall map_page, ebp, esi, PG_READ
-
 
5812
        lea     eax, [esi+1000h]
-
 
5813
        lea     edx, [ebp+1000h]
-
 
5814
        stdcall map_page, edx, eax, PG_READ
-
 
5815
        and     esi, 0xFFF
-
 
5816
        add     esi, ebp
-
 
5817
        cmp     dword [esi], 'RSDT'
-
 
5818
        jnz     no_acpi_power_off
-
 
5819
        mov     ecx, [esi+4]
-
 
5820
        sub     ecx, 24h
-
 
5821
        jbe     no_acpi_power_off
-
 
5822
        shr     ecx, 2
-
 
5823
        add     esi, 24h
-
 
5824
.scan_fadt:
-
 
5825
        lodsd
-
 
5826
        mov     ebx, eax
-
 
5827
        lea     eax, [ebp+2000h]
-
 
5828
        stdcall map_page, eax, ebx, PG_READ
-
 
5829
        lea     eax, [ebp+3000h]
-
 
5830
        add     ebx, 0x1000
-
 
5831
        stdcall map_page, eax, ebx, PG_READ
-
 
5832
        and     ebx, 0xFFF
-
 
5833
        lea     ebx, [ebx+ebp+2000h]
-
 
5834
        cmp     dword [ebx], 'FACP'
-
 
5835
        jz      .fadt_found
-
 
5836
        loop    .scan_fadt
-
 
5837
        jmp     no_acpi_power_off
-
 
5838
.fadt_found:
-
 
5839
; ebx is linear address of FADT
-
 
5840
        mov     edi, [ebx+40] ; physical address of the DSDT
-
 
5841
        lea     eax, [ebp+4000h]
-
 
5842
        stdcall map_page, eax, edi, PG_READ
-
 
5843
        lea     eax, [ebp+5000h]
-
 
5844
        lea     esi, [edi+0x1000]
-
 
5845
        stdcall map_page, eax, esi, PG_READ
-
 
5846
        and     esi, 0xFFF
-
 
5847
        sub     edi, esi
-
 
5848
        cmp     dword [esi+ebp+4000h], 'DSDT'
-
 
5849
        jnz     no_acpi_power_off
-
 
5850
        mov     eax, [esi+ebp+4004h] ; DSDT length
-
 
5851
        sub     eax, 36+4
-
 
5852
        jbe     no_acpi_power_off
-
 
5853
        add     esi, 36
-
 
5854
.scan_dsdt:
-
 
5855
        cmp     dword [esi+ebp+4000h], '_S5_'
-
 
5856
        jnz     .scan_dsdt_cont
-
 
5857
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
-
 
5858
        jnz     .scan_dsdt_cont
-
 
5859
        mov     dl, [esi+ebp+4000h+6]
-
 
5860
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
-
 
5861
                      ; ...in theory; in practice, VirtualBox has 2 bytes
-
 
5862
        ja      .scan_dsdt_cont
-
 
5863
        cmp     dl, 1
-
 
5864
        jb      .scan_dsdt_cont
-
 
5865
        lea     esi, [esi+ebp+4000h+7]
-
 
5866
        xor     ecx, ecx
-
 
5867
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
-
 
5868
        jz      @f
-
 
5869
        cmp     byte [esi], 0xA
-
 
5870
        jnz     no_acpi_power_off
-
 
5871
        inc     esi
-
 
5872
        mov     cl, [esi]
-
 
5873
@@:
-
 
5874
        inc     esi
-
 
5875
        cmp     dl, 2
-
 
5876
        jb      @f
-
 
5877
        cmp     byte [esi], 0
-
 
5878
        jz      @f
-
 
5879
        cmp     byte [esi], 0xA
-
 
5880
        jnz     no_acpi_power_off
-
 
5881
        inc     esi
-
 
5882
        mov     ch, [esi]
-
 
5883
@@:
-
 
5884
        jmp     do_acpi_power_off
-
 
5885
.scan_dsdt_cont:
-
 
5886
        inc     esi
-
 
5887
        cmp     esi, 0x1000
-
 
5888
        jb      @f
-
 
5889
        sub     esi, 0x1000
-
 
5890
        add     edi, 0x1000
-
 
5891
        push    eax
-
 
5892
        lea     eax, [ebp+4000h]
-
 
5893
        stdcall map_page, eax, edi, PG_READ
-
 
5894
        push    PG_READ
-
 
5895
        lea     eax, [edi+1000h]
-
 
5896
        push    eax
-
 
5897
        lea     eax, [ebp+5000h]
-
 
5898
        push    eax
-
 
5899
        stdcall map_page
-
 
5900
        pop     eax
-
 
5901
@@:
-
 
5902
        dec     eax
-
 
5903
        jnz     .scan_dsdt
-
 
5904
        jmp     no_acpi_power_off
-
 
5905
do_acpi_power_off:
-
 
5906
        mov     edx, [ebx+48]
-
 
5907
        test    edx, edx
-
 
5908
        jz      .nosmi
-
 
5909
        mov     al, [ebx+52]
-
 
5910
        out     dx, al
-
 
5911
        mov     edx, [ebx+64]
-
 
5912
@@:
-
 
5913
        in      ax, dx
-
 
5914
        test    al, 1
-
 
5915
        jz      @b
-
 
5916
.nosmi:
-
 
5917
        and     cx, 0x0707
-
 
5918
        shl     cx, 2
-
 
5919
        or      cx, 0x2020
-
 
5920
        mov     edx, [ebx+64]
-
 
5921
        in      ax, dx
-
 
5922
        and     ax, 203h
-
 
5923
        or      ah, cl
-
 
5924
        out     dx, ax
-
 
5925
        mov     edx, [ebx+68]
-
 
5926
        test    edx, edx
-
 
5927
        jz      @f
-
 
5928
        in      ax, dx
-
 
5929
        and     ax, 203h
-
 
5930
        or      ah, ch
-
 
5931
        out     dx, ax
-
 
5932
@@:
-
 
5933
        jmp     $
-
 
5934
 
-
 
5935
 
-
 
5936
scan_rsdp:
-
 
5937
        add     eax, OS_BASE
-
 
5938
.s:
-
 
5939
        cmp     dword [eax], 'RSD '
-
 
5940
        jnz     .n
-
 
5941
        cmp     dword [eax+4], 'PTR '
-
 
5942
        jnz     .n
-
 
5943
        xor     edx, edx
-
 
5944
        xor     esi, esi
-
 
5945
@@:
-
 
5946
        add     dl, [eax+esi]
-
 
5947
        inc     esi
-
 
5948
        cmp     esi, 20
-
 
5949
        jnz     @b
-
 
5950
        test    dl, dl
-
 
5951
        jz      .ok
-
 
5952
.n:
-
 
5953
        add     eax, 10h
-
 
5954
        loop    .s
-
 
5955
        stc
-
 
5956
.ok:
-
 
5957
        ret
-
 
5958
 
-
 
5959
no_acpi_power_off:
-
 
5960
        call    create_trampoline_pgmap
-
 
5961
        mov     cr3, eax
-
 
5962
        jmp     become_real+0x10000
-
 
5963
iglobal
-
 
5964
align 4
-
 
5965
realmode_gdt:
-
 
5966
; selector 0 - not used
-
 
5967
        dw      23
-
 
5968
        dd      realmode_gdt-OS_BASE
-
 
5969
        dw      0
-
 
5970
; selector 8 - code from 1000:0000 to 1000:FFFF
-
 
5971
        dw      0FFFFh
-
 
5972
        dw      0
-
 
5973
        db      1
-
 
5974
        db      10011011b
-
 
5975
        db      00000000b
-
 
5976
        db      0
-
 
5977
; selector 10h - data from 1000:0000 to 1000:FFFF
-
 
5978
        dw      0FFFFh
-
 
5979
        dw      0
-
 
5980
        db      1
-
 
5981
        db      10010011b
-
 
5982
        db      00000000b
-
 
Line 5983... Line 5718...
5983
        db      0
5718
        ret
5984
endg
5719
 
5985
 
5720