2010-10-01 11:21:55 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-06-01 21:18:07 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2010-10-01 11:21:55 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; Shutdown for Menuet ;;
|
|
|
|
;; ;;
|
|
|
|
;; Distributed under General Public License ;;
|
|
|
|
;; See file COPYING for details. ;;
|
|
|
|
;; Copyright 2003 Ville Turjanmaa ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
2014-12-01 04:51:07 +01:00
|
|
|
use32
|
|
|
|
become_real:
|
2016-02-17 03:56:18 +01:00
|
|
|
xor ebx, ebx
|
|
|
|
xor edx, edx
|
|
|
|
xor ecx, ecx
|
|
|
|
xor esi, esi
|
|
|
|
xor edi, edi
|
|
|
|
xor ebp, ebp
|
2014-12-01 04:51:07 +01:00
|
|
|
cli
|
2016-02-17 03:56:18 +01:00
|
|
|
ltr bx
|
2014-12-01 04:51:07 +01:00
|
|
|
lgdt [realmode_gdt-OS_BASE]
|
|
|
|
jmp 8:@f
|
|
|
|
use16
|
|
|
|
@@:
|
|
|
|
mov ax, 10h
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
|
|
|
mov eax, cr0
|
|
|
|
and eax, not 80000001h
|
|
|
|
mov cr0, eax
|
|
|
|
jmp 0x1000:pr_mode_exit
|
2010-10-01 11:21:55 +02:00
|
|
|
|
|
|
|
pr_mode_exit:
|
|
|
|
|
|
|
|
; setup stack
|
2016-02-17 03:56:18 +01:00
|
|
|
mov ax, (TMP_STACK_TOP and 0xF0000) shr 4
|
2012-03-08 09:33:38 +01:00
|
|
|
mov ss, ax
|
2016-02-17 03:56:18 +01:00
|
|
|
mov esp, TMP_STACK_TOP and 0xFFFF
|
|
|
|
|
|
|
|
;setup ds
|
2010-10-01 11:21:55 +02:00
|
|
|
push cs
|
2012-03-08 09:33:38 +01:00
|
|
|
pop ds
|
2010-10-01 11:21:55 +02:00
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
lidt [old_ints_h]
|
2010-10-01 11:21:55 +02:00
|
|
|
;remap IRQs
|
2012-03-08 09:33:38 +01:00
|
|
|
mov al, 0x11
|
|
|
|
out 0x20, al
|
|
|
|
call rdelay
|
|
|
|
out 0xA0, al
|
|
|
|
call rdelay
|
|
|
|
|
|
|
|
mov al, 0x08
|
|
|
|
out 0x21, al
|
|
|
|
call rdelay
|
|
|
|
mov al, 0x70
|
|
|
|
out 0xA1, al
|
|
|
|
call rdelay
|
|
|
|
|
|
|
|
mov al, 0x04
|
|
|
|
out 0x21, al
|
|
|
|
call rdelay
|
|
|
|
mov al, 0x02
|
|
|
|
out 0xA1, al
|
|
|
|
call rdelay
|
|
|
|
|
|
|
|
mov al, 0x01
|
|
|
|
out 0x21, al
|
|
|
|
call rdelay
|
|
|
|
out 0xA1, al
|
|
|
|
call rdelay
|
|
|
|
|
|
|
|
mov al, 0xB8
|
|
|
|
out 0x21, al
|
|
|
|
call rdelay
|
|
|
|
mov al, 0xBD
|
|
|
|
out 0xA1, al
|
2010-10-01 11:21:55 +02:00
|
|
|
sti
|
|
|
|
|
|
|
|
temp_3456:
|
2012-03-08 09:33:38 +01:00
|
|
|
xor ax, ax
|
|
|
|
mov es, ax
|
|
|
|
mov al, byte [es:0x9030]
|
|
|
|
cmp al, 1
|
|
|
|
jl nbw
|
|
|
|
cmp al, 4
|
|
|
|
jle nbw32
|
2010-10-01 11:21:55 +02:00
|
|
|
|
|
|
|
nbw:
|
2012-03-08 09:33:38 +01:00
|
|
|
in al, 0x60
|
|
|
|
cmp al, 6
|
|
|
|
jae nbw
|
|
|
|
mov bl, al
|
2010-10-01 11:21:55 +02:00
|
|
|
nbw2:
|
2012-03-08 09:33:38 +01:00
|
|
|
in al, 0x60
|
|
|
|
cmp al, bl
|
|
|
|
je nbw2
|
|
|
|
cmp al, 240;ax,240
|
|
|
|
jne nbw31
|
|
|
|
mov al, bl
|
|
|
|
dec ax
|
|
|
|
jmp nbw32
|
2010-10-01 11:21:55 +02:00
|
|
|
nbw31:
|
2012-03-08 09:33:38 +01:00
|
|
|
add bl, 128
|
|
|
|
cmp al, bl
|
|
|
|
jne nbw
|
|
|
|
sub al, 129
|
2010-10-01 11:21:55 +02:00
|
|
|
|
|
|
|
nbw32:
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
dec ax
|
|
|
|
dec ax ; 2 = power off
|
|
|
|
jnz no_apm_off
|
|
|
|
call APM_PowerOff
|
|
|
|
jmp $
|
2010-10-01 11:21:55 +02:00
|
|
|
no_apm_off:
|
|
|
|
|
2011-07-22 20:08:47 +02:00
|
|
|
if ~ defined extended_primary_loader ; kernel restarting is not supported
|
2012-03-08 09:33:38 +01:00
|
|
|
dec ax ; 3 = reboot
|
|
|
|
jnz restart_kernel ; 4 = restart kernel
|
2011-07-22 20:08:47 +02:00
|
|
|
end if
|
2012-03-08 09:33:38 +01:00
|
|
|
push 0x40
|
|
|
|
pop ds
|
|
|
|
mov word[0x0072], 0x1234
|
|
|
|
jmp 0xF000:0xFFF0
|
2010-10-01 11:21:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
rdelay:
|
|
|
|
ret
|
|
|
|
|
|
|
|
APM_PowerOff:
|
|
|
|
mov ax, 5304h
|
|
|
|
xor bx, bx
|
|
|
|
int 15h
|
|
|
|
;!!!!!!!!!!!!!!!!!!!!!!!!
|
2012-03-08 09:33:38 +01:00
|
|
|
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
|
2010-10-01 11:21:55 +02:00
|
|
|
;!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
ret
|
|
|
|
|
2011-07-22 20:08:47 +02:00
|
|
|
if ~ defined extended_primary_loader
|
2010-10-01 11:21:55 +02:00
|
|
|
restart_kernel:
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
mov ax, 0x0003 ; set text mode for screen
|
2010-10-01 11:21:55 +02:00
|
|
|
int 0x10
|
2016-02-17 03:56:18 +01:00
|
|
|
jmp 0x5000:0000
|
2010-10-01 11:21:55 +02:00
|
|
|
|
2016-02-17 03:56:18 +01:00
|
|
|
restart_kernel_5001:
|
2010-10-01 11:21:55 +02:00
|
|
|
cli
|
|
|
|
|
|
|
|
push ds
|
|
|
|
pop es
|
|
|
|
xor si, si
|
|
|
|
xor di, di
|
2016-02-17 03:56:18 +01:00
|
|
|
|
|
|
|
push 0x7100
|
|
|
|
pop ds
|
|
|
|
mov cx, 0x4000
|
|
|
|
rep movsd
|
|
|
|
|
|
|
|
push 0x8100
|
|
|
|
pop ds
|
2010-10-01 11:21:55 +02:00
|
|
|
push 0x2000
|
|
|
|
pop es
|
2016-02-17 03:56:18 +01:00
|
|
|
mov cx, 0x4000
|
|
|
|
rep movsd
|
|
|
|
|
|
|
|
push 0x9100
|
2010-10-01 11:21:55 +02:00
|
|
|
pop ds
|
|
|
|
push 0x3000
|
|
|
|
pop es
|
2016-02-17 03:56:18 +01:00
|
|
|
mov cx, 0x4000
|
|
|
|
rep movsd
|
|
|
|
xchg bx, bx
|
|
|
|
push 0xA100
|
|
|
|
pop ds
|
|
|
|
push 0x4000
|
|
|
|
pop es
|
|
|
|
mov cx, 0x800
|
|
|
|
rep movsd
|
2010-10-01 11:21:55 +02:00
|
|
|
|
|
|
|
wbinvd ; write and invalidate cache
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
mov al, 00110100b
|
|
|
|
out 43h, al
|
2010-10-01 11:21:55 +02:00
|
|
|
jcxz $+2
|
2012-03-08 09:33:38 +01:00
|
|
|
mov al, 0xFF
|
|
|
|
out 40h, al
|
2010-10-01 11:21:55 +02:00
|
|
|
jcxz $+2
|
2012-03-08 09:33:38 +01:00
|
|
|
out 40h, al
|
2010-10-01 11:21:55 +02:00
|
|
|
jcxz $+2
|
|
|
|
sti
|
|
|
|
|
|
|
|
; (hint by Black_mirror)
|
|
|
|
; We must read data from keyboard port,
|
|
|
|
; because there may be situation when previous keyboard interrupt is lost
|
|
|
|
; (due to return to real mode and IRQ reprogramming)
|
|
|
|
; and next interrupt will not be generated (as keyboard waits for handling)
|
|
|
|
in al, 0x60
|
|
|
|
|
|
|
|
; bootloader interface
|
|
|
|
push 0x1000
|
2012-03-08 09:33:38 +01:00
|
|
|
pop ds
|
|
|
|
mov si, kernel_restart_bootblock
|
|
|
|
mov ax, 'KL'
|
2010-10-01 11:21:55 +02:00
|
|
|
jmp 0x1000:0000
|
2011-07-22 20:08:47 +02:00
|
|
|
end if
|
2010-10-01 11:21:55 +02:00
|
|
|
|