diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-03-09 23:05:14 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-03-09 23:05:14 +0000 |
commit | 39cb247af46536e5a7d0a097f52832fc60d9905f (patch) | |
tree | d6c28e376fbff53b3481581fc7b7e15255e6297c /sys | |
parent | f0ae6fb0bf466588839c30aa7f844383b0350d74 (diff) |
simplify the delay stuff
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 19 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/microtime.S | 4 | ||||
-rw-r--r-- | sys/arch/amd64/include/cpu.h | 10 | ||||
-rw-r--r-- | sys/arch/amd64/isa/clock.c | 58 |
4 files changed, 49 insertions, 42 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 6d62a9931dc..e3987fa1798 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.18 2004/02/28 22:26:05 deraadt Exp $ */ +/* $OpenBSD: machdep.c,v 1.19 2004/03/09 23:05:13 deraadt Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -200,10 +200,6 @@ pid_t sigpid = 0; extern paddr_t avail_start, avail_end; -void (*delay_func)(int) = i8254_delay; -void (*microtime_func)(struct timeval *) = i8254_microtime; -void (*initclock_func)(void) = i8254_initclocks; - struct mtrr_funcs *mtrr_funcs; /* @@ -847,7 +843,12 @@ boot(int howto) { if (cold) { - howto |= RB_HALT; + /* + * If the system is cold, just halt, unless the user + * explicitly asked for reboot. + */ + if ((howto & RB_USERREQ) == 0) + howto |= RB_HALT; goto haltsys; } @@ -1802,12 +1803,6 @@ microtime(struct timeval *tv) } #endif -void -cpu_initclocks() -{ - (*initclock_func)(); -} - #ifdef MULTIPROCESSOR void need_resched(struct cpu_info *ci) diff --git a/sys/arch/amd64/amd64/microtime.S b/sys/arch/amd64/amd64/microtime.S index 2e64a7e585a..6475d6baba5 100644 --- a/sys/arch/amd64/amd64/microtime.S +++ b/sys/arch/amd64/amd64/microtime.S @@ -1,4 +1,4 @@ -/* $OpenBSD: microtime.S,v 1.1 2004/01/28 01:39:39 mickey Exp $ */ +/* $OpenBSD: microtime.S,v 1.2 2004/03/09 23:05:13 deraadt Exp $ */ /* $NetBSD: microtime.S,v 1.1 2003/04/26 18:39:30 fvdl Exp $ */ /*- @@ -43,7 +43,7 @@ #define IRQ_BIT(irq_num) (1 << ((irq_num) & 7)) #define IRQ_BYTE(irq_num) ((irq_num) >> 3) -ENTRY(i8254_microtime) +ENTRY(microtime) # clear registers and do whatever we can up front xorl %edx,%edx movl $(TIMER_SEL0|TIMER_LATCH),%eax diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 953f2da6998..cc688f39aa6 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.5 2004/02/28 18:12:21 deraadt Exp $ */ +/* $OpenBSD: cpu.h,v 1.6 2004/03/09 23:05:13 deraadt Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -246,13 +246,11 @@ extern u_int32_t cpus_attached; /* * We need a machine-independent name for this. */ -extern void (*delay_func)(int); +extern void delay(int); struct timeval; -extern void (*microtime_func)(struct timeval *); +extern void microtime(struct timeval *); -#define DELAY(x) (*delay_func)(x) -#define delay(x) (*delay_func)(x) -#define microtime(tv) (*microtime_func)(tv) +#define DELAY(x) delay(x) /* diff --git a/sys/arch/amd64/isa/clock.c b/sys/arch/amd64/isa/clock.c index 524ad712ec3..8c2fc2dab1f 100644 --- a/sys/arch/amd64/isa/clock.c +++ b/sys/arch/amd64/isa/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.1 2004/01/28 01:39:39 mickey Exp $ */ +/* $OpenBSD: clock.c,v 1.2 2004/03/09 23:05:13 deraadt Exp $ */ /* $NetBSD: clock.c,v 1.1 2003/04/26 18:39:50 fvdl Exp $ */ /*- @@ -184,6 +184,8 @@ mc146818_write(sc, reg, datum) DELAY(1); } +static u_long rtclock_tval; + /* minimal initialization, enough for delay() */ void initrtclock() @@ -204,6 +206,8 @@ initrtclock() /* Correct rounding will buy us a better precision in timekeeping */ outb(IO_TIMER1+TIMER_CNTR0, tval % 256); outb(IO_TIMER1+TIMER_CNTR0, tval / 256); + + rtclock_tval = tval; } /* @@ -310,9 +314,18 @@ gettick() * wave' mode counts at 2:1). */ void -i8254_delay(int n) +delay(int n) { int limit, tick, otick; + static const int delaytab[26] = { + 0, 2, 3, 4, 5, 6, 7, 9, 10, 11, + 12, 13, 15, 16, 17, 18, 19, 21, 22, 23, + 24, 25, 27, 28, 29, 30, + }; + + /* allow DELAY() to be used before startrtclock() */ + if (!rtclock_tval) + initrtclock(); /* * Read the counter first, so that the rest of the setup overhead is @@ -320,34 +333,35 @@ i8254_delay(int n) */ otick = gettick(); + if (n <= 25) + n = delaytab[n]; + else { #ifdef __GNUC__ - /* - * Calculate ((n * TIMER_FREQ) / 1e6) using explicit assembler code so - * we can take advantage of the intermediate 64-bit quantity to prevent - * loss of significance. - */ - n -= 5; - if (n < 0) - return; - __asm __volatile("mul %2\n\tdiv %3" - : "=a" (n) - : "0" (n), "r" (TIMER_FREQ), "r" (1000000) - : "%edx", "cc"); + /* + * Calculate ((n * TIMER_FREQ) / 1e6) using explicit assembler + * code so we can take advantage of the intermediate 64-bit + * quantity to prevent loss of significance. + */ + int m; + __asm __volatile("mul %3" + : "=a" (n), "=d" (m) + : "0" (n), "r" (TIMER_FREQ)); + __asm __volatile("div %4" + : "=a" (n), "=d" (m) + : "0" (n), "1" (m), "r" (1000000)); #else - /* - * Calculate ((n * TIMER_FREQ) / 1e6) without using floating point and - * without any avoidable overflows. - */ - n -= 20; - { + /* + * Calculate ((n * TIMER_FREQ) / 1e6) without using floating + * point and without any avoidable overflows. + */ int sec = n / 1000000, usec = n % 1000000; n = sec * TIMER_FREQ + usec * (TIMER_FREQ / 1000000) + usec * ((TIMER_FREQ % 1000000) / 1000) / 1000 + usec * (TIMER_FREQ % 1000) / 1000000; - } #endif + } limit = TIMER_FREQ / hz; @@ -435,7 +449,7 @@ rtcdrain(void *v) } void -i8254_initclocks() +cpu_initclocks() { static struct timeout rtcdrain_timeout; |