--- Gnu-Mach/i386/i386at/rtc.c 2020/09/02 04:36:58 1.1 +++ Gnu-Mach/i386/i386at/rtc.c 2020/09/02 04:51:32 1.1.1.5 @@ -1,25 +1,25 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ @@ -48,14 +48,15 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT #include #include -#include +#include #include +#include #include -static unsigned char rtc[RTC_NREG]; -static int first_rtcopen_ever = 1; +static boolean_t first_rtcopen_ever = TRUE; -rtcinit() +void +rtcinit(void) { outb(RTC_ADDR, RTC_A); outb(RTC_DATA, RTC_DIV2 | RTC_RATE6); @@ -65,68 +66,66 @@ rtcinit() int -rtcget(regs) -unsigned char *regs; +rtcget(struct rtc_st *st) { + unsigned char *regs = (unsigned char *)st; if (first_rtcopen_ever) { rtcinit(); - first_rtcopen_ever = 0; + first_rtcopen_ever = FALSE; } - outb(RTC_ADDR, RTC_D); - if (inb(RTC_DATA) & RTC_VRT == 0) return(-1); - outb(RTC_ADDR, RTC_A); + outb(RTC_ADDR, RTC_D); + if ((inb(RTC_DATA) & RTC_VRT) == 0) return(-1); + outb(RTC_ADDR, RTC_A); while (inb(RTC_DATA) & RTC_UIP) /* busy wait */ - outb(RTC_ADDR, RTC_A); + outb(RTC_ADDR, RTC_A); load_rtc(regs); return(0); -} +} -rtcput(regs) -unsigned char *regs; +void +rtcput(struct rtc_st *st) { - register unsigned char x; + unsigned char *regs = (unsigned char *)st; + unsigned char x; if (first_rtcopen_ever) { rtcinit(); - first_rtcopen_ever = 0; + first_rtcopen_ever = FALSE; } outb(RTC_ADDR, RTC_B); x = inb(RTC_DATA); outb(RTC_ADDR, RTC_B); - outb(RTC_DATA, x | RTC_SET); + outb(RTC_DATA, x | RTC_SET); save_rtc(regs); outb(RTC_ADDR, RTC_B); - outb(RTC_DATA, x & ~RTC_SET); + outb(RTC_DATA, x & ~RTC_SET); } extern struct timeval time; -extern struct timezone tz; static int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -yeartoday(year) -int year; +int +yeartoday(int year) { return((year%4) ? 365 : 366); } -hexdectodec(n) -char n; +int +hexdectodec(char n) { return(((n>>4)&0x0F)*10 + (n&0x0F)); } char -dectohexdec(n) -int n; +dectohexdec(int n) { return((char)(((n/10)<<4)&0xF0) | ((n%10)&0x0F)); } - -readtodc(tp) - u_int *tp; +int +readtodc(u_int *tp) { struct rtc_st rtclk; time_t n; @@ -134,11 +133,7 @@ readtodc(tp) int i, days = 0; spl_t ospl; -#ifdef MACH_KERNEL ospl = splclock(); -#else MACH_KERNEL - ospl = spl5(); -#endif MACH_KERNEL if (rtcget(&rtclk)) { splx(ospl); return(-1); @@ -165,43 +160,28 @@ readtodc(tp) days += yeartoday(i); n += days * 3600 * 24; -#ifdef MACH_KERNEL -#else MACH_KERNEL - n += tz.tz_minuteswest * 60; - if (tz.tz_dsttime) - n -= 3600; -#endif MACH_KERNEL *tp = n; return(0); } -writetodc() +int +writetodc(void) { struct rtc_st rtclk; time_t n; int diff, i, j; spl_t ospl; -#ifdef MACH_KERNEL ospl = splclock(); -#else MACH_KERNEL - ospl = spl5(); -#endif MACH_KERNEL if (rtcget(&rtclk)) { splx(ospl); return(-1); } splx(ospl); -#ifdef MACH_KERNEL diff = 0; -#else MACH_KERNEL - diff = tz.tz_minuteswest * 60; - if (tz.tz_dsttime) - diff -= 3600; -#endif MACH_KERNEL n = (time.tv_sec - diff) % (3600 * 24); /* hrs+mins+secs */ rtclk.rtc_sec = dectohexdec(n%60); n /= 60; @@ -225,11 +205,7 @@ writetodc() rtclk.rtc_dom = dectohexdec(++n); -#ifdef MACH_KERNEL ospl = splclock(); -#else MACH_KERNEL - ospl = spl5(); -#endif MACH_KERNEL rtcput(&rtclk); splx(ospl);