17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
260a47c91cSRobert Mustacchi /*
2731779036SDoma Gergő Mihály  * Copyright 2019 Doma Gergő Mihály <doma.gergo.mihaly@gmail.com>
289c3024a3SHans Rosenfeld  * Copyright 2018 Joyent, Inc.
29*ed093b41SRobert Mustacchi  * Copyright 2023 Oxide Computer Company
300a47c91cSRobert Mustacchi  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * User Process Target Intel 32-bit component
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * This file provides the ISA-dependent portion of the user process target.
367c478bd9Sstevel@tonic-gate  * For more details on the implementation refer to mdb_proc.c.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <mdb/mdb_proc.h>
407c478bd9Sstevel@tonic-gate #include <mdb/mdb_kreg.h>
417c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h>
429c3024a3SHans Rosenfeld #include <mdb/mdb_isautil.h>
437c478bd9Sstevel@tonic-gate #include <mdb/mdb_ia32util.h>
44*ed093b41SRobert Mustacchi #include <mdb/proc_x86util.h>
457c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
467c478bd9Sstevel@tonic-gate 
478f88a51fSJoshua M. Clulow #include <sys/ucontext.h>
487c478bd9Sstevel@tonic-gate #include <sys/frame.h>
497c478bd9Sstevel@tonic-gate #include <libproc.h>
507c478bd9Sstevel@tonic-gate #include <sys/fp.h>
517c478bd9Sstevel@tonic-gate #include <ieeefp.h>
52*ed093b41SRobert Mustacchi #include <sys/sysmacros.h>
537c478bd9Sstevel@tonic-gate 
548f88a51fSJoshua M. Clulow #include <stddef.h>
558f88a51fSJoshua M. Clulow 
567c478bd9Sstevel@tonic-gate const mdb_tgt_regdesc_t pt_regdesc[] = {
577c478bd9Sstevel@tonic-gate 	{ "gs", GS, MDB_TGT_R_EXPORT },
587c478bd9Sstevel@tonic-gate 	{ "fs", FS, MDB_TGT_R_EXPORT },
597c478bd9Sstevel@tonic-gate 	{ "es", ES, MDB_TGT_R_EXPORT },
607c478bd9Sstevel@tonic-gate 	{ "ds", DS, MDB_TGT_R_EXPORT },
617c478bd9Sstevel@tonic-gate 	{ "edi", EDI, MDB_TGT_R_EXPORT },
620a47c91cSRobert Mustacchi 	{ "di",	EDI, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
637c478bd9Sstevel@tonic-gate 	{ "esi", ESI, MDB_TGT_R_EXPORT },
640a47c91cSRobert Mustacchi 	{ "si", ESI, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
657c478bd9Sstevel@tonic-gate 	{ "ebp", EBP, MDB_TGT_R_EXPORT },
660a47c91cSRobert Mustacchi 	{ "bp", EBP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
677c478bd9Sstevel@tonic-gate 	{ "kesp", ESP, MDB_TGT_R_EXPORT },
680a47c91cSRobert Mustacchi 	{ "ksp", ESP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
697c478bd9Sstevel@tonic-gate 	{ "ebx", EBX, MDB_TGT_R_EXPORT },
700a47c91cSRobert Mustacchi 	{ "bx", EBX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
710a47c91cSRobert Mustacchi 	{ "bh", EBX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
720a47c91cSRobert Mustacchi 	{ "bl", EBX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
737c478bd9Sstevel@tonic-gate 	{ "edx", EDX, MDB_TGT_R_EXPORT },
740a47c91cSRobert Mustacchi 	{ "dx", EDX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
750a47c91cSRobert Mustacchi 	{ "dh", EDX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
760a47c91cSRobert Mustacchi 	{ "dl", EDX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
777c478bd9Sstevel@tonic-gate 	{ "ecx", ECX, MDB_TGT_R_EXPORT },
780a47c91cSRobert Mustacchi 	{ "cx", ECX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
790a47c91cSRobert Mustacchi 	{ "ch", ECX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
800a47c91cSRobert Mustacchi 	{ "cl", ECX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
817c478bd9Sstevel@tonic-gate 	{ "eax", EAX, MDB_TGT_R_EXPORT },
820a47c91cSRobert Mustacchi 	{ "ax", EAX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
830a47c91cSRobert Mustacchi 	{ "ah", EAX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
840a47c91cSRobert Mustacchi 	{ "al", EAX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
857c478bd9Sstevel@tonic-gate 	{ "trapno", TRAPNO, MDB_TGT_R_EXPORT },
867c478bd9Sstevel@tonic-gate 	{ "err", ERR, MDB_TGT_R_EXPORT },
877c478bd9Sstevel@tonic-gate 	{ "eip", EIP, MDB_TGT_R_EXPORT },
887c478bd9Sstevel@tonic-gate 	{ "cs", CS, MDB_TGT_R_EXPORT },
897c478bd9Sstevel@tonic-gate 	{ "eflags", EFL, MDB_TGT_R_EXPORT },
907c478bd9Sstevel@tonic-gate 	{ "esp", UESP, MDB_TGT_R_EXPORT },
910a47c91cSRobert Mustacchi 	{ "sp", UESP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
927c478bd9Sstevel@tonic-gate 	{ "ss", SS, MDB_TGT_R_EXPORT },
937c478bd9Sstevel@tonic-gate 	{ NULL, 0, 0 }
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * We cannot rely on pr_instr, because if we hit a breakpoint or the user has
987c478bd9Sstevel@tonic-gate  * artifically modified memory, it will no longer be correct.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate static uint8_t
pt_read_instr(mdb_tgt_t * t)1017c478bd9Sstevel@tonic-gate pt_read_instr(mdb_tgt_t *t)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
1047c478bd9Sstevel@tonic-gate 	uint8_t ret = 0;
1057c478bd9Sstevel@tonic-gate 
1069c3024a3SHans Rosenfeld 	(void) mdb_tgt_aread(t, MDB_TGT_AS_VIRT_I, &ret, sizeof (ret),
1079c3024a3SHans Rosenfeld 	    psp->pr_reg[EIP]);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	return (ret);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1137c478bd9Sstevel@tonic-gate int
pt_regs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1147c478bd9Sstevel@tonic-gate pt_regs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb.m_target;
1177c478bd9Sstevel@tonic-gate 	mdb_tgt_tid_t tid;
1187c478bd9Sstevel@tonic-gate 	prgregset_t grs;
1197c478bd9Sstevel@tonic-gate 	prgreg_t eflags;
1208f88a51fSJoshua M. Clulow 	boolean_t from_ucontext = B_FALSE;
1217c478bd9Sstevel@tonic-gate 
1228f88a51fSJoshua M. Clulow 	if (mdb_getopts(argc, argv,
1238f88a51fSJoshua M. Clulow 	    'u', MDB_OPT_SETBITS, B_TRUE, &from_ucontext, NULL) != argc) {
1247c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1258f88a51fSJoshua M. Clulow 	}
1268f88a51fSJoshua M. Clulow 
1278f88a51fSJoshua M. Clulow 	if (from_ucontext) {
1288f88a51fSJoshua M. Clulow 		int off;
1298f88a51fSJoshua M. Clulow 		int o0, o1;
1308f88a51fSJoshua M. Clulow 
1318f88a51fSJoshua M. Clulow 		if (!(flags & DCMD_ADDRSPEC)) {
1328f88a51fSJoshua M. Clulow 			mdb_warn("-u requires a ucontext_t address\n");
1338f88a51fSJoshua M. Clulow 			return (DCMD_ERR);
1348f88a51fSJoshua M. Clulow 		}
1358f88a51fSJoshua M. Clulow 
1368f88a51fSJoshua M. Clulow 		o0 = mdb_ctf_offsetof_by_name("ucontext_t", "uc_mcontext");
1378f88a51fSJoshua M. Clulow 		o1 = mdb_ctf_offsetof_by_name("mcontext_t", "gregs");
1388f88a51fSJoshua M. Clulow 		if (o0 == -1 || o1 == -1) {
1398f88a51fSJoshua M. Clulow 			off = offsetof(ucontext_t, uc_mcontext) +
1408f88a51fSJoshua M. Clulow 			    offsetof(mcontext_t, gregs);
1418f88a51fSJoshua M. Clulow 		} else {
1428f88a51fSJoshua M. Clulow 			off = o0 + o1;
1438f88a51fSJoshua M. Clulow 		}
1448f88a51fSJoshua M. Clulow 
1458f88a51fSJoshua M. Clulow 		if (mdb_vread(&grs, sizeof (grs), addr + off) != sizeof (grs)) {
1468f88a51fSJoshua M. Clulow 			mdb_warn("failed to read from ucontext_t %p", addr);
1478f88a51fSJoshua M. Clulow 			return (DCMD_ERR);
1488f88a51fSJoshua M. Clulow 		}
1498f88a51fSJoshua M. Clulow 		goto print_regs;
1508f88a51fSJoshua M. Clulow 	}
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	if (t->t_pshandle == NULL || Pstate(t->t_pshandle) == PS_UNDEAD) {
1537c478bd9Sstevel@tonic-gate 		mdb_warn("no process active\n");
1547c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) == PS_LOST) {
1587c478bd9Sstevel@tonic-gate 		mdb_warn("debugger has lost control of process\n");
1597c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1607c478bd9Sstevel@tonic-gate 	}
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
1637c478bd9Sstevel@tonic-gate 		tid = (mdb_tgt_tid_t)addr;
1647c478bd9Sstevel@tonic-gate 	else
1657c478bd9Sstevel@tonic-gate 		tid = PTL_TID(t);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (PTL_GETREGS(t, tid, grs) != 0) {
1687c478bd9Sstevel@tonic-gate 		mdb_warn("failed to get current register set");
1697c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1707c478bd9Sstevel@tonic-gate 	}
1717c478bd9Sstevel@tonic-gate 
1728f88a51fSJoshua M. Clulow print_regs:
1737c478bd9Sstevel@tonic-gate 	eflags = grs[EFL];
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	mdb_printf("%%cs = 0x%04x\t\t%%eax = 0x%0?p %A\n",
1767c478bd9Sstevel@tonic-gate 	    grs[CS], grs[EAX], grs[EAX]);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	mdb_printf("%%ds = 0x%04x\t\t%%ebx = 0x%0?p %A\n",
1797c478bd9Sstevel@tonic-gate 	    grs[DS], grs[EBX], grs[EBX]);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	mdb_printf("%%ss = 0x%04x\t\t%%ecx = 0x%0?p %A\n",
1827c478bd9Sstevel@tonic-gate 	    grs[SS], grs[ECX], grs[ECX]);
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	mdb_printf("%%es = 0x%04x\t\t%%edx = 0x%0?p %A\n",
1857c478bd9Sstevel@tonic-gate 	    grs[ES], grs[EDX], grs[EDX]);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	mdb_printf("%%fs = 0x%04x\t\t%%esi = 0x%0?p %A\n",
1887c478bd9Sstevel@tonic-gate 	    grs[FS], grs[ESI], grs[ESI]);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	mdb_printf("%%gs = 0x%04x\t\t%%edi = 0x%0?p %A\n\n",
1917c478bd9Sstevel@tonic-gate 	    grs[GS], grs[EDI], grs[EDI]);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	mdb_printf(" %%eip = 0x%0?p %A\n", grs[EIP], grs[EIP]);
1947c478bd9Sstevel@tonic-gate 	mdb_printf(" %%ebp = 0x%0?p\n", grs[EBP]);
1957c478bd9Sstevel@tonic-gate 	mdb_printf("%%kesp = 0x%0?p\n\n", grs[ESP]);
1967c478bd9Sstevel@tonic-gate 	mdb_printf("%%eflags = 0x%08x\n", eflags);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	mdb_printf("  id=%u vip=%u vif=%u ac=%u vm=%u rf=%u nt=%u iopl=0x%x\n",
1997c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_ID_MASK) >> KREG_EFLAGS_ID_SHIFT,
2007c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_VIP_MASK) >> KREG_EFLAGS_VIP_SHIFT,
2017c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_VIF_MASK) >> KREG_EFLAGS_VIF_SHIFT,
2027c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_AC_MASK) >> KREG_EFLAGS_AC_SHIFT,
2037c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_VM_MASK) >> KREG_EFLAGS_VM_SHIFT,
2047c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_RF_MASK) >> KREG_EFLAGS_RF_SHIFT,
2057c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_NT_MASK) >> KREG_EFLAGS_NT_SHIFT,
2067c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_IOPL_MASK) >> KREG_EFLAGS_IOPL_SHIFT);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	mdb_printf("  status=<%s,%s,%s,%s,%s,%s,%s,%s,%s>\n\n",
2097c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_OF_MASK) ? "OF" : "of",
2107c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_DF_MASK) ? "DF" : "df",
2117c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_IF_MASK) ? "IF" : "if",
2127c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_TF_MASK) ? "TF" : "tf",
2137c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_SF_MASK) ? "SF" : "sf",
2147c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_ZF_MASK) ? "ZF" : "zf",
2157c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_AF_MASK) ? "AF" : "af",
2167c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_PF_MASK) ? "PF" : "pf",
2177c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_CF_MASK) ? "CF" : "cf");
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	mdb_printf("   %%esp = 0x%0?x\n", grs[UESP]);
2207c478bd9Sstevel@tonic-gate 	mdb_printf("%%trapno = 0x%x\n", grs[TRAPNO]);
2217c478bd9Sstevel@tonic-gate 	mdb_printf("   %%err = 0x%x\n", grs[ERR]);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate int
pt_fpregs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2277c478bd9Sstevel@tonic-gate pt_fpregs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2287c478bd9Sstevel@tonic-gate {
229*ed093b41SRobert Mustacchi 	int ret;
2307c478bd9Sstevel@tonic-gate 	prfpregset_t fprs;
2317c478bd9Sstevel@tonic-gate 	struct _fpstate fps;
2327c478bd9Sstevel@tonic-gate 	char buf[256];
2337c478bd9Sstevel@tonic-gate 	uint_t top;
234*ed093b41SRobert Mustacchi 	size_t i;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	/*
2377c478bd9Sstevel@tonic-gate 	 * Union for overlaying _fpreg structure on to quad-precision
2387c478bd9Sstevel@tonic-gate 	 * floating-point value (long double).
2397c478bd9Sstevel@tonic-gate 	 */
2407c478bd9Sstevel@tonic-gate 	union {
2417c478bd9Sstevel@tonic-gate 		struct _fpreg reg;
2427c478bd9Sstevel@tonic-gate 		long double ld;
2437c478bd9Sstevel@tonic-gate 	} fpru;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	/*
246*ed093b41SRobert Mustacchi 	 * We use common code between 32-bit and 64-bit x86 to capture and print
247*ed093b41SRobert Mustacchi 	 * the extended vector state. The remaining classic 387 state is
248*ed093b41SRobert Mustacchi 	 * finicky and different enough that it is left to be dealt with on its
249*ed093b41SRobert Mustacchi 	 * own.
2507c478bd9Sstevel@tonic-gate 	 */
251*ed093b41SRobert Mustacchi 	if ((ret = x86_pt_fpregs_common(addr, flags, argc, &fprs)) != DCMD_OK)
252*ed093b41SRobert Mustacchi 		return (ret);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	bcopy(&fprs.fp_reg_set.fpchip_state, &fps, sizeof (fps));
255*ed093b41SRobert Mustacchi 	mdb_printf("387 and FP Control State\n");
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	fps.cw &= 0xffff;	/* control word is really 16 bits */
2587c478bd9Sstevel@tonic-gate 	fps.sw &= 0xffff;	/* status word is really 16 bits */
2597c478bd9Sstevel@tonic-gate 	fps.status &= 0xffff;	/* saved status word is really 16 bits */
2607c478bd9Sstevel@tonic-gate 	fps.cssel &= 0xffff;	/* %cs is really 16-bits */
2617c478bd9Sstevel@tonic-gate 	fps.datasel &= 0xffff;	/* %ds is really 16-bits too */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	mdb_printf("cw     0x%04x (%s)\n", fps.cw,
2647c478bd9Sstevel@tonic-gate 	    fpcw2str(fps.cw, buf, sizeof (buf)));
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	top = (fps.sw & FPS_TOP) >> 11;
2677c478bd9Sstevel@tonic-gate 	mdb_printf("sw     0x%04x (TOP=0t%u) (%s)\n", fps.sw,
2687c478bd9Sstevel@tonic-gate 	    top, fpsw2str(fps.sw, buf, sizeof (buf)));
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	mdb_printf("xcp sw 0x%04x (%s)\n\n", fps.status,
2717c478bd9Sstevel@tonic-gate 	    fpsw2str(fps.status, buf, sizeof (buf)));
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	mdb_printf("ipoff  %a\n", fps.ipoff);
2747c478bd9Sstevel@tonic-gate 	mdb_printf("cssel  0x%x\n", fps.cssel);
2757c478bd9Sstevel@tonic-gate 	mdb_printf("dtoff  %a\n", fps.dataoff);
2767c478bd9Sstevel@tonic-gate 	mdb_printf("dtsel  0x%x\n\n", fps.datasel);
2777c478bd9Sstevel@tonic-gate 
278*ed093b41SRobert Mustacchi 	for (i = 0; i < ARRAY_SIZE(fps._st); i++) {
2797c478bd9Sstevel@tonic-gate 		/*
2807c478bd9Sstevel@tonic-gate 		 * Recall that we need to use the current TOP-of-stack value to
2817c478bd9Sstevel@tonic-gate 		 * associate the _st[] index back to a physical register number,
2827c478bd9Sstevel@tonic-gate 		 * since tag word indices are physical register numbers.  Then
2837c478bd9Sstevel@tonic-gate 		 * to get the tag value, we shift over two bits for each tag
2847c478bd9Sstevel@tonic-gate 		 * index, and then grab the bottom two bits.
2857c478bd9Sstevel@tonic-gate 		 */
2867c478bd9Sstevel@tonic-gate 		uint_t tag_index = (i + top) & 7;
2877c478bd9Sstevel@tonic-gate 		uint_t tag_value = (fps.tag >> (tag_index * 2)) & 3;
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 		fpru.reg = fps._st[i];
2907c478bd9Sstevel@tonic-gate 		mdb_printf("%%st%d   0x%04x.%04x%04x%04x%04x = %lg %s\n",
2917c478bd9Sstevel@tonic-gate 		    i, fpru.reg.exponent,
2927c478bd9Sstevel@tonic-gate 		    fpru.reg.significand[3], fpru.reg.significand[2],
2937c478bd9Sstevel@tonic-gate 		    fpru.reg.significand[1], fpru.reg.significand[0],
294*ed093b41SRobert Mustacchi 		    fpru.ld, fptag2str(tag_value));
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 
297*ed093b41SRobert Mustacchi 	x86_pt_fpregs_sse_ctl(fps.mxcsr, fps.xstatus, buf, sizeof (buf));
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3037c478bd9Sstevel@tonic-gate int
pt_getfpreg(mdb_tgt_t * t,mdb_tgt_tid_t tid,ushort_t rd_num,ushort_t rd_flags,mdb_tgt_reg_t * rp)3047c478bd9Sstevel@tonic-gate pt_getfpreg(mdb_tgt_t *t, mdb_tgt_tid_t tid, ushort_t rd_num,
3057c478bd9Sstevel@tonic-gate     ushort_t rd_flags, mdb_tgt_reg_t *rp)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3117c478bd9Sstevel@tonic-gate int
pt_putfpreg(mdb_tgt_t * t,mdb_tgt_tid_t tid,ushort_t rd_num,ushort_t rd_flags,mdb_tgt_reg_t rval)3127c478bd9Sstevel@tonic-gate pt_putfpreg(mdb_tgt_t *t, mdb_tgt_tid_t tid, ushort_t rd_num,
3137c478bd9Sstevel@tonic-gate     ushort_t rd_flags, mdb_tgt_reg_t rval)
3147c478bd9Sstevel@tonic-gate {
3157c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3197c478bd9Sstevel@tonic-gate void
pt_addfpregs(mdb_tgt_t * t)3207c478bd9Sstevel@tonic-gate pt_addfpregs(mdb_tgt_t *t)
3217c478bd9Sstevel@tonic-gate {
3227c478bd9Sstevel@tonic-gate 	/* not implemented */
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3267c478bd9Sstevel@tonic-gate int
pt_frameregs(void * arglim,uintptr_t pc,uint_t argc,const long * argv,const mdb_tgt_gregset_t * gregs,boolean_t pc_faked)3277c478bd9Sstevel@tonic-gate pt_frameregs(void *arglim, uintptr_t pc, uint_t argc, const long *argv,
3287c478bd9Sstevel@tonic-gate     const mdb_tgt_gregset_t *gregs, boolean_t pc_faked)
3297c478bd9Sstevel@tonic-gate {
3307c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3347c478bd9Sstevel@tonic-gate const char *
pt_disasm(const GElf_Ehdr * ehp)3357c478bd9Sstevel@tonic-gate pt_disasm(const GElf_Ehdr *ehp)
3367c478bd9Sstevel@tonic-gate {
3377c478bd9Sstevel@tonic-gate 	return ("ia32");
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate  * Determine the return address for the current frame.
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate int
pt_step_out(mdb_tgt_t * t,uintptr_t * p)3447c478bd9Sstevel@tonic-gate pt_step_out(mdb_tgt_t *t, uintptr_t *p)
3457c478bd9Sstevel@tonic-gate {
3467c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) != PS_STOP)
3497c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_TGTBUSY));
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	return (mdb_ia32_step_out(t, p, psp->pr_reg[EIP], psp->pr_reg[EBP],
3527c478bd9Sstevel@tonic-gate 	    psp->pr_reg[UESP], pt_read_instr(t)));
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate /*
3567c478bd9Sstevel@tonic-gate  * Return the address of the next instruction following a call, or return -1
3577c478bd9Sstevel@tonic-gate  * and set errno to EAGAIN if the target should just single-step.
3587c478bd9Sstevel@tonic-gate  */
3597c478bd9Sstevel@tonic-gate int
pt_next(mdb_tgt_t * t,uintptr_t * p)3607c478bd9Sstevel@tonic-gate pt_next(mdb_tgt_t *t, uintptr_t *p)
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) != PS_STOP)
3657c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_TGTBUSY));
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	return (mdb_ia32_next(t, p, psp->pr_reg[EIP], pt_read_instr(t)));
3687c478bd9Sstevel@tonic-gate }
369