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