--- Makefile.inc1.orig +++ Makefile.inc1 @@ -1054,9 +1054,11 @@ usr.bin/clang/clang-tblgen .endif +# dtrace tools are required for older bootstrap env and cross-build .if ${MK_CDDL} != "no" && \ - ${BOOTSTRAPPING} < 800038 && \ - !(${BOOTSTRAPPING} >= 700112 && ${BOOTSTRAPPING} < 799999) + ((${BOOTSTRAPPING} < 800038 && \ + !(${BOOTSTRAPPING} >= 700112 && ${BOOTSTRAPPING} < 799999)) \ + || (${MACHINE} != ${TARGET} || ${MACHINE_ARCH} != ${TARGET_ARCH})) _dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \ lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge .endif --- /dev/null 2012-02-29 23:00:00.000000000 -0800 +++ cddl/contrib/opensolaris/lib/libdtrace/mips/dt_isadep.c 2012-02-29 23:06:15.000000000 -0800 @@ -0,0 +1,181 @@ +/* + * 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. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include +#include +#include +#include +#include + +#include +#include + +#define OP(x) ((x) >> 30) +#define OP2(x) (((x) >> 22) & 0x07) +#define COND(x) (((x) >> 25) & 0x0f) +#define A(x) (((x) >> 29) & 0x01) + +#define OP_BRANCH 0 + +#define OP2_BPcc 0x1 +#define OP2_Bicc 0x2 +#define OP2_BPr 0x3 +#define OP2_FBPfcc 0x5 +#define OP2_FBfcc 0x6 + +/*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) +{ + + uint32_t *text; + int i; + int srdepth = 0; + + dt_dprintf("%s: unimplemented\n", __func__); + return (DT_PROC_ERR); + + if ((text = malloc(symp->st_size + 4)) == NULL) { + dt_dprintf("mr sparkle: malloc() failed\n"); + return (DT_PROC_ERR); + } + + if (Pread(P, text, symp->st_size, symp->st_value) != symp->st_size) { + dt_dprintf("mr sparkle: Pread() failed\n"); + free(text); + return (DT_PROC_ERR); + } + + /* + * Leave a dummy instruction in the last slot to simplify edge + * conditions. + */ + text[symp->st_size / 4] = 0; + + ftp->ftps_type = DTFTP_RETURN; + ftp->ftps_pc = symp->st_value; + ftp->ftps_size = symp->st_size; + ftp->ftps_noffs = 0; + + + free(text); + if (ftp->ftps_noffs > 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 (ftp->ftps_noffs); +} + +/*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 (off & 0x3) + 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); +} --- cddl/lib/Makefile.orig +++ cddl/lib/Makefile @@ -19,7 +19,7 @@ .endif .endif -.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" +.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "mips64eb" _drti= drti _libdtrace= libdtrace .endif --- cddl/lib/libdtrace/Makefile.orig +++ cddl/lib/libdtrace/Makefile @@ -42,8 +42,7 @@ dt_subr.c \ dt_work.c \ dt_xlator.c \ - gmatch.c \ - dis_tables.c + gmatch.c DSRCS= errno.d \ psinfo.d \ @@ -70,12 +69,17 @@ .elif ${MACHINE_CPUARCH} == "sparc64" CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/sparc .PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/sparc +.elif ${MACHINE_CPUARCH} == "mips" +CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/mips +.PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libdtrace/mips +.PATH: ${.CURDIR}/../../../sys/cddl/dev/dtrace/mips .else # temporary hack CFLAGS+= -I${OPENSOLARIS_SYS_DISTDIR}/uts/intel .endif .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64" +SRCS+= dis_tables.c DSRCS+= regs_x86.d .endif --- cddl/usr.sbin/Makefile.orig +++ cddl/usr.sbin/Makefile @@ -19,4 +19,8 @@ _lockstat= lockstat .endif +.if ${MACHINE_CPUARCH} == "mips" +_dtrace= dtrace +.endif + .include --- lib/Makefile.orig +++ lib/Makefile @@ -179,7 +179,7 @@ _libypclnt= libypclnt .endif -.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" +.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "mips" .if ${MK_NCP} != "no" _libncp= libncp .endif --- lib/libelf/libelf_data.c.orig +++ lib/libelf/libelf_data.c @@ -86,6 +86,8 @@ #endif case SHT_MIPS_DWARF: /* FALLTHROUGH */ + case SHT_MIPS_OPTIONS: + /* FALLTHROUGH */ case SHT_AMD64_UNWIND: /* == SHT_IA_64_UNWIND */ return (ELF_T_BYTE); default: --- lib/libproc/proc_bkpt.c.orig +++ lib/libproc/proc_bkpt.c @@ -44,6 +44,9 @@ #if defined(__i386__) || defined(__amd64__) #define BREAKPOINT_INSTR 0xcc /* int 0x3 */ #define BREAKPOINT_INSTR_SZ 1 +#elif defined(__mips__) +#define BREAKPOINT_INSTR 0xd /* break */ +#define BREAKPOINT_INSTR_SZ 4 #else #error "Add support for your architecture" #endif --- lib/libproc/proc_regs.c.orig +++ lib/libproc/proc_regs.c @@ -58,6 +58,8 @@ *regvalue = regs.r_rip; #elif defined(__i386__) *regvalue = regs.r_eip; +#elif defined(__mips__) + *regvalue = regs.r_regs[PC]; #endif break; case REG_SP: @@ -65,6 +67,8 @@ *regvalue = regs.r_rsp; #elif defined(__i386__) *regvalue = regs.r_esp; +#elif defined(__mips__) + *regvalue = regs.r_regs[SP]; #endif break; default: @@ -93,6 +97,8 @@ regs.r_rip = regvalue; #elif defined(__i386__) regs.r_eip = regvalue; +#elif defined(__mips__) + regs.r_regs[PC] = regvalue; #endif break; case REG_SP: @@ -100,6 +106,8 @@ regs.r_rsp = regvalue; #elif defined(__i386__) regs.r_esp = regvalue; +#elif defined(__mips__) + regs.r_regs[PC] = regvalue; #endif break; default: