1 // TODO some minor issues
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 2001 - 2007 Tensilica Inc.
9 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
10 * Chris Zankel <chris@zankel.net>
11 * Scott Foehner<sfoehner@yahoo.com>,
13 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
19 #include <linux/errno.h>
20 #include <linux/ptrace.h>
21 #include <linux/smp.h>
22 #include <linux/security.h>
23 #include <linux/signal.h>
25 #include <asm/pgtable.h>
27 #include <asm/uaccess.h>
28 #include <asm/ptrace.h>
30 #include <asm/coprocessor.h>
33 void user_enable_single_step(struct task_struct
*child
)
35 child
->ptrace
|= PT_SINGLESTEP
;
38 void user_disable_single_step(struct task_struct
*child
)
40 child
->ptrace
&= ~PT_SINGLESTEP
;
44 * Called by kernel/ptrace.c when detaching to disable single stepping.
47 void ptrace_disable(struct task_struct
*child
)
52 int ptrace_getregs(struct task_struct
*child
, void __user
*uregs
)
54 struct pt_regs
*regs
= task_pt_regs(child
);
55 xtensa_gregset_t __user
*gregset
= uregs
;
56 unsigned long wm
= regs
->wmask
;
57 unsigned long wb
= regs
->windowbase
;
60 if (!access_ok(VERIFY_WRITE
, uregs
, sizeof(xtensa_gregset_t
)))
63 __put_user(regs
->pc
, &gregset
->pc
);
64 __put_user(regs
->ps
& ~(1 << PS_EXCM_BIT
), &gregset
->ps
);
65 __put_user(regs
->lbeg
, &gregset
->lbeg
);
66 __put_user(regs
->lend
, &gregset
->lend
);
67 __put_user(regs
->lcount
, &gregset
->lcount
);
68 __put_user(regs
->windowstart
, &gregset
->windowstart
);
69 __put_user(regs
->windowbase
, &gregset
->windowbase
);
71 live
= (wm
& 2) ? 4 : (wm
& 4) ? 8 : (wm
& 8) ? 12 : 16;
73 for (i
= 0; i
< live
; i
++)
74 __put_user(regs
->areg
[i
],gregset
->a
+((wb
*4+i
)%XCHAL_NUM_AREGS
));
75 for (i
= XCHAL_NUM_AREGS
- (wm
>> 4) * 4; i
< XCHAL_NUM_AREGS
; i
++)
76 __put_user(regs
->areg
[i
],gregset
->a
+((wb
*4+i
)%XCHAL_NUM_AREGS
));
81 int ptrace_setregs(struct task_struct
*child
, void __user
*uregs
)
83 struct pt_regs
*regs
= task_pt_regs(child
);
84 xtensa_gregset_t
*gregset
= uregs
;
85 const unsigned long ps_mask
= PS_CALLINC_MASK
| PS_OWB_MASK
;
89 if (!access_ok(VERIFY_WRITE
, uregs
, sizeof(xtensa_gregset_t
)))
92 __get_user(regs
->pc
, &gregset
->pc
);
93 __get_user(ps
, &gregset
->ps
);
94 __get_user(regs
->lbeg
, &gregset
->lbeg
);
95 __get_user(regs
->lend
, &gregset
->lend
);
96 __get_user(regs
->lcount
, &gregset
->lcount
);
97 __get_user(regs
->windowstart
, &gregset
->windowstart
);
98 __get_user(wb
, &gregset
->windowbase
);
100 regs
->ps
= (regs
->ps
& ~ps_mask
) | (ps
& ps_mask
) | (1 << PS_EXCM_BIT
);
102 if (wb
>= XCHAL_NUM_AREGS
/ 4)
105 regs
->windowbase
= wb
;
107 if (wb
!= 0 && __copy_from_user(regs
->areg
+ XCHAL_NUM_AREGS
- wb
* 4,
108 gregset
->a
, wb
* 16))
111 if (__copy_from_user(regs
->areg
, gregset
->a
+ wb
*4, (WSBITS
-wb
) * 16))
118 int ptrace_getxregs(struct task_struct
*child
, void __user
*uregs
)
120 struct pt_regs
*regs
= task_pt_regs(child
);
121 struct thread_info
*ti
= task_thread_info(child
);
122 elf_xtregs_t __user
*xtregs
= uregs
;
125 if (!access_ok(VERIFY_WRITE
, uregs
, sizeof(elf_xtregs_t
)))
128 #if XTENSA_HAVE_COPROCESSORS
129 /* Flush all coprocessor registers to memory. */
130 coprocessor_flush_all(ti
);
131 ret
|= __copy_to_user(&xtregs
->cp0
, &ti
->xtregs_cp
,
132 sizeof(xtregs_coprocessor_t
));
134 ret
|= __copy_to_user(&xtregs
->opt
, ®s
->xtregs_opt
,
135 sizeof(xtregs
->opt
));
136 ret
|= __copy_to_user(&xtregs
->user
,&ti
->xtregs_user
,
137 sizeof(xtregs
->user
));
139 return ret
? -EFAULT
: 0;
142 int ptrace_setxregs(struct task_struct
*child
, void __user
*uregs
)
144 struct thread_info
*ti
= task_thread_info(child
);
145 struct pt_regs
*regs
= task_pt_regs(child
);
146 elf_xtregs_t
*xtregs
= uregs
;
149 if (!access_ok(VERIFY_READ
, uregs
, sizeof(elf_xtregs_t
)))
152 #if XTENSA_HAVE_COPROCESSORS
153 /* Flush all coprocessors before we overwrite them. */
154 coprocessor_flush_all(ti
);
155 coprocessor_release_all(ti
);
157 ret
|= __copy_from_user(&ti
->xtregs_cp
, &xtregs
->cp0
,
158 sizeof(xtregs_coprocessor_t
));
160 ret
|= __copy_from_user(®s
->xtregs_opt
, &xtregs
->opt
,
161 sizeof(xtregs
->opt
));
162 ret
|= __copy_from_user(&ti
->xtregs_user
, &xtregs
->user
,
163 sizeof(xtregs
->user
));
165 return ret
? -EFAULT
: 0;
168 int ptrace_peekusr(struct task_struct
*child
, long regno
, long __user
*ret
)
170 struct pt_regs
*regs
;
173 regs
= task_pt_regs(child
);
174 tmp
= 0; /* Default return value. */
178 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
179 tmp
= regs
->areg
[regno
- REG_AR_BASE
];
182 case REG_A_BASE
... REG_A_BASE
+ 15:
183 tmp
= regs
->areg
[regno
- REG_A_BASE
];
191 /* Note: PS.EXCM is not set while user task is running;
192 * its being set in regs is for exception handling
194 tmp
= (regs
->ps
& ~(1 << PS_EXCM_BIT
));
202 unsigned long wb
= regs
->windowbase
;
203 unsigned long ws
= regs
->windowstart
;
204 tmp
= ((ws
>>wb
) | (ws
<<(WSBITS
-wb
))) & ((1<<WSBITS
)-1);
230 return put_user(tmp
, ret
);
233 int ptrace_pokeusr(struct task_struct
*child
, long regno
, long val
)
235 struct pt_regs
*regs
;
236 regs
= task_pt_regs(child
);
239 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
240 regs
->areg
[regno
- REG_AR_BASE
] = val
;
243 case REG_A_BASE
... REG_A_BASE
+ 15:
244 regs
->areg
[regno
- REG_A_BASE
] = val
;
261 long arch_ptrace(struct task_struct
*child
, long request
,
262 unsigned long addr
, unsigned long data
)
265 void __user
*datap
= (void __user
*) data
;
268 case PTRACE_PEEKTEXT
: /* read word at location addr. */
269 case PTRACE_PEEKDATA
:
270 ret
= generic_ptrace_peekdata(child
, addr
, data
);
273 case PTRACE_PEEKUSR
: /* read register specified by addr. */
274 ret
= ptrace_peekusr(child
, addr
, datap
);
277 case PTRACE_POKETEXT
: /* write the word at location addr. */
278 case PTRACE_POKEDATA
:
279 ret
= generic_ptrace_pokedata(child
, addr
, data
);
282 case PTRACE_POKEUSR
: /* write register specified by addr. */
283 ret
= ptrace_pokeusr(child
, addr
, data
);
287 ret
= ptrace_getregs(child
, datap
);
291 ret
= ptrace_setregs(child
, datap
);
294 case PTRACE_GETXTREGS
:
295 ret
= ptrace_getxregs(child
, datap
);
298 case PTRACE_SETXTREGS
:
299 ret
= ptrace_setxregs(child
, datap
);
303 ret
= ptrace_request(child
, request
, addr
, data
);
310 void do_syscall_trace(void)
313 * The 0x80 provides a way for the tracing parent to distinguish
314 * between a syscall stop and SIGTRAP delivery
316 ptrace_notify(SIGTRAP
|((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
319 * this isn't the same as continuing with a signal, but it will do
320 * for normal use. strace only continues with a signal if the
321 * stopping signal is not SIGTRAP. -brl
323 if (current
->exit_code
) {
324 send_sig(current
->exit_code
, current
, 1);
325 current
->exit_code
= 0;
329 void do_syscall_trace_enter(struct pt_regs
*regs
)
331 if (test_thread_flag(TIF_SYSCALL_TRACE
)
332 && (current
->ptrace
& PT_PTRACED
))
336 audit_syscall_entry(current
, AUDIT_ARCH_XTENSA
..);
340 void do_syscall_trace_leave(struct pt_regs
*regs
)
342 if ((test_thread_flag(TIF_SYSCALL_TRACE
))
343 && (current
->ptrace
& PT_PTRACED
))