Merge tag 'gpio-v3.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-2.6.git] / arch / arc / kernel / ptrace.c
blob5d76706139dd36a246eb545f36fe42c1bf44ee9d
1 /*
2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/ptrace.h>
10 #include <linux/tracehook.h>
11 #include <linux/regset.h>
12 #include <linux/unistd.h>
13 #include <linux/elf.h>
15 static struct callee_regs *task_callee_regs(struct task_struct *tsk)
17 struct callee_regs *tmp = (struct callee_regs *)tsk->thread.callee_reg;
18 return tmp;
21 static int genregs_get(struct task_struct *target,
22 const struct user_regset *regset,
23 unsigned int pos, unsigned int count,
24 void *kbuf, void __user *ubuf)
26 const struct pt_regs *ptregs = task_pt_regs(target);
27 const struct callee_regs *cregs = task_callee_regs(target);
28 int ret = 0;
29 unsigned int stop_pc_val;
31 #define REG_O_CHUNK(START, END, PTR) \
32 if (!ret) \
33 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \
34 offsetof(struct user_regs_struct, START), \
35 offsetof(struct user_regs_struct, END));
37 #define REG_O_ONE(LOC, PTR) \
38 if (!ret) \
39 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \
40 offsetof(struct user_regs_struct, LOC), \
41 offsetof(struct user_regs_struct, LOC) + 4);
43 #define REG_O_ZERO(LOC) \
44 if (!ret) \
45 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, \
46 offsetof(struct user_regs_struct, LOC), \
47 offsetof(struct user_regs_struct, LOC) + 4);
49 REG_O_ZERO(pad);
50 REG_O_CHUNK(scratch, callee, ptregs);
51 REG_O_ZERO(pad2);
52 REG_O_CHUNK(callee, efa, cregs);
53 REG_O_CHUNK(efa, stop_pc, &target->thread.fault_address);
55 if (!ret) {
56 if (in_brkpt_trap(ptregs)) {
57 stop_pc_val = target->thread.fault_address;
58 pr_debug("\t\tstop_pc (brk-pt)\n");
59 } else {
60 stop_pc_val = ptregs->ret;
61 pr_debug("\t\tstop_pc (others)\n");
64 REG_O_ONE(stop_pc, &stop_pc_val);
67 return ret;
70 static int genregs_set(struct task_struct *target,
71 const struct user_regset *regset,
72 unsigned int pos, unsigned int count,
73 const void *kbuf, const void __user *ubuf)
75 const struct pt_regs *ptregs = task_pt_regs(target);
76 const struct callee_regs *cregs = task_callee_regs(target);
77 int ret = 0;
79 #define REG_IN_CHUNK(FIRST, NEXT, PTR) \
80 if (!ret) \
81 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
82 (void *)(PTR), \
83 offsetof(struct user_regs_struct, FIRST), \
84 offsetof(struct user_regs_struct, NEXT));
86 #define REG_IN_ONE(LOC, PTR) \
87 if (!ret) \
88 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
89 (void *)(PTR), \
90 offsetof(struct user_regs_struct, LOC), \
91 offsetof(struct user_regs_struct, LOC) + 4);
93 #define REG_IGNORE_ONE(LOC) \
94 if (!ret) \
95 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
96 offsetof(struct user_regs_struct, LOC), \
97 offsetof(struct user_regs_struct, LOC) + 4);
99 REG_IGNORE_ONE(pad);
100 /* TBD: disallow updates to STATUS32 etc*/
101 REG_IN_CHUNK(scratch, pad2, ptregs); /* pt_regs[bta..sp] */
102 REG_IGNORE_ONE(pad2);
103 REG_IN_CHUNK(callee, efa, cregs); /* callee_regs[r25..r13] */
104 REG_IGNORE_ONE(efa); /* efa update invalid */
105 REG_IGNORE_ONE(stop_pc); /* PC updated via @ret */
107 return ret;
110 enum arc_getset {
111 REGSET_GENERAL,
114 static const struct user_regset arc_regsets[] = {
115 [REGSET_GENERAL] = {
116 .core_note_type = NT_PRSTATUS,
117 .n = ELF_NGREG,
118 .size = sizeof(unsigned long),
119 .align = sizeof(unsigned long),
120 .get = genregs_get,
121 .set = genregs_set,
125 static const struct user_regset_view user_arc_view = {
126 .name = UTS_MACHINE,
127 .e_machine = EM_ARCOMPACT,
128 .regsets = arc_regsets,
129 .n = ARRAY_SIZE(arc_regsets)
132 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
134 return &user_arc_view;
137 void ptrace_disable(struct task_struct *child)
141 long arch_ptrace(struct task_struct *child, long request,
142 unsigned long addr, unsigned long data)
144 int ret = -EIO;
146 pr_debug("REQ=%ld: ADDR =0x%lx, DATA=0x%lx)\n", request, addr, data);
148 switch (request) {
149 default:
150 ret = ptrace_request(child, request, addr, data);
151 break;
154 return ret;
157 asmlinkage int syscall_trace_entry(struct pt_regs *regs)
159 if (tracehook_report_syscall_entry(regs))
160 return ULONG_MAX;
162 return regs->r8;
165 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
167 tracehook_report_syscall_exit(regs, 0);