ia64/linux-2.6.18-xen.hg

annotate arch/m68knommu/kernel/ptrace.c @ 854:950b9eb27661

usbback: fix urb interval value for interrupt urbs.

Signed-off-by: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 06 13:51:20 2009 +0100 (2009-04-06)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * linux/arch/m68knommu/kernel/ptrace.c
ian@0 3 *
ian@0 4 * Copyright (C) 1994 by Hamish Macdonald
ian@0 5 * Taken from linux/kernel/ptrace.c and modified for M680x0.
ian@0 6 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
ian@0 7 *
ian@0 8 * This file is subject to the terms and conditions of the GNU General
ian@0 9 * Public License. See the file COPYING in the main directory of
ian@0 10 * this archive for more details.
ian@0 11 */
ian@0 12
ian@0 13 #include <linux/kernel.h>
ian@0 14 #include <linux/sched.h>
ian@0 15 #include <linux/mm.h>
ian@0 16 #include <linux/smp.h>
ian@0 17 #include <linux/smp_lock.h>
ian@0 18 #include <linux/errno.h>
ian@0 19 #include <linux/ptrace.h>
ian@0 20 #include <linux/user.h>
ian@0 21 #include <linux/signal.h>
ian@0 22
ian@0 23 #include <asm/uaccess.h>
ian@0 24 #include <asm/page.h>
ian@0 25 #include <asm/pgtable.h>
ian@0 26 #include <asm/system.h>
ian@0 27 #include <asm/processor.h>
ian@0 28
ian@0 29 /*
ian@0 30 * does not yet catch signals sent when the child dies.
ian@0 31 * in exit.c or in signal.c.
ian@0 32 */
ian@0 33
ian@0 34 /* determines which bits in the SR the user has access to. */
ian@0 35 /* 1 = access 0 = no access */
ian@0 36 #define SR_MASK 0x001f
ian@0 37
ian@0 38 /* sets the trace bits. */
ian@0 39 #define TRACE_BITS 0x8000
ian@0 40
ian@0 41 /* Find the stack offset for a register, relative to thread.esp0. */
ian@0 42 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
ian@0 43 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
ian@0 44 - sizeof(struct switch_stack))
ian@0 45 /* Mapping from PT_xxx to the stack offset at which the register is
ian@0 46 saved. Notice that usp has no stack-slot and needs to be treated
ian@0 47 specially (see get_reg/put_reg below). */
ian@0 48 static int regoff[] = {
ian@0 49 PT_REG(d1), PT_REG(d2), PT_REG(d3), PT_REG(d4),
ian@0 50 PT_REG(d5), SW_REG(d6), SW_REG(d7), PT_REG(a0),
ian@0 51 PT_REG(a1), PT_REG(a2), SW_REG(a3), SW_REG(a4),
ian@0 52 SW_REG(a5), SW_REG(a6), PT_REG(d0), -1,
ian@0 53 PT_REG(orig_d0), PT_REG(sr), PT_REG(pc),
ian@0 54 };
ian@0 55
ian@0 56 /*
ian@0 57 * Get contents of register REGNO in task TASK.
ian@0 58 */
ian@0 59 static inline long get_reg(struct task_struct *task, int regno)
ian@0 60 {
ian@0 61 unsigned long *addr;
ian@0 62
ian@0 63 if (regno == PT_USP)
ian@0 64 addr = &task->thread.usp;
ian@0 65 else if (regno < sizeof(regoff)/sizeof(regoff[0]))
ian@0 66 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
ian@0 67 else
ian@0 68 return 0;
ian@0 69 return *addr;
ian@0 70 }
ian@0 71
ian@0 72 /*
ian@0 73 * Write contents of register REGNO in task TASK.
ian@0 74 */
ian@0 75 static inline int put_reg(struct task_struct *task, int regno,
ian@0 76 unsigned long data)
ian@0 77 {
ian@0 78 unsigned long *addr;
ian@0 79
ian@0 80 if (regno == PT_USP)
ian@0 81 addr = &task->thread.usp;
ian@0 82 else if (regno < sizeof(regoff)/sizeof(regoff[0]))
ian@0 83 addr = (unsigned long *) (task->thread.esp0 + regoff[regno]);
ian@0 84 else
ian@0 85 return -1;
ian@0 86 *addr = data;
ian@0 87 return 0;
ian@0 88 }
ian@0 89
ian@0 90 /*
ian@0 91 * Called by kernel/ptrace.c when detaching..
ian@0 92 *
ian@0 93 * Make sure the single step bit is not set.
ian@0 94 */
ian@0 95 void ptrace_disable(struct task_struct *child)
ian@0 96 {
ian@0 97 unsigned long tmp;
ian@0 98 /* make sure the single step bit is not set. */
ian@0 99 tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
ian@0 100 put_reg(child, PT_SR, tmp);
ian@0 101 }
ian@0 102
ian@0 103 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
ian@0 104 {
ian@0 105 int ret;
ian@0 106
ian@0 107 switch (request) {
ian@0 108 /* when I and D space are separate, these will need to be fixed. */
ian@0 109 case PTRACE_PEEKTEXT: /* read word at location addr. */
ian@0 110 case PTRACE_PEEKDATA: {
ian@0 111 unsigned long tmp;
ian@0 112 int copied;
ian@0 113
ian@0 114 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
ian@0 115 ret = -EIO;
ian@0 116 if (copied != sizeof(tmp))
ian@0 117 break;
ian@0 118 ret = put_user(tmp,(unsigned long *) data);
ian@0 119 break;
ian@0 120 }
ian@0 121
ian@0 122 /* read the word at location addr in the USER area. */
ian@0 123 case PTRACE_PEEKUSR: {
ian@0 124 unsigned long tmp;
ian@0 125
ian@0 126 ret = -EIO;
ian@0 127 if ((addr & 3) || addr < 0 ||
ian@0 128 addr > sizeof(struct user) - 3)
ian@0 129 break;
ian@0 130
ian@0 131 tmp = 0; /* Default return condition */
ian@0 132 addr = addr >> 2; /* temporary hack. */
ian@0 133 ret = -EIO;
ian@0 134 if (addr < 19) {
ian@0 135 tmp = get_reg(child, addr);
ian@0 136 if (addr == PT_SR)
ian@0 137 tmp >>= 16;
ian@0 138 } else if (addr >= 21 && addr < 49) {
ian@0 139 tmp = child->thread.fp[addr - 21];
ian@0 140 #ifdef CONFIG_M68KFPU_EMU
ian@0 141 /* Convert internal fpu reg representation
ian@0 142 * into long double format
ian@0 143 */
ian@0 144 if (FPU_IS_EMU && (addr < 45) && !(addr % 3))
ian@0 145 tmp = ((tmp & 0xffff0000) << 15) |
ian@0 146 ((tmp & 0x0000ffff) << 16);
ian@0 147 #endif
ian@0 148 } else if (addr == 49) {
ian@0 149 tmp = child->mm->start_code;
ian@0 150 } else if (addr == 50) {
ian@0 151 tmp = child->mm->start_data;
ian@0 152 } else if (addr == 51) {
ian@0 153 tmp = child->mm->end_code;
ian@0 154 } else
ian@0 155 break;
ian@0 156 ret = put_user(tmp,(unsigned long *) data);
ian@0 157 break;
ian@0 158 }
ian@0 159
ian@0 160 /* when I and D space are separate, this will have to be fixed. */
ian@0 161 case PTRACE_POKETEXT: /* write the word at location addr. */
ian@0 162 case PTRACE_POKEDATA:
ian@0 163 ret = 0;
ian@0 164 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
ian@0 165 break;
ian@0 166 ret = -EIO;
ian@0 167 break;
ian@0 168
ian@0 169 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
ian@0 170 ret = -EIO;
ian@0 171 if ((addr & 3) || addr < 0 ||
ian@0 172 addr > sizeof(struct user) - 3)
ian@0 173 break;
ian@0 174
ian@0 175 addr = addr >> 2; /* temporary hack. */
ian@0 176
ian@0 177 if (addr == PT_SR) {
ian@0 178 data &= SR_MASK;
ian@0 179 data <<= 16;
ian@0 180 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
ian@0 181 }
ian@0 182 if (addr < 19) {
ian@0 183 if (put_reg(child, addr, data))
ian@0 184 break;
ian@0 185 ret = 0;
ian@0 186 break;
ian@0 187 }
ian@0 188 if (addr >= 21 && addr < 48)
ian@0 189 {
ian@0 190 #ifdef CONFIG_M68KFPU_EMU
ian@0 191 /* Convert long double format
ian@0 192 * into internal fpu reg representation
ian@0 193 */
ian@0 194 if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
ian@0 195 data = (unsigned long)data << 15;
ian@0 196 data = (data & 0xffff0000) |
ian@0 197 ((data & 0x0000ffff) >> 1);
ian@0 198 }
ian@0 199 #endif
ian@0 200 child->thread.fp[addr - 21] = data;
ian@0 201 ret = 0;
ian@0 202 }
ian@0 203 break;
ian@0 204
ian@0 205 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
ian@0 206 case PTRACE_CONT: { /* restart after signal. */
ian@0 207 long tmp;
ian@0 208
ian@0 209 ret = -EIO;
ian@0 210 if (!valid_signal(data))
ian@0 211 break;
ian@0 212 if (request == PTRACE_SYSCALL)
ian@0 213 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
ian@0 214 else
ian@0 215 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
ian@0 216 child->exit_code = data;
ian@0 217 /* make sure the single step bit is not set. */
ian@0 218 tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
ian@0 219 put_reg(child, PT_SR, tmp);
ian@0 220 wake_up_process(child);
ian@0 221 ret = 0;
ian@0 222 break;
ian@0 223 }
ian@0 224
ian@0 225 /*
ian@0 226 * make the child exit. Best I can do is send it a sigkill.
ian@0 227 * perhaps it should be put in the status that it wants to
ian@0 228 * exit.
ian@0 229 */
ian@0 230 case PTRACE_KILL: {
ian@0 231 long tmp;
ian@0 232
ian@0 233 ret = 0;
ian@0 234 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
ian@0 235 break;
ian@0 236 child->exit_code = SIGKILL;
ian@0 237 /* make sure the single step bit is not set. */
ian@0 238 tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
ian@0 239 put_reg(child, PT_SR, tmp);
ian@0 240 wake_up_process(child);
ian@0 241 break;
ian@0 242 }
ian@0 243
ian@0 244 case PTRACE_SINGLESTEP: { /* set the trap flag. */
ian@0 245 long tmp;
ian@0 246
ian@0 247 ret = -EIO;
ian@0 248 if (!valid_signal(data))
ian@0 249 break;
ian@0 250 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
ian@0 251 tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16);
ian@0 252 put_reg(child, PT_SR, tmp);
ian@0 253
ian@0 254 child->exit_code = data;
ian@0 255 /* give it a chance to run. */
ian@0 256 wake_up_process(child);
ian@0 257 ret = 0;
ian@0 258 break;
ian@0 259 }
ian@0 260
ian@0 261 case PTRACE_DETACH: /* detach a process that was attached. */
ian@0 262 ret = ptrace_detach(child, data);
ian@0 263 break;
ian@0 264
ian@0 265 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
ian@0 266 int i;
ian@0 267 unsigned long tmp;
ian@0 268 for (i = 0; i < 19; i++) {
ian@0 269 tmp = get_reg(child, i);
ian@0 270 if (i == PT_SR)
ian@0 271 tmp >>= 16;
ian@0 272 if (put_user(tmp, (unsigned long *) data)) {
ian@0 273 ret = -EFAULT;
ian@0 274 break;
ian@0 275 }
ian@0 276 data += sizeof(long);
ian@0 277 }
ian@0 278 ret = 0;
ian@0 279 break;
ian@0 280 }
ian@0 281
ian@0 282 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
ian@0 283 int i;
ian@0 284 unsigned long tmp;
ian@0 285 for (i = 0; i < 19; i++) {
ian@0 286 if (get_user(tmp, (unsigned long *) data)) {
ian@0 287 ret = -EFAULT;
ian@0 288 break;
ian@0 289 }
ian@0 290 if (i == PT_SR) {
ian@0 291 tmp &= SR_MASK;
ian@0 292 tmp <<= 16;
ian@0 293 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
ian@0 294 }
ian@0 295 put_reg(child, i, tmp);
ian@0 296 data += sizeof(long);
ian@0 297 }
ian@0 298 ret = 0;
ian@0 299 break;
ian@0 300 }
ian@0 301
ian@0 302 #ifdef PTRACE_GETFPREGS
ian@0 303 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
ian@0 304 ret = 0;
ian@0 305 if (copy_to_user((void *)data, &child->thread.fp,
ian@0 306 sizeof(struct user_m68kfp_struct)))
ian@0 307 ret = -EFAULT;
ian@0 308 break;
ian@0 309 }
ian@0 310 #endif
ian@0 311
ian@0 312 #ifdef PTRACE_SETFPREGS
ian@0 313 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
ian@0 314 ret = 0;
ian@0 315 if (copy_from_user(&child->thread.fp, (void *)data,
ian@0 316 sizeof(struct user_m68kfp_struct)))
ian@0 317 ret = -EFAULT;
ian@0 318 break;
ian@0 319 }
ian@0 320 #endif
ian@0 321
ian@0 322 default:
ian@0 323 ret = -EIO;
ian@0 324 break;
ian@0 325 }
ian@0 326 return ret;
ian@0 327 }
ian@0 328
ian@0 329 asmlinkage void syscall_trace(void)
ian@0 330 {
ian@0 331 if (!test_thread_flag(TIF_SYSCALL_TRACE))
ian@0 332 return;
ian@0 333 if (!(current->ptrace & PT_PTRACED))
ian@0 334 return;
ian@0 335 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
ian@0 336 ? 0x80 : 0));
ian@0 337 /*
ian@0 338 * this isn't the same as continuing with a signal, but it will do
ian@0 339 * for normal use. strace only continues with a signal if the
ian@0 340 * stopping signal is not SIGTRAP. -brl
ian@0 341 */
ian@0 342 if (current->exit_code) {
ian@0 343 send_sig(current->exit_code, current, 1);
ian@0 344 current->exit_code = 0;
ian@0 345 }
ian@0 346 }