1 /* $NetBSD: locore.h,v 1.79 2009/05/30 18:26:06 martin Exp $ */
4 * Copyright 1996 The Board of Trustees of The Leland Stanford
5 * Junior University. All Rights Reserved.
7 * Permission to use, copy, modify, and distribute this
8 * software and its documentation for any purpose and without
9 * fee is hereby granted, provided that the above copyright
10 * notice appear in all copies. Stanford University
11 * makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without
13 * express or implied warranty.
17 * Jump table for MIPS CPU locore functions that are implemented
18 * differently on different generations, or instruction-level
19 * archtecture (ISA) level, the Mips family.
21 * We currently provide support for MIPS I and MIPS III.
24 #ifndef _MIPS_LOCORE_H
25 #define _MIPS_LOCORE_H
28 #include "opt_cputype.h"
31 #include <mips/cpuregs.h>
35 uint32_t mips_cp0_cause_read(void);
36 void mips_cp0_cause_write(uint32_t);
37 uint32_t mips_cp0_status_read(void);
38 void mips_cp0_status_write(uint32_t);
45 void _setsoftintr(int);
46 void _clrsoftintr(int);
49 void mips1_SetPID(int);
51 void mips1_TBIAP(int);
52 void mips1_TBIS(vaddr_t
);
53 int mips1_TLBUpdate(vaddr_t
, uint32_t);
54 void mips1_wbflush(void);
55 void mips1_lwp_trampoline(void);
56 void mips1_setfunc_trampoline(void);
57 void mips1_cpu_switch_resume(void);
59 uint32_t tx3900_cp0_config_read(void);
62 #if defined(MIPS3) || defined(MIPS4)
63 void mips3_SetPID(int);
65 void mips3_TBIAP(int);
66 void mips3_TBIS(vaddr_t
);
67 int mips3_TLBUpdate(vaddr_t
, uint32_t);
68 void mips3_TLBRead(int, struct tlb
*);
69 void mips3_TLBWriteIndexedVPS(int, struct tlb
*);
70 void mips3_wbflush(void);
71 void mips3_lwp_trampoline(void);
72 void mips3_setfunc_trampoline(void);
73 void mips3_cpu_switch_resume(void);
74 void mips3_pagezero(void *dst
);
77 void mips5900_SetPID(int);
78 void mips5900_TBIA(int);
79 void mips5900_TBIAP(int);
80 void mips5900_TBIS(vaddr_t
);
81 int mips5900_TLBUpdate(vaddr_t
, uint32_t);
82 void mips5900_TLBRead(int, struct tlb
*);
83 void mips5900_TLBWriteIndexedVPS(int, struct tlb
*);
84 void mips5900_wbflush(void);
85 void mips5900_lwp_trampoline(void);
86 void mips5900_setfunc_trampoline(void);
87 void mips5900_cpu_switch_resume(void);
88 void mips5900_pagezero(void *dst
);
93 void mips32_SetPID(int);
94 void mips32_TBIA(int);
95 void mips32_TBIAP(int);
96 void mips32_TBIS(vaddr_t
);
97 int mips32_TLBUpdate(vaddr_t
, uint32_t);
98 void mips32_TLBRead(int, struct tlb
*);
99 void mips32_TLBWriteIndexedVPS(int, struct tlb
*);
100 void mips32_wbflush(void);
101 void mips32_lwp_trampoline(void);
102 void mips32_setfunc_trampoline(void);
103 void mips32_cpu_switch_resume(void);
107 void mips64_SetPID(int);
108 void mips64_TBIA(int);
109 void mips64_TBIAP(int);
110 void mips64_TBIS(vaddr_t
);
111 int mips64_TLBUpdate(vaddr_t
, uint32_t);
112 void mips64_TLBRead(int, struct tlb
*);
113 void mips64_TLBWriteIndexedVPS(int, struct tlb
*);
114 void mips64_wbflush(void);
115 void mips64_lwp_trampoline(void);
116 void mips64_setfunc_trampoline(void);
117 void mips64_cpu_switch_resume(void);
118 void mips64_pagezero(void *dst
);
121 #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
122 uint32_t mips3_cp0_compare_read(void);
123 void mips3_cp0_compare_write(uint32_t);
125 uint32_t mips3_cp0_config_read(void);
126 void mips3_cp0_config_write(uint32_t);
127 #if defined(MIPS32) || defined(MIPS64)
128 uint32_t mipsNN_cp0_config1_read(void);
129 void mipsNN_cp0_config1_write(uint32_t);
130 uint32_t mipsNN_cp0_config2_read(void);
131 uint32_t mipsNN_cp0_config3_read(void);
134 uint32_t mips3_cp0_count_read(void);
135 void mips3_cp0_count_write(uint32_t);
137 uint32_t mips3_cp0_wired_read(void);
138 void mips3_cp0_wired_write(uint32_t);
139 void mips3_cp0_pg_mask_write(uint32_t);
141 #if defined(__GNUC__) && !defined(__mips_o32)
142 static inline uint64_t
143 mips3_ld(const volatile uint64_t *va
)
146 #if defined(__mips_o32)
149 sr
= mips_cp0_status_read();
150 mips_cp0_status_write(sr
& ~MIPS_SR_INT_IE
);
155 ".set noreorder \n\t"
158 "dsll32 %L0,%M0,0 \n\t"
159 "dsra32 %M0,%M0,0 \n\t" /* high word */
160 "dsra32 %L0,%L0,0 \n\t" /* low word */
166 mips_cp0_status_write(sr
);
170 __asm
volatile("ld %0,0(%1)" : "=d"(rv
) : "r"(va
));
176 mips3_sd(volatile uint64_t *va
, uint64_t v
)
178 #if defined(__mips_o32)
181 sr
= mips_cp0_status_read();
182 mips_cp0_status_write(sr
& ~MIPS_SR_INT_IE
);
187 ".set noreorder \n\t"
189 "dsll32 %M0,%M0,0 \n\t"
190 "dsll32 %L0,%L0,0 \n\t"
191 "dsrl32 %L0,%L0,0 \n\t"
195 : "=d"(v
) : "0"(v
), "r"(va
));
197 mips_cp0_status_write(sr
);
201 __asm
volatile("sd %0,0(%1)" :: "r"(v
), "r"(va
));
205 uint64_t mips3_ld(volatile uint64_t *va
);
206 void mips3_sd(volatile uint64_t *, uint64_t);
207 #endif /* __GNUC__ */
208 #endif /* MIPS3 || MIPS4 || MIPS32 || MIPS64 */
210 #if defined(MIPS3) || defined(MIPS4) || defined(MIPS64)
211 static __inline
uint32_t mips3_lw_a64(uint64_t addr
)
212 __attribute__((__unused__
));
213 static __inline
void mips3_sw_a64(uint64_t addr
, uint32_t val
)
214 __attribute__ ((__unused__
));
216 static __inline
uint32_t
217 mips3_lw_a64(uint64_t addr
)
220 #if defined(__mips_o32)
223 sr
= mips_cp0_status_read();
224 mips_cp0_status_write((sr
& ~MIPS_SR_INT_IE
) | MIPS3_SR_KX
);
229 ".set noreorder \n\t"
231 "dsll32 %M1,%M1,0 \n\t"
232 "dsll32 %L1,%L1,0 \n\t"
233 "dsrl32 $L1,%L1,0 \n\t"
237 : "=r"(rv
), "=d"(addr
)
241 mips_cp0_status_write(sr
);
243 rv
= *(const uint32_t *)addr
;
245 __asm
volatile("lw %0, 0(%1)" : "=r"(rv
) : "d"(addr
));
251 mips3_sw_a64(uint64_t addr
, uint32_t val
)
253 #if defined(__mips_o32)
256 sr
= mips_cp0_status_read();
257 mips_cp0_status_write((sr
& ~MIPS_SR_INT_IE
) | MIPS3_SR_KX
);
262 ".set noreorder \n\t"
264 "dsll32 %M0,%M0,0 \n\t"
265 "dsll32 %L0,%L0,0 \n\t"
266 "dsrl32 $L0,%L0,0 \n\t"
270 : "=d"(addr
): "r"(val
), "0"(addr
)
273 mips_cp0_status_write(sr
);
275 *(uint32_t *)addr
= val
;
277 __asm
volatile("sw %1, 0(%0)" :: "d"(addr
), "r"(val
));
280 #endif /* MIPS3 || MIPS4 || MIPS64 */
283 * A vector with an entry for each mips-ISA-level dependent
284 * locore function, and macros which jump through it.
286 * XXX the macro names are chosen to be compatible with the old
287 * XXX Sprite coding-convention names used in 4.4bsd/pmax.
290 void (*setTLBpid
)(int pid
);
292 void (*TBIS
)(vaddr_t
);
293 int (*tlbUpdate
)(vaddr_t
, uint32_t);
294 void (*wbflush
)(void);
295 } mips_locore_jumpvec_t
;
297 void mips_set_wbflush(void (*)(void));
298 void mips_wait_idle(void);
300 void stacktrace(void);
301 void logstacktrace(void);
304 uintptr_t lsw_cpu_switch_resume
;
305 uintptr_t lsw_lwp_trampoline
;
306 void (*lsw_cpu_idle
)(void);
307 uintptr_t lsw_setfunc_trampoline
;
311 * The "active" locore-fuction vector, and
313 extern mips_locore_jumpvec_t mips_locore_jumpvec
;
314 extern struct locoresw mips_locoresw
;
316 #if defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64)
317 #define MachSetPID mips1_SetPID
318 #define MIPS_TBIAP() mips1_TBIAP(mips_num_tlb_entries)
319 #define MIPS_TBIS mips1_TBIS
320 #define MachTLBUpdate mips1_TLBUpdate
321 #define wbflush() mips1_wbflush()
322 #define lwp_trampoline mips1_lwp_trampoline
323 #define setfunc_trampoline mips1_setfunc_trampoline
324 #elif !defined(MIPS1) && defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && !defined(MIPS3_5900)
325 #define MachSetPID mips3_SetPID
326 #define MIPS_TBIAP() mips3_TBIAP(mips_num_tlb_entries)
327 #define MIPS_TBIS mips3_TBIS
328 #define MachTLBUpdate mips3_TLBUpdate
329 #define MachTLBWriteIndexedVPS mips3_TLBWriteIndexedVPS
330 #define lwp_trampoline mips3_lwp_trampoline
331 #define setfunc_trampoline mips3_setfunc_trampoline
332 #define wbflush() mips3_wbflush()
333 #elif !defined(MIPS1) && !defined(MIPS3) && defined(MIPS32) && !defined(MIPS64)
334 #define MachSetPID mips32_SetPID
335 #define MIPS_TBIAP() mips32_TBIAP(mips_num_tlb_entries)
336 #define MIPS_TBIS mips32_TBIS
337 #define MachTLBUpdate mips32_TLBUpdate
338 #define MachTLBWriteIndexedVPS mips32_TLBWriteIndexedVPS
339 #define lwp_trampoline mips32_lwp_trampoline
340 #define setfunc_trampoline mips32_setfunc_trampoline
341 #define wbflush() mips32_wbflush()
342 #elif !defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) && defined(MIPS64)
343 /* all common with mips3 */
344 #define MachSetPID mips64_SetPID
345 #define MIPS_TBIAP() mips64_TBIAP(mips_num_tlb_entries)
346 #define MIPS_TBIS mips64_TBIS
347 #define MachTLBUpdate mips64_TLBUpdate
348 #define MachTLBWriteIndexedVPS mips64_TLBWriteIndexedVPS
349 #define lwp_trampoline mips64_lwp_trampoline
350 #define setfunc_trampoline mips64_setfunc_trampoline
351 #define wbflush() mips64_wbflush()
352 #elif !defined(MIPS1) && defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && defined(MIPS3_5900)
353 #define MachSetPID mips5900_SetPID
354 #define MIPS_TBIAP() mips5900_TBIAP(mips_num_tlb_entries)
355 #define MIPS_TBIS mips5900_TBIS
356 #define MachTLBUpdate mips5900_TLBUpdate
357 #define MachTLBWriteIndexedVPS mips5900_TLBWriteIndexedVPS
358 #define lwp_trampoline mips5900_lwp_trampoline
359 #define setfunc_trampoline mips5900_setfunc_trampoline
360 #define wbflush() mips5900_wbflush()
362 #define MachSetPID (*(mips_locore_jumpvec.setTLBpid))
363 #define MIPS_TBIAP() (*(mips_locore_jumpvec.TBIAP))(mips_num_tlb_entries)
364 #define MIPS_TBIS (*(mips_locore_jumpvec.TBIS))
365 #define MachTLBUpdate (*(mips_locore_jumpvec.tlbUpdate))
366 #define wbflush() (*(mips_locore_jumpvec.wbflush))()
367 #define lwp_trampoline mips_locoresw.lsw_lwp_trampoline
368 #define setfunc_trampoline mips_locoresw.lsw_setfunc_trampoline
371 #define CPU_IDLE mips_locoresw.lsw_cpu_idle
373 /* cpu_switch_resume is called inside locore.S */
376 * CPU identification, from PRID register.
378 typedef int mips_prid_t
;
380 #define MIPS_PRID_REV(x) (((x) >> 0) & 0x00ff)
381 #define MIPS_PRID_IMPL(x) (((x) >> 8) & 0x00ff)
384 #define MIPS_PRID_RSVD(x) (((x) >> 16) & 0xffff)
385 #define MIPS_PRID_REV_MIN(x) ((MIPS_PRID_REV(x) >> 0) & 0x0f)
386 #define MIPS_PRID_REV_MAJ(x) ((MIPS_PRID_REV(x) >> 4) & 0x0f)
389 #define MIPS_PRID_CID(x) (((x) >> 16) & 0x00ff) /* Company ID */
390 #define MIPS_PRID_CID_PREHISTORIC 0x00 /* Not MIPS32/64 */
391 #define MIPS_PRID_CID_MTI 0x01 /* MIPS Technologies, Inc. */
392 #define MIPS_PRID_CID_BROADCOM 0x02 /* Broadcom */
393 #define MIPS_PRID_CID_ALCHEMY 0x03 /* Alchemy Semiconductor */
394 #define MIPS_PRID_CID_SIBYTE 0x04 /* SiByte */
395 #define MIPS_PRID_CID_SANDCRAFT 0x05 /* SandCraft */
396 #define MIPS_PRID_CID_PHILIPS 0x06 /* Philips */
397 #define MIPS_PRID_CID_TOSHIBA 0x07 /* Toshiba */
398 #define MIPS_PRID_CID_LSI 0x08 /* LSI */
399 /* 0x09 unannounced */
400 /* 0x0a unannounced */
401 #define MIPS_PRID_CID_LEXRA 0x0b /* Lexra */
402 #define MIPS_PRID_CID_RMI 0x0c /* RMI / NetLogic */
403 #define MIPS_PRID_COPTS(x) (((x) >> 24) & 0x00ff) /* Company Options */
407 * Global variables used to communicate CPU type, and parameters
408 * such as cache size, from locore to higher-level code (e.g., pmap).
411 extern mips_prid_t cpu_id
;
412 extern mips_prid_t fpu_id
;
413 extern int mips_num_tlb_entries
;
415 void mips_pagecopy(void *dst
, void *src
);
416 void mips_pagezero(void *dst
);
418 #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
419 void mips_machdep_cache_config(void);
423 * trapframe argument passed to trap()
438 #if defined(__mips_n32) || defined(__mips_n64)
448 #endif /* __mips_n32 || __mips_n64 */
462 #define TF_EPC 21 /* may be changed by trap() call */
467 mips_reg_t tf_regs
[TF_NREGS
];
468 uint32_t tf_ppl
; /* previous priority level */
469 mips_reg_t tf_pad
; /* for 8 byte aligned */
473 * Stack frame for kernel traps. four args passed in registers.
474 * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
475 * is used to avoid alignment problems
479 #if defined(__mips_o32) || defined(__mips_o64)
480 register_t cf_args
[4 + 1];
481 #if defined(__mips_o32)
482 register_t cf_pad
; /* (for 8 word alignment) */
485 #if defined(__mips_n32) || defined(__mips_n64)
486 register_t cf_pad
[2]; /* for 16 byte alignment */
490 struct trapframe cf_frame
;
493 #endif /* _MIPS_LOCORE_H */