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