locore.h revision 1.78.36.1.2.35 1 1.78.36.1.2.30 matt /* locore.h,v 1.78.36.1.2.29 2011/04/29 08:26:21 matt Exp */
2 1.78.36.1.2.14 matt
3 1.78.36.1.2.14 matt /*
4 1.78.36.1.2.14 matt * This file should not be included by MI code!!!
5 1.78.36.1.2.14 matt */
6 1.1 jonathan
7 1.1 jonathan /*
8 1.1 jonathan * Copyright 1996 The Board of Trustees of The Leland Stanford
9 1.1 jonathan * Junior University. All Rights Reserved.
10 1.1 jonathan *
11 1.1 jonathan * Permission to use, copy, modify, and distribute this
12 1.1 jonathan * software and its documentation for any purpose and without
13 1.1 jonathan * fee is hereby granted, provided that the above copyright
14 1.1 jonathan * notice appear in all copies. Stanford University
15 1.1 jonathan * makes no representations about the suitability of this
16 1.1 jonathan * software for any purpose. It is provided "as is" without
17 1.1 jonathan * express or implied warranty.
18 1.1 jonathan */
19 1.1 jonathan
20 1.1 jonathan /*
21 1.68 wiz * Jump table for MIPS CPU locore functions that are implemented
22 1.1 jonathan * differently on different generations, or instruction-level
23 1.78.36.1.2.29 matt * architecture (ISA) level, the Mips family.
24 1.1 jonathan *
25 1.33 soren * We currently provide support for MIPS I and MIPS III.
26 1.1 jonathan */
27 1.1 jonathan
28 1.1 jonathan #ifndef _MIPS_LOCORE_H
29 1.70 tsutsui #define _MIPS_LOCORE_H
30 1.2 jonathan
31 1.17 castor #ifndef _LKM
32 1.32 soren #include "opt_cputype.h"
33 1.17 castor #endif
34 1.16 castor
35 1.78.36.1.2.34 matt #include <sys/kcore.h>
36 1.78.36.1.2.34 matt
37 1.78.36.1.2.29 matt #include <mips/mutex.h>
38 1.59 simonb #include <mips/cpuregs.h>
39 1.78.36.1.2.11 matt #include <mips/reg.h>
40 1.59 simonb
41 1.78.36.1.2.8 matt struct tlbmask;
42 1.78.36.1.2.27 matt struct trapframe;
43 1.78.36.1.2.27 matt
44 1.78.36.1.2.27 matt void trap(uint32_t, uint32_t, vaddr_t, vaddr_t, struct trapframe *);
45 1.78.36.1.2.27 matt void ast(void);
46 1.78.36.1.2.27 matt
47 1.78.36.1.2.33 matt /*
48 1.78.36.1.2.33 matt * Perform a trapsignal, and if cpu_printfataltraps is true, print the trap info
49 1.78.36.1.2.33 matt * to the console.
50 1.78.36.1.2.33 matt */
51 1.78.36.1.2.33 matt extern bool cpu_printfataltraps;
52 1.78.36.1.2.33 matt void cpu_trapsignal(struct lwp *, ksiginfo_t *, struct trapframe *);
53 1.78.36.1.2.33 matt
54 1.78.36.1.2.27 matt void mips_fpu_trap(vaddr_t, struct trapframe *);
55 1.78.36.1.2.27 matt void mips_fpu_intr(vaddr_t, struct trapframe *);
56 1.78.36.1.2.27 matt
57 1.78.36.1.2.27 matt vaddr_t mips_emul_branch(struct trapframe *, vaddr_t, uint32_t, bool);
58 1.78.36.1.2.27 matt void mips_emul_inst(uint32_t, uint32_t, vaddr_t, struct trapframe *);
59 1.78.36.1.2.27 matt
60 1.78.36.1.2.27 matt void mips_emul_fp(uint32_t, struct trapframe *, uint32_t);
61 1.78.36.1.2.27 matt void mips_emul_branchdelayslot(uint32_t, struct trapframe *, uint32_t);
62 1.78.36.1.2.27 matt
63 1.78.36.1.2.27 matt void mips_emul_lwc0(uint32_t, struct trapframe *, uint32_t);
64 1.78.36.1.2.27 matt void mips_emul_swc0(uint32_t, struct trapframe *, uint32_t);
65 1.78.36.1.2.27 matt void mips_emul_special(uint32_t, struct trapframe *, uint32_t);
66 1.78.36.1.2.27 matt void mips_emul_special3(uint32_t, struct trapframe *, uint32_t);
67 1.78.36.1.2.27 matt
68 1.78.36.1.2.27 matt void mips_emul_lwc1(uint32_t, struct trapframe *, uint32_t);
69 1.78.36.1.2.27 matt void mips_emul_swc1(uint32_t, struct trapframe *, uint32_t);
70 1.78.36.1.2.27 matt void mips_emul_ldc1(uint32_t, struct trapframe *, uint32_t);
71 1.78.36.1.2.27 matt void mips_emul_sdc1(uint32_t, struct trapframe *, uint32_t);
72 1.78.36.1.2.27 matt
73 1.78.36.1.2.27 matt void mips_emul_lb(uint32_t, struct trapframe *, uint32_t);
74 1.78.36.1.2.27 matt void mips_emul_lbu(uint32_t, struct trapframe *, uint32_t);
75 1.78.36.1.2.27 matt void mips_emul_lh(uint32_t, struct trapframe *, uint32_t);
76 1.78.36.1.2.27 matt void mips_emul_lhu(uint32_t, struct trapframe *, uint32_t);
77 1.78.36.1.2.27 matt void mips_emul_lw(uint32_t, struct trapframe *, uint32_t);
78 1.78.36.1.2.27 matt void mips_emul_lwl(uint32_t, struct trapframe *, uint32_t);
79 1.78.36.1.2.27 matt void mips_emul_lwr(uint32_t, struct trapframe *, uint32_t);
80 1.78.36.1.2.27 matt #if defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64)
81 1.78.36.1.2.27 matt void mips_emul_lwu(uint32_t, struct trapframe *, uint32_t);
82 1.78.36.1.2.27 matt void mips_emul_ld(uint32_t, struct trapframe *, uint32_t);
83 1.78.36.1.2.27 matt void mips_emul_ldl(uint32_t, struct trapframe *, uint32_t);
84 1.78.36.1.2.27 matt void mips_emul_ldr(uint32_t, struct trapframe *, uint32_t);
85 1.78.36.1.2.27 matt #endif
86 1.78.36.1.2.27 matt void mips_emul_sb(uint32_t, struct trapframe *, uint32_t);
87 1.78.36.1.2.27 matt void mips_emul_sh(uint32_t, struct trapframe *, uint32_t);
88 1.78.36.1.2.27 matt void mips_emul_sw(uint32_t, struct trapframe *, uint32_t);
89 1.78.36.1.2.27 matt void mips_emul_swl(uint32_t, struct trapframe *, uint32_t);
90 1.78.36.1.2.27 matt void mips_emul_swr(uint32_t, struct trapframe *, uint32_t);
91 1.78.36.1.2.27 matt #if defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64)
92 1.78.36.1.2.27 matt void mips_emul_sd(uint32_t, struct trapframe *, uint32_t);
93 1.78.36.1.2.27 matt void mips_emul_sdl(uint32_t, struct trapframe *, uint32_t);
94 1.78.36.1.2.27 matt void mips_emul_sdr(uint32_t, struct trapframe *, uint32_t);
95 1.78.36.1.2.27 matt #endif
96 1.38 cgd
97 1.59 simonb uint32_t mips_cp0_cause_read(void);
98 1.59 simonb void mips_cp0_cause_write(uint32_t);
99 1.59 simonb uint32_t mips_cp0_status_read(void);
100 1.59 simonb void mips_cp0_status_write(uint32_t);
101 1.29 simonb
102 1.78.36.1.2.16 matt void softint_process(uint32_t);
103 1.78.36.1.2.16 matt void softint_fast_dispatch(struct lwp *, int);
104 1.78.36.1.2.16 matt
105 1.78.36.1.2.19 matt /*
106 1.78.36.1.2.19 matt * Convert an address to an offset used in a MIPS jump instruction. The offset
107 1.78.36.1.2.19 matt * contains the low 28 bits (allowing a jump to anywhere within the same 256MB
108 1.78.36.1.2.19 matt * segment of address space) of the address but since mips instructions are
109 1.78.36.1.2.19 matt * always on a 4 byte boundary the low 2 bits are always zero so the 28 bits
110 1.78.36.1.2.19 matt * get shifted right by 2 bits leaving us with a 26 bit result. To make the
111 1.78.36.1.2.19 matt * offset, we shift left to clear the upper four bits and then right by 6.
112 1.78.36.1.2.19 matt */
113 1.78.36.1.2.19 matt #define fixup_addr2offset(x) ((((uint32_t)(uintptr_t)(x)) << 4) >> 6)
114 1.78.36.1.2.16 matt typedef bool (*mips_fixup_callback_t)(int32_t, uint32_t [2]);
115 1.78.36.1.2.19 matt struct mips_jump_fixup_info {
116 1.78.36.1.2.19 matt uint32_t jfi_stub;
117 1.78.36.1.2.19 matt uint32_t jfi_real;
118 1.78.36.1.2.19 matt };
119 1.78.36.1.2.16 matt
120 1.78.36.1.2.17 matt void fixup_splcalls(void); /* splstubs.c */
121 1.78.36.1.2.16 matt bool mips_fixup_exceptions(mips_fixup_callback_t);
122 1.78.36.1.2.16 matt bool mips_fixup_zero_relative(int32_t, uint32_t [2]);
123 1.78.36.1.2.32 matt intptr_t
124 1.78.36.1.2.32 matt mips_fixup_addr(const uint32_t *);
125 1.78.36.1.2.26 matt void mips_fixup_stubs(uint32_t *, uint32_t *);
126 1.78.36.1.2.17 matt
127 1.78.36.1.2.26 matt /*
128 1.78.36.1.2.26 matt * Define these stubs...
129 1.78.36.1.2.26 matt */
130 1.78.36.1.2.17 matt void mips_cpu_switch_resume(struct lwp *);
131 1.78.36.1.2.26 matt void tlb_set_asid(uint32_t);
132 1.78.36.1.2.26 matt void tlb_invalidate_all(void);
133 1.78.36.1.2.26 matt void tlb_invalidate_globals(void);
134 1.78.36.1.2.26 matt void tlb_invalidate_asids(uint32_t, uint32_t);
135 1.78.36.1.2.26 matt void tlb_invalidate_addr(vaddr_t);
136 1.78.36.1.2.26 matt u_int tlb_record_asids(u_long *, uint32_t);
137 1.78.36.1.2.26 matt int tlb_update(vaddr_t, uint32_t);
138 1.78.36.1.2.26 matt void tlb_enter(size_t, vaddr_t, uint32_t);
139 1.78.36.1.2.26 matt void tlb_read_indexed(size_t, struct tlbmask *);
140 1.78.36.1.2.27 matt void tlb_write_indexed(size_t, const struct tlbmask *);
141 1.78.36.1.2.26 matt void wbflush(void);
142 1.77 tsutsui
143 1.59 simonb #ifdef MIPS1
144 1.78.36.1.2.14 matt void mips1_tlb_invalidate_all(void);
145 1.38 cgd
146 1.58 thorpej uint32_t tx3900_cp0_config_read(void);
147 1.59 simonb #endif
148 1.38 cgd
149 1.78.36.1.2.30 matt #if (MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2 + MIPS64_RMIXL + MIPS64R2_RMIXL) > 0
150 1.59 simonb uint32_t mips3_cp0_compare_read(void);
151 1.59 simonb void mips3_cp0_compare_write(uint32_t);
152 1.49 cgd
153 1.59 simonb uint32_t mips3_cp0_config_read(void);
154 1.59 simonb void mips3_cp0_config_write(uint32_t);
155 1.78.36.1.2.29 matt
156 1.78.36.1.2.30 matt #if (MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2 + MIPS64_RMIXL + MIPS64R2_RMIXL) > 0
157 1.59 simonb uint32_t mipsNN_cp0_config1_read(void);
158 1.59 simonb void mipsNN_cp0_config1_write(uint32_t);
159 1.63 simonb uint32_t mipsNN_cp0_config2_read(void);
160 1.78.36.1.2.31 matt void mipsNN_cp0_config2_write(uint32_t);
161 1.63 simonb uint32_t mipsNN_cp0_config3_read(void);
162 1.78.36.1.2.31 matt void mipsNN_cp0_config3_write(uint32_t);
163 1.78.36.1.2.31 matt uint32_t mipsNN_cp0_config4_read(void);
164 1.78.36.1.2.31 matt void mipsNN_cp0_config4_write(uint32_t);
165 1.78.36.1.2.31 matt uint32_t mipsNN_cp0_config5_read(void);
166 1.78.36.1.2.31 matt void mipsNN_cp0_config5_write(uint32_t);
167 1.78.36.1.2.31 matt uint32_t mipsNN_cp0_config6_read(void);
168 1.78.36.1.2.31 matt void mipsNN_cp0_config6_write(uint32_t);
169 1.78.36.1.2.31 matt uint32_t mipsNN_cp0_config7_read(void);
170 1.78.36.1.2.31 matt void mipsNN_cp0_config7_write(uint32_t);
171 1.78.36.1.2.31 matt uint64_t mips64_cp0_config7_read(void);
172 1.78.36.1.2.31 matt void mips64_cp0_config7_write(uint32_t);
173 1.78.36.1.2.29 matt
174 1.78.36.1.2.29 matt uintptr_t mipsNN_cp0_watchlo_read(u_int);
175 1.78.36.1.2.29 matt void mipsNN_cp0_watchlo_write(u_int, uintptr_t);
176 1.78.36.1.2.29 matt uint32_t mipsNN_cp0_watchhi_read(u_int);
177 1.78.36.1.2.29 matt void mipsNN_cp0_watchhi_write(u_int, uint32_t);
178 1.78.36.1.2.29 matt
179 1.78.36.1.2.30 matt #if (MIPS32R2 + MIPS64R2 + MIPS64R2_RMIXL) > 0
180 1.78.36.1.2.29 matt void mipsNN_cp0_hwrena_write(uint32_t);
181 1.78.36.1.2.29 matt void mipsNN_cp0_userlocal_write(void *);
182 1.78.36.1.2.29 matt #endif
183 1.63 simonb #endif
184 1.59 simonb
185 1.59 simonb uint32_t mips3_cp0_count_read(void);
186 1.59 simonb void mips3_cp0_count_write(uint32_t);
187 1.59 simonb
188 1.78.36.1.2.31 matt uint32_t mips3_cp0_random_read(void);
189 1.78.36.1.2.31 matt
190 1.59 simonb uint32_t mips3_cp0_wired_read(void);
191 1.59 simonb void mips3_cp0_wired_write(uint32_t);
192 1.69 tsutsui void mips3_cp0_pg_mask_write(uint32_t);
193 1.59 simonb
194 1.78.36.1.2.1 matt #if defined(__GNUC__) && !defined(__mips_o32)
195 1.78.36.1.2.1 matt static inline uint64_t
196 1.78.36.1.2.5 matt mips3_ld(const volatile uint64_t *va)
197 1.78.36.1.2.1 matt {
198 1.78.36.1.2.1 matt uint64_t rv;
199 1.78.36.1.2.1 matt #if defined(__mips_o32)
200 1.78.36.1.2.1 matt uint32_t sr;
201 1.78.36.1.2.1 matt
202 1.78.36.1.2.1 matt sr = mips_cp0_status_read();
203 1.78.36.1.2.1 matt mips_cp0_status_write(sr & ~MIPS_SR_INT_IE);
204 1.78.36.1.2.1 matt
205 1.78.36.1.2.1 matt __asm volatile(
206 1.78.36.1.2.1 matt ".set push \n\t"
207 1.78.36.1.2.1 matt ".set mips3 \n\t"
208 1.78.36.1.2.1 matt ".set noreorder \n\t"
209 1.78.36.1.2.1 matt ".set noat \n\t"
210 1.78.36.1.2.1 matt "ld %M0,0(%1) \n\t"
211 1.78.36.1.2.1 matt "dsll32 %L0,%M0,0 \n\t"
212 1.78.36.1.2.1 matt "dsra32 %M0,%M0,0 \n\t" /* high word */
213 1.78.36.1.2.1 matt "dsra32 %L0,%L0,0 \n\t" /* low word */
214 1.78.36.1.2.1 matt "ld %0,0(%1) \n\t"
215 1.78.36.1.2.1 matt ".set pop"
216 1.78.36.1.2.1 matt : "=d"(rv)
217 1.78.36.1.2.1 matt : "r"(va));
218 1.78.36.1.2.1 matt
219 1.78.36.1.2.1 matt mips_cp0_status_write(sr);
220 1.78.36.1.2.1 matt #elif defined(_LP64)
221 1.78.36.1.2.1 matt rv = *va;
222 1.78.36.1.2.1 matt #else
223 1.78.36.1.2.1 matt __asm volatile("ld %0,0(%1)" : "=d"(rv) : "r"(va));
224 1.78.36.1.2.1 matt #endif
225 1.78.36.1.2.1 matt
226 1.78.36.1.2.1 matt return rv;
227 1.78.36.1.2.1 matt }
228 1.78.36.1.2.1 matt static inline void
229 1.78.36.1.2.5 matt mips3_sd(volatile uint64_t *va, uint64_t v)
230 1.78.36.1.2.1 matt {
231 1.78.36.1.2.1 matt #if defined(__mips_o32)
232 1.78.36.1.2.1 matt uint32_t sr;
233 1.78.36.1.2.1 matt
234 1.78.36.1.2.1 matt sr = mips_cp0_status_read();
235 1.78.36.1.2.1 matt mips_cp0_status_write(sr & ~MIPS_SR_INT_IE);
236 1.78.36.1.2.1 matt
237 1.78.36.1.2.1 matt __asm volatile(
238 1.78.36.1.2.1 matt ".set push \n\t"
239 1.78.36.1.2.1 matt ".set mips3 \n\t"
240 1.78.36.1.2.1 matt ".set noreorder \n\t"
241 1.78.36.1.2.1 matt ".set noat \n\t"
242 1.78.36.1.2.1 matt "dsll32 %M0,%M0,0 \n\t"
243 1.78.36.1.2.1 matt "dsll32 %L0,%L0,0 \n\t"
244 1.78.36.1.2.1 matt "dsrl32 %L0,%L0,0 \n\t"
245 1.78.36.1.2.1 matt "or %0,%L0,%M0 \n\t"
246 1.78.36.1.2.1 matt "sd %0,0(%1) \n\t"
247 1.78.36.1.2.1 matt ".set pop"
248 1.78.36.1.2.1 matt : "=d"(v) : "0"(v), "r"(va));
249 1.78.36.1.2.1 matt
250 1.78.36.1.2.1 matt mips_cp0_status_write(sr);
251 1.78.36.1.2.1 matt #elif defined(_LP64)
252 1.78.36.1.2.1 matt *va = v;
253 1.78.36.1.2.1 matt #else
254 1.78.36.1.2.1 matt __asm volatile("sd %0,0(%1)" :: "r"(v), "r"(va));
255 1.78.36.1.2.1 matt #endif
256 1.78.36.1.2.1 matt }
257 1.78.36.1.2.1 matt #else
258 1.78.36.1.2.5 matt uint64_t mips3_ld(volatile uint64_t *va);
259 1.78.36.1.2.5 matt void mips3_sd(volatile uint64_t *, uint64_t);
260 1.78.36.1.2.1 matt #endif /* __GNUC__ */
261 1.78.36.1.2.30 matt #endif /* (MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2 + MIPS64_RMIXL + MIPS64R2_RMIXL) > 0 */
262 1.59 simonb
263 1.78.36.1.2.30 matt #if (MIPS3 + MIPS4 + MIPS64 + MIPS64R2 + MIPS64_RMIXL + MIPS64R2_RMIXL) > 0
264 1.78.36.1.2.29 matt static __inline uint32_t mips3_lw_a64(uint64_t addr) __unused;
265 1.78.36.1.2.29 matt static __inline void mips3_sw_a64(uint64_t addr, uint32_t val) __unused;
266 1.59 simonb
267 1.74 perry static __inline uint32_t
268 1.59 simonb mips3_lw_a64(uint64_t addr)
269 1.59 simonb {
270 1.59 simonb uint32_t rv;
271 1.78.36.1.2.1 matt #if defined(__mips_o32)
272 1.59 simonb uint32_t sr;
273 1.59 simonb
274 1.59 simonb sr = mips_cp0_status_read();
275 1.78.36.1.2.1 matt mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
276 1.59 simonb
277 1.78.36.1.2.1 matt __asm volatile (
278 1.78.36.1.2.1 matt ".set push \n\t"
279 1.78.36.1.2.1 matt ".set mips3 \n\t"
280 1.78.36.1.2.1 matt ".set noreorder \n\t"
281 1.78.36.1.2.1 matt ".set noat \n\t"
282 1.78.36.1.2.1 matt "dsll32 %M1,%M1,0 \n\t"
283 1.78.36.1.2.1 matt "dsll32 %L1,%L1,0 \n\t"
284 1.78.36.1.2.10 cyber "dsrl32 %L1,%L1,0 \n\t"
285 1.78.36.1.2.1 matt "or %1,%M1,%L1 \n\t"
286 1.78.36.1.2.1 matt "lw %0, 0(%1) \n\t"
287 1.78.36.1.2.1 matt ".set pop"
288 1.78.36.1.2.1 matt : "=r"(rv), "=d"(addr)
289 1.78.36.1.2.1 matt : "1"(addr)
290 1.78.36.1.2.1 matt );
291 1.59 simonb
292 1.59 simonb mips_cp0_status_write(sr);
293 1.78.36.1.2.23 matt #elif defined(__mips_n32)
294 1.78.36.1.2.23 matt uint32_t sr = mips_cp0_status_read();
295 1.78.36.1.2.23 matt mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
296 1.78.36.1.2.24 matt __asm volatile("lw %0, 0(%1)" : "=r"(rv) : "d"(addr));
297 1.78.36.1.2.23 matt mips_cp0_status_write(sr);
298 1.78.36.1.2.1 matt #elif defined(_LP64)
299 1.78.36.1.2.1 matt rv = *(const uint32_t *)addr;
300 1.78.36.1.2.1 matt #else
301 1.78.36.1.2.24 matt #error unknown ABI
302 1.78.36.1.2.1 matt #endif
303 1.59 simonb return (rv);
304 1.59 simonb }
305 1.59 simonb
306 1.74 perry static __inline void
307 1.59 simonb mips3_sw_a64(uint64_t addr, uint32_t val)
308 1.59 simonb {
309 1.78.36.1.2.1 matt #if defined(__mips_o32)
310 1.59 simonb uint32_t sr;
311 1.59 simonb
312 1.59 simonb sr = mips_cp0_status_read();
313 1.78.36.1.2.1 matt mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
314 1.59 simonb
315 1.78.36.1.2.1 matt __asm volatile (
316 1.78.36.1.2.1 matt ".set push \n\t"
317 1.78.36.1.2.1 matt ".set mips3 \n\t"
318 1.78.36.1.2.1 matt ".set noreorder \n\t"
319 1.78.36.1.2.1 matt ".set noat \n\t"
320 1.78.36.1.2.1 matt "dsll32 %M0,%M0,0 \n\t"
321 1.78.36.1.2.1 matt "dsll32 %L0,%L0,0 \n\t"
322 1.78.36.1.2.10 cyber "dsrl32 %L0,%L0,0 \n\t"
323 1.78.36.1.2.1 matt "or %0,%M0,%L0 \n\t"
324 1.78.36.1.2.1 matt "sw %1, 0(%0) \n\t"
325 1.78.36.1.2.1 matt ".set pop"
326 1.78.36.1.2.1 matt : "=d"(addr): "r"(val), "0"(addr)
327 1.78.36.1.2.1 matt );
328 1.44 cgd
329 1.59 simonb mips_cp0_status_write(sr);
330 1.78.36.1.2.23 matt #elif defined(__mips_n32)
331 1.78.36.1.2.23 matt uint32_t sr = mips_cp0_status_read();
332 1.78.36.1.2.23 matt mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
333 1.78.36.1.2.24 matt __asm volatile("sw %1, 0(%0)" :: "d"(addr), "r"(val));
334 1.78.36.1.2.23 matt mips_cp0_status_write(sr);
335 1.78.36.1.2.1 matt #elif defined(_LP64)
336 1.78.36.1.2.1 matt *(uint32_t *)addr = val;
337 1.78.36.1.2.1 matt #else
338 1.78.36.1.2.24 matt #error unknown ABI
339 1.78.36.1.2.1 matt #endif
340 1.59 simonb }
341 1.78.36.1.2.30 matt #endif /* (MIPS3 + MIPS4 + MIPS64 + MIPS64R2 + MIPS64_RMIXL + MIPS64R2_RMIXL) > 0 */
342 1.7 jonathan
343 1.1 jonathan /*
344 1.58 thorpej * A vector with an entry for each mips-ISA-level dependent
345 1.1 jonathan * locore function, and macros which jump through it.
346 1.1 jonathan */
347 1.1 jonathan typedef struct {
348 1.78.36.1.2.27 matt void (*ljv_cpu_switch_resume)(struct lwp *);
349 1.78.36.1.2.27 matt intptr_t ljv_lwp_trampoline;
350 1.78.36.1.2.27 matt intptr_t ljv_setfunc_trampoline;
351 1.78.36.1.2.28 matt void (*ljv_wbflush)(void);
352 1.78.36.1.2.16 matt void (*ljv_tlb_set_asid)(uint32_t pid);
353 1.78.36.1.2.16 matt void (*ljv_tlb_invalidate_asids)(uint32_t, uint32_t);
354 1.78.36.1.2.16 matt void (*ljv_tlb_invalidate_addr)(vaddr_t);
355 1.78.36.1.2.16 matt void (*ljv_tlb_invalidate_globals)(void);
356 1.78.36.1.2.16 matt void (*ljv_tlb_invalidate_all)(void);
357 1.78.36.1.2.16 matt u_int (*ljv_tlb_record_asids)(u_long *, uint32_t);
358 1.78.36.1.2.16 matt int (*ljv_tlb_update)(vaddr_t, uint32_t);
359 1.78.36.1.2.16 matt void (*ljv_tlb_enter)(size_t, vaddr_t, uint32_t);
360 1.78.36.1.2.16 matt void (*ljv_tlb_read_indexed)(size_t, struct tlbmask *);
361 1.78.36.1.2.27 matt void (*ljv_tlb_write_indexed)(size_t, const struct tlbmask *);
362 1.78.36.1.2.32 matt lwp_t * (*ljv_cpu_switchto)(lwp_t *, lwp_t *, bool);
363 1.1 jonathan } mips_locore_jumpvec_t;
364 1.13 jonathan
365 1.78.36.1.2.29 matt typedef struct {
366 1.78.36.1.2.29 matt u_int (*lav_atomic_cas_uint)(volatile u_int *, u_int, u_int);
367 1.78.36.1.2.29 matt u_long (*lav_atomic_cas_ulong)(volatile u_long *, u_long, u_long);
368 1.78.36.1.2.29 matt int (*lav_ucas_uint)(volatile u_int *, u_int, u_int, u_int *);
369 1.78.36.1.2.29 matt int (*lav_ucas_ulong)(volatile u_long *, u_long, u_long, u_long *);
370 1.78.36.1.2.29 matt void (*lav_mutex_enter)(kmutex_t *);
371 1.78.36.1.2.29 matt void (*lav_mutex_exit)(kmutex_t *);
372 1.78.36.1.2.29 matt void (*lav_mutex_spin_enter)(kmutex_t *);
373 1.78.36.1.2.29 matt void (*lav_mutex_spin_exit)(kmutex_t *);
374 1.78.36.1.2.29 matt } mips_locore_atomicvec_t;
375 1.78.36.1.2.29 matt
376 1.38 cgd void mips_set_wbflush(void (*)(void));
377 1.62 simonb void mips_wait_idle(void);
378 1.1 jonathan
379 1.38 cgd void stacktrace(void);
380 1.38 cgd void logstacktrace(void);
381 1.1 jonathan
382 1.78.36.1.2.28 matt struct cpu_info;
383 1.78.36.1.2.28 matt struct splsw;
384 1.78.36.1.2.28 matt
385 1.78.36.1.2.2 matt struct locoresw {
386 1.78.36.1.2.27 matt void (*lsw_wbflush)(void);
387 1.78.36.1.2.16 matt void (*lsw_cpu_idle)(void);
388 1.78.36.1.2.16 matt int (*lsw_send_ipi)(struct cpu_info *, int);
389 1.78.36.1.2.16 matt void (*lsw_cpu_offline_md)(void);
390 1.78.36.1.2.21 matt void (*lsw_cpu_init)(struct cpu_info *);
391 1.78.36.1.2.29 matt void (*lsw_cpu_run)(struct cpu_info *);
392 1.78.36.1.2.25 cliff int (*lsw_bus_error)(unsigned int);
393 1.78.36.1.2.2 matt };
394 1.78.36.1.2.2 matt
395 1.78.36.1.2.7 matt struct mips_vmfreelist {
396 1.78.36.1.2.7 matt paddr_t fl_start;
397 1.78.36.1.2.7 matt paddr_t fl_end;
398 1.78.36.1.2.7 matt int fl_freelist;
399 1.78.36.1.2.7 matt };
400 1.78.36.1.2.7 matt
401 1.1 jonathan /*
402 1.78.36.1.2.29 matt * The "active" locore-function vector, and
403 1.1 jonathan */
404 1.78.36.1.2.29 matt extern const mips_locore_atomicvec_t mips_llsc_locore_atomicvec;
405 1.78.36.1.2.29 matt extern const mips_locore_atomicvec_t mips_ras_locore_atomicvec;
406 1.78.36.1.2.29 matt
407 1.78.36.1.2.29 matt extern mips_locore_atomicvec_t mips_locore_atomicvec;
408 1.1 jonathan extern mips_locore_jumpvec_t mips_locore_jumpvec;
409 1.78.36.1.2.2 matt extern struct locoresw mips_locoresw;
410 1.78.36.1.2.29 matt
411 1.78.36.1.2.29 matt struct splsw;
412 1.78.36.1.2.29 matt struct mips_vmfreelist;
413 1.78.36.1.2.29 matt struct phys_ram_seg;
414 1.78.36.1.2.29 matt
415 1.78.36.1.2.29 matt void mips_vector_init(const struct splsw *, bool);
416 1.78.36.1.2.29 matt void mips_init_msgbuf(void);
417 1.78.36.1.2.29 matt void mips_init_lwp0_uarea(void);
418 1.78.36.1.2.29 matt void mips_page_physload(vaddr_t, vaddr_t,
419 1.78.36.1.2.29 matt const struct phys_ram_seg *, size_t,
420 1.78.36.1.2.29 matt const struct mips_vmfreelist *, size_t);
421 1.78.36.1.2.29 matt
422 1.78.36.1.2.34 matt paddr_t kvtophys(vaddr_t);
423 1.78.36.1.2.34 matt
424 1.78.36.1.2.34 matt extern struct phys_ram_seg mem_clusters[];
425 1.78.36.1.2.34 matt extern u_int mem_cluster_cnt;
426 1.78.36.1.2.34 matt
427 1.78.36.1.2.34 matt /*
428 1.78.36.1.2.34 matt * Helper routines for kernel coredumps.
429 1.78.36.1.2.34 matt */
430 1.78.36.1.2.34 matt vaddr_t mips_kcore_window_map(paddr_t, vsize_t *);
431 1.78.36.1.2.35 matt #ifndef _LP64
432 1.78.36.1.2.35 matt bool mips_kcore_window_vtophys(vaddr_t, paddr_t *);
433 1.78.36.1.2.34 matt #endif
434 1.78.36.1.2.34 matt
435 1.1 jonathan
436 1.7 jonathan /*
437 1.7 jonathan * CPU identification, from PRID register.
438 1.7 jonathan */
439 1.70 tsutsui #define MIPS_PRID_REV(x) (((x) >> 0) & 0x00ff)
440 1.70 tsutsui #define MIPS_PRID_IMPL(x) (((x) >> 8) & 0x00ff)
441 1.45 cgd
442 1.59 simonb /* pre-MIPS32/64 */
443 1.70 tsutsui #define MIPS_PRID_RSVD(x) (((x) >> 16) & 0xffff)
444 1.70 tsutsui #define MIPS_PRID_REV_MIN(x) ((MIPS_PRID_REV(x) >> 0) & 0x0f)
445 1.70 tsutsui #define MIPS_PRID_REV_MAJ(x) ((MIPS_PRID_REV(x) >> 4) & 0x0f)
446 1.45 cgd
447 1.59 simonb /* MIPS32/64 */
448 1.70 tsutsui #define MIPS_PRID_CID(x) (((x) >> 16) & 0x00ff) /* Company ID */
449 1.70 tsutsui #define MIPS_PRID_CID_PREHISTORIC 0x00 /* Not MIPS32/64 */
450 1.70 tsutsui #define MIPS_PRID_CID_MTI 0x01 /* MIPS Technologies, Inc. */
451 1.70 tsutsui #define MIPS_PRID_CID_BROADCOM 0x02 /* Broadcom */
452 1.70 tsutsui #define MIPS_PRID_CID_ALCHEMY 0x03 /* Alchemy Semiconductor */
453 1.70 tsutsui #define MIPS_PRID_CID_SIBYTE 0x04 /* SiByte */
454 1.70 tsutsui #define MIPS_PRID_CID_SANDCRAFT 0x05 /* SandCraft */
455 1.70 tsutsui #define MIPS_PRID_CID_PHILIPS 0x06 /* Philips */
456 1.70 tsutsui #define MIPS_PRID_CID_TOSHIBA 0x07 /* Toshiba */
457 1.70 tsutsui #define MIPS_PRID_CID_LSI 0x08 /* LSI */
458 1.67 simonb /* 0x09 unannounced */
459 1.67 simonb /* 0x0a unannounced */
460 1.70 tsutsui #define MIPS_PRID_CID_LEXRA 0x0b /* Lexra */
461 1.78.36.1.2.3 matt #define MIPS_PRID_CID_RMI 0x0c /* RMI / NetLogic */
462 1.70 tsutsui #define MIPS_PRID_COPTS(x) (((x) >> 24) & 0x00ff) /* Company Options */
463 1.6 jonathan
464 1.6 jonathan #ifdef _KERNEL
465 1.6 jonathan /*
466 1.6 jonathan * Global variables used to communicate CPU type, and parameters
467 1.6 jonathan * such as cache size, from locore to higher-level code (e.g., pmap).
468 1.6 jonathan */
469 1.75 christos void mips_pagecopy(void *dst, void *src);
470 1.75 christos void mips_pagezero(void *dst);
471 1.19 jonathan
472 1.59 simonb #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
473 1.59 simonb void mips_machdep_cache_config(void);
474 1.59 simonb #endif
475 1.59 simonb
476 1.19 jonathan /*
477 1.20 simonb * trapframe argument passed to trap()
478 1.19 jonathan */
479 1.64 thorpej
480 1.78.36.1.2.11 matt #if 0
481 1.78.36.1.2.11 matt #define TF_AST 0 /* really zero */
482 1.78.36.1.2.11 matt #define TF_V0 _R_V0
483 1.78.36.1.2.11 matt #define TF_V1 _R_V1
484 1.78.36.1.2.11 matt #define TF_A0 _R_A0
485 1.78.36.1.2.11 matt #define TF_A1 _R_A1
486 1.78.36.1.2.11 matt #define TF_A2 _R_A2
487 1.78.36.1.2.11 matt #define TF_A3 _R_A3
488 1.78.36.1.2.11 matt #define TF_T0 _R_T0
489 1.78.36.1.2.11 matt #define TF_T1 _R_T1
490 1.78.36.1.2.11 matt #define TF_T2 _R_T2
491 1.78.36.1.2.11 matt #define TF_T3 _R_T3
492 1.64 thorpej
493 1.64 thorpej #if defined(__mips_n32) || defined(__mips_n64)
494 1.78.36.1.2.11 matt #define TF_A4 _R_A4
495 1.78.36.1.2.11 matt #define TF_A5 _R_A5
496 1.78.36.1.2.11 matt #define TF_A6 _R_A6
497 1.78.36.1.2.11 matt #define TF_A7 _R_A7
498 1.64 thorpej #else
499 1.78.36.1.2.11 matt #define TF_T4 _R_T4
500 1.78.36.1.2.11 matt #define TF_T5 _R_T5
501 1.78.36.1.2.11 matt #define TF_T6 _R_T6
502 1.78.36.1.2.11 matt #define TF_T7 _R_T7
503 1.64 thorpej #endif /* __mips_n32 || __mips_n64 */
504 1.64 thorpej
505 1.78.36.1.2.11 matt #define TF_TA0 _R_TA0
506 1.78.36.1.2.11 matt #define TF_TA1 _R_TA1
507 1.78.36.1.2.11 matt #define TF_TA2 _R_TA2
508 1.78.36.1.2.11 matt #define TF_TA3 _R_TA3
509 1.78.36.1.2.11 matt
510 1.78.36.1.2.11 matt #define TF_T8 _R_T8
511 1.78.36.1.2.11 matt #define TF_T9 _R_T9
512 1.78.36.1.2.11 matt
513 1.78.36.1.2.11 matt #define TF_RA _R_RA
514 1.78.36.1.2.11 matt #define TF_SR _R_SR
515 1.78.36.1.2.11 matt #define TF_MULLO _R_MULLO
516 1.78.36.1.2.11 matt #define TF_MULHI _R_MULLO
517 1.78.36.1.2.11 matt #define TF_EPC _R_PC /* may be changed by trap() call */
518 1.65 thorpej
519 1.78.36.1.2.11 matt #define TF_NREGS (sizeof(struct reg) / sizeof(mips_reg_t))
520 1.78.36.1.2.11 matt #endif
521 1.64 thorpej
522 1.19 jonathan struct trapframe {
523 1.78.36.1.2.11 matt struct reg tf_registers;
524 1.78.36.1.2.11 matt #define tf_regs tf_registers.r_regs
525 1.78.36.1.2.2 matt uint32_t tf_ppl; /* previous priority level */
526 1.78.36.1.2.2 matt mips_reg_t tf_pad; /* for 8 byte aligned */
527 1.19 jonathan };
528 1.19 jonathan
529 1.78.36.1.2.11 matt CTASSERT(sizeof(struct trapframe) % (4*sizeof(mips_reg_t)) == 0);
530 1.78.36.1.2.11 matt
531 1.19 jonathan /*
532 1.19 jonathan * Stack frame for kernel traps. four args passed in registers.
533 1.19 jonathan * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
534 1.19 jonathan * is used to avoid alignment problems
535 1.19 jonathan */
536 1.19 jonathan
537 1.19 jonathan struct kernframe {
538 1.78.36.1.2.1 matt #if defined(__mips_o32) || defined(__mips_o64)
539 1.19 jonathan register_t cf_args[4 + 1];
540 1.78.36.1.2.1 matt #if defined(__mips_o32)
541 1.78.36.1.2.11 matt register_t cf_pad; /* (for 8 byte alignment) */
542 1.78.36.1.2.1 matt #endif
543 1.78.36.1.2.1 matt #endif
544 1.78.36.1.2.1 matt #if defined(__mips_n32) || defined(__mips_n64)
545 1.78.36.1.2.4 matt register_t cf_pad[2]; /* for 16 byte alignment */
546 1.78.36.1.2.1 matt #endif
547 1.19 jonathan register_t cf_sp;
548 1.19 jonathan register_t cf_ra;
549 1.19 jonathan struct trapframe cf_frame;
550 1.19 jonathan };
551 1.78.36.1.2.11 matt
552 1.78.36.1.2.11 matt CTASSERT(sizeof(struct kernframe) % (2*sizeof(mips_reg_t)) == 0);
553 1.78.36.1.2.11 matt
554 1.78.36.1.2.18 matt /*
555 1.78.36.1.2.18 matt * PRocessor IDentity TABle
556 1.78.36.1.2.18 matt */
557 1.78.36.1.2.18 matt
558 1.78.36.1.2.18 matt struct pridtab {
559 1.78.36.1.2.18 matt int cpu_cid;
560 1.78.36.1.2.18 matt int cpu_pid;
561 1.78.36.1.2.18 matt int cpu_rev; /* -1 == wildcard */
562 1.78.36.1.2.18 matt int cpu_copts; /* -1 == wildcard */
563 1.78.36.1.2.18 matt int cpu_isa; /* -1 == probed (mips32/mips64) */
564 1.78.36.1.2.18 matt int cpu_ntlb; /* -1 == unknown, 0 == probed */
565 1.78.36.1.2.18 matt int cpu_flags;
566 1.78.36.1.2.18 matt u_int cpu_cp0flags; /* presence of some cp0 regs */
567 1.78.36.1.2.18 matt u_int cpu_cidflags; /* company-specific flags */
568 1.78.36.1.2.18 matt const char *cpu_name;
569 1.78.36.1.2.18 matt };
570 1.78.36.1.2.18 matt
571 1.78.36.1.2.18 matt /*
572 1.78.36.1.2.18 matt * bitfield defines for cpu_cp0flags
573 1.78.36.1.2.18 matt */
574 1.78.36.1.2.18 matt #define MIPS_CP0FL_USE __BIT(0) /* use these flags */
575 1.78.36.1.2.18 matt #define MIPS_CP0FL_ECC __BIT(1)
576 1.78.36.1.2.18 matt #define MIPS_CP0FL_CACHE_ERR __BIT(2)
577 1.78.36.1.2.18 matt #define MIPS_CP0FL_EIRR __BIT(3)
578 1.78.36.1.2.18 matt #define MIPS_CP0FL_EIMR __BIT(4)
579 1.78.36.1.2.18 matt #define MIPS_CP0FL_EBASE __BIT(5)
580 1.78.36.1.2.18 matt #define MIPS_CP0FL_CONFIG __BIT(6)
581 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG1 __BIT(7)
582 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG2 __BIT(8)
583 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG3 __BIT(9)
584 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG4 __BIT(10)
585 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG5 __BIT(11)
586 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG6 __BIT(12)
587 1.78.36.1.2.29 matt #define MIPS_CP0FL_CONFIG7 __BIT(13)
588 1.78.36.1.2.29 matt #define MIPS_CP0FL_USERLOCAL __BIT(14)
589 1.78.36.1.2.29 matt #define MIPS_CP0FL_HWRENA __BIT(15)
590 1.78.36.1.2.18 matt
591 1.78.36.1.2.18 matt /*
592 1.78.36.1.2.18 matt * cpu_cidflags defines, by company
593 1.78.36.1.2.18 matt */
594 1.78.36.1.2.18 matt /*
595 1.78.36.1.2.18 matt * RMI company-specific cpu_cidflags
596 1.78.36.1.2.18 matt */
597 1.78.36.1.2.29 matt #define MIPS_CIDFL_RMI_TYPE __BITS(2,0)
598 1.78.36.1.2.29 matt # define CIDFL_RMI_TYPE_XLR 0
599 1.78.36.1.2.29 matt # define CIDFL_RMI_TYPE_XLS 1
600 1.78.36.1.2.29 matt # define CIDFL_RMI_TYPE_XLP 2
601 1.78.36.1.2.18 matt #define MIPS_CIDFL_RMI_THREADS_MASK __BITS(6,3)
602 1.78.36.1.2.18 matt #define MIPS_CIDFL_RMI_CORES_MASK __BITS(10,7)
603 1.78.36.1.2.18 matt # define LOG2_1 0
604 1.78.36.1.2.18 matt # define LOG2_2 1
605 1.78.36.1.2.18 matt # define LOG2_4 2
606 1.78.36.1.2.18 matt # define LOG2_8 3
607 1.78.36.1.2.18 matt # define MIPS_CIDFL_RMI_CPUS(ncores, nthreads) \
608 1.78.36.1.2.31 matt (__SHIFTIN(LOG2_ ## ncores, MIPS_CIDFL_RMI_CORES_MASK) \
609 1.78.36.1.2.31 matt |__SHIFTIN(LOG2_ ## nthreads, MIPS_CIDFL_RMI_THREADS_MASK))
610 1.78.36.1.2.18 matt # define MIPS_CIDFL_RMI_NTHREADS(cidfl) \
611 1.78.36.1.2.31 matt (1 << __SHIFTOUT((cidfl), MIPS_CIDFL_RMI_THREADS_MASK))
612 1.78.36.1.2.18 matt # define MIPS_CIDFL_RMI_NCORES(cidfl) \
613 1.78.36.1.2.31 matt (1 << __SHIFTOUT((cidfl), MIPS_CIDFL_RMI_CORES_MASK))
614 1.78.36.1.2.18 matt #define MIPS_CIDFL_RMI_L2SZ_MASK __BITS(14,11)
615 1.78.36.1.2.18 matt # define RMI_L2SZ_256KB 0
616 1.78.36.1.2.18 matt # define RMI_L2SZ_512KB 1
617 1.78.36.1.2.18 matt # define RMI_L2SZ_1MB 2
618 1.78.36.1.2.18 matt # define RMI_L2SZ_2MB 3
619 1.78.36.1.2.18 matt # define RMI_L2SZ_4MB 4
620 1.78.36.1.2.18 matt # define MIPS_CIDFL_RMI_L2(l2sz) \
621 1.78.36.1.2.31 matt __SHIFTIN(RMI_L2SZ_ ## l2sz, MIPS_CIDFL_RMI_L2SZ_MASK)
622 1.78.36.1.2.18 matt # define MIPS_CIDFL_RMI_L2SZ(cidfl) \
623 1.78.36.1.2.31 matt ((256*1024) << __SHIFTOUT((cidfl), MIPS_CIDFL_RMI_L2SZ_MASK))
624 1.78.36.1.2.31 matt #define MIPS_CIDFL_RMI_L3SZ_MASK __BITS(18,15)
625 1.78.36.1.2.31 matt # define RMI_L3SZ_256KB 0
626 1.78.36.1.2.31 matt # define RMI_L3SZ_512KB 1
627 1.78.36.1.2.31 matt # define RMI_L3SZ_1MB 2
628 1.78.36.1.2.31 matt # define RMI_L3SZ_2MB 3
629 1.78.36.1.2.31 matt # define RMI_L3SZ_4MB 4
630 1.78.36.1.2.31 matt # define MIPS_CIDFL_RMI_L3(l3sz) \
631 1.78.36.1.2.31 matt __SHIFTIN(RMI_L3SZ_ ## l3sz, MIPS_CIDFL_RMI_L3SZ_MASK)
632 1.78.36.1.2.31 matt # define MIPS_CIDFL_RMI_L3SZ(cidfl) \
633 1.78.36.1.2.31 matt ((256*1024) << __SHIFTOUT((cidfl), MIPS_CIDFL_RMI_L3SZ_MASK))
634 1.78.36.1.2.18 matt
635 1.61 simonb #endif /* _KERNEL */
636 1.1 jonathan #endif /* _MIPS_LOCORE_H */
637