cpu.h revision 1.90.16.13 1 1.90.16.13 matt /* $NetBSD: cpu.h,v 1.90.16.13 2010/01/20 06:58:35 matt 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.71 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 deraadt * may be used to endorse or promote products derived from this software
20 1.1 deraadt * without specific prior written permission.
21 1.1 deraadt *
22 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 deraadt * SUCH DAMAGE.
33 1.1 deraadt *
34 1.8 cgd * @(#)cpu.h 8.4 (Berkeley) 1/4/94
35 1.1 deraadt */
36 1.1 deraadt
37 1.1 deraadt #ifndef _CPU_H_
38 1.1 deraadt #define _CPU_H_
39 1.1 deraadt
40 1.54 simonb #include <mips/cpuregs.h>
41 1.53 simonb
42 1.1 deraadt /*
43 1.13 jonathan * Exported definitions unique to NetBSD/mips cpu support.
44 1.1 deraadt */
45 1.36 soren
46 1.68 simonb #ifdef _KERNEL
47 1.53 simonb #ifndef _LOCORE
48 1.73 yamt #include <sys/cpu_data.h>
49 1.90.16.10 cliff #include <sys/device.h>
50 1.55 simonb
51 1.53 simonb #if defined(_KERNEL_OPT)
52 1.53 simonb #include "opt_lockdebug.h"
53 1.90.16.11 matt #include "opt_multiprocessor.h"
54 1.53 simonb #endif
55 1.53 simonb
56 1.90.16.5 cliff struct pridtab {
57 1.90.16.5 cliff int cpu_cid;
58 1.90.16.5 cliff int cpu_pid;
59 1.90.16.5 cliff int cpu_rev; /* -1 == wildcard */
60 1.90.16.5 cliff int cpu_copts; /* -1 == wildcard */
61 1.90.16.5 cliff int cpu_isa; /* -1 == probed (mips32/mips64) */
62 1.90.16.5 cliff int cpu_ntlb; /* -1 == unknown, 0 == probed */
63 1.90.16.5 cliff int cpu_flags;
64 1.90.16.5 cliff u_int cpu_cp0flags; /* presence of some cp0 regs */
65 1.90.16.5 cliff u_int cpu_cidflags; /* company-specific flags */
66 1.90.16.5 cliff const char *cpu_name;
67 1.90.16.5 cliff };
68 1.90.16.5 cliff
69 1.90.16.5 cliff /*
70 1.90.16.5 cliff * bitfield defines for cpu_cp0flags
71 1.90.16.5 cliff */
72 1.90.16.5 cliff #define MIPS_CP0FL_USE __BIT(0) /* use these flags */
73 1.90.16.5 cliff #define MIPS_CP0FL_ECC __BIT(1)
74 1.90.16.5 cliff #define MIPS_CP0FL_CACHE_ERR __BIT(2)
75 1.90.16.5 cliff #define MIPS_CP0FL_EIRR __BIT(3)
76 1.90.16.5 cliff #define MIPS_CP0FL_EIMR __BIT(4)
77 1.90.16.5 cliff #define MIPS_CP0FL_EBASE __BIT(5)
78 1.90.16.5 cliff #define MIPS_CP0FL_CONFIG __BIT(6)
79 1.90.16.5 cliff #define MIPS_CP0FL_CONFIGn(n) (__BIT(7) << ((n) & 7))
80 1.90.16.5 cliff
81 1.90.16.5 cliff /*
82 1.90.16.5 cliff * cpu_cidflags defines, by company
83 1.90.16.5 cliff */
84 1.90.16.5 cliff /*
85 1.90.16.5 cliff * RMI company-specific cpu_cidflags
86 1.90.16.5 cliff */
87 1.90.16.10 cliff #define MIPS_CIDFL_RMI_TYPE __BITS(2,0)
88 1.90.16.10 cliff # define CIDFL_RMI_TYPE_XLR 0
89 1.90.16.10 cliff # define CIDFL_RMI_TYPE_XLS 1
90 1.90.16.10 cliff # define CIDFL_RMI_TYPE_XLP 2
91 1.90.16.10 cliff #define MIPS_CIDFL_RMI_THREADS_MASK __BITS(6,3)
92 1.90.16.10 cliff # define MIPS_CIDFL_RMI_THREADS_SHIFT 3
93 1.90.16.10 cliff #define MIPS_CIDFL_RMI_CORES_MASK __BITS(10,7)
94 1.90.16.10 cliff # define MIPS_CIDFL_RMI_CORES_SHIFT 7
95 1.90.16.10 cliff # define LOG2_1 0
96 1.90.16.10 cliff # define LOG2_2 1
97 1.90.16.10 cliff # define LOG2_4 2
98 1.90.16.10 cliff # define LOG2_8 3
99 1.90.16.10 cliff # define MIPS_CIDFL_RMI_CPUS(ncores, nthreads) \
100 1.90.16.10 cliff ((LOG2_ ## ncores << MIPS_CIDFL_RMI_CORES_SHIFT) \
101 1.90.16.10 cliff |(LOG2_ ## nthreads << MIPS_CIDFL_RMI_THREADS_SHIFT))
102 1.90.16.10 cliff # define MIPS_CIDFL_RMI_NTHREADS(cidfl) \
103 1.90.16.10 cliff (1 << (((cidfl) & MIPS_CIDFL_RMI_THREADS_MASK) \
104 1.90.16.10 cliff >> MIPS_CIDFL_RMI_THREADS_SHIFT))
105 1.90.16.10 cliff # define MIPS_CIDFL_RMI_NCORES(cidfl) \
106 1.90.16.10 cliff (1 << (((cidfl) & MIPS_CIDFL_RMI_CORES_MASK) \
107 1.90.16.10 cliff >> MIPS_CIDFL_RMI_CORES_SHIFT))
108 1.90.16.10 cliff #define MIPS_CIDFL_RMI_L2SZ_MASK __BITS(14,11)
109 1.90.16.10 cliff # define MIPS_CIDFL_RMI_L2SZ_SHIFT 11
110 1.90.16.10 cliff # define RMI_L2SZ_256KB 0
111 1.90.16.10 cliff # define RMI_L2SZ_512KB 1
112 1.90.16.10 cliff # define RMI_L2SZ_1MB 2
113 1.90.16.10 cliff # define RMI_L2SZ_2MB 3
114 1.90.16.10 cliff # define RMI_L2SZ_4MB 4
115 1.90.16.10 cliff # define MIPS_CIDFL_RMI_L2(l2sz) \
116 1.90.16.10 cliff (RMI_L2SZ_ ## l2sz << MIPS_CIDFL_RMI_L2SZ_SHIFT)
117 1.90.16.10 cliff # define MIPS_CIDFL_RMI_L2SZ(cidfl) \
118 1.90.16.10 cliff ((256*1024) << (((cidfl) & MIPS_CIDFL_RMI_L2SZ_MASK) \
119 1.90.16.10 cliff >> MIPS_CIDFL_RMI_L2SZ_SHIFT))
120 1.90.16.10 cliff
121 1.90.16.5 cliff
122 1.90.16.5 cliff
123 1.53 simonb struct cpu_info {
124 1.73 yamt struct cpu_data ci_data; /* MI per-cpu data */
125 1.85 ad struct cpu_info *ci_next; /* Next CPU in list */
126 1.85 ad cpuid_t ci_cpuid; /* Machine-level identifier */
127 1.58 simonb u_long ci_cpu_freq; /* CPU frequency */
128 1.58 simonb u_long ci_cycles_per_hz; /* CPU freq / hz */
129 1.58 simonb u_long ci_divisor_delay; /* for delay/DELAY */
130 1.90 tsutsui u_long ci_divisor_recip; /* unused, for obsolete microtime(9) */
131 1.82 yamt struct lwp *ci_curlwp; /* currently running lwp */
132 1.82 yamt struct lwp *ci_fpcurlwp; /* the current FPU owner */
133 1.82 yamt int ci_want_resched; /* user preemption pending */
134 1.78 ad int ci_mtx_count; /* negative count of held mutexes */
135 1.78 ad int ci_mtx_oldspl; /* saved SPL value */
136 1.86 ad int ci_idepth; /* hardware interrupt depth */
137 1.90.16.11 matt device_t ci_dev; /* owning device */
138 1.90.16.11 matt vaddr_t ci_ebase; /* VA of exception base */
139 1.90.16.11 matt paddr_t ci_ebase_pa; /* PA of exception base */
140 1.90.16.13 matt u_long ci_cctr_freq; /* cycle counter frequency */
141 1.90.16.12 matt /*
142 1.90.16.12 matt * Per-cpu pmap information
143 1.90.16.12 matt */
144 1.90.16.12 matt struct segtab *ci_pmap_segbase;
145 1.90.16.13 matt uint32_t ci_pmap_asid_next; /* next asid to be assigned */
146 1.90.16.13 matt uint32_t ci_pmap_asid_generation; /* current asid generation */
147 1.90.16.13 matt uint32_t ci_pmap_asid_reserved; /* base of ASID space */
148 1.90.16.13 matt uint32_t ci_pmap_asid_max; /* max (exclusive) assignable asid */
149 1.53 simonb };
150 1.68 simonb
151 1.85 ad #define CPU_INFO_ITERATOR int
152 1.85 ad #define CPU_INFO_FOREACH(cii, ci) \
153 1.85 ad (void)(cii), ci = &cpu_info_store; ci != NULL; ci = ci->ci_next
154 1.85 ad
155 1.68 simonb #endif /* !_LOCORE */
156 1.68 simonb #endif /* _KERNEL */
157 1.53 simonb
158 1.36 soren /*
159 1.36 soren * CTL_MACHDEP definitions.
160 1.36 soren */
161 1.36 soren #define CPU_CONSDEV 1 /* dev_t: console terminal device */
162 1.36 soren #define CPU_BOOTED_KERNEL 2 /* string: booted kernel name */
163 1.36 soren #define CPU_ROOT_DEVICE 3 /* string: root device name */
164 1.66 gmcgarry #define CPU_LLSC 4 /* OS/CPU supports LL/SC instruction */
165 1.43 jeffs
166 1.43 jeffs /*
167 1.51 wiz * Platform can override, but note this breaks userland compatibility
168 1.43 jeffs * with other mips platforms.
169 1.43 jeffs */
170 1.43 jeffs #ifndef CPU_MAXID
171 1.67 shin #define CPU_MAXID 5 /* number of valid machdep ids */
172 1.36 soren
173 1.42 jeffs #endif
174 1.33 simonb
175 1.33 simonb #ifdef _KERNEL
176 1.87 he #if defined(_LKM) || defined(_STANDALONE)
177 1.87 he /* Assume all CPU architectures are valid for LKM's and standlone progs */
178 1.77 tsutsui #define MIPS1 1
179 1.77 tsutsui #define MIPS3 1
180 1.77 tsutsui #define MIPS4 1
181 1.77 tsutsui #define MIPS32 1
182 1.77 tsutsui #define MIPS64 1
183 1.77 tsutsui #endif
184 1.77 tsutsui
185 1.77 tsutsui #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 0
186 1.77 tsutsui #error at least one of MIPS1, MIPS3, MIPS4, MIPS32 or MIPS64 must be specified
187 1.77 tsutsui #endif
188 1.53 simonb
189 1.77 tsutsui /* Shortcut for MIPS3 or above defined */
190 1.77 tsutsui #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
191 1.77 tsutsui #define MIPS3_PLUS 1
192 1.77 tsutsui #else
193 1.77 tsutsui #undef MIPS3_PLUS
194 1.77 tsutsui #endif
195 1.33 simonb
196 1.33 simonb /*
197 1.21 jonathan * Macros to find the CPU architecture we're on at run-time,
198 1.21 jonathan * or if possible, at compile-time.
199 1.21 jonathan */
200 1.21 jonathan
201 1.58 simonb #define CPU_ARCH_MIPSx 0 /* XXX unknown */
202 1.46 cgd #define CPU_ARCH_MIPS1 (1 << 0)
203 1.46 cgd #define CPU_ARCH_MIPS2 (1 << 1)
204 1.46 cgd #define CPU_ARCH_MIPS3 (1 << 2)
205 1.46 cgd #define CPU_ARCH_MIPS4 (1 << 3)
206 1.46 cgd #define CPU_ARCH_MIPS5 (1 << 4)
207 1.46 cgd #define CPU_ARCH_MIPS32 (1 << 5)
208 1.46 cgd #define CPU_ARCH_MIPS64 (1 << 6)
209 1.46 cgd
210 1.82 yamt /* Note: must be kept in sync with -ffixed-?? Makefile.mips. */
211 1.82 yamt #define MIPS_CURLWP $23
212 1.82 yamt #define MIPS_CURLWP_QUOTED "$23"
213 1.82 yamt #define MIPS_CURLWP_CARD 23
214 1.82 yamt #define MIPS_CURLWP_FRAME(x) FRAME_S7(x)
215 1.82 yamt
216 1.58 simonb #ifndef _LOCORE
217 1.82 yamt
218 1.77 tsutsui extern struct cpu_info cpu_info_store;
219 1.82 yamt register struct lwp *mips_curlwp asm(MIPS_CURLWP_QUOTED);
220 1.77 tsutsui
221 1.82 yamt #define curlwp mips_curlwp
222 1.82 yamt #define curcpu() (curlwp->l_cpu)
223 1.82 yamt #define curpcb ((struct pcb *)curlwp->l_addr)
224 1.82 yamt #define fpcurlwp (curcpu()->ci_fpcurlwp)
225 1.90.16.13 matt #ifdef MULTIPROCESSOR
226 1.90.16.13 matt #define cpu_number() (curcpu()->ci_cpuid)
227 1.90.16.13 matt #else
228 1.82 yamt #define cpu_number() (0)
229 1.90.16.13 matt #endif
230 1.90.16.1 matt #define cpu_proc_fork(p1, p2) ((void)((p2)->p_md.md_abi = (p1)->p_md.md_abi))
231 1.77 tsutsui
232 1.58 simonb /* XXX simonb
233 1.58 simonb * Should the following be in a cpu_info type structure?
234 1.58 simonb * And how many of these are per-cpu vs. per-system? (Ie,
235 1.58 simonb * we can assume that all cpus have the same mmu-type, but
236 1.58 simonb * maybe not that all cpus run at the same clock speed.
237 1.58 simonb * Some SGI's apparently support R12k and R14k in the same
238 1.58 simonb * box.)
239 1.58 simonb */
240 1.90.16.13 matt struct mips_options {
241 1.90.16.13 matt const struct pridtab *mips_cpu;
242 1.90.16.13 matt
243 1.90.16.13 matt u_int mips_cpu_arch;
244 1.90.16.13 matt u_int mips_cpu_mhz;
245 1.90.16.13 matt u_int mips_cpu_flags;
246 1.90.16.13 matt u_int mips_num_tlb_entries;
247 1.90.16.13 matt mips_prid_t mips_cpu_id;
248 1.90.16.13 matt mips_prid_t mips_fpu_id;
249 1.90.16.13 matt bool mips_has_r4k_mmu;
250 1.90.16.13 matt bool mips_has_llsc;
251 1.90.16.13 matt #ifdef MIPS3_PLUS
252 1.90.16.2 matt #ifdef _LP64
253 1.90.16.13 matt uint64_t mips3_xkphys_cached;
254 1.90.16.2 matt #endif
255 1.90.16.13 matt uint64_t mips3_tlb_vpn_mask;
256 1.90.16.13 matt uint64_t mips3_tlb_pfn_mask;
257 1.90.16.13 matt uint32_t mips3_tlb_pg_mask;
258 1.90.16.13 matt u_int mips3_pg_cached;
259 1.90.16.13 matt u_int mips3_pg_shift;
260 1.90.16.13 matt #endif
261 1.90.16.13 matt };
262 1.90.16.13 matt extern struct mips_options mips_options;
263 1.58 simonb
264 1.58 simonb #define CPU_MIPS_R4K_MMU 0x0001
265 1.58 simonb #define CPU_MIPS_NO_LLSC 0x0002
266 1.58 simonb #define CPU_MIPS_CAUSE_IV 0x0004
267 1.58 simonb #define CPU_MIPS_HAVE_SPECIAL_CCA 0x0008 /* Defaults to '3' if not set. */
268 1.58 simonb #define CPU_MIPS_CACHED_CCA_MASK 0x0070
269 1.58 simonb #define CPU_MIPS_CACHED_CCA_SHIFT 4
270 1.62 simonb #define CPU_MIPS_DOUBLE_COUNT 0x0080 /* 1 cp0 count == 2 clock cycles */
271 1.63 simonb #define CPU_MIPS_USE_WAIT 0x0100 /* Use "wait"-based cpu_idle() */
272 1.63 simonb #define CPU_MIPS_NO_WAIT 0x0200 /* Inverse of previous, for mips32/64 */
273 1.69 simonb #define CPU_MIPS_D_CACHE_COHERENT 0x0400 /* D-cache is fully coherent */
274 1.69 simonb #define CPU_MIPS_I_D_CACHE_COHERENT 0x0800 /* I-cache funcs don't need to flush the D-cache */
275 1.90.16.3 matt #define CPU_MIPS_NO_LLADDR 0x1000
276 1.90.16.5 cliff #define CPU_MIPS_HAVE_MxCR 0x2000 /* have mfcr, mtcr insns */
277 1.58 simonb #define MIPS_NOT_SUPP 0x8000
278 1.60 simonb
279 1.78 ad #endif /* !_LOCORE */
280 1.78 ad
281 1.78 ad #if ((MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 1) || defined(_LOCORE)
282 1.78 ad
283 1.78 ad #if defined(MIPS1)
284 1.78 ad
285 1.58 simonb # define CPUISMIPS3 0
286 1.58 simonb # define CPUIS64BITS 0
287 1.58 simonb # define CPUISMIPS32 0
288 1.58 simonb # define CPUISMIPS64 0
289 1.58 simonb # define CPUISMIPSNN 0
290 1.58 simonb # define MIPS_HAS_R4K_MMU 0
291 1.58 simonb # define MIPS_HAS_CLOCK 0
292 1.58 simonb # define MIPS_HAS_LLSC 0
293 1.90.16.4 matt # define MIPS_HAS_LLADDR 0
294 1.58 simonb
295 1.78 ad #elif defined(MIPS3) || defined(MIPS4)
296 1.78 ad
297 1.58 simonb # define CPUISMIPS3 1
298 1.58 simonb # define CPUIS64BITS 1
299 1.58 simonb # define CPUISMIPS32 0
300 1.58 simonb # define CPUISMIPS64 0
301 1.58 simonb # define CPUISMIPSNN 0
302 1.58 simonb # define MIPS_HAS_R4K_MMU 1
303 1.58 simonb # define MIPS_HAS_CLOCK 1
304 1.78 ad # if defined(_LOCORE)
305 1.78 ad # if !defined(MIPS3_5900) && !defined(MIPS3_4100)
306 1.78 ad # define MIPS_HAS_LLSC 1
307 1.78 ad # else
308 1.78 ad # define MIPS_HAS_LLSC 0
309 1.78 ad # endif
310 1.78 ad # else /* _LOCORE */
311 1.90.16.13 matt # define MIPS_HAS_LLSC (mips_options.mips_has_llsc)
312 1.78 ad # endif /* _LOCORE */
313 1.90.16.13 matt # define MIPS_HAS_LLADDR ((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
314 1.78 ad
315 1.78 ad #elif defined(MIPS32)
316 1.58 simonb
317 1.58 simonb # define CPUISMIPS3 1
318 1.58 simonb # define CPUIS64BITS 0
319 1.58 simonb # define CPUISMIPS32 1
320 1.58 simonb # define CPUISMIPS64 0
321 1.58 simonb # define CPUISMIPSNN 1
322 1.58 simonb # define MIPS_HAS_R4K_MMU 1
323 1.58 simonb # define MIPS_HAS_CLOCK 1
324 1.58 simonb # define MIPS_HAS_LLSC 1
325 1.90.16.13 matt # define MIPS_HAS_LLADDR ((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
326 1.58 simonb
327 1.80 oster #elif defined(MIPS64)
328 1.78 ad
329 1.58 simonb # define CPUISMIPS3 1
330 1.58 simonb # define CPUIS64BITS 1
331 1.58 simonb # define CPUISMIPS32 0
332 1.58 simonb # define CPUISMIPS64 1
333 1.58 simonb # define CPUISMIPSNN 1
334 1.58 simonb # define MIPS_HAS_R4K_MMU 1
335 1.58 simonb # define MIPS_HAS_CLOCK 1
336 1.58 simonb # define MIPS_HAS_LLSC 1
337 1.90.16.13 matt # define MIPS_HAS_LLADDR ((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
338 1.78 ad
339 1.78 ad #endif
340 1.21 jonathan
341 1.58 simonb #else /* run-time test */
342 1.21 jonathan
343 1.78 ad #ifndef _LOCORE
344 1.78 ad
345 1.90.16.13 matt #define MIPS_HAS_R4K_MMU (mips_options.mips_has_r4k_mmu)
346 1.90.16.13 matt #define MIPS_HAS_LLSC (mips_options.mips_has_llsc)
347 1.90.16.13 matt #define MIPS_HAS_LLADDR ((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
348 1.45 cgd
349 1.45 cgd /* This test is ... rather bogus */
350 1.90.16.13 matt #define CPUISMIPS3 ((mips_options.mips_cpu_arch & \
351 1.58 simonb (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
352 1.58 simonb
353 1.58 simonb /* And these aren't much better while the previous test exists as is... */
354 1.90.16.13 matt #define CPUISMIPS4 ((mips_options.mips_cpu_arch & CPU_ARCH_MIPS4) != 0)
355 1.90.16.13 matt #define CPUISMIPS5 ((mips_options.mips_cpu_arch & CPU_ARCH_MIPS5) != 0)
356 1.90.16.13 matt #define CPUISMIPS32 ((mips_options.mips_cpu_arch & CPU_ARCH_MIPS32) != 0)
357 1.90.16.13 matt #define CPUISMIPS64 ((mips_options.mips_cpu_arch & CPU_ARCH_MIPS64) != 0)
358 1.90.16.13 matt #define CPUISMIPSNN ((mips_options.mips_cpu_arch & (CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
359 1.90.16.13 matt #define CPUIS64BITS ((mips_options.mips_cpu_arch & \
360 1.58 simonb (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS64)) != 0)
361 1.58 simonb
362 1.90.16.13 matt #define MIPS_HAS_CLOCK (mips_options.mips_cpu_arch >= CPU_ARCH_MIPS3)
363 1.78 ad
364 1.78 ad #else /* !_LOCORE */
365 1.78 ad
366 1.78 ad #define MIPS_HAS_LLSC 0
367 1.78 ad
368 1.78 ad #endif /* !_LOCORE */
369 1.78 ad
370 1.21 jonathan #endif /* run-time test */
371 1.21 jonathan
372 1.78 ad #ifndef _LOCORE
373 1.58 simonb
374 1.21 jonathan /*
375 1.1 deraadt * definitions of cpu-dependent requirements
376 1.1 deraadt * referenced in generic code
377 1.1 deraadt */
378 1.11 cgd #define cpu_swapout(p) panic("cpu_swapout: can't get here");
379 1.42 jeffs
380 1.90.16.8 cliff void cpu_intr(uint32_t, uint32_t, vaddr_t, uint32_t);
381 1.1 deraadt
382 1.1 deraadt /*
383 1.1 deraadt * Arguments to hardclock and gatherstats encapsulate the previous
384 1.1 deraadt * machine state in an opaque clockframe.
385 1.1 deraadt */
386 1.5 glass struct clockframe {
387 1.90.16.8 cliff vaddr_t pc; /* program counter at time of interrupt */
388 1.90.16.8 cliff uint32_t sr; /* status register at time of interrupt */
389 1.90.16.8 cliff u_int ppl; /* previous priority level at time of interrupt */
390 1.5 glass };
391 1.1 deraadt
392 1.14 jonathan /*
393 1.79 ad * A port must provde CLKF_USERMODE() for use in machine-independent code.
394 1.79 ad * These differ on r4000 and r3000 systems; provide them in the
395 1.79 ad * port-dependent file that includes this one, using the macros below.
396 1.14 jonathan */
397 1.14 jonathan
398 1.21 jonathan /* mips1 versions */
399 1.22 jonathan #define MIPS1_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KU_PREV)
400 1.14 jonathan
401 1.21 jonathan /* mips3 versions */
402 1.22 jonathan #define MIPS3_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KSU_USER)
403 1.56 uch
404 1.1 deraadt #define CLKF_PC(framep) ((framep)->pc)
405 1.1 deraadt #define CLKF_INTR(framep) (0)
406 1.18 jonathan
407 1.58 simonb #if defined(MIPS3_PLUS) && !defined(MIPS1) /* XXX bogus! */
408 1.21 jonathan #define CLKF_USERMODE(framep) MIPS3_CLKF_USERMODE(framep)
409 1.21 jonathan #endif
410 1.21 jonathan
411 1.58 simonb #if !defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
412 1.21 jonathan #define CLKF_USERMODE(framep) MIPS1_CLKF_USERMODE(framep)
413 1.21 jonathan #endif
414 1.21 jonathan
415 1.58 simonb #if defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
416 1.21 jonathan #define CLKF_USERMODE(framep) \
417 1.21 jonathan ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep): MIPS1_CLKF_USERMODE(framep))
418 1.18 jonathan #endif
419 1.18 jonathan
420 1.47 thorpej /*
421 1.47 thorpej * This is used during profiling to integrate system time. It can safely
422 1.47 thorpej * assume that the process is resident.
423 1.47 thorpej */
424 1.48 thorpej #define PROC_PC(p) \
425 1.48 thorpej (((struct frame *)(p)->p_md.md_regs)->f_regs[37]) /* XXX PC */
426 1.1 deraadt
427 1.1 deraadt /*
428 1.1 deraadt * Preempt the current process if in interrupt from user mode,
429 1.1 deraadt * or after the current trap/syscall if in system mode.
430 1.1 deraadt */
431 1.82 yamt void cpu_need_resched(struct cpu_info *, int);
432 1.1 deraadt
433 1.1 deraadt /*
434 1.1 deraadt * Give a profiling tick to the current process when the user profiling
435 1.13 jonathan * buffer pages are invalid. On the MIPS, request an ast to send us
436 1.1 deraadt * through trap, marking the proc as needing a profiling tick.
437 1.1 deraadt */
438 1.78 ad #define cpu_need_proftick(l) \
439 1.50 thorpej do { \
440 1.78 ad (l)->l_pflag |= LP_OWEUPC; \
441 1.78 ad aston(l); \
442 1.50 thorpej } while (/*CONSTCOND*/0)
443 1.1 deraadt
444 1.1 deraadt /*
445 1.81 simonb * Notify the current lwp (l) that it has a signal pending,
446 1.1 deraadt * process as soon as possible.
447 1.1 deraadt */
448 1.81 simonb #define cpu_signotify(l) aston(l)
449 1.1 deraadt
450 1.78 ad #define aston(l) ((l)->l_md.md_astpending = 1)
451 1.1 deraadt
452 1.23 thorpej /*
453 1.37 simonb * Misc prototypes and variable declarations.
454 1.23 thorpej */
455 1.70 thorpej struct lwp;
456 1.28 castor struct user;
457 1.37 simonb
458 1.90.16.9 matt extern struct segtab *segbase; /* current segtab base */
459 1.90.16.9 matt extern int mips_poolpage_vmfreelist; /* freelist to allocate poolpages */
460 1.25 jonathan
461 1.90.16.6 matt /* copy.S */
462 1.90.16.6 matt int8_t ufetch_int8(void *);
463 1.90.16.6 matt int16_t ufetch_int16(void *);
464 1.90.16.6 matt int32_t ufetch_int32(void *);
465 1.90.16.6 matt uint8_t ufetch_uint8(void *);
466 1.90.16.6 matt uint16_t ufetch_uint16(void *);
467 1.90.16.6 matt uint32_t ufetch_uint32(void *);
468 1.90.16.6 matt int8_t ufetch_int8_intrsafe(void *);
469 1.90.16.6 matt int16_t ufetch_int16_intrsafe(void *);
470 1.90.16.6 matt int32_t ufetch_int32_intrsafe(void *);
471 1.90.16.6 matt uint8_t ufetch_uint8_intrsafe(void *);
472 1.90.16.6 matt uint16_t ufetch_uint16_intrsafe(void *);
473 1.90.16.6 matt uint32_t ufetch_uint32_intrsafe(void *);
474 1.90.16.6 matt #ifdef _LP64
475 1.90.16.6 matt int64_t ufetch_int64(void *);
476 1.90.16.6 matt uint64_t ufetch_uint64(void *);
477 1.90.16.6 matt int64_t ufetch_int64_intrsafe(void *);
478 1.90.16.6 matt uint64_t ufetch_uint64_intrsafe(void *);
479 1.90.16.6 matt #endif
480 1.90.16.6 matt char ufetch_char(void *);
481 1.90.16.6 matt short ufetch_short(void *);
482 1.90.16.6 matt int ufetch_int(void *);
483 1.90.16.6 matt long ufetch_long(void *);
484 1.90.16.6 matt char ufetch_char_intrsafe(void *);
485 1.90.16.6 matt short ufetch_short_intrsafe(void *);
486 1.90.16.6 matt int ufetch_int_intrsafe(void *);
487 1.90.16.6 matt long ufetch_long_intrsafe(void *);
488 1.90.16.6 matt
489 1.90.16.6 matt u_char ufetch_uchar(void *);
490 1.90.16.6 matt u_short ufetch_ushort(void *);
491 1.90.16.6 matt u_int ufetch_uint(void *);
492 1.90.16.6 matt u_long ufetch_ulong(void *);
493 1.90.16.6 matt u_char ufetch_uchar_intrsafe(void *);
494 1.90.16.6 matt u_short ufetch_ushort_intrsafe(void *);
495 1.90.16.6 matt u_int ufetch_uint_intrsafe(void *);
496 1.90.16.6 matt u_long ufetch_ulong_intrsafe(void *);
497 1.90.16.6 matt void *ufetch_ptr(void *);
498 1.90.16.6 matt
499 1.90.16.6 matt int ustore_int8(void *, int8_t);
500 1.90.16.6 matt int ustore_int16(void *, int16_t);
501 1.90.16.6 matt int ustore_int32(void *, int32_t);
502 1.90.16.6 matt int ustore_uint8(void *, uint8_t);
503 1.90.16.7 matt int ustore_uint16(void *, uint16_t);
504 1.90.16.6 matt int ustore_uint32(void *, uint32_t);
505 1.90.16.6 matt int ustore_int8_intrsafe(void *, int8_t);
506 1.90.16.6 matt int ustore_int16_intrsafe(void *, int16_t);
507 1.90.16.6 matt int ustore_int32_intrsafe(void *, int32_t);
508 1.90.16.6 matt int ustore_uint8_intrsafe(void *, uint8_t);
509 1.90.16.6 matt int ustore_uint16_intrsafe(void *, uint16_t);
510 1.90.16.6 matt int ustore_uint32_intrsafe(void *, uint32_t);
511 1.90.16.6 matt #ifdef _LP64
512 1.90.16.6 matt int ustore_int64(void *, int64_t);
513 1.90.16.6 matt int ustore_uint64(void *, uint64_t);
514 1.90.16.6 matt int ustore_int64_intrsafe(void *, int64_t);
515 1.90.16.6 matt int ustore_uint64_intrsafe(void *, uint64_t);
516 1.90.16.6 matt #endif
517 1.90.16.6 matt int ustore_char(void *, char);
518 1.90.16.6 matt int ustore_char_intrsafe(void *, char);
519 1.90.16.6 matt int ustore_short(void *, short);
520 1.90.16.6 matt int ustore_short_intrsafe(void *, short);
521 1.90.16.6 matt int ustore_int(void *, int);
522 1.90.16.6 matt int ustore_int_intrsafe(void *, int);
523 1.90.16.6 matt int ustore_long(void *, long);
524 1.90.16.6 matt int ustore_long_intrsafe(void *, long);
525 1.90.16.6 matt int ustore_uchar(void *, u_char);
526 1.90.16.6 matt int ustore_uchar_intrsafe(void *, u_char);
527 1.90.16.6 matt int ustore_ushort(void *, u_short);
528 1.90.16.6 matt int ustore_ushort_intrsafe(void *, u_short);
529 1.90.16.6 matt int ustore_uint(void *, u_int);
530 1.90.16.6 matt int ustore_uint_intrsafe(void *, u_int);
531 1.90.16.6 matt int ustore_ulong(void *, u_long);
532 1.90.16.6 matt int ustore_ulong_intrsafe(void *, u_long);
533 1.90.16.6 matt int ustore_ptr(void *, void *);
534 1.90.16.6 matt int ustore_ptr_intrsafe(void *, void *);
535 1.90.16.6 matt
536 1.90.16.6 matt int ustore_uint32_isync(void *, uint32_t);
537 1.90.16.6 matt
538 1.28 castor /* trap.c */
539 1.58 simonb void netintr(void);
540 1.58 simonb int kdbpeek(vaddr_t);
541 1.23 thorpej
542 1.28 castor /* mips_machdep.c */
543 1.90.16.9 matt struct mips_vmfreelist;
544 1.90.16.9 matt struct phys_ram_seg;
545 1.58 simonb void dumpsys(void);
546 1.58 simonb int savectx(struct user *);
547 1.90.16.13 matt void mips_vector_init(void);
548 1.58 simonb void mips_init_msgbuf(void);
549 1.90.16.9 matt void mips_init_lwp0_uarea(void);
550 1.90.16.9 matt void mips_page_physload(vaddr_t, vaddr_t,
551 1.90.16.9 matt const struct phys_ram_seg *, size_t,
552 1.90.16.9 matt const struct mips_vmfreelist *, size_t);
553 1.70 thorpej void savefpregs(struct lwp *);
554 1.70 thorpej void loadfpregs(struct lwp *);
555 1.90.16.13 matt void cpu_identify(device_t);
556 1.90.16.13 matt #ifdef MULTIPROCESSOR
557 1.90.16.13 matt void cpu_boot_secondary_processors(void);
558 1.90.16.13 matt #endif
559 1.13 jonathan
560 1.61 simonb /* locore*.S */
561 1.58 simonb int badaddr(void *, size_t);
562 1.61 simonb int badaddr64(uint64_t, size_t);
563 1.25 jonathan
564 1.33 simonb #endif /* ! _LOCORE */
565 1.28 castor #endif /* _KERNEL */
566 1.1 deraadt #endif /* _CPU_H_ */
567