cpu.h revision 203180
1178172Simp/*	$OpenBSD: cpu.h,v 1.4 1998/09/15 10:50:12 pefo Exp $	*/
2178172Simp
3178172Simp/*-
4178172Simp * Copyright (c) 1992, 1993
5178172Simp *	The Regents of the University of California.  All rights reserved.
6178172Simp *
7178172Simp * This code is derived from software contributed to Berkeley by
8178172Simp * Ralph Campbell and Rick Macklem.
9178172Simp *
10178172Simp * Redistribution and use in source and binary forms, with or without
11178172Simp * modification, are permitted provided that the following conditions
12178172Simp * are met:
13178172Simp * 1. Redistributions of source code must retain the above copyright
14178172Simp *    notice, this list of conditions and the following disclaimer.
15178172Simp * 2. Redistributions in binary form must reproduce the above copyright
16178172Simp *    notice, this list of conditions and the following disclaimer in the
17178172Simp *    documentation and/or other materials provided with the distribution.
18178172Simp * 4. Neither the name of the University nor the names of its contributors
19178172Simp *    may be used to endorse or promote products derived from this software
20178172Simp *    without specific prior written permission.
21178172Simp *
22178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32178172Simp * SUCH DAMAGE.
33178172Simp *
34178172Simp *	Copyright (C) 1989 Digital Equipment Corporation.
35178172Simp *	Permission to use, copy, modify, and distribute this software and
36178172Simp *	its documentation for any purpose and without fee is hereby granted,
37178172Simp *	provided that the above copyright notice appears in all copies.
38178172Simp *	Digital Equipment Corporation makes no representations about the
39178172Simp *	suitability of this software for any purpose.  It is provided "as is"
40178172Simp *	without express or implied warranty.
41178172Simp *
42178172Simp *	from: @(#)cpu.h	8.4 (Berkeley) 1/4/94
43178172Simp *	JNPR: cpu.h,v 1.9.2.2 2007/09/10 08:23:46 girish
44178172Simp * $FreeBSD: head/sys/mips/include/cpu.h 203180 2010-01-30 01:54:29Z neel $
45178172Simp */
46178172Simp
47178172Simp#ifndef _MACHINE_CPU_H_
48178172Simp#define	_MACHINE_CPU_H_
49178172Simp
50178172Simp#include <machine/psl.h>
51178172Simp#include <machine/endian.h>
52178172Simp
53178172Simp#define	MIPS_CACHED_MEMORY_ADDR		0x80000000
54178172Simp#define	MIPS_UNCACHED_MEMORY_ADDR	0xa0000000
55178172Simp#define	MIPS_MAX_MEM_ADDR		0xbe000000
56178172Simp#define	MIPS_RESERVED_ADDR		0xbfc80000
57178172Simp
58178172Simp#define MIPS_KSEG0_LARGEST_PHYS         0x20000000
59202031Simp#define	MIPS_CACHED_TO_PHYS(x)		((uintptr_t)(x) & 0x1fffffff)
60202031Simp#define	MIPS_PHYS_TO_CACHED(x)		((uintptr_t)(x) | MIPS_CACHED_MEMORY_ADDR)
61202031Simp#define	MIPS_UNCACHED_TO_PHYS(x)	((uintptr_t)(x) & 0x1fffffff)
62202031Simp#define	MIPS_PHYS_TO_UNCACHED(x)	((uintptr_t)(x) | MIPS_UNCACHED_MEMORY_ADDR)
63178172Simp
64178172Simp#define	MIPS_PHYS_MASK			(0x1fffffff)
65178172Simp#define	MIPS_PA_2_K1VA(x)		(MIPS_KSEG1_START | ((x) & MIPS_PHYS_MASK))
66178172Simp
67202031Simp#define	MIPS_VA_TO_CINDEX(x)		((uintptr_t)(x) & 0xffffff | MIPS_CACHED_MEMORY_ADDR)
68178172Simp#define	MIPS_CACHED_TO_UNCACHED(x)	(MIPS_PHYS_TO_UNCACHED(MIPS_CACHED_TO_PHYS(x)))
69178172Simp
70202031Simp#define	MIPS_PHYS_TO_KSEG0(x)		((uintptr_t)(x) | MIPS_KSEG0_START)
71202031Simp#define	MIPS_PHYS_TO_KSEG1(x)		((uintptr_t)(x) | MIPS_KSEG1_START)
72202031Simp#define	MIPS_KSEG0_TO_PHYS(x)		((uintptr_t)(x) & MIPS_PHYS_MASK)
73202031Simp#define	MIPS_KSEG1_TO_PHYS(x)		((uintptr_t)(x) & MIPS_PHYS_MASK)
74178172Simp
75202031Simp#define	MIPS_IS_KSEG0_ADDR(x)					\
76202031Simp	(((vm_offset_t)(x) >= MIPS_KSEG0_START) &&		\
77202031Simp	    ((vm_offset_t)(x) <= MIPS_KSEG0_END))
78202031Simp#define	MIPS_IS_KSEG1_ADDR(x)					\
79202031Simp	(((vm_offset_t)(x) >= MIPS_KSEG1_START) &&		\
80202031Simp	    ((vm_offset_t)(x) <= MIPS_KSEG1_END))
81202031Simp#define	MIPS_IS_VALID_PTR(x)		(MIPS_IS_KSEG0_ADDR(x) || \
82202031Simp						MIPS_IS_KSEG1_ADDR(x))
83202031Simp
84178172Simp/*
85178172Simp *  Status register.
86178172Simp */
87178172Simp#define	SR_COP_USABILITY	0xf0000000
88178172Simp#define	SR_COP_0_BIT		0x10000000
89178172Simp#define	SR_COP_1_BIT		0x20000000
90178172Simp#define	SR_COP_2_BIT		0x40000000
91178172Simp#define	SR_RP			0x08000000
92178172Simp#define	SR_FR_32		0x04000000
93178172Simp#define	SR_RE			0x02000000
94178172Simp#define	SR_PX			0x00800000
95178172Simp#define	SR_BOOT_EXC_VEC		0x00400000
96178172Simp#define	SR_TLB_SHUTDOWN		0x00200000
97178172Simp#define	SR_SOFT_RESET		0x00100000
98178172Simp#define	SR_DIAG_CH		0x00040000
99178172Simp#define	SR_DIAG_CE		0x00020000
100178172Simp#define	SR_DIAG_DE		0x00010000
101178172Simp#define	SR_KX			0x00000080
102178172Simp#define	SR_SX			0x00000040
103178172Simp#define	SR_UX			0x00000020
104178172Simp#define	SR_KSU_MASK		0x00000018
105178172Simp#define	SR_KSU_USER		0x00000010
106178172Simp#define	SR_KSU_SUPER		0x00000008
107178172Simp#define	SR_KSU_KERNEL		0x00000000
108178172Simp#define	SR_ERL			0x00000004
109178172Simp#define	SR_EXL			0x00000002
110178172Simp#define	SR_INT_ENAB		0x00000001
111178172Simp
112178172Simp#define	SR_INT_MASK		0x0000ff00
113178172Simp#define	SOFT_INT_MASK_0		0x00000100
114178172Simp#define	SOFT_INT_MASK_1		0x00000200
115178172Simp#define	SR_INT_MASK_0		0x00000400
116178172Simp#define	SR_INT_MASK_1		0x00000800
117178172Simp#define	SR_INT_MASK_2		0x00001000
118178172Simp#define	SR_INT_MASK_3		0x00002000
119178172Simp#define	SR_INT_MASK_4		0x00004000
120178172Simp#define	SR_INT_MASK_5		0x00008000
121178172Simp#define	ALL_INT_MASK		SR_INT_MASK
122178172Simp#define	SOFT_INT_MASK		(SOFT_INT_MASK_0 | SOFT_INT_MASK_1)
123178172Simp#define	HW_INT_MASK		(ALL_INT_MASK & ~SOFT_INT_MASK)
124178172Simp
125178172Simp
126178172Simp/*
127178172Simp * The bits in the cause register.
128178172Simp *
129178172Simp *	CR_BR_DELAY	Exception happened in branch delay slot.
130178172Simp *	CR_COP_ERR	Coprocessor error.
131178172Simp *	CR_IP		Interrupt pending bits defined below.
132178172Simp *	CR_EXC_CODE	The exception type (see exception codes below).
133178172Simp */
134178172Simp#define	CR_BR_DELAY		0x80000000
135178172Simp#define	CR_COP_ERR		0x30000000
136178172Simp#define	CR_EXC_CODE		0x0000007c
137178172Simp#define	CR_EXC_CODE_SHIFT	2
138178172Simp#define	CR_IPEND		0x0000ff00
139178172Simp
140178172Simp/*
141178172Simp * Cause Register Format:
142178172Simp *
143178172Simp *   31  30  29 28 27  26  25  24 23                   8  7 6       2  1  0
144178172Simp *  ----------------------------------------------------------------------
145178172Simp * | BD | 0| CE   | 0| W2| W1| IV|	IP15 - IP0	| 0| Exc Code | 0|
146178172Simp * |______________________________________________________________________
147178172Simp */
148178172Simp
149178172Simp#define	CR_INT_SOFT0		0x00000100
150178172Simp#define	CR_INT_SOFT1		0x00000200
151178172Simp#define	CR_INT_0		0x00000400
152178172Simp#define	CR_INT_1		0x00000800
153178172Simp#define	CR_INT_2		0x00001000
154178172Simp#define	CR_INT_3		0x00002000
155178172Simp#define	CR_INT_4		0x00004000
156178172Simp#define	CR_INT_5		0x00008000
157178172Simp
158178172Simp#define	CR_INT_UART	CR_INT_1
159178172Simp#define	CR_INT_IPI	CR_INT_2
160178172Simp#define	CR_INT_CLOCK	CR_INT_5
161178172Simp
162178172Simp/*
163178172Simp * The bits in the CONFIG register
164178172Simp */
165178172Simp#define CFG_K0_UNCACHED	2
166178172Simp#define	CFG_K0_CACHED	3
167202864Sneel#define	CFG_K0_MASK	0x7
168178172Simp
169178172Simp/*
170178172Simp * The bits in the context register.
171178172Simp */
172178172Simp#define	CNTXT_PTE_BASE		0xff800000
173178172Simp#define	CNTXT_BAD_VPN2		0x007ffff0
174178172Simp
175178172Simp/*
176178172Simp * Location of exception vectors.
177178172Simp */
178178172Simp#define	RESET_EXC_VEC		0xbfc00000
179178172Simp#define	TLB_MISS_EXC_VEC	0x80000000
180178172Simp#define	XTLB_MISS_EXC_VEC	0x80000080
181178172Simp#define	CACHE_ERR_EXC_VEC	0x80000100
182178172Simp#define	GEN_EXC_VEC		0x80000180
183178172Simp
184178172Simp/*
185178172Simp * Coprocessor 0 registers:
186178172Simp */
187178172Simp#define	COP_0_TLB_INDEX		$0
188178172Simp#define	COP_0_TLB_RANDOM	$1
189178172Simp#define	COP_0_TLB_LO0		$2
190178172Simp#define	COP_0_TLB_LO1		$3
191178172Simp#define	COP_0_TLB_CONTEXT	$4
192178172Simp#define	COP_0_TLB_PG_MASK	$5
193178172Simp#define	COP_0_TLB_WIRED		$6
194178172Simp#define	COP_0_INFO		$7
195178172Simp#define	COP_0_BAD_VADDR		$8
196178172Simp#define	COP_0_COUNT		$9
197178172Simp#define	COP_0_TLB_HI		$10
198178172Simp#define	COP_0_COMPARE		$11
199178172Simp#define	COP_0_STATUS_REG	$12
200178172Simp#define	COP_0_CAUSE_REG		$13
201178172Simp#define	COP_0_EXC_PC		$14
202178172Simp#define	COP_0_PRID		$15
203178172Simp#define	COP_0_CONFIG		$16
204178172Simp#define	COP_0_LLADDR		$17
205178172Simp#define	COP_0_WATCH_LO		$18
206178172Simp#define	COP_0_WATCH_HI		$19
207178172Simp#define	COP_0_TLB_XCONTEXT	$20
208178172Simp#define	COP_0_ECC		$26
209178172Simp#define	COP_0_CACHE_ERR		$27
210178172Simp#define	COP_0_TAG_LO		$28
211178172Simp#define	COP_0_TAG_HI		$29
212178172Simp#define	COP_0_ERROR_PC		$30
213178172Simp
214178172Simp/*
215178172Simp *  Coprocessor 0 Set 1
216178172Simp */
217178172Simp#define	C0P_1_IPLLO	$18
218178172Simp#define	C0P_1_IPLHI	$19
219178172Simp#define	C0P_1_INTCTL	$20
220178172Simp#define	C0P_1_DERRADDR0	$26
221178172Simp#define	C0P_1_DERRADDR1	$27
222178172Simp
223178172Simp/*
224178172Simp * Values for the code field in a break instruction.
225178172Simp */
226178172Simp#define	BREAK_INSTR		0x0000000d
227178172Simp#define	BREAK_VAL_MASK		0x03ffffc0
228178172Simp#define	BREAK_VAL_SHIFT		16
229178172Simp#define	BREAK_KDB_VAL		512
230178172Simp#define	BREAK_SSTEP_VAL		513
231178172Simp#define	BREAK_BRKPT_VAL		514
232178172Simp#define	BREAK_SOVER_VAL		515
233178172Simp#define	BREAK_DDB_VAL		516
234178172Simp#define	BREAK_KDB	(BREAK_INSTR | (BREAK_KDB_VAL << BREAK_VAL_SHIFT))
235178172Simp#define	BREAK_SSTEP	(BREAK_INSTR | (BREAK_SSTEP_VAL << BREAK_VAL_SHIFT))
236178172Simp#define	BREAK_BRKPT	(BREAK_INSTR | (BREAK_BRKPT_VAL << BREAK_VAL_SHIFT))
237178172Simp#define	BREAK_SOVER	(BREAK_INSTR | (BREAK_SOVER_VAL << BREAK_VAL_SHIFT))
238178172Simp#define	BREAK_DDB	(BREAK_INSTR | (BREAK_DDB_VAL << BREAK_VAL_SHIFT))
239178172Simp
240178172Simp/*
241178172Simp * Mininum and maximum cache sizes.
242178172Simp */
243178172Simp#define	MIN_CACHE_SIZE		(16 * 1024)
244178172Simp#define	MAX_CACHE_SIZE		(256 * 1024)
245178172Simp
246178172Simp/*
247178172Simp * The floating point version and status registers.
248178172Simp */
249178172Simp#define	FPC_ID			$0
250178172Simp#define	FPC_CSR			$31
251178172Simp
252178172Simp/*
253178172Simp * The floating point coprocessor status register bits.
254178172Simp */
255178172Simp#define	FPC_ROUNDING_BITS		0x00000003
256178172Simp#define	FPC_ROUND_RN			0x00000000
257178172Simp#define	FPC_ROUND_RZ			0x00000001
258178172Simp#define	FPC_ROUND_RP			0x00000002
259178172Simp#define	FPC_ROUND_RM			0x00000003
260178172Simp#define	FPC_STICKY_BITS			0x0000007c
261178172Simp#define	FPC_STICKY_INEXACT		0x00000004
262178172Simp#define	FPC_STICKY_UNDERFLOW		0x00000008
263178172Simp#define	FPC_STICKY_OVERFLOW		0x00000010
264178172Simp#define	FPC_STICKY_DIV0			0x00000020
265178172Simp#define	FPC_STICKY_INVALID		0x00000040
266178172Simp#define	FPC_ENABLE_BITS			0x00000f80
267178172Simp#define	FPC_ENABLE_INEXACT		0x00000080
268178172Simp#define	FPC_ENABLE_UNDERFLOW		0x00000100
269178172Simp#define	FPC_ENABLE_OVERFLOW		0x00000200
270178172Simp#define	FPC_ENABLE_DIV0			0x00000400
271178172Simp#define	FPC_ENABLE_INVALID		0x00000800
272178172Simp#define	FPC_EXCEPTION_BITS		0x0003f000
273178172Simp#define	FPC_EXCEPTION_INEXACT		0x00001000
274178172Simp#define	FPC_EXCEPTION_UNDERFLOW		0x00002000
275178172Simp#define	FPC_EXCEPTION_OVERFLOW		0x00004000
276178172Simp#define	FPC_EXCEPTION_DIV0		0x00008000
277178172Simp#define	FPC_EXCEPTION_INVALID		0x00010000
278178172Simp#define	FPC_EXCEPTION_UNIMPL		0x00020000
279178172Simp#define	FPC_COND_BIT			0x00800000
280178172Simp#define	FPC_FLUSH_BIT			0x01000000
281178172Simp#define	FPC_MBZ_BITS			0xfe7c0000
282178172Simp
283178172Simp/*
284178172Simp * Constants to determine if have a floating point instruction.
285178172Simp */
286178172Simp#define	OPCODE_SHIFT		26
287178172Simp#define	OPCODE_C1		0x11
288178172Simp
289178172Simp/*
290178172Simp * The low part of the TLB entry.
291178172Simp */
292178172Simp#define	VMTLB_PF_NUM		0x3fffffc0
293178172Simp#define	VMTLB_ATTR_MASK		0x00000038
294178172Simp#define	VMTLB_MOD_BIT		0x00000004
295178172Simp#define	VMTLB_VALID_BIT		0x00000002
296178172Simp#define	VMTLB_GLOBAL_BIT	0x00000001
297178172Simp
298178172Simp#define	VMTLB_PHYS_PAGE_SHIFT	6
299178172Simp
300178172Simp/*
301178172Simp * The high part of the TLB entry.
302178172Simp */
303178172Simp#define	VMTLB_VIRT_PAGE_NUM		0xffffe000
304178172Simp#define	VMTLB_PID			0x000000ff
305178172Simp#define	VMTLB_PID_R9K			0x00000fff
306178172Simp#define	VMTLB_PID_SHIFT			0
307178172Simp#define	VMTLB_VIRT_PAGE_SHIFT		12
308178172Simp#define	VMTLB_VIRT_PAGE_SHIFT_R9K	13
309178172Simp
310178172Simp/*
311178172Simp * The first TLB entry that write random hits.
312203180Sneel * TLB entry 0 maps the kernel stack of the currently running thread
313203180Sneel * TLB entry 1 maps the pcpu area of processor (only for SMP builds)
314178172Simp */
315203180Sneel#define	KSTACK_TLB_ENTRY	0
316203180Sneel#ifdef SMP
317203180Sneel#define	PCPU_TLB_ENTRY		1
318203180Sneel#define	VMWIRED_ENTRIES		2
319203180Sneel#else
320178172Simp#define	VMWIRED_ENTRIES		1
321203180Sneel#endif	/* SMP */
322178172Simp
323178172Simp/*
324178172Simp * The number of process id entries.
325178172Simp */
326178172Simp#define	VMNUM_PIDS		256
327178172Simp
328178172Simp/*
329178172Simp * TLB probe return codes.
330178172Simp */
331178172Simp#define	VMTLB_NOT_FOUND		0
332178172Simp#define	VMTLB_FOUND		1
333178172Simp#define	VMTLB_FOUND_WITH_PATCH	2
334178172Simp#define	VMTLB_PROBE_ERROR	3
335178172Simp
336178172Simp/*
337178172Simp * Exported definitions unique to mips cpu support.
338178172Simp */
339178172Simp
340178172Simp/*
341178172Simp * definitions of cpu-dependent requirements
342178172Simp * referenced in generic code
343178172Simp */
344178172Simp#define	COPY_SIGCODE		/* copy sigcode above user stack in exec */
345178172Simp
346178172Simp#define	cpu_swapout(p)		panic("cpu_swapout: can't get here");
347178172Simp
348178172Simp#ifndef _LOCORE
349178172Simp#include <machine/frame.h>
350178172Simp/*
351178172Simp * Arguments to hardclock and gatherstats encapsulate the previous
352178172Simp * machine state in an opaque clockframe.
353178172Simp */
354178172Simp#define	clockframe trapframe	/* Use normal trap frame */
355178172Simp
356178172Simp#define	CLKF_USERMODE(framep)	((framep)->sr & SR_KSU_USER)
357178172Simp#define	CLKF_BASEPRI(framep)	((framep)->cpl == 0)
358178172Simp#define	CLKF_PC(framep)		((framep)->pc)
359178172Simp#define	CLKF_INTR(framep)	(0)
360178172Simp#define	MIPS_CLKF_INTR()	(intr_nesting_level >= 1)
361178172Simp#define	TRAPF_USERMODE(framep)  (((framep)->sr & SR_KSU_USER) != 0)
362178172Simp#define	TRAPF_PC(framep)	((framep)->pc)
363178172Simp#define	cpu_getstack(td)	((td)->td_frame->sp)
364178172Simp
365178172Simp/*
366178172Simp * CPU identification, from PRID register.
367178172Simp */
368178172Simpunion cpuprid {
369178172Simp	int cpuprid;
370178172Simp	struct {
371178172Simp#if BYTE_ORDER == BIG_ENDIAN
372178172Simp		u_int pad1:8;	/* reserved */
373178172Simp		u_int cp_vendor:8;	/* company identifier */
374178172Simp		u_int cp_imp:8;	/* implementation identifier */
375178172Simp		u_int cp_majrev:4;	/* major revision identifier */
376178172Simp		u_int cp_minrev:4;	/* minor revision identifier */
377178172Simp#else
378178172Simp		u_int cp_minrev:4;	/* minor revision identifier */
379178172Simp		u_int cp_majrev:4;	/* major revision identifier */
380178172Simp		u_int cp_imp:8;	/* implementation identifier */
381178172Simp		u_int cp_vendor:8;	/* company identifier */
382178172Simp		u_int pad1:8;	/* reserved */
383178172Simp#endif
384178172Simp	}      cpu;
385178172Simp};
386178172Simp
387178172Simp#endif				/* !_LOCORE */
388178172Simp
389178172Simp/*
390178172Simp * CTL_MACHDEP definitions.
391178172Simp */
392178172Simp#define	CPU_CONSDEV		1	/* dev_t: console terminal device */
393178172Simp#define	CPU_ADJKERNTZ		2	/* int: timezone offset (seconds) */
394178172Simp#define	CPU_DISRTCSET		3	/* int: disable resettodr() call */
395178172Simp#define	CPU_BOOTINFO		4	/* struct: bootinfo */
396178172Simp#define	CPU_WALLCLOCK		5	/* int: indicates wall CMOS clock */
397178172Simp#define	CPU_MAXID		6	/* number of valid machdep ids */
398178172Simp
399178172Simp#define	CTL_MACHDEP_NAMES {			\
400178172Simp	{ 0, 0 },				\
401178172Simp	{ "console_device", CTLTYPE_STRUCT },	\
402178172Simp	{ "adjkerntz", CTLTYPE_INT },		\
403178172Simp	{ "disable_rtc_set", CTLTYPE_INT },	\
404178172Simp	{ "bootinfo", CTLTYPE_STRUCT },		\
405178172Simp	{ "wall_cmos_clock", CTLTYPE_INT },	\
406178172Simp}
407178172Simp
408178172Simp/*
409178172Simp * MIPS CPU types (cp_imp).
410178172Simp */
411178172Simp#define	MIPS_R2000	0x01	/* MIPS R2000 CPU		ISA I	 */
412178172Simp#define	MIPS_R3000	0x02	/* MIPS R3000 CPU		ISA I	 */
413178172Simp#define	MIPS_R6000	0x03	/* MIPS R6000 CPU		ISA II	 */
414178172Simp#define	MIPS_R4000	0x04	/* MIPS R4000/4400 CPU		ISA III	 */
415178172Simp#define	MIPS_R3LSI	0x05	/* LSI Logic R3000 derivate	ISA I	 */
416178172Simp#define	MIPS_R6000A	0x06	/* MIPS R6000A CPU		ISA II	 */
417178172Simp#define	MIPS_R3IDT	0x07	/* IDT R3000 derivate		ISA I	 */
418178172Simp#define	MIPS_R10000	0x09	/* MIPS R10000/T5 CPU		ISA IV	 */
419178172Simp#define	MIPS_R4200	0x0a	/* MIPS R4200 CPU (ICE)		ISA III	 */
420178172Simp#define	MIPS_R4300	0x0b	/* NEC VR4300 CPU		ISA III	 */
421178172Simp#define	MIPS_R4100	0x0c	/* NEC VR41xx CPU MIPS-16	ISA III	 */
422178172Simp#define	MIPS_R8000	0x10	/* MIPS R8000 Blackbird/TFP	ISA IV	 */
423178172Simp#define	MIPS_R4600	0x20	/* QED R4600 Orion		ISA III	 */
424178172Simp#define	MIPS_R4700	0x21	/* QED R4700 Orion		ISA III	 */
425178172Simp#define	MIPS_R3TOSH	0x22	/* Toshiba R3000 based CPU	ISA I	 */
426178172Simp#define	MIPS_R5000	0x23	/* MIPS R5000 CPU		ISA IV	 */
427178172Simp#define	MIPS_RM7000	0x27	/* QED RM7000 CPU		ISA IV	 */
428178172Simp#define	MIPS_RM52X0	0x28	/* QED RM52X0 CPU		ISA IV	 */
429178172Simp#define	MIPS_VR5400	0x54	/* NEC Vr5400 CPU		ISA IV+	 */
430178172Simp#define	MIPS_RM9000	0x34	/* E9000 CPU				 */
431178172Simp
432178172Simp/*
433178172Simp * MIPS FPU types
434178172Simp */
435178172Simp#define	MIPS_SOFT	0x00	/* Software emulation		ISA I	 */
436178172Simp#define	MIPS_R2360	0x01	/* MIPS R2360 FPC		ISA I	 */
437178172Simp#define	MIPS_R2010	0x02	/* MIPS R2010 FPC		ISA I	 */
438178172Simp#define	MIPS_R3010	0x03	/* MIPS R3010 FPC		ISA I	 */
439178172Simp#define	MIPS_R6010	0x04	/* MIPS R6010 FPC		ISA II	 */
440178172Simp#define	MIPS_R4010	0x05	/* MIPS R4000/R4400 FPC		ISA II	 */
441178172Simp#define	MIPS_R31LSI	0x06	/* LSI Logic derivate		ISA I	 */
442178172Simp#define	MIPS_R10010	0x09	/* MIPS R10000/T5 FPU		ISA IV	 */
443178172Simp#define	MIPS_R4210	0x0a	/* MIPS R4200 FPC (ICE)		ISA III	 */
444178172Simp#define	MIPS_UNKF1	0x0b	/* unnanounced product cpu	ISA III	 */
445178172Simp#define	MIPS_R8000	0x10	/* MIPS R8000 Blackbird/TFP	ISA IV	 */
446178172Simp#define	MIPS_R4600	0x20	/* QED R4600 Orion		ISA III	 */
447178172Simp#define	MIPS_R3SONY	0x21	/* Sony R3000 based FPU		ISA I	 */
448178172Simp#define	MIPS_R3TOSH	0x22	/* Toshiba R3000 based FPU	ISA I	 */
449178172Simp#define	MIPS_R5010	0x23	/* MIPS R5000 based FPU		ISA IV	 */
450178172Simp#define	MIPS_RM7000	0x27	/* QED RM7000 FPU		ISA IV	 */
451178172Simp#define	MIPS_RM5230	0x28	/* QED RM52X0 based FPU		ISA IV	 */
452178172Simp#define	MIPS_RM52XX	0x28	/* QED RM52X0 based FPU		ISA IV	 */
453178172Simp#define	MIPS_VR5400	0x54	/* NEC Vr5400 FPU		ISA IV+	 */
454178172Simp
455178172Simp#ifndef _LOCORE
456178172Simpextern union cpuprid cpu_id;
457178172Simp
458178172Simp#define	mips_proc_type()      ((cpu_id.cpu.cp_vendor << 8) | cpu_id.cpu.cp_imp)
459178172Simp#define	mips_set_proc_type(type)	(cpu_id.cpu.cp_vendor = (type)  >> 8, \
460178172Simp					 cpu_id.cpu.cp_imp = ((type) & 0x00ff))
461178172Simp#endif				/* !_LOCORE */
462178172Simp
463178172Simp#if defined(_KERNEL) && !defined(_LOCORE)
464178172Simpextern union cpuprid fpu_id;
465178172Simp
466178172Simpstruct tlb;
467178172Simpstruct user;
468178172Simp
469178172Simpu_int32_t mips_cp0_config1_read(void);
470178172Simpint Mips_ConfigCache(void);
471178172Simpvoid Mips_SetWIRED(int);
472178172Simpvoid Mips_SetPID(int);
473178172Simpu_int Mips_GetCOUNT(void);
474178172Simpvoid Mips_SetCOMPARE(u_int);
475178172Simpu_int Mips_GetCOMPARE(void);
476178172Simp
477178172Simpvoid Mips_SyncCache(void);
478178172Simpvoid Mips_SyncDCache(vm_offset_t, int);
479178172Simpvoid Mips_HitSyncDCache(vm_offset_t, int);
480178172Simpvoid Mips_HitSyncSCache(vm_offset_t, int);
481178172Simpvoid Mips_IOSyncDCache(vm_offset_t, int, int);
482178172Simpvoid Mips_HitInvalidateDCache(vm_offset_t, int);
483178172Simpvoid Mips_SyncICache(vm_offset_t, int);
484178172Simpvoid Mips_InvalidateICache(vm_offset_t, int);
485178172Simp
486178172Simpvoid Mips_TLBFlush(int);
487178172Simpvoid Mips_TLBFlushAddr(vm_offset_t);
488178172Simpvoid Mips_TLBWriteIndexed(int, struct tlb *);
489178172Simpvoid Mips_TLBUpdate(vm_offset_t, unsigned);
490178172Simpvoid Mips_TLBRead(int, struct tlb *);
491178172Simpvoid mips_TBIAP(int);
492178172Simpvoid wbflush(void);
493178172Simp
494178172Simpextern u_int32_t cpu_counter_interval;	/* Number of counter ticks/tick */
495178172Simpextern u_int32_t cpu_counter_last;	/* Last compare value loaded    */
496178172Simpextern int num_tlbentries;
497178172Simpextern char btext[];
498178172Simpextern char etext[];
499178172Simpextern int intr_nesting_level;
500178172Simp
501178172Simp#define	func_0args_asmmacro(func, in)					\
502178172Simp	__asm __volatile ( "jalr %0"					\
503178172Simp			: "=r" (in)	/* outputs */			\
504178172Simp			: "r" (func)	/* inputs */			\
505178172Simp			: "$31", "$4");
506178172Simp
507178172Simp#define	func_1args_asmmacro(func, arg0)					\
508178172Simp	__asm __volatile ("move $4, %1;"				\
509178172Simp			"jalr %0"					\
510178172Simp			:				/* outputs */	\
511178172Simp			: "r" (func), "r" (arg0)	/* inputs */	\
512178172Simp			: "$31", "$4");
513178172Simp
514178172Simp#define	func_2args_asmmacro(func, arg0, arg1)				\
515178172Simp	__asm __volatile ("move $4, %1;"				\
516178172Simp			"move $5, %2;"					\
517178172Simp			"jalr %0"					\
518178172Simp			:				/* outputs */   \
519178172Simp			: "r" (func), "r" (arg0), "r" (arg1) /* inputs */ \
520178172Simp			: "$31", "$4", "$5");
521178172Simp
522178172Simp#define	func_3args_asmmacro(func, arg0, arg1, arg2)			\
523178172Simp	__asm __volatile ( "move $4, %1;"				\
524178172Simp			"move $5, %2;"					\
525178172Simp			"move $6, %3;"					\
526178172Simp			"jalr %0"					\
527178172Simp			:				/* outputs */	\
528178172Simp			: "r" (func), "r" (arg0), "r" (arg1), "r" (arg2)  /* inputs */ \
529178172Simp			: "$31", "$4", "$5", "$6");
530178172Simp
531178172Simp#define	MachSetPID			Mips_SetPID
532178172Simp#define	MachTLBUpdate   		Mips_TLBUpdate
533178172Simp#define	mips_TBIS			Mips_TLBFlushAddr
534178172Simp#define	MIPS_TBIAP()			mips_TBIAP(num_tlbentries)
535178172Simp#define	MachSetWIRED(index)		Mips_SetWIRED(index)
536178172Simp#define	MachTLBFlush(count)		Mips_TLBFlush(count)
537178172Simp#define	MachTLBGetPID(pid)		(pid = Mips_TLBGetPID())
538178172Simp#define	MachTLBRead(tlbno, tlbp)	Mips_TLBRead(tlbno, tlbp)
539178172Simp#define	MachFPTrap(sr, cause, pc)	MipsFPTrap(sr, cause, pc)
540178172Simp
541178172Simp/*
542178172Simp * Enable realtime clock (always enabled).
543178172Simp */
544178172Simp#define	enablertclock()
545178172Simp
546178172Simp/*
547178172Simp * Are we in an interrupt handler? required by JunOS
548178172Simp */
549178172Simp#define	IN_INT_HANDLER()				\
550178172Simp	(curthread->td_intr_nesting_level != 0 ||	\
551178172Simp	(curthread->td_pflags & TDP_ITHREAD))
552178172Simp
553178172Simp/*
554178172Simp *  Low level access routines to CPU registers
555178172Simp */
556178172Simp
557178172Simpvoid setsoftintr0(void);
558178172Simpvoid clearsoftintr0(void);
559178172Simpvoid setsoftintr1(void);
560178172Simpvoid clearsoftintr1(void);
561178172Simp
562178172Simp
563178172Simpu_int32_t mips_cp0_status_read(void);
564178172Simpvoid mips_cp0_status_write(u_int32_t);
565178172Simp
566178172Simpint disableintr(void);
567178172Simpvoid restoreintr(int);
568178172Simpint enableintr(void);
569178172Simpint Mips_TLBGetPID(void);
570178172Simp
571178172Simpvoid swi_vm(void *);
572178172Simpvoid cpu_halt(void);
573178172Simpvoid cpu_reset(void);
574178172Simp
575178172Simpu_int32_t set_intr_mask(u_int32_t);
576178172Simpu_int32_t get_intr_mask(void);
577178172Simpu_int32_t get_cyclecount(void);
578178172Simp
579178172Simp#define	cpu_spinwait()		/* nothing */
580178172Simp
581178172Simp#endif				/* _KERNEL */
582178172Simp#endif				/* !_MACHINE_CPU_H_ */
583