1633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
2633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * This file is subject to the terms and conditions of the GNU General Public
3633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * License.  See the file "COPYING" in the main directory of this archive
4633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * for more details.
5633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham *
6633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Copyright (C) 1994 Waldorf GMBH
7633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle
8633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Copyright (C) 1996 Paul M. Antoine
9633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
11633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifndef _ASM_PROCESSOR_H
12633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _ASM_PROCESSOR_H
13633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
14633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <linux/cpumask.h>
15633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <linux/threads.h>
16633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
17633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <asm/cachectl.h>
18633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <asm/cpu.h>
19633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <asm/cpu-info.h>
20633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <asm/mipsregs.h>
21633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <asm/prefetch.h>
22633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#include <asm/system.h>
23633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
24633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
25633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Return current * instruction pointer ("program counter").
26633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
27633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define current_text_addr() ({ __label__ _l; _l: &&_l;})
28633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
29633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
30633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * System setup and hardware flags..
31633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
32633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamextern void (*cpu_wait)(void);
33633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
34633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamextern unsigned int vced_count, vcei_count;
35633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
36633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifdef CONFIG_32BIT
37633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
38633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * User space process size: 2GB. This is hardcoded into a few places,
39633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * so don't change it unless you know what you are doing.
40633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
41633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define TASK_SIZE	0x7fff8000UL
42633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define STACK_TOP	TASK_SIZE
43633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
44633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
45633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * This decides where the kernel will search for a free chunk of vm
46633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * space during mmap's.
47633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
48633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define TASK_UNMAPPED_BASE	((TASK_SIZE / 3) & ~(PAGE_SIZE))
49633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif
50633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
51633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifdef CONFIG_64BIT
52633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
53633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * User space process size: 1TB. This is hardcoded into a few places,
54633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * so don't change it unless you know what you are doing.  TASK_SIZE
55633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * is limited to 1TB by the R4000 architecture; R10000 and better can
56633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * support 16TB; the architectural reserve for future expansion is
57633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * 8192EB ...
58633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
59633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define TASK_SIZE32	0x7fff8000UL
60633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define TASK_SIZE	0x10000000000UL
61633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define STACK_TOP	\
62633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham      (test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
63633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
64633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
65633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * This decides where the kernel will search for a free chunk of vm
66633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * space during mmap's.
67633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
68633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define TASK_UNMAPPED_BASE						\
69633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	(test_thread_flag(TIF_32BIT_ADDR) ?				\
70633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham		PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
71633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define TASK_SIZE_OF(tsk)						\
72633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	(test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
73633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif
74633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
75633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifdef __KERNEL__
76633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define STACK_TOP_MAX	TASK_SIZE
77633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif
78633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
79633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define NUM_FPU_REGS	32
80633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
81633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamtypedef __u64 fpureg_t;
82633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
83633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
84633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * It would be nice to add some more fields for emulator statistics, but there
85633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * are a number of fixed offsets in offset.h and elsewhere that would have to
86633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * be recalculated by hand.  So the additional information will be private to
87633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * the FPU emulator for now.  See asm-mips/fpu_emulator.h.
88633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
89633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
90633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamstruct mips_fpu_struct {
91633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	fpureg_t	fpr[NUM_FPU_REGS];
92633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned int	fcr31;
93633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham};
94633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
95633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define NUM_DSP_REGS   6
96633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
97633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamtypedef __u32 dspreg_t;
98633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
99633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamstruct mips_dsp_state {
100633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	dspreg_t        dspr[NUM_DSP_REGS];
101633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned int    dspcontrol;
102633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham};
103633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
104633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define INIT_CPUMASK { \
105633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	{0,} \
106633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham}
107633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
108633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamtypedef struct {
109633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long seg;
110633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham} mm_segment_t;
111633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
112633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define ARCH_MIN_TASKALIGN	8
113633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
114633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamstruct mips_abi;
115633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
116633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
117633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * If you change thread_struct remember to change the #defines below too!
118633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
119633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamstruct thread_struct {
120633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Saved main processor registers. */
121633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long reg16;
122633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
123633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long reg29, reg30, reg31;
124633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
125633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Saved cp0 stuff. */
126633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long cp0_status;
127633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
128633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Saved fpu/fpu emulator stuff. */
129633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	struct mips_fpu_struct fpu;
130633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifdef CONFIG_MIPS_MT_FPAFF
131633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Emulated instruction count */
132633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long emulated_fp;
133633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Saved per-thread scheduler affinity mask */
134633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	cpumask_t user_cpus_allowed;
135633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif /* CONFIG_MIPS_MT_FPAFF */
136633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
137633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Saved state of the DSP ASE, if available. */
138633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	struct mips_dsp_state dsp;
139633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
140633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/* Other stuff associated with the thread. */
141633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long cp0_badvaddr;	/* Last user fault */
142633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long cp0_baduaddr;	/* Last kernel fault accessing USEG */
143633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long error_code;
144633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long trap_no;
145633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long irix_trampoline;  /* Wheee... */
146633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	unsigned long irix_oldctx;
147633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	struct mips_abi *abi;
148633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham};
149633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
150633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifdef CONFIG_MIPS_MT_FPAFF
151633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define FPAFF_INIT						\
152633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.emulated_fp			= 0,			\
153633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.user_cpus_allowed		= INIT_CPUMASK,
154633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#else
155633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define FPAFF_INIT
156633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif /* CONFIG_MIPS_MT_FPAFF */
157633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
158633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define INIT_THREAD  {						\
159633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham        /*							\
160633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham         * Saved main processor registers			\
161633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham         */							\
162633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg16			= 0,				\
163633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg17			= 0,				\
164633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg18			= 0,				\
165633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg19			= 0,				\
166633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg20			= 0,				\
167633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg21			= 0,				\
168633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg22			= 0,				\
169633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg23			= 0,				\
170633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg29			= 0,				\
171633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg30			= 0,				\
172633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.reg31			= 0,				\
173633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/*							\
174633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 * Saved cp0 stuff					\
175633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 */							\
176633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.cp0_status		= 0,				\
177633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/*							\
178633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 * Saved FPU/FPU emulator stuff				\
179633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 */							\
180633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.fpu			= {				\
181633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham		.fpr		= {0,},				\
182633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham		.fcr31		= 0,				\
183633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	},							\
184633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/*							\
185633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 * FPU affinity state (null if not FPAFF)		\
186633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 */							\
187633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	FPAFF_INIT						\
188633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/*							\
189633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 * Saved DSP stuff					\
190633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 */							\
191633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.dsp			= {				\
192633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham		.dspr		= {0, },			\
193633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham		.dspcontrol	= 0,				\
194633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	},							\
195633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	/*							\
196633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 * Other stuff associated with the process		\
197633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 */							\
198633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.cp0_badvaddr		= 0,				\
199633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.cp0_baduaddr		= 0,				\
200633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.error_code		= 0,				\
201633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.trap_no		= 0,				\
202633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.irix_trampoline	= 0,				\
203633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	.irix_oldctx		= 0,				\
204633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham}
205633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
206633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamstruct task_struct;
207633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
208633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/* Free all resources held by a thread. */
209633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define release_thread(thread) do { } while(0)
210633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
211633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/* Prepare to copy thread state - unlazy all lazy status */
212633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define prepare_to_copy(tsk)	do { } while (0)
213633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
214633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamextern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
215633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
216633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamextern unsigned long thread_saved_pc(struct task_struct *tsk);
217633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
218633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
219633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Do necessary setup to start up a newly executed thread.
220633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
221633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamextern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
222633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
223633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamunsigned long get_wchan(struct task_struct *p);
224633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
225633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + THREAD_SIZE - 32)
226633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk) - 1)
227633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
228633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
229633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
230633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
231633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define cpu_relax()	barrier()
232633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
233633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
234633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Return_address is a replacement for __builtin_return_address(count)
235633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * which on certain architectures cannot reasonably be implemented in GCC
236633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
237633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Note that __builtin_return_address(x>=1) is forbidden because GCC
238633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * aborts compilation on some CPUs.  It's simply not possible to unwind
239633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * some CPU's stackframes.
240633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham *
241633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * __builtin_return_address works only for non-leaf functions.  We avoid the
242633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * overhead of a function call by forcing the compiler to save the return
243633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * address register on the stack.
244633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
245633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
246633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
247633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifdef CONFIG_CPU_HAS_PREFETCH
248633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
249633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define ARCH_HAS_PREFETCH
250633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
251633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamstatic inline void prefetch(const void *addr)
252633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham{
253633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	__asm__ __volatile__(
254633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	"	.set	mips4		\n"
255633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	"	pref	%0, (%1)	\n"
256633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	"	.set	mips0		\n"
257633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	:
258633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	: "i" (Pref_Load), "r" (addr));
259633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham}
260633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
261633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif
262633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
263633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif /* _ASM_PROCESSOR_H */
264