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