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