2 * linux/arch/m68k/kernel/ptrace.c
4 * Copyright (C) 1994 by Hamish Macdonald
5 * Taken from linux/kernel/ptrace.c and modified for M680x0.
6 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of
10 * this archive for more details.
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/sched/task_stack.h>
17 #include <linux/smp.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/user.h>
21 #include <linux/signal.h>
22 #include <linux/regset.h>
23 #include <linux/elf.h>
24 #include <linux/seccomp.h>
25 #include <linux/uaccess.h>
27 #include <asm/processor.h>
32 * does not yet catch signals sent when the child dies.
33 * in exit.c or in signal.c.
36 /* determines which bits in the SR the user has access to. */
37 /* 1 = access 0 = no access */
38 #define SR_MASK 0x001f
40 /* sets the trace bits. */
41 #define TRACE_BITS 0xC000
45 /* Find the stack offset for a register, relative to thread.esp0. */
46 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
47 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
48 - sizeof(struct switch_stack))
49 /* Mapping from PT_xxx to the stack offset at which the register is
50 saved. Notice that usp has no stack-slot and needs to be treated
51 specially (see get_reg/put_reg below). */
52 static const int regoff[] = {
69 [16] = PT_REG(orig_d0),
75 * Get contents of register REGNO in task TASK.
77 static inline long get_reg(struct task_struct *task, int regno)
82 addr = &task->thread.usp;
83 else if (regno < ARRAY_SIZE(regoff))
84 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
87 /* Need to take stkadj into account. */
88 if (regno == PT_SR || regno == PT_PC) {
89 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
90 addr = (unsigned long *) ((unsigned long)addr + stkadj);
91 /* The sr is actually a 16 bit register. */
93 return *(unsigned short *)addr;
99 * Write contents of register REGNO in task TASK.
101 static inline int put_reg(struct task_struct *task, int regno,
107 addr = &task->thread.usp;
108 else if (regno < ARRAY_SIZE(regoff))
109 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
112 /* Need to take stkadj into account. */
113 if (regno == PT_SR || regno == PT_PC) {
114 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
115 addr = (unsigned long *) ((unsigned long)addr + stkadj);
116 /* The sr is actually a 16 bit register. */
117 if (regno == PT_SR) {
118 *(unsigned short *)addr = data;
127 * Make sure the single step bit is not set.
129 static inline void singlestep_disable(struct task_struct *child)
131 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
132 put_reg(child, PT_SR, tmp);
133 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE);
137 * Called by kernel/ptrace.c when detaching..
139 void ptrace_disable(struct task_struct *child)
141 singlestep_disable(child);
144 void user_enable_single_step(struct task_struct *child)
146 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
147 put_reg(child, PT_SR, tmp | T1_BIT);
148 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
152 void user_enable_block_step(struct task_struct *child)
154 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
155 put_reg(child, PT_SR, tmp | T0_BIT);
159 void user_disable_single_step(struct task_struct *child)
161 singlestep_disable(child);
164 long arch_ptrace(struct task_struct *child, long request,
165 unsigned long addr, unsigned long data)
169 int regno = addr >> 2; /* temporary hack. */
170 unsigned long __user *datap = (unsigned long __user *) data;
173 /* read the word at location addr in the USER area. */
178 if (regno >= 0 && regno < 19) {
179 tmp = get_reg(child, regno);
180 } else if (regno >= 21 && regno < 49) {
181 tmp = child->thread.fp[regno - 21];
182 /* Convert internal fpu reg representation
183 * into long double format
185 if (FPU_IS_EMU && (regno < 45) && !(regno % 3))
186 tmp = ((tmp & 0xffff0000) << 15) |
187 ((tmp & 0x0000ffff) << 16);
189 } else if (regno == 49) {
190 tmp = child->mm->start_code;
191 } else if (regno == 50) {
192 tmp = child->mm->start_data;
193 } else if (regno == 51) {
194 tmp = child->mm->end_code;
198 ret = put_user(tmp, datap);
202 /* write the word at location addr in the USER area */
206 if (regno == PT_SR) {
208 data |= get_reg(child, PT_SR) & ~SR_MASK;
210 if (regno >= 0 && regno < 19) {
211 if (put_reg(child, regno, data))
213 } else if (regno >= 21 && regno < 48) {
214 /* Convert long double format
215 * into internal fpu reg representation
217 if (FPU_IS_EMU && (regno < 45) && !(regno % 3)) {
219 data = (data & 0xffff0000) |
220 ((data & 0x0000ffff) >> 1);
222 child->thread.fp[regno - 21] = data;
227 case PTRACE_GETREGS: /* Get all gp regs from the child. */
228 for (i = 0; i < 19; i++) {
229 tmp = get_reg(child, i);
230 ret = put_user(tmp, datap);
237 case PTRACE_SETREGS: /* Set all gp regs in the child. */
238 for (i = 0; i < 19; i++) {
239 ret = get_user(tmp, datap);
244 tmp |= get_reg(child, PT_SR) & ~SR_MASK;
246 put_reg(child, i, tmp);
251 case PTRACE_GETFPREGS: /* Get the child FPU state. */
252 if (copy_to_user(datap, &child->thread.fp,
253 sizeof(struct user_m68kfp_struct)))
257 case PTRACE_SETFPREGS: /* Set the child FPU state. */
258 if (copy_from_user(&child->thread.fp, datap,
259 sizeof(struct user_m68kfp_struct)))
263 case PTRACE_GET_THREAD_AREA:
264 ret = put_user(task_thread_info(child)->tp_value, datap);
268 ret = ptrace_request(child, request, addr, data);
277 asmlinkage int syscall_trace_enter(void)
281 if (test_thread_flag(TIF_SYSCALL_TRACE))
282 ret = ptrace_report_syscall_entry(task_pt_regs(current));
284 if (secure_computing() == -1)
290 asmlinkage void syscall_trace_leave(void)
292 if (test_thread_flag(TIF_SYSCALL_TRACE))
293 ptrace_report_syscall_exit(task_pt_regs(current), 0);
296 #if defined(CONFIG_BINFMT_ELF_FDPIC) && defined(CONFIG_ELF_CORE)
298 * Currently the only thing that needs to use regsets for m68k is the
299 * coredump support of the elf_fdpic loader. Implement the minimum
300 * definitions required for that.
302 static int m68k_regset_get(struct task_struct *target,
303 const struct user_regset *regset,
306 struct pt_regs *ptregs = task_pt_regs(target);
307 u32 uregs[ELF_NGREG];
309 ELF_CORE_COPY_REGS(uregs, ptregs);
310 return membuf_write(&to, uregs, sizeof(uregs));
320 static const struct user_regset m68k_user_regsets[] = {
322 .core_note_type = NT_PRSTATUS,
325 .align = sizeof(u16),
326 .regset_get = m68k_regset_get,
330 .core_note_type = NT_PRFPREG,
331 .n = sizeof(struct user_m68kfp_struct) / sizeof(u32),
333 .align = sizeof(u32),
335 #endif /* CONFIG_FPU */
338 static const struct user_regset_view user_m68k_view = {
341 .ei_osabi = ELF_OSABI,
342 .regsets = m68k_user_regsets,
343 .n = ARRAY_SIZE(m68k_user_regsets)
346 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
348 return &user_m68k_view;
350 #endif /* CONFIG_BINFMT_ELF_FDPIC && CONFIG_ELF_CORE */