Skip to content

Commit

Permalink
m68k: use generic code for ptrace requests
Browse files Browse the repository at this point in the history
Remove all but PTRACE_{PEEK,POKE}USR and PTRACE_{GET,SET}{REGS,FPREGS}
from arch_ptrace and let the rest be handled by generic code.  Define
PTRACE_SINGLEBLOCK to enable singleblock tracing.
[Geert] Not yet applicable for m68knommu

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
  • Loading branch information
Andreas Schwab authored and Geert Uytterhoeven committed Dec 4, 2009
1 parent 4f672ce commit faa47b4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 54 deletions.
17 changes: 17 additions & 0 deletions arch/m68k/include/asm/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct switch_stack {
#define PTRACE_GETFPREGS 14
#define PTRACE_SETFPREGS 15

#define PTRACE_SINGLEBLOCK 33 /* resume execution until next branch */

#ifdef __KERNEL__

#ifndef PS_S
Expand All @@ -82,6 +84,21 @@ struct switch_stack {
#define instruction_pointer(regs) ((regs)->pc)
#define profile_pc(regs) instruction_pointer(regs)
extern void show_regs(struct pt_regs *);

/*
* These are defined as per linux/ptrace.h, which see.
*/
struct task_struct;

#ifdef CONFIG_MMU
#define arch_has_single_step() (1)
extern void user_enable_single_step(struct task_struct *);
extern void user_disable_single_step(struct task_struct *);

#define arch_has_block_step() (1)
extern void user_enable_block_step(struct task_struct *);
#endif

#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */
#endif /* _M68K_PTRACE_H */
75 changes: 21 additions & 54 deletions arch/m68k/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
#define SR_MASK 0x001f

/* sets the trace bits. */
#define TRACE_BITS 0x8000
#define TRACE_BITS 0xC000
#define T1_BIT 0x8000
#define T0_BIT 0x4000

/* Find the stack offset for a register, relative to thread.esp0. */
#define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
Expand Down Expand Up @@ -118,18 +120,30 @@ void ptrace_disable(struct task_struct *child)
singlestep_disable(child);
}

void user_enable_single_step(struct task_struct *child)
{
unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
put_reg(child, PT_SR, tmp | (T1_BIT << 16));
set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
}

void user_enable_block_step(struct task_struct *child)
{
unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
put_reg(child, PT_SR, tmp | (T0_BIT << 16));
}

void user_disable_single_step(struct task_struct *child)
{
singlestep_disable(child);
}

long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{
unsigned long tmp;
int i, ret = 0;

switch (request) {
/* when I and D space are separate, these will need to be fixed. */
case PTRACE_PEEKTEXT: /* read word at location addr. */
case PTRACE_PEEKDATA:
ret = generic_ptrace_peekdata(child, addr, data);
break;

/* read the word at location addr in the USER area. */
case PTRACE_PEEKUSR:
if (addr & 3)
Expand All @@ -153,12 +167,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
ret = put_user(tmp, (unsigned long *)data);
break;

/* when I and D space are separate, this will have to be fixed. */
case PTRACE_POKETEXT: /* write the word at location addr. */
case PTRACE_POKEDATA:
ret = generic_ptrace_pokedata(child, addr, data);
break;

case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
if (addr & 3)
goto out_eio;
Expand All @@ -185,47 +193,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
goto out_eio;
break;

case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
case PTRACE_CONT: /* restart after signal. */
if (!valid_signal(data))
goto out_eio;

if (request == PTRACE_SYSCALL)
set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
else
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
child->exit_code = data;
singlestep_disable(child);
wake_up_process(child);
break;

/*
* make the child exit. Best I can do is send it a sigkill.
* perhaps it should be put in the status that it wants to
* exit.
*/
case PTRACE_KILL:
if (child->exit_state == EXIT_ZOMBIE) /* already dead */
break;
child->exit_code = SIGKILL;
singlestep_disable(child);
wake_up_process(child);
break;

case PTRACE_SINGLESTEP: /* set the trap flag. */
if (!valid_signal(data))
goto out_eio;

clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16);
put_reg(child, PT_SR, tmp);
set_tsk_thread_flag(child, TIF_DELAYED_TRACE);

child->exit_code = data;
/* give it a chance to run. */
wake_up_process(child);
break;

case PTRACE_GETREGS: /* Get all gp regs from the child. */
for (i = 0; i < 19; i++) {
tmp = get_reg(child, i);
Expand Down

0 comments on commit faa47b4

Please sign in to comment.