reboot & power off

git-svn-id: svn://kolibrios.org@863 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2008-09-13 15:52:04 +00:00
parent d08f862229
commit 0e79d8c724
2 changed files with 134 additions and 174 deletions

View File

@ -20,6 +20,7 @@ public _16bit_start
public _16bit_end public _16bit_end
public _enter_bootscreen public _enter_bootscreen
public _poweroff
public _bx_from_load public _bx_from_load
@ -63,7 +64,6 @@ include "bootcode.inc" ; 16 bit system boot code
include "../bus/pci/pci16.inc" include "../bus/pci/pci16.inc"
include "../detect/biosdisk.inc" include "../detect/biosdisk.inc"
;include "boot/shutdown.inc" ; shutdown or restart
cli cli
@ -73,23 +73,28 @@ include "../detect/biosdisk.inc"
jmp pword 0x08:__setvars jmp pword 0x08:__setvars
;align 4
;_leave_16bit:
;
; cli
; mov eax, cr0
; or eax, CR0_PG+CR0_WP+CR0_PE
; mov cr0, eax
; hlt
align 4 align 4
_enter_16bit: rmode_idt:
dw 0x400
dd 0
dw 0
align 4
_poweroff:
mov eax, cr0 mov eax, cr0
and eax, not 0x80000001 and eax, not 0x80000001
mov cr0, eax mov cr0, eax
jmp far 0x1000:@F jmp far 0x1000:@F
align 4
_leave_16bit:
cli
mov eax, cr0
or eax, CR0_PG+CR0_WP+CR0_PE
mov cr0, eax
hlt
align 4
@@: @@:
mov eax, 0x3000 mov eax, 0x3000
mov ss, ax mov ss, ax
@ -98,8 +103,51 @@ align 4
mov ebx, 0x1000 mov ebx, 0x1000
mov ds, bx mov ds, bx
mov es, bx mov es, bx
cli
hlt lidt [rmode_idt]
APM_PowerOff:
mov ax, 5304h
xor bx, bx
int 15h
;!!!!!!!!!!!!!!!!!!!!!!!!
mov ax,0x5300
xor bx,bx
int 0x15
push ax
mov ax,0x5301
xor bx,bx
int 0x15
mov ax,0x5308
mov bx,1
mov cx,bx
int 0x15
mov ax,0x530E
xor bx,bx
pop cx
int 0x15
mov ax,0x530D
mov bx,1
mov cx,bx
int 0x15
mov ax,0x530F
mov bx,1
mov cx,bx
int 0x15
mov ax,0x5307
mov bx,1
mov cx,3
int 0x15
;!!!!!!!!!!!!!!!!!!!!!!!!
jmp $
align 4 align 4
_16bit_end: _16bit_end:

View File

@ -129,10 +129,14 @@ public _rd_fat_end
public _rd_root public _rd_root
public _rd_root_end public _rd_root_end
extrn __edata
extrn _16bit_start extrn _16bit_start
extrn _16bit_end extrn _16bit_end
extrn _enter_bootscreen extrn _enter_bootscreen
extrn _poweroff
extrn _init extrn _init
extrn _init_mm extrn _init_mm
@ -213,31 +217,6 @@ proc test_cpu
mov [cpu_caps], eax mov [cpu_caps], eax
mov [cpu_caps+4], eax mov [cpu_caps+4], eax
pushfd
pop eax
mov ecx, eax
xor eax, 0x40000
push eax
popfd
pushfd
pop eax
xor eax, ecx
mov [cpu_type], CPU_386
jz .end_cpuid
push ecx
popfd
mov [cpu_type], CPU_486
mov eax, ecx
xor eax, 0x200000
push eax
popfd
pushfd
pop eax
xor eax, ecx
je .end_cpuid
mov [cpu_id], 1
xor eax, eax xor eax, eax
cpuid cpuid
@ -299,6 +278,9 @@ proc test_cpu
endp endp
align 4 align 4
_copy_pg_balloc dd 0
_high_code: _high_code:
mov ax,os_stack mov ax,os_stack
@ -331,6 +313,9 @@ _high_code:
call test_cpu call test_cpu
call _init call _init
mov eax, [_pg_balloc]
mov [_copy_pg_balloc], eax
mov [tss._ss0], os_stack mov [tss._ss0], os_stack
mov [tss._esp0], __os_stack mov [tss._esp0], __os_stack
mov [tss._esp], __os_stack mov [tss._esp], __os_stack
@ -351,6 +336,8 @@ _high_code:
mov ax,tss0 mov ax,tss0
ltr ax ltr ax
__core_restart:
mov ecx, 1280*1024 mov ecx, 1280*1024
fastcall _balloc fastcall _balloc
mov [_display_data], eax mov [_display_data], eax
@ -5171,127 +5158,76 @@ system_shutdown: ; shut down the system
call sys_cd_audio call sys_cd_audio
yes_shutdown_param: yes_shutdown_param:
cli cli
mov eax, kernel_file ; load kernel.mnt to 0x7000:0 cmp byte [BOOT_VAR+0x9030], 3
push 12 je _sys_reboot
pop esi
xor ebx,ebx
or ecx,-1
mov edx, OS_BASE+0x70000
call fileread
; mov esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0 cmp byte [BOOT_VAR+0x9030], 4
; mov edi,OS_BASE+0x40000 je _sys_restart
; mov ecx,1000
; rep movsb
cld
mov esi, BOOT_VAR ; restore 0x0 - 0xffff mov esi, BOOT_VAR ; restore 0x0 - 0xffff
mov edi, OS_BASE mov edi, OS_BASE
mov ecx,0x10000/4 mov ecx,0x10000/4
cld
rep movsd rep movsd
mov esi, _16bit_start + OS_BASE
mov ecx, _16bit_end
shr ecx, 2
mov edi, _16BIT_BASE + OS_BASE
rep movsd
mov dword [_sys_pdbr], PG_LARGE+PG_SW
mov eax, _sys_pdbr + (0x100000000-OS_BASE)
mov cr3, eax
jmp far 0x60:_poweroff;
_sys_restart:
mov ax,os_stack
mov dx,app_data
mov ss,ax
mov esp, __os_stack
mov ds, dx
mov es, dx
mov fs, dx
mov gs, dx
call restorefatchain call restorefatchain
mov al, 0xFF cld
out 0x21, al mov esi, BOOT_VAR ; restore 0x0 - 0xffff
out 0xA1, al mov edi, OS_BASE
mov ecx,0x10000/4
rep movsd
if 1 mov eax, [_copy_pg_balloc]
; mov word [OS_BASE+0x467+0],pr_mode_exit mov [_pg_balloc], eax
; mov word [OS_BASE+0x467+2],0x1000
mov al,0x0F mov dword [_sys_pdbr], PG_LARGE+PG_SW
out 0x70,al mov eax, _sys_pdbr + (0x100000000-OS_BASE)
mov al,0x05 mov cr3, eax
out 0x71,al
mov al,0xFE mov ecx, LAST_PAGE
out 0x64,al mov edi, cur_saved_data
sub edi, OS_BASE
hlt sub ecx, edi
else
cmp byte [OS_BASE + 0x9030], 2
jnz no_acpi_power_off
; scan for RSDP
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
movzx eax, word [OS_BASE + 0x40E]
shl eax, 4
jz @f
mov ecx, 1024/16
call scan_rsdp
jnc .rsdp_found
@@:
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
mov eax, 0xE0000
mov ecx, 0x2000
call scan_rsdp
jc no_acpi_power_off
.rsdp_found:
mov esi, [eax+16] ; esi contains physical address of the RSDT
mov ebp, [ipc_tmp]
stdcall map_page, ebp, esi, PG_MAP
lea eax, [esi+1000h]
lea edx, [ebp+1000h]
stdcall map_page, edx, eax, PG_MAP
and esi, 0xFFF
add esi, ebp
cmp dword [esi], 'RSDT'
jnz no_acpi_power_off
mov ecx, [esi+4]
sub ecx, 24h
jbe no_acpi_power_off
shr ecx, 2 shr ecx, 2
add esi, 24h xor eax, eax
.scan_fadt: rep stosd
lodsd
mov ebx, eax
lea eax, [ebp+2000h]
stdcall map_page, eax, ebx, PG_MAP
lea eax, [ebp+3000h]
add ebx, 0x1000
stdcall map_page, eax, ebx, PG_MAP
and ebx, 0xFFF
lea ebx, [ebx+ebp+2000h]
cmp dword [ebx], 'FACP'
jz .fadt_found
loop .scan_fadt
jmp no_acpi_power_off
.fadt_found:
; ebx is linear address of FADT
mov edx, [ebx+48]
test edx, edx
jz .nosmi
mov al, [ebx+52]
out dx, al
mov edx, [ebx+64]
@@:
in ax, dx
test al, 1
jz @b
.nosmi:
mov edx, [ebx+64]
in ax, dx
and ax, 203h
or ax, 3C00h
out dx, ax
mov edx, [ebx+68]
test edx, edx
jz @f
in ax, dx
and ax, 203h
or ax, 3C00h
out dx, ax
@@:
jmp $
call test_cpu
no_acpi_power_off: ; jmp __core_restart
mov word [OS_BASE+0x467+0],pr_mode_exit
mov word [OS_BASE+0x467+2],0x1000 _sys_reboot:
mov word [OS_BASE+0x467+0],0xFFF0
mov word [OS_BASE+0x467+2],0xF000
mov al,0x0F mov al,0x0F
out 0x70,al out 0x70,al
@ -5303,30 +5239,6 @@ no_acpi_power_off:
hlt hlt
scan_rsdp:
add eax, OS_BASE
.s:
cmp dword [eax], 'RSD '
jnz .n
cmp dword [eax+4], 'PTR '
jnz .n
xor edx, edx
xor esi, esi
@@:
add dl, [eax+esi]
inc esi
cmp esi, 20
jnz @b
test dl, dl
jz .ok
.n:
add eax, 10h
loop .s
stc
.ok:
ret
end if
include "data32.inc" include "data32.inc"
__REV__ = __REV __REV__ = __REV