blob: df114122ebdf6b42659e42c86df594ba84bc544b [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
Christoph Hellwig481bed42005-11-07 00:59:47 -080053long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 int ret;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 switch (request) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 /* read the word at location addr in the USER area. */
59 case PTRACE_PEEKUSR: {
60 unsigned long tmp = 0;
61
62 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
63 ret = -EIO;
64 break ;
65 }
66
67 ret = 0; /* Default return condition */
68 addr = addr >> 2; /* temporary hack. */
69
70 if (addr < H8300_REGS_NO)
71 tmp = h8300_get_reg(child, addr);
72 else {
73 switch(addr) {
74 case 49:
75 tmp = child->mm->start_code;
76 break ;
77 case 50:
78 tmp = child->mm->start_data;
79 break ;
80 case 51:
81 tmp = child->mm->end_code;
82 break ;
83 case 52:
84 tmp = child->mm->end_data;
85 break ;
86 default:
87 ret = -EIO;
88 }
89 }
90 if (!ret)
91 ret = put_user(tmp,(unsigned long *) data);
92 break ;
93 }
94
95 /* when I and D space are separate, this will have to be fixed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
97 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
98 ret = -EIO;
99 break ;
100 }
101 addr = addr >> 2; /* temporary hack. */
102
103 if (addr == PT_ORIG_ER0) {
104 ret = -EIO;
105 break ;
106 }
107 if (addr < H8300_REGS_NO) {
108 ret = h8300_put_reg(child, addr, data);
109 break ;
110 }
111 ret = -EIO;
112 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
115 int i;
116 unsigned long tmp;
117 for (i = 0; i < H8300_REGS_NO; i++) {
118 tmp = h8300_get_reg(child, i);
119 if (put_user(tmp, (unsigned long *) data)) {
120 ret = -EFAULT;
121 break;
122 }
123 data += sizeof(long);
124 }
125 ret = 0;
126 break;
127 }
128
129 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
130 int i;
131 unsigned long tmp;
132 for (i = 0; i < H8300_REGS_NO; i++) {
133 if (get_user(tmp, (unsigned long *) data)) {
134 ret = -EFAULT;
135 break;
136 }
137 h8300_put_reg(child, i, tmp);
138 data += sizeof(long);
139 }
140 ret = 0;
141 break;
142 }
143
144 default:
Christoph Hellwigb3c1e012010-03-10 15:22:44 -0800145 ret = ptrace_request(child, request, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 break;
147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return ret;
149}
150
Yoshinori Sato2fea2992007-07-15 23:38:36 -0700151asmlinkage void do_syscall_trace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 if (!test_thread_flag(TIF_SYSCALL_TRACE))
154 return;
155 if (!(current->ptrace & PT_PTRACED))
156 return;
157 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
158 ? 0x80 : 0));
159 /*
160 * this isn't the same as continuing with a signal, but it will do
161 * for normal use. strace only continues with a signal if the
162 * stopping signal is not SIGTRAP. -brl
163 */
164 if (current->exit_code) {
165 send_sig(current->exit_code, current, 1);
166 current->exit_code = 0;
167 }
168}