summaryrefslogtreecommitdiff
path: root/sys/arch/i386/stand/libsa
diff options
context:
space:
mode:
authorTobias Weingartner <weingart@cvs.openbsd.org>1997-04-28 07:39:02 +0000
committerTobias Weingartner <weingart@cvs.openbsd.org>1997-04-28 07:39:02 +0000
commit4ef6cdf0befb6c0f6216955125f8fd6d6baea02b (patch)
treed0a9420019dcc83c39ce68afde0645bb60f89e55 /sys/arch/i386/stand/libsa
parentc941e38f34044523866fe64fcdcee65a8d1d2a77 (diff)
Add getsecs(). Use biostime & biosdate routines.
Parse and convert to seconds since epoch. Please test, there is a new command "time", which should print the current time (according to the BIOS) on the console.
Diffstat (limited to 'sys/arch/i386/stand/libsa')
-rw-r--r--sys/arch/i386/stand/libsa/Makefile5
-rw-r--r--sys/arch/i386/stand/libsa/biosdev.h8
-rw-r--r--sys/arch/i386/stand/libsa/biostime.S66
-rw-r--r--sys/arch/i386/stand/libsa/time.c141
4 files changed, 214 insertions, 6 deletions
diff --git a/sys/arch/i386/stand/libsa/Makefile b/sys/arch/i386/stand/libsa/Makefile
index e51dd626693..aba5ea1a4ee 100644
--- a/sys/arch/i386/stand/libsa/Makefile
+++ b/sys/arch/i386/stand/libsa/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.10 1997/04/18 02:14:28 mickey Exp $
+# $OpenBSD: Makefile,v 1.11 1997/04/28 07:39:00 weingart Exp $
LIB= sa
@@ -16,7 +16,8 @@ AS+= -R
# i386 stuff (so, it will possibly load in the same 64k)
SRCS= unixsys.S bioscom.S biosdisk.S bioskbd.S biostime.S biosmem.S gidt.S \
- debug_i386.S dev_i386.c exec_i386.c biosdev.c gateA20.c memprobe.c
+ debug_i386.S dev_i386.c exec_i386.c biosdev.c gateA20.c memprobe.c \
+ time.c
# stand routines
SRCS+= alloc.c exit.c exec.c getfile.c gets.c globals.c strcmp.c strlen.c \
diff --git a/sys/arch/i386/stand/libsa/biosdev.h b/sys/arch/i386/stand/libsa/biosdev.h
index fd556f44e3a..3fca437122a 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.7 1997/04/23 14:49:23 weingart Exp $ */
+/* $OpenBSD: biosdev.h,v 1.8 1997/04/28 07:39:01 weingart Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -69,6 +69,12 @@ int com_ischar __P((void));
/* biosmem.S */
u_int biosmem __P((void));
+/* time.c */
+void time_print __P((void));
+time_t getsecs __P((void));
+
/* biostime.S */
int usleep __P((u_long));
+int biostime __P((char *));
+int biosdate __P((char *));
#endif
diff --git a/sys/arch/i386/stand/libsa/biostime.S b/sys/arch/i386/stand/libsa/biostime.S
index 0640542fce5..0a0ddf86820 100644
--- a/sys/arch/i386/stand/libsa/biostime.S
+++ b/sys/arch/i386/stand/libsa/biostime.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: biostime.S,v 1.5 1997/04/21 20:20:28 mickey Exp $ */
+/* $OpenBSD: biostime.S,v 1.6 1997/04/28 07:39:01 weingart Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
@@ -58,9 +58,69 @@ ENTRY(usleep)
popl %ecx
ret
+
/*
- *
+ * int biostime(char buf[4])
*/
-ENTRY(getsecs)
+ENTRY(biostime)
+ pushl %ebp
+ movl %esp, %ebp
+
+ pushl %ecx
+ pushl %ebx
+
+ /* Get address of buffer */
+ movl 8(%ebp), %ebx
+
+ movb $0x02, %ah
+ BIOSINT(0x1a)
+ jc 1f
+
+ movl $0x0, %eax
+ movb %ch, 0(%ebx)
+ movb %cl, 1(%ebx)
+ movb %dh, 2(%ebx)
+ movb %dl, 3(%ebx)
+
+ jmp 2f
+
+1: movl $0x01, %eax
+
+2: popl %ebx
+ popl %ecx
+ popl %ebp
+ ret
+
+
+/*
+ * int biosdate(char buf[4])
+ */
+ENTRY(biosdate)
+ pushl %ebp
+ movl %esp, %ebp
+
+ pushl %ecx
+ pushl %ebx
+
+ /* Get address of buffer */
+ movl 8(%ebp), %ebx
+
+ movb $0x04, %ah
+ BIOSINT(0x1a)
+ jc 1f
+
+ movl $0x0, %eax
+ movb %ch, 0(%ebx)
+ movb %cl, 1(%ebx)
+ movb %dh, 2(%ebx)
+ movb %dl, 3(%ebx)
+
+ jmp 2f
+
+1: movl $0x01, %eax
+
+2: 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
new file mode 100644
index 00000000000..8438a3b3f2a
--- /dev/null
+++ b/sys/arch/i386/stand/libsa/time.c
@@ -0,0 +1,141 @@
+/* $OpenBSD: time.c,v 1.1 1997/04/28 07:39:01 weingart Exp $ */
+
+#include <libsa.h>
+#include <sys/time.h>
+#include "biosdev.h"
+
+#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
+
+
+/*
+ * Convert from bcd (packed) to int
+ */
+static int bcdtoint(char c){
+ int tens;
+ int ones;
+
+ tens = (c & 0xf0) >> 4;
+ tens *= 10;
+ ones = c & 0x0f;
+
+ return (tens + ones);
+}
+
+
+/* Number of days per month */
+static int 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){
+ int yearsec, daysec, timesec;
+ int i;
+
+ /* Compute years of seconds */
+ yearsec = year - 1970;
+ yearsec *= (365 * 24 * 60 * 60);
+
+ /* Compute days of seconds */
+ daysec = 0;
+ for(i = 1; i < month; i++){
+ daysec += monthcount[i];
+ }
+ daysec += day;
+
+ /* Compute for leap year */
+ for(i = 1970; i < year; i++){
+ if(isleap(i))
+ daysec += 1;
+ }
+ daysec *= (24 * 60 * 60);
+
+ /* Plus the time */
+ timesec = sec;
+ timesec += (min * 60);
+ timesec += (hour * 60 * 60);
+
+ /* Return sum */
+ return (yearsec + daysec + timesec);
+}
+
+
+/*
+ * Return time since epoch
+ */
+time_t getsecs(void){
+ char timebuf[4], datebuf[4];
+ int st1, st2;
+ time_t tt = 0;
+
+ /* Query BIOS for time & date */
+ st1 = biostime(timebuf);
+ st2 = biosdate(datebuf);
+
+ /* Convert to seconds since Epoch */
+ if(!st1 && !st2){
+ int year, month, day;
+ int hour, min, sec;
+ int dst;
+
+ dst = bcdtoint(timebuf[3]);
+ sec = bcdtoint(timebuf[2]);
+ min = bcdtoint(timebuf[1]);
+ hour = bcdtoint(timebuf[0]);
+
+ year = bcdtoint(datebuf[0]);
+ year *= 100;
+ year += bcdtoint(datebuf[1]);
+ month = bcdtoint(datebuf[2]);
+ day = bcdtoint(datebuf[3]);
+
+ printf("%d/%d/%d - %d:%d:%d\n", day, month, year, hour, min, sec);
+
+ tt = compute(year, month, day, hour, min, sec);
+ return(tt);
+ }
+
+ return(1);
+}
+
+
+/*
+ * Return time since epoch
+ */
+void time_print(void){
+ char timebuf[4], datebuf[4];
+ int st1, st2;
+
+ /* Query BIOS for time & date */
+ st1 = biostime(timebuf);
+ st2 = biosdate(datebuf);
+
+ /* Convert to sane values */
+ if (!st1 && !st2) {
+ int year, month, day;
+ int hour, min, sec;
+ int dst;
+
+ dst = bcdtoint(timebuf[3]);
+ sec = bcdtoint(timebuf[2]);
+ min = bcdtoint(timebuf[1]);
+ hour = bcdtoint(timebuf[0]);
+
+ year = bcdtoint(datebuf[0]);
+ year *= 100;
+ year += bcdtoint(datebuf[1]);
+ month = bcdtoint(datebuf[2]);
+ day = bcdtoint(datebuf[3]);
+
+ printf("%d/%d/%d - %d:%d:%d\n", day, month, year, hour, min, sec);
+
+ } else
+ printf("Error in biostime() or biosdate().\n");
+
+ return;
+}
+