2010-07-23 16:24:34 +02:00
|
|
|
/* sections */
|
|
|
|
|
|
|
|
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
2010-08-17 18:44:07 +02:00
|
|
|
#include <machine/asm.h>
|
2010-07-23 16:24:34 +02:00
|
|
|
#include <machine/interrupt.h>
|
|
|
|
#include "archconst.h"
|
|
|
|
#include "kernel/const.h"
|
|
|
|
#include "sconst.h"
|
2011-06-24 17:20:25 +02:00
|
|
|
#include <machine/multiboot.h>
|
2010-07-23 16:24:34 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file contains a number of 16-bit assembly code utility routines needed by the
|
2010-08-17 18:44:07 +02:00
|
|
|
* kernel.
|
2010-07-23 16:24:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
.text
|
2010-08-06 14:46:44 +02:00
|
|
|
.code16
|
2010-07-23 16:24:34 +02:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* poweroff16 */
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* PUBLIC void poweroff16(); */
|
|
|
|
/* Power down system */
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(poweroff16)
|
2010-07-23 16:24:34 +02:00
|
|
|
/* Assume eax is already set to required value of cr0*/
|
|
|
|
.byte 0x0F,0x22,0xC0 /* mov %cr0,%eax */
|
2010-08-17 18:44:07 +02:00
|
|
|
ljmp $0,$(BIOS_POWEROFF_ENTRY + real_mode - _C_LABEL(poweroff16))
|
2010-07-23 16:24:34 +02:00
|
|
|
real_mode:
|
|
|
|
mov $((BIOS_POWEROFF_ENTRY >> 4) + 0x200),%ax
|
|
|
|
mov %ax, %ds
|
|
|
|
mov %ax, %es
|
|
|
|
mov %ax, %ss
|
|
|
|
mov $0x1000, %sp
|
|
|
|
|
|
|
|
xorb %ah, %ah
|
|
|
|
/* Close gate A20 */
|
|
|
|
gate_A20:
|
|
|
|
call kb_wait
|
|
|
|
movb $0xD1,%al
|
2010-08-06 14:46:44 +02:00
|
|
|
outb $0x64
|
2010-07-23 16:24:34 +02:00
|
|
|
call kb_wait
|
|
|
|
movb $0xDD,%al
|
|
|
|
orb %ah,%al
|
2010-08-06 14:46:44 +02:00
|
|
|
outb $0x60
|
2010-07-23 16:24:34 +02:00
|
|
|
call kb_wait
|
|
|
|
movb $0xFF,%al
|
2010-08-06 14:46:44 +02:00
|
|
|
outb $0x64
|
2010-07-23 16:24:34 +02:00
|
|
|
call kb_wait
|
|
|
|
|
|
|
|
/* Connect to APM */
|
|
|
|
mov $0x5301,%ax
|
|
|
|
mov $0x0,%bx
|
2010-08-06 14:46:44 +02:00
|
|
|
int $0x15
|
2010-08-02 16:40:26 +02:00
|
|
|
jc apm_err
|
2010-07-23 16:24:34 +02:00
|
|
|
|
|
|
|
/* Enable power management */
|
|
|
|
mov $0x5308,%ax
|
|
|
|
mov $0x1,%bx
|
|
|
|
mov $0x1,%cx
|
2010-08-06 14:46:44 +02:00
|
|
|
int $0x15
|
2010-08-02 16:40:26 +02:00
|
|
|
jc apm_err
|
2010-07-23 16:24:34 +02:00
|
|
|
|
|
|
|
/* Set power state to off */
|
|
|
|
mov $0x5307,%ax
|
|
|
|
mov $0x01,%bx
|
|
|
|
mov $0x3,%cx
|
2010-08-06 14:46:44 +02:00
|
|
|
int $0x15
|
2010-08-02 16:40:26 +02:00
|
|
|
jc apm_err
|
|
|
|
0: hlt
|
|
|
|
jmp 0b
|
|
|
|
|
|
|
|
poweroff_msg:
|
|
|
|
.ascii "You can poweroff the machine safely now"
|
|
|
|
poweroff_msg_end:
|
|
|
|
#define POWEROFF_MSG_LEN (poweroff_msg_end-poweroff_msg)
|
|
|
|
apm_err:
|
|
|
|
/* If APM can't perform the shutdown, print something to inform */
|
|
|
|
mov $0x02, %ax /* clear screen */
|
|
|
|
int $0x10
|
|
|
|
|
|
|
|
mov $(BIOS_POWEROFF_ENTRY >> 4), %ax
|
|
|
|
mov %ax, %es
|
|
|
|
mov $0x1301, %ax
|
|
|
|
mov $0x07, %bx
|
|
|
|
mov $POWEROFF_MSG_LEN, %cx
|
|
|
|
mov $0x0300, %dx
|
2010-08-17 18:44:07 +02:00
|
|
|
mov $(poweroff_msg - _C_LABEL(poweroff16)), %bp
|
2010-08-02 16:40:26 +02:00
|
|
|
int $0x10
|
2010-07-23 16:24:34 +02:00
|
|
|
0: hlt
|
|
|
|
jmp 0b
|
|
|
|
|
|
|
|
kb_wait:
|
2010-08-06 14:46:44 +02:00
|
|
|
inb $0x64
|
2010-07-23 16:24:34 +02:00
|
|
|
testb $0x02,%al
|
|
|
|
jnz kb_wait
|
|
|
|
ret
|
|
|
|
/*mark the end for copy*/
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(poweroff16_end)
|