Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151325773
D39489.id120125.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D39489.id120125.diff
View Options
diff --git a/cddl/lib/libdtrace/Makefile b/cddl/lib/libdtrace/Makefile
--- a/cddl/lib/libdtrace/Makefile
+++ b/cddl/lib/libdtrace/Makefile
@@ -122,10 +122,14 @@
.endif
.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
-SRCS+= dis_tables.c
+SRCS+= dis_tables.c instr_size.c
DSRCS+= regs_x86.d
.endif
+.if ${MACHINE_CPUARCH} == "riscv"
+SRCS+= instr_size.c
+.endif
+
YFLAGS+=-d
LIBADD= ctf elf proc pthread rtld_db
diff --git a/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h b/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
--- a/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
+++ b/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
@@ -51,6 +51,8 @@
#include <sys/param.h>
#include <sys/stdint.h>
+#include <sys/types.h>
+
#ifdef _KERNEL
#include <sys/endian.h>
#endif
@@ -71,7 +73,6 @@
#include <sys/ioccom.h>
#include <sys/cred.h>
#include <sys/proc.h>
-#include <sys/types.h>
#include <sys/ucred.h>
#endif
typedef int model_t;
@@ -2399,8 +2400,7 @@
extern int dtrace_mach_aframes(void);
#if defined(__i386) || defined(__amd64)
-extern int dtrace_instr_size(uchar_t *instr);
-extern int dtrace_instr_size_isa(uchar_t *, model_t, int *);
+extern int dtrace_instr_size_isa(uint8_t *, model_t, int *);
extern void dtrace_invop_callsite(void);
#endif
extern void dtrace_invop_add(int (*)(uintptr_t, struct trapframe *, uintptr_t));
@@ -2428,6 +2428,10 @@
#endif /* _KERNEL */
+#if defined(__i386) || defined(__amd64) || defined (__riscv)
+extern int dtrace_instr_size(uint8_t *instr);
+#endif
+
#endif /* _ASM */
#if defined(__i386) || defined(__amd64)
diff --git a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c
--- a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c
+++ b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c
@@ -449,7 +449,7 @@
* Offset the instruction pointer to the instruction
* following the one causing the fault.
*/
- frame->tf_rip += dtrace_instr_size((u_char *) frame->tf_rip);
+ frame->tf_rip += dtrace_instr_size((uint8_t *) frame->tf_rip);
return (1);
/* Page fault. */
case T_PAGEFLT:
@@ -461,7 +461,7 @@
* Offset the instruction pointer to the instruction
* following the one causing the fault.
*/
- frame->tf_rip += dtrace_instr_size((u_char *) frame->tf_rip);
+ frame->tf_rip += dtrace_instr_size((uint8_t *) frame->tf_rip);
return (1);
default:
/* Handle all other traps in the usual way. */
diff --git a/sys/cddl/dev/dtrace/i386/dtrace_subr.c b/sys/cddl/dev/dtrace/i386/dtrace_subr.c
--- a/sys/cddl/dev/dtrace/i386/dtrace_subr.c
+++ b/sys/cddl/dev/dtrace/i386/dtrace_subr.c
@@ -449,7 +449,7 @@
* Offset the instruction pointer to the instruction
* following the one causing the fault.
*/
- frame->tf_eip += dtrace_instr_size((u_char *) frame->tf_eip);
+ frame->tf_eip += dtrace_instr_size((uint8_t *) frame->tf_eip);
return (1);
/* Page fault. */
case T_PAGEFLT:
@@ -461,7 +461,7 @@
* Offset the instruction pointer to the instruction
* following the one causing the fault.
*/
- frame->tf_eip += dtrace_instr_size((u_char *) frame->tf_eip);
+ frame->tf_eip += dtrace_instr_size((uint8_t *) frame->tf_eip);
return (1);
default:
/* Handle all other traps in the usual way. */
diff --git a/sys/cddl/dev/dtrace/riscv/instr_size.c b/sys/cddl/dev/dtrace/riscv/instr_size.c
new file mode 100644
--- /dev/null
+++ b/sys/cddl/dev/dtrace/riscv/instr_size.c
@@ -0,0 +1,22 @@
+/*
+ * SPDX-License-Identifier: CDDL 1.0
+ *
+ * Copyright 2023 Christos Margiolis <christos@FreeBSD.org>
+ */
+
+#include <sys/types.h>
+#include <sys/dtrace.h>
+
+#include <machine/riscvreg.h>
+
+#define RVC_MASK 0x03
+
+int
+dtrace_instr_size(uint8_t *instr)
+{
+ /* Detect compressed instructions. */
+ if ((~(*instr) & RVC_MASK) == 0)
+ return (INSN_SIZE);
+ else
+ return (INSN_C_SIZE);
+}
diff --git a/sys/cddl/dev/dtrace/x86/instr_size.c b/sys/cddl/dev/dtrace/x86/instr_size.c
--- a/sys/cddl/dev/dtrace/x86/instr_size.c
+++ b/sys/cddl/dev/dtrace/x86/instr_size.c
@@ -49,8 +49,8 @@
typedef u_int model_t;
#define DATAMODEL_NATIVE 0
-int dtrace_instr_size(uchar_t *);
-int dtrace_instr_size_isa(uchar_t *, model_t, int *);
+int dtrace_instr_size(uint8_t *);
+int dtrace_instr_size_isa(uint8_t *, model_t, int *);
#endif
#include <dis_tables.h>
@@ -83,7 +83,7 @@
dtrace_dis_get_byte(void *p)
{
int ret;
- uchar_t **instr = p;
+ uint8_t **instr = p;
ret = **instr;
*instr += 1;
@@ -101,7 +101,7 @@
*/
/* ARGSUSED2 */
static int
-dtrace_dis_isize(uchar_t *instr, dis_isize_t which, model_t model, int *rmindex)
+dtrace_dis_isize(uint8_t *instr, dis_isize_t which, model_t model, int *rmindex)
{
int sz;
dis86_t x;
@@ -127,13 +127,13 @@
}
int
-dtrace_instr_size_isa(uchar_t *instr, model_t model, int *rmindex)
+dtrace_instr_size_isa(uint8_t *instr, model_t model, int *rmindex)
{
return (dtrace_dis_isize(instr, DIS_ISIZE_INSTR, model, rmindex));
}
int
-dtrace_instr_size(uchar_t *instr)
+dtrace_instr_size(uint8_t *instr)
{
return (dtrace_dis_isize(instr, DIS_ISIZE_INSTR, DATAMODEL_NATIVE,
NULL));
diff --git a/sys/modules/dtrace/dtrace/Makefile b/sys/modules/dtrace/dtrace/Makefile
--- a/sys/modules/dtrace/dtrace/Makefile
+++ b/sys/modules/dtrace/dtrace/Makefile
@@ -23,6 +23,9 @@
CFLAGS+= -I${SYSDIR}/cddl/contrib/opensolaris/uts/intel \
-I${SYSDIR}/cddl/dev/dtrace/x86
+.endif
+.if ${MACHINE_CPUARCH} == "riscv"
+SRCS+= instr_size.c
.endif
CFLAGS+= ${OPENZFS_CFLAGS}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 8, 3:07 PM (14 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31104237
Default Alt Text
D39489.id120125.diff (5 KB)
Attached To
Mode
D39489: dtrace: expose dtrace_instr_size() to userland and implement it for RISC-V
Attached
Detach File
Event Timeline
Log In to Comment