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
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.
11 #ifndef _ASM_PROCESSOR_H
12 #define _ASM_PROCESSOR_H
14 #include <linux/config.h>
16 #include <asm/isadep.h>
19 * Default implementation of macro that returns current
20 * instruction pointer ("program counter").
22 #define current_text_addr() ({ __label__ _l; _l: &&_l;})
24 #if !defined (_LANGUAGE_ASSEMBLY)
26 #include <linux/threads.h>
28 #include <asm/cachectl.h>
29 #include <asm/mipsregs.h>
31 #include <asm/system.h>
34 unsigned long udelay_val;
35 unsigned long *pgd_quick;
36 unsigned long *pte_quick;
37 unsigned long pgtable_cache_sz;
41 * System setup and hardware flags..
42 * XXX: Should go into mips_cpuinfo.
44 extern void (*cpu_wait)(void); /* only available on R4[26]00 and R3081 */
45 extern void r3081_wait(void);
46 extern void r4k_wait(void);
47 extern char cyclecounter_available; /* only available from R4000 upwards. */
49 extern struct mips_cpuinfo boot_cpu_data;
50 extern unsigned int vced_count, vcei_count;
53 extern struct mips_cpuinfo cpu_data[];
54 #define current_cpu_data cpu_data[smp_processor_id()]
56 #define cpu_data &boot_cpu_data
57 #define current_cpu_data boot_cpu_data
61 * Bus types (default is ISA, but people can check others with these..)
62 * MCA_bus hardcoded to 0 for now.
64 * This needs to be extended since MIPS systems are being delivered with
65 * numerous different types of bus systems.
69 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
72 * MIPS has no problems with write protection
75 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
77 /* Lazy FPU handling on uni-processor */
78 extern struct task_struct *last_task_used_math;
81 * User space process size: 2GB. This is hardcoded into a few places,
82 * so don't change it unless you know what you are doing. TASK_SIZE
83 * for a 64 bit kernel expandable to 8192EB, of which the current MIPS
84 * implementations will "only" be able to use 1TB ...
86 #define TASK_SIZE (0x7fff8000UL)
88 /* This decides where the kernel will search for a free chunk of vm
89 * space during mmap's.
91 #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
94 * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
96 #define IO_BITMAP_SIZE 32
98 #define NUM_FPU_REGS 32
100 struct mips_fpu_hard_struct {
101 double fp_regs[NUM_FPU_REGS];
102 unsigned int control;
106 * It would be nice to add some more fields for emulator statistics, but there
107 * are a number of fixed offsets in offset.h and elsewhere that would have to
108 * be recalculated by hand. So the additional information will be private to
109 * the FPU emulator for now. See asm-mips/fpu_emulator.h.
111 typedef u64 fpureg_t;
112 struct mips_fpu_soft_struct {
113 fpureg_t regs[NUM_FPU_REGS];
117 union mips_fpu_union {
118 struct mips_fpu_hard_struct hard;
119 struct mips_fpu_soft_struct soft;
131 * If you change thread_struct remember to change the #defines below too!
133 struct thread_struct {
134 /* Saved main processor registers. */
136 unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
137 unsigned long reg29, reg30, reg31;
139 /* Saved cp0 stuff. */
140 unsigned long cp0_status;
142 /* Saved fpu/fpu emulator stuff. */
143 union mips_fpu_union fpu;
145 /* Other stuff associated with the thread. */
146 unsigned long cp0_badvaddr; /* Last user fault */
147 unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
148 unsigned long error_code;
149 unsigned long trap_no;
150 #define MF_FIXADE 1 /* Fix address errors in software */
151 #define MF_LOGADE 2 /* Log address errors to syslog */
152 unsigned long mflags;
153 mm_segment_t current_ds;
154 unsigned long irix_trampoline; /* Wheee... */
155 unsigned long irix_oldctx;
158 * These are really only needed if the full FPU emulator is configured.
159 * Would be made conditional on MIPS_FPU_EMULATOR if it weren't for the
160 * fact that having offset.h rebuilt differently for different config
161 * options would be asking for trouble.
163 * Saved EPC during delay-slot emulation (see math-emu/cp1emu.c)
165 unsigned long dsemul_epc;
168 * Pointer to instruction used to induce address error
170 unsigned long dsemul_aerpc;
173 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
175 #define INIT_THREAD { \
177 * saved main processor registers \
179 0, 0, 0, 0, 0, 0, 0, 0, \
186 * saved fpu/fpu emulator stuff \
190 * Other stuff associated with the process \
194 * For now the default is to fix address errors \
196 MF_FIXADE, { 0 }, 0, 0, \
198 * dsemul_epc and dsemul_aerpc should never be used uninitialized, \
206 #define KERNEL_STACK_SIZE 8192
208 #if !defined (_LANGUAGE_ASSEMBLY)
210 /* Free all resources held by a thread. */
211 #define release_thread(thread) do { } while(0)
213 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
215 /* Copy and release all segment info associated with a VM */
216 #define copy_segments(p, mm) do { } while(0)
217 #define release_segments(mm) do { } while(0)
220 * Return saved PC of a blocked thread.
222 extern inline unsigned long thread_saved_pc(struct thread_struct *t)
224 extern void ret_from_fork(void);
226 /* New born processes are a special case */
227 if (t->reg31 == (unsigned long) ret_from_fork)
230 return ((unsigned long *)t->reg29)[10];
234 * Do necessary setup to start up a newly executed thread.
236 #define start_thread(regs, new_pc, new_sp) do { \
237 /* New thread looses kernel privileges. */ \
238 regs->cp0_status = (regs->cp0_status & ~(ST0_CU0|ST0_KSU)) | KU_USER;\
239 regs->cp0_epc = new_pc; \
240 regs->regs[29] = new_sp; \
241 current->thread.current_ds = USER_DS; \
244 unsigned long get_wchan(struct task_struct *p);
246 #define __PT_REG(reg) ((long)&((struct pt_regs *)0)->reg - sizeof(struct pt_regs))
247 #define __KSTK_TOS(tsk) ((unsigned long)(tsk) + KERNEL_STACK_SIZE - 32)
248 #define KSTK_EIP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_epc)))
249 #define KSTK_ESP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(regs[29])))
251 /* Allocation and freeing of basic task resources. */
253 * NOTE! The task struct and the stack go together
255 #define THREAD_SIZE (2*PAGE_SIZE)
256 #define alloc_task_struct() \
257 ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
258 #define free_task_struct(p) free_pages((unsigned long)(p),1)
259 #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
261 #define init_task (init_task_union.task)
262 #define init_stack (init_task_union.stack)
264 #define cpu_relax() do { } while (0)
266 #endif /* !defined (_LANGUAGE_ASSEMBLY) */
267 #endif /* __KERNEL__ */
270 * Return_address is a replacement for __builtin_return_address(count)
271 * which on certain architectures cannot reasonably be implemented in GCC
272 * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
273 * Note that __builtin_return_address(x>=1) is forbidden because GCC
274 * aborts compilation on some CPUs. It's simply not possible to unwind
275 * some CPU's stackframes.
277 * __builtin_return_address works only for non-leaf functions. We avoid the
278 * overhead of a function call by forcing the compiler to save the return
279 * address register on the stack.
281 #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
283 #endif /* _ASM_PROCESSOR_H */