blob: fd7866dc8c83462b2d8a3274ac4118b5315de8d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/asm-parisc/processor.h
3 *
4 * Copyright (C) 1994 Linus Torvalds
5 * Copyright (C) 2001 Grant Grundler
6 */
7
8#ifndef __ASM_PARISC_PROCESSOR_H
9#define __ASM_PARISC_PROCESSOR_H
10
11#ifndef __ASSEMBLY__
Kyle McMartin4068d932006-08-13 22:15:47 -040012#include <asm/prefetch.h> /* lockdep.h needs <linux/prefetch.h> */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/threads.h>
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070015#include <linux/spinlock_types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <asm/hardware.h>
18#include <asm/page.h>
19#include <asm/pdc.h>
20#include <asm/ptrace.h>
21#include <asm/types.h>
22#include <asm/system.h>
23#endif /* __ASSEMBLY__ */
24
25#define KERNEL_STACK_SIZE (4*PAGE_SIZE)
26
27/*
28 * Default implementation of macro that returns current
29 * instruction pointer ("program counter").
30 */
Kyle McMartin1b6d1b52006-05-19 20:18:17 +000031#ifdef CONFIG_PA20
32#define current_ia(x) __asm__("mfia %0" : "=r"(x))
33#else /* mfia added in pa2.0 */
34#define current_ia(x) __asm__("blr 0,%0\n\tnop" : "=r"(x))
35#endif
36#define current_text_addr() ({ void *pc; current_ia(pc); pc; })
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#define TASK_SIZE (current->thread.task_size)
39#define TASK_UNMAPPED_BASE (current->thread.map_base)
40
41#define DEFAULT_TASK_SIZE32 (0xFFF00000UL)
42#define DEFAULT_MAP_BASE32 (0x40000000UL)
43
44#ifdef __LP64__
45#define DEFAULT_TASK_SIZE (MAX_ADDRESS-0xf000000)
46#define DEFAULT_MAP_BASE (0x200000000UL)
47#else
48#define DEFAULT_TASK_SIZE DEFAULT_TASK_SIZE32
49#define DEFAULT_MAP_BASE DEFAULT_MAP_BASE32
50#endif
51
52#ifndef __ASSEMBLY__
53
54/*
55 * Data detected about CPUs at boot time which is the same for all CPU's.
56 * HP boxes are SMP - ie identical processors.
57 *
58 * FIXME: some CPU rev info may be processor specific...
59 */
60struct system_cpuinfo_parisc {
61 unsigned int cpu_count;
62 unsigned int cpu_hz;
63 unsigned int hversion;
64 unsigned int sversion;
65 enum cpu_type cpu_type;
66
67 struct {
68 struct pdc_model model;
69 unsigned long versions;
70 unsigned long cpuid;
71 unsigned long capabilities;
72 char sys_model_name[81]; /* PDC-ROM returnes this model name */
73 } pdc;
74
75 char *cpu_name; /* e.g. "PA7300LC (PCX-L2)" */
76 char *family_name; /* e.g. "1.1e" */
77};
78
79
80/* Per CPU data structure - ie varies per CPU. */
81struct cpuinfo_parisc {
82 unsigned long it_value; /* Interval Timer at last timer Intr */
83 unsigned long it_delta; /* Interval delta (tic_10ms / HZ * 100) */
84 unsigned long irq_count; /* number of IRQ's since boot */
85 unsigned long irq_max_cr16; /* longest time to handle a single IRQ */
86 unsigned long cpuid; /* aka slot_number or set to NO_PROC_ID */
87 unsigned long hpa; /* Host Physical address */
88 unsigned long txn_addr; /* MMIO addr of EIR or id_eid */
89#ifdef CONFIG_SMP
90 spinlock_t lock; /* synchronization for ipi's */
91 unsigned long pending_ipi; /* bitmap of type ipi_message_type */
92 unsigned long ipi_count; /* number ipi Interrupts */
93#endif
94 unsigned long bh_count; /* number of times bh was invoked */
95 unsigned long prof_counter; /* per CPU profiling support */
96 unsigned long prof_multiplier; /* per CPU profiling support */
97 unsigned long fp_rev;
98 unsigned long fp_model;
99 unsigned int state;
100 struct parisc_device *dev;
101 unsigned long loops_per_jiffy;
102};
103
104extern struct system_cpuinfo_parisc boot_cpu_data;
105extern struct cpuinfo_parisc cpu_data[NR_CPUS];
106#define current_cpu_data cpu_data[smp_processor_id()]
107
108#define CPU_HVERSION ((boot_cpu_data.hversion >> 4) & 0x0FFF)
109
110typedef struct {
111 int seg;
112} mm_segment_t;
113
114#define ARCH_MIN_TASKALIGN 8
115
116struct thread_struct {
117 struct pt_regs regs;
118 unsigned long task_size;
119 unsigned long map_base;
120 unsigned long flags;
121};
122
123/* Thread struct flags. */
Kyle McMartinf0537252005-10-21 22:43:15 -0400124#define PARISC_UAC_NOPRINT (1UL << 0) /* see prctl and unaligned.c */
125#define PARISC_UAC_SIGBUS (1UL << 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define PARISC_KERNEL_DEATH (1UL << 31) /* see die_if_kernel()... */
127
Kyle McMartinf0537252005-10-21 22:43:15 -0400128#define PARISC_UAC_SHIFT 0
129#define PARISC_UAC_MASK (PARISC_UAC_NOPRINT|PARISC_UAC_SIGBUS)
130
131#define SET_UNALIGN_CTL(task,value) \
132 ({ \
133 (task)->thread.flags = (((task)->thread.flags & ~PARISC_UAC_MASK) \
134 | (((value) << PARISC_UAC_SHIFT) & \
135 PARISC_UAC_MASK)); \
136 0; \
137 })
138
139#define GET_UNALIGN_CTL(task,addr) \
140 ({ \
141 put_user(((task)->thread.flags & PARISC_UAC_MASK) \
142 >> PARISC_UAC_SHIFT, (int __user *) (addr)); \
143 })
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define INIT_THREAD { \
Alexey Dobriyan02d79802006-01-10 20:48:02 -0500146 .regs = { .gr = { 0, }, \
147 .fr = { 0, }, \
148 .sr = { 0, }, \
149 .iasq = { 0, }, \
150 .iaoq = { 0, }, \
151 .cr27 = 0, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }, \
Alexey Dobriyan02d79802006-01-10 20:48:02 -0500153 .task_size = DEFAULT_TASK_SIZE, \
154 .map_base = DEFAULT_MAP_BASE, \
155 .flags = 0 \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
158/*
159 * Return saved PC of a blocked thread. This is used by ps mostly.
160 */
161
162unsigned long thread_saved_pc(struct task_struct *t);
163void show_trace(struct task_struct *task, unsigned long *stack);
164
165/*
166 * Start user thread in another space.
167 *
168 * Note that we set both the iaoq and r31 to the new pc. When
169 * the kernel initially calls execve it will return through an
170 * rfi path that will use the values in the iaoq. The execve
171 * syscall path will return through the gateway page, and
172 * that uses r31 to branch to.
173 *
174 * For ELF we clear r23, because the dynamic linker uses it to pass
175 * the address of the finalizer function.
176 *
177 * We also initialize sr3 to an illegal value (illegal for our
178 * implementation, not for the architecture).
179 */
180typedef unsigned int elf_caddr_t;
181
182#define start_thread_som(regs, new_pc, new_sp) do { \
183 unsigned long *sp = (unsigned long *)new_sp; \
184 __u32 spaceid = (__u32)current->mm->context; \
185 unsigned long pc = (unsigned long)new_pc; \
186 /* offset pc for priv. level */ \
187 pc |= 3; \
188 \
189 set_fs(USER_DS); \
190 regs->iasq[0] = spaceid; \
191 regs->iasq[1] = spaceid; \
192 regs->iaoq[0] = pc; \
193 regs->iaoq[1] = pc + 4; \
194 regs->sr[2] = LINUX_GATEWAY_SPACE; \
195 regs->sr[3] = 0xffff; \
196 regs->sr[4] = spaceid; \
197 regs->sr[5] = spaceid; \
198 regs->sr[6] = spaceid; \
199 regs->sr[7] = spaceid; \
200 regs->gr[ 0] = USER_PSW; \
201 regs->gr[30] = ((new_sp)+63)&~63; \
202 regs->gr[31] = pc; \
203 \
204 get_user(regs->gr[26],&sp[0]); \
205 get_user(regs->gr[25],&sp[-1]); \
206 get_user(regs->gr[24],&sp[-2]); \
207 get_user(regs->gr[23],&sp[-3]); \
208} while(0)
209
210/* The ELF abi wants things done a "wee bit" differently than
211 * som does. Supporting this behavior here avoids
212 * having our own version of create_elf_tables.
213 *
214 * Oh, and yes, that is not a typo, we are really passing argc in r25
215 * and argv in r24 (rather than r26 and r25). This is because that's
216 * where __libc_start_main wants them.
217 *
218 * Duplicated from dl-machine.h for the benefit of readers:
219 *
220 * Our initial stack layout is rather different from everyone else's
221 * due to the unique PA-RISC ABI. As far as I know it looks like
222 * this:
223
224 ----------------------------------- (user startup code creates this frame)
225 | 32 bytes of magic |
226 |---------------------------------|
227 | 32 bytes argument/sp save area |
228 |---------------------------------| (bprm->p)
229 | ELF auxiliary info |
230 | (up to 28 words) |
231 |---------------------------------|
232 | NULL |
233 |---------------------------------|
234 | Environment pointers |
235 |---------------------------------|
236 | NULL |
237 |---------------------------------|
238 | Argument pointers |
239 |---------------------------------| <- argv
240 | argc (1 word) |
241 |---------------------------------| <- bprm->exec (HACK!)
242 | N bytes of slack |
243 |---------------------------------|
244 | filename passed to execve |
245 |---------------------------------| (mm->env_end)
246 | env strings |
247 |---------------------------------| (mm->env_start, mm->arg_end)
248 | arg strings |
249 |---------------------------------|
250 | additional faked arg strings if |
251 | we're invoked via binfmt_script |
252 |---------------------------------| (mm->arg_start)
253 stack base is at TASK_SIZE - rlim_max.
254
255on downward growing arches, it looks like this:
256 stack base at TASK_SIZE
257 | filename passed to execve
258 | env strings
259 | arg strings
260 | faked arg strings
261 | slack
262 | ELF
263 | envps
264 | argvs
265 | argc
266
267 * The pleasant part of this is that if we need to skip arguments we
268 * can just decrement argc and move argv, because the stack pointer
269 * is utterly unrelated to the location of the environment and
270 * argument vectors.
271 *
272 * Note that the S/390 people took the easy way out and hacked their
273 * GCC to make the stack grow downwards.
274 *
275 * Final Note: For entry from syscall, the W (wide) bit of the PSW
276 * is stuffed into the lowest bit of the user sp (%r30), so we fill
277 * it in here from the current->personality
278 */
279
280#ifdef __LP64__
Kyle McMartindf570b92006-08-27 11:04:26 -0400281#define USER_WIDE_MODE (!test_thread_flag(TIF_32BIT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#else
283#define USER_WIDE_MODE 0
284#endif
285
286#define start_thread(regs, new_pc, new_sp) do { \
287 elf_addr_t *sp = (elf_addr_t *)new_sp; \
288 __u32 spaceid = (__u32)current->mm->context; \
289 elf_addr_t pc = (elf_addr_t)new_pc | 3; \
290 elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1; \
291 \
292 set_fs(USER_DS); \
293 regs->iasq[0] = spaceid; \
294 regs->iasq[1] = spaceid; \
295 regs->iaoq[0] = pc; \
296 regs->iaoq[1] = pc + 4; \
297 regs->sr[2] = LINUX_GATEWAY_SPACE; \
298 regs->sr[3] = 0xffff; \
299 regs->sr[4] = spaceid; \
300 regs->sr[5] = spaceid; \
301 regs->sr[6] = spaceid; \
302 regs->sr[7] = spaceid; \
303 regs->gr[ 0] = USER_PSW | (USER_WIDE_MODE ? PSW_W : 0); \
304 regs->fr[ 0] = 0LL; \
305 regs->fr[ 1] = 0LL; \
306 regs->fr[ 2] = 0LL; \
307 regs->fr[ 3] = 0LL; \
308 regs->gr[30] = (((unsigned long)sp + 63) &~ 63) | (USER_WIDE_MODE ? 1 : 0); \
309 regs->gr[31] = pc; \
310 \
311 get_user(regs->gr[25], (argv - 1)); \
312 regs->gr[24] = (long) argv; \
313 regs->gr[23] = 0; \
314} while(0)
315
316struct task_struct;
317struct mm_struct;
318
319/* Free all resources held by a thread. */
320extern void release_thread(struct task_struct *);
321extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
322
323/* Prepare to copy thread state - unlazy all lazy status */
324#define prepare_to_copy(tsk) do { } while (0)
325
326extern void map_hpux_gateway_page(struct task_struct *tsk, struct mm_struct *mm);
327
328extern unsigned long get_wchan(struct task_struct *p);
329
330#define KSTK_EIP(tsk) ((tsk)->thread.regs.iaoq[0])
331#define KSTK_ESP(tsk) ((tsk)->thread.regs.gr[30])
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#define cpu_relax() barrier()
334
James Bottomley20f4d3c2006-08-23 09:00:04 -0700335/* Used as a macro to identify the combined VIPT/PIPT cached
336 * CPUs which require a guarantee of coherency (no inequivalent
337 * aliases with different data, whether clean or not) to operate */
338static inline int parisc_requires_coherency(void)
339{
340#ifdef CONFIG_PA8X00
341 /* FIXME: also pa8900 - when we see one */
342 return boot_cpu_data.cpu_type == mako;
343#else
344 return 0;
345#endif
346}
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#endif /* __ASSEMBLY__ */
349
350#endif /* __ASM_PARISC_PROCESSOR_H */