iiasa fixup
[unix-history] / usr / src / sys / vax / vax / machdep.c
CommitLineData
81263dba 1/* machdep.c 3.4 %H% */
79821b2c
BJ
2
3#include "../h/param.h"
4#include "../h/systm.h"
5#include "../h/dir.h"
6#include "../h/user.h"
7#include "../h/map.h"
8#include "../h/reg.h"
9#include "../h/mtpr.h"
10#include "../h/clock.h"
11#include "../h/pte.h"
12#include "../h/vm.h"
13#include "../h/proc.h"
14#include "../h/psl.h"
15
16char version[] = "VM/UNIX (Berkeley Version 3.1) 4/2/80 \n";
17int icode[] =
18{
19 0x9f19af9f, /* pushab [&"init.vm",0]; pushab */
20 0x02dd09af, /* "/etc/init.vm"; pushl $2 */
21 0xbc5c5ed0, /* movl sp,ap; chmk */
22 0x2ffe110b, /* $exec; brb .; "/ */
23 0x2f637465, /* etc/ */
24 0x74696e69, /* init */
80f49ec9 25 0x00000000, /* \0\0\0"; 0 */ /* was .vm" */
79821b2c
BJ
26 0x00000014, /* [&"init", */
27 0x00000000, /* 0] */
28};
29int szicode = sizeof(icode);
30int memchk();
31
32/*
33 * Machine-dependent startup code
34 */
35startup(firstaddr)
36{
37 register int unixsize;
38
39 /*
40 * Good {morning,afternoon,evening,night}.
41 */
42
43 printf(version);
44 printf("real mem = %d\n", ctob(maxmem));
45
46 /*
47 * Allow for the u. area of process 0.
48 */
49 unixsize = (firstaddr+UPAGES+1);
50 if (coresw)
1fb18892 51 maxmem = 4096;
79821b2c
BJ
52
53 /*
54 * Initialize maps.
55 */
56 meminit(unixsize, maxmem);
57 maxmem -= (unixsize+1);
58 printf("avail mem = %d\n", ctob(maxmem));
59 mfree(swapmap, nswap - CLSIZE, CLSIZE);
60 mfree(kernelmap, USRPTSIZE, 1);
61 swplo--;
62 mbainit();
63 ubainit();
64 timeout(memchk, (caddr_t)0, 60); /* it will pick its own intvl */
65}
66
67/*
68 * set up a physical address
69 * into users virtual address space.
70 */
71sysphys()
72{
73
74 if(!suser())
75 return;
76 u.u_error = EINVAL;
77}
78
79/*
80 * Start clock
81 */
82clkstart()
83{
84
85 mtpr(NICR, -16667); /* 16.667 milli-seconds */
86 mtpr(ICCS, ICCS_RUN+ICCS_IE+ICCS_TRANS+ICCS_INT+ICCS_ERR);
87}
88
89clkreld()
90{
91
92 mtpr(ICCS, ICCS_RUN+ICCS_IE+ICCS_INT+ICCS_ERR);
93}
94
95#ifdef PGINPROF
96/*
97 * Return the difference (in microseconds)
98 * between the current time and a previous
99 * time as represented by the arguments.
100 * If there is a pending clock interrupt
101 * which has not been serviced due to high
102 * ipl, return error code.
103 */
104vmtime(otime, olbolt, oicr)
105 register int otime, olbolt, oicr;
106{
107
108 if (mfpr(ICCS)&ICCS_INT)
109 return(-1);
110 else
111 return(((time-otime)*60 + lbolt-olbolt)*16667 + mfpr(ICR)-oicr);
112}
113#endif
114
115/*
116 * Send an interrupt to process
117 */
118sendsig(p, n)
119{
120 register int *usp, *regs;
121
122 regs = u.u_ar0;
123 usp = (int *)regs[SP];
124#ifdef FASTVAX
125 usp -= 5;
126 if ((int)usp <= USRSTACK - ctob(u.u_ssize))
81263dba 127 (void) grow((unsigned)usp);
79821b2c
BJ
128 ; /* Avoid asm() label botch */
129 asm("probew $3,$20,(r11)");
130 asm("beql bad");
131 *usp++ = n;
132 *usp++ = n == SIGINS ? u.u_cfcode : 0;
133 *usp++ = p;
134 *usp++ = regs[PC];
135 *usp++ = regs[PS];
136 regs[SP] = (int)(usp - 5);
137#else
81263dba 138 (void) grow((unsigned)(usp-5));
79821b2c
BJ
139 if (suword((caddr_t)--usp, regs[PS]))
140 goto bad;
141 if (suword((caddr_t)--usp, regs[PC]))
142 goto bad;
143 if (suword((caddr_t)--usp, p))
144 goto bad;
145 if (suword((caddr_t)--usp, n==SIGINS ? u.u_cfcode : 0))
146 goto bad;
147 if (suword((caddr_t)--usp, n))
148 goto bad;
149 regs[SP] = (int)usp;
150#endif
151 regs[PS] &= ~(PSL_CM|PSL_FPD);
152 regs[PC] = (int)u.u_pcb.pcb_sigc;
153 return;
154
155#ifdef FASTVAX
156asm("bad:");
157#endif
158bad:
159 printf("%d: cant send signal\n", u.u_procp->p_pid);
160 psignal(u.u_procp, SIGKIL);
161}
162
163/*
164 * Check memory controller for memory parity errors
165 */
166#define MEMINTVL (60*60*10) /* 10 minutes */
167int memintvl = MEMINTVL;
168
169#define MHIERR 0x20000000
170#define MERLOG 0x10000000
171
172memchk()
173{
174 register int c = mcr[2];
175
176 if (c & MERLOG) {
177 printf("MEMERR: %X\n", c);
178 mcr[2] = (MERLOG|MHIERR);
179 }
180 if (memintvl > 0)
181 timeout(memchk, (caddr_t)0, memintvl);
182}
183
184/*
185 * Invalidate single all pte's in a cluster
186 */
187tbiscl(v)
188 unsigned v;
189{
190 register caddr_t addr; /* must be first reg var */
191 register int i;
192
193 asm(".set TBIS,58");
194 addr = ptob(v);
195 for (i = 0; i < CLSIZE; i++) {
196#ifdef lint
197 mtpr(TBIS, addr);
198#else
199 asm("mtpr r11,$TBIS");
200#endif
201 addr += NBPG;
202 }
203}