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