blob: 497fa89b5df40815ca3b20b4c252a8d9e09c3d1a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/h8300/kernel/ptrace.c
3 *
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
5 *
6 * Based on:
7 * linux/arch/m68k/kernel/ptrace.c
8 *
9 * Copyright (C) 1994 by Hamish Macdonald
10 * Taken from linux/kernel/ptrace.c and modified for M680x0.
11 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
12 *
13 * This file is subject to the terms and conditions of the GNU General
14 * Public License. See the file COPYING in the main directory of
15 * this archive for more details.
16 */
17
18#include <linux/kernel.h>
19#include <linux/sched.h>
20#include <linux/mm.h>
21#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/errno.h>
23#include <linux/ptrace.h>
24#include <linux/user.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070025#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/uaccess.h>
28#include <asm/page.h>
29#include <asm/pgtable.h>
30#include <asm/system.h>
31#include <asm/processor.h>
32#include <asm/signal.h>
33
34/* cpu depend functions */
35extern long h8300_get_reg(struct task_struct *task, int regno);
36extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data);
Christoph Hellwig857fb252010-03-10 15:22:52 -080037
38
39void user_disable_single_step(struct task_struct *child)
40{
41}
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/*
44 * does not yet catch signals sent when the child dies.
45 * in exit.c or in signal.c.
46 */
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048void ptrace_disable(struct task_struct *child)
49{
Christoph Hellwig857fb252010-03-10 15:22:52 -080050 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Namhyung Kim9b05a692010-10-27 15:33:47 -070053long arch_ptrace(struct task_struct *child, long request,
54 unsigned long addr, unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 int ret;
Namhyung Kim05fabda2010-10-27 15:33:53 -070057 int regno = addr >> 2;
58 unsigned long __user *datap = (unsigned long __user *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 switch (request) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 /* read the word at location addr in the USER area. */
62 case PTRACE_PEEKUSR: {
63 unsigned long tmp = 0;
64
Namhyung Kim05fabda2010-10-27 15:33:53 -070065 if ((addr & 3) || addr >= sizeof(struct user)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 ret = -EIO;
67 break ;
68 }
69
70 ret = 0; /* Default return condition */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Namhyung Kim05fabda2010-10-27 15:33:53 -070072 if (regno < H8300_REGS_NO)
73 tmp = h8300_get_reg(child, regno);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 else {
Namhyung Kim05fabda2010-10-27 15:33:53 -070075 switch (regno) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 case 49:
77 tmp = child->mm->start_code;
78 break ;
79 case 50:
80 tmp = child->mm->start_data;
81 break ;
82 case 51:
83 tmp = child->mm->end_code;
84 break ;
85 case 52:
86 tmp = child->mm->end_data;
87 break ;
88 default:
89 ret = -EIO;
90 }
91 }
92 if (!ret)
Namhyung Kim05fabda2010-10-27 15:33:53 -070093 ret = put_user(tmp, datap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 break ;
95 }
96
97 /* when I and D space are separate, this will have to be fixed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
Namhyung Kim05fabda2010-10-27 15:33:53 -070099 if ((addr & 3) || addr >= sizeof(struct user)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 ret = -EIO;
101 break ;
102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Namhyung Kim05fabda2010-10-27 15:33:53 -0700104 if (regno == PT_ORIG_ER0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 ret = -EIO;
106 break ;
107 }
Namhyung Kim05fabda2010-10-27 15:33:53 -0700108 if (regno < H8300_REGS_NO) {
109 ret = h8300_put_reg(child, regno, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 break ;
111 }
112 ret = -EIO;
113 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
116 int i;
117 unsigned long tmp;
118 for (i = 0; i < H8300_REGS_NO; i++) {
119 tmp = h8300_get_reg(child, i);
Namhyung Kim05fabda2010-10-27 15:33:53 -0700120 if (put_user(tmp, datap)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 ret = -EFAULT;
122 break;
123 }
Namhyung Kim05fabda2010-10-27 15:33:53 -0700124 datap++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126 ret = 0;
127 break;
128 }
129
130 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
131 int i;
132 unsigned long tmp;
133 for (i = 0; i < H8300_REGS_NO; i++) {
Namhyung Kim05fabda2010-10-27 15:33:53 -0700134 if (get_user(tmp, datap)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 ret = -EFAULT;
136 break;
137 }
138 h8300_put_reg(child, i, tmp);
Namhyung Kim05fabda2010-10-27 15:33:53 -0700139 datap++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141 ret = 0;
142 break;
143 }
144
145 default:
Christoph Hellwigb3c1e012010-03-10 15:22:44 -0800146 ret = ptrace_request(child, request, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 break;
148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 return ret;
150}
151
Yoshinori Sato2fea2992007-07-15 23:38:36 -0700152asmlinkage void do_syscall_trace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 if (!test_thread_flag(TIF_SYSCALL_TRACE))
155 return;
156 if (!(current->ptrace & PT_PTRACED))
157 return;
158 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
159 ? 0x80 : 0));
160 /*
161 * this isn't the same as continuing with a signal, but it will do
162 * for normal use. strace only continues with a signal if the
163 * stopping signal is not SIGTRAP. -brl
164 */
165 if (current->exit_code) {
166 send_sig(current->exit_code, current, 1);
167 current->exit_code = 0;
168 }
169}