make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-mips64 / 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, 2000 Ralf Baechle
8  * Modified further for R[236]000 compatibility by 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>
15
16 /*
17  * Return current * instruction pointer ("program counter").
18  */
19 #define current_text_addr()                                             \
20 ({                                                                      \
21         void *_a;                                                       \
22                                                                         \
23         __asm__ ("bal\t1f\t\t\t# current_text_addr\n"                   \
24                 "1:\tmove\t%0, $31"                                     \
25                 : "=r" (_a)                                             \
26                 :                                                       \
27                 : "$31");                                               \
28                                                                         \
29         _a;                                                             \
30 })
31
32 #ifndef __ASSEMBLY__
33 #include <asm/cachectl.h>
34 #include <asm/mipsregs.h>
35 #include <asm/reg.h>
36 #include <asm/system.h>
37
38 #if defined(CONFIG_SGI_IP27)
39 #include <asm/sn/types.h>
40 #include <asm/sn/intr_public.h>
41 #endif
42
43 struct cpuinfo_mips {
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 */
57 #endif
58 #if 0
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;
66 #endif
67 } __attribute__((aligned(128)));
68
69 /*
70  * System setup and hardware flags..
71  * XXX: Should go into mips_cpuinfo.
72  */
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);
78
79 extern unsigned int vced_count, vcei_count;
80 extern struct cpuinfo_mips cpu_data[];
81
82 #ifdef CONFIG_SMP
83 #define current_cpu_data cpu_data[smp_processor_id()]
84 #else
85 #define current_cpu_data cpu_data[0]
86 #endif
87
88 /*
89  * Bus types (default is ISA, but people can check others with these..)
90  */
91 #ifdef CONFIG_EISA
92 extern int EISA_bus;
93 #else
94 #define EISA_bus (0)
95 #endif
96
97 #define MCA_bus 0
98 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
99
100 /*
101  * MIPS has no problems with write protection
102  */
103 #define wp_works_ok 1
104 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
105
106 /* Lazy FPU handling on uni-processor */
107 extern struct task_struct *last_task_used_math;
108
109 #ifndef CONFIG_SMP
110 #define IS_FPU_OWNER()          (last_task_used_math == current)
111 #define CLEAR_FPU_OWNER()       last_task_used_math = NULL;
112 #else
113 #define IS_FPU_OWNER()          (current->flags & PF_USEDFPU)
114 #define CLEAR_FPU_OWNER()       current->flags &= ~PF_USEDFPU;
115 #endif
116
117 /*
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
121  * support 16TB.
122  */
123 #define TASK_SIZE32        0x7fff8000UL
124 #define TASK_SIZE       0x10000000000UL
125
126 /* This decides where the kernel will search for a free chunk of vm
127  * space during mmap's.
128  */
129 #define TASK_UNMAPPED_BASE      ((current->thread.mflags & MF_32BIT) ? \
130         (TASK_SIZE32 / 3) : (TASK_SIZE / 3))
131
132 /*
133  * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
134  */
135 #define IO_BITMAP_SIZE  32
136
137 #define NUM_FPU_REGS    32
138
139 struct mips_fpu_hard_struct {
140         unsigned long fp_regs[NUM_FPU_REGS];
141         unsigned int control;
142 };
143
144 /*
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.
149  */
150 typedef u64 fpureg_t;
151 struct mips_fpu_soft_struct {
152         fpureg_t        regs[NUM_FPU_REGS];
153         unsigned int    sr;
154 };
155
156
157 union mips_fpu_union {
158         struct mips_fpu_hard_struct hard;
159         struct mips_fpu_soft_struct soft;
160 };
161
162 #define INIT_FPU { \
163         {{0,},} \
164 }
165
166 typedef struct {
167         unsigned long seg;
168 } mm_segment_t;
169
170 /*
171  * If you change thread_struct remember to change the #defines below too!
172  */
173 struct thread_struct {
174         /* Saved main processor registers. */
175         unsigned long reg16;
176         unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
177         unsigned long reg29, reg30, reg31;
178
179         /* Saved cp0 stuff. */
180         unsigned long cp0_status;
181
182         /* Saved fpu/fpu emulator stuff. */
183         union mips_fpu_union fpu;
184
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;
197 };
198
199 #endif /* !__ASSEMBLY__ */
200
201 #define INIT_THREAD  { \
202         /* \
203          * saved main processor registers \
204          */ \
205         0, 0, 0, 0, 0, 0, 0, 0, \
206                        0, 0, 0, \
207         /* \
208          * saved cp0 stuff \
209          */ \
210         0, \
211         /* \
212          * saved fpu/fpu emulator stuff \
213          */ \
214         INIT_FPU, \
215         /* \
216          * Other stuff associated with the process \
217          */ \
218         0, 0, 0, 0, \
219         /* \
220          * For now the default is to fix address errors \
221          */ \
222         MF_FIXADE, { 0 }, 0, 0 \
223 }
224
225 #ifdef __KERNEL__
226
227 #define KERNEL_STACK_SIZE 0x4000
228
229 #ifndef __ASSEMBLY__
230
231 /* Free all resources held by a thread. */
232 #define release_thread(thread) do { } while(0)
233
234 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
235
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)
239
240 /*
241  * Return saved PC of a blocked thread.
242  */
243 static inline unsigned long thread_saved_pc(struct thread_struct *t)
244 {
245         extern void ret_from_sys_call(void);
246
247         /* New born processes are a special case */
248         if (t->reg31 == (unsigned long) ret_from_sys_call)
249                 return t->reg31;
250
251         return ((unsigned long*)t->reg29)[11];
252 }
253
254 #define user_mode(regs) (((regs)->cp0_status & ST0_KSU) == KSU_USER)
255
256 /*
257  * Do necessary setup to start up a newly executed thread.
258  */
259 #define start_thread(regs, pc, sp)                                      \
260 do {                                                                    \
261         unsigned long __status;                                         \
262                                                                         \
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;                           \
271 } while(0)
272
273 unsigned long get_wchan(struct task_struct *p);
274
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])))
279
280 /* Allocation and freeing of basic task resources. */
281 /*
282  * NOTE! The task struct and the stack go together
283  */
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)
289
290 #define init_task       (init_task_union.task)
291 #define init_stack      (init_task_union.stack)
292
293 #define cpu_relax()     do { } while (0)
294
295 #endif /* !__ASSEMBLY__ */
296 #endif /* __KERNEL__ */
297
298 /*
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.
305  *
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.
309  */
310 #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
311
312 #endif /* _ASM_PROCESSOR_H */