cpu.h revision 1.58 1 1.58 simonb /* $NetBSD: cpu.h,v 1.58 2002/03/05 15:34:04 simonb Exp $ */
2 1.8 cgd
3 1.1 deraadt /*-
4 1.5 glass * Copyright (c) 1992, 1993
5 1.5 glass * The Regents of the University of California. All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * This code is derived from software contributed to Berkeley by
8 1.1 deraadt * Ralph Campbell and Rick Macklem.
9 1.1 deraadt *
10 1.1 deraadt * Redistribution and use in source and binary forms, with or without
11 1.1 deraadt * modification, are permitted provided that the following conditions
12 1.1 deraadt * are met:
13 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
14 1.1 deraadt * notice, this list of conditions and the following disclaimer.
15 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
17 1.1 deraadt * documentation and/or other materials provided with the distribution.
18 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
19 1.1 deraadt * must display the following acknowledgement:
20 1.1 deraadt * This product includes software developed by the University of
21 1.1 deraadt * California, Berkeley and its contributors.
22 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
23 1.1 deraadt * may be used to endorse or promote products derived from this software
24 1.1 deraadt * without specific prior written permission.
25 1.1 deraadt *
26 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 deraadt * SUCH DAMAGE.
37 1.1 deraadt *
38 1.8 cgd * @(#)cpu.h 8.4 (Berkeley) 1/4/94
39 1.1 deraadt */
40 1.1 deraadt
41 1.1 deraadt #ifndef _CPU_H_
42 1.1 deraadt #define _CPU_H_
43 1.1 deraadt
44 1.54 simonb #include <mips/cpuregs.h>
45 1.53 simonb
46 1.1 deraadt /*
47 1.13 jonathan * Exported definitions unique to NetBSD/mips cpu support.
48 1.1 deraadt */
49 1.36 soren
50 1.53 simonb #ifndef _LOCORE
51 1.55 simonb #include <sys/sched.h>
52 1.55 simonb
53 1.53 simonb #if defined(_KERNEL_OPT)
54 1.53 simonb #include "opt_lockdebug.h"
55 1.53 simonb #endif
56 1.53 simonb
57 1.53 simonb struct cpu_info {
58 1.53 simonb struct schedstate_percpu ci_schedstate; /* scheduler state */
59 1.58 simonb u_long ci_cpu_freq; /* CPU frequency */
60 1.58 simonb u_long ci_cycles_per_hz; /* CPU freq / hz */
61 1.58 simonb u_long ci_divisor_delay; /* for delay/DELAY */
62 1.53 simonb #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
63 1.53 simonb u_long ci_spin_locks; /* # of spin locks held */
64 1.53 simonb u_long ci_simple_locks; /* # of simple locks held */
65 1.53 simonb #endif
66 1.53 simonb };
67 1.53 simonb #endif /* !defined(_LOCORE) */
68 1.53 simonb
69 1.36 soren /*
70 1.36 soren * CTL_MACHDEP definitions.
71 1.36 soren */
72 1.36 soren #define CPU_CONSDEV 1 /* dev_t: console terminal device */
73 1.36 soren #define CPU_BOOTED_KERNEL 2 /* string: booted kernel name */
74 1.36 soren #define CPU_ROOT_DEVICE 3 /* string: root device name */
75 1.43 jeffs
76 1.43 jeffs /*
77 1.51 wiz * Platform can override, but note this breaks userland compatibility
78 1.43 jeffs * with other mips platforms.
79 1.43 jeffs */
80 1.43 jeffs #ifndef CPU_MAXID
81 1.36 soren #define CPU_MAXID 4 /* number of valid machdep ids */
82 1.36 soren
83 1.36 soren #define CTL_MACHDEP_NAMES { \
84 1.36 soren { 0, 0 }, \
85 1.36 soren { "console_device", CTLTYPE_STRUCT }, \
86 1.36 soren { "booted_kernel", CTLTYPE_STRING }, \
87 1.36 soren { "root_device", CTLTYPE_STRING }, \
88 1.36 soren }
89 1.42 jeffs #endif
90 1.33 simonb
91 1.33 simonb #ifdef _KERNEL
92 1.33 simonb #ifndef _LOCORE
93 1.53 simonb extern struct cpu_info cpu_info_store;
94 1.53 simonb
95 1.53 simonb #define curcpu() (&cpu_info_store)
96 1.53 simonb #define cpu_number() (0)
97 1.58 simonb #endif /* !_LOCORE */
98 1.33 simonb
99 1.33 simonb /*
100 1.21 jonathan * Macros to find the CPU architecture we're on at run-time,
101 1.21 jonathan * or if possible, at compile-time.
102 1.21 jonathan */
103 1.21 jonathan
104 1.58 simonb #define CPU_ARCH_MIPSx 0 /* XXX unknown */
105 1.46 cgd #define CPU_ARCH_MIPS1 (1 << 0)
106 1.46 cgd #define CPU_ARCH_MIPS2 (1 << 1)
107 1.46 cgd #define CPU_ARCH_MIPS3 (1 << 2)
108 1.46 cgd #define CPU_ARCH_MIPS4 (1 << 3)
109 1.46 cgd #define CPU_ARCH_MIPS5 (1 << 4)
110 1.46 cgd #define CPU_ARCH_MIPS32 (1 << 5)
111 1.46 cgd #define CPU_ARCH_MIPS64 (1 << 6)
112 1.46 cgd
113 1.58 simonb #ifndef _LOCORE
114 1.58 simonb /* XXX simonb
115 1.58 simonb * Should the following be in a cpu_info type structure?
116 1.58 simonb * And how many of these are per-cpu vs. per-system? (Ie,
117 1.58 simonb * we can assume that all cpus have the same mmu-type, but
118 1.58 simonb * maybe not that all cpus run at the same clock speed.
119 1.58 simonb * Some SGI's apparently support R12k and R14k in the same
120 1.58 simonb * box.)
121 1.58 simonb */
122 1.58 simonb extern int cpu_arch;
123 1.58 simonb extern int mips_cpu_flags;
124 1.58 simonb extern int mips_has_r4k_mmu;
125 1.58 simonb extern int mips_has_llsc;
126 1.58 simonb extern int mips3_pg_cached;
127 1.58 simonb
128 1.58 simonb #define CPU_MIPS_R4K_MMU 0x0001
129 1.58 simonb #define CPU_MIPS_NO_LLSC 0x0002
130 1.58 simonb #define CPU_MIPS_CAUSE_IV 0x0004
131 1.58 simonb #define CPU_MIPS_HAVE_SPECIAL_CCA 0x0008 /* Defaults to '3' if not set. */
132 1.58 simonb #define CPU_MIPS_CACHED_CCA_MASK 0x0070
133 1.58 simonb #define CPU_MIPS_CACHED_CCA_SHIFT 4
134 1.58 simonb #define MIPS_NOT_SUPP 0x8000
135 1.58 simonb
136 1.58 simonb #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 0
137 1.58 simonb #error at least one of MIPS1, MIPS3, MIPS4, MIPS32 or MIPS64 must be specified
138 1.58 simonb #endif
139 1.58 simonb
140 1.58 simonb #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 1
141 1.21 jonathan #ifdef MIPS1
142 1.58 simonb # define CPUISMIPS3 0
143 1.58 simonb # define CPUIS64BITS 0
144 1.58 simonb # define CPUISMIPS32 0
145 1.58 simonb # define CPUISMIPS64 0
146 1.58 simonb # define CPUISMIPSNN 0
147 1.58 simonb # define MIPS_HAS_R4K_MMU 0
148 1.58 simonb # define MIPS_HAS_CLOCK 0
149 1.58 simonb # define MIPS_HAS_LLSC 0
150 1.58 simonb #endif /* MIPS1 */
151 1.58 simonb
152 1.58 simonb #if defined(MIPS3) || defined(MIPS4)
153 1.58 simonb # define CPUISMIPS3 1
154 1.58 simonb # define CPUIS64BITS 1
155 1.58 simonb # define CPUISMIPS32 0
156 1.58 simonb # define CPUISMIPS64 0
157 1.58 simonb # define CPUISMIPSNN 0
158 1.58 simonb # define MIPS_HAS_R4K_MMU 1
159 1.58 simonb # define MIPS_HAS_CLOCK 1
160 1.58 simonb # define MIPS_HAS_LLSC (mips_has_llsc)
161 1.58 simonb #endif /* MIPS3 || MIPS4 */
162 1.58 simonb
163 1.58 simonb #ifdef MIPS32
164 1.58 simonb # define CPUISMIPS3 1
165 1.58 simonb # define CPUIS64BITS 0
166 1.58 simonb # define CPUISMIPS32 1
167 1.58 simonb # define CPUISMIPS64 0
168 1.58 simonb # define CPUISMIPSNN 1
169 1.58 simonb # define MIPS_HAS_R4K_MMU 1
170 1.58 simonb # define MIPS_HAS_CLOCK 1
171 1.58 simonb # define MIPS_HAS_LLSC 1
172 1.58 simonb #endif /* MIPS32 */
173 1.58 simonb
174 1.58 simonb #ifdef MIPS64
175 1.58 simonb # define CPUISMIPS3 1
176 1.58 simonb # define CPUIS64BITS 1
177 1.58 simonb # define CPUISMIPS32 0
178 1.58 simonb # define CPUISMIPS64 1
179 1.58 simonb # define CPUISMIPSNN 1
180 1.58 simonb # define MIPS_HAS_R4K_MMU 1
181 1.58 simonb # define MIPS_HAS_CLOCK 1
182 1.58 simonb # define MIPS_HAS_LLSC 1
183 1.58 simonb #endif /* MIPS32 */
184 1.21 jonathan
185 1.58 simonb #else /* run-time test */
186 1.21 jonathan
187 1.58 simonb #define MIPS_HAS_R4K_MMU (mips_has_r4k_mmu)
188 1.58 simonb #define MIPS_HAS_LLSC (mips_has_llsc)
189 1.45 cgd
190 1.45 cgd /* This test is ... rather bogus */
191 1.58 simonb #define CPUISMIPS3 ((cpu_arch & \
192 1.58 simonb (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
193 1.58 simonb
194 1.58 simonb /* And these aren't much better while the previous test exists as is... */
195 1.58 simonb #define CPUISMIPS32 ((cpu_arch & CPU_ARCH_MIPS32) != 0)
196 1.58 simonb #define CPUISMIPS64 ((cpu_arch & CPU_ARCH_MIPS64) != 0)
197 1.58 simonb #define CPUISMIPSNN ((cpu_arch & (CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
198 1.58 simonb #define CPUIS64BITS ((cpu_arch & \
199 1.58 simonb (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS64)) != 0)
200 1.58 simonb
201 1.58 simonb #define MIPS_HAS_CLOCK (cpu_arch >= CPU_ARCH_MIPS3)
202 1.21 jonathan #endif /* run-time test */
203 1.21 jonathan
204 1.58 simonb /* Shortcut for MIPS3 or above defined */
205 1.58 simonb #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
206 1.58 simonb #define MIPS3_PLUS 1
207 1.58 simonb #else
208 1.58 simonb #undef MIPS3_PLUS
209 1.58 simonb #endif
210 1.58 simonb
211 1.58 simonb
212 1.21 jonathan /*
213 1.1 deraadt * definitions of cpu-dependent requirements
214 1.1 deraadt * referenced in generic code
215 1.1 deraadt */
216 1.11 cgd #define cpu_wait(p) /* nothing */
217 1.11 cgd #define cpu_swapout(p) panic("cpu_swapout: can't get here");
218 1.42 jeffs
219 1.58 simonb void cpu_intr(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
220 1.1 deraadt
221 1.1 deraadt /*
222 1.1 deraadt * Arguments to hardclock and gatherstats encapsulate the previous
223 1.1 deraadt * machine state in an opaque clockframe.
224 1.1 deraadt */
225 1.5 glass struct clockframe {
226 1.1 deraadt int pc; /* program counter at time of interrupt */
227 1.1 deraadt int sr; /* status register at time of interrupt */
228 1.56 uch int ppl; /* previous priority level at time of interrupt */
229 1.5 glass };
230 1.1 deraadt
231 1.14 jonathan /*
232 1.14 jonathan * A port must provde CLKF_USERMODE() and CLKF_BASEPRI() for use
233 1.14 jonathan * in machine-independent code. These differ on r4000 and r3000 systems;
234 1.14 jonathan * provide them in the port-dependent file that includes this one, using
235 1.14 jonathan * the macros below.
236 1.14 jonathan */
237 1.14 jonathan
238 1.21 jonathan /* mips1 versions */
239 1.22 jonathan #define MIPS1_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KU_PREV)
240 1.21 jonathan #define MIPS1_CLKF_BASEPRI(framep) \
241 1.22 jonathan ((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_ENA_PREV)) == 0)
242 1.14 jonathan
243 1.21 jonathan /* mips3 versions */
244 1.22 jonathan #define MIPS3_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KSU_USER)
245 1.21 jonathan #define MIPS3_CLKF_BASEPRI(framep) \
246 1.34 soren ((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_IE)) == 0)
247 1.14 jonathan
248 1.56 uch #ifdef IPL_ICU_MASK
249 1.56 uch #define ICU_CLKF_BASEPRI(framep) ((framep)->ppl == 0)
250 1.56 uch #endif
251 1.56 uch
252 1.1 deraadt #define CLKF_PC(framep) ((framep)->pc)
253 1.1 deraadt #define CLKF_INTR(framep) (0)
254 1.18 jonathan
255 1.58 simonb #if defined(MIPS3_PLUS) && !defined(MIPS1) /* XXX bogus! */
256 1.21 jonathan #define CLKF_USERMODE(framep) MIPS3_CLKF_USERMODE(framep)
257 1.21 jonathan #define CLKF_BASEPRI(framep) MIPS3_CLKF_BASEPRI(framep)
258 1.21 jonathan #endif
259 1.21 jonathan
260 1.58 simonb #if !defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
261 1.21 jonathan #define CLKF_USERMODE(framep) MIPS1_CLKF_USERMODE(framep)
262 1.21 jonathan #define CLKF_BASEPRI(framep) MIPS1_CLKF_BASEPRI(framep)
263 1.56 uch #endif
264 1.56 uch
265 1.56 uch #ifdef IPL_ICU_MASK
266 1.56 uch #undef CLKF_BASEPRI
267 1.56 uch #define CLKF_BASEPRI(framep) ICU_CLKF_BASEPRI(framep)
268 1.21 jonathan #endif
269 1.21 jonathan
270 1.58 simonb #if defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
271 1.21 jonathan #define CLKF_USERMODE(framep) \
272 1.21 jonathan ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep): MIPS1_CLKF_USERMODE(framep))
273 1.21 jonathan #define CLKF_BASEPRI(framep) \
274 1.21 jonathan ((CPUISMIPS3) ? MIPS3_CLKF_BASEPRI(framep): MIPS1_CLKF_BASEPRI(framep))
275 1.18 jonathan #endif
276 1.18 jonathan
277 1.47 thorpej /*
278 1.47 thorpej * This is used during profiling to integrate system time. It can safely
279 1.47 thorpej * assume that the process is resident.
280 1.47 thorpej */
281 1.48 thorpej #define PROC_PC(p) \
282 1.48 thorpej (((struct frame *)(p)->p_md.md_regs)->f_regs[37]) /* XXX PC */
283 1.1 deraadt
284 1.1 deraadt /*
285 1.1 deraadt * Preempt the current process if in interrupt from user mode,
286 1.1 deraadt * or after the current trap/syscall if in system mode.
287 1.1 deraadt */
288 1.50 thorpej #define need_resched(ci) \
289 1.50 thorpej do { \
290 1.50 thorpej want_resched = 1; \
291 1.50 thorpej if (curproc != NULL) \
292 1.50 thorpej aston(curproc); \
293 1.50 thorpej } while (/*CONSTCOND*/0)
294 1.1 deraadt
295 1.1 deraadt /*
296 1.1 deraadt * Give a profiling tick to the current process when the user profiling
297 1.13 jonathan * buffer pages are invalid. On the MIPS, request an ast to send us
298 1.1 deraadt * through trap, marking the proc as needing a profiling tick.
299 1.1 deraadt */
300 1.50 thorpej #define need_proftick(p) \
301 1.50 thorpej do { \
302 1.50 thorpej (p)->p_flag |= P_OWEUPC; \
303 1.50 thorpej aston(p); \
304 1.50 thorpej } while (/*CONSTCOND*/0)
305 1.1 deraadt
306 1.1 deraadt /*
307 1.1 deraadt * Notify the current process (p) that it has a signal pending,
308 1.1 deraadt * process as soon as possible.
309 1.1 deraadt */
310 1.50 thorpej #define signotify(p) aston(p)
311 1.1 deraadt
312 1.50 thorpej #define aston(p) ((p)->p_md.md_astpending = 1)
313 1.1 deraadt
314 1.49 thorpej extern int want_resched; /* resched() was called */
315 1.28 castor
316 1.23 thorpej /*
317 1.37 simonb * Misc prototypes and variable declarations.
318 1.23 thorpej */
319 1.28 castor struct proc;
320 1.28 castor struct user;
321 1.37 simonb
322 1.37 simonb extern struct proc *fpcurproc;
323 1.25 jonathan
324 1.28 castor /* trap.c */
325 1.58 simonb void netintr(void);
326 1.58 simonb int kdbpeek(vaddr_t);
327 1.23 thorpej
328 1.28 castor /* mips_machdep.c */
329 1.58 simonb void dumpsys(void);
330 1.58 simonb int savectx(struct user *);
331 1.58 simonb void mips_init_msgbuf(void);
332 1.58 simonb void savefpregs(struct proc *);
333 1.58 simonb void loadfpregs(struct proc *);
334 1.13 jonathan
335 1.25 jonathan /* locore.S */
336 1.58 simonb int badaddr(void *, size_t);
337 1.25 jonathan
338 1.25 jonathan /* mips_machdep.c */
339 1.58 simonb void cpu_identify(void);
340 1.58 simonb void mips_vector_init(void);
341 1.27 thorpej
342 1.33 simonb #endif /* ! _LOCORE */
343 1.28 castor #endif /* _KERNEL */
344 1.1 deraadt #endif /* _CPU_H_ */
345