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/hardware.h>
15#include <asm/page.h>
16#include <asm/pdc.h>
17#include <asm/ptrace.h>
18#include <asm/types.h>
19#include <asm/system.h>
20#endif /* __ASSEMBLY__ */
21
22/*
23 * Default implementation of macro that returns current
24 * instruction pointer ("program counter").
25 */
26
27/* We cannot use MFIA as it was added for PA2.0 - prumpf
28
29   At one point there were no "0f/0b" type local symbols in gas for
30   PA-RISC.  This is no longer true, but this still seems like the
31   nicest way to implement this. */
32
33#define current_text_addr() ({ void *pc; __asm__("\n\tblr 0,%0\n\tnop":"=r" (pc)); pc; })
34
35#define TASK_SIZE               (current->thread.task_size)
36#define DEFAULT_TASK_SIZE       (0xFFF00000UL)
37
38#define TASK_UNMAPPED_BASE      (current->thread.map_base)
39#define DEFAULT_MAP_BASE        (0x40000000UL)
40
41#ifndef __ASSEMBLY__
42
43struct system_cpuinfo_parisc {
44	unsigned int	cpu_count;
45	unsigned int	cpu_hz;
46	unsigned int	hversion;
47	unsigned int	sversion;
48	enum cpu_type	cpu_type;
49
50	struct {
51		struct pdc_model model;
52		unsigned long versions;
53		unsigned long cpuid;
54		unsigned long capabilities;
55		char   sys_model_name[81]; /* PDC-ROM returnes this model name */
56	} pdc;
57
58	char		*cpu_name;	/* e.g. "PA7300LC (PCX-L2)" */
59	char		*family_name;	/* e.g. "1.1e" */
60};
61
62
63/*
64** Per CPU data structure - ie varies per CPU.
65*/
66struct cpuinfo_parisc {
67
68	struct irq_region *region;
69	unsigned long it_value;     /* Interval Timer value at last timer Intr */
70	unsigned long it_delta;     /* Interval Timer delta (tic_10ms / HZ * 100) */
71	unsigned long irq_count;    /* number of IRQ's since boot */
72	unsigned long irq_max_cr16; /* longest time to handle a single IRQ */
73	unsigned long cpuid;        /* aka slot_number or set to NO_PROC_ID */
74	unsigned long hpa;          /* Host Physical address */
75	unsigned long txn_addr;     /* MMIO addr of EIR or id_eid */
76#ifdef CONFIG_SMP
77	spinlock_t lock;            /* synchronization for ipi's */
78	unsigned long pending_ipi;  /* bitmap of type ipi_message_type */
79	unsigned long ipi_count;    /* number ipi Interrupts */
80#endif
81	unsigned long bh_count;     /* number of times bh was invoked */
82	unsigned long prof_counter; /* per CPU profiling support */
83	unsigned long prof_multiplier;	/* per CPU profiling support */
84	unsigned long fp_rev;
85	unsigned long fp_model;
86	unsigned int state;
87	struct parisc_device *dev;
88};
89
90extern struct system_cpuinfo_parisc boot_cpu_data;
91extern struct cpuinfo_parisc cpu_data[NR_CPUS];
92#define current_cpu_data cpu_data[smp_processor_id()]
93
94#define CPU_HVERSION ((boot_cpu_data.hversion >> 4) & 0x0FFF)
95
96#ifdef CONFIG_EISA
97extern int EISA_bus;
98#else
99#define EISA_bus 0
100#endif
101
102#define MCA_bus 0
103#define MCA_bus__is_a_macro /* for versions in ksyms.c */
104
105typedef struct {
106	int seg;
107} mm_segment_t;
108
109struct thread_struct {
110	struct pt_regs regs;
111	unsigned long  task_size;
112	unsigned long  map_base;
113	unsigned long  flags;
114};
115
116/* Thread struct flags. */
117#define PARISC_KERNEL_DEATH	(1UL << 31)	/* see die_if_kernel()... */
118
119#define INIT_THREAD { \
120	regs:	{	gr: { 0, }, \
121			fr: { 0, }, \
122			sr: { 0, }, \
123			iasq: { 0, }, \
124			iaoq: { 0, }, \
125			cr27: 0, \
126		}, \
127	task_size:      DEFAULT_TASK_SIZE, \
128	map_base:       DEFAULT_MAP_BASE, \
129	flags:          0 \
130	}
131
132/*
133 * Return saved PC of a blocked thread.  This is used by ps mostly.
134 */
135
136static inline unsigned long thread_saved_pc(struct thread_struct *t)
137{
138	return 0xabcdef;
139}
140
141/*
142 * Start user thread in another space.
143 *
144 * Note that we set both the iaoq and r31 to the new pc. When
145 * the kernel initially calls execve it will return through an
146 * rfi path that will use the values in the iaoq. The execve
147 * syscall path will return through the gateway page, and
148 * that uses r31 to branch to.
149 *
150 * For ELF we clear r23, because the dynamic linker uses it to pass
151 * the address of the finalizer function.
152 *
153 * We also initialize sr3 to an illegal value (illegal for our
154 * implementation, not for the architecture).
155 */
156
157#define start_thread_som(regs, new_pc, new_sp) do {	\
158	unsigned long *sp = (unsigned long *)new_sp;	\
159	__u32 spaceid = (__u32)current->mm->context;	\
160	unsigned long pc = (unsigned long)new_pc;	\
161	/* offset pc for priv. level */			\
162	pc |= 3;					\
163							\
164	set_fs(USER_DS);				\
165	regs->iasq[0] = spaceid;			\
166	regs->iasq[1] = spaceid;			\
167	regs->iaoq[0] = pc;				\
168	regs->iaoq[1] = pc + 4;                         \
169	regs->sr[2] = LINUX_GATEWAY_SPACE;              \
170	regs->sr[3] = 0xffff;				\
171	regs->sr[4] = spaceid;				\
172	regs->sr[5] = spaceid;				\
173	regs->sr[6] = spaceid;				\
174	regs->sr[7] = spaceid;				\
175	regs->gr[ 0] = USER_PSW;                        \
176	regs->gr[30] = ((new_sp)+63)&~63;		\
177	regs->gr[31] = pc;				\
178							\
179	get_user(regs->gr[26],&sp[0]);			\
180	get_user(regs->gr[25],&sp[-1]); 		\
181	get_user(regs->gr[24],&sp[-2]); 		\
182	get_user(regs->gr[23],&sp[-3]); 		\
183} while(0)
184
185/* The ELF abi wants things done a "wee bit" differently than
186 * som does.  Supporting this behavior here avoids
187 * having our own version of create_elf_tables.
188 *
189 * Oh, and yes, that is not a typo, we are really passing argc in r25
190 * and argv in r24 (rather than r26 and r25).  This is because that's
191 * where __libc_start_main wants them.
192 *
193 * Duplicated from dl-machine.h for the benefit of readers:
194 *
195 *  Our initial stack layout is rather different from everyone else's
196 *  due to the unique PA-RISC ABI.  As far as I know it looks like
197 *  this:
198
199   -----------------------------------  (user startup code creates this frame)
200   |         32 bytes of magic       |
201   |---------------------------------|
202   | 32 bytes argument/sp save area  |
203   |---------------------------------| (bprm->p)
204   |	    ELF auxiliary info	     |
205   |         (up to 28 words)        |
206   |---------------------------------|
207   |		   NULL		     |
208   |---------------------------------|
209   |	   Environment pointers	     |
210   |---------------------------------|
211   |		   NULL		     |
212   |---------------------------------|
213   |        Argument pointers        |
214   |---------------------------------| <- argv
215   |          argc (1 word)          |
216   |---------------------------------| <- bprm->exec (HACK!)
217   |         N bytes of slack        |
218   |---------------------------------|
219   |	filename passed to execve    |
220   |---------------------------------| (mm->env_end)
221   |           env strings           |
222   |---------------------------------| (mm->env_start, mm->arg_end)
223   |           arg strings           |
224   |---------------------------------|
225   | additional faked arg strings if |
226   | we're invoked via binfmt_script |
227   |---------------------------------| (mm->arg_start)
228   stack base is at TASK_SIZE - rlim_max.
229
230on downward growing arches, it looks like this:
231   stack base at TASK_SIZE
232   | filename passed to execve
233   | env strings
234   | arg strings
235   | faked arg strings
236   | slack
237   | ELF
238   | envps
239   | argvs
240   | argc
241
242 *  The pleasant part of this is that if we need to skip arguments we
243 *  can just decrement argc and move argv, because the stack pointer
244 *  is utterly unrelated to the location of the environment and
245 *  argument vectors.
246 *
247 * Note that the S/390 people took the easy way out and hacked their
248 * GCC to make the stack grow downwards.
249 */
250
251#define start_thread(regs, new_pc, new_sp) do {		\
252	elf_addr_t *sp = (elf_addr_t *)new_sp;		\
253	__u32 spaceid = (__u32)current->mm->context;	\
254	elf_addr_t pc = (elf_addr_t)new_pc | 3;		\
255	elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1;	\
256							\
257	set_fs(USER_DS);				\
258	regs->iasq[0] = spaceid;			\
259	regs->iasq[1] = spaceid;			\
260	regs->iaoq[0] = pc;				\
261	regs->iaoq[1] = pc + 4;                         \
262	regs->sr[2] = LINUX_GATEWAY_SPACE;              \
263	regs->sr[3] = 0xffff;				\
264	regs->sr[4] = spaceid;				\
265	regs->sr[5] = spaceid;				\
266	regs->sr[6] = spaceid;				\
267	regs->sr[7] = spaceid;				\
268	regs->gr[ 0] = USER_PSW;                        \
269	regs->fr[ 0] = 0LL;                            	\
270	regs->fr[ 1] = 0LL;                            	\
271	regs->fr[ 2] = 0LL;                            	\
272	regs->fr[ 3] = 0LL;                            	\
273	regs->gr[30] = ((unsigned long)sp + 63) &~ 63;	\
274	regs->gr[31] = pc;				\
275							\
276	get_user(regs->gr[25], (argv - 1));		\
277	regs->gr[24] = (long) argv;			\
278	regs->gr[23] = 0;				\
279} while(0)
280
281struct task_struct;
282struct mm_struct;
283
284/* Free all resources held by a thread. */
285extern void release_thread(struct task_struct *);
286extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
287
288extern void map_hpux_gateway_page(struct task_struct *tsk, struct mm_struct *mm);
289
290#define copy_segments(tsk, mm)  do { \
291					if (tsk->personality == PER_HPUX)  \
292					    map_hpux_gateway_page(tsk,mm); \
293				} while (0)
294#define release_segments(mm)	do { } while (0)
295
296static inline unsigned long get_wchan(struct task_struct *p)
297{
298	return 0xdeadbeef;
299}
300
301#define KSTK_EIP(tsk)	((tsk)->thread.regs.iaoq[0])
302#define KSTK_ESP(tsk)	((tsk)->thread.regs.gr[30])
303
304#endif /* __ASSEMBLY__ */
305
306#ifdef  CONFIG_PA20
307#define ARCH_HAS_PREFETCH
308extern inline void prefetch(const void *addr)
309{
310	__asm__("ldw 0(%0), %%r0" : : "r" (addr));
311}
312
313#define ARCH_HAS_PREFETCHW
314extern inline void prefetchw(const void *addr)
315{
316	__asm__("ldd 0(%0), %%r0" : : "r" (addr));
317}
318#endif
319
320/* Be sure to hunt all references to this down when you change the size of
321 * the kernel stack */
322
323#define THREAD_SIZE	(4*PAGE_SIZE)
324
325#define alloc_task_struct() \
326	((struct task_struct *)	__get_free_pages(GFP_KERNEL,2))
327#define free_task_struct(p)	free_pages((unsigned long)(p),2)
328#define get_task_struct(tsk)	atomic_inc(&virt_to_page(tsk)->count)
329
330#define init_task (init_task_union.task)
331#define init_stack (init_task_union.stack)
332
333#define cpu_relax()	do { } while (0)
334
335#endif /* __ASM_PARISC_PROCESSOR_H */
336