summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdisasm
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libdisasm')
-rw-r--r--usr/src/lib/libdisasm/Makefile60
-rw-r--r--usr/src/lib/libdisasm/Makefile.com141
-rw-r--r--usr/src/lib/libdisasm/Makefile.targ100
-rw-r--r--usr/src/lib/libdisasm/amd64/Makefile37
-rw-r--r--usr/src/lib/libdisasm/common/libdisasm.c92
-rw-r--r--usr/src/lib/libdisasm/common/libdisasm.h78
-rw-r--r--usr/src/lib/libdisasm/common/libdisasm_impl.h45
-rw-r--r--usr/src/lib/libdisasm/common/linktest_stand.c42
-rw-r--r--usr/src/lib/libdisasm/common/llib-ldisasm35
-rw-r--r--usr/src/lib/libdisasm/i386/Makefile36
-rw-r--r--usr/src/lib/libdisasm/i386/dis_i386.c225
-rw-r--r--usr/src/lib/libdisasm/spec/Makefile27
-rw-r--r--usr/src/lib/libdisasm/spec/Makefile.targ30
-rw-r--r--usr/src/lib/libdisasm/spec/amd64/Makefile34
-rw-r--r--usr/src/lib/libdisasm/spec/i386/Makefile33
-rw-r--r--usr/src/lib/libdisasm/spec/libdisasm.spec57
-rw-r--r--usr/src/lib/libdisasm/spec/sparc/Makefile33
-rw-r--r--usr/src/lib/libdisasm/spec/sparcv9/Makefile34
-rw-r--r--usr/src/lib/libdisasm/spec/versions43
19 files changed, 1182 insertions, 0 deletions
diff --git a/usr/src/lib/libdisasm/Makefile b/usr/src/lib/libdisasm/Makefile
new file mode 100644
index 0000000000..7108f761fb
--- /dev/null
+++ b/usr/src/lib/libdisasm/Makefile
@@ -0,0 +1,60 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+
+include ../Makefile.lib
+
+HDRS= libdisasm.h
+
+HDRDIR= common
+$(INTEL_BLD)SUBDIRS= $(MACH)
+$(INTEL_BLD)$(BUILD64)SUBDIRS += $(MACH64)
+$(CLOSED_BLD)SUBDIRS += $(CLOSED)/lib/libdisasm
+
+all := TARGET = all
+clean := TARGET = clean
+clobber := TARGET = clobber
+install := TARGET = install
+lint := TARGET = lint
+
+.KEEP_STATE:
+
+$(INTEL_BLD)SPECDIR= spec
+
+all clean clobber install: $(SPECDIR) .WAIT $(SUBDIRS)
+
+lint: $(SUBDIRS)
+
+install_h: $(ROOTHDRS)
+
+check: $(CHECKHDRS)
+
+$(SUBDIRS) spec: FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+FRC:
+
+include ../Makefile.targ
diff --git a/usr/src/lib/libdisasm/Makefile.com b/usr/src/lib/libdisasm/Makefile.com
new file mode 100644
index 0000000000..85ab0b9361
--- /dev/null
+++ b/usr/src/lib/libdisasm/Makefile.com
@@ -0,0 +1,141 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+#
+# The build process for libdisasm is sightly different from that used by other
+# libraries, because libdisasm must be built in two flavors - as a standalone
+# for use by kmdb and as a normal library. We use $(CURTYPE) to indicate the
+# current flavor being built.
+#
+# The SPARC library is built from the closed gate. This Makefile is shared
+# between both environments, so all paths must be absolute.
+#
+
+LIBRARY= libdisasm.a
+STANDLIBRARY= libstanddisasm.so
+VERS= .1
+
+# By default, we build the shared library. Construction of the standalone
+# is specifically requested by architecture-specific Makefiles.
+TYPES= library
+CURTYPE= library
+
+COMDIR= $(SRC)/lib/libdisasm/common
+SPECDIR= $(SRC)/lib/libdisasm/spec
+
+# Files specific to the library version of libdisasm
+OBJECTS_library =
+SRC_libary = $(OBJECTS_library:%.o=$(COMDIR)/%.c)
+
+#
+# Architecture-dependent files common to both versions of libdisasm
+#
+OBJECTS_common_i386 = dis_i386.o dis_tables.o
+OBJECTS_common_sparc = dis_sparc.o
+
+SRCS_common_i386 = $(ISASRCDIR)/dis_i386.c $(SRC)/common/dis/i386/dis_tables.c
+SRCS_common_sparc = $(ISASRCDIR)/dis_sparc.c
+
+#
+# Architecture-independent files common to both version of libdisasm
+#
+OBJECTS_common_common = libdisasm.o
+SRC_common_common = $(OBJECTS_common_common:%.o=$(COMDIR)/%.c)
+
+
+OBJECTS= \
+ $(OBJECTS_$(CURTYPE)) \
+ $(OBJECTS_common_$(MACH)) \
+ $(OBJECTS_common_common)
+
+include $(SRC)/lib/Makefile.lib
+
+SRCS= \
+ $(SRCS_$(CURTYPE)) \
+ $(SRCS_common_$(MACH)) \
+ $(SRCS_common_common)
+
+#
+# Used to verify that the standalone doesn't have any unexpected external
+# dependencies.
+#
+LINKTEST_OBJ = objs/linktest_stand.o
+
+CLOBBERFILES_standalone = $(LINKTEST_OBJ)
+CLOBBERFILES += $(CLOBBERFILES_$(CURTYPE))
+
+LIBS_standalone = $(STANDLIBRARY)
+LIBS_library = $(DYNLIB) $(LINTLIB)
+LIBS = $(LIBS_$(CURTYPE))
+
+MAPDIR= $(SPECDIR)/$(TRANSMACH)
+SPECMAPFILE= $(MAPDIR)/mapfile
+
+LDLIBS += -lc
+
+LDFLAGS_standalone = -znoversion -Breduce -dy -r
+LDFLAGS = $(LDFLAGS_$(CURTYPE))
+
+ASFLAGS_standalone = -DDIS_STANDALONE
+ASFLAGS_library =
+ASFLAGS += -P $(ASFLAGS_$(CURTYPE)) -D_ASM
+
+$(LINTLIB) := SRCS = $(COMDIR)/$(LINTSRC)
+
+# We want the thread-specific errno in the library, but we don't want it in
+# the standalone. $(DTS_ERRNO) is designed to add -D_TS_ERRNO to $(CPPFLAGS),
+# in order to enable this feature. Conveniently, -D_REENTRANT does the same
+# thing. As such, we null out $(DTS_ERRNO) to ensure that the standalone
+# doesn't get it.
+DTS_ERRNO=
+
+# We need to rename some standard functions so we can easily implement them
+# in consumers.
+STAND_RENAMED_FUNCS= \
+ snprintf
+
+CPPFLAGS_standalone = -DDIS_STANDALONE $(STAND_RENAMED_FUNCS:%=-D%=mdb_%) \
+ -I$(SRC)/cmd/mdb/common
+CPPFLAGS_library = -D_REENTRANT
+CPPFLAGS += -I$(COMDIR) $(CPPFLAGS_$(CURTYPE))
+
+#
+# For x86, we have to link to sources in usr/src/common
+#
+CPPFLAGS_dis_i386 = -I$(SRC)/common/dis/i386 -DDIS_TEXT
+CPPFLAGS_dis_sparc =
+CPPFLAGS += $(CPPFLAGS_dis_$(MACH))
+
+CFLAGS_standalone = $(STAND_FLAGS_32)
+CFLAGS_common =
+CFLAGS += $(CFLAGS_$(CURTYPE)) $(CFLAGS_common)
+
+CFLAGS64_standalone = $(STAND_FLAGS_64)
+CFLAGS64 += $(CCVERBOSE) $(CFLAGS64_$(CURTYPE)) $(CFLAGS64_common)
+
+DYNFLAGS += $(ZINTERPOSE)
+
+.KEEP_STATE:
diff --git a/usr/src/lib/libdisasm/Makefile.targ b/usr/src/lib/libdisasm/Makefile.targ
new file mode 100644
index 0000000000..c5798c1a94
--- /dev/null
+++ b/usr/src/lib/libdisasm/Makefile.targ
@@ -0,0 +1,100 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# We build each flavor in a separate make invocation to improve clarity(!) in
+# Makefile.com. The subordinate makes have $(CURTYPE) set to indicate the
+# flavor they're supposed to build. This causes the correct set of source
+# files and compiler and linker flags to be selected.
+#
+# The SPARC library is built from the closed gate. This Makefile is shared
+# between both environments, so all paths must be absolute.
+#
+
+install: $(TYPES:%=install.%)
+
+all: $(TYPES:%=all.%)
+
+$(TYPES:%=all.%):
+ @CURTYPE=$(@:all.%=%) $(MAKE) $@.targ
+
+$(TYPES:%=install.%):
+ @CURTYPE=$(@:install.%=%) $(MAKE) $@.targ
+
+install.library.targ: all.library $(INSTALL_DEPS_library)
+install.standalone.targ: all.standalone $(INSTALL_DEPS_standalone)
+
+all.library.targ: $(LIBS)
+all.standalone.targ: $(STANDLIBRARY)
+
+lint: $(TYPES:%=lint.%)
+
+$(TYPES:%=lint.%):
+ @CURTYPE=$(@:lint.%=%) $(MAKE) lintcheck
+
+$(STANDLIBRARY): $(OBJS) $(LINKTEST_OBJ)
+ $(LD) -Breduce -zdefs $(LDFLAGS) -o $@.linktest $(OBJS) $(LINKTEST_OBJ)
+ rm $@.linktest
+ $(LD) $(LDFLAGS) -o $@ $(OBJS)
+
+$(DYNLIB): $(MAPFILE)
+
+$(MAPFILE):
+ @cd $(MAPDIR); $(MAKE) mapfile
+
+clobber: $(TYPES:%=clobber.%)
+
+$(TYPES:%=clobber.%):
+ @CURTYPE=$(@:clobber.%=%) $(MAKE) clobber.targ
+
+clobber.targ: clean
+ -$(RM) $(CLOBBERTARGFILES)
+
+# include library targets
+include $(SRC)/lib/Makefile.targ
+
+$(PICS): pics
+$(OBJS): objs
+
+objs/%.o pics/%.o: $(ISASRCDIR)/%.c
+ $(COMPILE.c) -o $@ $<
+ $(POST_PROCESS_O)
+
+objs/%.o pics/%.o: $(ISASRCDIR)/%.s
+ $(COMPILE.s) -o $@ $<
+ $(POST_PROCESS_O)
+
+objs/%.o pics/%.o: $(COMDIR)/%.c
+ $(COMPILE.c) -o $@ $<
+ $(POST_PROCESS_O)
+
+# install rule for lint library target
+$(ROOTLINTDIR)/%: $(COMDIR)/%
+ $(INS.file)
+
+# install rule for x86 common source
+objs/%.o pics/%.o: $(SRC)/common/dis/i386/%.c
+ $(COMPILE.c) -o $@ $<
+ $(POST_PROCESS_O)
diff --git a/usr/src/lib/libdisasm/amd64/Makefile b/usr/src/lib/libdisasm/amd64/Makefile
new file mode 100644
index 0000000000..f53089a463
--- /dev/null
+++ b/usr/src/lib/libdisasm/amd64/Makefile
@@ -0,0 +1,37 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+ISASRCDIR=../$(MACH)/
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+TYPES=library standalone
+
+INSTALL_DEPS_library = $(ROOTLINKS64) $(ROOTLINT64) $(ROOTLIBS64)
+INSTALL_DEPS_standalone = $(ROOTLIBS64)
+
+include ../Makefile.targ
diff --git a/usr/src/lib/libdisasm/common/libdisasm.c b/usr/src/lib/libdisasm/common/libdisasm.c
new file mode 100644
index 0000000000..197c2c34df
--- /dev/null
+++ b/usr/src/lib/libdisasm/common/libdisasm.c
@@ -0,0 +1,92 @@
+/*
+ * 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 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <libdisasm.h>
+#include <stdlib.h>
+#ifdef DIS_STANDALONE
+#include <mdb/mdb_modapi.h>
+#endif
+
+static int _dis_errno;
+
+/*
+ * For the standalone library, we need to link against mdb's malloc/free.
+ * Otherwise, use the standard malloc/free.
+ */
+#ifdef DIS_STANDALONE
+void *
+dis_zalloc(size_t bytes)
+{
+ return (mdb_zalloc(bytes, UM_SLEEP));
+}
+
+void
+dis_free(void *ptr, size_t bytes)
+{
+ mdb_free(ptr, bytes);
+}
+#else
+void *
+dis_zalloc(size_t bytes)
+{
+ return (calloc(1, bytes));
+}
+
+/*ARGSUSED*/
+void
+dis_free(void *ptr, size_t bytes)
+{
+ free(ptr);
+}
+#endif
+
+int
+dis_seterrno(int error)
+{
+ _dis_errno = error;
+ return (-1);
+}
+
+int
+dis_errno(void)
+{
+ return (_dis_errno);
+}
+
+const char *
+dis_strerror(int error)
+{
+ switch (error) {
+ case E_DIS_NOMEM:
+ return ("out of memory");
+ case E_DIS_INVALFLAG:
+ return ("invalid flags for this architecture");
+ default:
+ return ("unknown error");
+ }
+}
diff --git a/usr/src/lib/libdisasm/common/libdisasm.h b/usr/src/lib/libdisasm/common/libdisasm.h
new file mode 100644
index 0000000000..f66150a4ec
--- /dev/null
+++ b/usr/src/lib/libdisasm/common/libdisasm.h
@@ -0,0 +1,78 @@
+/*
+ * 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 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _LIBDISASM_H
+#define _LIBDISASM_H
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct dis_handle dis_handle_t;
+
+#define DIS_DEFAULT 0x0
+
+/* SPARC disassembler flags */
+#define DIS_SPARC_V8 0x01
+#define DIS_SPARC_V9 0x02
+#define DIS_SPARC_V9_SGI 0x04
+
+/* x86 diassembler flags (mutually exclusive) */
+#define DIS_X86_SIZE16 0x08
+#define DIS_X86_SIZE32 0x10
+#define DIS_X86_SIZE64 0x20
+
+/* generic disassembler flags */
+#define DIS_OCTAL 0x40
+
+typedef int (*dis_lookup_f)(void *, uint64_t, char *, size_t, uint64_t *,
+ size_t *);
+typedef int (*dis_read_f)(void *, uint64_t, void *, size_t);
+
+extern dis_handle_t *dis_handle_create(int, void *, dis_lookup_f, dis_read_f);
+extern void dis_handle_destroy(dis_handle_t *);
+
+extern int dis_disassemble(dis_handle_t *, uint64_t, char *, size_t);
+extern uint64_t dis_previnstr(dis_handle_t *, uint64_t, int n);
+extern void dis_set_data(dis_handle_t *, void *);
+extern int dis_max_instrlen(dis_handle_t *);
+
+/* libdisasm errors */
+#define E_DIS_NOMEM 1 /* Out of memory */
+#define E_DIS_INVALFLAG 2 /* Invalid flag for this architecture */
+
+extern int dis_errno(void);
+extern const char *dis_strerror(int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LIBDISASM_H */
diff --git a/usr/src/lib/libdisasm/common/libdisasm_impl.h b/usr/src/lib/libdisasm/common/libdisasm_impl.h
new file mode 100644
index 0000000000..c31c24fe6a
--- /dev/null
+++ b/usr/src/lib/libdisasm/common/libdisasm_impl.h
@@ -0,0 +1,45 @@
+/*
+ * 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 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _LIBDISASM_IMPL_H
+#define _LIBDISASM_IMPL_H
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int dis_seterrno(int);
+
+extern void *dis_zalloc(size_t);
+extern void dis_free(void *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LIBDISASM_IMPL_H */
diff --git a/usr/src/lib/libdisasm/common/linktest_stand.c b/usr/src/lib/libdisasm/common/linktest_stand.c
new file mode 100644
index 0000000000..fd6ff8e353
--- /dev/null
+++ b/usr/src/lib/libdisasm/common/linktest_stand.c
@@ -0,0 +1,42 @@
+/*
+ * 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 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * This file is used to verify that the standalone's external dependencies
+ * haven't changed in a way that'll break things that use it.
+ */
+
+void mdb_free(void) {}
+void snprintf(void) {}
+void mdb_zalloc(void) {}
+void strcmp(void) {}
+void strlen(void) {}
+void strlcat(void) {}
+void strncpy(void) {}
+void strncmp(void) {}
+void memcpy(void) {}
diff --git a/usr/src/lib/libdisasm/common/llib-ldisasm b/usr/src/lib/libdisasm/common/llib-ldisasm
new file mode 100644
index 0000000000..4ca0ab20e6
--- /dev/null
+++ b/usr/src/lib/libdisasm/common/llib-ldisasm
@@ -0,0 +1,35 @@
+/*
+ * 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
+ */
+
+/*LINTLIBRARY*/
+/*PROTOLIB1*/
+
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/* LINTLIBRARY */
+/* PROTOLIB1 */
+
+#include <libdisasm.h>
diff --git a/usr/src/lib/libdisasm/i386/Makefile b/usr/src/lib/libdisasm/i386/Makefile
new file mode 100644
index 0000000000..8d0d4453a2
--- /dev/null
+++ b/usr/src/lib/libdisasm/i386/Makefile
@@ -0,0 +1,36 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+ISASRCDIR=.
+
+include ../Makefile.com
+
+TYPES=library standalone
+
+INSTALL_DEPS_library = $(ROOTLINKS) $(ROOTLINT) $(ROOTLIBS)
+INSTALL_DEPS_standalone = $(ROOTLIBS)
+
+include ../Makefile.targ
diff --git a/usr/src/lib/libdisasm/i386/dis_i386.c b/usr/src/lib/libdisasm/i386/dis_i386.c
new file mode 100644
index 0000000000..e499bd9ee0
--- /dev/null
+++ b/usr/src/lib/libdisasm/i386/dis_i386.c
@@ -0,0 +1,225 @@
+/*
+ * 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 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <libdisasm.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "dis_tables.h"
+#include "libdisasm_impl.h"
+
+struct dis_handle {
+ void *dh_data;
+ int dh_flags;
+ dis_lookup_f dh_lookup;
+ dis_read_f dh_read;
+ int dh_mode;
+ dis86_t dh_dis;
+ uint64_t dh_addr;
+ uint64_t dh_end;
+};
+
+/*
+ * Returns true if we are near the end of a function. This is a cheap hack at
+ * detecting NULL padding between functions. If we're within a few bytes of the
+ * next function, or past the start, then return true.
+ */
+static int
+check_func(void *data)
+{
+ dis_handle_t *dhp = data;
+ uint64_t start;
+ size_t len;
+
+ if (dhp->dh_lookup(dhp->dh_data, dhp->dh_addr, NULL, 0, &start, &len)
+ != 0)
+ return (0);
+
+ if (start < dhp->dh_addr)
+ return (dhp->dh_addr > start + len - 0x10);
+
+ return (1);
+}
+
+static int
+get_byte(void *data)
+{
+ uchar_t byte;
+ dis_handle_t *dhp = data;
+
+ if (dhp->dh_read(dhp->dh_data, dhp->dh_addr, &byte,
+ sizeof (byte)) < sizeof (byte))
+ return (-1);
+
+ dhp->dh_addr++;
+
+ return ((int)byte);
+}
+
+static int
+do_lookup(void *data, uint64_t addr, char *buf, size_t buflen)
+{
+ dis_handle_t *dhp = data;
+
+ return (dhp->dh_lookup(dhp->dh_data, addr, buf, buflen, NULL, NULL));
+}
+
+dis_handle_t *
+dis_handle_create(int flags, void *data, dis_lookup_f lookup_func,
+ dis_read_f read_func)
+{
+ dis_handle_t *dhp;
+
+ /*
+ * Validate architecture flags
+ */
+ if (flags & ~(DIS_X86_SIZE16 | DIS_X86_SIZE32 | DIS_X86_SIZE64 |
+ DIS_OCTAL)) {
+ (void) dis_seterrno(E_DIS_INVALFLAG);
+ return (NULL);
+ }
+
+ /*
+ * Create and initialize the internal structure
+ */
+ if ((dhp = dis_zalloc(sizeof (struct dis_handle))) == NULL) {
+ (void) dis_seterrno(E_DIS_NOMEM);
+ return (NULL);
+ }
+
+ dhp->dh_lookup = lookup_func;
+ dhp->dh_read = read_func;
+ dhp->dh_flags = flags;
+ dhp->dh_data = data;
+
+ /*
+ * Initialize x86-specific architecture structure
+ */
+ if (flags & DIS_X86_SIZE16)
+ dhp->dh_mode = SIZE16;
+ else if (flags & DIS_X86_SIZE64)
+ dhp->dh_mode = SIZE64;
+ else
+ dhp->dh_mode = SIZE32;
+
+ if (flags & DIS_OCTAL)
+ dhp->dh_dis.d86_flags = DIS_OP_OCTAL;
+
+ dhp->dh_dis.d86_sprintf_func = snprintf;
+ dhp->dh_dis.d86_get_byte = get_byte;
+ dhp->dh_dis.d86_sym_lookup = do_lookup;
+ dhp->dh_dis.d86_check_func = check_func;
+
+ dhp->dh_dis.d86_data = dhp;
+
+ return (dhp);
+}
+
+int
+dis_disassemble(dis_handle_t *dhp, uint64_t addr, char *buf, size_t buflen)
+{
+ dhp->dh_addr = addr;
+
+ if (dtrace_disx86(&dhp->dh_dis, dhp->dh_mode) != 0)
+ return (-1);
+
+ if (buf != NULL)
+ dtrace_disx86_str(&dhp->dh_dis, dhp->dh_mode, addr, buf,
+ buflen);
+
+ return (0);
+}
+
+void
+dis_handle_destroy(dis_handle_t *dhp)
+{
+ dis_free(dhp, sizeof (dis_handle_t));
+}
+
+void
+dis_set_data(dis_handle_t *dhp, void *data)
+{
+ dhp->dh_data = data;
+}
+
+/* ARGSUSED */
+int
+dis_max_instrlen(dis_handle_t *dhp)
+{
+ return (15);
+}
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
+/*
+ * Return the previous instruction. On x86, we have no choice except to
+ * disassemble everything from the start of the symbol, and stop when we have
+ * reached our instruction address. If we're not in the middle of a known
+ * symbol, then we return the same address to indicate failure.
+ */
+uint64_t
+dis_previnstr(dis_handle_t *dhp, uint64_t pc, int n)
+{
+ uint64_t *hist, addr, start;
+ int cur, nseen;
+ uint64_t res = pc;
+
+ if (dhp->dh_lookup(dhp->dh_data, pc, NULL, 0, &start, NULL) != 0 ||
+ start == pc)
+ return (res);
+
+ hist = dis_zalloc(sizeof (uint64_t) * n);
+
+ for (cur = 0, nseen = 0, addr = start; addr < pc; addr = dhp->dh_addr) {
+ hist[cur] = addr;
+ cur = (cur + 1) % n;
+ nseen++;
+
+ /* if we cannot make forward progress, give up */
+ if (dis_disassemble(dhp, addr, NULL, 0) != 0)
+ goto done;
+ }
+
+ if (addr != pc) {
+ /*
+ * We scanned past %pc, but didn't find an instruction that
+ * started at %pc. This means that either the caller specified
+ * an invalid address, or we ran into something other than code
+ * during our scan. Virtually any combination of bytes can be
+ * construed as a valid Intel instruction, so any non-code bytes
+ * we encounter will have thrown off the scan.
+ */
+ goto done;
+ }
+
+ res = hist[(cur + n - MIN(n, nseen)) % n];
+
+done:
+ dis_free(hist, sizeof (uint64_t) * n);
+ return (res);
+}
diff --git a/usr/src/lib/libdisasm/spec/Makefile b/usr/src/lib/libdisasm/spec/Makefile
new file mode 100644
index 0000000000..aa4090be64
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/Makefile
@@ -0,0 +1,27 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+include $(SRC)/lib/Makefile.spec.arch
diff --git a/usr/src/lib/libdisasm/spec/Makefile.targ b/usr/src/lib/libdisasm/spec/Makefile.targ
new file mode 100644
index 0000000000..7f0c111966
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/Makefile.targ
@@ -0,0 +1,30 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+LIBRARY= libdisasm.a
+VERS= .1
+
+OBJECTS= libdisasm.o
diff --git a/usr/src/lib/libdisasm/spec/amd64/Makefile b/usr/src/lib/libdisasm/spec/amd64/Makefile
new file mode 100644
index 0000000000..ccb7881373
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/amd64/Makefile
@@ -0,0 +1,34 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.lib.64
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB64)
diff --git a/usr/src/lib/libdisasm/spec/i386/Makefile b/usr/src/lib/libdisasm/spec/i386/Makefile
new file mode 100644
index 0000000000..9c275ffd2d
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/i386/Makefile
@@ -0,0 +1,33 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB)
diff --git a/usr/src/lib/libdisasm/spec/libdisasm.spec b/usr/src/lib/libdisasm/spec/libdisasm.spec
new file mode 100644
index 0000000000..d06dc0f18e
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/libdisasm.spec
@@ -0,0 +1,57 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+#ident "%Z%%M% %I% %E% SMI"
+
+function dis_disassemble
+version SUNWprivate_1.1
+end
+
+function dis_errno
+version SUNWprivate_1.1
+end
+
+function dis_handle_create
+version SUNWprivate_1.1
+end
+
+function dis_handle_destroy
+version SUNWprivate_1.1
+end
+
+function dis_max_instrlen
+version SUNWprivate_1.1
+end
+
+function dis_previnstr
+version SUNWprivate_1.1
+end
+
+function dis_set_data
+version SUNWprivate_1.1
+end
+
+function dis_strerror
+version SUNWprivate_1.1
+end
diff --git a/usr/src/lib/libdisasm/spec/sparc/Makefile b/usr/src/lib/libdisasm/spec/sparc/Makefile
new file mode 100644
index 0000000000..9c275ffd2d
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/sparc/Makefile
@@ -0,0 +1,33 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB)
diff --git a/usr/src/lib/libdisasm/spec/sparcv9/Makefile b/usr/src/lib/libdisasm/spec/sparcv9/Makefile
new file mode 100644
index 0000000000..ccb7881373
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/sparcv9/Makefile
@@ -0,0 +1,34 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.lib.64
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB64)
diff --git a/usr/src/lib/libdisasm/spec/versions b/usr/src/lib/libdisasm/spec/versions
new file mode 100644
index 0000000000..06da2dd348
--- /dev/null
+++ b/usr/src/lib/libdisasm/spec/versions
@@ -0,0 +1,43 @@
+#
+# 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 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+#ident "%Z%%M% %I% %E% SMI"
+
+sparc {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}
+sparcv9 {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}
+i386 {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}
+amd64 {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}