Staging: Panel: panel: Fixed checkpatch line length warnings
[linux/fpc-iii.git] / arch / frv / kernel / ptrace.c
blob3987ff88dab0cd14d6273a05b86b6c8aef07d94a
1 /* ptrace.c: FRV specific parts of process tracing
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/ptrace.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16 #include <linux/smp.h>
17 #include <linux/errno.h>
18 #include <linux/ptrace.h>
19 #include <linux/user.h>
20 #include <linux/security.h>
21 #include <linux/signal.h>
22 #include <linux/regset.h>
23 #include <linux/elf.h>
24 #include <linux/tracehook.h>
26 #include <asm/uaccess.h>
27 #include <asm/page.h>
28 #include <asm/pgtable.h>
29 #include <asm/processor.h>
30 #include <asm/unistd.h>
33 * does not yet catch signals sent when the child dies.
34 * in exit.c or in signal.c.
38 * retrieve the contents of FRV userspace general registers
40 static int genregs_get(struct task_struct *target,
41 const struct user_regset *regset,
42 unsigned int pos, unsigned int count,
43 void *kbuf, void __user *ubuf)
45 const struct user_int_regs *iregs = &target->thread.user->i;
46 int ret;
48 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
49 iregs, 0, sizeof(*iregs));
50 if (ret < 0)
51 return ret;
53 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
54 sizeof(*iregs), -1);
58 * update the contents of the FRV userspace general registers
60 static int genregs_set(struct task_struct *target,
61 const struct user_regset *regset,
62 unsigned int pos, unsigned int count,
63 const void *kbuf, const void __user *ubuf)
65 struct user_int_regs *iregs = &target->thread.user->i;
66 unsigned int offs_gr0, offs_gr1;
67 int ret;
69 /* not allowed to set PSR or __status */
70 if (pos < offsetof(struct user_int_regs, psr) + sizeof(long) &&
71 pos + count > offsetof(struct user_int_regs, psr))
72 return -EIO;
74 if (pos < offsetof(struct user_int_regs, __status) + sizeof(long) &&
75 pos + count > offsetof(struct user_int_regs, __status))
76 return -EIO;
78 /* set the control regs */
79 offs_gr0 = offsetof(struct user_int_regs, gr[0]);
80 offs_gr1 = offsetof(struct user_int_regs, gr[1]);
81 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
82 iregs, 0, offs_gr0);
83 if (ret < 0)
84 return ret;
86 /* skip GR0/TBR */
87 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
88 offs_gr0, offs_gr1);
89 if (ret < 0)
90 return ret;
92 /* set the general regs */
93 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
94 &iregs->gr[1], offs_gr1, sizeof(*iregs));
95 if (ret < 0)
96 return ret;
98 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
99 sizeof(*iregs), -1);
103 * retrieve the contents of FRV userspace FP/Media registers
105 static int fpmregs_get(struct task_struct *target,
106 const struct user_regset *regset,
107 unsigned int pos, unsigned int count,
108 void *kbuf, void __user *ubuf)
110 const struct user_fpmedia_regs *fpregs = &target->thread.user->f;
111 int ret;
113 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
114 fpregs, 0, sizeof(*fpregs));
115 if (ret < 0)
116 return ret;
118 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
119 sizeof(*fpregs), -1);
123 * update the contents of the FRV userspace FP/Media registers
125 static int fpmregs_set(struct task_struct *target,
126 const struct user_regset *regset,
127 unsigned int pos, unsigned int count,
128 const void *kbuf, const void __user *ubuf)
130 struct user_fpmedia_regs *fpregs = &target->thread.user->f;
131 int ret;
133 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
134 fpregs, 0, sizeof(*fpregs));
135 if (ret < 0)
136 return ret;
138 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
139 sizeof(*fpregs), -1);
143 * determine if the FP/Media registers have actually been used
145 static int fpmregs_active(struct task_struct *target,
146 const struct user_regset *regset)
148 return tsk_used_math(target) ? regset->n : 0;
152 * Define the register sets available on the FRV under Linux
154 enum frv_regset {
155 REGSET_GENERAL,
156 REGSET_FPMEDIA,
159 static const struct user_regset frv_regsets[] = {
161 * General register format is:
162 * PSR, ISR, CCR, CCCR, LR, LCR, PC, (STATUS), SYSCALLNO, ORIG_G8
163 * GNER0-1, IACC0, TBR, GR1-63
165 [REGSET_GENERAL] = {
166 .core_note_type = NT_PRSTATUS,
167 .n = ELF_NGREG,
168 .size = sizeof(long),
169 .align = sizeof(long),
170 .get = genregs_get,
171 .set = genregs_set,
174 * FPU/Media register format is:
175 * FR0-63, FNER0-1, MSR0-1, ACC0-7, ACCG0-8, FSR
177 [REGSET_FPMEDIA] = {
178 .core_note_type = NT_PRFPREG,
179 .n = sizeof(struct user_fpmedia_regs) / sizeof(long),
180 .size = sizeof(long),
181 .align = sizeof(long),
182 .get = fpmregs_get,
183 .set = fpmregs_set,
184 .active = fpmregs_active,
188 static const struct user_regset_view user_frv_native_view = {
189 .name = "frv",
190 .e_machine = EM_FRV,
191 .regsets = frv_regsets,
192 .n = ARRAY_SIZE(frv_regsets),
195 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
197 return &user_frv_native_view;
201 * Get contents of register REGNO in task TASK.
203 static inline long get_reg(struct task_struct *task, int regno)
205 struct user_context *user = task->thread.user;
207 if (regno < 0 || regno >= PT__END)
208 return 0;
210 return ((unsigned long *) user)[regno];
214 * Write contents of register REGNO in task TASK.
216 static inline int put_reg(struct task_struct *task, int regno,
217 unsigned long data)
219 struct user_context *user = task->thread.user;
221 if (regno < 0 || regno >= PT__END)
222 return -EIO;
224 switch (regno) {
225 case PT_GR(0):
226 return 0;
227 case PT_PSR:
228 case PT__STATUS:
229 return -EIO;
230 default:
231 ((unsigned long *) user)[regno] = data;
232 return 0;
237 * Called by kernel/ptrace.c when detaching..
239 * Control h/w single stepping
241 void user_enable_single_step(struct task_struct *child)
243 child->thread.frame0->__status |= REG__STATUS_STEP;
246 void user_disable_single_step(struct task_struct *child)
248 child->thread.frame0->__status &= ~REG__STATUS_STEP;
251 void ptrace_disable(struct task_struct *child)
253 user_disable_single_step(child);
256 long arch_ptrace(struct task_struct *child, long request,
257 unsigned long addr, unsigned long data)
259 unsigned long tmp;
260 int ret;
261 int regno = addr >> 2;
262 unsigned long __user *datap = (unsigned long __user *) data;
264 switch (request) {
265 /* read the word at location addr in the USER area. */
266 case PTRACE_PEEKUSR: {
267 tmp = 0;
268 ret = -EIO;
269 if (addr & 3)
270 break;
272 ret = 0;
273 switch (regno) {
274 case 0 ... PT__END - 1:
275 tmp = get_reg(child, regno);
276 break;
278 case PT__END + 0:
279 tmp = child->mm->end_code - child->mm->start_code;
280 break;
282 case PT__END + 1:
283 tmp = child->mm->end_data - child->mm->start_data;
284 break;
286 case PT__END + 2:
287 tmp = child->mm->start_stack - child->mm->start_brk;
288 break;
290 case PT__END + 3:
291 tmp = child->mm->start_code;
292 break;
294 case PT__END + 4:
295 tmp = child->mm->start_stack;
296 break;
298 default:
299 ret = -EIO;
300 break;
303 if (ret == 0)
304 ret = put_user(tmp, datap);
305 break;
308 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
309 ret = -EIO;
310 if (addr & 3)
311 break;
313 switch (regno) {
314 case 0 ... PT__END - 1:
315 ret = put_reg(child, regno, data);
316 break;
318 break;
320 case PTRACE_GETREGS: /* Get all integer regs from the child. */
321 return copy_regset_to_user(child, &user_frv_native_view,
322 REGSET_GENERAL,
323 0, sizeof(child->thread.user->i),
324 datap);
326 case PTRACE_SETREGS: /* Set all integer regs in the child. */
327 return copy_regset_from_user(child, &user_frv_native_view,
328 REGSET_GENERAL,
329 0, sizeof(child->thread.user->i),
330 datap);
332 case PTRACE_GETFPREGS: /* Get the child FP/Media state. */
333 return copy_regset_to_user(child, &user_frv_native_view,
334 REGSET_FPMEDIA,
335 0, sizeof(child->thread.user->f),
336 datap);
338 case PTRACE_SETFPREGS: /* Set the child FP/Media state. */
339 return copy_regset_from_user(child, &user_frv_native_view,
340 REGSET_FPMEDIA,
341 0, sizeof(child->thread.user->f),
342 datap);
344 default:
345 ret = ptrace_request(child, request, addr, data);
346 break;
348 return ret;
352 * handle tracing of system call entry
353 * - return the revised system call number or ULONG_MAX to cause ENOSYS
355 asmlinkage unsigned long syscall_trace_entry(void)
357 __frame->__status |= REG__STATUS_SYSC_ENTRY;
358 if (tracehook_report_syscall_entry(__frame)) {
359 /* tracing decided this syscall should not happen, so
360 * We'll return a bogus call number to get an ENOSYS
361 * error, but leave the original number in
362 * __frame->syscallno
364 return ULONG_MAX;
367 return __frame->syscallno;
371 * handle tracing of system call exit
373 asmlinkage void syscall_trace_exit(void)
375 __frame->__status |= REG__STATUS_SYSC_EXIT;
376 tracehook_report_syscall_exit(__frame, 0);