Subversion Repositories Kolibri OS

Rev

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

Rev 6078 Rev 6240
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: 6078 $
74
$Revision: 6240 $
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 2175... Line 2175...
2175
 
2175
 
2176
        stdcall user_free, eax
2176
        stdcall user_free, eax
Line 2177... Line 2177...
2177
@@:
2177
@@:
2178
 
2178
 
2179
        mov     eax, [TASK_BASE]
2179
        mov     eax, [TASK_BASE]
Line 2180... Line 2180...
2180
        mov     [eax+TASKDATA.state], 3; terminate this program
2180
        mov     [eax+TASKDATA.state], TSTATE_ZOMBIE
2181
        call    wakeup_osloop
2181
        call    wakeup_osloop
2182
 
2182
 
Line 3744... Line 3744...
3744
        jecxz   no_mark_system_shutdown
3744
        jecxz   no_mark_system_shutdown
3745
;--------------------------------------
3745
;--------------------------------------
3746
align 4
3746
align 4
3747
markz:
3747
markz:
3748
        push    ecx edx
3748
        push    ecx edx
3749
        cmp     [edx+TASKDATA.state], 9
3749
        cmp     [edx+TASKDATA.state], TSTATE_FREE
3750
        jz      .nokill
3750
        jz      .nokill
3751
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
3751
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
3752
        cmp     [edx+APPDATA.process], sys_proc
3752
        cmp     [edx+APPDATA.process], sys_proc
3753
        jz      .nokill
3753
        jz      .nokill
3754
        call    request_terminate
3754
        call    request_terminate
Line 3758... Line 3758...
3758
        xor     eax, eax
3758
        xor     eax, eax
3759
.common:
3759
.common:
3760
        pop     edx ecx
3760
        pop     edx ecx
3761
        test    eax, eax
3761
        test    eax, eax
3762
        jz      @f
3762
        jz      @f
3763
        mov     [edx+TASKDATA.state], byte 3
3763
        mov     [edx+TASKDATA.state], TSTATE_ZOMBIE
3764
@@:
3764
@@:
3765
        add     edx, 0x20
3765
        add     edx, 0x20
3766
        loop    markz
3766
        loop    markz
3767
        call    wakeup_osloop
3767
        call    wakeup_osloop
3768
;--------------------------------------
3768
;--------------------------------------
Line 5764... Line 5764...
5764
        dec     ebx
5764
        dec     ebx
5765
        jnz     .shutdown_cpus_loop
5765
        jnz     .shutdown_cpus_loop
5766
.no_shutdown_cpus:
5766
.no_shutdown_cpus:
Line 5767... Line 5767...
5767
 
5767
 
-
 
5768
        cli
-
 
5769
        call    IRQ_mask_all
-
 
5770
 
-
 
5771
        mov     eax, [OS_BASE + 0x9030]
-
 
5772
        cmp     al, SYSTEM_RESTART
Line 5768... Line -...
5768
        cli
-
 
5769
 
5773
        jne     @F
5770
if ~ defined extended_primary_loader
5774
 
5771
; load kernel.mnt to 0x7000:0
5775
; load kernel.mnt to _CLEAN_ZONE
5772
        mov     ebx, kernel_file_load
5776
        mov     ebx, kernel_file_load
5773
        pushad
5777
        pushad
Line 5774... Line 5778...
5774
        call    file_system_lfn
5778
        call    file_system_lfn
5775
        popad
5779
        popad
5776
 
5780
 
5777
        mov     esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5781
        mov     esi, OS_BASE+restart_kernel_5000 ; move kernel re-starter to 0x5000:0
5778
        mov     edi, OS_BASE+0x40000
-
 
Line 5779... Line -...
5779
        mov     ecx, 1000
-
 
5780
        rep movsb
-
 
5781
end if
-
 
5782
 
5782
        mov     edi, OS_BASE+0x50000
5783
;        mov     esi, BOOT_VAR    ; restore 0x0 - 0xffff
5783
        mov     ecx, (restart_code_end - restart_kernel_5000)/4
Line -... Line 5784...
-
 
5784
        rep movsd
5784
;        mov     edi, OS_BASE
5785
 
-
 
5786
@@:
-
 
5787
;disable paging
-
 
5788
 
-
 
5789
        call    create_trampoline_pgmap
-
 
5790
        mov     cr3, eax
-
 
5791
        jmp     @F
-
 
5792
org $-OS_BASE
-
 
5793
@@:
Line 5785... Line 5794...
5785
;        mov     ecx, 0x10000/4
5794
        mov     eax, cr0
5786
;        cld
5795
        and     eax, 0x7FFFFFFF
Line 5787... Line 5796...
5787
;        rep movsd
5796
        mov     cr0, eax
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).
5797
        mov     eax, cr3
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.
5798
        mov     cr3, eax
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]
5799
 
5828
        stdcall map_page, eax, ebx, PG_READ
-
 
5829
        lea     eax, [ebp+3000h]
-
 
5830
        add     ebx, 0x1000
5800
        cmp     byte [0x9030], SYSTEM_SHUTDOWN
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
5801
        jne     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]
5802
 
5842
        stdcall map_page, eax, edi, PG_READ
5803
; system_power_off
5843
        lea     eax, [ebp+5000h]
5804
 
5844
        lea     esi, [edi+0x1000]
5805
        mov     ebx, [acpi_fadt_base-OS_BASE]
5845
        stdcall map_page, eax, esi, PG_READ
5806
        cmp     dword [ebx], 'FACP'
5846
        and     esi, 0xFFF
5807
        jne     no_acpi_power_off
5847
        sub     edi, esi
5808
        mov     esi, [acpi_dsdt_base-OS_BASE]
5848
        cmp     dword [esi+ebp+4000h], 'DSDT'
5809
        cmp     dword [esi], 'DSDT'
5849
        jnz     no_acpi_power_off
5810
        jne     no_acpi_power_off
5850
        mov     eax, [esi+ebp+4004h] ; DSDT length
5811
        mov     eax, [esi+4] ; DSDT length
5851
        sub     eax, 36+4
5812
        sub     eax, 36+4
5852
        jbe     no_acpi_power_off
5813
        jbe     no_acpi_power_off
5853
        add     esi, 36
5814
        add     esi, 36
5854
.scan_dsdt:
5815
.scan_dsdt:
5855
        cmp     dword [esi+ebp+4000h], '_S5_'
5816
        cmp     dword [esi], '_S5_'
5856
        jnz     .scan_dsdt_cont
5817
        jnz     .scan_dsdt_cont
5857
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5818
        cmp     byte [esi+4], 12h ; DefPackage opcode
5858
        jnz     .scan_dsdt_cont
5819
        jnz     .scan_dsdt_cont
5859
        mov     dl, [esi+ebp+4000h+6]
5820
        mov     dl, [esi+6]
5860
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5821
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5861
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5822
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5862
        ja      .scan_dsdt_cont
5823
        ja      .scan_dsdt_cont
5863
        cmp     dl, 1
5824
        cmp     dl, 1
Line 5882... Line 5843...
5882
        mov     ch, [esi]
5843
        mov     ch, [esi]
5883
@@:
5844
@@:
5884
        jmp     do_acpi_power_off
5845
        jmp     do_acpi_power_off
5885
.scan_dsdt_cont:
5846
.scan_dsdt_cont:
5886
        inc     esi
5847
        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
5848
        dec     eax
5903
        jnz     .scan_dsdt
5849
        jnz     .scan_dsdt
5904
        jmp     no_acpi_power_off
5850
        jmp     no_acpi_power_off
5905
do_acpi_power_off:
5851
do_acpi_power_off:
5906
        mov     edx, [ebx+48]
5852
        mov     edx, [ebx+48]
Line 5930... Line 5876...
5930
        or      ah, ch
5876
        or      ah, ch
5931
        out     dx, ax
5877
        out     dx, ax
5932
@@:
5878
@@:
5933
        jmp     $
5879
        jmp     $
Line -... Line 5880...
-
 
5880
 
-
 
5881
no_acpi_power_off:
-
 
5882
 
-
 
5883
        jmp     0x50000
-
 
5884
 
-
 
5885
align 4
-
 
5886
restart_kernel_5000:
-
 
5887
org 0x50000
-
 
5888
 
-
 
5889
        cmp     byte [0x9030], SYSTEM_RESTART
-
 
5890
        jne     @F
-
 
5891
 
-
 
5892
        xchg    bx, bx
-
 
5893
 
-
 
5894
        mov     esi, _CLEAN_ZONE-OS_BASE
-
 
5895
        mov     edi, 0x10000
-
 
5896
        mov     ecx, 0x31000/4
-
 
5897
        cld
-
 
5898
        rep     movsd
Line 5934... Line -...
5934
 
-
 
5935
 
5899
@@:
5936
scan_rsdp:
-
 
5937
        add     eax, OS_BASE
-
 
5938
.s:
-
 
5939
        cmp     dword [eax], 'RSD '
-
 
5940
        jnz     .n
-
 
5941
        cmp     dword [eax+4], 'PTR '
5900
 
-
 
5901
        xor     ebx, ebx
5942
        jnz     .n
5902
        xor     edx, edx
-
 
5903
        xor     ecx, ecx
-
 
5904
        xor     esi, esi
-
 
5905
        xor     edi, edi
-
 
5906
        xor     ebp, ebp
-
 
5907
        lidt    [.idt]
-
 
5908
        lgdt    [.gdt]
-
 
5909
        jmp     8:@f
-
 
5910
align 8
-
 
5911
.gdt:
-
 
5912
; selector 0 - not used
-
 
5913
        dw      23
-
 
5914
        dd      .gdt
-
 
5915
        dw      0
-
 
5916
; selector 8 - code from 5000:0000 to 1000:FFFF
-
 
5917
        dw      0FFFFh
-
 
5918
        dw      0
-
 
5919
        db      5
-
 
5920
        db      10011011b
-
 
5921
        db      00000000b
-
 
5922
        db      0
-
 
5923
; selector 10h - data from 1000:0000 to 1000:FFFF
-
 
5924
        dw      0FFFFh
-
 
5925
        dw      0
-
 
5926
        db      1
-
 
5927
        db      10010011b
-
 
5928
        db      00000000b
-
 
5929
        db      0
-
 
5930
.idt:
-
 
5931
        dw 256*4
-
 
5932
        dd 0
5943
        xor     edx, edx
5933
org $ - 0x50000
5944
        xor     esi, esi
5934
use16
5945
@@:
5935
@@:
5946
        add     dl, [eax+esi]
5936
        mov     ax, 10h
5947
        inc     esi
5937
        mov     ds, ax
5948
        cmp     esi, 20
5938
        mov     es, ax
5949
        jnz     @b
5939
        mov     fs, ax
5950
        test    dl, dl
5940
        mov     gs, ax
5951
        jz      .ok
5941
        mov     ss, ax
-
 
5942
 
-
 
5943
        mov     eax, cr0
-
 
5944
        and     eax, not 80000001h
-
 
5945
        mov     cr0, eax
-
 
5946
        jmp     0x5000:.real_mode
-
 
5947
 
-
 
5948
align 4
-
 
5949
.real_mode:
-
 
5950
 
-
 
5951
; setup stack
5952
.n:
5952
 
-
 
5953
        mov     ax, (TMP_STACK_TOP and 0xF0000) shr 4
-
 
5954
        mov     ss, ax
-
 
5955
        mov     esp, TMP_STACK_TOP and 0xFFFF
-
 
5956
 
-
 
5957
;remap IRQs
-
 
5958
        mov     al, 0x11
-
 
5959
        out     0x20, al
-
 
5960
        out     0xA0, al
-
 
5961
 
-
 
5962
        mov     al, 0x08
-
 
5963
        out     0x21, al
-
 
5964
        mov     al, 0x70
-
 
5965
        out     0xA1, al
-
 
5966
 
-
 
5967
        mov     al, 0x04
-
 
5968
        out     0x21, al
-
 
5969
        mov     al, 0x02
-
 
5970
        out     0xA1, al
-
 
5971
 
-
 
5972
        mov     al, 0x01
-
 
5973
        out     0x21, al
-
 
5974
        out     0xA1, al
-
 
5975
 
-
 
5976
        mov     al, 0xB8
-
 
5977
        out     0x21, al
-
 
5978
        mov     al, 0xBD
-
 
5979
        out     0xA1, al
-
 
5980
 
-
 
5981
        mov     al, 00110100b
-
 
5982
        out     43h, al
-
 
5983
        mov     al, 0xFF
-
 
5984
        out     40h, al
-
 
5985
        out     40h, al
-
 
5986
 
-
 
5987
        mov     al, byte [es:0x9030]
-
 
5988
        cmp     al, SYSTEM_RESTART
5953
        add     eax, 10h
5989
        je      .do_restart
-
 
5990
 
5954
        loop    .s
5991
        jmp $
-
 
5992
 
-
 
5993
.do_restart:
-
 
5994
 
5955
        stc
5995
        mov     ax, 0x0003     ; set text mode for screen
-
 
5996
        int     0x10
-
 
5997
        sti
-
 
5998
 
-
 
5999
; (hint by Black_mirror)
-
 
6000
; We must read data from keyboard port,
-
 
6001
; because there may be situation when previous keyboard interrupt is lost
-
 
6002
; (due to return to real mode and IRQ reprogramming)
-
 
6003
; and next interrupt will not be generated (as keyboard waits for handling)
-
 
6004
        in      al, 0x60
-
 
6005
 
-
 
6006
; bootloader interface
-
 
6007
        push    0x1000
-
 
6008
        pop     ds
-
 
6009
        mov     si, kernel_restart_bootblock
-
 
6010
        mov     ax, 'KL'
-
 
6011
        jmp     0x1000:0000
-
 
6012
 
-
 
6013
 
-
 
6014
align 4
Line 5956... Line -...
5956
.ok:
-
 
5957
        ret
-
 
5958
 
-
 
5959
no_acpi_power_off:
-
 
5960
        call    create_trampoline_pgmap
6015
org restart_kernel_5000 + $
5961
        mov     cr3, eax
6016
restart_code_end:
5962
        jmp     become_real+0x10000
6017
 
5963
iglobal
6018
iglobal
5964
align 4
6019
align 4
5965
realmode_gdt:
6020
realmode_gdt:
5966
; selector 0 - not used
6021
; selector 0 - not used
5967
        dw      23
6022
        dw      23
5968
        dd      realmode_gdt-OS_BASE
6023
        dd      realmode_gdt-OS_BASE
5969
        dw      0
6024
        dw      0
5970
; selector 8 - code from 1000:0000 to 1000:FFFF
6025
; selector 8 - code from 1000:0000 to 1000:FFFF
5971
        dw      0FFFFh
6026
        dw      0FFFFh
5972
        dw      0
6027
        dw      0
5973
        db      1
6028
        db      5
5974
        db      10011011b
6029
        db      10011011b
5975
        db      00000000b
6030
        db      00000000b
Line 5981... Line 6036...
5981
        db      10010011b
6036
        db      10010011b
5982
        db      00000000b
6037
        db      00000000b
5983
        db      0
6038
        db      0
5984
endg
6039
endg
Line -... Line 6040...
-
 
6040
 
-
 
6041
org $+OS_BASE
5985
 
6042
 
5986
if ~ lang eq sp
6043
if ~ lang eq sp
5987
diff16 "end of .text segment",0,$
6044
diff16 "end of .text segment",0,$
Line 5988... Line 6045...
5988
end if
6045
end if