From faa47b466935e73251b18b17d51455b06ed65764 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sun, 10 May 2009 21:14:52 +0200 Subject: m68k: use generic code for ptrace requests 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 Signed-off-by: Geert Uytterhoeven --- arch/m68k/include/asm/ptrace.h | 17 ++++++++++ arch/m68k/kernel/ptrace.c | 75 ++++++++++++------------------------------ 2 files changed, 38 insertions(+), 54 deletions(-) (limited to 'arch') diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h index 8c9194b98548..117adb1e4806 100644 --- a/arch/m68k/include/asm/ptrace.h +++ b/arch/m68k/include/asm/ptrace.h @@ -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 @@ -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 */ diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c index 2075543c2d92..bd0842059d11 100644 --- a/arch/m68k/kernel/ptrace.c +++ b/arch/m68k/kernel/ptrace.c @@ -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) @@ -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) @@ -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; @@ -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); -- cgit v1.2.3-59-g8ed1b From f195e2bff3000b8bc251ee6f685e0f027eec6f25 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Tue, 19 May 2009 15:38:01 +0200 Subject: m68k: ptrace fixes This fixes the following issues in ptrace: - when single stepping into the signal handler stop at the first insn of the handler - handle non-zero stkadj when accessing pc and sr in ptregs - correctly handle PT_SR in PTRACE_POKEUSR - report -EIO when trying to read unknown offset in PTRACE_PEEKUSR Additionally, the handling of the special case that PT_SR accesses a 16 bit word instead of a 32 bit word has been moved into get_reg/put_reg. Signed-off-by: Andreas Schwab Signed-off-by: Geert Uytterhoeven --- arch/m68k/kernel/entry.S | 6 +++++- arch/m68k/kernel/ptrace.c | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 17 deletions(-) (limited to 'arch') diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S index c5b33634c980..77fc7c16bf48 100644 --- a/arch/m68k/kernel/entry.S +++ b/arch/m68k/kernel/entry.S @@ -179,7 +179,11 @@ do_signal_return: addql #8,%sp RESTORE_SWITCH_STACK addql #4,%sp - jbra resume_userspace + tstl %d0 + jeq resume_userspace + | when single stepping into handler stop at the first insn + btst #6,%curptr@(TASK_INFO+TINFO_FLAGS+2) + jeq resume_userspace do_delayed_trace: bclr #7,%sp@(PT_OFF_SR) | clear trace bit in SR diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c index bd0842059d11..1fc217e5f06b 100644 --- a/arch/m68k/kernel/ptrace.c +++ b/arch/m68k/kernel/ptrace.c @@ -46,7 +46,7 @@ /* Mapping from PT_xxx to the stack offset at which the register is saved. Notice that usp has no stack-slot and needs to be treated specially (see get_reg/put_reg below). */ -static int regoff[] = { +static const int regoff[] = { [0] = PT_REG(d1), [1] = PT_REG(d2), [2] = PT_REG(d3), @@ -81,6 +81,14 @@ static inline long get_reg(struct task_struct *task, int regno) addr = (unsigned long *)(task->thread.esp0 + regoff[regno]); else return 0; + /* Need to take stkadj into account. */ + if (regno == PT_SR || regno == PT_PC) { + long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj)); + addr = (unsigned long *) ((unsigned long)addr + stkadj); + /* The sr is actually a 16 bit register. */ + if (regno == PT_SR) + return *(unsigned short *)addr; + } return *addr; } @@ -98,6 +106,16 @@ static inline int put_reg(struct task_struct *task, int regno, addr = (unsigned long *)(task->thread.esp0 + regoff[regno]); else return -1; + /* Need to take stkadj into account. */ + if (regno == PT_SR || regno == PT_PC) { + long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj)); + addr = (unsigned long *) ((unsigned long)addr + stkadj); + /* The sr is actually a 16 bit register. */ + if (regno == PT_SR) { + *(unsigned short *)addr = data; + return 0; + } + } *addr = data; return 0; } @@ -107,7 +125,7 @@ static inline int put_reg(struct task_struct *task, int regno, */ static inline void singlestep_disable(struct task_struct *child) { - unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); + unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS; put_reg(child, PT_SR, tmp); clear_tsk_thread_flag(child, TIF_DELAYED_TRACE); } @@ -122,15 +140,15 @@ void ptrace_disable(struct task_struct *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)); + unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS; + put_reg(child, PT_SR, tmp | T1_BIT); 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)); + unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS; + put_reg(child, PT_SR, tmp | T0_BIT); } void user_disable_single_step(struct task_struct *child) @@ -152,8 +170,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) if (addr >= 0 && addr < 19) { tmp = get_reg(child, addr); - if (addr == PT_SR) - tmp >>= 16; } else if (addr >= 21 && addr < 49) { tmp = child->thread.fp[addr - 21]; /* Convert internal fpu reg representation @@ -163,7 +179,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) tmp = ((tmp & 0xffff0000) << 15) | ((tmp & 0x0000ffff) << 16); } else - break; + goto out_eio; ret = put_user(tmp, (unsigned long *)data); break; @@ -174,9 +190,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) if (addr == PT_SR) { data &= SR_MASK; - data <<= 16; - data |= get_reg(child, PT_SR) & ~(SR_MASK << 16); - } else if (addr >= 0 && addr < 19) { + data |= get_reg(child, PT_SR) & ~SR_MASK; + } + if (addr >= 0 && addr < 19) { if (put_reg(child, addr, data)) goto out_eio; } else if (addr >= 21 && addr < 48) { @@ -196,8 +212,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) case PTRACE_GETREGS: /* Get all gp regs from the child. */ for (i = 0; i < 19; i++) { tmp = get_reg(child, i); - if (i == PT_SR) - tmp >>= 16; ret = put_user(tmp, (unsigned long *)data); if (ret) break; @@ -212,8 +226,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) break; if (i == PT_SR) { tmp &= SR_MASK; - tmp <<= 16; - tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16); + tmp |= get_reg(child, PT_SR) & ~SR_MASK; } put_reg(child, i, tmp); data += sizeof(long); -- cgit v1.2.3-59-g8ed1b From f60a5572679ef8508b62bd82063b05ffbe838716 Mon Sep 17 00:00:00 2001 From: Greg Ungerer Date: Tue, 7 Jul 2009 15:54:54 +1000 Subject: m68knommu: define arch_has_single_step() and friends Towards adding CONFIG_UTRACE support for non-mmu m68k add arch_has_single_step, and its support functions user_enable_single_step() and user_disable_single_step(). [Geert] m68k conflict resolution from linux-next Signed-off-by: Greg Ungerer Signed-off-by: Geert Uytterhoeven --- arch/m68k/include/asm/ptrace.h | 2 +- arch/m68knommu/kernel/ptrace.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'arch') diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h index 117adb1e4806..a6ab663bcc2e 100644 --- a/arch/m68k/include/asm/ptrace.h +++ b/arch/m68k/include/asm/ptrace.h @@ -90,11 +90,11 @@ extern void show_regs(struct pt_regs *); */ 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 *); +#ifdef CONFIG_MMU #define arch_has_block_step() (1) extern void user_enable_block_step(struct task_struct *); #endif diff --git a/arch/m68knommu/kernel/ptrace.c b/arch/m68knommu/kernel/ptrace.c index ef70ca070ce2..4d3828959fb0 100644 --- a/arch/m68knommu/kernel/ptrace.c +++ b/arch/m68knommu/kernel/ptrace.c @@ -86,6 +86,20 @@ static inline int put_reg(struct task_struct *task, int regno, return 0; } +void user_enable_single_step(struct task_struct *task) +{ + unsigned long srflags; + srflags = get_reg(task, PT_SR) | (TRACE_BITS << 16); + put_reg(task, PT_SR, srflags); +} + +void user_disable_single_step(struct task_struct *task) +{ + unsigned long srflags; + srflags = get_reg(task, PT_SR) & ~(TRACE_BITS << 16); + put_reg(task, PT_SR, srflags); +} + /* * Called by kernel/ptrace.c when detaching.. * @@ -93,10 +107,8 @@ static inline int put_reg(struct task_struct *task, int regno, */ void ptrace_disable(struct task_struct *child) { - unsigned long tmp; /* make sure the single step bit is not set. */ - tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); - put_reg(child, PT_SR, tmp); + user_disable_single_step(child); } long arch_ptrace(struct task_struct *child, long request, long addr, long data) -- cgit v1.2.3-59-g8ed1b From 5cdef24b2ab44ca587d46d212468b0cfb5b83a59 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 16 Sep 2009 12:44:25 -0400 Subject: m68k: Make thread_info.h usable from assembly. [Geert] pulls in , which contains C only. So the include must be moved inside #ifndef __ASSEMBLY__. Signed-off-by: Tim Abbott Cc: Geert Uytterhoeven Cc: Roman Zippel Cc: linux-m68k@lists.linux-m68k.org Cc: Sam Ravnborg Signed-off-by: Geert Uytterhoeven --- arch/m68k/include/asm/thread_info_mm.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h index b6da3882be9b..167e518db41b 100644 --- a/arch/m68k/include/asm/thread_info_mm.h +++ b/arch/m68k/include/asm/thread_info_mm.h @@ -4,10 +4,12 @@ #ifndef ASM_OFFSETS_C #include #endif -#include #include #include +#ifndef __ASSEMBLY__ +#include + struct thread_info { struct task_struct *task; /* main task structure */ unsigned long flags; @@ -16,6 +18,7 @@ struct thread_info { __u32 cpu; /* should always be 0 on m68k */ struct restart_block restart_block; }; +#endif /* __ASSEMBLY__ */ #define PREEMPT_ACTIVE 0x4000000 -- cgit v1.2.3-59-g8ed1b From 7c5fd5619dc89fb52d2c2cf144fc6e4365427b86 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 27 Sep 2009 13:57:55 -0400 Subject: m68k: Cleanup linker scripts using new linker script macros. Signed-off-by: Tim Abbott Tested-by: Andreas Schwab Cc: Roman Zippel Cc: Sam Ravnborg Signed-off-by: Geert Uytterhoeven --- arch/m68k/kernel/vmlinux-std.lds | 61 +++++++++------------------------------ arch/m68k/kernel/vmlinux-sun3.lds | 54 +++++----------------------------- 2 files changed, 20 insertions(+), 95 deletions(-) (limited to 'arch') diff --git a/arch/m68k/kernel/vmlinux-std.lds b/arch/m68k/kernel/vmlinux-std.lds index 47eac19e8f61..878be5f38cad 100644 --- a/arch/m68k/kernel/vmlinux-std.lds +++ b/arch/m68k/kernel/vmlinux-std.lds @@ -2,6 +2,7 @@ #include #include +#include OUTPUT_FORMAT("elf32-m68k", "elf32-m68k", "elf32-m68k") OUTPUT_ARCH(m68k) @@ -22,73 +23,37 @@ SECTIONS _etext = .; /* End of text section */ - . = ALIGN(16); /* Exception table */ - __start___ex_table = .; - __ex_table : { *(__ex_table) } - __stop___ex_table = .; + EXCEPTION_TABLE(16) RODATA - .data : { /* Data */ - DATA_DATA - CONSTRUCTORS - } + RW_DATA_SECTION(16, PAGE_SIZE, THREAD_SIZE) - . = ALIGN(16); - .data.cacheline_aligned : { *(.data.cacheline_aligned) } - - .bss : { *(.bss) } /* BSS */ + BSS_SECTION(0, 0, 0) _edata = .; /* End of data section */ /* will be freed after init */ . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; - .init.text : { - _sinittext = .; - INIT_TEXT - _einittext = .; - } :data - .init.data : { INIT_DATA } - . = ALIGN(16); - __setup_start = .; - .init.setup : { *(.init.setup) } - __setup_end = .; - __initcall_start = .; - .initcall.init : { - INITCALLS - } - __initcall_end = .; - __con_initcall_start = .; - .con_initcall.init : { *(.con_initcall.init) } - __con_initcall_end = .; + INIT_TEXT_SECTION(PAGE_SIZE) :data + INIT_DATA_SECTION(16) .m68k_fixup : { __start_fixup = .; *(.m68k_fixup) __stop_fixup = .; } - SECURITY_INIT -#ifdef CONFIG_BLK_DEV_INITRD - . = ALIGN(8192); - __initramfs_start = .; - .init.ramfs : { *(.init.ramfs) } - __initramfs_end = .; -#endif NOTES - . = ALIGN(8192); - __init_end = .; - - .data.init_task : { *(.data.init_task) } /* The initial task and kernel stack */ + .init_end : { + /* This ALIGN be in a section so that _end is at the end of the + load segment. */ + . = ALIGN(PAGE_SIZE); + __init_end = .; + } _end = . ; - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } + STABS_DEBUG .comment 0 : { *(.comment) } /* Sections to be discarded */ diff --git a/arch/m68k/kernel/vmlinux-sun3.lds b/arch/m68k/kernel/vmlinux-sun3.lds index 03efaf04d7d7..1ad6b7ad2c17 100644 --- a/arch/m68k/kernel/vmlinux-sun3.lds +++ b/arch/m68k/kernel/vmlinux-sun3.lds @@ -2,6 +2,7 @@ #include #include +#include OUTPUT_FORMAT("elf32-m68k", "elf32-m68k", "elf32-m68k") OUTPUT_ARCH(m68k) @@ -23,14 +24,8 @@ SECTIONS _etext = .; /* End of text section */ - .data : { /* Data */ - DATA_DATA - CONSTRUCTORS - . = ALIGN(16); /* Exception table */ - __start___ex_table = .; - *(__ex_table) - __stop___ex_table = .; - } :data + EXCEPTION_TABLE(16) :data + RW_DATA_SECTION(16, PAGE_SIZE, THREAD_SIZE) :data /* End of data goes *here* so that freeing init code works properly. */ _edata = .; NOTES @@ -38,56 +33,21 @@ SECTIONS /* will be freed after init */ . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; - .init.text : { - _sinittext = .; - INIT_TEXT - _einittext = .; - } - .init.data : { INIT_DATA } - . = ALIGN(16); - __setup_start = .; - .init.setup : { *(.init.setup) } - __setup_end = .; - __initcall_start = .; - .initcall.init : { - INITCALLS - } - __initcall_end = .; - __con_initcall_start = .; - .con_initcall.init : { *(.con_initcall.init) } - __con_initcall_end = .; + INIT_TEXT_SECTION(PAGE_SIZE) + INIT_DATA_SECTION(16) .m68k_fixup : { __start_fixup = .; *(.m68k_fixup) __stop_fixup = .; } - SECURITY_INIT -#ifdef CONFIG_BLK_DEV_INITRD - . = ALIGN(PAGE_SIZE); - __initramfs_start = .; - .init.ramfs : { *(.init.ramfs) } - __initramfs_end = .; -#endif . = ALIGN(PAGE_SIZE); __init_end = .; - .data.init.task : { *(.data.init_task) } - - .bss : { *(.bss) } /* BSS */ + BSS_SECTION(0, 0, 0) _end = . ; - .crap : { - /* Stabs debugging sections. */ - *(.stab) - *(.stabstr) - *(.stab.excl) - *(.stab.exclstr) - *(.stab.index) - *(.stab.indexstr) - *(.comment) - *(.note) - } + STABS_DEBUG /* Sections to be discarded */ DISCARDS -- cgit v1.2.3-59-g8ed1b From 87fbaf6aea142b01756bbea09461daee41d93c0b Mon Sep 17 00:00:00 2001 From: John Kacur Date: Mon, 12 Oct 2009 23:09:24 +0200 Subject: m68k: Remove the BKL from sys_execve This seems like a copy-and-paste from code that no-longer needs the BKL Just remove it. Signed-off-by: John Kacur Reviewed-by: Frederic Weisbecker Signed-off-by: Geert Uytterhoeven --- arch/m68k/kernel/process.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'arch') diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c index 41230c595a8e..05296593e718 100644 --- a/arch/m68k/kernel/process.c +++ b/arch/m68k/kernel/process.c @@ -317,15 +317,12 @@ asmlinkage int sys_execve(char __user *name, char __user * __user *argv, char __ char * filename; struct pt_regs *regs = (struct pt_regs *) &name; - lock_kernel(); filename = getname(name); error = PTR_ERR(filename); if (IS_ERR(filename)) - goto out; + return error; error = do_execve(filename, argv, envp, regs); putname(filename); -out: - unlock_kernel(); return error; } -- cgit v1.2.3-59-g8ed1b