Mon Mar 29 03:22:18 2021 UTC ()
(Very) minimal kernel support for dtrace on MIPS; enough to system call
tracing to work for example.


(simonb)
diff -r1.259 -r1.260 src/sys/arch/mips/mips/trap.c

cvs diff -r1.259 -r1.260 src/sys/arch/mips/mips/trap.c (expand / switch to unified diff)

--- src/sys/arch/mips/mips/trap.c 2021/03/17 11:05:37 1.259
+++ src/sys/arch/mips/mips/trap.c 2021/03/29 03:22:17 1.260
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: trap.c,v 1.259 2021/03/17 11:05:37 simonb Exp $ */ 1/* $NetBSD: trap.c,v 1.260 2021/03/29 03:22:17 simonb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988 University of Utah. 4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 1993 5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer 9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department and Ralph Campbell. 10 * Science Department and Ralph Campbell.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -29,30 +29,31 @@ @@ -29,30 +29,31 @@
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * from: Utah Hdr: trap.c 1.32 91/04/06 36 * from: Utah Hdr: trap.c 1.32 91/04/06
37 * 37 *
38 * @(#)trap.c 8.5 (Berkeley) 1/11/94 38 * @(#)trap.c 8.5 (Berkeley) 1/11/94
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.259 2021/03/17 11:05:37 simonb Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.260 2021/03/29 03:22:17 simonb Exp $");
43 43
44#include "opt_cputype.h" /* which mips CPU levels do we support? */ 44#include "opt_cputype.h" /* which mips CPU levels do we support? */
45#include "opt_ddb.h" 45#include "opt_ddb.h"
 46#include "opt_dtrace.h"
46#include "opt_kgdb.h" 47#include "opt_kgdb.h"
47#include "opt_multiprocessor.h" 48#include "opt_multiprocessor.h"
48 49
49#include <sys/param.h> 50#include <sys/param.h>
50#include <sys/systm.h> 51#include <sys/systm.h>
51#include <sys/kernel.h> 52#include <sys/kernel.h>
52#include <sys/cpu.h> 53#include <sys/cpu.h>
53#include <sys/proc.h> 54#include <sys/proc.h>
54#include <sys/ras.h> 55#include <sys/ras.h>
55#include <sys/signalvar.h> 56#include <sys/signalvar.h>
56#include <sys/syscall.h> 57#include <sys/syscall.h>
57#include <sys/buf.h> 58#include <sys/buf.h>
58#include <sys/ktrace.h> 59#include <sys/ktrace.h>
@@ -794,26 +795,36 @@ mips_singlestep(struct lwp *l) @@ -794,26 +795,36 @@ mips_singlestep(struct lwp *l)
794 MIPS_BREAK_SSTEP); 795 MIPS_BREAK_SSTEP);
795 (void)uvm_map_protect(&p->p_vmspace->vm_map, 796 (void)uvm_map_protect(&p->p_vmspace->vm_map,
796 sa, ea, VM_PROT_READ|VM_PROT_EXECUTE, false); 797 sa, ea, VM_PROT_READ|VM_PROT_EXECUTE, false);
797 } 798 }
798 } 799 }
799#if 0 800#if 0
800 printf("SS %s (%d): breakpoint set at %x: %x (pc %x) br %x\n", 801 printf("SS %s (%d): breakpoint set at %x: %x (pc %x) br %x\n",
801 p->p_comm, p->p_pid, p->p_md.md_ss_addr, 802 p->p_comm, p->p_pid, p->p_md.md_ss_addr,
802 p->p_md.md_ss_instr, pc, mips_ufetch32((void *)va)); /* XXX */ 803 p->p_md.md_ss_instr, pc, mips_ufetch32((void *)va)); /* XXX */
803#endif 804#endif
804 return 0; 805 return 0;
805} 806}
806 807
 808#ifdef KDTRACE_HOOKS
 809#include <sys/dtrace_bsd.h>
 810
 811/* Not used for now, but needed for dtrace/fbt modules */
 812dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL;
 813dtrace_trap_func_t dtrace_trap_func = NULL;
 814
 815int (* dtrace_invop_jump_addr)(struct trapframe *);
 816#endif /* KDTRACE_HOOKS */
 817
807#ifdef TRAP_SIGDEBUG 818#ifdef TRAP_SIGDEBUG
808static void 819static void
809frame_dump(const struct trapframe *tf, struct pcb *pcb) 820frame_dump(const struct trapframe *tf, struct pcb *pcb)
810{ 821{
811 822
812 printf("trapframe %p\n", tf); 823 printf("trapframe %p\n", tf);
813 printf("ast %#018lx v0 %#018lx v1 %#018lx\n", 824 printf("ast %#018lx v0 %#018lx v1 %#018lx\n",
814 tf->tf_regs[_R_AST], tf->tf_regs[_R_V0], tf->tf_regs[_R_V1]); 825 tf->tf_regs[_R_AST], tf->tf_regs[_R_V0], tf->tf_regs[_R_V1]);
815 printf(" a0 %#018lx a1 %#018lx a2 %#018lx\n", 826 printf(" a0 %#018lx a1 %#018lx a2 %#018lx\n",
816 tf->tf_regs[_R_A0], tf->tf_regs[_R_A1], tf->tf_regs[_R_A2]); 827 tf->tf_regs[_R_A0], tf->tf_regs[_R_A1], tf->tf_regs[_R_A2]);
817#if defined(__mips_n32) || defined(__mips_n64) 828#if defined(__mips_n32) || defined(__mips_n64)
818 printf(" a3 %#018lx a4 %#018lx a5 %#018lx\n", 829 printf(" a3 %#018lx a4 %#018lx a5 %#018lx\n",
819 tf->tf_regs[_R_A3], tf->tf_regs[_R_A4], tf->tf_regs[_R_A5]); 830 tf->tf_regs[_R_A3], tf->tf_regs[_R_A4], tf->tf_regs[_R_A5]);
@@ -853,14 +864,14 @@ static void @@ -853,14 +864,14 @@ static void
853sigdebug(const struct trapframe *tf, const ksiginfo_t *ksi, int e, 864sigdebug(const struct trapframe *tf, const ksiginfo_t *ksi, int e,
854 vaddr_t pc) 865 vaddr_t pc)
855{ 866{
856 struct lwp *l = curlwp; 867 struct lwp *l = curlwp;
857 struct proc *p = l->l_proc; 868 struct proc *p = l->l_proc;
858 869
859 printf("pid %d.%d (%s): signal %d code=%d (trap %#lx) " 870 printf("pid %d.%d (%s): signal %d code=%d (trap %#lx) "
860 "@pc %#lx addr %#lx error=%d\n", 871 "@pc %#lx addr %#lx error=%d\n",
861 p->p_pid, l->l_lid, p->p_comm, ksi->ksi_signo, ksi->ksi_code, 872 p->p_pid, l->l_lid, p->p_comm, ksi->ksi_signo, ksi->ksi_code,
862 tf->tf_regs[_R_CAUSE], (unsigned long)pc, tf->tf_regs[_R_BADVADDR], 873 tf->tf_regs[_R_CAUSE], (unsigned long)pc, tf->tf_regs[_R_BADVADDR],
863 e); 874 e);
864 frame_dump(tf, lwp_getpcb(l)); 875 frame_dump(tf, lwp_getpcb(l));
865} 876}
866#endif 877#endif /* TRAP_SIGDEBUG */