blob: 83936469fe873a7cc3dcb7ae6fca70d491f37674 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 Waldorf GMBH
7 * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle
8 * Copyright (C) 1996 Paul M. Antoine
9 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10 */
11#ifndef _ASM_PROCESSOR_H
12#define _ASM_PROCESSOR_H
13
14#include <linux/config.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010015#include <linux/cpumask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/threads.h>
17
18#include <asm/cachectl.h>
19#include <asm/cpu.h>
20#include <asm/cpu-info.h>
21#include <asm/mipsregs.h>
22#include <asm/prefetch.h>
23#include <asm/system.h>
24
25/*
26 * Return current * instruction pointer ("program counter").
27 */
28#define current_text_addr() ({ __label__ _l; _l: &&_l;})
29
30/*
31 * System setup and hardware flags..
32 */
33extern void (*cpu_wait)(void);
34
35extern unsigned int vced_count, vcei_count;
36
Ralf Baechle875d43e2005-09-03 15:56:16 -070037#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * User space process size: 2GB. This is hardcoded into a few places,
40 * so don't change it unless you know what you are doing.
41 */
42#define TASK_SIZE 0x7fff8000UL
43
44/*
45 * This decides where the kernel will search for a free chunk of vm
46 * space during mmap's.
47 */
48#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
49#endif
50
Ralf Baechle875d43e2005-09-03 15:56:16 -070051#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/*
53 * User space process size: 1TB. This is hardcoded into a few places,
54 * so don't change it unless you know what you are doing. TASK_SIZE
55 * is limited to 1TB by the R4000 architecture; R10000 and better can
56 * support 16TB; the architectural reserve for future expansion is
57 * 8192EB ...
58 */
59#define TASK_SIZE32 0x7fff8000UL
60#define TASK_SIZE 0x10000000000UL
61
62/*
63 * This decides where the kernel will search for a free chunk of vm
64 * space during mmap's.
65 */
66#define TASK_UNMAPPED_BASE ((current->thread.mflags & MF_32BIT_ADDR) ? \
67 PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
68#endif
69
70#define NUM_FPU_REGS 32
71
72typedef __u64 fpureg_t;
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/*
75 * It would be nice to add some more fields for emulator statistics, but there
76 * are a number of fixed offsets in offset.h and elsewhere that would have to
77 * be recalculated by hand. So the additional information will be private to
78 * the FPU emulator for now. See asm-mips/fpu_emulator.h.
79 */
80
Atsushi Nemotoeae89072006-05-16 01:26:03 +090081struct mips_fpu_struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 fpureg_t fpr[NUM_FPU_REGS];
83 unsigned int fcr31;
84};
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define INIT_FPU { \
Atsushi Nemotoeae89072006-05-16 01:26:03 +090087 {0,} \
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Ralf Baechlee50c0a82005-05-31 11:49:19 +000090#define NUM_DSP_REGS 6
91
92typedef __u32 dspreg_t;
93
94struct mips_dsp_state {
95 dspreg_t dspr[NUM_DSP_REGS];
96 unsigned int dspcontrol;
Ralf Baechlee50c0a82005-05-31 11:49:19 +000097};
98
99#define INIT_DSP {{0,},}
100
Ralf Baechle41c594a2006-04-05 09:45:45 +0100101#define INIT_CPUMASK { \
102 {0,} \
103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105typedef struct {
106 unsigned long seg;
107} mm_segment_t;
108
109#define ARCH_MIN_TASKALIGN 8
110
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000111struct mips_abi;
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*
114 * If you change thread_struct remember to change the #defines below too!
115 */
116struct thread_struct {
117 /* Saved main processor registers. */
118 unsigned long reg16;
119 unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
120 unsigned long reg29, reg30, reg31;
121
122 /* Saved cp0 stuff. */
123 unsigned long cp0_status;
124
125 /* Saved fpu/fpu emulator stuff. */
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900126 struct mips_fpu_struct fpu;
Ralf Baechlef088fc82006-04-05 09:45:47 +0100127#ifdef CONFIG_MIPS_MT_FPAFF
128 /* Emulated instruction count */
129 unsigned long emulated_fp;
130 /* Saved per-thread scheduler affinity mask */
131 cpumask_t user_cpus_allowed;
132#endif /* CONFIG_MIPS_MT_FPAFF */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000134 /* Saved state of the DSP ASE, if available. */
135 struct mips_dsp_state dsp;
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 /* Other stuff associated with the thread. */
138 unsigned long cp0_badvaddr; /* Last user fault */
139 unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
140 unsigned long error_code;
141 unsigned long trap_no;
142#define MF_FIXADE 1 /* Fix address errors in software */
143#define MF_LOGADE 2 /* Log address errors to syslog */
144#define MF_32BIT_REGS 4 /* also implies 16/32 fprs */
145#define MF_32BIT_ADDR 8 /* 32-bit address space (o32/n32) */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100146#define MF_FPUBOUND 0x10 /* thread bound to FPU-full CPU set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 unsigned long mflags;
148 unsigned long irix_trampoline; /* Wheee... */
149 unsigned long irix_oldctx;
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000150 struct mips_abi *abi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
153#define MF_ABI_MASK (MF_32BIT_REGS | MF_32BIT_ADDR)
154#define MF_O32 (MF_32BIT_REGS | MF_32BIT_ADDR)
155#define MF_N32 MF_32BIT_ADDR
156#define MF_N64 0
157
Ralf Baechlef088fc82006-04-05 09:45:47 +0100158#ifdef CONFIG_MIPS_MT_FPAFF
159#define FPAFF_INIT 0, INIT_CPUMASK,
160#else
161#define FPAFF_INIT
162#endif /* CONFIG_MIPS_MT_FPAFF */
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define INIT_THREAD { \
165 /* \
166 * saved main processor registers \
167 */ \
168 0, 0, 0, 0, 0, 0, 0, 0, \
169 0, 0, 0, \
170 /* \
171 * saved cp0 stuff \
172 */ \
173 0, \
174 /* \
175 * saved fpu/fpu emulator stuff \
176 */ \
177 INIT_FPU, \
178 /* \
Ralf Baechlef088fc82006-04-05 09:45:47 +0100179 * fpu affinity state (null if not FPAFF) \
180 */ \
181 FPAFF_INIT \
182 /* \
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000183 * saved dsp/dsp emulator stuff \
184 */ \
185 INIT_DSP, \
186 /* \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 * Other stuff associated with the process \
188 */ \
189 0, 0, 0, 0, \
190 /* \
191 * For now the default is to fix address errors \
192 */ \
193 MF_FIXADE, 0, 0 \
194}
195
196struct task_struct;
197
198/* Free all resources held by a thread. */
199#define release_thread(thread) do { } while(0)
200
201/* Prepare to copy thread state - unlazy all lazy status */
202#define prepare_to_copy(tsk) do { } while (0)
203
204extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
205
206extern unsigned long thread_saved_pc(struct task_struct *tsk);
207
208/*
209 * Do necessary setup to start up a newly executed thread.
210 */
211extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
212
213unsigned long get_wchan(struct task_struct *p);
214
Al Viro75bb07e2006-01-12 01:06:08 -0800215#define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + THREAD_SIZE - 32)
Al Viro40bc9c62006-01-12 01:06:07 -0800216#define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk) - 1)
217#define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
218#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
219#define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221#define cpu_relax() barrier()
222
223/*
224 * Return_address is a replacement for __builtin_return_address(count)
225 * which on certain architectures cannot reasonably be implemented in GCC
226 * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
227 * Note that __builtin_return_address(x>=1) is forbidden because GCC
228 * aborts compilation on some CPUs. It's simply not possible to unwind
229 * some CPU's stackframes.
230 *
231 * __builtin_return_address works only for non-leaf functions. We avoid the
232 * overhead of a function call by forcing the compiler to save the return
233 * address register on the stack.
234 */
235#define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
236
237#ifdef CONFIG_CPU_HAS_PREFETCH
238
239#define ARCH_HAS_PREFETCH
240
241extern inline void prefetch(const void *addr)
242{
243 __asm__ __volatile__(
244 " .set mips4 \n"
245 " pref %0, (%1) \n"
246 " .set mips0 \n"
247 :
248 : "i" (Pref_Load), "r" (addr));
249}
250
251#endif
252
253#endif /* _ASM_PROCESSOR_H */