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 static unsigned long user_txstatus(const struct pt_regs
*regs
)
31 unsigned long data
= (unsigned long)regs
->ctx
.Flags
;
33 if (regs
->ctx
.SaveMask
& TBICTX_CBUF_BIT
)
34 data
|= USER_GP_REGS_STATUS_CATCH_BIT
;
39 int metag_gp_regs_copyout(const struct pt_regs
*regs
,
40 unsigned int pos
, unsigned int count
,
41 void *kbuf
, void __user
*ubuf
)
48 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
49 regs
->ctx
.DX
, 0, 4*16);
53 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
54 regs
->ctx
.AX
, 4*16, 4*20);
58 if (regs
->ctx
.SaveMask
& TBICTX_XEXT_BIT
)
59 ptr
= regs
->ctx
.Ext
.Ctx
.pExt
;
61 ptr
= ®s
->ctx
.Ext
.AX2
;
62 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
67 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
68 ®s
->ctx
.AX3
, 4*22, 4*24);
72 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
73 ®s
->ctx
.CurrPC
, 4*24, 4*25);
77 data
= user_txstatus(regs
);
78 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
82 /* TXRPT, TXBPOBITS, TXMODE */
83 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
84 ®s
->ctx
.CurrRPT
, 4*26, 4*29);
88 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
94 int metag_gp_regs_copyin(struct pt_regs
*regs
,
95 unsigned int pos
, unsigned int count
,
96 const void *kbuf
, const void __user
*ubuf
)
103 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
104 regs
->ctx
.DX
, 0, 4*16);
108 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
109 regs
->ctx
.AX
, 4*16, 4*20);
113 if (regs
->ctx
.SaveMask
& TBICTX_XEXT_BIT
)
114 ptr
= regs
->ctx
.Ext
.Ctx
.pExt
;
116 ptr
= ®s
->ctx
.Ext
.AX2
;
117 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
122 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
123 ®s
->ctx
.AX3
, 4*22, 4*24);
127 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
128 ®s
->ctx
.CurrPC
, 4*24, 4*25);
132 data
= user_txstatus(regs
);
133 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
137 regs
->ctx
.Flags
= data
& 0xffff;
138 if (data
& USER_GP_REGS_STATUS_CATCH_BIT
)
139 regs
->ctx
.SaveMask
|= TBICTX_XCBF_BIT
| TBICTX_CBUF_BIT
;
141 regs
->ctx
.SaveMask
&= ~TBICTX_CBUF_BIT
;
142 /* TXRPT, TXBPOBITS, TXMODE */
143 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
144 ®s
->ctx
.CurrRPT
, 4*26, 4*29);
149 static int metag_gp_regs_get(struct task_struct
*target
,
150 const struct user_regset
*regset
,
151 unsigned int pos
, unsigned int count
,
152 void *kbuf
, void __user
*ubuf
)
154 const struct pt_regs
*regs
= task_pt_regs(target
);
155 return metag_gp_regs_copyout(regs
, pos
, count
, kbuf
, ubuf
);
158 static int metag_gp_regs_set(struct task_struct
*target
,
159 const struct user_regset
*regset
,
160 unsigned int pos
, unsigned int count
,
161 const void *kbuf
, const void __user
*ubuf
)
163 struct pt_regs
*regs
= task_pt_regs(target
);
164 return metag_gp_regs_copyin(regs
, pos
, count
, kbuf
, ubuf
);
167 int metag_cb_regs_copyout(const struct pt_regs
*regs
,
168 unsigned int pos
, unsigned int count
,
169 void *kbuf
, void __user
*ubuf
)
174 if (regs
->ctx
.SaveMask
& TBICTX_XCBF_BIT
)
175 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
176 regs
->extcb0
, 0, 4*4);
178 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
183 int metag_cb_regs_copyin(struct pt_regs
*regs
,
184 unsigned int pos
, unsigned int count
,
185 const void *kbuf
, const void __user
*ubuf
)
190 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
191 regs
->extcb0
, 0, 4*4);
195 static int metag_cb_regs_get(struct task_struct
*target
,
196 const struct user_regset
*regset
,
197 unsigned int pos
, unsigned int count
,
198 void *kbuf
, void __user
*ubuf
)
200 const struct pt_regs
*regs
= task_pt_regs(target
);
201 return metag_cb_regs_copyout(regs
, pos
, count
, kbuf
, ubuf
);
204 static int metag_cb_regs_set(struct task_struct
*target
,
205 const struct user_regset
*regset
,
206 unsigned int pos
, unsigned int count
,
207 const void *kbuf
, const void __user
*ubuf
)
209 struct pt_regs
*regs
= task_pt_regs(target
);
210 return metag_cb_regs_copyin(regs
, pos
, count
, kbuf
, ubuf
);
213 int metag_rp_state_copyout(const struct pt_regs
*regs
,
214 unsigned int pos
, unsigned int count
,
215 void *kbuf
, void __user
*ubuf
)
221 /* Empty read pipeline */
222 if (!(regs
->ctx
.SaveMask
& TBICTX_CBRP_BIT
)) {
223 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
228 mask
= (regs
->ctx
.CurrDIVTIME
& TXDIVTIME_RPMASK_BITS
) >>
231 /* Read pipeline entries */
232 ptr
= (void *)®s
->extcb0
[1];
233 for (i
= 0; i
< 6; ++i
, ++ptr
) {
235 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
236 ptr
, 8*i
, 8*(i
+ 1));
238 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
,
239 &ubuf
, 8*i
, 8*(i
+ 1));
243 /* Mask of entries */
244 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
250 int metag_rp_state_copyin(struct pt_regs
*regs
,
251 unsigned int pos
, unsigned int count
,
252 const void *kbuf
, const void __user
*ubuf
)
254 struct user_rp_state rp
;
255 unsigned long long *ptr
;
260 /* Read the entire pipeline before making any changes */
261 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
266 /* Write pipeline entries */
267 ptr
= (void *)®s
->extcb0
[1];
268 for (i
= 0; i
< 6; ++i
, ++ptr
)
269 if (rp
.mask
& (1 << i
))
270 *ptr
= rp
.entries
[i
];
272 /* Update RPMask in TXDIVTIME */
273 regs
->ctx
.CurrDIVTIME
&= ~TXDIVTIME_RPMASK_BITS
;
274 regs
->ctx
.CurrDIVTIME
|= (rp
.mask
<< TXDIVTIME_RPMASK_S
)
275 & TXDIVTIME_RPMASK_BITS
;
277 /* Set/clear flags to indicate catch/read pipeline state */
279 regs
->ctx
.SaveMask
|= TBICTX_XCBF_BIT
| TBICTX_CBRP_BIT
;
281 regs
->ctx
.SaveMask
&= ~TBICTX_CBRP_BIT
;
286 static int metag_rp_state_get(struct task_struct
*target
,
287 const struct user_regset
*regset
,
288 unsigned int pos
, unsigned int count
,
289 void *kbuf
, void __user
*ubuf
)
291 const struct pt_regs
*regs
= task_pt_regs(target
);
292 return metag_rp_state_copyout(regs
, pos
, count
, kbuf
, ubuf
);
295 static int metag_rp_state_set(struct task_struct
*target
,
296 const struct user_regset
*regset
,
297 unsigned int pos
, unsigned int count
,
298 const void *kbuf
, const void __user
*ubuf
)
300 struct pt_regs
*regs
= task_pt_regs(target
);
301 return metag_rp_state_copyin(regs
, pos
, count
, kbuf
, ubuf
);
304 static int metag_tls_get(struct task_struct
*target
,
305 const struct user_regset
*regset
,
306 unsigned int pos
, unsigned int count
,
307 void *kbuf
, void __user
*ubuf
)
309 void __user
*tls
= target
->thread
.tls_ptr
;
310 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &tls
, 0, -1);
313 static int metag_tls_set(struct task_struct
*target
,
314 const struct user_regset
*regset
,
315 unsigned int pos
, unsigned int count
,
316 const void *kbuf
, const void __user
*ubuf
)
319 void __user
*tls
= target
->thread
.tls_ptr
;
321 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &tls
, 0, -1);
325 target
->thread
.tls_ptr
= tls
;
336 static const struct user_regset metag_regsets
[] = {
338 .core_note_type
= NT_PRSTATUS
,
340 .size
= sizeof(long),
341 .align
= sizeof(long long),
342 .get
= metag_gp_regs_get
,
343 .set
= metag_gp_regs_set
,
346 .core_note_type
= NT_METAG_CBUF
,
347 .n
= sizeof(struct user_cb_regs
) / sizeof(long),
348 .size
= sizeof(long),
349 .align
= sizeof(long long),
350 .get
= metag_cb_regs_get
,
351 .set
= metag_cb_regs_set
,
353 [REGSET_READPIPE
] = {
354 .core_note_type
= NT_METAG_RPIPE
,
355 .n
= sizeof(struct user_rp_state
) / sizeof(long),
356 .size
= sizeof(long),
357 .align
= sizeof(long long),
358 .get
= metag_rp_state_get
,
359 .set
= metag_rp_state_set
,
362 .core_note_type
= NT_METAG_TLS
,
364 .size
= sizeof(void *),
365 .align
= sizeof(void *),
366 .get
= metag_tls_get
,
367 .set
= metag_tls_set
,
371 static const struct user_regset_view user_metag_view
= {
373 .e_machine
= EM_METAG
,
374 .regsets
= metag_regsets
,
375 .n
= ARRAY_SIZE(metag_regsets
)
378 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
380 return &user_metag_view
;
384 * Called by kernel/ptrace.c when detaching..
386 * Make sure single step bits etc are not set.
388 void ptrace_disable(struct task_struct
*child
)
390 /* nothing to do.. */
393 long arch_ptrace(struct task_struct
*child
, long request
, unsigned long addr
,
400 ret
= ptrace_request(child
, request
, addr
, data
);
407 int syscall_trace_enter(struct pt_regs
*regs
)
411 if (test_thread_flag(TIF_SYSCALL_TRACE
))
412 ret
= tracehook_report_syscall_entry(regs
);
414 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
415 trace_sys_enter(regs
, regs
->ctx
.DX
[0].U1
);
417 return ret
? -1 : regs
->ctx
.DX
[0].U1
;
420 void syscall_trace_leave(struct pt_regs
*regs
)
422 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
423 trace_sys_exit(regs
, regs
->ctx
.DX
[0].U1
);
425 if (test_thread_flag(TIF_SYSCALL_TRACE
))
426 tracehook_report_syscall_exit(regs
, 0);