Remove some unnecessary #includes.

Restore the simple leap year calculation as a macro and document it so
that it doesn't become complicated again.  The simple version works
for all leap years covered by 32-bit time_t's.  The complicated version
doesn't work for all leap years covered by 64-bit time_t's since among
other reasons, the solar system is not stable for long enough.

Fix declarations.

Nuke spinwait().
This commit is contained in:
bde 1994-09-18 23:08:56 +00:00
parent 08d0a25b4c
commit ebcdd61f52
7 changed files with 76 additions and 106 deletions

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
* $Id: clock.c,v 1.17 1994/09/14 23:09:06 ache Exp $
* $Id: clock.c,v 1.18 1994/09/18 20:39:42 wollman Exp $
*/
/*
@ -44,13 +44,17 @@
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <machine/segments.h>
#include <machine/frame.h>
#include <i386/isa/icu.h>
#include <i386/isa/isa.h>
#include <i386/isa/rtc.h>
#include <i386/isa/timerreg.h>
#include <machine/cpu.h>
/*
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
* can use a simple formula for leap years.
*/
#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
/* X-tals being what they are, it's nice to be able to fudge this one... */
/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */
@ -58,9 +62,8 @@
#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */
#endif
#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
#define LEAPYEAR(y) (!((y)%4) && ((y)%100) || !((y)%400))
static int beeping;
static int beeping;
int timer0_divisor = TIMER_DIV(100); /* XXX should be hz */
u_int timer0_prescale;
int adjkerntz = 0; /* offset from CMOS clock */
@ -258,7 +261,7 @@ calibrate_cyclecounter(void)
void
DELAY(int n)
{
int counter_limit, prev_tick, tick, ticks_left, sec, usec;
int prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@ -314,7 +317,8 @@ DELAY(int n)
static void
sysbeepstop()
sysbeepstop(chan)
void *chan;
{
outb(IO_PPI, inb(IO_PPI)&0xFC); /* disable counter2 output to speaker */
release_timer2();
@ -335,7 +339,7 @@ sysbeep(int pitch, int period)
if (!beeping) {
outb(IO_PPI, inb(IO_PPI) | 3); /* enable counter2 output to speaker */
beeping = period;
timeout(sysbeepstop, 0, period);
timeout(sysbeepstop, (void *)NULL, period);
}
return 0;
}
@ -489,16 +493,6 @@ enablertclock()
outb(IO_RTC+1, RTCSB_PINTR | RTCSB_24HR);
}
/*
* Delay for some number of milliseconds.
*/
void
spinwait(int millisecs)
{
DELAY(1000 * millisecs);
}
void
cpu_initclocks()
{

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
* $Id: clock.c,v 1.17 1994/09/14 23:09:06 ache Exp $
* $Id: clock.c,v 1.18 1994/09/18 20:39:42 wollman Exp $
*/
/*
@ -44,13 +44,17 @@
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <machine/segments.h>
#include <machine/frame.h>
#include <i386/isa/icu.h>
#include <i386/isa/isa.h>
#include <i386/isa/rtc.h>
#include <i386/isa/timerreg.h>
#include <machine/cpu.h>
/*
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
* can use a simple formula for leap years.
*/
#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
/* X-tals being what they are, it's nice to be able to fudge this one... */
/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */
@ -58,9 +62,8 @@
#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */
#endif
#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
#define LEAPYEAR(y) (!((y)%4) && ((y)%100) || !((y)%400))
static int beeping;
static int beeping;
int timer0_divisor = TIMER_DIV(100); /* XXX should be hz */
u_int timer0_prescale;
int adjkerntz = 0; /* offset from CMOS clock */
@ -258,7 +261,7 @@ calibrate_cyclecounter(void)
void
DELAY(int n)
{
int counter_limit, prev_tick, tick, ticks_left, sec, usec;
int prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@ -314,7 +317,8 @@ DELAY(int n)
static void
sysbeepstop()
sysbeepstop(chan)
void *chan;
{
outb(IO_PPI, inb(IO_PPI)&0xFC); /* disable counter2 output to speaker */
release_timer2();
@ -335,7 +339,7 @@ sysbeep(int pitch, int period)
if (!beeping) {
outb(IO_PPI, inb(IO_PPI) | 3); /* enable counter2 output to speaker */
beeping = period;
timeout(sysbeepstop, 0, period);
timeout(sysbeepstop, (void *)NULL, period);
}
return 0;
}
@ -489,16 +493,6 @@ enablertclock()
outb(IO_RTC+1, RTCSB_PINTR | RTCSB_24HR);
}
/*
* Delay for some number of milliseconds.
*/
void
spinwait(int millisecs)
{
DELAY(1000 * millisecs);
}
void
cpu_initclocks()
{

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)icu.h 5.6 (Berkeley) 5/9/91
* $Id: icu.h,v 1.3 1994/04/02 07:00:40 davidg Exp $
* $Id: icu.h,v 1.4 1994/09/16 13:33:38 davidg Exp $
*/
/*
@ -42,8 +42,8 @@
* W. Jolitz 8/89
*/
#ifndef __ICU__
#define __ICU__
#ifndef _I386_ISA_ICU_H_
#define _I386_ISA_ICU_H_
#ifndef LOCORE
@ -52,17 +52,17 @@
*/
extern unsigned imen; /* interrupt mask enable */
#define INTREN(s) {imen &= ~(s); SET_ICUS()}
#define INTRDIS(s) {imen |= (s); SET_ICUS()}
#define INTREN(s) (imen &= ~(s), SET_ICUS())
#define INTRDIS(s) (imen |= (s), SET_ICUS())
#define INTRMASK(msk,s) (msk |= (s))
#if 0
#define SET_ICUS() {outb(IO_ICU1 + 1, imen); outb(IU_ICU2 + 1, imen >> 8);}
#define SET_ICUS() (outb(IO_ICU1 + 1, imen), outb(IU_ICU2 + 1, imen >> 8))
#else
/*
* XXX - IO_ICU* are defined in isa.h, not icu.h, and nothing much bothers to
* include isa.h, while too many things include icu.h.
*/
#define SET_ICUS() {outb(0x21, imen); outb(0xa1, imen >> 8);}
#define SET_ICUS() (outb(0x21, imen), outb(0xa1, imen >> 8))
#endif
#endif
@ -94,4 +94,4 @@ extern unsigned imen; /* interrupt mask enable */
#define ICU_OFFSET 32 /* 0-31 are processor exceptions */
#define ICU_LEN 16 /* 32-47 are ISA interrupts */
#endif __ICU__
#endif /* !_I386_ISA_ICU_H_ */

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
* $Id: clock.c,v 1.17 1994/09/14 23:09:06 ache Exp $
* $Id: clock.c,v 1.18 1994/09/18 20:39:42 wollman Exp $
*/
/*
@ -44,13 +44,17 @@
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <machine/segments.h>
#include <machine/frame.h>
#include <i386/isa/icu.h>
#include <i386/isa/isa.h>
#include <i386/isa/rtc.h>
#include <i386/isa/timerreg.h>
#include <machine/cpu.h>
/*
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
* can use a simple formula for leap years.
*/
#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
/* X-tals being what they are, it's nice to be able to fudge this one... */
/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */
@ -58,9 +62,8 @@
#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */
#endif
#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
#define LEAPYEAR(y) (!((y)%4) && ((y)%100) || !((y)%400))
static int beeping;
static int beeping;
int timer0_divisor = TIMER_DIV(100); /* XXX should be hz */
u_int timer0_prescale;
int adjkerntz = 0; /* offset from CMOS clock */
@ -258,7 +261,7 @@ calibrate_cyclecounter(void)
void
DELAY(int n)
{
int counter_limit, prev_tick, tick, ticks_left, sec, usec;
int prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@ -314,7 +317,8 @@ DELAY(int n)
static void
sysbeepstop()
sysbeepstop(chan)
void *chan;
{
outb(IO_PPI, inb(IO_PPI)&0xFC); /* disable counter2 output to speaker */
release_timer2();
@ -335,7 +339,7 @@ sysbeep(int pitch, int period)
if (!beeping) {
outb(IO_PPI, inb(IO_PPI) | 3); /* enable counter2 output to speaker */
beeping = period;
timeout(sysbeepstop, 0, period);
timeout(sysbeepstop, (void *)NULL, period);
}
return 0;
}
@ -489,16 +493,6 @@ enablertclock()
outb(IO_RTC+1, RTCSB_PINTR | RTCSB_24HR);
}
/*
* Delay for some number of milliseconds.
*/
void
spinwait(int millisecs)
{
DELAY(1000 * millisecs);
}
void
cpu_initclocks()
{

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
* $Id: clock.c,v 1.17 1994/09/14 23:09:06 ache Exp $
* $Id: clock.c,v 1.18 1994/09/18 20:39:42 wollman Exp $
*/
/*
@ -44,13 +44,17 @@
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <machine/segments.h>
#include <machine/frame.h>
#include <i386/isa/icu.h>
#include <i386/isa/isa.h>
#include <i386/isa/rtc.h>
#include <i386/isa/timerreg.h>
#include <machine/cpu.h>
/*
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
* can use a simple formula for leap years.
*/
#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
/* X-tals being what they are, it's nice to be able to fudge this one... */
/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */
@ -58,9 +62,8 @@
#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */
#endif
#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
#define LEAPYEAR(y) (!((y)%4) && ((y)%100) || !((y)%400))
static int beeping;
static int beeping;
int timer0_divisor = TIMER_DIV(100); /* XXX should be hz */
u_int timer0_prescale;
int adjkerntz = 0; /* offset from CMOS clock */
@ -258,7 +261,7 @@ calibrate_cyclecounter(void)
void
DELAY(int n)
{
int counter_limit, prev_tick, tick, ticks_left, sec, usec;
int prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@ -314,7 +317,8 @@ DELAY(int n)
static void
sysbeepstop()
sysbeepstop(chan)
void *chan;
{
outb(IO_PPI, inb(IO_PPI)&0xFC); /* disable counter2 output to speaker */
release_timer2();
@ -335,7 +339,7 @@ sysbeep(int pitch, int period)
if (!beeping) {
outb(IO_PPI, inb(IO_PPI) | 3); /* enable counter2 output to speaker */
beeping = period;
timeout(sysbeepstop, 0, period);
timeout(sysbeepstop, (void *)NULL, period);
}
return 0;
}
@ -489,16 +493,6 @@ enablertclock()
outb(IO_RTC+1, RTCSB_PINTR | RTCSB_24HR);
}
/*
* Delay for some number of milliseconds.
*/
void
spinwait(int millisecs)
{
DELAY(1000 * millisecs);
}
void
cpu_initclocks()
{

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)icu.h 5.6 (Berkeley) 5/9/91
* $Id: icu.h,v 1.3 1994/04/02 07:00:40 davidg Exp $
* $Id: icu.h,v 1.4 1994/09/16 13:33:38 davidg Exp $
*/
/*
@ -42,8 +42,8 @@
* W. Jolitz 8/89
*/
#ifndef __ICU__
#define __ICU__
#ifndef _I386_ISA_ICU_H_
#define _I386_ISA_ICU_H_
#ifndef LOCORE
@ -52,17 +52,17 @@
*/
extern unsigned imen; /* interrupt mask enable */
#define INTREN(s) {imen &= ~(s); SET_ICUS()}
#define INTRDIS(s) {imen |= (s); SET_ICUS()}
#define INTREN(s) (imen &= ~(s), SET_ICUS())
#define INTRDIS(s) (imen |= (s), SET_ICUS())
#define INTRMASK(msk,s) (msk |= (s))
#if 0
#define SET_ICUS() {outb(IO_ICU1 + 1, imen); outb(IU_ICU2 + 1, imen >> 8);}
#define SET_ICUS() (outb(IO_ICU1 + 1, imen), outb(IU_ICU2 + 1, imen >> 8))
#else
/*
* XXX - IO_ICU* are defined in isa.h, not icu.h, and nothing much bothers to
* include isa.h, while too many things include icu.h.
*/
#define SET_ICUS() {outb(0x21, imen); outb(0xa1, imen >> 8);}
#define SET_ICUS() (outb(0x21, imen), outb(0xa1, imen >> 8))
#endif
#endif
@ -94,4 +94,4 @@ extern unsigned imen; /* interrupt mask enable */
#define ICU_OFFSET 32 /* 0-31 are processor exceptions */
#define ICU_LEN 16 /* 32-47 are ISA interrupts */
#endif __ICU__
#endif /* !_I386_ISA_ICU_H_ */

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)clock.c 7.2 (Berkeley) 5/12/91
* $Id: clock.c,v 1.17 1994/09/14 23:09:06 ache Exp $
* $Id: clock.c,v 1.18 1994/09/18 20:39:42 wollman Exp $
*/
/*
@ -44,13 +44,17 @@
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <machine/segments.h>
#include <machine/frame.h>
#include <i386/isa/icu.h>
#include <i386/isa/isa.h>
#include <i386/isa/rtc.h>
#include <i386/isa/timerreg.h>
#include <machine/cpu.h>
/*
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
* can use a simple formula for leap years.
*/
#define LEAPYEAR(y) ((u_int)(y) % 4 == 0)
/* X-tals being what they are, it's nice to be able to fudge this one... */
/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */
@ -58,9 +62,8 @@
#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */
#endif
#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
#define LEAPYEAR(y) (!((y)%4) && ((y)%100) || !((y)%400))
static int beeping;
static int beeping;
int timer0_divisor = TIMER_DIV(100); /* XXX should be hz */
u_int timer0_prescale;
int adjkerntz = 0; /* offset from CMOS clock */
@ -258,7 +261,7 @@ calibrate_cyclecounter(void)
void
DELAY(int n)
{
int counter_limit, prev_tick, tick, ticks_left, sec, usec;
int prev_tick, tick, ticks_left, sec, usec;
#ifdef DELAYDEBUG
int getit_calls = 1;
@ -314,7 +317,8 @@ DELAY(int n)
static void
sysbeepstop()
sysbeepstop(chan)
void *chan;
{
outb(IO_PPI, inb(IO_PPI)&0xFC); /* disable counter2 output to speaker */
release_timer2();
@ -335,7 +339,7 @@ sysbeep(int pitch, int period)
if (!beeping) {
outb(IO_PPI, inb(IO_PPI) | 3); /* enable counter2 output to speaker */
beeping = period;
timeout(sysbeepstop, 0, period);
timeout(sysbeepstop, (void *)NULL, period);
}
return 0;
}
@ -489,16 +493,6 @@ enablertclock()
outb(IO_RTC+1, RTCSB_PINTR | RTCSB_24HR);
}
/*
* Delay for some number of milliseconds.
*/
void
spinwait(int millisecs)
{
DELAY(1000 * millisecs);
}
void
cpu_initclocks()
{