Author: kp
Date: Fri Sep 11 09:15:49 2020
New Revision: 365626
URL: https://svnweb.freebsd.org/changeset/base/365626

Log:
  dtrace: fix fbt return probes on RISC-V
  
  Return values are passed in a0, so read it from there. We also pass a1 through
  to userspace, as the ABI allows small structs to be returned in registers
  a0/a1. While here read the register values directly from the trapframe rather
  than rtval, and remove the now unneeded argument from dtrace_invop().
  
  Set fbtp_roffset so that we get the correct return location in arg0.
  
  Reviewed by:  markj
  Sponsored by: Axiado
  Differential Revision:        https://reviews.freebsd.org/D26389

Modified:
  head/sys/cddl/dev/dtrace/riscv/dtrace_subr.c
  head/sys/cddl/dev/fbt/riscv/fbt_isa.c

Modified: head/sys/cddl/dev/dtrace/riscv/dtrace_subr.c
==============================================================================
--- head/sys/cddl/dev/dtrace/riscv/dtrace_subr.c        Fri Sep 11 05:45:27 
2020        (r365625)
+++ head/sys/cddl/dev/dtrace/riscv/dtrace_subr.c        Fri Sep 11 09:15:49 
2020        (r365626)
@@ -53,7 +53,7 @@ extern dtrace_id_t    dtrace_probeid_error;
 extern int (*dtrace_invop_jump_addr)(struct trapframe *);
 extern void dtrace_getnanotime(struct timespec *tsp);
 
-int dtrace_invop(uintptr_t, struct trapframe *, uintptr_t);
+int dtrace_invop(uintptr_t, struct trapframe *);
 void dtrace_invop_init(void);
 void dtrace_invop_uninit(void);
 
@@ -65,13 +65,13 @@ typedef struct dtrace_invop_hdlr {
 dtrace_invop_hdlr_t *dtrace_invop_hdlr;
 
 int
-dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t eax)
+dtrace_invop(uintptr_t addr, struct trapframe *frame)
 {
        dtrace_invop_hdlr_t *hdlr;
        int rval;
 
        for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next)
-               if ((rval = hdlr->dtih_func(addr, frame, eax)) != 0)
+               if ((rval = hdlr->dtih_func(addr, frame, 0)) != 0)
                        return (rval);
 
        return (0);
@@ -254,7 +254,7 @@ dtrace_invop_start(struct trapframe *frame)
        uint32_t imm;
        int invop;
 
-       invop = dtrace_invop(frame->tf_sepc, frame, frame->tf_sepc);
+       invop = dtrace_invop(frame->tf_sepc, frame);
        if (invop == 0)
                return (-1);
 

Modified: head/sys/cddl/dev/fbt/riscv/fbt_isa.c
==============================================================================
--- head/sys/cddl/dev/fbt/riscv/fbt_isa.c       Fri Sep 11 05:45:27 2020        
(r365625)
+++ head/sys/cddl/dev/fbt/riscv/fbt_isa.c       Fri Sep 11 09:15:49 2020        
(r365626)
@@ -59,9 +59,14 @@ fbt_invop(uintptr_t addr, struct trapframe *frame, uin
                if ((uintptr_t)fbt->fbtp_patchpoint == addr) {
                        cpu->cpu_dtrace_caller = addr;
 
-                       dtrace_probe(fbt->fbtp_id, frame->tf_a[0],
-                           frame->tf_a[1], frame->tf_a[2],
-                           frame->tf_a[3], frame->tf_a[4]);
+                       if (fbt->fbtp_roffset == 0) {
+                               dtrace_probe(fbt->fbtp_id, frame->tf_a[0],
+                                   frame->tf_a[1], frame->tf_a[2],
+                                   frame->tf_a[3], frame->tf_a[4]);
+                       } else {
+                               dtrace_probe(fbt->fbtp_id, fbt->fbtp_roffset,
+                                   frame->tf_a[0], frame->tf_a[1], 0, 0);
+                       }
 
                        cpu->cpu_dtrace_caller = 0;
                        return (fbt->fbtp_savedval);
@@ -233,6 +238,7 @@ again:
        fbt->fbtp_loadcnt = lf->loadcnt;
        fbt->fbtp_symindx = symindx;
        fbt->fbtp_rval = rval;
+       fbt->fbtp_roffset = (uintptr_t)instr - (uintptr_t)symval->value;
        fbt->fbtp_savedval = *instr;
        fbt->fbtp_patchval = patchval;
        fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to