2 * Copyright (C) 2005-2012 Imagination Technologies Ltd.
4 * This file is subject to the terms and conditions of the GNU General
5 * Public License. See the file COPYING in the main directory of
6 * this archive for more details.
9 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/ptrace.h>
13 #include <linux/user.h>
14 #include <linux/regset.h>
15 #include <linux/tracehook.h>
16 #include <linux/elf.h>
17 #include <linux/uaccess.h>
18 #include <linux/sched/task_stack.h>
20 #include <trace/syscall.h>
22 #define CREATE_TRACE_POINTS
23 #include <trace/events/syscalls.h>
26 * user_regset definitions.
29 int metag_gp_regs_copyout(const struct pt_regs
*regs
,
30 unsigned int pos
, unsigned int count
,
31 void *kbuf
, void __user
*ubuf
)
38 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
39 regs
->ctx
.DX
, 0, 4*16);
43 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
44 regs
->ctx
.AX
, 4*16, 4*20);
48 if (regs
->ctx
.SaveMask
& TBICTX_XEXT_BIT
)
49 ptr
= regs
->ctx
.Ext
.Ctx
.pExt
;
51 ptr
= ®s
->ctx
.Ext
.AX2
;
52 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
57 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
58 ®s
->ctx
.AX3
, 4*22, 4*24);
62 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
63 ®s
->ctx
.CurrPC
, 4*24, 4*25);
67 data
= (unsigned long)regs
->ctx
.Flags
;
68 if (regs
->ctx
.SaveMask
& TBICTX_CBUF_BIT
)
69 data
|= USER_GP_REGS_STATUS_CATCH_BIT
;
70 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
74 /* TXRPT, TXBPOBITS, TXMODE */
75 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
76 ®s
->ctx
.CurrRPT
, 4*26, 4*29);
80 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
86 int metag_gp_regs_copyin(struct pt_regs
*regs
,
87 unsigned int pos
, unsigned int count
,
88 const void *kbuf
, const void __user
*ubuf
)
95 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
96 regs
->ctx
.DX
, 0, 4*16);
100 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
101 regs
->ctx
.AX
, 4*16, 4*20);
105 if (regs
->ctx
.SaveMask
& TBICTX_XEXT_BIT
)
106 ptr
= regs
->ctx
.Ext
.Ctx
.pExt
;
108 ptr
= ®s
->ctx
.Ext
.AX2
;
109 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
114 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
115 ®s
->ctx
.AX3
, 4*22, 4*24);
119 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
120 ®s
->ctx
.CurrPC
, 4*24, 4*25);
124 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
128 regs
->ctx
.Flags
= data
& 0xffff;
129 if (data
& USER_GP_REGS_STATUS_CATCH_BIT
)
130 regs
->ctx
.SaveMask
|= TBICTX_XCBF_BIT
| TBICTX_CBUF_BIT
;
132 regs
->ctx
.SaveMask
&= ~TBICTX_CBUF_BIT
;
133 /* TXRPT, TXBPOBITS, TXMODE */
134 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
135 ®s
->ctx
.CurrRPT
, 4*26, 4*29);
140 static int metag_gp_regs_get(struct task_struct
*target
,
141 const struct user_regset
*regset
,
142 unsigned int pos
, unsigned int count
,
143 void *kbuf
, void __user
*ubuf
)
145 const struct pt_regs
*regs
= task_pt_regs(target
);
146 return metag_gp_regs_copyout(regs
, pos
, count
, kbuf
, ubuf
);
149 static int metag_gp_regs_set(struct task_struct
*target
,
150 const struct user_regset
*regset
,
151 unsigned int pos
, unsigned int count
,
152 const void *kbuf
, const void __user
*ubuf
)
154 struct pt_regs
*regs
= task_pt_regs(target
);
155 return metag_gp_regs_copyin(regs
, pos
, count
, kbuf
, ubuf
);
158 int metag_cb_regs_copyout(const struct pt_regs
*regs
,
159 unsigned int pos
, unsigned int count
,
160 void *kbuf
, void __user
*ubuf
)
165 if (regs
->ctx
.SaveMask
& TBICTX_XCBF_BIT
)
166 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
167 regs
->extcb0
, 0, 4*4);
169 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
174 int metag_cb_regs_copyin(struct pt_regs
*regs
,
175 unsigned int pos
, unsigned int count
,
176 const void *kbuf
, const void __user
*ubuf
)
181 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
182 regs
->extcb0
, 0, 4*4);
186 static int metag_cb_regs_get(struct task_struct
*target
,
187 const struct user_regset
*regset
,
188 unsigned int pos
, unsigned int count
,
189 void *kbuf
, void __user
*ubuf
)
191 const struct pt_regs
*regs
= task_pt_regs(target
);
192 return metag_cb_regs_copyout(regs
, pos
, count
, kbuf
, ubuf
);
195 static int metag_cb_regs_set(struct task_struct
*target
,
196 const struct user_regset
*regset
,
197 unsigned int pos
, unsigned int count
,
198 const void *kbuf
, const void __user
*ubuf
)
200 struct pt_regs
*regs
= task_pt_regs(target
);
201 return metag_cb_regs_copyin(regs
, pos
, count
, kbuf
, ubuf
);
204 int metag_rp_state_copyout(const struct pt_regs
*regs
,
205 unsigned int pos
, unsigned int count
,
206 void *kbuf
, void __user
*ubuf
)
212 /* Empty read pipeline */
213 if (!(regs
->ctx
.SaveMask
& TBICTX_CBRP_BIT
)) {
214 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
219 mask
= (regs
->ctx
.CurrDIVTIME
& TXDIVTIME_RPMASK_BITS
) >>
222 /* Read pipeline entries */
223 ptr
= (void *)®s
->extcb0
[1];
224 for (i
= 0; i
< 6; ++i
, ++ptr
) {
226 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
227 ptr
, 8*i
, 8*(i
+ 1));
229 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
,
230 &ubuf
, 8*i
, 8*(i
+ 1));
234 /* Mask of entries */
235 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
241 int metag_rp_state_copyin(struct pt_regs
*regs
,
242 unsigned int pos
, unsigned int count
,
243 const void *kbuf
, const void __user
*ubuf
)
245 struct user_rp_state rp
;
246 unsigned long long *ptr
;
249 /* Read the entire pipeline before making any changes */
250 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
255 /* Write pipeline entries */
256 ptr
= (void *)®s
->extcb0
[1];
257 for (i
= 0; i
< 6; ++i
, ++ptr
)
258 if (rp
.mask
& (1 << i
))
259 *ptr
= rp
.entries
[i
];
261 /* Update RPMask in TXDIVTIME */
262 regs
->ctx
.CurrDIVTIME
&= ~TXDIVTIME_RPMASK_BITS
;
263 regs
->ctx
.CurrDIVTIME
|= (rp
.mask
<< TXDIVTIME_RPMASK_S
)
264 & TXDIVTIME_RPMASK_BITS
;
266 /* Set/clear flags to indicate catch/read pipeline state */
268 regs
->ctx
.SaveMask
|= TBICTX_XCBF_BIT
| TBICTX_CBRP_BIT
;
270 regs
->ctx
.SaveMask
&= ~TBICTX_CBRP_BIT
;
275 static int metag_rp_state_get(struct task_struct
*target
,
276 const struct user_regset
*regset
,
277 unsigned int pos
, unsigned int count
,
278 void *kbuf
, void __user
*ubuf
)
280 const struct pt_regs
*regs
= task_pt_regs(target
);
281 return metag_rp_state_copyout(regs
, pos
, count
, kbuf
, ubuf
);
284 static int metag_rp_state_set(struct task_struct
*target
,
285 const struct user_regset
*regset
,
286 unsigned int pos
, unsigned int count
,
287 const void *kbuf
, const void __user
*ubuf
)
289 struct pt_regs
*regs
= task_pt_regs(target
);
290 return metag_rp_state_copyin(regs
, pos
, count
, kbuf
, ubuf
);
293 static int metag_tls_get(struct task_struct
*target
,
294 const struct user_regset
*regset
,
295 unsigned int pos
, unsigned int count
,
296 void *kbuf
, void __user
*ubuf
)
298 void __user
*tls
= target
->thread
.tls_ptr
;
299 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &tls
, 0, -1);
302 static int metag_tls_set(struct task_struct
*target
,
303 const struct user_regset
*regset
,
304 unsigned int pos
, unsigned int count
,
305 const void *kbuf
, const void __user
*ubuf
)
310 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &tls
, 0, -1);
314 target
->thread
.tls_ptr
= tls
;
325 static const struct user_regset metag_regsets
[] = {
327 .core_note_type
= NT_PRSTATUS
,
329 .size
= sizeof(long),
330 .align
= sizeof(long long),
331 .get
= metag_gp_regs_get
,
332 .set
= metag_gp_regs_set
,
335 .core_note_type
= NT_METAG_CBUF
,
336 .n
= sizeof(struct user_cb_regs
) / sizeof(long),
337 .size
= sizeof(long),
338 .align
= sizeof(long long),
339 .get
= metag_cb_regs_get
,
340 .set
= metag_cb_regs_set
,
342 [REGSET_READPIPE
] = {
343 .core_note_type
= NT_METAG_RPIPE
,
344 .n
= sizeof(struct user_rp_state
) / sizeof(long),
345 .size
= sizeof(long),
346 .align
= sizeof(long long),
347 .get
= metag_rp_state_get
,
348 .set
= metag_rp_state_set
,
351 .core_note_type
= NT_METAG_TLS
,
353 .size
= sizeof(void *),
354 .align
= sizeof(void *),
355 .get
= metag_tls_get
,
356 .set
= metag_tls_set
,
360 static const struct user_regset_view user_metag_view
= {
362 .e_machine
= EM_METAG
,
363 .regsets
= metag_regsets
,
364 .n
= ARRAY_SIZE(metag_regsets
)
367 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
369 return &user_metag_view
;
373 * Called by kernel/ptrace.c when detaching..
375 * Make sure single step bits etc are not set.
377 void ptrace_disable(struct task_struct
*child
)
379 /* nothing to do.. */
382 long arch_ptrace(struct task_struct
*child
, long request
, unsigned long addr
,
389 ret
= ptrace_request(child
, request
, addr
, data
);
396 int syscall_trace_enter(struct pt_regs
*regs
)
400 if (test_thread_flag(TIF_SYSCALL_TRACE
))
401 ret
= tracehook_report_syscall_entry(regs
);
403 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
404 trace_sys_enter(regs
, regs
->ctx
.DX
[0].U1
);
406 return ret
? -1 : regs
->ctx
.DX
[0].U1
;
409 void syscall_trace_leave(struct pt_regs
*regs
)
411 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
412 trace_sys_exit(regs
, regs
->ctx
.DX
[0].U1
);
414 if (test_thread_flag(TIF_SYSCALL_TRACE
))
415 tracehook_report_syscall_exit(regs
, 0);