Index: arch/v850/kernel/entry.S =================================================================== RCS file: /var/cvs/uClinux-2.4.x/arch/v850/kernel/entry.S,v retrieving revision 1.2 diff -u -r1.2 entry.S --- arch/v850/kernel/entry.S 2002/01/10 12:36:30 1.2 +++ arch/v850/kernel/entry.S 2002/02/27 02:44:11 @@ -2,8 +2,8 @@ * arch/v850/kernel/entry.S -- Low-level system-call handling, trap handlers, * and context-switching * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001,2002 NEC Corporation + * Copyright (C) 2001,2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -1011,5 +1011,14 @@ .long CSYM(sys_setgid) .long CSYM(sys_setfsuid) // 215 .long CSYM(sys_setfsgid) + .long CSYM(sys_pivot_root) + .long CSYM(sys_mincore) // just returns ENOSYS without MMU + .long CSYM(sys_madvise) // just returns ENOSYS without MMU + .long CSYM(sys_getdents64) // 220 + .long CSYM(sys_fcntl64) + .long CSYM(sys_ni_syscall) // Reserved for TUX + .long CSYM(sys_ni_syscall) // Reserved for `security' + .long CSYM(sys_gettid) + .long CSYM(sys_ni_syscall) // 225, sys_readahead on i386 - .space (NR_syscalls-216)*4 + .space (NR_syscalls-225)*4 Index: arch/v850/kernel/ptrace.c =================================================================== RCS file: /var/cvs/uClinux-2.4.x/arch/v850/kernel/ptrace.c,v retrieving revision 1.2 diff -u -r1.2 ptrace.c --- arch/v850/kernel/ptrace.c 2002/01/10 12:36:30 1.2 +++ arch/v850/kernel/ptrace.c 2002/02/27 02:44:12 @@ -1,9 +1,18 @@ /* * arch/v850/kernel/ptrace.c -- `ptrace' system call * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2002 NEC Corporation + * Copyright (C) 2002 Miles Bader * + * Derived from arch/mips/kernel/ptrace.c: + * + * Copyright (C) 1992 Ross Biro + * Copyright (C) Linus Torvalds + * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle + * Copyright (C) 1996 David S. Miller + * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com + * Copyright (C) 1999 MIPS Technologies, Inc. + * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this * archive for more details. @@ -11,15 +20,184 @@ * Written by Miles Bader */ +#include +#include +#include +#include +#include + #include +#include +#include +#include + +int sys_ptrace(long request, long pid, long addr, long data) +{ + struct task_struct *child; + int rval; + + lock_kernel(); + +#if 0 + printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n", + (int) request, (int) pid, (unsigned long) addr, + (unsigned long) data); +#endif + + if (request == PTRACE_TRACEME) { + /* are we already being traced? */ + if (current->ptrace & PT_PTRACED) { + rval = -EPERM; + goto out; + } + /* set the ptrace bit in the process flags. */ + current->ptrace |= PT_PTRACED; + rval = 0; + goto out; + } + rval = -ESRCH; + read_lock(&tasklist_lock); + child = find_task_by_pid(pid); + if (child) + get_task_struct(child); + read_unlock(&tasklist_lock); + if (!child) + goto out; + + rval = -EPERM; + if (pid == 1) /* you may not mess with init */ + goto out; + + if (request == PTRACE_ATTACH) { + rval = ptrace_attach(child); + goto out_tsk; + } + rval = -ESRCH; + if (!(child->ptrace & PT_PTRACED)) + goto out_tsk; + if (child->state != TASK_STOPPED) { + if (request != PTRACE_KILL) + goto out_tsk; + } + if (child->p_pptr != current) + goto out_tsk; + + switch (request) { + case PTRACE_PEEKTEXT: /* read word at location addr. */ + case PTRACE_PEEKDATA:{ + unsigned long tmp; + int copied; + + copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); + rval = -EIO; + if (copied != sizeof(tmp)) + break; + rval = put_user(tmp,(unsigned long *) data); + + goto out; + } + + /* Read the word at location addr in the USER area. */ + case PTRACE_PEEKUSR: + if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) { + struct pt_regs *regs = task_regs (child); + unsigned long val = + *(unsigned long *)((char *)regs + addr); + rval = put_user (val, (unsigned long *)data); + } else { + rval = 0; + rval = -EIO; + } + goto out; + + case PTRACE_POKETEXT: /* write the word at location addr. */ + case PTRACE_POKEDATA: + rval = 0; + if (access_process_vm(child, addr, &data, sizeof(data), 1) + == sizeof(data)) + break; + rval = -EIO; + goto out; + + case PTRACE_POKEUSR: + if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) { + struct pt_regs *regs = task_regs (child); + unsigned long *loc = + (unsigned long *)((char *)regs + addr); + *loc = data; + } else { + rval = 0; + rval = -EIO; + } + goto out; + + case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ + case PTRACE_CONT: /* rvaltart after signal. */ + rval = -EIO; + if ((unsigned long) data > _NSIG) + break; + if (request == PTRACE_SYSCALL) + child->ptrace |= PT_TRACESYS; + else + child->ptrace &= ~PT_TRACESYS; + child->exit_code = data; + wake_up_process(child); + rval = 0; + 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: + rval = 0; + if (child->state == TASK_ZOMBIE) /* already dead */ + break; + child->exit_code = SIGKILL; + wake_up_process(child); + break; + + case PTRACE_DETACH: /* detach a process that was attached. */ + rval = ptrace_detach(child, data); + break; + + default: + rval = -EIO; + goto out; + } + +out_tsk: + free_task_struct(child); +out: + unlock_kernel(); + return rval; +} -/* Not implemented yet. XXX */ -int sys_ptrace (long request, long pid, long addr, long data) +asmlinkage void syscall_trace(void) { - return -ENOSYS; + if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) + != (PT_PTRACED|PT_TRACESYS)) + return; + /* The 0x80 provides a way for the tracing parent to distinguish + between a syscall stop and SIGTRAP delivery */ + current->exit_code = SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) + ? 0x80 : 0); + current->state = TASK_STOPPED; + notify_parent(current, SIGCHLD); + schedule(); + /* + * this isn't the same as continuing with a signal, but it will do + * for normal use. strace only continues with a signal if the + * stopping signal is not SIGTRAP. -brl + */ + if (current->exit_code) { + send_sig(current->exit_code, current, 1); + current->exit_code = 0; + } } void ptrace_disable (struct task_struct *child) { - /* There's no ptracing yet, so nothing to disable. */ + /* nothing to do */ } Index: arch/v850/sim/gdb-scripts/trace-loadproc.gdb =================================================================== RCS file: /var/cvs/uClinux-2.4.x/arch/v850/sim/gdb-scripts/trace-loadproc.gdb,v retrieving revision 1.2 diff -u -r1.2 trace-loadproc.gdb --- arch/v850/sim/gdb-scripts/trace-loadproc.gdb 2002/01/29 22:29:43 1.2 +++ arch/v850/sim/gdb-scripts/trace-loadproc.gdb 2002/02/27 02:44:12 @@ -1,6 +1,12 @@ +break load_flat_binary +command + silent + set $bprm = $r6 + cont +end break binfmt_flat.c:727 command silent - printf "[loaded process `%s' at 0x%x (text 0x%x-0x%x, data 0x%x-0x%x, bss 0x%x-0x%x)]\n", bprm->filename, textpos, current->mm->start_code, current->mm->end_code, current->mm->start_data, current->mm->end_data, current->mm->end_data, current->mm->brk + printf "[loaded process `%s' at 0x%x (text 0x%x-0x%x, data 0x%x-0x%x, bss 0x%x-0x%x)]\n", ((struct linux_binprm *)$bprm)->filename, textpos, current->mm->start_code, current->mm->end_code, current->mm->start_data, current->mm->end_data, current->mm->end_data, current->mm->brk cont end Index: include/asm-v850/processor.h =================================================================== RCS file: /var/cvs/uClinux-2.4.x/include/asm-v850/processor.h,v retrieving revision 1.1 diff -u -r1.1 processor.h --- include/asm-v850/processor.h 2001/10/22 13:39:02 1.1 +++ include/asm-v850/processor.h 2002/02/27 02:44:55 @@ -1,8 +1,8 @@ /* * include/asm-v850/processor.h * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001,2002 NEC Corporation + * Copyright (C) 2001,2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -96,10 +96,13 @@ /* Return some info about the user process TASK. */ -#define __KSTK_TOS(task) ((unsigned long)(task) + KERNEL_STACK_SIZE) -#define __KSTK_REGS(task) ((struct pt_regs *)__KSTK_TOS(task) - 1) -#define KSTK_EIP(task) (__KSTK_REGS(task)->pc) -#define KSTK_ESP(task) (__KSTK_REGS(task)->gpr[GPR_SP]) +#define task_tos(task) ((unsigned long)(task) + KERNEL_STACK_SIZE) +#define task_regs(task) ((struct pt_regs *)task_tos (task) - 1) +#define task_sp(task) (task_regs (task)->gpr[GPR_SP]) +#define task_pc(task) (task_regs (task)->pc) +/* Grotty old names for some. */ +#define KSTK_EIP(task) task_pc (task) +#define KSTK_ESP(task) task_sp (task) /* Allocation and freeing of basic task resources. */ Index: include/asm-v850/ptrace.h =================================================================== RCS file: /var/cvs/uClinux-2.4.x/include/asm-v850/ptrace.h,v retrieving revision 1.1 diff -u -r1.1 ptrace.h --- include/asm-v850/ptrace.h 2001/10/22 13:39:02 1.1 +++ include/asm-v850/ptrace.h 2002/02/27 02:44:55 @@ -1,8 +1,8 @@ /* * include/asm-v850/ptrace.h -- Access to CPU registers * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001,2002 NEC Corporation + * Copyright (C) 2001,2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -85,7 +85,7 @@ #define PT_REGS_SYSCALL(regs) (regs)->gpr[0] #define PT_REGS_SET_SYSCALL(regs, val) ((regs)->gpr[0] = (val)) -#else /* __ASSEMBLY__ */ +#endif /* !__ASSEMBLY__ */ /* The number of bytes used to store each register. */ @@ -106,9 +106,6 @@ /* Size of struct pt_regs, including alignment. */ #define PT_SIZE ((NUM_GPRS + 6) * _PT_REG_SIZE) - - -#endif /* __ASSEMBLY__ */ #endif /* __V850_PTRACE_H__ */ Index: include/asm-v850/unistd.h =================================================================== RCS file: /var/cvs/uClinux-2.4.x/include/asm-v850/unistd.h,v retrieving revision 1.1 diff -u -r1.1 unistd.h --- include/asm-v850/unistd.h 2001/10/22 13:39:03 1.1 +++ include/asm-v850/unistd.h 2002/02/27 02:44:55 @@ -1,8 +1,8 @@ /* * include/asm-v850/unistd.h -- System call numbers and invocation mechanism * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001,2002 NEC Corporation + * Copyright (C) 2001,2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -123,10 +123,7 @@ #define __NR_lstat 107 #define __NR_fstat 108 #define __NR_olduname 109 -#define __NR_iopl /* 110 */ not supported #define __NR_vhangup 111 -#define __NR_idle /* 112 */ Obsolete -#define __NR_vm86 /* 113 */ not supported #define __NR_wait4 114 #define __NR_swapoff 115 #define __NR_sysinfo 116 @@ -229,9 +226,16 @@ #define __NR_setgid32 214 #define __NR_setfsuid32 215 #define __NR_setfsgid32 216 +#define __NR_pivot_root 217 +/* #define __NR_mincore 218 */ +/* #define __NR_madvise 219 */ +#define __NR_getdents64 220 +#define __NR_fcntl64 221 +/* 224 `reserved for TUX' */ +/* #define __NR_security 223 */ /* syscall for security modules */ +#define __NR_gettid 224 +/* #define __NR_readahead 225 */ -/* user-visible error numbers are in the range -1 - -122: see - */ /* Syscall protocol: Syscall number in r12, args in r6-r9, r13-r14 @@ -258,6 +262,8 @@ #define __syscall_return(type, res) \ do { \ + /* user-visible error numbers are in the range -1 - -124: \ + see */ \ if ((unsigned long)(res) >= (unsigned long)(-125)) { \ errno = -(res); \ res = -1; \ Index: include/asm-v850/virtconvert.h =================================================================== RCS file: /var/cvs/uClinux-2.4.x/include/asm-v850/virtconvert.h,v retrieving revision 1.1 diff -u -r1.1 virtconvert.h --- include/asm-v850/virtconvert.h 2001/10/22 13:39:03 1.1 +++ include/asm-v850/virtconvert.h 2002/02/27 02:44:56 @@ -2,8 +2,8 @@ * include/asm-v850/virtconvert.h -- conversion between virtual and * physical mappings * - * Copyright (C) 2001 NEC Corporation - * Copyright (C) 2001 Miles Bader + * Copyright (C) 2001,2002 NEC Corporation + * Copyright (C) 2001,2002 Miles Bader * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this @@ -23,9 +23,6 @@ #define mm_vtop(addr) ((unsigned long)__virt_to_phys (addr)) #define phys_to_virt(addr) ((void *)__phys_to_virt (addr)) #define virt_to_phys(addr) ((unsigned long)__virt_to_phys (addr)) - -#define virt_to_bus virt_to_phys -#define bus_to_virt phys_to_virt #endif /* __KERNEL__ */