2 * linux/arch/h8300/kernel/ptrace.c
4 * Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp>
6 * This file is subject to the terms and conditions of the GNU General
7 * Public License. See the file COPYING in the main directory of
8 * this archive for more details.
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/ptrace.h>
14 #include <linux/audit.h>
15 #include <linux/tracehook.h>
16 #include <linux/regset.h>
17 #include <linux/elf.h>
19 #define CCR_MASK 0x6f /* mode/imask not set */
20 #define EXR_MASK 0x80 /* modify only T */
22 #define PT_REG(r) offsetof(struct pt_regs, r)
24 extern void user_disable_single_step(struct task_struct
*child
);
26 /* Mapping from PT_xxx to the stack offset at which the register is
27 saved. Notice that usp has no stack-slot and needs to be treated
28 specially (see get_reg/put_reg below). */
29 static const int register_offset
[] = {
30 PT_REG(er1
), PT_REG(er2
), PT_REG(er3
), PT_REG(er4
),
31 PT_REG(er5
), PT_REG(er6
), PT_REG(er0
), -1,
32 PT_REG(orig_er0
), PT_REG(ccr
), PT_REG(pc
),
33 #if defined(CONFIG_CPU_H8S)
39 long h8300_get_reg(struct task_struct
*task
, int regno
)
43 return task
->thread
.usp
+ sizeof(long)*2;
46 return *(unsigned short *)(task
->thread
.esp0
+
47 register_offset
[regno
]);
49 return *(unsigned long *)(task
->thread
.esp0
+
50 register_offset
[regno
]);
54 int h8300_put_reg(struct task_struct
*task
, int regno
, unsigned long data
)
56 unsigned short oldccr
;
57 unsigned short oldexr
;
61 task
->thread
.usp
= data
- sizeof(long)*2;
63 oldccr
= *(unsigned short *)(task
->thread
.esp0
+
64 register_offset
[regno
]);
68 *(unsigned short *)(task
->thread
.esp0
+
69 register_offset
[regno
]) = data
;
72 oldexr
= *(unsigned short *)(task
->thread
.esp0
+
73 register_offset
[regno
]);
77 *(unsigned short *)(task
->thread
.esp0
+
78 register_offset
[regno
]) = data
;
81 *(unsigned long *)(task
->thread
.esp0
+
82 register_offset
[regno
]) = data
;
88 static int regs_get(struct task_struct
*target
,
89 const struct user_regset
*regset
,
90 unsigned int pos
, unsigned int count
,
91 void *kbuf
, void __user
*ubuf
)
94 struct user_regs_struct regs
;
95 long *reg
= (long *)®s
;
97 /* build user regs in buffer */
98 BUILD_BUG_ON(sizeof(regs
) % sizeof(long) != 0);
99 for (r
= 0; r
< sizeof(regs
) / sizeof(long); r
++)
100 *reg
++ = h8300_get_reg(target
, r
);
102 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
103 ®s
, 0, sizeof(regs
));
106 static int regs_set(struct task_struct
*target
,
107 const struct user_regset
*regset
,
108 unsigned int pos
, unsigned int count
,
109 const void *kbuf
, const void __user
*ubuf
)
113 struct user_regs_struct regs
;
116 /* build user regs in buffer */
117 BUILD_BUG_ON(sizeof(regs
) % sizeof(long) != 0);
118 for (reg
= (long *)®s
, r
= 0; r
< sizeof(regs
) / sizeof(long); r
++)
119 *reg
++ = h8300_get_reg(target
, r
);
121 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
122 ®s
, 0, sizeof(regs
));
126 /* write back to pt_regs */
127 for (reg
= (long *)®s
, r
= 0; r
< sizeof(regs
) / sizeof(long); r
++)
128 h8300_put_reg(target
, r
, *reg
++);
136 static const struct user_regset h8300_regsets
[] = {
138 .core_note_type
= NT_PRSTATUS
,
140 .size
= sizeof(long),
141 .align
= sizeof(long),
147 static const struct user_regset_view user_h8300_native_view
= {
149 .e_machine
= EM_H8_300
,
150 .regsets
= h8300_regsets
,
151 .n
= ARRAY_SIZE(h8300_regsets
),
154 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
156 return &user_h8300_native_view
;
159 void ptrace_disable(struct task_struct
*child
)
161 user_disable_single_step(child
);
164 long arch_ptrace(struct task_struct
*child
, long request
,
165 unsigned long addr
, unsigned long data
)
171 ret
= ptrace_request(child
, request
, addr
, data
);
177 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
181 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
182 tracehook_report_syscall_entry(regs
))
184 * Tracing decided this syscall should not happen.
185 * We'll return a bogus call number to get an ENOSYS
186 * error, but leave the original number in regs->regs[0].
190 audit_syscall_entry(regs
->er1
, regs
->er2
, regs
->er3
,
191 regs
->er4
, regs
->er5
);
193 return ret
?: regs
->er0
;
196 asmlinkage
void do_syscall_trace_leave(struct pt_regs
*regs
)
200 audit_syscall_exit(regs
);
202 step
= test_thread_flag(TIF_SINGLESTEP
);
203 if (step
|| test_thread_flag(TIF_SYSCALL_TRACE
))
204 tracehook_report_syscall_exit(regs
, step
);