diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-07-08 03:41:01 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-07-08 03:41:01 +0000 |
commit | 8a05d80dd77510a6c111902a080b319b4a9b0e8c (patch) | |
tree | dd500a9b87707c6fda728666d055b9806e2f04e9 /sys | |
parent | bdbb983fefd9a4c1a07a4fcb8edb0ea6516ee09c (diff) |
optimize
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/stand/libsa/biostime.S | 44 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/time.c | 118 |
2 files changed, 64 insertions, 98 deletions
diff --git a/sys/arch/i386/stand/libsa/biostime.S b/sys/arch/i386/stand/libsa/biostime.S index 7c850cf849b..1abd6ad4b29 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.8 1997/05/29 05:24:01 mickey Exp $ */ +/* $OpenBSD: biostime.S,v 1.9 1997/07/08 03:41:00 mickey Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -43,21 +43,29 @@ * 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 BIOSINT(0x15) +#ifdef notdef xorb %al, %al jnc 1f movl %ah, %al 1: movzbl %al, %eax - +#endif + popl %ecx popl %ebx ret @@ -72,24 +80,22 @@ ENTRY(biostime) pushl %ecx pushl %ebx - /* Get address of buffer */ - movl 8(%ebp), %ebx - movb $0x02, %ah BIOSINT(0x1a) - jc 1f + movb $1, %al + jc 1f - movl $0x0, %eax + /* 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 - jmp 2f - -1: movl $0x01, %eax +1: movzbl %al, %eax -2: popl %ebx + popl %ebx popl %ecx popl %ebp ret @@ -105,24 +111,22 @@ ENTRY(biosdate) pushl %ecx pushl %ebx - /* Get address of buffer */ - movl 8(%ebp), %ebx - movb $0x04, %ah BIOSINT(0x1a) - jc 1f + movb $1, %al + jc 1f - movl $0x0, %eax + /* 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 - jmp 2f - -1: movl $0x01, %eax +1: movzbl %al, %eax -2: popl %ebx + 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 701df11296e..cae2dd12f68 100644 --- a/sys/arch/i386/stand/libsa/time.c +++ b/sys/arch/i386/stand/libsa/time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: time.c,v 1.3 1997/05/31 15:36:41 mickey Exp $ */ +/* $OpenBSD: time.c,v 1.4 1997/07/08 03:41:00 mickey Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -38,24 +38,17 @@ #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; +static int +bcdtoint(register char c){ - return (tens + ones); + return ((c & 0xf0) >> 4) * 10 + (c & 0x0f); } - /* Number of days per month */ -static int monthcount[] = { +static char monthcount[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31 }; @@ -64,73 +57,52 @@ static int monthcount[] = { * 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(int year, int month, int day, int hour, int min, int sec) { + register time_t tt; + register int i; /* Compute years of seconds */ - yearsec = year - 1970; - yearsec *= (365 * 24 * 60 * 60); + tt = (year - 1970) * (365 * 24 * 60 * 60); /* Compute days of seconds */ - daysec = 0; - for(i = 1; i < month; i++){ - daysec += monthcount[i]; - } - daysec += day; + for(i = 1; i < month; i++) + day += monthcount[i]; /* Compute for leap year */ - for(i = 1970; i < year; i++){ + for(i = 1970; i < year; i++) if(isleap(i)) - daysec += 1; - } - daysec *= (24 * 60 * 60); + day++; + tt += day * (24 * 60 * 60); /* Plus the time */ - timesec = sec; - timesec += (min * 60); - timesec += (hour * 60 * 60); + tt += sec + 60 * (min + 60 * hour); - /* Return sum */ - return (yearsec + daysec + timesec); + return tt; } /* * Return time since epoch */ -time_t getsecs(void){ +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; + if(!biostime(timebuf) && !biosdate(datebuf)) { +#ifdef notdef 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]); -#ifdef notdef - printf("%d/%d/%d - %d:%d:%d\n", - day, month, year, hour, min, sec); #endif - tt = compute(year, month, day, hour, min, sec); - return(tt); - } + /* 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])); + } else + errno = EIO; return(1); } @@ -139,33 +111,23 @@ time_t getsecs(void){ /* * Return time since epoch */ -void time_print(void){ +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; + if(!biostime(timebuf) && !biosdate(datebuf)) { +#ifdef notdef 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); - +#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])); } else printf("Error in biostime() or biosdate().\n"); @@ -180,7 +142,7 @@ sleep(i) /* loop for that number of seconds, polling BIOS, so that it may handle interrupts */ - for (t = getsecs(); (getsecs() - t) < i; ischar()); + for (t = getsecs() + i; getsecs() < t; ischar()); return 0; } |