Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
1da177e4 LT |
22 | #include <linux/errno.h> |
23 | #include <linux/ptrace.h> | |
24 | #include <linux/user.h> | |
7ed20e1a | 25 | #include <linux/signal.h> |
1da177e4 LT |
26 | |
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 */ | |
35 | extern long h8300_get_reg(struct task_struct *task, int regno); | |
36 | extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data); | |
857fb252 CH |
37 | |
38 | ||
39 | void user_disable_single_step(struct task_struct *child) | |
40 | { | |
41 | } | |
1da177e4 LT |
42 | |
43 | /* | |
44 | * does not yet catch signals sent when the child dies. | |
45 | * in exit.c or in signal.c. | |
46 | */ | |
47 | ||
1da177e4 LT |
48 | void ptrace_disable(struct task_struct *child) |
49 | { | |
857fb252 | 50 | user_disable_single_step(child); |
1da177e4 LT |
51 | } |
52 | ||
9b05a69e NK |
53 | long arch_ptrace(struct task_struct *child, long request, |
54 | unsigned long addr, unsigned long data) | |
1da177e4 | 55 | { |
1da177e4 LT |
56 | int ret; |
57 | ||
1da177e4 | 58 | switch (request) { |
1da177e4 LT |
59 | /* read the word at location addr in the USER area. */ |
60 | case PTRACE_PEEKUSR: { | |
61 | unsigned long tmp = 0; | |
62 | ||
63 | if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { | |
64 | ret = -EIO; | |
65 | break ; | |
66 | } | |
67 | ||
68 | ret = 0; /* Default return condition */ | |
69 | addr = addr >> 2; /* temporary hack. */ | |
70 | ||
71 | if (addr < H8300_REGS_NO) | |
72 | tmp = h8300_get_reg(child, addr); | |
73 | else { | |
74 | switch(addr) { | |
75 | case 49: | |
76 | tmp = child->mm->start_code; | |
77 | break ; | |
78 | case 50: | |
79 | tmp = child->mm->start_data; | |
80 | break ; | |
81 | case 51: | |
82 | tmp = child->mm->end_code; | |
83 | break ; | |
84 | case 52: | |
85 | tmp = child->mm->end_data; | |
86 | break ; | |
87 | default: | |
88 | ret = -EIO; | |
89 | } | |
90 | } | |
91 | if (!ret) | |
92 | ret = put_user(tmp,(unsigned long *) data); | |
93 | break ; | |
94 | } | |
95 | ||
96 | /* when I and D space are separate, this will have to be fixed. */ | |
1da177e4 LT |
97 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
98 | if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { | |
99 | ret = -EIO; | |
100 | break ; | |
101 | } | |
102 | addr = addr >> 2; /* temporary hack. */ | |
103 | ||
104 | if (addr == PT_ORIG_ER0) { | |
105 | ret = -EIO; | |
106 | break ; | |
107 | } | |
108 | if (addr < H8300_REGS_NO) { | |
109 | ret = h8300_put_reg(child, addr, data); | |
110 | break ; | |
111 | } | |
112 | ret = -EIO; | |
113 | break ; | |
1da177e4 | 114 | |
1da177e4 LT |
115 | 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); | |
120 | if (put_user(tmp, (unsigned long *) data)) { | |
121 | ret = -EFAULT; | |
122 | break; | |
123 | } | |
9b05a69e | 124 | data += sizeof(unsigned long); |
1da177e4 LT |
125 | } |
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++) { | |
134 | if (get_user(tmp, (unsigned long *) data)) { | |
135 | ret = -EFAULT; | |
136 | break; | |
137 | } | |
138 | h8300_put_reg(child, i, tmp); | |
9b05a69e | 139 | data += sizeof(unsigned long); |
1da177e4 LT |
140 | } |
141 | ret = 0; | |
142 | break; | |
143 | } | |
144 | ||
145 | default: | |
b3c1e01a | 146 | ret = ptrace_request(child, request, addr, data); |
1da177e4 LT |
147 | break; |
148 | } | |
1da177e4 LT |
149 | return ret; |
150 | } | |
151 | ||
2fea299f | 152 | asmlinkage void do_syscall_trace(void) |
1da177e4 LT |
153 | { |
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 | } |