locore.h revision 1.77 1 1.77 tsutsui /* $NetBSD: locore.h,v 1.77 2007/06/17 06:04:28 tsutsui Exp $ */
2 1.1 jonathan
3 1.1 jonathan /*
4 1.1 jonathan * Copyright 1996 The Board of Trustees of The Leland Stanford
5 1.1 jonathan * Junior University. All Rights Reserved.
6 1.1 jonathan *
7 1.1 jonathan * Permission to use, copy, modify, and distribute this
8 1.1 jonathan * software and its documentation for any purpose and without
9 1.1 jonathan * fee is hereby granted, provided that the above copyright
10 1.1 jonathan * notice appear in all copies. Stanford University
11 1.1 jonathan * makes no representations about the suitability of this
12 1.1 jonathan * software for any purpose. It is provided "as is" without
13 1.1 jonathan * express or implied warranty.
14 1.1 jonathan */
15 1.1 jonathan
16 1.1 jonathan /*
17 1.68 wiz * Jump table for MIPS CPU locore functions that are implemented
18 1.1 jonathan * differently on different generations, or instruction-level
19 1.1 jonathan * archtecture (ISA) level, the Mips family.
20 1.1 jonathan *
21 1.33 soren * We currently provide support for MIPS I and MIPS III.
22 1.1 jonathan */
23 1.1 jonathan
24 1.1 jonathan #ifndef _MIPS_LOCORE_H
25 1.70 tsutsui #define _MIPS_LOCORE_H
26 1.2 jonathan
27 1.17 castor #ifndef _LKM
28 1.32 soren #include "opt_cputype.h"
29 1.17 castor #endif
30 1.16 castor
31 1.59 simonb #include <mips/cpuregs.h>
32 1.59 simonb
33 1.38 cgd struct tlb;
34 1.38 cgd
35 1.59 simonb uint32_t mips_cp0_cause_read(void);
36 1.59 simonb void mips_cp0_cause_write(uint32_t);
37 1.59 simonb uint32_t mips_cp0_status_read(void);
38 1.59 simonb void mips_cp0_status_write(uint32_t);
39 1.29 simonb
40 1.77 tsutsui int _splraise(int);
41 1.77 tsutsui int _spllower(int);
42 1.77 tsutsui int _splset(int);
43 1.77 tsutsui int _splget(void);
44 1.77 tsutsui void _splnone(void);
45 1.77 tsutsui void _setsoftintr(int);
46 1.77 tsutsui void _clrsoftintr(int);
47 1.77 tsutsui
48 1.59 simonb #ifdef MIPS1
49 1.54 simonb void mips1_SetPID(int);
50 1.38 cgd void mips1_TBIA(int);
51 1.38 cgd void mips1_TBIAP(int);
52 1.38 cgd void mips1_TBIS(vaddr_t);
53 1.38 cgd int mips1_TLBUpdate(u_int, u_int);
54 1.38 cgd void mips1_wbflush(void);
55 1.76 yamt void mips1_lwp_trampoline(void);
56 1.38 cgd void mips1_cpu_switch_resume(void);
57 1.38 cgd
58 1.58 thorpej uint32_t tx3900_cp0_config_read(void);
59 1.59 simonb #endif
60 1.38 cgd
61 1.59 simonb #if defined(MIPS3) || defined(MIPS4)
62 1.54 simonb void mips3_SetPID(int);
63 1.38 cgd void mips3_TBIA(int);
64 1.38 cgd void mips3_TBIAP(int);
65 1.38 cgd void mips3_TBIS(vaddr_t);
66 1.38 cgd int mips3_TLBUpdate(u_int, u_int);
67 1.38 cgd void mips3_TLBRead(int, struct tlb *);
68 1.71 tsutsui void mips3_TLBWriteIndexedVPS(int, struct tlb *);
69 1.38 cgd void mips3_wbflush(void);
70 1.76 yamt void mips3_lwp_trampoline(void);
71 1.38 cgd void mips3_cpu_switch_resume(void);
72 1.75 christos void mips3_pagezero(void *dst);
73 1.38 cgd
74 1.59 simonb #ifdef MIPS3_5900
75 1.59 simonb void mips5900_SetPID(int);
76 1.59 simonb void mips5900_TBIA(int);
77 1.59 simonb void mips5900_TBIAP(int);
78 1.59 simonb void mips5900_TBIS(vaddr_t);
79 1.59 simonb int mips5900_TLBUpdate(u_int, u_int);
80 1.59 simonb void mips5900_TLBRead(int, struct tlb *);
81 1.71 tsutsui void mips5900_TLBWriteIndexedVPS(int, struct tlb *);
82 1.59 simonb void mips5900_wbflush(void);
83 1.76 yamt void mips5900_lwp_trampoline(void);
84 1.59 simonb void mips5900_cpu_switch_resume(void);
85 1.75 christos void mips5900_pagezero(void *dst);
86 1.59 simonb #endif
87 1.59 simonb #endif
88 1.49 cgd
89 1.59 simonb #ifdef MIPS32
90 1.59 simonb void mips32_SetPID(int);
91 1.59 simonb void mips32_TBIA(int);
92 1.59 simonb void mips32_TBIAP(int);
93 1.59 simonb void mips32_TBIS(vaddr_t);
94 1.59 simonb int mips32_TLBUpdate(u_int, u_int);
95 1.59 simonb void mips32_TLBRead(int, struct tlb *);
96 1.71 tsutsui void mips32_TLBWriteIndexedVPS(int, struct tlb *);
97 1.59 simonb void mips32_wbflush(void);
98 1.76 yamt void mips32_lwp_trampoline(void);
99 1.59 simonb void mips32_cpu_switch_resume(void);
100 1.59 simonb #endif
101 1.59 simonb
102 1.59 simonb #ifdef MIPS64
103 1.59 simonb void mips64_SetPID(int);
104 1.59 simonb void mips64_TBIA(int);
105 1.59 simonb void mips64_TBIAP(int);
106 1.59 simonb void mips64_TBIS(vaddr_t);
107 1.59 simonb int mips64_TLBUpdate(u_int, u_int);
108 1.59 simonb void mips64_TLBRead(int, struct tlb *);
109 1.71 tsutsui void mips64_TLBWriteIndexedVPS(int, struct tlb *);
110 1.59 simonb void mips64_wbflush(void);
111 1.76 yamt void mips64_lwp_trampoline(void);
112 1.59 simonb void mips64_cpu_switch_resume(void);
113 1.75 christos void mips64_pagezero(void *dst);
114 1.59 simonb #endif
115 1.49 cgd
116 1.63 simonb #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
117 1.59 simonb uint32_t mips3_cp0_compare_read(void);
118 1.59 simonb void mips3_cp0_compare_write(uint32_t);
119 1.49 cgd
120 1.59 simonb uint32_t mips3_cp0_config_read(void);
121 1.59 simonb void mips3_cp0_config_write(uint32_t);
122 1.63 simonb #if defined(MIPS32) || defined(MIPS64)
123 1.59 simonb uint32_t mipsNN_cp0_config1_read(void);
124 1.59 simonb void mipsNN_cp0_config1_write(uint32_t);
125 1.63 simonb uint32_t mipsNN_cp0_config2_read(void);
126 1.63 simonb uint32_t mipsNN_cp0_config3_read(void);
127 1.63 simonb #endif
128 1.59 simonb
129 1.59 simonb uint32_t mips3_cp0_count_read(void);
130 1.59 simonb void mips3_cp0_count_write(uint32_t);
131 1.59 simonb
132 1.59 simonb uint32_t mips3_cp0_wired_read(void);
133 1.59 simonb void mips3_cp0_wired_write(uint32_t);
134 1.69 tsutsui void mips3_cp0_pg_mask_write(uint32_t);
135 1.59 simonb
136 1.59 simonb uint64_t mips3_ld(uint64_t *);
137 1.59 simonb void mips3_sd(uint64_t *, uint64_t);
138 1.63 simonb #endif /* MIPS3 || MIPS4 || MIPS32 || MIPS64 */
139 1.59 simonb
140 1.63 simonb #if defined(MIPS3) || defined(MIPS4) || defined(MIPS64)
141 1.74 perry static __inline uint32_t mips3_lw_a64(uint64_t addr)
142 1.59 simonb __attribute__((__unused__));
143 1.74 perry static __inline void mips3_sw_a64(uint64_t addr, uint32_t val)
144 1.59 simonb __attribute__ ((__unused__));
145 1.59 simonb
146 1.74 perry static __inline uint32_t
147 1.59 simonb mips3_lw_a64(uint64_t addr)
148 1.59 simonb {
149 1.59 simonb uint32_t addrlo, addrhi;
150 1.59 simonb uint32_t rv;
151 1.59 simonb uint32_t sr;
152 1.59 simonb
153 1.59 simonb sr = mips_cp0_status_read();
154 1.59 simonb mips_cp0_status_write(sr | MIPS3_SR_KX);
155 1.59 simonb
156 1.59 simonb addrlo = addr & 0xffffffff;
157 1.59 simonb addrhi = addr >> 32;
158 1.73 perry __asm volatile (" \n\
159 1.59 simonb .set push \n\
160 1.59 simonb .set mips3 \n\
161 1.59 simonb .set noreorder \n\
162 1.59 simonb .set noat \n\
163 1.59 simonb dsll32 $3, %1, 0 \n\
164 1.59 simonb dsll32 $1, %2, 0 \n\
165 1.59 simonb dsrl32 $3, $3, 0 \n\
166 1.59 simonb or $1, $1, $3 \n\
167 1.59 simonb lw %0, 0($1) \n\
168 1.59 simonb .set pop \n\
169 1.59 simonb " : "=r"(rv) : "r"(addrlo), "r"(addrhi) : "$1", "$3" );
170 1.59 simonb
171 1.59 simonb mips_cp0_status_write(sr);
172 1.59 simonb
173 1.59 simonb return (rv);
174 1.59 simonb }
175 1.59 simonb
176 1.74 perry static __inline void
177 1.59 simonb mips3_sw_a64(uint64_t addr, uint32_t val)
178 1.59 simonb {
179 1.59 simonb uint32_t addrlo, addrhi;
180 1.59 simonb uint32_t sr;
181 1.59 simonb
182 1.59 simonb sr = mips_cp0_status_read();
183 1.59 simonb mips_cp0_status_write(sr | MIPS3_SR_KX);
184 1.59 simonb
185 1.59 simonb addrlo = addr & 0xffffffff;
186 1.59 simonb addrhi = addr >> 32;
187 1.73 perry __asm volatile (" \n\
188 1.59 simonb .set push \n\
189 1.59 simonb .set mips3 \n\
190 1.59 simonb .set noreorder \n\
191 1.59 simonb .set noat \n\
192 1.59 simonb dsll32 $3, %1, 0 \n\
193 1.59 simonb dsll32 $1, %2, 0 \n\
194 1.59 simonb dsrl32 $3, $3, 0 \n\
195 1.59 simonb or $1, $1, $3 \n\
196 1.59 simonb sw %0, 0($1) \n\
197 1.59 simonb .set pop \n\
198 1.59 simonb " : : "r"(val), "r"(addrlo), "r"(addrhi) : "$1", "$3" );
199 1.44 cgd
200 1.59 simonb mips_cp0_status_write(sr);
201 1.59 simonb }
202 1.63 simonb #endif /* MIPS3 || MIPS4 || MIPS64 */
203 1.7 jonathan
204 1.1 jonathan /*
205 1.58 thorpej * A vector with an entry for each mips-ISA-level dependent
206 1.1 jonathan * locore function, and macros which jump through it.
207 1.58 thorpej *
208 1.1 jonathan * XXX the macro names are chosen to be compatible with the old
209 1.58 thorpej * XXX Sprite coding-convention names used in 4.4bsd/pmax.
210 1.1 jonathan */
211 1.1 jonathan typedef struct {
212 1.38 cgd void (*setTLBpid)(int pid);
213 1.38 cgd void (*TBIAP)(int);
214 1.38 cgd void (*TBIS)(vaddr_t);
215 1.38 cgd int (*tlbUpdate)(u_int highreg, u_int lowreg);
216 1.38 cgd void (*wbflush)(void);
217 1.1 jonathan } mips_locore_jumpvec_t;
218 1.13 jonathan
219 1.38 cgd void mips_set_wbflush(void (*)(void));
220 1.62 simonb void mips_wait_idle(void);
221 1.1 jonathan
222 1.38 cgd void stacktrace(void);
223 1.38 cgd void logstacktrace(void);
224 1.1 jonathan
225 1.1 jonathan /*
226 1.1 jonathan * The "active" locore-fuction vector, and
227 1.1 jonathan */
228 1.1 jonathan extern mips_locore_jumpvec_t mips_locore_jumpvec;
229 1.31 nisimura extern long *mips_locoresw[];
230 1.1 jonathan
231 1.59 simonb #if defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64)
232 1.11 jonathan #define MachSetPID mips1_SetPID
233 1.30 nisimura #define MIPS_TBIAP() mips1_TBIAP(mips_num_tlb_entries)
234 1.30 nisimura #define MIPS_TBIS mips1_TBIS
235 1.11 jonathan #define MachTLBUpdate mips1_TLBUpdate
236 1.22 nisimura #define wbflush() mips1_wbflush()
237 1.76 yamt #define lwp_trampoline mips1_lwp_trampoline
238 1.60 uch #elif !defined(MIPS1) && defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && !defined(MIPS3_5900)
239 1.59 simonb #define MachSetPID mips3_SetPID
240 1.59 simonb #define MIPS_TBIAP() mips3_TBIAP(mips_num_tlb_entries)
241 1.59 simonb #define MIPS_TBIS mips3_TBIS
242 1.59 simonb #define MachTLBUpdate mips3_TLBUpdate
243 1.71 tsutsui #define MachTLBWriteIndexedVPS mips3_TLBWriteIndexedVPS
244 1.76 yamt #define lwp_trampoline mips3_lwp_trampoline
245 1.59 simonb #define wbflush() mips3_wbflush()
246 1.59 simonb #elif !defined(MIPS1) && !defined(MIPS3) && defined(MIPS32) && !defined(MIPS64)
247 1.70 tsutsui #define MachSetPID mips32_SetPID
248 1.70 tsutsui #define MIPS_TBIAP() mips32_TBIAP(mips_num_tlb_entries)
249 1.70 tsutsui #define MIPS_TBIS mips32_TBIS
250 1.70 tsutsui #define MachTLBUpdate mips32_TLBUpdate
251 1.71 tsutsui #define MachTLBWriteIndexedVPS mips32_TLBWriteIndexedVPS
252 1.76 yamt #define lwp_trampoline mips32_lwp_trampoline
253 1.59 simonb #define wbflush() mips32_wbflush()
254 1.59 simonb #elif !defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) && defined(MIPS64)
255 1.59 simonb /* all common with mips3 */
256 1.59 simonb #define MachSetPID mips64_SetPID
257 1.59 simonb #define MIPS_TBIAP() mips64_TBIAP(mips_num_tlb_entries)
258 1.59 simonb #define MIPS_TBIS mips64_TBIS
259 1.59 simonb #define MachTLBUpdate mips64_TLBUpdate
260 1.71 tsutsui #define MachTLBWriteIndexedVPS mips64_TLBWriteIndexedVPS
261 1.76 yamt #define lwp_trampoline mips64_lwp_trampoline
262 1.59 simonb #define wbflush() mips64_wbflush()
263 1.60 uch #elif !defined(MIPS1) && defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && defined(MIPS3_5900)
264 1.60 uch #define MachSetPID mips5900_SetPID
265 1.60 uch #define MIPS_TBIAP() mips5900_TBIAP(mips_num_tlb_entries)
266 1.60 uch #define MIPS_TBIS mips5900_TBIS
267 1.60 uch #define MachTLBUpdate mips5900_TLBUpdate
268 1.71 tsutsui #define MachTLBWriteIndexedVPS mips5900_TLBWriteIndexedVPS
269 1.76 yamt #define lwp_trampoline mips5900_lwp_trampoline
270 1.60 uch #define wbflush() mips5900_wbflush()
271 1.59 simonb #else
272 1.1 jonathan #define MachSetPID (*(mips_locore_jumpvec.setTLBpid))
273 1.31 nisimura #define MIPS_TBIAP() (*(mips_locore_jumpvec.TBIAP))(mips_num_tlb_entries)
274 1.31 nisimura #define MIPS_TBIS (*(mips_locore_jumpvec.TBIS))
275 1.1 jonathan #define MachTLBUpdate (*(mips_locore_jumpvec.tlbUpdate))
276 1.22 nisimura #define wbflush() (*(mips_locore_jumpvec.wbflush))()
277 1.76 yamt #define lwp_trampoline (mips_locoresw[1])
278 1.11 jonathan #endif
279 1.31 nisimura
280 1.31 nisimura #define CPU_IDLE (mips_locoresw[2])
281 1.11 jonathan
282 1.16 castor /* cpu_switch_resume is called inside locore.S */
283 1.7 jonathan
284 1.7 jonathan /*
285 1.7 jonathan * CPU identification, from PRID register.
286 1.7 jonathan */
287 1.40 cgd typedef int mips_prid_t;
288 1.40 cgd
289 1.70 tsutsui #define MIPS_PRID_REV(x) (((x) >> 0) & 0x00ff)
290 1.70 tsutsui #define MIPS_PRID_IMPL(x) (((x) >> 8) & 0x00ff)
291 1.45 cgd
292 1.59 simonb /* pre-MIPS32/64 */
293 1.70 tsutsui #define MIPS_PRID_RSVD(x) (((x) >> 16) & 0xffff)
294 1.70 tsutsui #define MIPS_PRID_REV_MIN(x) ((MIPS_PRID_REV(x) >> 0) & 0x0f)
295 1.70 tsutsui #define MIPS_PRID_REV_MAJ(x) ((MIPS_PRID_REV(x) >> 4) & 0x0f)
296 1.45 cgd
297 1.59 simonb /* MIPS32/64 */
298 1.70 tsutsui #define MIPS_PRID_CID(x) (((x) >> 16) & 0x00ff) /* Company ID */
299 1.70 tsutsui #define MIPS_PRID_CID_PREHISTORIC 0x00 /* Not MIPS32/64 */
300 1.70 tsutsui #define MIPS_PRID_CID_MTI 0x01 /* MIPS Technologies, Inc. */
301 1.70 tsutsui #define MIPS_PRID_CID_BROADCOM 0x02 /* Broadcom */
302 1.70 tsutsui #define MIPS_PRID_CID_ALCHEMY 0x03 /* Alchemy Semiconductor */
303 1.70 tsutsui #define MIPS_PRID_CID_SIBYTE 0x04 /* SiByte */
304 1.70 tsutsui #define MIPS_PRID_CID_SANDCRAFT 0x05 /* SandCraft */
305 1.70 tsutsui #define MIPS_PRID_CID_PHILIPS 0x06 /* Philips */
306 1.70 tsutsui #define MIPS_PRID_CID_TOSHIBA 0x07 /* Toshiba */
307 1.70 tsutsui #define MIPS_PRID_CID_LSI 0x08 /* LSI */
308 1.67 simonb /* 0x09 unannounced */
309 1.67 simonb /* 0x0a unannounced */
310 1.70 tsutsui #define MIPS_PRID_CID_LEXRA 0x0b /* Lexra */
311 1.70 tsutsui #define MIPS_PRID_COPTS(x) (((x) >> 24) & 0x00ff) /* Company Options */
312 1.6 jonathan
313 1.6 jonathan #ifdef _KERNEL
314 1.6 jonathan /*
315 1.6 jonathan * Global variables used to communicate CPU type, and parameters
316 1.6 jonathan * such as cache size, from locore to higher-level code (e.g., pmap).
317 1.6 jonathan */
318 1.40 cgd
319 1.40 cgd extern mips_prid_t cpu_id;
320 1.40 cgd extern mips_prid_t fpu_id;
321 1.14 jonathan extern int mips_num_tlb_entries;
322 1.52 jeffs
323 1.75 christos void mips_pagecopy(void *dst, void *src);
324 1.75 christos void mips_pagezero(void *dst);
325 1.19 jonathan
326 1.59 simonb #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
327 1.59 simonb void mips_machdep_cache_config(void);
328 1.59 simonb #endif
329 1.59 simonb
330 1.19 jonathan /*
331 1.20 simonb * trapframe argument passed to trap()
332 1.19 jonathan */
333 1.64 thorpej
334 1.70 tsutsui #define TF_AST 0
335 1.70 tsutsui #define TF_V0 1
336 1.70 tsutsui #define TF_V1 2
337 1.70 tsutsui #define TF_A0 3
338 1.70 tsutsui #define TF_A1 4
339 1.70 tsutsui #define TF_A2 5
340 1.70 tsutsui #define TF_A3 6
341 1.70 tsutsui #define TF_T0 7
342 1.70 tsutsui #define TF_T1 8
343 1.70 tsutsui #define TF_T2 9
344 1.70 tsutsui #define TF_T3 10
345 1.64 thorpej
346 1.64 thorpej #if defined(__mips_n32) || defined(__mips_n64)
347 1.70 tsutsui #define TF_A4 11
348 1.70 tsutsui #define TF_A5 12
349 1.70 tsutsui #define TF_A6 13
350 1.70 tsutsui #define TF_A7 14
351 1.64 thorpej #else
352 1.70 tsutsui #define TF_T4 11
353 1.70 tsutsui #define TF_T5 12
354 1.70 tsutsui #define TF_T6 13
355 1.70 tsutsui #define TF_T7 14
356 1.64 thorpej #endif /* __mips_n32 || __mips_n64 */
357 1.64 thorpej
358 1.70 tsutsui #define TF_TA0 11
359 1.70 tsutsui #define TF_TA1 12
360 1.70 tsutsui #define TF_TA2 13
361 1.70 tsutsui #define TF_TA3 14
362 1.70 tsutsui
363 1.70 tsutsui #define TF_T8 15
364 1.70 tsutsui #define TF_T9 16
365 1.70 tsutsui
366 1.70 tsutsui #define TF_RA 17
367 1.70 tsutsui #define TF_SR 18
368 1.70 tsutsui #define TF_MULLO 19
369 1.70 tsutsui #define TF_MULHI 20
370 1.70 tsutsui #define TF_EPC 21 /* may be changed by trap() call */
371 1.65 thorpej
372 1.70 tsutsui #define TF_NREGS 22
373 1.64 thorpej
374 1.19 jonathan struct trapframe {
375 1.64 thorpej mips_reg_t tf_regs[TF_NREGS];
376 1.57 uch u_int32_t tf_ppl; /* previous priority level */
377 1.57 uch int32_t tf_pad; /* for 8 byte aligned */
378 1.19 jonathan };
379 1.19 jonathan
380 1.19 jonathan /*
381 1.19 jonathan * Stack frame for kernel traps. four args passed in registers.
382 1.19 jonathan * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
383 1.19 jonathan * is used to avoid alignment problems
384 1.19 jonathan */
385 1.19 jonathan
386 1.19 jonathan struct kernframe {
387 1.19 jonathan register_t cf_args[4 + 1];
388 1.19 jonathan register_t cf_pad; /* (for 8 word alignment) */
389 1.19 jonathan register_t cf_sp;
390 1.19 jonathan register_t cf_ra;
391 1.19 jonathan struct trapframe cf_frame;
392 1.19 jonathan };
393 1.61 simonb #endif /* _KERNEL */
394 1.1 jonathan #endif /* _MIPS_LOCORE_H */
395