Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/kernel/process.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 4 | * This file handles the architecture-dependent parts of process handling.. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 1995 Linus Torvalds |
| 7 | * |
| 8 | * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 9 | * Copyright (C) 2006 Lineo Solutions Inc. support SH4A UBC |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 10 | * Copyright (C) 2002 - 2006 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/mm.h> |
| 14 | #include <linux/elfcore.h> |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 15 | #include <linux/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/kallsyms.h> |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 17 | #include <linux/kexec.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/uaccess.h> |
| 19 | #include <asm/mmu_context.h> |
Paul Mundt | b5233d0 | 2006-09-20 03:25:34 +0900 | [diff] [blame] | 20 | #include <asm/ubc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 22 | static int hlt_counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | int ubc_usercnt = 0; |
| 24 | |
| 25 | #define HARD_IDLE_TIMEOUT (HZ / 3) |
| 26 | |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 27 | void (*pm_idle)(void); |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 28 | void (*pm_power_off)(void); |
| 29 | EXPORT_SYMBOL(pm_power_off); |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | void disable_hlt(void) |
| 32 | { |
| 33 | hlt_counter++; |
| 34 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | EXPORT_SYMBOL(disable_hlt); |
| 36 | |
| 37 | void enable_hlt(void) |
| 38 | { |
| 39 | hlt_counter--; |
| 40 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | EXPORT_SYMBOL(enable_hlt); |
| 42 | |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 43 | void default_idle(void) |
| 44 | { |
| 45 | if (!hlt_counter) |
| 46 | cpu_sleep(); |
| 47 | else |
| 48 | cpu_relax(); |
| 49 | } |
| 50 | |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 51 | void cpu_idle(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | /* endless idle loop with no priority at all */ |
| 54 | while (1) { |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 55 | void (*idle)(void) = pm_idle; |
| 56 | |
| 57 | if (!idle) |
| 58 | idle = default_idle; |
| 59 | |
| 60 | while (!need_resched()) |
| 61 | idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 63 | preempt_enable_no_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | schedule(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 65 | preempt_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | void machine_restart(char * __unused) |
| 70 | { |
| 71 | /* SR.BL=1 and invoke address error to let CPU reset (manual reset) */ |
| 72 | asm volatile("ldc %0, sr\n\t" |
| 73 | "mov.l @%1, %0" : : "r" (0x10000000), "r" (0x80000001)); |
| 74 | } |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | void machine_halt(void) |
| 77 | { |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 78 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | while (1) |
| 81 | cpu_sleep(); |
| 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | void machine_power_off(void) |
| 85 | { |
Paul Mundt | a3310bb | 2006-02-01 03:06:08 -0800 | [diff] [blame] | 86 | if (pm_power_off) |
| 87 | pm_power_off(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | void show_regs(struct pt_regs * regs) |
| 91 | { |
| 92 | printk("\n"); |
| 93 | printk("Pid : %d, Comm: %20s\n", current->pid, current->comm); |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 94 | print_symbol("PC is at %s\n", instruction_pointer(regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | printk("PC : %08lx SP : %08lx SR : %08lx ", |
| 96 | regs->pc, regs->regs[15], regs->sr); |
| 97 | #ifdef CONFIG_MMU |
| 98 | printk("TEA : %08x ", ctrl_inl(MMU_TEA)); |
| 99 | #else |
| 100 | printk(" "); |
| 101 | #endif |
| 102 | printk("%s\n", print_tainted()); |
| 103 | |
| 104 | printk("R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n", |
| 105 | regs->regs[0],regs->regs[1], |
| 106 | regs->regs[2],regs->regs[3]); |
| 107 | printk("R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n", |
| 108 | regs->regs[4],regs->regs[5], |
| 109 | regs->regs[6],regs->regs[7]); |
| 110 | printk("R8 : %08lx R9 : %08lx R10 : %08lx R11 : %08lx\n", |
| 111 | regs->regs[8],regs->regs[9], |
| 112 | regs->regs[10],regs->regs[11]); |
| 113 | printk("R12 : %08lx R13 : %08lx R14 : %08lx\n", |
| 114 | regs->regs[12],regs->regs[13], |
| 115 | regs->regs[14]); |
| 116 | printk("MACH: %08lx MACL: %08lx GBR : %08lx PR : %08lx\n", |
| 117 | regs->mach, regs->macl, regs->gbr, regs->pr); |
| 118 | |
Paul Mundt | 6b00223 | 2006-10-12 17:07:45 +0900 | [diff] [blame] | 119 | show_trace(NULL, (unsigned long *)regs->regs[15], regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Create a kernel thread |
| 124 | */ |
| 125 | |
| 126 | /* |
| 127 | * This is the mechanism for creating a new kernel thread. |
| 128 | * |
| 129 | */ |
| 130 | extern void kernel_thread_helper(void); |
| 131 | __asm__(".align 5\n" |
| 132 | "kernel_thread_helper:\n\t" |
| 133 | "jsr @r5\n\t" |
| 134 | " nop\n\t" |
| 135 | "mov.l 1f, r1\n\t" |
| 136 | "jsr @r1\n\t" |
| 137 | " mov r0, r4\n\t" |
| 138 | ".align 2\n\t" |
| 139 | "1:.long do_exit"); |
| 140 | |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 141 | /* Don't use this in BL=1(cli). Or else, CPU resets! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 143 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | struct pt_regs regs; |
| 145 | |
| 146 | memset(®s, 0, sizeof(regs)); |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 147 | regs.regs[4] = (unsigned long)arg; |
| 148 | regs.regs[5] = (unsigned long)fn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 150 | regs.pc = (unsigned long)kernel_thread_helper; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | regs.sr = (1 << 30); |
| 152 | |
| 153 | /* Ok, create the new process.. */ |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 154 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, |
| 155 | ®s, 0, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Free current thread data structures etc.. |
| 160 | */ |
| 161 | void exit_thread(void) |
| 162 | { |
| 163 | if (current->thread.ubc_pc) { |
| 164 | current->thread.ubc_pc = 0; |
| 165 | ubc_usercnt -= 1; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void flush_thread(void) |
| 170 | { |
| 171 | #if defined(CONFIG_SH_FPU) |
| 172 | struct task_struct *tsk = current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* Forget lazy FPU state */ |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 174 | clear_fpu(tsk, task_pt_regs(tsk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | clear_used_math(); |
| 176 | #endif |
| 177 | } |
| 178 | |
| 179 | void release_thread(struct task_struct *dead_task) |
| 180 | { |
| 181 | /* do nothing */ |
| 182 | } |
| 183 | |
| 184 | /* Fill in the fpu structure for a core dump.. */ |
| 185 | int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) |
| 186 | { |
| 187 | int fpvalid = 0; |
| 188 | |
| 189 | #if defined(CONFIG_SH_FPU) |
| 190 | struct task_struct *tsk = current; |
| 191 | |
| 192 | fpvalid = !!tsk_used_math(tsk); |
| 193 | if (fpvalid) { |
| 194 | unlazy_fpu(tsk, regs); |
| 195 | memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu)); |
| 196 | } |
| 197 | #endif |
| 198 | |
| 199 | return fpvalid; |
| 200 | } |
| 201 | |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 202 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * Capture the user space registers if the task is not running (in user space) |
| 204 | */ |
| 205 | int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs) |
| 206 | { |
| 207 | struct pt_regs ptregs; |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 208 | |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 209 | ptregs = *task_pt_regs(tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | elf_core_copy_regs(regs, &ptregs); |
| 211 | |
| 212 | return 1; |
| 213 | } |
| 214 | |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 215 | int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | int fpvalid = 0; |
| 218 | |
| 219 | #if defined(CONFIG_SH_FPU) |
| 220 | fpvalid = !!tsk_used_math(tsk); |
| 221 | if (fpvalid) { |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 222 | unlazy_fpu(tsk, task_pt_regs(tsk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu)); |
| 224 | } |
| 225 | #endif |
| 226 | |
| 227 | return fpvalid; |
| 228 | } |
| 229 | |
| 230 | asmlinkage void ret_from_fork(void); |
| 231 | |
| 232 | int copy_thread(int nr, unsigned long clone_flags, unsigned long usp, |
| 233 | unsigned long unused, |
| 234 | struct task_struct *p, struct pt_regs *regs) |
| 235 | { |
Paul Mundt | 2991be7 | 2006-09-27 17:07:07 +0900 | [diff] [blame] | 236 | struct thread_info *ti = task_thread_info(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | struct pt_regs *childregs; |
| 238 | #if defined(CONFIG_SH_FPU) |
| 239 | struct task_struct *tsk = current; |
| 240 | |
| 241 | unlazy_fpu(tsk, regs); |
| 242 | p->thread.fpu = tsk->thread.fpu; |
| 243 | copy_to_stopped_child_used_math(p); |
| 244 | #endif |
| 245 | |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 246 | childregs = task_pt_regs(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | *childregs = *regs; |
| 248 | |
| 249 | if (user_mode(regs)) { |
| 250 | childregs->regs[15] = usp; |
Paul Mundt | 2991be7 | 2006-09-27 17:07:07 +0900 | [diff] [blame] | 251 | ti->addr_limit = USER_DS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } else { |
Hideo Saito | e6bcf56 | 2007-02-28 18:35:42 +0900 | [diff] [blame^] | 253 | childregs->regs[15] = (unsigned long)childregs; |
Paul Mundt | 2991be7 | 2006-09-27 17:07:07 +0900 | [diff] [blame] | 254 | ti->addr_limit = KERNEL_DS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 256 | |
Hideo Saito | e6bcf56 | 2007-02-28 18:35:42 +0900 | [diff] [blame^] | 257 | if (clone_flags & CLONE_SETTLS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | childregs->gbr = childregs->regs[0]; |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | childregs->regs[0] = 0; /* Set return value for child */ |
| 261 | |
| 262 | p->thread.sp = (unsigned long) childregs; |
| 263 | p->thread.pc = (unsigned long) ret_from_fork; |
| 264 | |
| 265 | p->thread.ubc_pc = 0; |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* Tracing by user break controller. */ |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 271 | static void ubc_set_tracing(int asid, unsigned long pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 273 | #if defined(CONFIG_CPU_SH4A) |
| 274 | unsigned long val; |
| 275 | |
| 276 | val = (UBC_CBR_ID_INST | UBC_CBR_RW_READ | UBC_CBR_CE); |
| 277 | val |= (UBC_CBR_AIE | UBC_CBR_AIV_SET(asid)); |
| 278 | |
| 279 | ctrl_outl(val, UBC_CBR0); |
| 280 | ctrl_outl(pc, UBC_CAR0); |
| 281 | ctrl_outl(0x0, UBC_CAMR0); |
| 282 | ctrl_outl(0x0, UBC_CBCR); |
| 283 | |
| 284 | val = (UBC_CRR_RES | UBC_CRR_PCB | UBC_CRR_BIE); |
| 285 | ctrl_outl(val, UBC_CRR0); |
| 286 | |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 287 | /* Read UBC register that we wrote last, for checking update */ |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 288 | val = ctrl_inl(UBC_CRR0); |
| 289 | |
| 290 | #else /* CONFIG_CPU_SH4A */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | ctrl_outl(pc, UBC_BARA); |
| 292 | |
Yoshinori Sato | a2d1a5f | 2006-09-27 17:25:07 +0900 | [diff] [blame] | 293 | #ifdef CONFIG_MMU |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | /* We don't have any ASID settings for the SH-2! */ |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 295 | if (current_cpu_data.type != CPU_SH7604) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | ctrl_outb(asid, UBC_BASRA); |
Yoshinori Sato | a2d1a5f | 2006-09-27 17:25:07 +0900 | [diff] [blame] | 297 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | ctrl_outl(0, UBC_BAMRA); |
| 300 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 301 | if (current_cpu_data.type == CPU_SH7729 || |
| 302 | current_cpu_data.type == CPU_SH7710) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | ctrl_outw(BBR_INST | BBR_READ | BBR_CPU, UBC_BBRA); |
| 304 | ctrl_outl(BRCR_PCBA | BRCR_PCTE, UBC_BRCR); |
| 305 | } else { |
| 306 | ctrl_outw(BBR_INST | BBR_READ, UBC_BBRA); |
| 307 | ctrl_outw(BRCR_PCBA, UBC_BRCR); |
| 308 | } |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 309 | #endif /* CONFIG_CPU_SH4A */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /* |
| 313 | * switch_to(x,y) should switch tasks from x to y. |
| 314 | * |
| 315 | */ |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 316 | struct task_struct *__switch_to(struct task_struct *prev, |
| 317 | struct task_struct *next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
| 319 | #if defined(CONFIG_SH_FPU) |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 320 | unlazy_fpu(prev, task_pt_regs(prev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | #endif |
| 322 | |
| 323 | #ifdef CONFIG_PREEMPT |
| 324 | { |
| 325 | unsigned long flags; |
| 326 | struct pt_regs *regs; |
| 327 | |
| 328 | local_irq_save(flags); |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 329 | regs = task_pt_regs(prev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (user_mode(regs) && regs->regs[15] >= 0xc0000000) { |
| 331 | int offset = (int)regs->regs[15]; |
| 332 | |
| 333 | /* Reset stack pointer: clear critical region mark */ |
| 334 | regs->regs[15] = regs->regs[1]; |
| 335 | if (regs->pc < regs->regs[0]) |
| 336 | /* Go to rewind point */ |
| 337 | regs->pc = regs->regs[0] + offset; |
| 338 | } |
| 339 | local_irq_restore(flags); |
| 340 | } |
| 341 | #endif |
| 342 | |
Yoshinori Sato | a2d1a5f | 2006-09-27 17:25:07 +0900 | [diff] [blame] | 343 | #ifdef CONFIG_MMU |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | /* |
| 345 | * Restore the kernel mode register |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 346 | * k7 (r7_bank1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | */ |
| 348 | asm volatile("ldc %0, r7_bank" |
| 349 | : /* no output */ |
Al Viro | cafcfca | 2006-01-12 01:05:45 -0800 | [diff] [blame] | 350 | : "r" (task_thread_info(next))); |
Yoshinori Sato | a2d1a5f | 2006-09-27 17:25:07 +0900 | [diff] [blame] | 351 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | /* If no tasks are using the UBC, we're done */ |
| 354 | if (ubc_usercnt == 0) |
| 355 | /* If no tasks are using the UBC, we're done */; |
| 356 | else if (next->thread.ubc_pc && next->mm) { |
Yoshinori Sato | a2d1a5f | 2006-09-27 17:25:07 +0900 | [diff] [blame] | 357 | int asid = 0; |
| 358 | #ifdef CONFIG_MMU |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 359 | asid |= cpu_asid(smp_processor_id(), next->mm); |
Yoshinori Sato | a2d1a5f | 2006-09-27 17:25:07 +0900 | [diff] [blame] | 360 | #endif |
| 361 | ubc_set_tracing(asid, next->thread.ubc_pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } else { |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 363 | #if defined(CONFIG_CPU_SH4A) |
| 364 | ctrl_outl(UBC_CBR_INIT, UBC_CBR0); |
| 365 | ctrl_outl(UBC_CRR_INIT, UBC_CRR0); |
| 366 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | ctrl_outw(0, UBC_BBRA); |
| 368 | ctrl_outw(0, UBC_BBRB); |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 369 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | return prev; |
| 373 | } |
| 374 | |
| 375 | asmlinkage int sys_fork(unsigned long r4, unsigned long r5, |
| 376 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 377 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 379 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | #ifdef CONFIG_MMU |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 381 | return do_fork(SIGCHLD, regs->regs[15], regs, 0, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | #else |
| 383 | /* fork almost works, enough to trick you into looking elsewhere :-( */ |
| 384 | return -EINVAL; |
| 385 | #endif |
| 386 | } |
| 387 | |
| 388 | asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, |
| 389 | unsigned long parent_tidptr, |
| 390 | unsigned long child_tidptr, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 391 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 393 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | if (!newsp) |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 395 | newsp = regs->regs[15]; |
| 396 | return do_fork(clone_flags, newsp, regs, 0, |
Paul Mundt | aec5e0e | 2006-12-25 09:51:47 +0900 | [diff] [blame] | 397 | (int __user *)parent_tidptr, |
| 398 | (int __user *)child_tidptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /* |
| 402 | * This is trivial, and on the face of it looks like it |
| 403 | * could equally well be done in user mode. |
| 404 | * |
| 405 | * Not so, for quite unobvious reasons - register pressure. |
| 406 | * In user mode vfork() cannot have a stack frame, and if |
| 407 | * done by calling the "clone()" system call directly, you |
| 408 | * do not have enough call-clobbered registers to hold all |
| 409 | * the information you need. |
| 410 | */ |
| 411 | asmlinkage int sys_vfork(unsigned long r4, unsigned long r5, |
| 412 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 413 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 415 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 416 | return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->regs[15], regs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | 0, NULL, NULL); |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * sys_execve() executes a new program. |
| 422 | */ |
| 423 | asmlinkage int sys_execve(char *ufilename, char **uargv, |
| 424 | char **uenvp, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 425 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 427 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | int error; |
| 429 | char *filename; |
| 430 | |
| 431 | filename = getname((char __user *)ufilename); |
| 432 | error = PTR_ERR(filename); |
| 433 | if (IS_ERR(filename)) |
| 434 | goto out; |
| 435 | |
| 436 | error = do_execve(filename, |
| 437 | (char __user * __user *)uargv, |
| 438 | (char __user * __user *)uenvp, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 439 | regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (error == 0) { |
| 441 | task_lock(current); |
| 442 | current->ptrace &= ~PT_DTRACE; |
| 443 | task_unlock(current); |
| 444 | } |
| 445 | putname(filename); |
| 446 | out: |
| 447 | return error; |
| 448 | } |
| 449 | |
| 450 | unsigned long get_wchan(struct task_struct *p) |
| 451 | { |
| 452 | unsigned long schedule_frame; |
| 453 | unsigned long pc; |
| 454 | |
| 455 | if (!p || p == current || p->state == TASK_RUNNING) |
| 456 | return 0; |
| 457 | |
| 458 | /* |
| 459 | * The same comment as on the Alpha applies here, too ... |
| 460 | */ |
| 461 | pc = thread_saved_pc(p); |
| 462 | if (in_sched_functions(pc)) { |
Paul Mundt | b652c23 | 2006-12-08 17:46:29 +0900 | [diff] [blame] | 463 | schedule_frame = (unsigned long)p->thread.sp; |
| 464 | return ((unsigned long *)schedule_frame)[21]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
Paul Mundt | b652c23 | 2006-12-08 17:46:29 +0900 | [diff] [blame] | 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return pc; |
| 468 | } |
| 469 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 470 | asmlinkage void break_point_trap(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
| 472 | /* Clear tracing. */ |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 473 | #if defined(CONFIG_CPU_SH4A) |
| 474 | ctrl_outl(UBC_CBR_INIT, UBC_CBR0); |
| 475 | ctrl_outl(UBC_CRR_INIT, UBC_CRR0); |
| 476 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | ctrl_outw(0, UBC_BBRA); |
| 478 | ctrl_outw(0, UBC_BBRB); |
Ryusuke Sakato | 8ae91b9 | 2006-10-12 12:16:13 +0900 | [diff] [blame] | 479 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | current->thread.ubc_pc = 0; |
| 481 | ubc_usercnt -= 1; |
| 482 | |
| 483 | force_sig(SIGTRAP, current); |
| 484 | } |
| 485 | |
Paul Mundt | f413d0d | 2006-12-13 17:40:05 +0900 | [diff] [blame] | 486 | /* |
| 487 | * Generic trap handler. |
| 488 | */ |
| 489 | asmlinkage void debug_trap_handler(unsigned long r4, unsigned long r5, |
| 490 | unsigned long r6, unsigned long r7, |
| 491 | struct pt_regs __regs) |
| 492 | { |
| 493 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 494 | |
| 495 | /* Rewind */ |
| 496 | regs->pc -= 2; |
| 497 | |
| 498 | force_sig(SIGTRAP, current); |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Special handler for BUG() traps. |
| 503 | */ |
| 504 | asmlinkage void bug_trap_handler(unsigned long r4, unsigned long r5, |
| 505 | unsigned long r6, unsigned long r7, |
| 506 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 508 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 509 | |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 510 | /* Rewind */ |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 511 | regs->pc -= 2; |
Paul Mundt | dc34d31 | 2006-12-08 17:41:43 +0900 | [diff] [blame] | 512 | |
| 513 | #ifdef CONFIG_BUG |
| 514 | if (__kernel_text_address(instruction_pointer(regs))) { |
| 515 | u16 insn = *(u16 *)instruction_pointer(regs); |
| 516 | if (insn == TRAPA_BUG_OPCODE) |
| 517 | handle_BUG(regs); |
| 518 | } |
| 519 | #endif |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | force_sig(SIGTRAP, current); |
| 522 | } |