Page MenuHomeFreeBSD

D59900.id.diff
No OneTemporary

D59900.id.diff

diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
@@ -228,6 +228,10 @@
rel->r_offset = s->dofs_offset + dofr[j].dofr_offset;
rel->r_info = ELF32_R_INFO(count + dep->de_global,
R_RISCV_32_PCREL);
+#elif defined(__loongarch__)
+ rel->r_offset = s->dofs_offset + dofr[j].dofr_offset;
+ rel->r_info = ELF32_R_INFO(count + dep->de_global,
+ R_LARCH_32);
#else
#error unknown ISA
#endif
@@ -411,6 +415,10 @@
dofr[j].dofr_offset;
rel->r_info = ELF64_R_INFO(count + dep->de_global,
R_X86_64_PC64);
+#elif defined(__loongarch__)
+ rel->r_offset = s->dofs_offset + dofr[j].dofr_offset;
+ rel->r_info = ELF64_R_INFO(count + dep->de_global,
+ R_LARCH_64);
#else
#error unknown ISA
#endif
@@ -522,6 +530,8 @@
#if defined(__riscv_float_abi_double)
elf_file.ehdr.e_flags |= EF_RISCV_FLOAT_ABI_DOUBLE;
#endif
+#elif defined(__loongarch__)
+ elf_file.ehdr.e_machine = EM_LOONGARCH;
#endif
elf_file.ehdr.e_version = EV_CURRENT;
elf_file.ehdr.e_shoff = sizeof (Elf32_Ehdr);
@@ -679,6 +689,8 @@
#if defined(__riscv_float_abi_double)
elf_file.ehdr.e_flags |= EF_RISCV_FLOAT_ABI_DOUBLE;
#endif
+#elif defined(__loongarch__)
+ elf_file.ehdr.e_machine = EM_LOONGARCH;
#endif
elf_file.ehdr.e_version = EV_CURRENT;
elf_file.ehdr.e_shoff = sizeof (Elf64_Ehdr);
@@ -1132,8 +1144,55 @@
return (0);
}
+#elif defined(__loongarch__)
+/*
+ * LoongArch uses pcaddu12i + jirl for long calls. For now provide a
+ * minimal stub implementation so that the library can be linked.
+ */
+#define DT_OP_NOP 0x03400000 /* andi $zero, $zero, 0 */
+#define DT_OP_RET 0x4c000020 /* jirl $zero, $ra, 0 */
+#define DT_REL_NONE R_LARCH_NONE
+
+static int
+dt_modtext(dtrace_hdl_t *dtp, char *p, int isenabled, GElf_Rela *rela,
+ uint32_t *off)
+{
+ uint32_t *ip;
+
+ /*
+ * Ensure that the offset is aligned on an instruction boundary.
+ */
+ if ((rela->r_offset & (sizeof (uint32_t) - 1)) != 0)
+ return (-1);
+
+ /*
+ * We only know about some specific relocation types.
+ */
+ if (GELF_R_TYPE(rela->r_info) != R_LARCH_NONE)
+ return (-1);
+
+ ip = (uint32_t *)(p + rela->r_offset);
+
+ /*
+ * We may have already processed this object file in an earlier linker
+ * invocation. Check to see if the present instruction sequence matches
+ * the one we would install below.
+ */
+ if (ip[0] == DT_OP_NOP || ip[0] == DT_OP_RET)
+ return (0);
+
+ /*
+ * XXX: Placeholder. Proper instruction modification needs to be
+ * implemented when full dtrace support for LoongArch is added.
+ */
+ ip[0] = DT_OP_NOP;
+
+ return (0);
+}
+
#else
#error unknown ISA
+
#endif
/*PRINTFLIKE5*/
@@ -1251,6 +1310,8 @@
emachine1 = emachine2 = EM_AARCH64;
#elif defined(__riscv)
emachine1 = emachine2 = EM_RISCV;
+#elif defined(__loongarch__)
+ emachine1 = emachine2 = EM_LOONGARCH;
#endif
symsize = sizeof (Elf64_Sym);
} else {
@@ -1261,6 +1322,8 @@
emachine1 = emachine2 = EM_PPC;
#elif defined(__i386) || defined(__amd64)
emachine1 = emachine2 = EM_386;
+#elif defined(__loongarch__)
+ emachine1 = emachine2 = EM_LOONGARCH;
#endif
symsize = sizeof (Elf32_Sym);
}
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/loongarch/dt_isadep.c b/cddl/contrib/opensolaris/lib/libdtrace/loongarch/dt_isadep.c
new file mode 100644
--- /dev/null
+++ b/cddl/contrib/opensolaris/lib/libdtrace/loongarch/dt_isadep.c
@@ -0,0 +1,139 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ * Copyright 2014 Howard Su
+ * Copyright 2015 George V. Neville-Neil
+ * Copyright 2015 Ruslan Bukin <br@bsdpad.com>
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdlib.h>
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <libgen.h>
+
+#include <dt_impl.h>
+#include <dt_pid.h>
+
+#if !defined(sun)
+#include <libproc_compat.h>
+#endif
+
+/*ARGSUSED*/
+int
+dt_pid_create_entry_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
+ fasttrap_probe_spec_t *ftp, const GElf_Sym *symp)
+{
+
+ ftp->ftps_type = DTFTP_ENTRY;
+ ftp->ftps_pc = (uintptr_t)symp->st_value;
+ ftp->ftps_size = (size_t)symp->st_size;
+ ftp->ftps_noffs = 1;
+ ftp->ftps_offs[0] = 0;
+
+ if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
+ dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
+ strerror(errno));
+ return (dt_set_errno(dtp, errno));
+ }
+
+ return (1);
+}
+
+int
+dt_pid_create_return_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
+ fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, uint64_t *stret)
+{
+
+ dt_dprintf("%s: unimplemented\n", __func__);
+
+ return (DT_PROC_ERR);
+}
+
+/*ARGSUSED*/
+int
+dt_pid_create_offset_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
+ fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, ulong_t off)
+{
+
+ if (!ALIGNED_POINTER(off, 4))
+ return (DT_PROC_ALIGN);
+
+ ftp->ftps_type = DTFTP_OFFSETS;
+ ftp->ftps_pc = (uintptr_t)symp->st_value;
+ ftp->ftps_size = (size_t)symp->st_size;
+ ftp->ftps_noffs = 1;
+ ftp->ftps_offs[0] = off;
+
+ if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
+ dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
+ strerror(errno));
+ return (dt_set_errno(dtp, errno));
+ }
+
+ return (1);
+}
+
+/*ARGSUSED*/
+int
+dt_pid_create_glob_offset_probes(struct ps_prochandle *P, dtrace_hdl_t *dtp,
+ fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, const char *pattern)
+{
+ ulong_t i;
+
+ ftp->ftps_type = DTFTP_OFFSETS;
+ ftp->ftps_pc = (uintptr_t)symp->st_value;
+ ftp->ftps_size = (size_t)symp->st_size;
+ ftp->ftps_noffs = 0;
+
+ /*
+ * If we're matching against everything, just iterate through each
+ * instruction in the function, otherwise look for matching offset
+ * names by constructing the string and comparing it against the
+ * pattern.
+ */
+ if (strcmp("*", pattern) == 0) {
+ for (i = 0; i < symp->st_size; i += 4) {
+ ftp->ftps_offs[ftp->ftps_noffs++] = i;
+ }
+ } else {
+ char name[sizeof (i) * 2 + 1];
+
+ for (i = 0; i < symp->st_size; i += 4) {
+ (void) sprintf(name, "%lx", i);
+ if (gmatch(name, pattern))
+ ftp->ftps_offs[ftp->ftps_noffs++] = i;
+ }
+ }
+
+ if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
+ dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
+ strerror(errno));
+ return (dt_set_errno(dtp, errno));
+ }
+
+ return (ftp->ftps_noffs);
+}
diff --git a/cddl/lib/libdtrace/Makefile b/cddl/lib/libdtrace/Makefile
--- a/cddl/lib/libdtrace/Makefile
+++ b/cddl/lib/libdtrace/Makefile
@@ -122,6 +122,9 @@
CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/riscv
.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/riscv
.PATH: ${SRCTOP}/sys/cddl/dev/dtrace/riscv
+.elif ${MACHINE_CPUARCH} == "loongarch"
+CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/loongarch
+.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/loongarch
.else
# temporary hack
CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel
diff --git a/sys/cddl/contrib/opensolaris/uts/loongarch/dtrace/fasttrap_isa.c b/sys/cddl/contrib/opensolaris/uts/loongarch/dtrace/fasttrap_isa.c
new file mode 100644
--- /dev/null
+++ b/sys/cddl/contrib/opensolaris/uts/loongarch/dtrace/fasttrap_isa.c
@@ -0,0 +1,29 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * XXX: Placeholder for LoongArch fasttrap code
+ */
diff --git a/sys/cddl/contrib/opensolaris/uts/loongarch/sys/fasttrap_isa.h b/sys/cddl/contrib/opensolaris/uts/loongarch/sys/fasttrap_isa.h
new file mode 100644
--- /dev/null
+++ b/sys/cddl/contrib/opensolaris/uts/loongarch/sys/fasttrap_isa.h
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _FASTTRAP_ISA_H
+#define _FASTTRAP_ISA_H
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef uint32_t fasttrap_instr_t;
+
+/* XXX: Place for LoongArch fasttrap headers */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FASTTRAP_ISA_H */

File Metadata

Mime Type
text/plain
Expires
Wed, Sep 30, 4:46 AM (5 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39758796
Default Alt Text
D59900.id.diff (10 KB)

Event Timeline