summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Rosenfeld <hans.rosenfeld@joyent.com>2019-02-13 16:08:32 +0000
committerHans Rosenfeld <hans.rosenfeld@joyent.com>2019-02-13 23:28:55 +0000
commit2a78db82bec123064d30d051995cb4d577ca04ba (patch)
treedf08459b898446fdc1355deaa6577c770266cd96
parenta34efbb67708deaa7bfc683cfc95bc54c769d912 (diff)
downloadillumos-joyent-2a78db82bec123064d30d051995cb4d577ca04ba.tar.gz
OS-7441 mdb: clean up ::sysregs duplication
Reviewed by: John Levon <john.levon@joyent.com> Reviewed by: Patrick Mooney <patrick.mooney@joyent.com> Approved by: John Levon <john.levon@joyent.com>
-rw-r--r--usr/src/cmd/mdb/i86pc/modules/unix/amd64/Makefile3
-rw-r--r--usr/src/cmd/mdb/i86pc/modules/unix/unix.c78
-rw-r--r--usr/src/cmd/mdb/i86xpv/modules/unix/amd64/Makefile3
-rw-r--r--usr/src/cmd/mdb/intel/Makefile.kmdb3
-rw-r--r--usr/src/cmd/mdb/intel/amd64/Makefile.kmdb5
-rw-r--r--usr/src/cmd/mdb/intel/amd64/mdb/Makefile3
-rw-r--r--usr/src/cmd/mdb/intel/mdb/mdb_bhyve.c230
-rw-r--r--usr/src/cmd/mdb/intel/mdb/mdb_x86util.c215
-rw-r--r--usr/src/cmd/mdb/intel/mdb/mdb_x86util.h68
9 files changed, 343 insertions, 265 deletions
diff --git a/usr/src/cmd/mdb/i86pc/modules/unix/amd64/Makefile b/usr/src/cmd/mdb/i86pc/modules/unix/amd64/Makefile
index 91b68537c3..ea8099272e 100644
--- a/usr/src/cmd/mdb/i86pc/modules/unix/amd64/Makefile
+++ b/usr/src/cmd/mdb/i86pc/modules/unix/amd64/Makefile
@@ -22,7 +22,7 @@
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright 2018 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
MODULE = unix.so
MDBTGT = kvm
@@ -38,6 +38,7 @@ include ../../../../Makefile.module
CPPFLAGS += -DMP -D_MACHDEP
CPPFLAGS += -I../../../../common
+CPPFLAGS += -I../../../../intel
CPPFLAGS += -I$(SRC)/uts/i86pc
CPPFLAGS += -I$(SRC)/uts/intel
diff --git a/usr/src/cmd/mdb/i86pc/modules/unix/unix.c b/usr/src/cmd/mdb/i86pc/modules/unix/unix.c
index e91321b235..bd7dfda6ed 100644
--- a/usr/src/cmd/mdb/i86pc/modules/unix/unix.c
+++ b/usr/src/cmd/mdb/i86pc/modules/unix/unix.c
@@ -20,11 +20,12 @@
*/
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2018 Joyent, Inc.
+ * Copyright 2019 Joyent, Inc.
*/
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_ctf.h>
+#include <mdb/mdb_x86util.h>
#include <sys/cpuvar.h>
#include <sys/systm.h>
#include <sys/traptrace.h>
@@ -963,73 +964,24 @@ x86_featureset_dcmd(uintptr_t addr, uint_t flags, int argc,
static int
sysregs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
- ulong_t cr0, cr2, cr3, cr4;
+ struct sysregs sregs = { 0 };
desctbr_t gdtr;
+ boolean_t longmode = B_FALSE;
- static const mdb_bitmask_t cr0_flag_bits[] = {
- { "PE", CR0_PE, CR0_PE },
- { "MP", CR0_MP, CR0_MP },
- { "EM", CR0_EM, CR0_EM },
- { "TS", CR0_TS, CR0_TS },
- { "ET", CR0_ET, CR0_ET },
- { "NE", CR0_NE, CR0_NE },
- { "WP", CR0_WP, CR0_WP },
- { "AM", CR0_AM, CR0_AM },
- { "NW", CR0_NW, CR0_NW },
- { "CD", CR0_CD, CR0_CD },
- { "PG", CR0_PG, CR0_PG },
- { NULL, 0, 0 }
- };
-
- static const mdb_bitmask_t cr3_flag_bits[] = {
- { "PCD", CR3_PCD, CR3_PCD },
- { "PWT", CR3_PWT, CR3_PWT },
- { NULL, 0, 0, }
- };
-
- static const mdb_bitmask_t cr4_flag_bits[] = {
- { "VME", CR4_VME, CR4_VME },
- { "PVI", CR4_PVI, CR4_PVI },
- { "TSD", CR4_TSD, CR4_TSD },
- { "DE", CR4_DE, CR4_DE },
- { "PSE", CR4_PSE, CR4_PSE },
- { "PAE", CR4_PAE, CR4_PAE },
- { "MCE", CR4_MCE, CR4_MCE },
- { "PGE", CR4_PGE, CR4_PGE },
- { "PCE", CR4_PCE, CR4_PCE },
- { "OSFXSR", CR4_OSFXSR, CR4_OSFXSR },
- { "OSXMMEXCPT", CR4_OSXMMEXCPT, CR4_OSXMMEXCPT },
- { "VMXE", CR4_VMXE, CR4_VMXE },
- { "SMXE", CR4_SMXE, CR4_SMXE },
- { "PCIDE", CR4_PCIDE, CR4_PCIDE },
- { "OSXSAVE", CR4_OSXSAVE, CR4_OSXSAVE },
- { "SMEP", CR4_SMEP, CR4_SMEP },
- { "SMAP", CR4_SMAP, CR4_SMAP },
- { NULL, 0, 0 }
- };
-
- cr0 = kmdb_unix_getcr0();
- cr2 = kmdb_unix_getcr2();
- cr3 = kmdb_unix_getcr3();
- cr4 = kmdb_unix_getcr4();
-
- kmdb_unix_getgdtr(&gdtr);
+#ifdef __amd64
+ longmode = B_TRUE;
+#endif
- mdb_printf("%%cr0 = 0x%lx <%b>\n", cr0, cr0, cr0_flag_bits);
- mdb_printf("%%cr2 = 0x%lx <%a>\n", cr2, cr2);
+ sregs.sr_cr0 = kmdb_unix_getcr0();
+ sregs.sr_cr2 = kmdb_unix_getcr2();
+ sregs.sr_cr3 = kmdb_unix_getcr3();
+ sregs.sr_cr4 = kmdb_unix_getcr4();
- if ((cr4 & CR4_PCIDE)) {
- mdb_printf("%%cr3 = 0x%lx <pfn:0x%lx pcid:%lu>\n", cr3,
- cr3 >> MMU_PAGESHIFT, cr3 & MMU_PAGEOFFSET);
- } else {
- mdb_printf("%%cr3 = 0x%lx <pfn:0x%lx flags:%b>\n", cr3,
- cr3 >> MMU_PAGESHIFT, cr3, cr3_flag_bits);
- }
-
- mdb_printf("%%cr4 = 0x%lx <%b>\n", cr4, cr4, cr4_flag_bits);
+ kmdb_unix_getgdtr(&gdtr);
+ sregs.sr_gdtr.d_base = gdtr.dtr_base;
+ sregs.sr_gdtr.d_lim = gdtr.dtr_limit;
- mdb_printf("%%gdtr.base = 0x%lx, %%gdtr.limit = 0x%hx\n",
- gdtr.dtr_base, gdtr.dtr_limit);
+ mdb_x86_print_sysregs(&sregs, longmode);
return (DCMD_OK);
}
diff --git a/usr/src/cmd/mdb/i86xpv/modules/unix/amd64/Makefile b/usr/src/cmd/mdb/i86xpv/modules/unix/amd64/Makefile
index 89ca0899ad..dd0e3d3318 100644
--- a/usr/src/cmd/mdb/i86xpv/modules/unix/amd64/Makefile
+++ b/usr/src/cmd/mdb/i86xpv/modules/unix/amd64/Makefile
@@ -22,7 +22,7 @@
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright 2018 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
MODULE = unix.so
MDBTGT = kvm
@@ -40,6 +40,7 @@ MODSRCS_DIR = ../../../../i86pc/modules/unix/
CPPFLAGS += -DMP -D_MACHDEP -D__xpv
CPPFLAGS += -I../../../../common
+CPPFLAGS += -I../../../../intel
CPPFLAGS += -I$(SRC)/uts/common
CPPFLAGS += -I$(SRC)/uts/i86xpv
CPPFLAGS += -I$(SRC)/uts/i86pc
diff --git a/usr/src/cmd/mdb/intel/Makefile.kmdb b/usr/src/cmd/mdb/intel/Makefile.kmdb
index 0a2a5e8581..b9ec60dffa 100644
--- a/usr/src/cmd/mdb/intel/Makefile.kmdb
+++ b/usr/src/cmd/mdb/intel/Makefile.kmdb
@@ -22,7 +22,7 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright 2018 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
#
PROMSRCS += \
@@ -66,6 +66,7 @@ KMDBLIBS = $(STANDLIBS) ../mdb_ks/kmod/mdb_ks
MAPFILE_SOURCES = \
$(MAPFILE_SOURCES_COMMON) \
../../kmdb/kmdb_dpi_isadep.h \
+ ../../mdb/mdb_x86util.h \
$(MAPFILE_SOURCES_$(MACH))
%.o: ../../../../../uts/intel/promif/%.c
diff --git a/usr/src/cmd/mdb/intel/amd64/Makefile.kmdb b/usr/src/cmd/mdb/intel/amd64/Makefile.kmdb
index 61cf1541a2..8cee9ff049 100644
--- a/usr/src/cmd/mdb/intel/amd64/Makefile.kmdb
+++ b/usr/src/cmd/mdb/intel/amd64/Makefile.kmdb
@@ -22,6 +22,8 @@
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+# Copyright 2019 Joyent, Inc.
+#
KMDBML += \
kaif_invoke.s \
@@ -29,6 +31,7 @@ KMDBML += \
KMDBSRCS += \
kmdb_makecontext.c \
- mdb_amd64util.c
+ mdb_amd64util.c \
+ mdb_x86util.c
SACPPFLAGS = -D__$(MACH64) -U__$(MACH)
diff --git a/usr/src/cmd/mdb/intel/amd64/mdb/Makefile b/usr/src/cmd/mdb/intel/amd64/mdb/Makefile
index bc4c1fc64f..918aa71ea1 100644
--- a/usr/src/cmd/mdb/intel/amd64/mdb/Makefile
+++ b/usr/src/cmd/mdb/intel/amd64/mdb/Makefile
@@ -22,13 +22,14 @@
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright 2018 Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
#
SRCS = kvm_amd64dep.c \
kvm_isadep.c \
mdb_amd64util.c \
mdb_ia32util.c \
+ mdb_x86util.c \
mdb_bhyve.c \
proc_amd64dep.c
diff --git a/usr/src/cmd/mdb/intel/mdb/mdb_bhyve.c b/usr/src/cmd/mdb/intel/mdb/mdb_bhyve.c
index 8795058ef9..1bfd8416c4 100644
--- a/usr/src/cmd/mdb/intel/mdb/mdb_bhyve.c
+++ b/usr/src/cmd/mdb/intel/mdb/mdb_bhyve.c
@@ -10,7 +10,7 @@
*/
/*
- * Copyright 2018 Joyent, Inc.
+ * Copyright 2019 Joyent, Inc.
*/
/*
@@ -64,6 +64,7 @@
#include <mdb/mdb_isautil.h>
#include <mdb/mdb_amd64util.h>
#include <mdb/mdb_ia32util.h>
+#include <mdb/mdb_x86util.h>
#include <mdb/mdb.h>
#include <sys/controlregs.h>
@@ -77,11 +78,6 @@
#define MDB_DEF_PROMPT "[%<_cpuid>]> "
-#define MMU_PAGESHIFT 12
-#define MMU_PAGESIZE (1 << MMU_PAGESHIFT)
-#define MMU_PAGEOFFSET (MMU_PAGESIZE - 1)
-#define MMU_PAGEMASK (~MMU_PAGEOFFSET)
-
typedef struct bhyve_data {
vmm_t *bd_vmm;
uint_t bd_curcpu;
@@ -480,75 +476,6 @@ bhyve_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
return (DCMD_OK);
}
-static void
-bhyve_print_desc(const char *name, const vmm_desc_t *desc, int width)
-{
- const char *type;
- const mdb_bitmask_t *bits;
-
- static const mdb_bitmask_t mem_desc_flag_bits[] = {
- { "P", 0x80, 0x80 },
- { "16b", 0x6000, 0x0 },
- { "32b", 0x6000, 0x4000 },
- { "64b", 0x6000, 0x2000 },
- { "G", 0x8000, 0x8000 },
- { "A", 0x1, 0x1 },
- { NULL, 0, 0 },
- };
-
- static const char *mem_desc_types[] = {
- "data, up, read-only",
- "data, up, read-write",
- "data, down, read-only",
- "data, down, read-write",
- "code, non-conforming, execute-only",
- "code, non-conforming, execute-read",
- "code, conforming, execute-only",
- "code, conforming, execute-read"
- };
-
- static const mdb_bitmask_t sys_desc_flag_bits[] = {
- { "P", 0x80, 0x80 },
- { "16b", 0x6000, 0x0 },
- { "32b", 0x6000, 0x4000 },
- { "64b", 0x6000, 0x2000 },
- { "G", 0x8000, 0x8000 },
- { NULL, 0, 0 },
- };
-
- static const char *sys_desc_types[] = {
- "reserved",
- "16b TSS, available",
- "LDT",
- "16b TSS, busy",
- "16b call gate",
- "task gate",
- "16b interrupt gate",
- "16b trap gate",
- "reserved",
- "32b/64b TSS, available",
- "reserved",
- "32b/64b TSS, busy",
- "32b/64b call gate",
- "reserved",
- "32b/64b interrupt gate"
- "32b/64b trap gate",
- };
-
- if (desc->vd_acc & 0x10) {
- type = mem_desc_types[(desc->vd_acc >> 1) & 7];
- bits = mem_desc_flag_bits;
- } else {
- type = sys_desc_types[desc->vd_acc & 0xf];
- bits = sys_desc_flag_bits;
- }
-
- mdb_printf("%%%s = 0x%0*p/0x%0*x 0x%05x "
- "<%susable, %s, dpl %d, flags: %b>\n",
- name, width, desc->vd_base, width / 2, desc->vd_lim, desc->vd_acc,
- (desc->vd_acc >> 16) & 1 ? "un" : "", type,
- (desc->vd_acc >> 5) & 3, desc->vd_acc, bits);
-}
static int
bhyve_sysregs_dcmd(uintptr_t addr, uint_t flags, int argc,
@@ -557,19 +484,12 @@ bhyve_sysregs_dcmd(uintptr_t addr, uint_t flags, int argc,
bhyve_data_t *bd = mdb.m_target->t_data;
uint64_t cpu = bd->bd_curcpu;
int ret = DCMD_ERR;
- vmm_desc_t gdtr, ldtr, idtr, tr, cs, ds, es, fs, gs, ss;
- uint64_t *regvals;
+ struct sysregs sregs;
int i;
- int width = sizeof (uint64_t) * 2;
-
- if (vmm_vcpu_mode(bd->bd_vmm, cpu) != VMM_MODE_LONG)
- width /= 2;
/*
- * This array must use the order of definitions set in libvmm.h
- * to make GETREG() work.
+ * This array must use the order of the elements of struct sysregs.
*/
-#define GETREG(r) (regvals[r - VMM_REG_OFFSET])
static const int regnums[] = {
VMM_REG_CR0,
VMM_REG_CR2,
@@ -589,64 +509,6 @@ bhyve_sysregs_dcmd(uintptr_t addr, uint_t flags, int argc,
VMM_REG_INTR_SHADOW
};
- static const mdb_bitmask_t efer_flag_bits[] = {
- { "SCE", AMD_EFER_SCE, AMD_EFER_SCE },
- { "LME", AMD_EFER_LME, AMD_EFER_LME },
- { "LMA", AMD_EFER_LMA, AMD_EFER_LMA },
- { "NXE", AMD_EFER_NXE, AMD_EFER_NXE },
- { "SVME", AMD_EFER_SVME, AMD_EFER_SVME },
- { "LMSLE", AMD_EFER_LMSLE, AMD_EFER_LMSLE },
- { "FFXSR", AMD_EFER_FFXSR, AMD_EFER_FFXSR },
- { "TCE", AMD_EFER_TCE, AMD_EFER_TCE },
- { NULL, 0, 0 }
- };
-
- static const mdb_bitmask_t cr0_flag_bits[] = {
- { "PE", CR0_PE, CR0_PE },
- { "MP", CR0_MP, CR0_MP },
- { "EM", CR0_EM, CR0_EM },
- { "TS", CR0_TS, CR0_TS },
- { "ET", CR0_ET, CR0_ET },
- { "NE", CR0_NE, CR0_NE },
- { "WP", CR0_WP, CR0_WP },
- { "AM", CR0_AM, CR0_AM },
- { "NW", CR0_NW, CR0_NW },
- { "CD", CR0_CD, CR0_CD },
- { "PG", CR0_PG, CR0_PG },
- { NULL, 0, 0 }
- };
-
- static const mdb_bitmask_t cr3_flag_bits[] = {
- { "PCD", CR3_PCD, CR3_PCD },
- { "PWT", CR3_PWT, CR3_PWT },
- { NULL, 0, 0, }
- };
-
- static const mdb_bitmask_t cr4_flag_bits[] = {
- { "VME", CR4_VME, CR4_VME },
- { "PVI", CR4_PVI, CR4_PVI },
- { "TSD", CR4_TSD, CR4_TSD },
- { "DE", CR4_DE, CR4_DE },
- { "PSE", CR4_PSE, CR4_PSE },
- { "PAE", CR4_PAE, CR4_PAE },
- { "MCE", CR4_MCE, CR4_MCE },
- { "PGE", CR4_PGE, CR4_PGE },
- { "PCE", CR4_PCE, CR4_PCE },
- { "OSFXSR", CR4_OSFXSR, CR4_OSFXSR },
- { "OSXMMEXCPT", CR4_OSXMMEXCPT, CR4_OSXMMEXCPT },
- { "UMIP", CR4_UMIP, CR4_UMIP },
- { "VMXE", CR4_VMXE, CR4_VMXE },
- { "SMXE", CR4_SMXE, CR4_SMXE },
- { "FSGSBASE", CR4_FSGSBASE, CR4_FSGSBASE },
- { "PCIDE", CR4_PCIDE, CR4_PCIDE },
- { "OSXSAVE", CR4_OSXSAVE, CR4_OSXSAVE },
- { "SMEP", CR4_SMEP, CR4_SMEP },
- { "SMAP", CR4_SMAP, CR4_SMAP },
- { "PKE", CR4_PKE, CR4_PKE },
- { NULL, 0, 0 }
- };
-
-
if (flags & DCMD_ADDRSPEC) {
if (argc != 0)
return (DCMD_USAGE);
@@ -667,66 +529,40 @@ bhyve_sysregs_dcmd(uintptr_t addr, uint_t flags, int argc,
return (DCMD_ERR);
}
- regvals = mdb_zalloc(ARRAY_SIZE(regnums) * sizeof (uint64_t), UM_SLEEP);
-
if (vmm_get_regset(bd->bd_vmm, cpu, ARRAY_SIZE(regnums), regnums,
- regvals) != 0)
+ (uint64_t *)&sregs) != 0)
goto fail;
- if (vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_GDTR, &gdtr) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_IDTR, &idtr) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_LDTR, &ldtr) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_TR, &tr) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_CS, &cs) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_DS, &ds) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_ES, &es) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_FS, &fs) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_GS, &gs) != 0 ||
- vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_SS, &ss) != 0)
+ if (vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_GDTR,
+ (vmm_desc_t *)&sregs.sr_gdtr) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_IDTR,
+ (vmm_desc_t *)&sregs.sr_idtr) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_LDTR,
+ (vmm_desc_t *)&sregs.sr_ldtr) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_TR,
+ (vmm_desc_t *)&sregs.sr_tr) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_CS,
+ (vmm_desc_t *)&sregs.sr_cs) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_DS,
+ (vmm_desc_t *)&sregs.sr_ds) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_ES,
+ (vmm_desc_t *)&sregs.sr_es) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_FS,
+ (vmm_desc_t *)&sregs.sr_fs) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_GS,
+ (vmm_desc_t *)&sregs.sr_gs) != 0 ||
+ vmm_get_desc(bd->bd_vmm, cpu, VMM_DESC_SS,
+ (vmm_desc_t *)&sregs.sr_ss) != 0)
goto fail;
- mdb_printf("%%efer = 0x%0lx <%b>\n",
- GETREG(VMM_REG_EFER), GETREG(VMM_REG_EFER), efer_flag_bits);
- mdb_printf("%%cr0 = 0x%0lx <%b>\n",
- GETREG(VMM_REG_CR0), GETREG(VMM_REG_CR0), cr0_flag_bits);
- mdb_printf("%%cr2 = 0x%0*p %A\n", width,
- GETREG(VMM_REG_CR2), GETREG(VMM_REG_CR2));
- mdb_printf("%%cr3 = 0x%0lx <pfn:0x%lx ",
- GETREG(VMM_REG_CR3), GETREG(VMM_REG_CR3) >> MMU_PAGESHIFT);
- if (GETREG(VMM_REG_CR4) & CR4_PCIDE)
- mdb_printf("pcid:%lu>\n", GETREG(VMM_REG_CR3) & MMU_PAGEOFFSET);
- else
- mdb_printf("flags:%b>\n", GETREG(VMM_REG_CR3), cr3_flag_bits);
- mdb_printf("%%cr4 = 0x%0lx <%b>\n\n",
- GETREG(VMM_REG_CR4), GETREG(VMM_REG_CR4), cr4_flag_bits);
-
- mdb_printf("%%pdpte0 = 0x%0?p\t%%pdpte2 = 0x%0?p\n",
- GETREG(VMM_REG_PDPTE0), GETREG(VMM_REG_PDPTE2));
- mdb_printf("%%pdpte1 = 0x%0?p\t%%pdpte3 = 0x%0?p\n\n",
- GETREG(VMM_REG_PDPTE1), GETREG(VMM_REG_PDPTE3));
-
- mdb_printf("%%gdtr = 0x%0*x/0x%hx\n",
- width, gdtr.vd_base, gdtr.vd_lim);
- mdb_printf("%%idtr = 0x%0*x/0x%hx\n",
- width, idtr.vd_base, idtr.vd_lim);
- bhyve_print_desc("ldtr", &ldtr, width);
- bhyve_print_desc("tr ", &tr, width);
- bhyve_print_desc("cs ", &cs, width);
- bhyve_print_desc("ss ", &ss, width);
- bhyve_print_desc("ds ", &ds, width);
- bhyve_print_desc("es ", &es, width);
- bhyve_print_desc("fs ", &fs, width);
- bhyve_print_desc("gs ", &gs, width);
-
- mdb_printf("%%intr_shadow = 0x%lx\n\n",
- GETREG(VMM_REG_INTR_SHADOW));
-#undef GETREG
+ mdb_x86_print_sysregs(&sregs, vmm_vcpu_mode(bd->bd_vmm, cpu) ==
+ VMM_MODE_LONG);
+
ret = DCMD_OK;
fail:
if (ret != DCMD_OK)
mdb_warn("failed to get system registers for CPU %d\n", cpu);
- mdb_free(regvals, ARRAY_SIZE(regnums) * sizeof (uint64_t));
return (ret);
}
@@ -892,13 +728,13 @@ static int
bhyve_seg2reg(const char *seg)
{
if (strcasecmp(seg, "cs") == 0)
- return(VMM_DESC_CS);
+ return (VMM_DESC_CS);
else if (strcasecmp(seg, "ds") == 0)
- return(VMM_DESC_DS);
+ return (VMM_DESC_DS);
else if (strcasecmp(seg, "es") == 0)
- return(VMM_DESC_ES);
+ return (VMM_DESC_ES);
else if (strcasecmp(seg, "fs") == 0)
- return(VMM_DESC_FS);
+ return (VMM_DESC_FS);
else if (strcasecmp(seg, "gs") == 0)
return (VMM_DESC_GS);
else if (strcasecmp(seg, "ss") == 0)
@@ -1058,7 +894,7 @@ bhyve_setflags(mdb_tgt_t *tgt, int flags)
boolean_t writable = (flags & MDB_TGT_F_RDWR) != 0;
vmm_unmap(bd->bd_vmm);
- if (vmm_map(bd->bd_vmm, writable)!= 0) {
+ if (vmm_map(bd->bd_vmm, writable) != 0) {
mdb_warn("failed to map guest memory");
return (set_errno(EMDB_TGT));
}
diff --git a/usr/src/cmd/mdb/intel/mdb/mdb_x86util.c b/usr/src/cmd/mdb/intel/mdb/mdb_x86util.c
new file mode 100644
index 0000000000..a01ee6cffb
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/mdb/mdb_x86util.c
@@ -0,0 +1,215 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2019 Joyent, Inc.
+ */
+
+/*
+ * ISA-independent utility functions for the x86 architecture
+ */
+
+#include <mdb/mdb_modapi.h>
+#include <mdb/mdb_x86util.h>
+
+#include <sys/controlregs.h>
+#include <inttypes.h>
+
+#define MMU_PAGESHIFT 12
+#define MMU_PAGESIZE (1 << MMU_PAGESHIFT)
+#define MMU_PAGEOFFSET (MMU_PAGESIZE - 1)
+#define MMU_PAGEMASK (~MMU_PAGEOFFSET)
+
+#ifndef _KMDB
+static void
+mdb_x86_print_desc(const char *name, const mdb_x86_desc_t *desc, uint_t width)
+{
+ const char *type;
+ const mdb_bitmask_t *bits;
+
+ static const mdb_bitmask_t mem_desc_flag_bits[] = {
+ { "P", 0x80, 0x80 },
+ { "16b", 0x6000, 0x0 },
+ { "32b", 0x6000, 0x4000 },
+ { "64b", 0x6000, 0x2000 },
+ { "G", 0x8000, 0x8000 },
+ { "A", 0x1, 0x1 },
+ { NULL, 0, 0 },
+ };
+
+ static const char *mem_desc_types[] = {
+ "data, up, read-only",
+ "data, up, read-write",
+ "data, down, read-only",
+ "data, down, read-write",
+ "code, non-conforming, execute-only",
+ "code, non-conforming, execute-read",
+ "code, conforming, execute-only",
+ "code, conforming, execute-read"
+ };
+
+ static const mdb_bitmask_t sys_desc_flag_bits[] = {
+ { "P", 0x80, 0x80 },
+ { "16b", 0x6000, 0x0 },
+ { "32b", 0x6000, 0x4000 },
+ { "64b", 0x6000, 0x2000 },
+ { "G", 0x8000, 0x8000 },
+ { NULL, 0, 0 },
+ };
+
+ static const char *sys_desc_types[] = {
+ "reserved",
+ "16b TSS, available",
+ "LDT",
+ "16b TSS, busy",
+ "16b call gate",
+ "task gate",
+ "16b interrupt gate",
+ "16b trap gate",
+ "reserved",
+ "32b/64b TSS, available",
+ "reserved",
+ "32b/64b TSS, busy",
+ "32b/64b call gate",
+ "reserved",
+ "32b/64b interrupt gate"
+ "32b/64b trap gate",
+ };
+
+ if (desc->d_acc & 0x10) {
+ type = mem_desc_types[(desc->d_acc >> 1) & 7];
+ bits = mem_desc_flag_bits;
+ } else {
+ type = sys_desc_types[desc->d_acc & 0xf];
+ bits = sys_desc_flag_bits;
+ }
+
+ mdb_printf("%%%s = 0x%0*lx/0x%0*x 0x%05x "
+ "<%susable, %s, dpl %d, flags: %b>\n",
+ name, width, desc->d_base, width / 2, desc->d_lim, desc->d_acc,
+ (desc->d_acc >> 16) & 1 ? "un" : "", type,
+ (desc->d_acc >> 5) & 3, desc->d_acc, bits);
+}
+#endif
+
+void
+mdb_x86_print_sysregs(struct sysregs *sregs, boolean_t long_mode)
+{
+ const uint_t width =
+ 2 * (long_mode ? sizeof (uint64_t) : sizeof (uint32_t));
+
+
+#ifndef _KMDB
+ static const mdb_bitmask_t efer_flag_bits[] = {
+ { "SCE", AMD_EFER_SCE, AMD_EFER_SCE },
+ { "LME", AMD_EFER_LME, AMD_EFER_LME },
+ { "LMA", AMD_EFER_LMA, AMD_EFER_LMA },
+ { "NXE", AMD_EFER_NXE, AMD_EFER_NXE },
+ { "SVME", AMD_EFER_SVME, AMD_EFER_SVME },
+ { "LMSLE", AMD_EFER_LMSLE, AMD_EFER_LMSLE },
+ { "FFXSR", AMD_EFER_FFXSR, AMD_EFER_FFXSR },
+ { "TCE", AMD_EFER_TCE, AMD_EFER_TCE },
+ { NULL, 0, 0 }
+ };
+#endif
+
+ static const mdb_bitmask_t cr0_flag_bits[] = {
+ { "PE", CR0_PE, CR0_PE },
+ { "MP", CR0_MP, CR0_MP },
+ { "EM", CR0_EM, CR0_EM },
+ { "TS", CR0_TS, CR0_TS },
+ { "ET", CR0_ET, CR0_ET },
+ { "NE", CR0_NE, CR0_NE },
+ { "WP", CR0_WP, CR0_WP },
+ { "AM", CR0_AM, CR0_AM },
+ { "NW", CR0_NW, CR0_NW },
+ { "CD", CR0_CD, CR0_CD },
+ { "PG", CR0_PG, CR0_PG },
+ { NULL, 0, 0 }
+ };
+
+ static const mdb_bitmask_t cr3_flag_bits[] = {
+ { "PCD", CR3_PCD, CR3_PCD },
+ { "PWT", CR3_PWT, CR3_PWT },
+ { NULL, 0, 0, }
+ };
+
+ static const mdb_bitmask_t cr4_flag_bits[] = {
+ { "VME", CR4_VME, CR4_VME },
+ { "PVI", CR4_PVI, CR4_PVI },
+ { "TSD", CR4_TSD, CR4_TSD },
+ { "DE", CR4_DE, CR4_DE },
+ { "PSE", CR4_PSE, CR4_PSE },
+ { "PAE", CR4_PAE, CR4_PAE },
+ { "MCE", CR4_MCE, CR4_MCE },
+ { "PGE", CR4_PGE, CR4_PGE },
+ { "PCE", CR4_PCE, CR4_PCE },
+ { "OSFXSR", CR4_OSFXSR, CR4_OSFXSR },
+ { "OSXMMEXCPT", CR4_OSXMMEXCPT, CR4_OSXMMEXCPT },
+ { "UMIP", CR4_UMIP, CR4_UMIP },
+ { "VMXE", CR4_VMXE, CR4_VMXE },
+ { "SMXE", CR4_SMXE, CR4_SMXE },
+ { "FSGSBASE", CR4_FSGSBASE, CR4_FSGSBASE },
+ { "PCIDE", CR4_PCIDE, CR4_PCIDE },
+ { "OSXSAVE", CR4_OSXSAVE, CR4_OSXSAVE },
+ { "SMEP", CR4_SMEP, CR4_SMEP },
+ { "SMAP", CR4_SMAP, CR4_SMAP },
+ { "PKE", CR4_PKE, CR4_PKE },
+ { NULL, 0, 0 }
+ };
+
+#ifndef _KMDB
+ mdb_printf("%%efer = 0x%0lx <%b>\n",
+ sregs->sr_efer, sregs->sr_efer, efer_flag_bits);
+#endif
+ mdb_printf("%%cr0 = 0x%0lx <%b>\n",
+ sregs->sr_cr0, sregs->sr_cr0, cr0_flag_bits);
+ mdb_printf("%%cr2 = 0x%0*x <%a>\n", width,
+ sregs->sr_cr2, sregs->sr_cr2);
+ mdb_printf("%%cr3 = 0x%0lx <pfn:0x%lx ",
+ sregs->sr_cr3, sregs->sr_cr3 >> MMU_PAGESHIFT);
+ if (sregs->sr_cr4 & CR4_PCIDE)
+ mdb_printf("pcid:%lu>\n", sregs->sr_cr3 & MMU_PAGEOFFSET);
+ else
+ mdb_printf("flags:%b>\n", sregs->sr_cr3, cr3_flag_bits);
+ mdb_printf("%%cr4 = 0x%0lx <%b>\n",
+ sregs->sr_cr4, sregs->sr_cr4, cr4_flag_bits);
+
+#ifndef _KMDB
+ mdb_printf("\n");
+ mdb_printf("%%pdpte0 = 0x%0?lx\t%%pdpte2 = 0x%0?lx\n",
+ sregs->sr_pdpte0, sregs->sr_pdpte2);
+ mdb_printf("%%pdpte1 = 0x%0?lx\t%%pdpte3 = 0x%0?lx\n",
+ sregs->sr_pdpte1, sregs->sr_pdpte3);
+ mdb_printf("\n");
+
+ mdb_printf("%%gdtr = 0x%0*lx/0x%hx\n",
+ width, sregs->sr_gdtr.d_base, sregs->sr_gdtr.d_lim);
+#else
+ mdb_printf("%%gdtr.base = 0x%0*lx, %%gdtr.limit = 0x%hx\n",
+ width, sregs->sr_gdtr.d_base, sregs->sr_gdtr.d_lim);
+#endif
+#ifndef _KMDB
+ mdb_printf("%%idtr = 0x%0*lx/0x%hx\n",
+ width, sregs->sr_idtr.d_base, sregs->sr_idtr.d_lim);
+ mdb_x86_print_desc("ldtr", &sregs->sr_ldtr, width);
+ mdb_x86_print_desc("tr ", &sregs->sr_tr, width);
+ mdb_x86_print_desc("cs ", &sregs->sr_cs, width);
+ mdb_x86_print_desc("ss ", &sregs->sr_ss, width);
+ mdb_x86_print_desc("ds ", &sregs->sr_ds, width);
+ mdb_x86_print_desc("es ", &sregs->sr_es, width);
+ mdb_x86_print_desc("fs ", &sregs->sr_fs, width);
+ mdb_x86_print_desc("gs ", &sregs->sr_gs, width);
+
+ mdb_printf("%%intr_shadow = 0x%lx\n",
+ sregs->sr_intr_shadow);
+#endif
+}
diff --git a/usr/src/cmd/mdb/intel/mdb/mdb_x86util.h b/usr/src/cmd/mdb/intel/mdb/mdb_x86util.h
new file mode 100644
index 0000000000..7641595d2a
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/mdb/mdb_x86util.h
@@ -0,0 +1,68 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2019 Joyent, Inc.
+ */
+
+#ifndef _MDB_X86UTIL_H
+#define _MDB_X86UTIL_H
+
+#include <sys/types.h>
+#include <inttypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct mdb_x86_desc {
+ uint64_t d_base;
+ uint32_t d_lim;
+ uint32_t d_acc;
+} mdb_x86_desc_t;
+
+struct sysregs {
+ uint64_t sr_cr0;
+ uint64_t sr_cr2;
+ uint64_t sr_cr3;
+ uint64_t sr_cr4;
+ uint64_t sr_dr0;
+ uint64_t sr_dr1;
+ uint64_t sr_dr2;
+ uint64_t sr_dr3;
+ uint64_t sr_dr6;
+ uint64_t sr_dr7;
+ uint64_t sr_efer;
+ uint64_t sr_pdpte0;
+ uint64_t sr_pdpte1;
+ uint64_t sr_pdpte2;
+ uint64_t sr_pdpte3;
+ uint64_t sr_intr_shadow;
+ mdb_x86_desc_t sr_gdtr;
+ mdb_x86_desc_t sr_idtr;
+ mdb_x86_desc_t sr_ldtr;
+ mdb_x86_desc_t sr_tr;
+ mdb_x86_desc_t sr_cs;
+ mdb_x86_desc_t sr_ss;
+ mdb_x86_desc_t sr_ds;
+ mdb_x86_desc_t sr_es;
+ mdb_x86_desc_t sr_fs;
+ mdb_x86_desc_t sr_gs;
+};
+
+extern void mdb_x86_print_sysregs(struct sysregs *, boolean_t);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MDB_X86UTIL_H */