1: /*
   2:  *	@(#)ka630.c	7.1 (Berkeley) 6/5/86
   3:  */
   4: #if defined(VAX630)
   5: /* ka630.c routines for the ka630 clock chip... */
   6: #include "param.h"
   7: #include "time.h"
   8: #include "kernel.h"
   9: #include "vmmac.h"
  10: 
  11: #include "mtpr.h"
  12: #include "cpu.h"
  13: #include "clock.h"
  14: #include "pte.h"
  15: #include "ka630.h"
  16: 
  17: /*
  18:  * These two fuctions handle the tod clock
  19:  * This code is defunct at the end of the century.
  20:  * Will Unix still be here then??
  21:  */
  22: 
  23: struct cldevice cldevice;
  24: struct ka630cpu ka630cpu;
  25: 
  26: short dayyr[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, };
  27: /* Starts the tod clock. Called from clkstart... */
  28: ka630tod(base)
  29:     time_t base;
  30: {
  31:     register int tmp1, tmp2;
  32:     struct pte *pte = &Clockmap[0];
  33:     register struct cldevice *claddr = &cldevice;
  34:     struct ka630cpu *ka630addr = &ka630cpu;
  35: 
  36:     /* Enable system page for registers */
  37:     *(int *)pte = PG_V|PG_KW|btop(0x200b8000);
  38:     pte = &Ka630map[0];
  39:     *(int *)pte = PG_V|PG_KW|btop(0x20080000);
  40:     mtpr(TBIA, 0);
  41:     /*
  42: 	 * Clear restart and boot in progress flags in the CPMBX. This has
  43: 	 * nothing to do with the clock except that it the CPMBX reg. is a
  44: 	 * byte in the clock's ram.
  45: 	 */
  46:     claddr->cpmbx=(u_short)((claddr->cpmbx&KA630CLK_LANG)|KA630CLK_REBOOT);
  47:     /*
  48: 	 * Enable memory parity error detection. again nothing to do with the
  49: 	 * tod clock except for being a convenient place.
  50: 	 */
  51:     ka630addr->ka630_mser = KA630MSER_PAREN;
  52:     claddr->csr1 = KA630CLK_SET;
  53:     while ((claddr->csr0 & KA630CLK_UIP) != 0)
  54:         ;
  55:     /* If the clock is valid, use it. */
  56:     if ((claddr->csr3 & KA630CLK_VRT) != 0 &&
  57:         (claddr->csr1 & KA630CLK_ENABLE) == KA630CLK_ENABLE) {
  58:         /* Convert yr,mon,day,hr,min,sec to sec past Jan.1, 1970. */
  59:         tmp2 = 0;
  60:         for (tmp1 = 70; tmp1 < claddr->yr; tmp1++) {
  61:             tmp2 += 365;
  62:             /* I just luv leap years... */
  63:             if (LEAPYEAR(tmp1))
  64:                 tmp2++;
  65:         }
  66:         tmp2 += (dayyr[claddr->mon-1]+claddr->day-1);
  67:         if (LEAPYEAR(claddr->yr) && claddr->mon > 2)
  68:             tmp2++;
  69:         /* Finally got days past Jan. 1,1970. the rest is easy.. */
  70:         time.tv_sec = tmp2*SECDAY+claddr->hr*HRSEC+
  71:             claddr->min*MINSEC+claddr->sec;
  72:         tmp1 = claddr->csr2;
  73:         claddr->csr0 = KA630CLK_RATE;
  74:         claddr->csr1 = KA630CLK_ENABLE;
  75:     } else if (base < 5*SECYR) {
  76:         printf("WARNING: preposterous time in file system\n");
  77:         time.tv_sec = 6*SECYR+186*SECDAY+SECDAY/2;
  78:         ka630stod();
  79:     } else {
  80:         printf("WARNING: Time set via file system\n");
  81:         time.tv_sec = base;
  82:         ka630stod();
  83:     }
  84: }
  85: /* Set the time of day clock, called via. stime system call.. */
  86: ka630stod()
  87: {
  88:     register int tmp1, tmp3;
  89:     register struct cldevice *claddr = &cldevice;
  90:     long tmp2, tmp4;
  91: 
  92:     claddr->csr1 = KA630CLK_SET;
  93:     while ((claddr->csr0 & KA630CLK_UIP) != 0)
  94:         ;
  95:     /* The reverse of above, sec. past Jan. 1,1970 to yr, mon... */
  96:     tmp2 = time.tv_sec/HRSEC;
  97:     tmp4 = tmp2 = tmp2/24;
  98:     tmp1 = 69;
  99:     while (tmp2 >= 0) {
 100:         tmp3 = tmp2;
 101:         tmp2 -= 365;
 102:         tmp1++;
 103:         if (LEAPYEAR(tmp1))
 104:             tmp2--;
 105:     }
 106:     /* Got the year... */
 107:     claddr->yr = tmp1;
 108:     tmp1 = -1;
 109:     do {
 110:         tmp2 = tmp3-dayyr[++tmp1];
 111:         if (LEAPYEAR(claddr->yr) && tmp1 > 1)
 112:             tmp2--;
 113:     } while (tmp2 >= 0);
 114:     /* Finally, got the rest... */
 115:     claddr->mon = tmp1;
 116:     claddr->day = tmp3-dayyr[tmp1-1]+1;
 117:     if (LEAPYEAR(claddr->yr) && tmp1 > 2)
 118:         claddr->day--;
 119:     tmp2 = time.tv_sec-(tmp4*SECDAY);
 120:     claddr->hr = tmp2/HRSEC;
 121:     tmp2 = tmp2%HRSEC;
 122:     claddr->min = tmp2/MINSEC;
 123:     tmp2 = tmp2%MINSEC;
 124:     claddr->sec = tmp2;
 125:     tmp1 = claddr->csr2;
 126:     tmp1 = claddr->csr3;
 127:     claddr->csr0 = KA630CLK_RATE;
 128:     claddr->csr1 = KA630CLK_ENABLE;
 129: }
 130: #endif

Defined functions

ka630stod defined in line 86; used 3 times
ka630tod defined in line 28; used 1 times

Defined variables

cldevice defined in line 23; used 2 times
dayyr defined in line 26; used 3 times
ka630cpu defined in line 24; used 1 times
  • in line 34
Last modified: 1986-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1128
Valid CSS Valid XHTML 1.0 Strict