blob: 6838aee98cc8198ce621980199c66c91641eaed2 [file] [log] [blame]
wdenk6069ff22003-02-28 00:49:47 +00001/*
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#if 0
26#include <linux/threads.h>
27#endif
28#include <asm/cachectl.h>
29#include <asm/mipsregs.h>
30#include <asm/reg.h>
31#include <asm/system.h>
32
33struct mips_cpuinfo {
34 unsigned long udelay_val;
35 unsigned long *pgd_quick;
36 unsigned long *pte_quick;
37 unsigned long pgtable_cache_sz;
38};
39
40/*
41 * System setup and hardware flags..
42 * XXX: Should go into mips_cpuinfo.
43 */
44extern void (*cpu_wait)(void); /* only available on R4[26]00 and R3081 */
45extern void r3081_wait(void);
46extern void r4k_wait(void);
47extern char cyclecounter_available; /* only available from R4000 upwards. */
48
49extern struct mips_cpuinfo boot_cpu_data;
50extern unsigned int vced_count, vcei_count;
51
52#ifdef CONFIG_SMP
53extern struct mips_cpuinfo cpu_data[];
54#define current_cpu_data cpu_data[smp_processor_id()]
55#else
56#define cpu_data &boot_cpu_data
57#define current_cpu_data boot_cpu_data
58#endif
59
60/*
61 * Bus types (default is ISA, but people can check others with these..)
62 * MCA_bus hardcoded to 0 for now.
63 *
64 * This needs to be extended since MIPS systems are being delivered with
65 * numerous different types of bus systems.
66 */
67extern int EISA_bus;
68#define MCA_bus 0
69#define MCA_bus__is_a_macro /* for versions in ksyms.c */
70
71/*
72 * MIPS has no problems with write protection
73 */
74#define wp_works_ok 1
75#define wp_works_ok__is_a_macro /* for versions in ksyms.c */
76
77/* Lazy FPU handling on uni-processor */
78extern struct task_struct *last_task_used_math;
79
80/*
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 ...
85 */
86#define TASK_SIZE (0x7fff8000UL)
87
88/* This decides where the kernel will search for a free chunk of vm
89 * space during mmap's.
90 */
91#define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
92
93/*
94 * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
95 */
96#define IO_BITMAP_SIZE 32
97
98#define NUM_FPU_REGS 32
99
100struct mips_fpu_hard_struct {
101 double fp_regs[NUM_FPU_REGS];
102 unsigned int control;
103};
104
105/*
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.
110 */
111typedef u64 fpureg_t;
112struct mips_fpu_soft_struct {
113 fpureg_t regs[NUM_FPU_REGS];
114 unsigned int sr;
115};
116
117union mips_fpu_union {
wdenk8bde7f72003-06-27 21:31:46 +0000118 struct mips_fpu_hard_struct hard;
119 struct mips_fpu_soft_struct soft;
wdenk6069ff22003-02-28 00:49:47 +0000120};
121
122#define INIT_FPU { \
123 {{0,},} \
124}
125
126typedef struct {
127 unsigned long seg;
128} mm_segment_t;
129
130/*
131 * If you change thread_struct remember to change the #defines below too!
132 */
133struct thread_struct {
134 /* Saved main processor registers. */
135 unsigned long reg16;
136 unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
137 unsigned long reg29, reg30, reg31;
138
139 /* Saved cp0 stuff. */
140 unsigned long cp0_status;
141
142 /* Saved fpu/fpu emulator stuff. */
143 union mips_fpu_union fpu;
144
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;
156
157 /*
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.
162 *
163 * Saved EPC during delay-slot emulation (see math-emu/cp1emu.c)
164 */
165 unsigned long dsemul_epc;
166
167 /*
168 * Pointer to instruction used to induce address error
169 */
170 unsigned long dsemul_aerpc;
171};
172
173#endif /* !defined (_LANGUAGE_ASSEMBLY) */
174
175#define INIT_THREAD { \
wdenk8bde7f72003-06-27 21:31:46 +0000176 /* \
177 * saved main processor registers \
178 */ \
wdenk6069ff22003-02-28 00:49:47 +0000179 0, 0, 0, 0, 0, 0, 0, 0, \
wdenk8bde7f72003-06-27 21:31:46 +0000180 0, 0, 0, \
wdenk6069ff22003-02-28 00:49:47 +0000181 /* \
182 * saved cp0 stuff \
183 */ \
184 0, \
185 /* \
186 * saved fpu/fpu emulator stuff \
187 */ \
188 INIT_FPU, \
189 /* \
190 * Other stuff associated with the process \
191 */ \
192 0, 0, 0, 0, \
193 /* \
194 * For now the default is to fix address errors \
195 */ \
196 MF_FIXADE, { 0 }, 0, 0, \
197 /* \
198 * dsemul_epc and dsemul_aerpc should never be used uninitialized, \
199 * but... \
200 */ \
201 0 ,0 \
202}
203
204#ifdef __KERNEL__
205
206#define KERNEL_STACK_SIZE 8192
207
208#if !defined (_LANGUAGE_ASSEMBLY)
209
210/* Free all resources held by a thread. */
211#define release_thread(thread) do { } while(0)
212
213extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
214
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)
218
219/*
220 * Return saved PC of a blocked thread.
221 */
222extern inline unsigned long thread_saved_pc(struct thread_struct *t)
223{
224 extern void ret_from_fork(void);
225
226 /* New born processes are a special case */
227 if (t->reg31 == (unsigned long) ret_from_fork)
228 return t->reg31;
229
230 return ((unsigned long *)t->reg29)[10];
231}
232
233/*
234 * Do necessary setup to start up a newly executed thread.
235 */
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; \
242} while (0)
243
244unsigned long get_wchan(struct task_struct *p);
245
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])))
250
251/* Allocation and freeing of basic task resources. */
252/*
253 * NOTE! The task struct and the stack go together
254 */
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)
260
261#define init_task (init_task_union.task)
262#define init_stack (init_task_union.stack)
263
264#define cpu_relax() do { } while (0)
265
266#endif /* !defined (_LANGUAGE_ASSEMBLY) */
267#endif /* __KERNEL__ */
268
269/*
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.
276 *
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.
280 */
281#define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
282
283#endif /* _ASM_PROCESSOR_H */