File: /usr/src/linux/include/asm-mips/processor.h
1 /*
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 Ralf Baechle
8 * Copyright (C) 1996 Paul M. Antoine
9 * Copyright (C) 1999 Silicon Graphics, Inc.
10 */
11 #ifndef _ASM_PROCESSOR_H
12 #define _ASM_PROCESSOR_H
13
14 #include <linux/config.h>
15
16 #include <asm/isadep.h>
17
18 /*
19 * Default implementation of macro that returns current
20 * instruction pointer ("program counter").
21 */
22 #define current_text_addr() ({ __label__ _l; _l: &&_l;})
23
24 #if !defined (_LANGUAGE_ASSEMBLY)
25 #include <linux/threads.h>
26 #include <asm/cachectl.h>
27 #include <asm/mipsregs.h>
28 #include <asm/reg.h>
29 #include <asm/system.h>
30
31 struct mips_cpuinfo {
32 unsigned long udelay_val;
33 unsigned long *pgd_quick;
34 unsigned long *pte_quick;
35 unsigned long pgtable_cache_sz;
36 };
37
38 /*
39 * System setup and hardware flags..
40 * XXX: Should go into mips_cpuinfo.
41 */
42 extern void (*cpu_wait)(void); /* only available on R4[26]00 and R3081 */
43 extern void r3081_wait(void);
44 extern void r4k_wait(void);
45 extern char cyclecounter_available; /* only available from R4000 upwards. */
46
47 extern struct mips_cpuinfo boot_cpu_data;
48 extern unsigned int vced_count, vcei_count;
49
50 #ifdef CONFIG_SMP
51 extern struct mips_cpuinfo cpu_data[];
52 #define current_cpu_data cpu_data[smp_processor_id()]
53 #else
54 #define cpu_data &boot_cpu_data
55 #define current_cpu_data boot_cpu_data
56 #endif
57
58 /*
59 * Bus types (default is ISA, but people can check others with these..)
60 * MCA_bus hardcoded to 0 for now.
61 *
62 * This needs to be extended since MIPS systems are being delivered with
63 * numerous different types of bus systems.
64 */
65 extern int EISA_bus;
66 #define MCA_bus 0
67 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
68
69 /*
70 * MIPS has no problems with write protection
71 */
72 #define wp_works_ok 1
73 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
74
75 /* Lazy FPU handling on uni-processor */
76 extern struct task_struct *last_task_used_math;
77
78 /*
79 * User space process size: 2GB. This is hardcoded into a few places,
80 * so don't change it unless you know what you are doing. TASK_SIZE
81 * for a 64 bit kernel expandable to 8192EB, of which the current MIPS
82 * implementations will "only" be able to use 1TB ...
83 */
84 #define TASK_SIZE (0x7fff8000UL)
85
86 /* This decides where the kernel will search for a free chunk of vm
87 * space during mmap's.
88 */
89 #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
90
91 /*
92 * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
93 */
94 #define IO_BITMAP_SIZE 32
95
96 #define NUM_FPU_REGS 32
97
98 struct mips_fpu_hard_struct {
99 double fp_regs[NUM_FPU_REGS];
100 unsigned int control;
101 };
102
103 /*
104 * It would be nice to add some more fields for emulator statistics, but there
105 * are a number of fixed offsets in offset.h and elsewhere that would have to
106 * be recalculated by hand. So the additional information will be private to
107 * the FPU emulator for now. See asm-mips/fpu_emulator.h.
108 */
109 typedef u64 fpureg_t;
110 struct mips_fpu_soft_struct {
111 fpureg_t regs[NUM_FPU_REGS];
112 unsigned int sr;
113 };
114
115 union mips_fpu_union {
116 struct mips_fpu_hard_struct hard;
117 struct mips_fpu_soft_struct soft;
118 };
119
120 #define INIT_FPU { \
121 {{0,},} \
122 }
123
124 typedef struct {
125 unsigned long seg;
126 } mm_segment_t;
127
128 /*
129 * If you change thread_struct remember to change the #defines below too!
130 */
131 struct thread_struct {
132 /* Saved main processor registers. */
133 unsigned long reg16;
134 unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
135 unsigned long reg29, reg30, reg31;
136
137 /* Saved cp0 stuff. */
138 unsigned long cp0_status;
139
140 /* Saved fpu/fpu emulator stuff. */
141 union mips_fpu_union fpu;
142
143 /* Other stuff associated with the thread. */
144 unsigned long cp0_badvaddr; /* Last user fault */
145 unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
146 unsigned long error_code;
147 unsigned long trap_no;
148 #define MF_FIXADE 1 /* Fix address errors in software */
149 #define MF_LOGADE 2 /* Log address errors to syslog */
150 unsigned long mflags;
151 mm_segment_t current_ds;
152 unsigned long irix_trampoline; /* Wheee... */
153 unsigned long irix_oldctx;
154
155 /*
156 * These are really only needed if the full FPU emulator is configured.
157 * Would be made conditional on MIPS_FPU_EMULATOR if it weren't for the
158 * fact that having offset.h rebuilt differently for different config
159 * options would be asking for trouble.
160 *
161 * Saved EPC during delay-slot emulation (see math-emu/cp1emu.c)
162 */
163 unsigned long dsemul_epc;
164
165 /*
166 * Pointer to instruction used to induce address error
167 */
168 unsigned long dsemul_aerpc;
169 };
170
171 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
172
173 #define INIT_THREAD { \
174 /* \
175 * saved main processor registers \
176 */ \
177 0, 0, 0, 0, 0, 0, 0, 0, \
178 0, 0, 0, \
179 /* \
180 * saved cp0 stuff \
181 */ \
182 0, \
183 /* \
184 * saved fpu/fpu emulator stuff \
185 */ \
186 INIT_FPU, \
187 /* \
188 * Other stuff associated with the process \
189 */ \
190 0, 0, 0, 0, \
191 /* \
192 * For now the default is to fix address errors \
193 */ \
194 MF_FIXADE, { 0 }, 0, 0, \
195 /* \
196 * dsemul_epc and dsemul_aerpc should never be used uninitialized, \
197 * but... \
198 */ \
199 0 ,0 \
200 }
201
202 #ifdef __KERNEL__
203
204 #define KERNEL_STACK_SIZE 8192
205
206 #if !defined (_LANGUAGE_ASSEMBLY)
207
208 /* Free all resources held by a thread. */
209 #define release_thread(thread) do { } while(0)
210
211 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
212
213 /* Copy and release all segment info associated with a VM */
214 #define copy_segments(p, mm) do { } while(0)
215 #define release_segments(mm) do { } while(0)
216
217 /*
218 * Return saved PC of a blocked thread.
219 */
220 extern inline unsigned long thread_saved_pc(struct thread_struct *t)
221 {
222 extern void ret_from_fork(void);
223
224 /* New born processes are a special case */
225 if (t->reg31 == (unsigned long) ret_from_fork)
226 return t->reg31;
227
228 return ((unsigned long *)t->reg29)[10];
229 }
230
231 /*
232 * Do necessary setup to start up a newly executed thread.
233 */
234 #define start_thread(regs, new_pc, new_sp) do { \
235 /* New thread looses kernel privileges. */ \
236 regs->cp0_status = (regs->cp0_status & ~(ST0_CU0|ST0_KSU)) | KU_USER;\
237 regs->cp0_epc = new_pc; \
238 regs->regs[29] = new_sp; \
239 current->thread.current_ds = USER_DS; \
240 } while (0)
241
242 unsigned long get_wchan(struct task_struct *p);
243
244 #define __PT_REG(reg) ((long)&((struct pt_regs *)0)->reg - sizeof(struct pt_regs))
245 #define __KSTK_TOS(tsk) ((unsigned long)(tsk) + KERNEL_STACK_SIZE - 32)
246 #define KSTK_EIP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_epc)))
247 #define KSTK_ESP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(regs[29])))
248
249 /* Allocation and freeing of basic task resources. */
250 /*
251 * NOTE! The task struct and the stack go together
252 */
253 #define THREAD_SIZE (2*PAGE_SIZE)
254 #define alloc_task_struct() \
255 ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
256 #define free_task_struct(p) free_pages((unsigned long)(p),1)
257 #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
258
259 #define init_task (init_task_union.task)
260 #define init_stack (init_task_union.stack)
261
262 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
263 #endif /* __KERNEL__ */
264
265 /*
266 * Return_address is a replacement for __builtin_return_address(count)
267 * which on certain architectures cannot reasonably be implemented in GCC
268 * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
269 * Note that __builtin_return_address(x>=1) is forbidden because GCC
270 * aborts compilation on some CPUs. It's simply not possible to unwind
271 * some CPU's stackframes.
272 *
273 * __builtin_return_address works only for non-leaf functions. We avoid the
274 * overhead of a function call by forcing the compiler to save the return
275 * address register on the stack.
276 */
277 #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
278
279 #endif /* _ASM_PROCESSOR_H */
280