cpu.h revision 1.57.2.4 1 1.57.2.4 nathanw /* $NetBSD: cpu.h,v 1.57.2.4 2002/01/08 00:26:16 nathanw Exp $ */
2 1.57.2.2 wdk
3 1.57.2.2 wdk /*-
4 1.57.2.2 wdk * Copyright (c) 1992, 1993
5 1.57.2.2 wdk * The Regents of the University of California. All rights reserved.
6 1.57.2.2 wdk *
7 1.57.2.2 wdk * This code is derived from software contributed to Berkeley by
8 1.57.2.2 wdk * Ralph Campbell and Rick Macklem.
9 1.57.2.2 wdk *
10 1.57.2.2 wdk * Redistribution and use in source and binary forms, with or without
11 1.57.2.2 wdk * modification, are permitted provided that the following conditions
12 1.57.2.2 wdk * are met:
13 1.57.2.2 wdk * 1. Redistributions of source code must retain the above copyright
14 1.57.2.2 wdk * notice, this list of conditions and the following disclaimer.
15 1.57.2.2 wdk * 2. Redistributions in binary form must reproduce the above copyright
16 1.57.2.2 wdk * notice, this list of conditions and the following disclaimer in the
17 1.57.2.2 wdk * documentation and/or other materials provided with the distribution.
18 1.57.2.2 wdk * 3. All advertising materials mentioning features or use of this software
19 1.57.2.2 wdk * must display the following acknowledgement:
20 1.57.2.2 wdk * This product includes software developed by the University of
21 1.57.2.2 wdk * California, Berkeley and its contributors.
22 1.57.2.2 wdk * 4. Neither the name of the University nor the names of its contributors
23 1.57.2.2 wdk * may be used to endorse or promote products derived from this software
24 1.57.2.2 wdk * without specific prior written permission.
25 1.57.2.2 wdk *
26 1.57.2.2 wdk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.57.2.2 wdk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.57.2.2 wdk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.57.2.2 wdk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.57.2.2 wdk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.57.2.2 wdk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.57.2.2 wdk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.57.2.2 wdk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.57.2.2 wdk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.57.2.2 wdk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.57.2.2 wdk * SUCH DAMAGE.
37 1.57.2.2 wdk *
38 1.57.2.2 wdk * @(#)cpu.h 8.4 (Berkeley) 1/4/94
39 1.57.2.2 wdk */
40 1.57.2.2 wdk
41 1.57.2.2 wdk #ifndef _CPU_H_
42 1.57.2.2 wdk #define _CPU_H_
43 1.57.2.2 wdk
44 1.57.2.2 wdk #include <mips/cpuregs.h>
45 1.57.2.2 wdk
46 1.57.2.2 wdk /*
47 1.57.2.2 wdk * Exported definitions unique to NetBSD/mips cpu support.
48 1.57.2.2 wdk */
49 1.57.2.2 wdk
50 1.57.2.2 wdk #ifndef _LOCORE
51 1.57.2.2 wdk #include <sys/sched.h>
52 1.57.2.2 wdk
53 1.57.2.2 wdk #if defined(_KERNEL_OPT)
54 1.57.2.2 wdk #include "opt_lockdebug.h"
55 1.57.2.2 wdk #endif
56 1.57.2.2 wdk
57 1.57.2.2 wdk struct cpu_info {
58 1.57.2.2 wdk struct schedstate_percpu ci_schedstate; /* scheduler state */
59 1.57.2.2 wdk #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
60 1.57.2.2 wdk u_long ci_spin_locks; /* # of spin locks held */
61 1.57.2.2 wdk u_long ci_simple_locks; /* # of simple locks held */
62 1.57.2.2 wdk #endif
63 1.57.2.2 wdk };
64 1.57.2.2 wdk #endif /* !defined(_LOCORE) */
65 1.57.2.2 wdk
66 1.57.2.2 wdk /*
67 1.57.2.2 wdk * CTL_MACHDEP definitions.
68 1.57.2.2 wdk */
69 1.57.2.2 wdk #define CPU_CONSDEV 1 /* dev_t: console terminal device */
70 1.57.2.2 wdk #define CPU_BOOTED_KERNEL 2 /* string: booted kernel name */
71 1.57.2.2 wdk #define CPU_ROOT_DEVICE 3 /* string: root device name */
72 1.57.2.2 wdk
73 1.57.2.2 wdk /*
74 1.57.2.2 wdk * Platform can override, but note this breaks userland compatibility
75 1.57.2.2 wdk * with other mips platforms.
76 1.57.2.2 wdk */
77 1.57.2.2 wdk #ifndef CPU_MAXID
78 1.57.2.2 wdk #define CPU_MAXID 4 /* number of valid machdep ids */
79 1.57.2.2 wdk
80 1.57.2.2 wdk #define CTL_MACHDEP_NAMES { \
81 1.57.2.2 wdk { 0, 0 }, \
82 1.57.2.2 wdk { "console_device", CTLTYPE_STRUCT }, \
83 1.57.2.2 wdk { "booted_kernel", CTLTYPE_STRING }, \
84 1.57.2.2 wdk { "root_device", CTLTYPE_STRING }, \
85 1.57.2.2 wdk }
86 1.57.2.2 wdk #endif
87 1.57.2.2 wdk
88 1.57.2.2 wdk #ifdef _KERNEL
89 1.57.2.2 wdk #ifndef _LOCORE
90 1.57.2.2 wdk extern struct cpu_info cpu_info_store;
91 1.57.2.2 wdk
92 1.57.2.2 wdk #define curcpu() (&cpu_info_store)
93 1.57.2.2 wdk #define cpu_number() (0)
94 1.57.2.3 thorpej #define cpu_proc_fork(p1, p2)
95 1.57.2.2 wdk
96 1.57.2.2 wdk /*
97 1.57.2.2 wdk * Macros to find the CPU architecture we're on at run-time,
98 1.57.2.2 wdk * or if possible, at compile-time.
99 1.57.2.2 wdk */
100 1.57.2.2 wdk
101 1.57.2.2 wdk extern int cpu_arch;
102 1.57.2.2 wdk
103 1.57.2.2 wdk #define CPU_ARCH_MIPS1 (1 << 0)
104 1.57.2.2 wdk #define CPU_ARCH_MIPS2 (1 << 1)
105 1.57.2.2 wdk #define CPU_ARCH_MIPS3 (1 << 2)
106 1.57.2.2 wdk #define CPU_ARCH_MIPS4 (1 << 3)
107 1.57.2.2 wdk #define CPU_ARCH_MIPS5 (1 << 4)
108 1.57.2.2 wdk #define CPU_ARCH_MIPS32 (1 << 5)
109 1.57.2.2 wdk #define CPU_ARCH_MIPS64 (1 << 6)
110 1.57.2.2 wdk
111 1.57.2.2 wdk #if (MIPS1 + MIPS3) == 1
112 1.57.2.2 wdk #ifdef MIPS1
113 1.57.2.2 wdk # define CPUISMIPS3 0
114 1.57.2.2 wdk #endif /* mips1 */
115 1.57.2.2 wdk
116 1.57.2.2 wdk #ifdef MIPS3
117 1.57.2.2 wdk # define CPUISMIPS3 1
118 1.57.2.2 wdk #endif /* mips1 */
119 1.57.2.2 wdk
120 1.57.2.2 wdk #else /* run-time test */
121 1.57.2.2 wdk
122 1.57.2.2 wdk /* This test is ... rather bogus */
123 1.57.2.2 wdk #define CPUISMIPS3 ((cpu_arch & (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4)) != 0)
124 1.57.2.2 wdk #endif /* run-time test */
125 1.57.2.2 wdk
126 1.57.2.2 wdk /*
127 1.57.2.2 wdk * definitions of cpu-dependent requirements
128 1.57.2.2 wdk * referenced in generic code
129 1.57.2.2 wdk */
130 1.57.2.2 wdk #define cpu_wait(p) /* nothing */
131 1.57.2.2 wdk #define cpu_swapout(p) panic("cpu_swapout: can't get here");
132 1.57.2.2 wdk
133 1.57.2.2 wdk void cpu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
134 1.57.2.2 wdk
135 1.57.2.2 wdk /*
136 1.57.2.2 wdk * Arguments to hardclock and gatherstats encapsulate the previous
137 1.57.2.2 wdk * machine state in an opaque clockframe.
138 1.57.2.2 wdk */
139 1.57.2.2 wdk struct clockframe {
140 1.57.2.2 wdk int pc; /* program counter at time of interrupt */
141 1.57.2.2 wdk int sr; /* status register at time of interrupt */
142 1.57.2.2 wdk int ppl; /* previous priority level at time of interrupt */
143 1.57.2.2 wdk };
144 1.57.2.2 wdk
145 1.57.2.2 wdk /*
146 1.57.2.2 wdk * A port must provde CLKF_USERMODE() and CLKF_BASEPRI() for use
147 1.57.2.2 wdk * in machine-independent code. These differ on r4000 and r3000 systems;
148 1.57.2.2 wdk * provide them in the port-dependent file that includes this one, using
149 1.57.2.2 wdk * the macros below.
150 1.57.2.2 wdk */
151 1.57.2.2 wdk
152 1.57.2.2 wdk /* mips1 versions */
153 1.57.2.2 wdk #define MIPS1_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KU_PREV)
154 1.57.2.2 wdk #define MIPS1_CLKF_BASEPRI(framep) \
155 1.57.2.2 wdk ((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_ENA_PREV)) == 0)
156 1.57.2.2 wdk
157 1.57.2.2 wdk /* mips3 versions */
158 1.57.2.2 wdk #define MIPS3_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KSU_USER)
159 1.57.2.2 wdk #define MIPS3_CLKF_BASEPRI(framep) \
160 1.57.2.2 wdk ((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_IE)) == 0)
161 1.57.2.2 wdk
162 1.57.2.2 wdk #ifdef IPL_ICU_MASK
163 1.57.2.2 wdk #define ICU_CLKF_BASEPRI(framep) ((framep)->ppl == 0)
164 1.57.2.2 wdk #endif
165 1.57.2.2 wdk
166 1.57.2.2 wdk #define CLKF_PC(framep) ((framep)->pc)
167 1.57.2.2 wdk #define CLKF_INTR(framep) (0)
168 1.57.2.2 wdk
169 1.57.2.2 wdk #if defined(MIPS3) && !defined(MIPS1)
170 1.57.2.2 wdk #define CLKF_USERMODE(framep) MIPS3_CLKF_USERMODE(framep)
171 1.57.2.2 wdk #define CLKF_BASEPRI(framep) MIPS3_CLKF_BASEPRI(framep)
172 1.57.2.2 wdk #endif
173 1.57.2.2 wdk
174 1.57.2.2 wdk #if !defined(MIPS3) && defined(MIPS1)
175 1.57.2.2 wdk #define CLKF_USERMODE(framep) MIPS1_CLKF_USERMODE(framep)
176 1.57.2.2 wdk #define CLKF_BASEPRI(framep) MIPS1_CLKF_BASEPRI(framep)
177 1.57.2.2 wdk #endif
178 1.57.2.2 wdk
179 1.57.2.2 wdk #ifdef IPL_ICU_MASK
180 1.57.2.2 wdk #undef CLKF_BASEPRI
181 1.57.2.2 wdk #define CLKF_BASEPRI(framep) ICU_CLKF_BASEPRI(framep)
182 1.57.2.2 wdk #endif
183 1.57.2.2 wdk
184 1.57.2.2 wdk #if defined(MIPS3) && defined(MIPS1)
185 1.57.2.2 wdk #define CLKF_USERMODE(framep) \
186 1.57.2.2 wdk ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep): MIPS1_CLKF_USERMODE(framep))
187 1.57.2.2 wdk #define CLKF_BASEPRI(framep) \
188 1.57.2.2 wdk ((CPUISMIPS3) ? MIPS3_CLKF_BASEPRI(framep): MIPS1_CLKF_BASEPRI(framep))
189 1.57.2.2 wdk #endif
190 1.57.2.2 wdk
191 1.57.2.2 wdk /*
192 1.57.2.2 wdk * This is used during profiling to integrate system time. It can safely
193 1.57.2.2 wdk * assume that the process is resident.
194 1.57.2.2 wdk */
195 1.57.2.2 wdk #define PROC_PC(p) \
196 1.57.2.2 wdk (((struct frame *)(p)->p_md.md_regs)->f_regs[37]) /* XXX PC */
197 1.57.2.2 wdk
198 1.57.2.2 wdk /*
199 1.57.2.2 wdk * Preempt the current process if in interrupt from user mode,
200 1.57.2.2 wdk * or after the current trap/syscall if in system mode.
201 1.57.2.2 wdk */
202 1.57.2.2 wdk #define need_resched(ci) \
203 1.57.2.2 wdk do { \
204 1.57.2.2 wdk want_resched = 1; \
205 1.57.2.2 wdk if (curproc != NULL) \
206 1.57.2.2 wdk aston(curproc->l_proc); \
207 1.57.2.2 wdk } while (/*CONSTCOND*/0)
208 1.57.2.2 wdk
209 1.57.2.2 wdk /*
210 1.57.2.2 wdk * Give a profiling tick to the current process when the user profiling
211 1.57.2.2 wdk * buffer pages are invalid. On the MIPS, request an ast to send us
212 1.57.2.2 wdk * through trap, marking the proc as needing a profiling tick.
213 1.57.2.2 wdk */
214 1.57.2.2 wdk #define need_proftick(p) \
215 1.57.2.2 wdk do { \
216 1.57.2.2 wdk (p)->p_flag |= P_OWEUPC; \
217 1.57.2.2 wdk aston(p); \
218 1.57.2.2 wdk } while (/*CONSTCOND*/0)
219 1.57.2.2 wdk
220 1.57.2.2 wdk /*
221 1.57.2.2 wdk * Notify the current process (p) that it has a signal pending,
222 1.57.2.2 wdk * process as soon as possible.
223 1.57.2.2 wdk */
224 1.57.2.2 wdk #define signotify(p) aston(p)
225 1.57.2.2 wdk
226 1.57.2.2 wdk #define aston(p) ((p)->p_md.md_astpending = 1)
227 1.57.2.2 wdk
228 1.57.2.2 wdk extern int want_resched; /* resched() was called */
229 1.57.2.2 wdk
230 1.57.2.2 wdk /*
231 1.57.2.2 wdk * Misc prototypes and variable declarations.
232 1.57.2.2 wdk */
233 1.57.2.2 wdk struct proc;
234 1.57.2.2 wdk struct user;
235 1.57.2.2 wdk
236 1.57.2.2 wdk extern struct lwp *fpcurproc;
237 1.57.2.2 wdk
238 1.57.2.2 wdk /* trap.c */
239 1.57.2.2 wdk void netintr __P((void));
240 1.57.2.2 wdk int kdbpeek __P((vaddr_t));
241 1.57.2.2 wdk
242 1.57.2.2 wdk /* mips_machdep.c */
243 1.57.2.2 wdk void dumpsys __P((void));
244 1.57.2.2 wdk int savectx __P((struct user *));
245 1.57.2.2 wdk void mips_init_msgbuf __P((void));
246 1.57.2.2 wdk void savefpregs __P((struct lwp *));
247 1.57.2.2 wdk void loadfpregs __P((struct lwp *));
248 1.57.2.2 wdk
249 1.57.2.2 wdk /* locore.S */
250 1.57.2.2 wdk int badaddr __P((void *, size_t));
251 1.57.2.2 wdk
252 1.57.2.2 wdk /* mips_machdep.c */
253 1.57.2.2 wdk void cpu_identify __P((void));
254 1.57.2.2 wdk void mips_vector_init __P((void));
255 1.57.2.2 wdk
256 1.57.2.2 wdk #endif /* ! _LOCORE */
257 1.57.2.2 wdk #endif /* _KERNEL */
258 1.57.2.2 wdk
259 1.57.2.2 wdk #endif /* _CPU_H_ */
260