diff options
author | hvozda <hvozda@cvs.openbsd.org> | 1996-04-29 14:17:54 +0000 |
---|---|---|
committer | hvozda <hvozda@cvs.openbsd.org> | 1996-04-29 14:17:54 +0000 |
commit | 7a9ddc83f934914d39af72bf24b67290a9e5700f (patch) | |
tree | d4e40de8eec73b77be31c346455984224213ff31 /sys/arch/i386/apm_init | |
parent | fdecada6f88b495c1afc81ad3a15c0cedffa2338 (diff) |
Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).
Diffstat (limited to 'sys/arch/i386/apm_init')
-rw-r--r-- | sys/arch/i386/apm_init/Makefile | 56 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/Makefile.inc | 39 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/apm_bios.h | 185 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/apm_init.S | 215 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/apm_segments.h | 30 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/apm_setup.h | 24 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/bin2asm.sh | 21 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/real_prot.S | 186 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/real_prot.h | 57 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/rmaouthdr | 6 | ||||
-rw-r--r-- | sys/arch/i386/apm_init/table.c | 25 |
11 files changed, 844 insertions, 0 deletions
diff --git a/sys/arch/i386/apm_init/Makefile b/sys/arch/i386/apm_init/Makefile new file mode 100644 index 00000000000..44e521eba13 --- /dev/null +++ b/sys/arch/i386/apm_init/Makefile @@ -0,0 +1,56 @@ +# +# LP (Laptop Package) +# +# (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> +# +# This software may be used, modified, copied, and distributed in +# both source and binary form provided that the above copyright and +# these terms are retained. Under no circumstances is the author +# responsible for the proper functioning of this software, nor does +# the author assume any responsibility for damages incurred with its +# use. +# +# Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) +# Oct., 1994 NetBSD port (1.0 BETA 10/2) by ukai +# Dec., 1995 NetBSD 1.1 kernel build retrofit, jtk@netbsd.org +# + +DIR=${APMREL}${APMDIR} + +.if exists (${DIR}/arch/${MACHINE_ARCH}/Makefile.inc) +.PATH: ${DIR}/arch/${MACHINE_ARCH} +.include "${DIR}/arch/${MACHINE_ARCH}/Makefile.inc" +.endif + +.PATH: ${DIR} + +CC = ${APMCC} +CFLAGS += -DINITIALIZER -I${DIR} -DKERNEL \ + ${APMCFLAGS:S@-I.@-I${KERNREL}.@g} + +OBJS = apm_init.o real_prot.o table.o + +#.SUFFIXES: .c .S .o +# +#.c.o: +# $(CC) $(CFLAGS) $(OPTFLAGS) $(INC) -c $< +# +.S.o: + $(CC) $(CFLAGS) $(INC) -c $< + +apm_init.inc: apm_init + sh ${DIR}/bin2asm.sh apm_init > apm_init.inc + +apm_init: $(OBJS) + $(LD) -Bstatic -N -T 0 -o apm_init $(OBJS) + cp apm_init apm_init.sym + @strip apm_init + @sh ${DIR}/rmaouthdr apm_init apm_init.tmp + @mv -f apm_init.tmp apm_init + +#allclean: clean +# @rm -f apm_init.inc +clean: + rm -f *.o apm_init apm_init.sym apm_init.inc + +#.include <bsd.prog.mk> diff --git a/sys/arch/i386/apm_init/Makefile.inc b/sys/arch/i386/apm_init/Makefile.inc new file mode 100644 index 00000000000..715da6093c5 --- /dev/null +++ b/sys/arch/i386/apm_init/Makefile.inc @@ -0,0 +1,39 @@ +# $NetBSD: Makefile.inc,v 1.12 1995/10/07 09:56:55 mycroft Exp $ +# +# NOTE: $S must correspond to the top of the 'sys' tree + +APMDIR= ${I386}/apm_init + +APMDST= lib/apm_init +APMREL?= ../../ +APMINC?= ${APMDST}/apm_init.inc + +APMDEPS= \ + ${APMDIR}/Makefile \ + ${APMDIR}/apm_bios.h \ + ${APMDIR}/apm_init.S \ + ${APMDIR}/apm_segments.h \ + ${APMDIR}/bin2asm.sh \ + ${APMDIR}/real_prot.S \ + ${APMDIR}/real_prot.h \ + ${APMDIR}/rmaouthdr \ + ${APMDIR}/table.c + +${APMINC}: ${APMDEPS} ${APMDST} + @echo making sure the apm grappling hook is up to date... + @(cd ${APMDST} && ${MAKE} -f ${APMREL}${APMDIR}/Makefile \ + APMCC="${CC}" \ + APMCFLAGS="${CFLAGS}" \ + APMREL="${APMREL}" \ + APMDIR="${APMDIR}" apm_init.inc) + +clean:: .NOTMAIN __always_make_apmlib + @echo cleaning the apm grappling hook objects + @(cd ${APMDST} && ${MAKE} -f ${APMREL}${APMDIR}/Makefile \ + APMCC="${CC}" \ + APMCFLAGS="${CFLAGS}" \ + APMREL="${APMREL}" \ + APMDIR="${APMDIR}" clean) + +${APMDST} __always_make_apmlib: .NOTMAIN + @([ -d ${APMDST} ] || mkdir -p ${APMDST}) diff --git a/sys/arch/i386/apm_init/apm_bios.h b/sys/arch/i386/apm_init/apm_bios.h new file mode 100644 index 00000000000..5354b9ccfb7 --- /dev/null +++ b/sys/arch/i386/apm_init/apm_bios.h @@ -0,0 +1,185 @@ +/* + * Advanced Power Management (APM) BIOS driver for laptop PCs. + * + * Copyright (c) 1994 by HOSOKAWA Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * Oct, 1994 NetBSD port (1.0 BETA 10/2) by ukai + */ + +#ifndef APM_BIOS_H +#define APM_BIOS_H 1 + +#ifdef KERNEL + +/* BIOS id */ +#define APM_BIOS 0x53 +#define SYSTEM_BIOS 0x15 + +/* APM flags */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +/* APM initializer physical address */ +#define APM_OURADDR 0x00080000 + +/* Error code of APM initializer */ +#define APMINI_CANTFIND 0xffffffff +#define APMINI_NOT32BIT 0xfffffffe +#define APMINI_CONNECTERR 0xfffffffd +#define APMINI_BADVER 0xfffffffc + +/* APM functions */ +#define APM_INSTCHECK 0x00 +#define APM_REALCONNECT 0x01 +#define APM_PROT16CONNECT 0x02 +#define APM_PROT32CONNECT 0x03 +#define APM_DISCONNECT 0x04 +#define APM_CPUIDLE 0x05 +#define APM_CPUBUSY 0x06 +#define APM_SETPWSTATE 0x07 +#define APM_ENABLEDISABLEPM 0x08 +#define APM_RESTOREDEFAULT 0x09 +#define APM_GETPWSTATUS 0x0a +#define APM_GETPMEVENT 0x0b +#define APM_GETPWSTATE 0x0c +#define APM_ENABLEDISABLEDPM 0x0d +#define APM_DRVVERSION 0x0e +#define APM_ENGAGEDISENGAGEPM 0x0f +#define APM_OEMFUNC 0x80 + +/* error code */ +#define APME_OK 0x00 +#define APME_PMDISABLED 0x01 +#define APME_REALESTABLISHED 0x02 +#define APME_NOTCONNECTED 0x03 +#define APME_PROT16ESTABLISHED 0x05 +#define APME_PROT16NOTSUPPORTED 0x06 +#define APME_PROT32ESTABLISHED 0x07 +#define APME_PROT32NOTDUPPORTED 0x08 +#define APME_UNKNOWNDEVICEID 0x09 +#define APME_OUTOFRANGE 0x0a +#define APME_NOTENGAGED 0x0b +#define APME_CANTENTERSTATE 0x60 +#define APME_NOPMEVENT 0x80 +#define APME_NOAPMPRESENT 0x86 + + +/* device code */ +#define PMDV_APMBIOS 0x0000 +#define PMDV_ALLDEV 0x0001 +#define PMDV_DISP0 0x0100 +#define PMDV_DISP1 0x0101 +#define PMDV_2NDSTORAGE0 0x0200 +#define PMDV_2NDSTORAGE1 0x0201 +#define PMDV_2NDSTORAGE2 0x0202 +#define PMDV_2NDSTORAGE3 0x0203 +#define PMDV_PARALLEL0 0x0300 +#define PMDV_PARALLEL1 0x0301 +#define PMDV_SERIAL0 0x0400 +#define PMDV_SERIAL1 0x0401 +#define PMDV_SERIAL2 0x0402 +#define PMDV_SERIAL3 0x0403 +#define PMDV_SERIAL4 0x0404 +#define PMDV_SERIAL5 0x0405 +#define PMDV_SERIAL6 0x0406 +#define PMDV_SERIAL7 0x0407 +#define PMDV_NET0 0x0500 +#define PMDV_NET1 0x0501 +#define PMDV_NET2 0x0502 +#define PMDV_NET3 0x0503 +#define PMDV_PCMCIA0 0x0600 +#define PMDV_PCMCIA1 0x0601 +#define PMDV_PCMCIA2 0x0602 +#define PMDV_PCMCIA3 0x0603 +/* 0x0700 - 0xdfff Reserved */ +/* 0xe000 - 0xefff OEM-defined power device IDs */ +/* 0xf000 - 0xffff Reserved */ + +/* Power state */ +#define PMST_APMENABLED 0x0000 +#define PMST_STANDBY 0x0001 +#define PMST_SUSPEND 0x0002 +#define PMST_OFF 0x0003 +#define PMST_LASTREQNOTIFY 0x0004 +#define PMST_LASTREQREJECT 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +#if !defined(ASM) && !defined(INITIALIZER) + +/* C definitions */ +typedef struct apm_hook_func { + struct apm_hook_func *next; /* Linked list */ + int (*func)(void); + const char *name; + int order; +} *apm_hook_func_t; + +apm_hook_func_t apm_resume_hook_init(int (*func)(void), char *name, int order); +void apm_resume_hook_delete(apm_hook_func_t delete_func); +apm_hook_func_t apm_suspend_hook_init(int (*func)(void), char *name, int order); +void apm_suspend_hook_delete(apm_hook_func_t delete_func); +void apm_suspend_resume(void); +void apm_cpu_idle(void); +void apm_cpu_busy(void); + +#endif /* !ASM && !INITIALIZER */ + +#define APM_MIN_ORDER 0x00 +#define APM_MID_ORDER 0x80 +#define APM_MAX_ORDER 0xff + +#endif /* KERNEL */ + +/* power management event code */ +#define PMEV_NOEVENT 0x0000 +#define PMEV_STANDBYREQ 0x0001 +#define PMEV_SUSPENDREQ 0x0002 +#define PMEV_NORMRESUME 0x0003 +#define PMEV_CRITRESUME 0x0004 +#define PMEV_BATTERYLOW 0x0005 +#define PMEV_POWERSTATECHANGE 0x0006 +#define PMEV_UPDATETIME 0x0007 +#define PMEV_CRITSUSPEND 0x0008 +#define PMEV_USERSTANDBYREQ 0x0009 +#define PMEV_USERSUSPENDREQ 0x000a +#define PMEV_STANDBYRESUME 0x000b +/* 0x000c - 0x00ff Reserved system events */ +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define PMEV_DEFAULT 0xffffffff /* used for customization */ + +#if !defined(ASM) && !defined(INITIALIZER) + +typedef struct apm_info { + u_int ai_major; /* APM major version */ + u_int ai_minor; /* APM minor version */ + u_int ai_acline; /* AC line status */ + u_int ai_batt_stat; /* Battery status */ + u_int ai_batt_life; /* Remaining battery life */ +} *apm_info_t; + +#define APMIO_SUSPEND _IO('P', 1) +#define APMIO_GETINFO _IOR('P', 2, struct apm_info) +#define APMIO_ENABLE _IO('P', 3) +#define APMIO_DISABLE _IO('P', 4) +#define APMIO_HALTCPU _IO('P', 5) +#define APMIO_NOTHALTCPU _IO('P', 6) + +#endif /* !ASM && !INITIALIZER */ + +#endif /* APM_BIOS_H */ diff --git a/sys/arch/i386/apm_init/apm_init.S b/sys/arch/i386/apm_init/apm_init.S new file mode 100644 index 00000000000..945c251446a --- /dev/null +++ b/sys/arch/i386/apm_init/apm_init.S @@ -0,0 +1,215 @@ +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * Oct., 1994 NetBSD port (1.0 BETA 10/2) by ukai + */ + +/* + * If you want to know the specification of APM BIOS, see the following + * documentations, + * + * [1] Intel Corporation and Microsoft Corporation, "Advanced Power + * Management, The Next Generation, Version 1.0", Feb.,1992. + * + * [2] Intel Corporation and Microsoft Corporation, "Advanced Power + * Management (APM) BIOS Interface Specification Revision 1.1", + * Sep.,1993, Intel Order Number: 241704-001, Microsoft Part + * Number: 781-110-X01 + * + * or contact + * + * APM Support Desk (Intel Corporation, US) + * TEL: (800)628-8686 + * FAX: (916)356-6100. + */ + + .file "apm_init.S" + +#define ASM + +#include "real_prot.h" +#include <apm_bios.h> +#include <apm_segments.h> + +/* + * APM BIOS initializer + * + * Return value: + * %eax 0xfffffff Can't find APM BIOS + * 0xffffffe Don't support 32bit connection + * 0xffffffd Connection error + * otherwise APM version (16bit BCD format) + * %ebx APM cs entry offset (32bit) + * %ecx lower 16bit APM 16bit cs base (real mode segment) + * upper 16bit APM 32bit cs base (real mode segment) + * %edx lower 16bit APM ds limit (real mode segment) + * upper 16bit [Reserved] + * %esi lower 16bit APM cs limit (APM 1.1 or later) + * upper 16bit APM ds limit (APM 1.1 or later) + * %edi bit0 = 1 16bit protected mode interface supported + * bit1 = 1 32bit protected mode interface supported + * bit2 = 1 "CPU idle" call slows processor clock speed + * bit3 = 1 APM BIOS Power Management disabled + * bit4 = 1 APM BIOS Power Management disengaged + */ + + .text +ENTRY(apm_init) + cli /* disable interrupt */ + push %ebp /* save original base pointer */ + /* ebp is used as a register variable */ + /* + * save old data segments: We assume that %ds == %es && %ds == %ss + */ + push %fs + movw %ds, %ax + movw %ax, %fs + movw $(APM_INIT_DS_SEL), %ax /* initializer data segment */ + movw %ax, %ds + movw %ax, %es + movw %ax, %ss + movl %esp, old_esp /* save original stack pointer */ + movl $0xf000, %esp /* setup temporary stack */ + /* (note that it isn't 0x00000000) */ + + sidt EXT(Idtr_prot) /* save current IDT */ + call EXT(prot_to_real) /* return to real mode */ + + /* + * APM installation check + */ + movb $(APM_BIOS), %ah + movb $(APM_INSTCHECK), %al + data32 + movl $(PMDV_APMBIOS), %ebx + sti + int $(SYSTEM_BIOS) /* call system BIOS */ + cli + + jnc 1f /* if found, goto 1f */ + + data32 + call EXT(real_to_prot) /* come back again to protected mode */ + movl $(APMINI_CANTFIND), apm_version + /* can't find APM BIOS */ + jmp finish + +1: + movl %eax, %edx /* actually, movw %ax, %dx */ + /* save the value of %ax */ + data32 + call EXT(real_to_prot) /* come back again to protected mode */ + cmpb $0x50, %bh /* %bh == 'P'? */ + jnz 1f + cmpb $0x4d, %bl /* %bl == 'M'? */ + jz 2f + +1: + movl $(APMINI_BADVER), apm_version + /* can't find APM BIOS */ + jmp finish + +2: + testl $(APM_32BIT_SUPPORT), %ecx + /* supports 32bit connection? */ + jnz 1f + + movl $(APMINI_NOT32BIT), apm_version + /* don't support 32bit connection */ + jmp finish +1: + movl %edx, apm_version + andl $0x0000ffff, %ecx + movl %ecx, apm_flags + + /* + * APM Protected Mode 32-bit Interface Connect + */ + call EXT(prot_to_real) /* return to real mode */ + + movb $(APM_BIOS), %ah + movb $(APM_DISCONNECT), %al /* just in case bootloader connected*/ + data32 + movl $(PMDV_APMBIOS), %ebx + sti + int $(SYSTEM_BIOS) + cli + movb $(APM_BIOS), %ah + movb $(APM_PROT32CONNECT), %al + data32 + movl $(PMDV_APMBIOS), %ebx + sti + int $(SYSTEM_BIOS) + cli + jnc 1f /* if successed, go to 1f */ + data32 + call EXT(real_to_prot) + movl $(APMINI_CONNECTERR), apm_version + /* connection error */ + jmp finish +1: + /* save PM 32bit code segment into %bp */ + movl %eax, %ebp /* actually, movw %ax, %bp */ + data32 + call EXT(real_to_prot) + movl $0x0000ffff, %eax + andl %eax, %ebp /* 32bit cs base */ + andl %eax, %ecx /* 16bit cs base */ + andl %eax, %edx /* ds base */ + andl %eax, %esi /* cs length (APM 1.1 or later) */ + andl %eax, %edi /* ds length (APM 1.1 or later) */ + /* %ebx is code offset */ + /* pack 32bit cs and 16bit cs into %ecx */ + shll $16, %ebp + orl %ebp, %ecx + /* pack cs length and ds length into %esi */ + shll $16, %edi + orl %edi, %esi +finish: + cli + lidt EXT(Idtr_prot) /* restore old IDTR */ + movl old_esp, %esp /* restore old stack pointer */ + movl apm_version, %ebp /* stored to %eax later */ + movl apm_flags, %edi +#if 0 + movw $(BOOTSTRAP_DS_SEL), %ax + /* restore old data segments */ +#else + movw %fs, %ax +#endif + movw %ax, %ss + movw %ax, %es + movw %ax, %ds + movl %ebp, %eax + pop %fs + popl %ebp /* restore old base pointer */ + lret /* restore old code segment */ + + .data + + .globl EXT(ouraddr) +LEXT(ouraddr) + .long APM_OURADDR + +old_esp: + .long 0 +apm_version: + .long 0 +apm_flags: + .long 0 +old_ds: + .word 0 +old_es: + .word 0 +old_ss: + .word 0 diff --git a/sys/arch/i386/apm_init/apm_segments.h b/sys/arch/i386/apm_init/apm_segments.h new file mode 100644 index 00000000000..5e5fcdbe7e4 --- /dev/null +++ b/sys/arch/i386/apm_init/apm_segments.h @@ -0,0 +1,30 @@ +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define SIZEOF_GDT 8 +#define BOOTSTRAP_GDT_NUM 9 + +#define APM_INIT_CS_INDEX (BOOTSTRAP_GDT_NUM - 3) +#define APM_INIT_DS_INDEX (BOOTSTRAP_GDT_NUM - 2) +#define APM_INIT_CS16_INDEX (BOOTSTRAP_GDT_NUM - 1) +#define APM_INIT_CS_SEL (APM_INIT_CS_INDEX << 3) +#define APM_INIT_DS_SEL (APM_INIT_DS_INDEX << 3) +#define APM_INIT_CS16_SEL (APM_INIT_CS16_INDEX << 3) + +#define CS32_ATTRIB 0x4F9e +#define CS16_ATTRIB 0x009e +#define DS32_ATTRIB 0x4F92 + +#define BOOTSTRAP_DS_SEL 0x10 diff --git a/sys/arch/i386/apm_init/apm_setup.h b/sys/arch/i386/apm_init/apm_setup.h new file mode 100644 index 00000000000..fdc380e50be --- /dev/null +++ b/sys/arch/i386/apm_init/apm_setup.h @@ -0,0 +1,24 @@ +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, distributed, and sold, + * in both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * Oct., 1994 NetBSD port (1.0 BETA 10/2) by ukai + */ + +extern u_long apm_version; +extern u_long apm_cs_entry; +extern u_short apm_cs32_base; +extern u_short apm_cs16_base; +extern u_short apm_ds_base; +extern u_short apm_cs_limit; +extern u_short apm_ds_limit; +extern u_short apm_flags; diff --git a/sys/arch/i386/apm_init/bin2asm.sh b/sys/arch/i386/apm_init/bin2asm.sh new file mode 100644 index 00000000000..6694b49d9b5 --- /dev/null +++ b/sys/arch/i386/apm_init/bin2asm.sh @@ -0,0 +1,21 @@ +#!/bin/sh - +# bin2asm (binary to asm) shell script version by ukai +# +# +if [ $# -lt 1 ]; then + echo 'usage: $0 [in]' + exit 1 +fi +in=$1 +size=`ls -l ${in} | awk '{print $5}'` +# Oops, must 8 byte align +len=`expr \( $size + 8 \) / 8 \* 8` + +echo "/* This file is automatically generated by bin2asm.sh */" +echo "/* Original file is '${in}' */" +echo +dd if=${in} bs=${len} conv=sync |\ + hexdump -v -e '" .byte " 7/1 "0x%02x, " 1/1 " 0x%02x" "\n"' +echo +echo "/* Total size = $size -> $len */" +echo "/* End of File */" diff --git a/sys/arch/i386/apm_init/real_prot.S b/sys/arch/i386/apm_init/real_prot.S new file mode 100644 index 00000000000..5f9e97ecf68 --- /dev/null +++ b/sys/arch/i386/apm_init/real_prot.S @@ -0,0 +1,186 @@ +/* + * Mach Operating System + * Copyright (c) 1992, 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * from: Mach, Revision 2.2 92/04/04 11:34:13 rpd + * $Id: real_prot.S,v 1.1 1996/04/29 14:15:43 hvozda Exp $ + */ + + +/* + Copyright 1988, 1989, 1990, 1991, 1992 + by Intel Corporation, Santa Clara, California. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appears in all +copies and that both the copyright notice and this permission notice +appear in supporting documentation, and that the name of Intel +not be used in advertising or publicity pertaining to distribution +of the software without specific, written prior permission. + +INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, +NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * Oct., 1994 NetBSD port (1.0 BETA 10/2) by ukai + */ + +/* + * Modified for APM BIOS initializer by HOSOKAWA Tatsumi + * + * See also locore.s. It supports these functions works correctly. + */ + + .file "real_prot.S" + +#include "real_prot.h" +#include "apm_segments.h" + +CR0_PE_ON = 0x1 +CR0_PE_OFF = 0xfffffffe + +.globl _ouraddr + .text + +/* + * + * real_to_prot() + * transfer from real mode to protected mode. + */ + +ENTRY(real_to_prot) + /* guarantee that interrupt is disabled when in prot mode */ + cli + + /* + * deleted for APM initializer by HOSOKAWA Tatsumi + * <hosoakwa@mt.cs.keio.ac.jp> + */ +#if 0 + /* load the gdtr */ + addr32 + data32 + lgdt EXT(Gdtr) +#endif + + /* set the PE bit of CR0 */ + mov %cr0, %eax + + data32 + or $CR0_PE_ON, %eax + mov %eax, %cr0 + + /* + * make intrasegment jump to flush the processor pipeline and + * reload CS register + */ + data32 + ljmp $(APM_INIT_CS_SEL), $xprot + +xprot: + /* + * we are in USE32 mode now + * set up the protected mode segment registers : DS, SS, ES + */ + mov $(APM_INIT_DS_SEL), %eax + movw %ax, %ds + movw %ax, %ss + movw %ax, %es + + /* load idtr so we can debug */ + lidt EXT(Idtr_prot) + + ret + +/* + * + * prot_to_real() + * transfer from protected mode to real mode + * + */ + +ENTRY(prot_to_real) + + /* set up a dummy stack frame for the second seg change. */ + movl _ouraddr, %eax + sarl $4, %eax + pushw %ax + movw $xreal, %ax /* gas botches pushw $xreal - extra bytes 0, 0*/ + pushw %ax /* decode to add %al, (%eax) (%al usually 0) */ + + /* Change to use16 mode. */ + ljmp $(APM_INIT_CS16_SEL), $x16 + +x16: + /* clear the PE bit of CR0 */ + mov %cr0, %eax + data32 + and $CR0_PE_OFF, %eax + mov %eax, %cr0 + + /* + * make intersegment jmp to flush the processor pipeline + * using the fake stack frame set up earlier + * and reload CS register + */ + lret + +xreal: + /* + * we are in real mode now + * set up the real mode segment registers : DS, SS, ES + */ + movw %cs, %ax + movw %ax, %ds + movw %ax, %ss + movw %ax, %es + + /* load idtr so we can debug */ + addr32 + data32 + lidt EXT(Idtr_real) + + data32 + ret diff --git a/sys/arch/i386/apm_init/real_prot.h b/sys/arch/i386/apm_init/real_prot.h new file mode 100644 index 00000000000..51e91cf05d9 --- /dev/null +++ b/sys/arch/i386/apm_init/real_prot.h @@ -0,0 +1,57 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * from: Mach, Revision 2.7 92/02/29 15:33:41 rpd + * $Id: real_prot.h,v 1.1 1996/04/29 14:15:14 hvozda Exp $ + */ + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * Oct., 1994 NetBSD port (1.0 BETA 10/2) by ukai + */ + +/* + * Modified to APM BIOS initializer by HOSOKAWA, Tatsumi + */ + +#define ALIGN 4 +#define EXT(x) _ ## x +#define LEXT(x) _ ## x ## : + +#define addr32 .byte 0x67 +#define data32 .byte 0x66 + +#define ENTRY(x) .globl EXT(x); .align ALIGN; LEXT(x) diff --git a/sys/arch/i386/apm_init/rmaouthdr b/sys/arch/i386/apm_init/rmaouthdr new file mode 100644 index 00000000000..608715015fe --- /dev/null +++ b/sys/arch/i386/apm_init/rmaouthdr @@ -0,0 +1,6 @@ +#!/bin/csh -f +# +# from: Mach, Revision 2.2 92/04/04 11:36:01 rpd +# $Id: rmaouthdr,v 1.1 1996/04/29 14:15:35 hvozda Exp $ +# +dd if=$1 of=$2 ibs=32 skip=1 obs=1024b diff --git a/sys/arch/i386/apm_init/table.c b/sys/arch/i386/apm_init/table.c new file mode 100644 index 00000000000..d3cc1d98670 --- /dev/null +++ b/sys/arch/i386/apm_init/table.c @@ -0,0 +1,25 @@ +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp> + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * Oct., 1994 NetBSD port (1.0 BETA 10/2) by ukai + */ + +#include <apm_bios.h> + +struct pseudo_desc { + unsigned short limit; + unsigned long base __attribute__ ((packed)); +}; + +struct pseudo_desc Idtr_prot = { 0, 0 }; /* filled on run time */ +struct pseudo_desc Idtr_real = { 0x400 - 1, 0x0 }; |