diff options
-rw-r--r-- | sys/arch/i386/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/biosdev.h | 6 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/biostime.S | 133 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/time.c | 113 |
4 files changed, 74 insertions, 182 deletions
diff --git a/sys/arch/i386/stand/libsa/Makefile b/sys/arch/i386/stand/libsa/Makefile index 8cee6af1e5c..d0158588149 100644 --- a/sys/arch/i386/stand/libsa/Makefile +++ b/sys/arch/i386/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.18 1997/08/07 01:11:53 mickey Exp $ +# $OpenBSD: Makefile,v 1.19 1997/08/12 19:05:57 mickey Exp $ LIB= sa @@ -13,7 +13,7 @@ DIR_KERN=$S/lib/libkern #AS+= -a # i386 stuff (so, it will possibly load in the same 64k) -SRCS= unixsys.S bioscom.S biosdisk.S bioskbd.S biostime.S gidt.S \ +SRCS= unixsys.S bioscom.S biosdisk.S bioskbd.S gidt.S \ debug_i386.S dev_i386.c exec_i386.c biosdev.c gateA20.c memprobe.c \ time.c alloca.S apm_init.S machdep.c diff --git a/sys/arch/i386/stand/libsa/biosdev.h b/sys/arch/i386/stand/libsa/biosdev.h index 200fd4d6acf..d6f801b91db 100644 --- a/sys/arch/i386/stand/libsa/biosdev.h +++ b/sys/arch/i386/stand/libsa/biosdev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: biosdev.h,v 1.11 1997/07/18 00:49:43 mickey Exp $ */ +/* $OpenBSD: biosdev.h,v 1.12 1997/08/12 19:05:56 mickey Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -73,7 +73,3 @@ u_int biosmem __P((void)); /* time.c */ void time_print __P((void)); time_t getsecs __P((void)); - -/* biostime.S */ -int biostime __P((char *)); -int biosdate __P((char *)); diff --git a/sys/arch/i386/stand/libsa/biostime.S b/sys/arch/i386/stand/libsa/biostime.S deleted file mode 100644 index f5527267cd9..00000000000 --- a/sys/arch/i386/stand/libsa/biostime.S +++ /dev/null @@ -1,133 +0,0 @@ -/* $OpenBSD: biostime.S,v 1.10 1997/07/18 00:29:10 mickey Exp $ */ - -/* - * Copyright (c) 1997 Michael Shalayeff - * Copyright (c) 1997 Tobias Weingartner - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by - * Michael Shalayeff and Tobias Weingartner. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include <machine/asm.h> -#define _LOCORE -#include <machine/biosvar.h> -#undef _LOCORE - -/* - * int usleep(u_long us); - * sleep for that number of microseconds - * returns nonzero if failed - * This BIOSes do not have this call: - * <mho> SystemSOFT BIOS for VLSI Eagle II Version 1.01 (2618-00) - * <mho> BIOS Version: 1.00.04, Date: 08/08/96 - * <mho> (WHatever that means...) - */ -ENTRY(usleep) - pushl %ebx - pushl %ecx - - xorl %edx, %edx - movl 8(%esp), %ecx - movw %cx, %dx - shrl $16, %ecx - - movb $0x86, %ah - DOINT(0x15) -#ifdef notdef - xorb %al, %al - jnc 1f - movl %ah, %al -1: movzbl %al, %eax -#endif - popl %ecx - popl %ebx - ret - - -/* - * int biostime(char buf[4]) - */ -ENTRY(biostime) - pushl %ebp - movl %esp, %ebp - - pushl %ecx - pushl %ebx - - movb $0x02, %ah - DOINT(0x1a) - movb $1, %al - jc 1f - - /* Get address of buffer */ - movl 8(%ebp), %ebx - movb %ch, 0(%ebx) - movb %cl, 1(%ebx) - movb %dh, 2(%ebx) - movb %dl, 3(%ebx) - xorl %eax, %eax - -1: movzbl %al, %eax - - popl %ebx - popl %ecx - popl %ebp - ret - - -/* - * int biosdate(char buf[4]) - */ -ENTRY(biosdate) - pushl %ebp - movl %esp, %ebp - - pushl %ecx - pushl %ebx - - movb $0x04, %ah - DOINT(0x1a) - movb $1, %al - jc 1f - - /* Get address of buffer */ - movl 8(%ebp), %ebx - movb %ch, 0(%ebx) - movb %cl, 1(%ebx) - movb %dh, 2(%ebx) - movb %dl, 3(%ebx) - xorl %eax, %eax - -1: movzbl %al, %eax - - popl %ebx - popl %ecx - popl %ebp - ret - diff --git a/sys/arch/i386/stand/libsa/time.c b/sys/arch/i386/stand/libsa/time.c index 0b3e9d44710..9f6e541ccea 100644 --- a/sys/arch/i386/stand/libsa/time.c +++ b/sys/arch/i386/stand/libsa/time.c @@ -1,6 +1,7 @@ -/* $OpenBSD: time.c,v 1.5 1997/07/17 23:00:27 mickey Exp $ */ +/* $OpenBSD: time.c,v 1.6 1997/08/12 19:05:55 mickey Exp $ */ /* + * Copyright (c) 1997 Michael Shalayeff * Copyright (c) 1997 Tobias Weingartner * All rights reserved. * @@ -33,6 +34,8 @@ */ #include <sys/time.h> +#include <machine/biosvar.h> +#include <machine/pio.h> #include "libsa.h" #include "biosdev.h" @@ -41,95 +44,121 @@ /* * Convert from bcd (packed) to int */ -static int -bcdtoint(register char c){ +static __inline u_int8_t +bcdtoint(register u_int8_t c) { - return ((c & 0xf0) >> 4) * 10 + (c & 0x0f); + return ((c & 0xf0) / 8) * 5 + (c & 0x0f); } -/* Number of days per month */ -static char monthcount[] = { - 31, 28, 31, 30, 31, 30, 31, - 31, 30, 31, 30, 31, 30, 31 -}; - /* * Quick compute of time in seconds since the Epoch */ -static time_t -compute(int year, int month, int day, int hour, int min, int sec) { +static __inline time_t +compute(year, month, day, hour, min, sec) + int year; + u_int8_t month, day, hour, min, sec; +{ + /* Number of days per month */ + static const u_short monthcount[] = { + 0, 0, 31, 59, 90, 120, 151, 181, + 212, 243, 273, 304, 334, 365 + }; register time_t tt; - register int i; - /* Compute years of seconds */ - tt = (year - 1970) * (365 * 24 * 60 * 60); - - /* Compute days of seconds */ - for(i = 1; i < month; i++) - day += monthcount[i]; + /* Compute days */ + tt = (year - 1970) * 365 + monthcount[month] + day; /* Compute for leap year */ - for(i = 1970; i < year; i++) - if(isleap(i)) - day++; - tt += day * (24 * 60 * 60); + for(month <= 2? year--:0;year >= 1970;year--) + if(isleap(year)) + tt++; /* Plus the time */ - tt += sec + 60 * (min + 60 * hour); + tt = sec + 60 * (min + 60 * (tt * 24 + hour)); return tt; } +static int +bios_time_date(int f, register u_int8_t *b) +{ + __asm __volatile(DOINT(0x1a) "\n\t" + "setc %b0\n\t" + "movb %%ch, 0(%1)\n\t" + "movb %%cl, 1(%1)\n\t" + "movb %%dh, 2(%1)\n\t" + "movb %%dl, 3(%1)\n\t" + : "=a" (f) + : "p" (b), "0" (f) : "%ecx", "%edx", "cc"); + if (f & 0xff) + return -1; + else { + b[0] = bcdtoint(b[0]); + b[1] = bcdtoint(b[1]); + b[2] = bcdtoint(b[2]); + b[3] = bcdtoint(b[3]); + return 0; + } +} + +static __inline int +biosdate(register u_int8_t *b) +{ + return bios_time_date(4 << 8, b); +} + +static __inline int +biostime(register u_int8_t *b) +{ + return bios_time_date(2 << 8, b); +} /* * Return time since epoch */ time_t -getsecs(void) { - - char timebuf[4], datebuf[4]; +getsecs(void) +{ + u_int8_t timebuf[4], datebuf[4]; /* Query BIOS for time & date */ if(!biostime(timebuf) && !biosdate(datebuf)) { #ifdef notdef int dst; - dst = bcdtoint(timebuf[3]); + dst = timebuf[3]; #endif /* Convert to seconds since Epoch */ - return compute(bcdtoint(datebuf[0])*100 + bcdtoint(datebuf[1]), - bcdtoint(datebuf[2]), bcdtoint(datebuf[3]), - bcdtoint(timebuf[0]), bcdtoint(timebuf[1]), - bcdtoint(timebuf[2])); + return compute(datebuf[0] * 100 + datebuf[1], + datebuf[2], datebuf[3], + timebuf[0], timebuf[1], timebuf[2]); } else errno = EIO; return(1); } - /* * Return time since epoch */ void -time_print(void) { - char timebuf[4], datebuf[4]; +time_print(void) +{ + u_int8_t timebuf[4], datebuf[4]; /* Query BIOS for time & date */ if(!biostime(timebuf) && !biosdate(datebuf)) { #ifdef notdef int dst; - dst = bcdtoint(timebuf[3]); + dst = timebuf[3]; #endif /* Convert to sane values */ printf("%d/%d/%d - %d:%d:%d\n", - bcdtoint(datebuf[3]), bcdtoint(datebuf[2]), - bcdtoint(datebuf[0]) * 100 + bcdtoint(datebuf[1]), - bcdtoint(timebuf[0]), bcdtoint(timebuf[1]), - bcdtoint(timebuf[2])); + datebuf[3], datebuf[2], datebuf[0] * 100 + datebuf[1], + timebuf[0], timebuf[1], timebuf[2]); } else - printf("Error in biostime() or biosdate().\n"); + printf("no idea (in BIOS)\n"); return; } @@ -142,7 +171,7 @@ sleep(i) /* loop for that number of seconds, polling BIOS, so that it may handle interrupts */ - for (t = getsecs() + i; getsecs() < t; ischar()); + for (t = getsecs() + i; getsecs() < t; ); return 0; } |