]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
b123923d | 2 | * ptrace for 32-bit processes running on a 64-bit kernel. |
1da177e4 LT |
3 | * |
4 | * PowerPC version | |
5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | |
6 | * | |
7 | * Derived from "arch/m68k/kernel/ptrace.c" | |
8 | * Copyright (C) 1994 by Hamish Macdonald | |
9 | * Taken from linux/kernel/ptrace.c and modified for M680x0. | |
10 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds | |
11 | * | |
12 | * Modified by Cort Dougan (cort@hq.fsmlabs.com) | |
b123923d | 13 | * and Paul Mackerras (paulus@samba.org). |
1da177e4 LT |
14 | * |
15 | * This file is subject to the terms and conditions of the GNU General | |
b123923d | 16 | * Public License. See the file COPYING in the main directory of |
1da177e4 LT |
17 | * this archive for more details. |
18 | */ | |
19 | ||
20 | #include <linux/kernel.h> | |
21 | #include <linux/sched.h> | |
22 | #include <linux/mm.h> | |
23 | #include <linux/smp.h> | |
1da177e4 LT |
24 | #include <linux/errno.h> |
25 | #include <linux/ptrace.h> | |
0deef2c7 | 26 | #include <linux/regset.h> |
1da177e4 LT |
27 | #include <linux/user.h> |
28 | #include <linux/security.h> | |
7ed20e1a | 29 | #include <linux/signal.h> |
1d48d71c | 30 | #include <linux/compat.h> |
1da177e4 LT |
31 | |
32 | #include <asm/uaccess.h> | |
33 | #include <asm/page.h> | |
34 | #include <asm/pgtable.h> | |
ae3a197e | 35 | #include <asm/switch_to.h> |
21a62902 | 36 | |
1da177e4 LT |
37 | /* |
38 | * does not yet catch signals sent when the child dies. | |
39 | * in exit.c or in signal.c. | |
40 | */ | |
41 | ||
9c75a31c MN |
42 | /* Macros to workout the correct index for the FPR in the thread struct */ |
43 | #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1) | |
44 | #define FPRHALF(i) (((i) - PT_FPR0) & 1) | |
bc826666 MN |
45 | #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i) |
46 | #define FPRINDEX_3264(i) (TS_FPRWIDTH * ((i) - PT_FPR0)) | |
9c75a31c | 47 | |
81e695c0 RM |
48 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
49 | compat_ulong_t caddr, compat_ulong_t cdata) | |
1da177e4 | 50 | { |
81e695c0 RM |
51 | unsigned long addr = caddr; |
52 | unsigned long data = cdata; | |
6b9c7ed8 | 53 | int ret; |
1da177e4 | 54 | |
1da177e4 | 55 | switch (request) { |
1da177e4 LT |
56 | /* |
57 | * Read 4 bytes of the other process' storage | |
58 | * data is a pointer specifying where the user wants the | |
59 | * 4 bytes copied into | |
60 | * addr is a pointer in the user's storage that contains an 8 byte | |
61 | * address in the other process of the 4 bytes that is to be read | |
62 | * (this is run in a 32-bit process looking at a 64-bit process) | |
63 | * when I and D space are separate, these will need to be fixed. | |
64 | */ | |
65 | case PPC_PTRACE_PEEKTEXT_3264: | |
66 | case PPC_PTRACE_PEEKDATA_3264: { | |
67 | u32 tmp; | |
68 | int copied; | |
69 | u32 __user * addrOthers; | |
70 | ||
71 | ret = -EIO; | |
72 | ||
73 | /* Get the addr in the other process that we want to read */ | |
74 | if (get_user(addrOthers, (u32 __user * __user *)addr) != 0) | |
75 | break; | |
76 | ||
77 | copied = access_process_vm(child, (u64)addrOthers, &tmp, | |
78 | sizeof(tmp), 0); | |
79 | if (copied != sizeof(tmp)) | |
80 | break; | |
81 | ret = put_user(tmp, (u32 __user *)data); | |
82 | break; | |
83 | } | |
84 | ||
85 | /* Read a register (specified by ADDR) out of the "user area" */ | |
86 | case PTRACE_PEEKUSR: { | |
87 | int index; | |
88 | unsigned long tmp; | |
89 | ||
90 | ret = -EIO; | |
91 | /* convert to index and check */ | |
92 | index = (unsigned long) addr >> 2; | |
93 | if ((addr & 3) || (index > PT_FPSCR32)) | |
94 | break; | |
95 | ||
fabca2c0 | 96 | CHECK_FULL_REGS(child->thread.regs); |
1da177e4 | 97 | if (index < PT_FPR0) { |
ee4a3916 AK |
98 | ret = ptrace_get_reg(child, index, &tmp); |
99 | if (ret) | |
100 | break; | |
1da177e4 LT |
101 | } else { |
102 | flush_fp_to_thread(child); | |
103 | /* | |
104 | * the user space code considers the floating point | |
105 | * to be an array of unsigned int (32 bits) - the | |
106 | * index passed in is based on this assumption. | |
107 | */ | |
9c75a31c MN |
108 | tmp = ((unsigned int *)child->thread.fpr) |
109 | [FPRINDEX(index)]; | |
1da177e4 LT |
110 | } |
111 | ret = put_user((unsigned int)tmp, (u32 __user *)data); | |
112 | break; | |
113 | } | |
114 | ||
115 | /* | |
116 | * Read 4 bytes out of the other process' pt_regs area | |
117 | * data is a pointer specifying where the user wants the | |
118 | * 4 bytes copied into | |
119 | * addr is the offset into the other process' pt_regs structure | |
120 | * that is to be read | |
121 | * (this is run in a 32-bit process looking at a 64-bit process) | |
122 | */ | |
123 | case PPC_PTRACE_PEEKUSR_3264: { | |
124 | u32 index; | |
125 | u32 reg32bits; | |
126 | u64 tmp; | |
127 | u32 numReg; | |
128 | u32 part; | |
129 | ||
130 | ret = -EIO; | |
131 | /* Determine which register the user wants */ | |
132 | index = (u64)addr >> 2; | |
133 | numReg = index / 2; | |
134 | /* Determine which part of the register the user wants */ | |
135 | if (index % 2) | |
136 | part = 1; /* want the 2nd half of the register (right-most). */ | |
137 | else | |
138 | part = 0; /* want the 1st half of the register (left-most). */ | |
139 | ||
912000e7 BH |
140 | /* Validate the input - check to see if address is on the wrong boundary |
141 | * or beyond the end of the user area | |
142 | */ | |
1da177e4 LT |
143 | if ((addr & 3) || numReg > PT_FPSCR) |
144 | break; | |
145 | ||
fabca2c0 | 146 | CHECK_FULL_REGS(child->thread.regs); |
1da177e4 LT |
147 | if (numReg >= PT_FPR0) { |
148 | flush_fp_to_thread(child); | |
bc826666 MN |
149 | /* get 64 bit FPR */ |
150 | tmp = ((u64 *)child->thread.fpr) | |
151 | [FPRINDEX_3264(numReg)]; | |
1da177e4 | 152 | } else { /* register within PT_REGS struct */ |
ee4a3916 AK |
153 | unsigned long tmp2; |
154 | ret = ptrace_get_reg(child, numReg, &tmp2); | |
155 | if (ret) | |
156 | break; | |
157 | tmp = tmp2; | |
1da177e4 LT |
158 | } |
159 | reg32bits = ((u32*)&tmp)[part]; | |
160 | ret = put_user(reg32bits, (u32 __user *)data); | |
161 | break; | |
162 | } | |
163 | ||
1da177e4 LT |
164 | /* |
165 | * Write 4 bytes into the other process' storage | |
166 | * data is the 4 bytes that the user wants written | |
167 | * addr is a pointer in the user's storage that contains an | |
168 | * 8 byte address in the other process where the 4 bytes | |
169 | * that is to be written | |
170 | * (this is run in a 32-bit process looking at a 64-bit process) | |
171 | * when I and D space are separate, these will need to be fixed. | |
172 | */ | |
173 | case PPC_PTRACE_POKETEXT_3264: | |
174 | case PPC_PTRACE_POKEDATA_3264: { | |
175 | u32 tmp = data; | |
176 | u32 __user * addrOthers; | |
177 | ||
178 | /* Get the addr in the other process that we want to write into */ | |
179 | ret = -EIO; | |
180 | if (get_user(addrOthers, (u32 __user * __user *)addr) != 0) | |
181 | break; | |
182 | ret = 0; | |
183 | if (access_process_vm(child, (u64)addrOthers, &tmp, | |
184 | sizeof(tmp), 1) == sizeof(tmp)) | |
185 | break; | |
186 | ret = -EIO; | |
187 | break; | |
188 | } | |
189 | ||
190 | /* write the word at location addr in the USER area */ | |
191 | case PTRACE_POKEUSR: { | |
192 | unsigned long index; | |
193 | ||
194 | ret = -EIO; | |
195 | /* convert to index and check */ | |
196 | index = (unsigned long) addr >> 2; | |
197 | if ((addr & 3) || (index > PT_FPSCR32)) | |
198 | break; | |
199 | ||
fabca2c0 | 200 | CHECK_FULL_REGS(child->thread.regs); |
1da177e4 | 201 | if (index < PT_FPR0) { |
865418d8 | 202 | ret = ptrace_put_reg(child, index, data); |
1da177e4 LT |
203 | } else { |
204 | flush_fp_to_thread(child); | |
205 | /* | |
206 | * the user space code considers the floating point | |
207 | * to be an array of unsigned int (32 bits) - the | |
208 | * index passed in is based on this assumption. | |
209 | */ | |
9c75a31c MN |
210 | ((unsigned int *)child->thread.fpr) |
211 | [FPRINDEX(index)] = data; | |
1da177e4 LT |
212 | ret = 0; |
213 | } | |
214 | break; | |
215 | } | |
216 | ||
217 | /* | |
218 | * Write 4 bytes into the other process' pt_regs area | |
219 | * data is the 4 bytes that the user wants written | |
220 | * addr is the offset into the other process' pt_regs structure | |
221 | * that is to be written into | |
222 | * (this is run in a 32-bit process looking at a 64-bit process) | |
223 | */ | |
224 | case PPC_PTRACE_POKEUSR_3264: { | |
225 | u32 index; | |
226 | u32 numReg; | |
227 | ||
228 | ret = -EIO; | |
229 | /* Determine which register the user wants */ | |
230 | index = (u64)addr >> 2; | |
231 | numReg = index / 2; | |
912000e7 | 232 | |
1da177e4 LT |
233 | /* |
234 | * Validate the input - check to see if address is on the | |
235 | * wrong boundary or beyond the end of the user area | |
236 | */ | |
237 | if ((addr & 3) || (numReg > PT_FPSCR)) | |
238 | break; | |
fabca2c0 | 239 | CHECK_FULL_REGS(child->thread.regs); |
912000e7 | 240 | if (numReg < PT_FPR0) { |
ee4a3916 AK |
241 | unsigned long freg; |
242 | ret = ptrace_get_reg(child, numReg, &freg); | |
243 | if (ret) | |
244 | break; | |
912000e7 BH |
245 | if (index % 2) |
246 | freg = (freg & ~0xfffffffful) | (data & 0xfffffffful); | |
247 | else | |
248 | freg = (freg & 0xfffffffful) | (data << 32); | |
249 | ret = ptrace_put_reg(child, numReg, freg); | |
250 | } else { | |
bc826666 | 251 | u64 *tmp; |
1da177e4 | 252 | flush_fp_to_thread(child); |
bc826666 MN |
253 | /* get 64 bit FPR ... */ |
254 | tmp = &(((u64 *)child->thread.fpr) | |
255 | [FPRINDEX_3264(numReg)]); | |
256 | /* ... write the 32 bit part we want */ | |
257 | ((u32 *)tmp)[index % 2] = data; | |
912000e7 | 258 | ret = 0; |
1da177e4 | 259 | } |
1da177e4 LT |
260 | break; |
261 | } | |
262 | ||
fd9648df | 263 | case PTRACE_GET_DEBUGREG: { |
9422de3e MN |
264 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
265 | unsigned long dabr_fake; | |
266 | #endif | |
fd9648df AB |
267 | ret = -EINVAL; |
268 | /* We only support one DABR and no IABRS at the moment */ | |
269 | if (addr > 0) | |
270 | break; | |
bb2c458b AS |
271 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
272 | ret = put_user(child->thread.dac1, (u32 __user *)data); | |
273 | #else | |
9422de3e MN |
274 | dabr_fake = ( |
275 | (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | | |
276 | (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); | |
277 | ret = put_user(dabr_fake, (u32 __user *)data); | |
bb2c458b | 278 | #endif |
fd9648df AB |
279 | break; |
280 | } | |
281 | ||
0deef2c7 RM |
282 | case PTRACE_GETREGS: /* Get all pt_regs from the child. */ |
283 | return copy_regset_to_user( | |
284 | child, task_user_regset_view(current), 0, | |
285 | 0, PT_REGS_COUNT * sizeof(compat_long_t), | |
286 | compat_ptr(data)); | |
287 | ||
288 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ | |
289 | return copy_regset_from_user( | |
290 | child, task_user_regset_view(current), 0, | |
291 | 0, PT_REGS_COUNT * sizeof(compat_long_t), | |
292 | compat_ptr(data)); | |
1da177e4 | 293 | |
e17666ba BH |
294 | case PTRACE_GETFPREGS: |
295 | case PTRACE_SETFPREGS: | |
962bca7f | 296 | case PTRACE_GETVRREGS: |
e17666ba | 297 | case PTRACE_SETVRREGS: |
33b3f03d MN |
298 | case PTRACE_GETVSRREGS: |
299 | case PTRACE_SETVSRREGS: | |
e17666ba BH |
300 | case PTRACE_GETREGS64: |
301 | case PTRACE_SETREGS64: | |
e17666ba BH |
302 | case PTRACE_KILL: |
303 | case PTRACE_SINGLESTEP: | |
304 | case PTRACE_DETACH: | |
305 | case PTRACE_SET_DEBUGREG: | |
306 | case PTRACE_SYSCALL: | |
307 | case PTRACE_CONT: | |
bb2c458b AS |
308 | case PPC_PTRACE_GETHWDBGINFO: |
309 | case PPC_PTRACE_SETHWDEBUG: | |
310 | case PPC_PTRACE_DELHWDEBUG: | |
e17666ba | 311 | ret = arch_ptrace(child, request, addr, data); |
962bca7f RJ |
312 | break; |
313 | ||
1da177e4 | 314 | default: |
1d48d71c | 315 | ret = compat_ptrace_request(child, request, addr, data); |
1da177e4 LT |
316 | break; |
317 | } | |
81e695c0 | 318 | |
1da177e4 LT |
319 | return ret; |
320 | } |