patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-parisc / processor.h
1 /*
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__
12 #include <linux/config.h>
13 #include <linux/threads.h>
14
15 #include <asm/hardware.h>
16 #include <asm/page.h>
17 #include <asm/pdc.h>
18 #include <asm/ptrace.h>
19 #include <asm/types.h>
20 #include <asm/system.h>
21 #endif /* __ASSEMBLY__ */
22
23 #define KERNEL_STACK_SIZE       (4*PAGE_SIZE)
24
25 /*
26  * Default implementation of macro that returns current
27  * instruction pointer ("program counter").
28  */
29
30 /* We cannot use MFIA as it was added for PA2.0 - prumpf
31
32    At one point there were no "0f/0b" type local symbols in gas for
33    PA-RISC.  This is no longer true, but this still seems like the
34    nicest way to implement this. */
35
36 #define current_text_addr() ({ void *pc; __asm__("\n\tblr 0,%0\n\tnop":"=r" (pc)); pc; })
37
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  */
60 struct 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.  */
81 struct 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
104 extern struct system_cpuinfo_parisc boot_cpu_data;
105 extern 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
110 #define MCA_bus 0
111 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
112
113 typedef struct {
114         int seg;  
115 } mm_segment_t;
116
117 #define ARCH_MIN_TASKALIGN      8
118
119 struct thread_struct {
120         struct pt_regs regs;
121         unsigned long  task_size;
122         unsigned long  map_base;
123         unsigned long  flags;
124 }; 
125
126 /* Thread struct flags. */
127 #define PARISC_KERNEL_DEATH     (1UL << 31)     /* see die_if_kernel()... */
128
129 #define INIT_THREAD { \
130         regs:   {       gr: { 0, }, \
131                         fr: { 0, }, \
132                         sr: { 0, }, \
133                         iasq: { 0, }, \
134                         iaoq: { 0, }, \
135                         cr27: 0, \
136                 }, \
137         task_size:      DEFAULT_TASK_SIZE, \
138         map_base:       DEFAULT_MAP_BASE, \
139         flags:          0 \
140         }
141
142 /*
143  * Return saved PC of a blocked thread.  This is used by ps mostly.
144  */
145
146 unsigned long thread_saved_pc(struct task_struct *t);
147 void show_trace(struct task_struct *task, unsigned long *stack);
148
149 /*
150  * Start user thread in another space.
151  *
152  * Note that we set both the iaoq and r31 to the new pc. When
153  * the kernel initially calls execve it will return through an
154  * rfi path that will use the values in the iaoq. The execve
155  * syscall path will return through the gateway page, and
156  * that uses r31 to branch to.
157  *
158  * For ELF we clear r23, because the dynamic linker uses it to pass
159  * the address of the finalizer function.
160  *
161  * We also initialize sr3 to an illegal value (illegal for our
162  * implementation, not for the architecture).
163  */
164 typedef unsigned int elf_caddr_t;
165
166 #define start_thread_som(regs, new_pc, new_sp) do {     \
167         unsigned long *sp = (unsigned long *)new_sp;    \
168         __u32 spaceid = (__u32)current->mm->context;    \
169         unsigned long pc = (unsigned long)new_pc;       \
170         /* offset pc for priv. level */                 \
171         pc |= 3;                                        \
172                                                         \
173         set_fs(USER_DS);                                \
174         regs->iasq[0] = spaceid;                        \
175         regs->iasq[1] = spaceid;                        \
176         regs->iaoq[0] = pc;                             \
177         regs->iaoq[1] = pc + 4;                         \
178         regs->sr[2] = LINUX_GATEWAY_SPACE;              \
179         regs->sr[3] = 0xffff;                           \
180         regs->sr[4] = spaceid;                          \
181         regs->sr[5] = spaceid;                          \
182         regs->sr[6] = spaceid;                          \
183         regs->sr[7] = spaceid;                          \
184         regs->gr[ 0] = USER_PSW;                        \
185         regs->gr[30] = ((new_sp)+63)&~63;               \
186         regs->gr[31] = pc;                              \
187                                                         \
188         get_user(regs->gr[26],&sp[0]);                  \
189         get_user(regs->gr[25],&sp[-1]);                 \
190         get_user(regs->gr[24],&sp[-2]);                 \
191         get_user(regs->gr[23],&sp[-3]);                 \
192 } while(0)
193
194 /* The ELF abi wants things done a "wee bit" differently than
195  * som does.  Supporting this behavior here avoids
196  * having our own version of create_elf_tables.
197  *
198  * Oh, and yes, that is not a typo, we are really passing argc in r25
199  * and argv in r24 (rather than r26 and r25).  This is because that's
200  * where __libc_start_main wants them.
201  *
202  * Duplicated from dl-machine.h for the benefit of readers:
203  *
204  *  Our initial stack layout is rather different from everyone else's
205  *  due to the unique PA-RISC ABI.  As far as I know it looks like
206  *  this:
207
208    -----------------------------------  (user startup code creates this frame)
209    |         32 bytes of magic       |
210    |---------------------------------|
211    | 32 bytes argument/sp save area  |
212    |---------------------------------| (bprm->p)
213    |        ELF auxiliary info       |
214    |         (up to 28 words)        |
215    |---------------------------------|
216    |               NULL              |
217    |---------------------------------|
218    |       Environment pointers      |
219    |---------------------------------|
220    |               NULL              |
221    |---------------------------------|
222    |        Argument pointers        |
223    |---------------------------------| <- argv
224    |          argc (1 word)          |
225    |---------------------------------| <- bprm->exec (HACK!)
226    |         N bytes of slack        |
227    |---------------------------------|
228    |    filename passed to execve    |
229    |---------------------------------| (mm->env_end)
230    |           env strings           |
231    |---------------------------------| (mm->env_start, mm->arg_end)
232    |           arg strings           |
233    |---------------------------------|
234    | additional faked arg strings if |
235    | we're invoked via binfmt_script |
236    |---------------------------------| (mm->arg_start)
237    stack base is at TASK_SIZE - rlim_max.
238
239 on downward growing arches, it looks like this:
240    stack base at TASK_SIZE
241    | filename passed to execve
242    | env strings
243    | arg strings
244    | faked arg strings
245    | slack
246    | ELF
247    | envps
248    | argvs
249    | argc
250
251  *  The pleasant part of this is that if we need to skip arguments we
252  *  can just decrement argc and move argv, because the stack pointer
253  *  is utterly unrelated to the location of the environment and
254  *  argument vectors.
255  *
256  * Note that the S/390 people took the easy way out and hacked their
257  * GCC to make the stack grow downwards.
258  *
259  * Final Note: For entry from syscall, the W (wide) bit of the PSW
260  * is stuffed into the lowest bit of the user sp (%r30), so we fill
261  * it in here from the current->personality
262  */
263
264 #ifdef __LP64__
265 #define USER_WIDE_MODE  (personality(current->personality) == PER_LINUX)
266 #else
267 #define USER_WIDE_MODE  0
268 #endif
269
270 #define start_thread(regs, new_pc, new_sp) do {         \
271         elf_addr_t *sp = (elf_addr_t *)new_sp;          \
272         __u32 spaceid = (__u32)current->mm->context;    \
273         elf_addr_t pc = (elf_addr_t)new_pc | 3;         \
274         elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1;      \
275                                                         \
276         set_fs(USER_DS);                                \
277         regs->iasq[0] = spaceid;                        \
278         regs->iasq[1] = spaceid;                        \
279         regs->iaoq[0] = pc;                             \
280         regs->iaoq[1] = pc + 4;                         \
281         regs->sr[2] = LINUX_GATEWAY_SPACE;              \
282         regs->sr[3] = 0xffff;                           \
283         regs->sr[4] = spaceid;                          \
284         regs->sr[5] = spaceid;                          \
285         regs->sr[6] = spaceid;                          \
286         regs->sr[7] = spaceid;                          \
287         regs->gr[ 0] = USER_PSW | (USER_WIDE_MODE ? PSW_W : 0); \
288         regs->fr[ 0] = 0LL;                             \
289         regs->fr[ 1] = 0LL;                             \
290         regs->fr[ 2] = 0LL;                             \
291         regs->fr[ 3] = 0LL;                             \
292         regs->gr[30] = (((unsigned long)sp + 63) &~ 63) | (USER_WIDE_MODE ? 1 : 0); \
293         regs->gr[31] = pc;                              \
294                                                         \
295         get_user(regs->gr[25], (argv - 1));             \
296         regs->gr[24] = (long) argv;                     \
297         regs->gr[23] = 0;                               \
298 } while(0)
299
300 struct task_struct;
301 struct mm_struct;
302
303 /* Free all resources held by a thread. */
304 extern void release_thread(struct task_struct *);
305 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
306
307 /* Prepare to copy thread state - unlazy all lazy status */
308 #define prepare_to_copy(tsk)    do { } while (0)
309
310 extern void map_hpux_gateway_page(struct task_struct *tsk, struct mm_struct *mm);
311
312 extern unsigned long get_wchan(struct task_struct *p);
313
314 #define KSTK_EIP(tsk)   ((tsk)->thread.regs.iaoq[0])
315 #define KSTK_ESP(tsk)   ((tsk)->thread.regs.gr[30])
316
317
318 /*
319  * PA 2.0 defines data prefetch instructions on page 6-11 of the Kane book.
320  * In addition, many implementations do hardware prefetching of both
321  * instructions and data.
322  *
323  * PA7300LC (page 14-4 of the ERS) also implements prefetching by a load
324  * to gr0 but not in a way that Linux can use.  If the load would cause an
325  * interruption (eg due to prefetching 0), it is suppressed on PA2.0
326  * processors, but not on 7300LC.
327  */
328 #ifdef  CONFIG_PREFETCH
329 #define ARCH_HAS_PREFETCH
330 #define ARCH_HAS_PREFETCHW
331
332 extern inline void prefetch(const void *addr)
333 {
334         __asm__("ldw 0(%0), %%r0" : : "r" (addr));
335 }
336
337 extern inline void prefetchw(const void *addr)
338 {
339         __asm__("ldd 0(%0), %%r0" : : "r" (addr));
340 }
341 #endif
342
343 #define cpu_relax()     barrier()
344
345 #endif /* __ASSEMBLY__ */
346
347 #endif /* __ASM_PARISC_PROCESSOR_H */