blob: 6e467e3585b0b64ea224994db754145edbf636ea [file] [log] [blame]
Vineet Guptac08098f2013-01-18 15:12:21 +05301/*
2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3 *
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 */
8
9#include <linux/ptrace.h>
Vineet Gupta547f1122013-01-18 15:12:22 +053010#include <linux/tracehook.h>
11#include <linux/regset.h>
12#include <linux/unistd.h>
13#include <linux/elf.h>
14
15static struct callee_regs *task_callee_regs(struct task_struct *tsk)
16{
17 struct callee_regs *tmp = (struct callee_regs *)tsk->thread.callee_reg;
18 return tmp;
19}
20
21static 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)
25{
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;
30
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));
36
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);
42
Vineet Gupta2fa91902013-05-28 09:43:17 +053043#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);
48
49 REG_O_ZERO(pad);
Vineet Gupta547f1122013-01-18 15:12:22 +053050 REG_O_CHUNK(scratch, callee, ptregs);
51 REG_O_CHUNK(callee, efa, cregs);
52 REG_O_CHUNK(efa, stop_pc, &target->thread.fault_address);
53
54 if (!ret) {
55 if (in_brkpt_trap(ptregs)) {
56 stop_pc_val = target->thread.fault_address;
57 pr_debug("\t\tstop_pc (brk-pt)\n");
58 } else {
59 stop_pc_val = ptregs->ret;
60 pr_debug("\t\tstop_pc (others)\n");
61 }
62
63 REG_O_ONE(stop_pc, &stop_pc_val);
64 }
65
66 return ret;
67}
68
69static int genregs_set(struct task_struct *target,
70 const struct user_regset *regset,
71 unsigned int pos, unsigned int count,
72 const void *kbuf, const void __user *ubuf)
73{
74 const struct pt_regs *ptregs = task_pt_regs(target);
75 const struct callee_regs *cregs = task_callee_regs(target);
76 int ret = 0;
77
78#define REG_IN_CHUNK(FIRST, NEXT, PTR) \
79 if (!ret) \
80 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
81 (void *)(PTR), \
82 offsetof(struct user_regs_struct, FIRST), \
83 offsetof(struct user_regs_struct, NEXT));
84
85#define REG_IN_ONE(LOC, PTR) \
86 if (!ret) \
87 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
88 (void *)(PTR), \
89 offsetof(struct user_regs_struct, LOC), \
90 offsetof(struct user_regs_struct, LOC) + 4);
91
92#define REG_IGNORE_ONE(LOC) \
93 if (!ret) \
94 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
95 offsetof(struct user_regs_struct, LOC), \
96 offsetof(struct user_regs_struct, LOC) + 4);
97
Vineet Gupta2fa91902013-05-28 09:43:17 +053098 REG_IGNORE_ONE(pad);
Vineet Gupta547f1122013-01-18 15:12:22 +053099 /* TBD: disallow updates to STATUS32, orig_r8 etc*/
100 REG_IN_CHUNK(scratch, callee, ptregs); /* pt_regs[bta..orig_r8] */
101 REG_IN_CHUNK(callee, efa, cregs); /* callee_regs[r25..r13] */
102 REG_IGNORE_ONE(efa); /* efa update invalid */
103 REG_IN_ONE(stop_pc, &ptregs->ret); /* stop_pc: PC update */
104
105 return ret;
106}
107
108enum arc_getset {
109 REGSET_GENERAL,
110};
111
112static const struct user_regset arc_regsets[] = {
113 [REGSET_GENERAL] = {
114 .core_note_type = NT_PRSTATUS,
115 .n = ELF_NGREG,
116 .size = sizeof(unsigned long),
117 .align = sizeof(unsigned long),
118 .get = genregs_get,
119 .set = genregs_set,
120 }
121};
122
123static const struct user_regset_view user_arc_view = {
124 .name = UTS_MACHINE,
125 .e_machine = EM_ARCOMPACT,
126 .regsets = arc_regsets,
127 .n = ARRAY_SIZE(arc_regsets)
128};
129
130const struct user_regset_view *task_user_regset_view(struct task_struct *task)
131{
132 return &user_arc_view;
133}
Vineet Guptac08098f2013-01-18 15:12:21 +0530134
135void ptrace_disable(struct task_struct *child)
136{
137}
138
139long arch_ptrace(struct task_struct *child, long request,
140 unsigned long addr, unsigned long data)
141{
142 int ret = -EIO;
Vineet Gupta547f1122013-01-18 15:12:22 +0530143
144 pr_debug("REQ=%ld: ADDR =0x%lx, DATA=0x%lx)\n", request, addr, data);
145
146 switch (request) {
147 default:
148 ret = ptrace_request(child, request, addr, data);
149 break;
150 }
151
Vineet Guptac08098f2013-01-18 15:12:21 +0530152 return ret;
153}
154
Vineet Gupta547f1122013-01-18 15:12:22 +0530155asmlinkage int syscall_trace_entry(struct pt_regs *regs)
Vineet Guptac08098f2013-01-18 15:12:21 +0530156{
Vineet Gupta547f1122013-01-18 15:12:22 +0530157 if (tracehook_report_syscall_entry(regs))
158 return ULONG_MAX;
159
160 return regs->r8;
161}
162
163asmlinkage void syscall_trace_exit(struct pt_regs *regs)
164{
165 tracehook_report_syscall_exit(regs, 0);
Vineet Guptac08098f2013-01-18 15:12:21 +0530166}