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, 2000 Ralf Baechle
8 * Modified further for R[236]000 compatibility by Paul M. Antoine
9 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
11 #ifndef _ASM_PROCESSOR_H
12 #define _ASM_PROCESSOR_H
14 #include <linux/config.h>
17 * Return current * instruction pointer ("program counter").
19 #define current_text_addr() \
23 __asm__ ("bal\t1f\t\t\t# current_text_addr\n" \
33 #include <asm/cachectl.h>
34 #include <asm/mipsregs.h>
36 #include <asm/system.h>
38 #if defined(CONFIG_SGI_IP27)
39 #include <asm/sn/types.h>
40 #include <asm/sn/intr_public.h>
44 unsigned long udelay_val;
45 unsigned long *pgd_quick;
46 unsigned long *pmd_quick;
47 unsigned long *pte_quick;
48 unsigned long pgtable_cache_sz;
49 unsigned long last_asn;
50 unsigned long asid_cache;
51 #if defined(CONFIG_SGI_IP27)
52 cpuid_t p_cpuid; /* PROM assigned cpuid */
53 cnodeid_t p_nodeid; /* my node ID in compact-id-space */
54 nasid_t p_nasid; /* my node ID in numa-as-id-space */
55 unsigned char p_slice; /* Physical position on node board */
56 hub_intmasks_t p_intmasks; /* SN0 per-CPU interrupt masks */
59 unsigned long loops_per_sec;
60 unsigned long pgtable_cache_sz;
61 unsigned long ipi_count;
62 unsigned long irq_attempt[NR_IRQS];
63 unsigned long smp_local_irq_count;
64 unsigned long prof_multiplier;
65 unsigned long prof_counter;
67 } __attribute__((aligned(128)));
70 * System setup and hardware flags..
71 * XXX: Should go into mips_cpuinfo.
73 extern void (*cpu_wait)(void);
74 extern void r3081_wait(void);
75 extern void r39xx_wait(void);
76 extern void r4k_wait(void);
77 extern void au1k_wait(void);
79 extern unsigned int vced_count, vcei_count;
80 extern struct cpuinfo_mips cpu_data[];
83 #define current_cpu_data cpu_data[smp_processor_id()]
85 #define current_cpu_data cpu_data[0]
89 * Bus types (default is ISA, but people can check others with these..)
98 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
101 * MIPS has no problems with write protection
103 #define wp_works_ok 1
104 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
106 /* Lazy FPU handling on uni-processor */
107 extern struct task_struct *last_task_used_math;
110 #define IS_FPU_OWNER() (last_task_used_math == current)
111 #define CLEAR_FPU_OWNER() last_task_used_math = NULL;
113 #define IS_FPU_OWNER() (current->flags & PF_USEDFPU)
114 #define CLEAR_FPU_OWNER() current->flags &= ~PF_USEDFPU;
118 * User space process size: 1TB. This is hardcoded into a few places,
119 * so don't change it unless you know what you are doing. TASK_SIZE
120 * is limited to 1TB by the R4000 architecture; R10000 and better can
123 #define TASK_SIZE32 0x7fff8000UL
124 #define TASK_SIZE 0x10000000000UL
126 /* This decides where the kernel will search for a free chunk of vm
127 * space during mmap's.
129 #define TASK_UNMAPPED_BASE ((current->thread.mflags & MF_32BIT) ? \
130 (TASK_SIZE32 / 3) : (TASK_SIZE / 3))
133 * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
135 #define IO_BITMAP_SIZE 32
137 #define NUM_FPU_REGS 32
139 struct mips_fpu_hard_struct {
140 unsigned long fp_regs[NUM_FPU_REGS];
141 unsigned int control;
145 * It would be nice to add some more fields for emulator statistics, but there
146 * are a number of fixed offsets in offset.h and elsewhere that would have to
147 * be recalculated by hand. So the additional information will be private to
148 * the FPU emulator for now. See asm-mips/fpu_emulator.h.
150 typedef u64 fpureg_t;
151 struct mips_fpu_soft_struct {
152 fpureg_t regs[NUM_FPU_REGS];
157 union mips_fpu_union {
158 struct mips_fpu_hard_struct hard;
159 struct mips_fpu_soft_struct soft;
171 * If you change thread_struct remember to change the #defines below too!
173 struct thread_struct {
174 /* Saved main processor registers. */
176 unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
177 unsigned long reg29, reg30, reg31;
179 /* Saved cp0 stuff. */
180 unsigned long cp0_status;
182 /* Saved fpu/fpu emulator stuff. */
183 union mips_fpu_union fpu;
185 /* Other stuff associated with the thread. */
186 unsigned long cp0_badvaddr; /* Last user fault */
187 unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
188 unsigned long error_code;
189 unsigned long trap_no;
190 #define MF_FIXADE 1 /* Fix address errors in software */
191 #define MF_LOGADE 2 /* Log address errors to syslog */
192 #define MF_32BIT 4 /* Process is in 32-bit compat mode */
193 unsigned long mflags;
194 mm_segment_t current_ds;
195 unsigned long irix_trampoline; /* Wheee... */
196 unsigned long irix_oldctx;
199 #endif /* !__ASSEMBLY__ */
201 #define INIT_THREAD { \
203 * saved main processor registers \
205 0, 0, 0, 0, 0, 0, 0, 0, \
212 * saved fpu/fpu emulator stuff \
216 * Other stuff associated with the process \
220 * For now the default is to fix address errors \
222 MF_FIXADE, { 0 }, 0, 0 \
227 #define KERNEL_STACK_SIZE 0x4000
231 /* Free all resources held by a thread. */
232 #define release_thread(thread) do { } while(0)
234 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
236 /* Copy and release all segment info associated with a VM */
237 #define copy_segments(p, mm) do { } while(0)
238 #define release_segments(mm) do { } while(0)
241 * Return saved PC of a blocked thread.
243 static inline unsigned long thread_saved_pc(struct thread_struct *t)
245 extern void ret_from_sys_call(void);
247 /* New born processes are a special case */
248 if (t->reg31 == (unsigned long) ret_from_sys_call)
251 return ((unsigned long*)t->reg29)[11];
254 #define user_mode(regs) (((regs)->cp0_status & ST0_KSU) == KSU_USER)
257 * Do necessary setup to start up a newly executed thread.
259 #define start_thread(regs, pc, sp) \
261 unsigned long __status; \
263 /* New thread looses kernel privileges. */ \
264 __status = regs->cp0_status & ~(ST0_CU0|ST0_FR|ST0_KSU); \
265 __status |= KSU_USER; \
266 __status |= (current->thread.mflags & MF_32BIT) ? 0 : ST0_FR; \
267 regs->cp0_status = __status; \
268 regs->cp0_epc = pc; \
269 regs->regs[29] = sp; \
270 current->thread.current_ds = USER_DS; \
273 unsigned long get_wchan(struct task_struct *p);
275 #define __PT_REG(reg) ((long)&((struct pt_regs *)0)->reg - sizeof(struct pt_regs))
276 #define __KSTK_TOS(tsk) ((unsigned long)(tsk) + KERNEL_STACK_SIZE - 32)
277 #define KSTK_EIP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_epc)))
278 #define KSTK_ESP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(regs[29])))
280 /* Allocation and freeing of basic task resources. */
282 * NOTE! The task struct and the stack go together
284 #define THREAD_SIZE (2*PAGE_SIZE)
285 #define alloc_task_struct() \
286 ((struct task_struct *) __get_free_pages(GFP_KERNEL, 2))
287 #define free_task_struct(p) free_pages((unsigned long)(p), 2)
288 #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
290 #define init_task (init_task_union.task)
291 #define init_stack (init_task_union.stack)
293 #define cpu_relax() do { } while (0)
295 #endif /* !__ASSEMBLY__ */
296 #endif /* __KERNEL__ */
299 * Return_address is a replacement for __builtin_return_address(count)
300 * which on certain architectures cannot reasonably be implemented in GCC
301 * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
302 * Note that __builtin_return_address(x>=1) is forbidden because GCC
303 * aborts compilation on some CPUs. It's simply not possible to unwind
304 * some CPU's stackframes.
306 * In gcc 2.8 and newer __builtin_return_address works only for non-leaf
307 * functions. We avoid the overhead of a function call by forcing the
308 * compiler to save the return address register on the stack.
310 #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
312 #endif /* _ASM_PROCESSOR_H */