dtrace: expose dtrace_instr_size() to userland and implement it for riscv

dtrace_instr_size() is needed by the forthcoming RISC-V port of kinst,
as well as by libdtrace in D38825 for both amd64 and RISC-V.

Reviewed by:	markj, mhorne
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39489
This commit is contained in:
Christos Margiolis 2023-04-20 16:21:46 +00:00 committed by Mark Johnston
parent 1a149d65ba
commit 080e56a6c9
4 changed files with 36 additions and 3 deletions

View File

@ -122,10 +122,14 @@ CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel
.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

View File

@ -2399,7 +2399,6 @@ extern void dtrace_safe_synchronous_signal(void);
extern int dtrace_mach_aframes(void);
#if defined(__i386) || defined(__amd64)
extern int dtrace_instr_size(uint8_t *instr);
extern int dtrace_instr_size_isa(uint8_t *, model_t, int *);
extern void dtrace_invop_callsite(void);
#endif
@ -2428,6 +2427,10 @@ extern void dtrace_helpers_destroy(proc_t *);
#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)

View File

@ -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);
}

View File

@ -22,8 +22,12 @@ SRCS+= dis_tables.c \
instr_size.c
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}
SRCS+= bus_if.h device_if.h vnode_if.h