cpu.h revision 1.34 1 /* $NetBSD: cpu.h,v 1.34 2003/01/18 06:55:21 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)cpu.h 8.4 (Berkeley) 1/5/94
45 */
46
47 #ifndef _CPU_H_
48 #define _CPU_H_
49
50 /*
51 * CTL_MACHDEP definitions.
52 */
53 #define CPU_BOOTED_KERNEL 1 /* string: booted kernel name */
54 #define CPU_BOOTED_DEVICE 2 /* string: device booted from */
55 #define CPU_BOOT_ARGS 3 /* string: args booted with */
56 #define CPU_ARCH 4 /* integer: cpu architecture version */
57 #define CPU_MAXID 5 /* number of valid machdep ids */
58
59 #define CTL_MACHDEP_NAMES { \
60 { 0, 0 }, \
61 { "booted_kernel", CTLTYPE_STRING }, \
62 { "booted_device", CTLTYPE_STRING }, \
63 { "boot_args", CTLTYPE_STRING }, \
64 { "cpu_arch", CTLTYPE_INT }, \
65 }
66
67 #ifdef _KERNEL
68 /*
69 * Exported definitions unique to SPARC cpu support.
70 */
71
72 #if !defined(_LKM)
73 #include "opt_multiprocessor.h"
74 #include "opt_lockdebug.h"
75 #endif
76
77 #include <machine/psl.h>
78 #include <machine/reg.h>
79 #include <machine/intr.h>
80 #include <sparc64/sparc64/intreg.h>
81
82 #include <sys/sched.h>
83 /*
84 * The cpu_info structure is part of a 64KB structure mapped both the kernel
85 * pmap and a single locked TTE a CPUINFO_VA for that particular processor.
86 * Each processor's cpu_info is accessible at CPUINFO_VA only for that
87 * processor. Other processors can access that through an additional mapping
88 * in the kernel pmap.
89 *
90 * The 64KB page contains:
91 *
92 * cpu_info
93 * interrupt stack (all remaining space)
94 * idle PCB
95 * idle stack (STACKSPACE - sizeof(PCB))
96 * 32KB TSB
97 */
98
99 struct cpu_info {
100 /* Most important fields first */
101 struct lwp *ci_curlwp;
102 struct pcb *ci_cpcb;
103 struct cpu_info *ci_next;
104
105 struct lwp *ci_fplwp;
106 int ci_number;
107 int ci_upaid;
108 struct schedstate_percpu ci_schedstate;
109
110 /* DEBUG/DIAGNOSTIC stuff */
111 u_long ci_spin_locks;
112 u_long ci_simple_locks;
113
114 /* Spinning up the CPU */
115 void (*ci_spinup) __P((void));
116 void *ci_initstack;
117 paddr_t ci_paddr;
118 };
119
120 extern struct cpu_info *cpus;
121 extern struct cpu_info cpu_info_store;
122
123 #if 1
124 #define curcpu() (&cpu_info_store)
125 #else
126 #define curcpu() ((struct cpu_info *)CPUINFO_VA)
127 #endif
128
129 /*
130 * definitions of cpu-dependent requirements
131 * referenced in generic code
132 */
133 #define cpu_swapin(p) /* nothing */
134 #define cpu_swapout(p) /* nothing */
135 #define cpu_wait(p) /* nothing */
136 #if 1
137 #define cpu_number() 0
138 #else
139 #define cpu_number() (curcpu()->ci_number)
140 #endif
141
142 /* This really should be somewhere else. */
143 #define cpu_proc_fork(p1, p2) /* nothing */
144
145 /*
146 * Arguments to hardclock, softclock and gatherstats encapsulate the
147 * previous machine state in an opaque clockframe. The ipl is here
148 * as well for strayintr (see locore.s:interrupt and intr.c:strayintr).
149 * Note that CLKF_INTR is valid only if CLKF_USERMODE is false.
150 */
151 extern int intstack[];
152 extern int eintstack[];
153 struct clockframe {
154 struct trapframe64 t;
155 };
156
157 #define CLKF_USERMODE(framep) (((framep)->t.tf_tstate & TSTATE_PRIV) == 0)
158 /*
159 * XXX Disable CLKF_BASEPRI() for now. If we use a counter-timer for
160 * the clock, the interrupt remains blocked until the interrupt handler
161 * returns and we write to the clear interrupt register. If we use
162 * %tick for the clock, we could get multiple interrupts, but the
163 * currently enabled INTR_INTERLOCK will prevent the interrupt from being
164 * posted twice anyway.
165 *
166 * Switching to %tick for all machines and disabling INTR_INTERLOCK
167 * in locore.s would allow us to take advantage of CLKF_BASEPRI().
168 */
169 #if 0
170 #define CLKF_BASEPRI(framep) (((framep)->t.tf_oldpil) == 0)
171 #else
172 #define CLKF_BASEPRI(framep) (0)
173 #endif
174 #define CLKF_PC(framep) ((framep)->t.tf_pc)
175 /* Since some files in sys/kern do not know BIAS, I'm using 0x7ff here */
176 #define CLKF_INTR(framep) \
177 ((!CLKF_USERMODE(framep))&& \
178 (((framep)->t.tf_out[6] & 1 ) ? \
179 (((vaddr_t)(framep)->t.tf_out[6] < \
180 (vaddr_t)EINTSTACK-0x7ff) && \
181 ((vaddr_t)(framep)->t.tf_out[6] > \
182 (vaddr_t)INTSTACK-0x7ff)) : \
183 (((vaddr_t)(framep)->t.tf_out[6] < \
184 (vaddr_t)EINTSTACK) && \
185 ((vaddr_t)(framep)->t.tf_out[6] > \
186 (vaddr_t)INTSTACK))))
187
188 /*
189 * Software interrupt request `register'.
190 */
191 #ifdef DEPRECATED
192 union sir {
193 int sir_any;
194 char sir_which[4];
195 } sir;
196
197 #define SIR_NET 0
198 #define SIR_CLOCK 1
199 #endif
200
201 extern struct intrhand soft01intr, soft01net, soft01clock;
202
203 #if 0
204 #define setsoftint() send_softint(-1, IPL_SOFTINT, &soft01intr)
205 #define setsoftnet() send_softint(-1, IPL_SOFTNET, &soft01net)
206 #else
207 void setsoftint __P((void));
208 void setsoftnet __P((void));
209 #endif
210
211 int want_ast;
212
213 /*
214 * Preempt the current process if in interrupt from user mode,
215 * or after the current trap/syscall if in system mode.
216 */
217 int want_resched; /* resched() was called */
218 #define need_resched(ci) (want_resched = 1, want_ast = 1)
219
220 /*
221 * Give a profiling tick to the current process when the user profiling
222 * buffer pages are invalid. On the sparc, request an ast to send us
223 * through trap(), marking the proc as needing a profiling tick.
224 */
225 #define need_proftick(p) ((p)->p_flag |= P_OWEUPC, want_ast = 1)
226
227 /*
228 * Notify the current process (p) that it has a signal pending,
229 * process as soon as possible.
230 */
231 #define signotify(p) (want_ast = 1)
232
233 /*
234 * Only one process may own the FPU state.
235 *
236 * XXX this must be per-cpu (eventually)
237 */
238 struct lwp *fplwp; /* FPU owner */
239
240 /*
241 * Interrupt handler chains. Interrupt handlers should return 0 for
242 * ``not me'' or 1 (``I took care of it''). intr_establish() inserts a
243 * handler into the list. The handler is called with its (single)
244 * argument, or with a pointer to a clockframe if ih_arg is NULL.
245 */
246 struct intrhand {
247 int (*ih_fun) __P((void *));
248 void *ih_arg;
249 short ih_number; /* interrupt number */
250 /* the H/W provides */
251 char ih_pil; /* interrupt priority */
252 struct intrhand *ih_next; /* global list */
253 struct intrhand *ih_pending; /* interrupt queued */
254 volatile u_int64_t *ih_map; /* Interrupt map reg */
255 volatile u_int64_t *ih_clr; /* clear interrupt reg */
256 };
257 extern struct intrhand *intrhand[];
258 extern struct intrhand *intrlev[MAXINTNUM];
259
260 void intr_establish __P((int level, struct intrhand *));
261
262 /* cpu.c */
263 paddr_t cpu_alloc __P((void));
264 u_int64_t cpu_init __P((paddr_t, int));
265 /* disksubr.c */
266 struct dkbad;
267 int isbad __P((struct dkbad *bt, int, int, int));
268 /* machdep.c */
269 int ldcontrolb __P((caddr_t));
270 void dumpconf __P((void));
271 caddr_t reserve_dumppages __P((caddr_t));
272 /* clock.c */
273 struct timeval;
274 int tickintr __P((void *)); /* level 10 (tick) interrupt code */
275 int clockintr __P((void *));/* level 10 (clock) interrupt code */
276 int statintr __P((void *)); /* level 14 (statclock) interrupt code */
277 /* locore.s */
278 struct fpstate64;
279 void savefpstate __P((struct fpstate64 *));
280 void loadfpstate __P((struct fpstate64 *));
281 u_int64_t probeget __P((paddr_t, int, int));
282 int probeset __P((paddr_t, int, int, u_int64_t));
283 #if 0
284 void write_all_windows __P((void));
285 void write_user_windows __P((void));
286 #else
287 #define write_all_windows() __asm __volatile("flushw" : : )
288 #define write_user_windows() __asm __volatile("flushw" : : )
289 #endif
290 void proc_trampoline __P((void));
291 struct pcb;
292 void snapshot __P((struct pcb *));
293 struct frame *getfp __P((void));
294 int xldcontrolb __P((caddr_t, struct pcb *));
295 void copywords __P((const void *, void *, size_t));
296 void qcopy __P((const void *, void *, size_t));
297 void qzero __P((void *, size_t));
298 void switchtoctx __P((int));
299 /* locore2.c */
300 void remrq __P((struct proc *));
301 /* trap.c */
302 void kill_user_windows __P((struct lwp *));
303 int rwindow_save __P((struct lwp *));
304 /* amd7930intr.s */
305 void amd7930_trap __P((void));
306 /* cons.c */
307 int cnrom __P((void));
308 /* zs.c */
309 void zsconsole __P((struct tty *, int, int, void (**)(struct tty *, int)));
310 #ifdef KGDB
311 void zs_kgdb_init __P((void));
312 #endif
313 /* fb.c */
314 void fb_unblank __P((void));
315 /* kgdb_stub.c */
316 #ifdef KGDB
317 void kgdb_attach __P((int (*)(void *), void (*)(void *, int), void *));
318 void kgdb_connect __P((int));
319 void kgdb_panic __P((void));
320 #endif
321 /* emul.c */
322 int fixalign __P((struct lwp *, struct trapframe64 *));
323 int emulinstr __P((vaddr_t, struct trapframe64 *));
324
325 /*
326 *
327 * The SPARC has a Trap Base Register (TBR) which holds the upper 20 bits
328 * of the trap vector table. The next eight bits are supplied by the
329 * hardware when the trap occurs, and the bottom four bits are always
330 * zero (so that we can shove up to 16 bytes of executable code---exactly
331 * four instructions---into each trap vector).
332 *
333 * The hardware allocates half the trap vectors to hardware and half to
334 * software.
335 *
336 * Traps have priorities assigned (lower number => higher priority).
337 */
338
339 struct trapvec {
340 int tv_instr[8]; /* the eight instructions */
341 };
342 extern struct trapvec *trapbase; /* the 256 vectors */
343
344 extern void wzero __P((void *, u_int));
345 extern void wcopy __P((const void *, void *, u_int));
346
347 #endif /* _KERNEL */
348 #endif /* _CPU_H_ */
349