idle governor: Avoid lock acquisition to read pm_qos before entering idle
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / frv / kernel / ptrace.c
blob9d68f7fac73041c6902c1e98b90580a59fe0f82f
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/system.h>
30 #include <asm/processor.h>
31 #include <asm/unistd.h>
34 * does not yet catch signals sent when the child dies.
35 * in exit.c or in signal.c.
39 * retrieve the contents of FRV userspace general registers
41 static int genregs_get(struct task_struct *target,
42 const struct user_regset *regset,
43 unsigned int pos, unsigned int count,
44 void *kbuf, void __user *ubuf)
46 const struct user_int_regs *iregs = &target->thread.user->i;
47 int ret;
49 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
50 iregs, 0, sizeof(*iregs));
51 if (ret < 0)
52 return ret;
54 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
55 sizeof(*iregs), -1);
59 * update the contents of the FRV userspace general registers
61 static int genregs_set(struct task_struct *target,
62 const struct user_regset *regset,
63 unsigned int pos, unsigned int count,
64 const void *kbuf, const void __user *ubuf)
66 struct user_int_regs *iregs = &target->thread.user->i;
67 unsigned int offs_gr0, offs_gr1;
68 int ret;
70 /* not allowed to set PSR or __status */
71 if (pos < offsetof(struct user_int_regs, psr) + sizeof(long) &&
72 pos + count > offsetof(struct user_int_regs, psr))
73 return -EIO;
75 if (pos < offsetof(struct user_int_regs, __status) + sizeof(long) &&
76 pos + count > offsetof(struct user_int_regs, __status))
77 return -EIO;
79 /* set the control regs */
80 offs_gr0 = offsetof(struct user_int_regs, gr[0]);
81 offs_gr1 = offsetof(struct user_int_regs, gr[1]);
82 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
83 iregs, 0, offs_gr0);
84 if (ret < 0)
85 return ret;
87 /* skip GR0/TBR */
88 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
89 offs_gr0, offs_gr1);
90 if (ret < 0)
91 return ret;
93 /* set the general regs */
94 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
95 &iregs->gr[1], offs_gr1, sizeof(*iregs));
96 if (ret < 0)
97 return ret;
99 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
100 sizeof(*iregs), -1);
104 * retrieve the contents of FRV userspace FP/Media registers
106 static int fpmregs_get(struct task_struct *target,
107 const struct user_regset *regset,
108 unsigned int pos, unsigned int count,
109 void *kbuf, void __user *ubuf)
111 const struct user_fpmedia_regs *fpregs = &target->thread.user->f;
112 int ret;
114 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
115 fpregs, 0, sizeof(*fpregs));
116 if (ret < 0)
117 return ret;
119 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
120 sizeof(*fpregs), -1);
124 * update the contents of the FRV userspace FP/Media registers
126 static int fpmregs_set(struct task_struct *target,
127 const struct user_regset *regset,
128 unsigned int pos, unsigned int count,
129 const void *kbuf, const void __user *ubuf)
131 struct user_fpmedia_regs *fpregs = &target->thread.user->f;
132 int ret;
134 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
135 fpregs, 0, sizeof(*fpregs));
136 if (ret < 0)
137 return ret;
139 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
140 sizeof(*fpregs), -1);
144 * determine if the FP/Media registers have actually been used
146 static int fpmregs_active(struct task_struct *target,
147 const struct user_regset *regset)
149 return tsk_used_math(target) ? regset->n : 0;
153 * Define the register sets available on the FRV under Linux
155 enum frv_regset {
156 REGSET_GENERAL,
157 REGSET_FPMEDIA,
160 static const struct user_regset frv_regsets[] = {
162 * General register format is:
163 * PSR, ISR, CCR, CCCR, LR, LCR, PC, (STATUS), SYSCALLNO, ORIG_G8
164 * GNER0-1, IACC0, TBR, GR1-63
166 [REGSET_GENERAL] = {
167 .core_note_type = NT_PRSTATUS,
168 .n = ELF_NGREG,
169 .size = sizeof(long),
170 .align = sizeof(long),
171 .get = genregs_get,
172 .set = genregs_set,
175 * FPU/Media register format is:
176 * FR0-63, FNER0-1, MSR0-1, ACC0-7, ACCG0-8, FSR
178 [REGSET_FPMEDIA] = {
179 .core_note_type = NT_PRFPREG,
180 .n = sizeof(struct user_fpmedia_regs) / sizeof(long),
181 .size = sizeof(long),
182 .align = sizeof(long),
183 .get = fpmregs_get,
184 .set = fpmregs_set,
185 .active = fpmregs_active,
189 static const struct user_regset_view user_frv_native_view = {
190 .name = "frv",
191 .e_machine = EM_FRV,
192 .regsets = frv_regsets,
193 .n = ARRAY_SIZE(frv_regsets),
196 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
198 return &user_frv_native_view;
202 * Get contents of register REGNO in task TASK.
204 static inline long get_reg(struct task_struct *task, int regno)
206 struct user_context *user = task->thread.user;
208 if (regno < 0 || regno >= PT__END)
209 return 0;
211 return ((unsigned long *) user)[regno];
215 * Write contents of register REGNO in task TASK.
217 static inline int put_reg(struct task_struct *task, int regno,
218 unsigned long data)
220 struct user_context *user = task->thread.user;
222 if (regno < 0 || regno >= PT__END)
223 return -EIO;
225 switch (regno) {
226 case PT_GR(0):
227 return 0;
228 case PT_PSR:
229 case PT__STATUS:
230 return -EIO;
231 default:
232 ((unsigned long *) user)[regno] = data;
233 return 0;
238 * Called by kernel/ptrace.c when detaching..
240 * Control h/w single stepping
242 void user_enable_single_step(struct task_struct *child)
244 child->thread.frame0->__status |= REG__STATUS_STEP;
247 void user_disable_single_step(struct task_struct *child)
249 child->thread.frame0->__status &= ~REG__STATUS_STEP;
252 void ptrace_disable(struct task_struct *child)
254 user_disable_single_step(child);
257 long arch_ptrace(struct task_struct *child, long request,
258 unsigned long addr, unsigned long data)
260 unsigned long tmp;
261 int ret;
262 int regno = addr >> 2;
263 unsigned long __user *datap = (unsigned long __user *) data;
265 switch (request) {
266 /* read the word at location addr in the USER area. */
267 case PTRACE_PEEKUSR: {
268 tmp = 0;
269 ret = -EIO;
270 if (addr & 3)
271 break;
273 ret = 0;
274 switch (regno) {
275 case 0 ... PT__END - 1:
276 tmp = get_reg(child, regno);
277 break;
279 case PT__END + 0:
280 tmp = child->mm->end_code - child->mm->start_code;
281 break;
283 case PT__END + 1:
284 tmp = child->mm->end_data - child->mm->start_data;
285 break;
287 case PT__END + 2:
288 tmp = child->mm->start_stack - child->mm->start_brk;
289 break;
291 case PT__END + 3:
292 tmp = child->mm->start_code;
293 break;
295 case PT__END + 4:
296 tmp = child->mm->start_stack;
297 break;
299 default:
300 ret = -EIO;
301 break;
304 if (ret == 0)
305 ret = put_user(tmp, datap);
306 break;
309 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
310 ret = -EIO;
311 if (addr & 3)
312 break;
314 switch (regno) {
315 case 0 ... PT__END - 1:
316 ret = put_reg(child, regno, data);
317 break;
319 break;
321 case PTRACE_GETREGS: /* Get all integer regs from the child. */
322 return copy_regset_to_user(child, &user_frv_native_view,
323 REGSET_GENERAL,
324 0, sizeof(child->thread.user->i),
325 datap);
327 case PTRACE_SETREGS: /* Set all integer regs in the child. */
328 return copy_regset_from_user(child, &user_frv_native_view,
329 REGSET_GENERAL,
330 0, sizeof(child->thread.user->i),
331 datap);
333 case PTRACE_GETFPREGS: /* Get the child FP/Media state. */
334 return copy_regset_to_user(child, &user_frv_native_view,
335 REGSET_FPMEDIA,
336 0, sizeof(child->thread.user->f),
337 datap);
339 case PTRACE_SETFPREGS: /* Set the child FP/Media state. */
340 return copy_regset_from_user(child, &user_frv_native_view,
341 REGSET_FPMEDIA,
342 0, sizeof(child->thread.user->f),
343 datap);
345 default:
346 ret = ptrace_request(child, request, addr, data);
347 break;
349 return ret;
353 * handle tracing of system call entry
354 * - return the revised system call number or ULONG_MAX to cause ENOSYS
356 asmlinkage unsigned long syscall_trace_entry(void)
358 __frame->__status |= REG__STATUS_SYSC_ENTRY;
359 if (tracehook_report_syscall_entry(__frame)) {
360 /* tracing decided this syscall should not happen, so
361 * We'll return a bogus call number to get an ENOSYS
362 * error, but leave the original number in
363 * __frame->syscallno
365 return ULONG_MAX;
368 return __frame->syscallno;
372 * handle tracing of system call exit
374 asmlinkage void syscall_trace_exit(void)
376 __frame->__status |= REG__STATUS_SYSC_EXIT;
377 tracehook_report_syscall_exit(__frame, 0);