aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/kernel/ptrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/m68k/kernel/ptrace.c')
-rw-r--r--arch/m68k/kernel/ptrace.c112
1 files changed, 46 insertions, 66 deletions
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 2075543c2d92..1fc217e5f06b 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -35,7 +35,9 @@
35#define SR_MASK 0x001f 35#define SR_MASK 0x001f
36 36
37/* sets the trace bits. */ 37/* sets the trace bits. */
38#define TRACE_BITS 0x8000 38#define TRACE_BITS 0xC000
39#define T1_BIT 0x8000
40#define T0_BIT 0x4000
39 41
40/* Find the stack offset for a register, relative to thread.esp0. */ 42/* Find the stack offset for a register, relative to thread.esp0. */
41#define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg) 43#define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
@@ -44,7 +46,7 @@
44/* Mapping from PT_xxx to the stack offset at which the register is 46/* Mapping from PT_xxx to the stack offset at which the register is
45 saved. Notice that usp has no stack-slot and needs to be treated 47 saved. Notice that usp has no stack-slot and needs to be treated
46 specially (see get_reg/put_reg below). */ 48 specially (see get_reg/put_reg below). */
47static int regoff[] = { 49static const int regoff[] = {
48 [0] = PT_REG(d1), 50 [0] = PT_REG(d1),
49 [1] = PT_REG(d2), 51 [1] = PT_REG(d2),
50 [2] = PT_REG(d3), 52 [2] = PT_REG(d3),
@@ -79,6 +81,14 @@ static inline long get_reg(struct task_struct *task, int regno)
79 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]); 81 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
80 else 82 else
81 return 0; 83 return 0;
84 /* Need to take stkadj into account. */
85 if (regno == PT_SR || regno == PT_PC) {
86 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
87 addr = (unsigned long *) ((unsigned long)addr + stkadj);
88 /* The sr is actually a 16 bit register. */
89 if (regno == PT_SR)
90 return *(unsigned short *)addr;
91 }
82 return *addr; 92 return *addr;
83} 93}
84 94
@@ -96,6 +106,16 @@ static inline int put_reg(struct task_struct *task, int regno,
96 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]); 106 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
97 else 107 else
98 return -1; 108 return -1;
109 /* Need to take stkadj into account. */
110 if (regno == PT_SR || regno == PT_PC) {
111 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
112 addr = (unsigned long *) ((unsigned long)addr + stkadj);
113 /* The sr is actually a 16 bit register. */
114 if (regno == PT_SR) {
115 *(unsigned short *)addr = data;
116 return 0;
117 }
118 }
99 *addr = data; 119 *addr = data;
100 return 0; 120 return 0;
101} 121}
@@ -105,7 +125,7 @@ static inline int put_reg(struct task_struct *task, int regno,
105 */ 125 */
106static inline void singlestep_disable(struct task_struct *child) 126static inline void singlestep_disable(struct task_struct *child)
107{ 127{
108 unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); 128 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
109 put_reg(child, PT_SR, tmp); 129 put_reg(child, PT_SR, tmp);
110 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE); 130 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE);
111} 131}
@@ -118,18 +138,30 @@ void ptrace_disable(struct task_struct *child)
118 singlestep_disable(child); 138 singlestep_disable(child);
119} 139}
120 140
141void user_enable_single_step(struct task_struct *child)
142{
143 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
144 put_reg(child, PT_SR, tmp | T1_BIT);
145 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
146}
147
148void user_enable_block_step(struct task_struct *child)
149{
150 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
151 put_reg(child, PT_SR, tmp | T0_BIT);
152}
153
154void user_disable_single_step(struct task_struct *child)
155{
156 singlestep_disable(child);
157}
158
121long arch_ptrace(struct task_struct *child, long request, long addr, long data) 159long arch_ptrace(struct task_struct *child, long request, long addr, long data)
122{ 160{
123 unsigned long tmp; 161 unsigned long tmp;
124 int i, ret = 0; 162 int i, ret = 0;
125 163
126 switch (request) { 164 switch (request) {
127 /* when I and D space are separate, these will need to be fixed. */
128 case PTRACE_PEEKTEXT: /* read word at location addr. */
129 case PTRACE_PEEKDATA:
130 ret = generic_ptrace_peekdata(child, addr, data);
131 break;
132
133 /* read the word at location addr in the USER area. */ 165 /* read the word at location addr in the USER area. */
134 case PTRACE_PEEKUSR: 166 case PTRACE_PEEKUSR:
135 if (addr & 3) 167 if (addr & 3)
@@ -138,8 +170,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
138 170
139 if (addr >= 0 && addr < 19) { 171 if (addr >= 0 && addr < 19) {
140 tmp = get_reg(child, addr); 172 tmp = get_reg(child, addr);
141 if (addr == PT_SR)
142 tmp >>= 16;
143 } else if (addr >= 21 && addr < 49) { 173 } else if (addr >= 21 && addr < 49) {
144 tmp = child->thread.fp[addr - 21]; 174 tmp = child->thread.fp[addr - 21];
145 /* Convert internal fpu reg representation 175 /* Convert internal fpu reg representation
@@ -149,16 +179,10 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
149 tmp = ((tmp & 0xffff0000) << 15) | 179 tmp = ((tmp & 0xffff0000) << 15) |
150 ((tmp & 0x0000ffff) << 16); 180 ((tmp & 0x0000ffff) << 16);
151 } else 181 } else
152 break; 182 goto out_eio;
153 ret = put_user(tmp, (unsigned long *)data); 183 ret = put_user(tmp, (unsigned long *)data);
154 break; 184 break;
155 185
156 /* when I and D space are separate, this will have to be fixed. */
157 case PTRACE_POKETEXT: /* write the word at location addr. */
158 case PTRACE_POKEDATA:
159 ret = generic_ptrace_pokedata(child, addr, data);
160 break;
161
162 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 186 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
163 if (addr & 3) 187 if (addr & 3)
164 goto out_eio; 188 goto out_eio;
@@ -166,9 +190,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
166 190
167 if (addr == PT_SR) { 191 if (addr == PT_SR) {
168 data &= SR_MASK; 192 data &= SR_MASK;
169 data <<= 16; 193 data |= get_reg(child, PT_SR) & ~SR_MASK;
170 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16); 194 }
171 } else if (addr >= 0 && addr < 19) { 195 if (addr >= 0 && addr < 19) {
172 if (put_reg(child, addr, data)) 196 if (put_reg(child, addr, data))
173 goto out_eio; 197 goto out_eio;
174 } else if (addr >= 21 && addr < 48) { 198 } else if (addr >= 21 && addr < 48) {
@@ -185,52 +209,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
185 goto out_eio; 209 goto out_eio;
186 break; 210 break;
187 211
188 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
189 case PTRACE_CONT: /* restart after signal. */
190 if (!valid_signal(data))
191 goto out_eio;
192
193 if (request == PTRACE_SYSCALL)
194 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
195 else
196 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
197 child->exit_code = data;
198 singlestep_disable(child);
199 wake_up_process(child);
200 break;
201
202 /*
203 * make the child exit. Best I can do is send it a sigkill.
204 * perhaps it should be put in the status that it wants to
205 * exit.
206 */
207 case PTRACE_KILL:
208 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
209 break;
210 child->exit_code = SIGKILL;
211 singlestep_disable(child);
212 wake_up_process(child);
213 break;
214
215 case PTRACE_SINGLESTEP: /* set the trap flag. */
216 if (!valid_signal(data))
217 goto out_eio;
218
219 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
220 tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16);
221 put_reg(child, PT_SR, tmp);
222 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
223
224 child->exit_code = data;
225 /* give it a chance to run. */
226 wake_up_process(child);
227 break;
228
229 case PTRACE_GETREGS: /* Get all gp regs from the child. */ 212 case PTRACE_GETREGS: /* Get all gp regs from the child. */
230 for (i = 0; i < 19; i++) { 213 for (i = 0; i < 19; i++) {
231 tmp = get_reg(child, i); 214 tmp = get_reg(child, i);
232 if (i == PT_SR)
233 tmp >>= 16;
234 ret = put_user(tmp, (unsigned long *)data); 215 ret = put_user(tmp, (unsigned long *)data);
235 if (ret) 216 if (ret)
236 break; 217 break;
@@ -245,8 +226,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
245 break; 226 break;
246 if (i == PT_SR) { 227 if (i == PT_SR) {
247 tmp &= SR_MASK; 228 tmp &= SR_MASK;
248 tmp <<= 16; 229 tmp |= get_reg(child, PT_SR) & ~SR_MASK;
249 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
250 } 230 }
251 put_reg(child, i, tmp); 231 put_reg(child, i, tmp);
252 data += sizeof(long); 232 data += sizeof(long);