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>
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 <linux/uaccess.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
;
48 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
49 iregs
, 0, sizeof(*iregs
));
53 return user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
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
;
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
))
74 if (pos
< offsetof(struct user_int_regs
, __status
) + sizeof(long) &&
75 pos
+ count
> offsetof(struct user_int_regs
, __status
))
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
,
87 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
92 /* set the general regs */
93 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
94 &iregs
->gr
[1], offs_gr1
, sizeof(*iregs
));
98 return user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
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
;
113 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
114 fpregs
, 0, sizeof(*fpregs
));
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
;
133 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
134 fpregs
, 0, sizeof(*fpregs
));
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
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
166 .core_note_type
= NT_PRSTATUS
,
168 .size
= sizeof(long),
169 .align
= sizeof(long),
174 * FPU/Media register format is:
175 * FR0-63, FNER0-1, MSR0-1, ACC0-7, ACCG0-8, FSR
178 .core_note_type
= NT_PRFPREG
,
179 .n
= sizeof(struct user_fpmedia_regs
) / sizeof(long),
180 .size
= sizeof(long),
181 .align
= sizeof(long),
184 .active
= fpmregs_active
,
188 static const struct user_regset_view user_frv_native_view
= {
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
)
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
,
219 struct user_context
*user
= task
->thread
.user
;
221 if (regno
< 0 || regno
>= PT__END
)
231 ((unsigned long *) user
)[regno
] = data
;
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
)
261 int regno
= addr
>> 2;
262 unsigned long __user
*datap
= (unsigned long __user
*) data
;
265 /* read the word at location addr in the USER area. */
266 case PTRACE_PEEKUSR
: {
274 case 0 ... PT__END
- 1:
275 tmp
= get_reg(child
, regno
);
279 tmp
= child
->mm
->end_code
- child
->mm
->start_code
;
283 tmp
= child
->mm
->end_data
- child
->mm
->start_data
;
287 tmp
= child
->mm
->start_stack
- child
->mm
->start_brk
;
291 tmp
= child
->mm
->start_code
;
295 tmp
= child
->mm
->start_stack
;
304 ret
= put_user(tmp
, datap
);
308 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
314 case 0 ... PT__END
- 1:
315 ret
= put_reg(child
, regno
, data
);
320 case PTRACE_GETREGS
: /* Get all integer regs from the child. */
321 return copy_regset_to_user(child
, &user_frv_native_view
,
323 0, sizeof(child
->thread
.user
->i
),
326 case PTRACE_SETREGS
: /* Set all integer regs in the child. */
327 return copy_regset_from_user(child
, &user_frv_native_view
,
329 0, sizeof(child
->thread
.user
->i
),
332 case PTRACE_GETFPREGS
: /* Get the child FP/Media state. */
333 return copy_regset_to_user(child
, &user_frv_native_view
,
335 0, sizeof(child
->thread
.user
->f
),
338 case PTRACE_SETFPREGS
: /* Set the child FP/Media state. */
339 return copy_regset_from_user(child
, &user_frv_native_view
,
341 0, sizeof(child
->thread
.user
->f
),
345 ret
= ptrace_request(child
, request
, addr
, data
);
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
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);