cpu.h revision 210029
1/*	$OpenBSD: cpu.h,v 1.4 1998/09/15 10:50:12 pefo 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 * 4. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 *	Copyright (C) 1989 Digital Equipment Corporation.
35 *	Permission to use, copy, modify, and distribute this software and
36 *	its documentation for any purpose and without fee is hereby granted,
37 *	provided that the above copyright notice appears in all copies.
38 *	Digital Equipment Corporation makes no representations about the
39 *	suitability of this software for any purpose.  It is provided "as is"
40 *	without express or implied warranty.
41 *
42 *	from: @(#)cpu.h	8.4 (Berkeley) 1/4/94
43 *	JNPR: cpu.h,v 1.9.2.2 2007/09/10 08:23:46 girish
44 * $FreeBSD: head/sys/mips/include/cpu.h 210029 2010-07-13 22:36:45Z imp $
45 */
46
47#ifndef _MACHINE_CPU_H_
48#define	_MACHINE_CPU_H_
49
50#include <machine/endian.h>
51
52/*
53 *  Status register.
54 */
55#define	SR_COP_USABILITY	0xf0000000
56#define	SR_COP_0_BIT		0x10000000
57#define	SR_COP_1_BIT		0x20000000
58#define	SR_COP_2_BIT		0x40000000
59#define	SR_RP			0x08000000
60#define	SR_FR_32		0x04000000
61#define	SR_RE			0x02000000
62#define	SR_PX			0x00800000
63#define	SR_BOOT_EXC_VEC		0x00400000
64#define	SR_TLB_SHUTDOWN		0x00200000
65#define	SR_SOFT_RESET		0x00100000
66#define	SR_DIAG_CH		0x00040000
67#define	SR_DIAG_CE		0x00020000
68#define	SR_DIAG_DE		0x00010000
69#define	SR_KX			0x00000080
70#define	SR_SX			0x00000040
71#define	SR_UX			0x00000020
72#define	SR_KSU_MASK		0x00000018
73#define	SR_KSU_USER		0x00000010
74#define	SR_KSU_SUPER		0x00000008
75#define	SR_KSU_KERNEL		0x00000000
76#define	SR_ERL			0x00000004
77#define	SR_EXL			0x00000002
78#define	SR_INT_ENAB		0x00000001
79
80#define	SR_INT_MASK		0x0000ff00
81#define	SOFT_INT_MASK_0		0x00000100
82#define	SOFT_INT_MASK_1		0x00000200
83#define	SR_INT_MASK_0		0x00000400
84#define	SR_INT_MASK_1		0x00000800
85#define	SR_INT_MASK_2		0x00001000
86#define	SR_INT_MASK_3		0x00002000
87#define	SR_INT_MASK_4		0x00004000
88#define	SR_INT_MASK_5		0x00008000
89#define	ALL_INT_MASK		SR_INT_MASK
90#define	SOFT_INT_MASK		(SOFT_INT_MASK_0 | SOFT_INT_MASK_1)
91#define	HW_INT_MASK		(ALL_INT_MASK & ~SOFT_INT_MASK)
92
93#define	soft_int_mask(softintr)	(1 << ((softintr) + 8))
94#define	hard_int_mask(hardintr)	(1 << ((hardintr) + 10))
95
96/*
97 * The bits in the cause register.
98 *
99 *	CR_BR_DELAY	Exception happened in branch delay slot.
100 *	CR_COP_ERR	Coprocessor error.
101 *	CR_IP		Interrupt pending bits defined below.
102 *	CR_EXC_CODE	The exception type (see exception codes below).
103 */
104#define	CR_BR_DELAY		0x80000000
105#define	CR_COP_ERR		0x30000000
106#define	CR_EXC_CODE		0x0000007c
107#define	CR_EXC_CODE_SHIFT	2
108#define	CR_IPEND		0x0000ff00
109
110/*
111 * Cause Register Format:
112 *
113 *   31  30  29 28 27  26  25  24 23                   8  7 6       2  1  0
114 *  ----------------------------------------------------------------------
115 * | BD | 0| CE   | 0| W2| W1| IV|	IP15 - IP0	| 0| Exc Code | 0|
116 * |______________________________________________________________________
117 */
118
119#define	CR_INT_SOFT0		0x00000100
120#define	CR_INT_SOFT1		0x00000200
121#define	CR_INT_0		0x00000400
122#define	CR_INT_1		0x00000800
123#define	CR_INT_2		0x00001000
124#define	CR_INT_3		0x00002000
125#define	CR_INT_4		0x00004000
126#define	CR_INT_5		0x00008000
127
128#define	CR_INT_UART	CR_INT_1
129#define	CR_INT_IPI	CR_INT_2
130#define	CR_INT_CLOCK	CR_INT_5
131
132/*
133 * The bits in the CONFIG register
134 */
135#define CFG_K0_UNCACHED	2
136#define	CFG_K0_CACHED	3
137#define	CFG_K0_MASK	0x7
138
139/*
140 * The bits in the context register.
141 */
142#define	CNTXT_PTE_BASE		0xff800000
143#define	CNTXT_BAD_VPN2		0x007ffff0
144
145/*
146 * Location of exception vectors.
147 */
148#define	RESET_EXC_VEC		((intptr_t)(int32_t)0xbfc00000)
149#define	TLB_MISS_EXC_VEC	((intptr_t)(int32_t)0x80000000)
150#define	XTLB_MISS_EXC_VEC	((intptr_t)(int32_t)0x80000080)
151#define	CACHE_ERR_EXC_VEC	((intptr_t)(int32_t)0x80000100)
152#define	GEN_EXC_VEC		((intptr_t)(int32_t)0x80000180)
153
154/*
155 * Coprocessor 0 registers:
156 */
157#define	COP_0_TLB_INDEX		$0
158#define	COP_0_TLB_RANDOM	$1
159#define	COP_0_TLB_LO0		$2
160#define	COP_0_TLB_LO1		$3
161#define	COP_0_TLB_CONTEXT	$4
162#define	COP_0_TLB_PG_MASK	$5
163#define	COP_0_TLB_WIRED		$6
164#define	COP_0_INFO		$7
165#define	COP_0_BAD_VADDR		$8
166#define	COP_0_COUNT		$9
167#define	COP_0_TLB_HI		$10
168#define	COP_0_COMPARE		$11
169#define	COP_0_STATUS_REG	$12
170#define	COP_0_CAUSE_REG		$13
171#define	COP_0_EXC_PC		$14
172#define	COP_0_PRID		$15
173#define	COP_0_CONFIG		$16
174#define	COP_0_LLADDR		$17
175#define	COP_0_WATCH_LO		$18
176#define	COP_0_WATCH_HI		$19
177#define	COP_0_TLB_XCONTEXT	$20
178#define	COP_0_ECC		$26
179#define	COP_0_CACHE_ERR		$27
180#define	COP_0_TAG_LO		$28
181#define	COP_0_TAG_HI		$29
182#define	COP_0_ERROR_PC		$30
183
184/*
185 *  Coprocessor 0 Set 1
186 */
187#define	C0P_1_IPLLO	$18
188#define	C0P_1_IPLHI	$19
189#define	C0P_1_INTCTL	$20
190#define	C0P_1_DERRADDR0	$26
191#define	C0P_1_DERRADDR1	$27
192
193/*
194 * Values for the code field in a break instruction.
195 */
196#define	BREAK_INSTR		0x0000000d
197#define	BREAK_VAL_MASK		0x03ffffc0
198#define	BREAK_VAL_SHIFT		16
199#define	BREAK_KDB_VAL		512
200#define	BREAK_SSTEP_VAL		513
201#define	BREAK_BRKPT_VAL		514
202#define	BREAK_SOVER_VAL		515
203#define	BREAK_DDB_VAL		516
204#define	BREAK_KDB	(BREAK_INSTR | (BREAK_KDB_VAL << BREAK_VAL_SHIFT))
205#define	BREAK_SSTEP	(BREAK_INSTR | (BREAK_SSTEP_VAL << BREAK_VAL_SHIFT))
206#define	BREAK_BRKPT	(BREAK_INSTR | (BREAK_BRKPT_VAL << BREAK_VAL_SHIFT))
207#define	BREAK_SOVER	(BREAK_INSTR | (BREAK_SOVER_VAL << BREAK_VAL_SHIFT))
208#define	BREAK_DDB	(BREAK_INSTR | (BREAK_DDB_VAL << BREAK_VAL_SHIFT))
209
210/*
211 * Mininum and maximum cache sizes.
212 */
213#define	MIN_CACHE_SIZE		(16 * 1024)
214#define	MAX_CACHE_SIZE		(256 * 1024)
215
216/*
217 * The floating point version and status registers.
218 */
219#define	FPC_ID			$0
220#define	FPC_CSR			$31
221
222/*
223 * The floating point coprocessor status register bits.
224 */
225#define	FPC_ROUNDING_BITS		0x00000003
226#define	FPC_ROUND_RN			0x00000000
227#define	FPC_ROUND_RZ			0x00000001
228#define	FPC_ROUND_RP			0x00000002
229#define	FPC_ROUND_RM			0x00000003
230#define	FPC_STICKY_BITS			0x0000007c
231#define	FPC_STICKY_INEXACT		0x00000004
232#define	FPC_STICKY_UNDERFLOW		0x00000008
233#define	FPC_STICKY_OVERFLOW		0x00000010
234#define	FPC_STICKY_DIV0			0x00000020
235#define	FPC_STICKY_INVALID		0x00000040
236#define	FPC_ENABLE_BITS			0x00000f80
237#define	FPC_ENABLE_INEXACT		0x00000080
238#define	FPC_ENABLE_UNDERFLOW		0x00000100
239#define	FPC_ENABLE_OVERFLOW		0x00000200
240#define	FPC_ENABLE_DIV0			0x00000400
241#define	FPC_ENABLE_INVALID		0x00000800
242#define	FPC_EXCEPTION_BITS		0x0003f000
243#define	FPC_EXCEPTION_INEXACT		0x00001000
244#define	FPC_EXCEPTION_UNDERFLOW		0x00002000
245#define	FPC_EXCEPTION_OVERFLOW		0x00004000
246#define	FPC_EXCEPTION_DIV0		0x00008000
247#define	FPC_EXCEPTION_INVALID		0x00010000
248#define	FPC_EXCEPTION_UNIMPL		0x00020000
249#define	FPC_COND_BIT			0x00800000
250#define	FPC_FLUSH_BIT			0x01000000
251#define	FPC_MBZ_BITS			0xfe7c0000
252
253/*
254 * Constants to determine if have a floating point instruction.
255 */
256#define	OPCODE_SHIFT		26
257#define	OPCODE_C1		0x11
258
259/*
260 * The first TLB entry that write random hits.
261 * TLB entry 0 maps the kernel stack of the currently running thread
262 * TLB entry 1 maps the pcpu area of processor (only for SMP builds)
263 */
264#define	KSTACK_TLB_ENTRY	0
265#ifdef SMP
266#define	PCPU_TLB_ENTRY		1
267#define	VMWIRED_ENTRIES		2
268#else
269#define	VMWIRED_ENTRIES		1
270#endif	/* SMP */
271
272/*
273 * The number of process id entries.
274 */
275#define	VMNUM_PIDS		256
276
277/*
278 * Exported definitions unique to mips cpu support.
279 */
280
281#define	cpu_swapout(p)		panic("cpu_swapout: can't get here");
282
283#ifndef _LOCORE
284#include <machine/cpufunc.h>
285#include <machine/frame.h>
286
287/*
288 * Arguments to hardclock and gatherstats encapsulate the previous
289 * machine state in an opaque clockframe.
290 */
291#define	clockframe trapframe	/* Use normal trap frame */
292
293#define	CLKF_USERMODE(framep)	((framep)->sr & SR_KSU_USER)
294#define	CLKF_PC(framep)		((framep)->pc)
295#define	CLKF_INTR(framep)	(0)
296#define	MIPS_CLKF_INTR()	(intr_nesting_level >= 1)
297#define	TRAPF_USERMODE(framep)  (((framep)->sr & SR_KSU_USER) != 0)
298#define	TRAPF_PC(framep)	((framep)->pc)
299#define	cpu_getstack(td)	((td)->td_frame->sp)
300
301/*
302 * A machine-independent interface to the CPU's counter.
303 */
304#define	get_cyclecount()	mips_rd_count()
305
306#endif				/* !_LOCORE */
307
308/*
309 * CTL_MACHDEP definitions.
310 */
311#define	CPU_CONSDEV		1	/* dev_t: console terminal device */
312#define	CPU_ADJKERNTZ		2	/* int: timezone offset (seconds) */
313#define	CPU_DISRTCSET		3	/* int: disable resettodr() call */
314#define	CPU_BOOTINFO		4	/* struct: bootinfo */
315#define	CPU_WALLCLOCK		5	/* int: indicates wall CMOS clock */
316#define	CPU_MAXID		6	/* number of valid machdep ids */
317
318#define	CTL_MACHDEP_NAMES {			\
319	{ 0, 0 },				\
320	{ "console_device", CTLTYPE_STRUCT },	\
321	{ "adjkerntz", CTLTYPE_INT },		\
322	{ "disable_rtc_set", CTLTYPE_INT },	\
323	{ "bootinfo", CTLTYPE_STRUCT },		\
324	{ "wall_cmos_clock", CTLTYPE_INT },	\
325}
326
327/*
328 * MIPS CPU types (cp_imp).
329 */
330#define	MIPS_R2000	0x01	/* MIPS R2000 CPU		ISA I	 */
331#define	MIPS_R3000	0x02	/* MIPS R3000 CPU		ISA I	 */
332#define	MIPS_R6000	0x03	/* MIPS R6000 CPU		ISA II	 */
333#define	MIPS_R4000	0x04	/* MIPS R4000/4400 CPU		ISA III	 */
334#define	MIPS_R3LSI	0x05	/* LSI Logic R3000 derivate	ISA I	 */
335#define	MIPS_R6000A	0x06	/* MIPS R6000A CPU		ISA II	 */
336#define	MIPS_R3IDT	0x07	/* IDT R3000 derivate		ISA I	 */
337#define	MIPS_R10000	0x09	/* MIPS R10000/T5 CPU		ISA IV	 */
338#define	MIPS_R4200	0x0a	/* MIPS R4200 CPU (ICE)		ISA III	 */
339#define	MIPS_R4300	0x0b	/* NEC VR4300 CPU		ISA III	 */
340#define	MIPS_R4100	0x0c	/* NEC VR41xx CPU MIPS-16	ISA III	 */
341#define	MIPS_R8000	0x10	/* MIPS R8000 Blackbird/TFP	ISA IV	 */
342#define	MIPS_R4600	0x20	/* QED R4600 Orion		ISA III	 */
343#define	MIPS_R4700	0x21	/* QED R4700 Orion		ISA III	 */
344#define	MIPS_R3TOSH	0x22	/* Toshiba R3000 based CPU	ISA I	 */
345#define	MIPS_R5000	0x23	/* MIPS R5000 CPU		ISA IV	 */
346#define	MIPS_RM7000	0x27	/* QED RM7000 CPU		ISA IV	 */
347#define	MIPS_RM52X0	0x28	/* QED RM52X0 CPU		ISA IV	 */
348#define	MIPS_VR5400	0x54	/* NEC Vr5400 CPU		ISA IV+	 */
349#define	MIPS_RM9000	0x34	/* E9000 CPU				 */
350
351/*
352 * MIPS FPU types
353 */
354#define	MIPS_SOFT	0x00	/* Software emulation		ISA I	 */
355#define	MIPS_R2360	0x01	/* MIPS R2360 FPC		ISA I	 */
356#define	MIPS_R2010	0x02	/* MIPS R2010 FPC		ISA I	 */
357#define	MIPS_R3010	0x03	/* MIPS R3010 FPC		ISA I	 */
358#define	MIPS_R6010	0x04	/* MIPS R6010 FPC		ISA II	 */
359#define	MIPS_R4010	0x05	/* MIPS R4000/R4400 FPC		ISA II	 */
360#define	MIPS_R31LSI	0x06	/* LSI Logic derivate		ISA I	 */
361#define	MIPS_R10010	0x09	/* MIPS R10000/T5 FPU		ISA IV	 */
362#define	MIPS_R4210	0x0a	/* MIPS R4200 FPC (ICE)		ISA III	 */
363#define	MIPS_UNKF1	0x0b	/* unnanounced product cpu	ISA III	 */
364#define	MIPS_R8000	0x10	/* MIPS R8000 Blackbird/TFP	ISA IV	 */
365#define	MIPS_R4600	0x20	/* QED R4600 Orion		ISA III	 */
366#define	MIPS_R3SONY	0x21	/* Sony R3000 based FPU		ISA I	 */
367#define	MIPS_R3TOSH	0x22	/* Toshiba R3000 based FPU	ISA I	 */
368#define	MIPS_R5010	0x23	/* MIPS R5000 based FPU		ISA IV	 */
369#define	MIPS_RM7000	0x27	/* QED RM7000 FPU		ISA IV	 */
370#define	MIPS_RM5230	0x28	/* QED RM52X0 based FPU		ISA IV	 */
371#define	MIPS_RM52XX	0x28	/* QED RM52X0 based FPU		ISA IV	 */
372#define	MIPS_VR5400	0x54	/* NEC Vr5400 FPU		ISA IV+	 */
373
374#if defined(_KERNEL) && !defined(_LOCORE)
375
376struct user;
377
378int Mips_ConfigCache(void);
379
380void Mips_SyncCache(void);
381void Mips_SyncDCache(vm_offset_t, int);
382void Mips_HitSyncDCache(vm_offset_t, int);
383void Mips_HitSyncSCache(vm_offset_t, int);
384void Mips_IOSyncDCache(vm_offset_t, int, int);
385void Mips_HitInvalidateDCache(vm_offset_t, int);
386void Mips_SyncICache(vm_offset_t, int);
387void Mips_InvalidateICache(vm_offset_t, int);
388
389void wbflush(void);
390
391extern u_int32_t cpu_counter_interval;	/* Number of counter ticks/tick */
392extern u_int32_t cpu_counter_last;	/* Last compare value loaded    */
393extern int num_tlbentries;
394extern char btext[];
395extern char etext[];
396extern int intr_nesting_level;
397
398#define	func_0args_asmmacro(func, in)					\
399	__asm __volatile ( "jalr %0"					\
400			: "=r" (in)	/* outputs */			\
401			: "r" (func)	/* inputs */			\
402			: "$31", "$4");
403
404#define	func_1args_asmmacro(func, arg0)					\
405	__asm __volatile ("move $4, %1;"				\
406			"jalr %0"					\
407			:				/* outputs */	\
408			: "r" (func), "r" (arg0)	/* inputs */	\
409			: "$31", "$4");
410
411#define	func_2args_asmmacro(func, arg0, arg1)				\
412	__asm __volatile ("move $4, %1;"				\
413			"move $5, %2;"					\
414			"jalr %0"					\
415			:				/* outputs */   \
416			: "r" (func), "r" (arg0), "r" (arg1) /* inputs */ \
417			: "$31", "$4", "$5");
418
419#define	func_3args_asmmacro(func, arg0, arg1, arg2)			\
420	__asm __volatile ( "move $4, %1;"				\
421			"move $5, %2;"					\
422			"move $6, %3;"					\
423			"jalr %0"					\
424			:				/* outputs */	\
425			: "r" (func), "r" (arg0), "r" (arg1), "r" (arg2)  /* inputs */ \
426			: "$31", "$4", "$5", "$6");
427
428/*
429 * Enable realtime clock (always enabled).
430 */
431#define	enablertclock()
432
433/*
434 * Are we in an interrupt handler? required by JunOS
435 */
436#define	IN_INT_HANDLER()				\
437	(curthread->td_intr_nesting_level != 0 ||	\
438	(curthread->td_pflags & TDP_ITHREAD))
439
440/*
441 *  Low level access routines to CPU registers
442 */
443
444void swi_vm(void *);
445void cpu_halt(void);
446void cpu_reset(void);
447
448u_int32_t set_intr_mask(u_int32_t);
449u_int32_t get_intr_mask(void);
450
451#define	cpu_spinwait()		/* nothing */
452
453#endif				/* _KERNEL */
454#endif				/* !_MACHINE_CPU_H_ */
455