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>
28*9c3024a3SHans Rosenfeld  * Copyright 2018 Joyent, Inc.
290a47c91cSRobert Mustacchi  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * User Process Target Intel 32-bit component
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * This file provides the ISA-dependent portion of the user process target.
357c478bd9Sstevel@tonic-gate  * For more details on the implementation refer to mdb_proc.c.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <mdb/mdb_proc.h>
397c478bd9Sstevel@tonic-gate #include <mdb/mdb_kreg.h>
407c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h>
41*9c3024a3SHans Rosenfeld #include <mdb/mdb_isautil.h>
427c478bd9Sstevel@tonic-gate #include <mdb/mdb_ia32util.h>
437c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
447c478bd9Sstevel@tonic-gate 
458f88a51fSJoshua M. Clulow #include <sys/ucontext.h>
467c478bd9Sstevel@tonic-gate #include <sys/frame.h>
477c478bd9Sstevel@tonic-gate #include <libproc.h>
487c478bd9Sstevel@tonic-gate #include <sys/fp.h>
497c478bd9Sstevel@tonic-gate #include <ieeefp.h>
507c478bd9Sstevel@tonic-gate 
518f88a51fSJoshua M. Clulow #include <stddef.h>
528f88a51fSJoshua M. Clulow 
537c478bd9Sstevel@tonic-gate const mdb_tgt_regdesc_t pt_regdesc[] = {
547c478bd9Sstevel@tonic-gate 	{ "gs", GS, MDB_TGT_R_EXPORT },
557c478bd9Sstevel@tonic-gate 	{ "fs", FS, MDB_TGT_R_EXPORT },
567c478bd9Sstevel@tonic-gate 	{ "es", ES, MDB_TGT_R_EXPORT },
577c478bd9Sstevel@tonic-gate 	{ "ds", DS, MDB_TGT_R_EXPORT },
587c478bd9Sstevel@tonic-gate 	{ "edi", EDI, MDB_TGT_R_EXPORT },
590a47c91cSRobert Mustacchi 	{ "di",	EDI, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
607c478bd9Sstevel@tonic-gate 	{ "esi", ESI, MDB_TGT_R_EXPORT },
610a47c91cSRobert Mustacchi 	{ "si", ESI, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
627c478bd9Sstevel@tonic-gate 	{ "ebp", EBP, MDB_TGT_R_EXPORT },
630a47c91cSRobert Mustacchi 	{ "bp", EBP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
647c478bd9Sstevel@tonic-gate 	{ "kesp", ESP, MDB_TGT_R_EXPORT },
650a47c91cSRobert Mustacchi 	{ "ksp", ESP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
667c478bd9Sstevel@tonic-gate 	{ "ebx", EBX, MDB_TGT_R_EXPORT },
670a47c91cSRobert Mustacchi 	{ "bx", EBX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
680a47c91cSRobert Mustacchi 	{ "bh", EBX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
690a47c91cSRobert Mustacchi 	{ "bl", EBX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
707c478bd9Sstevel@tonic-gate 	{ "edx", EDX, MDB_TGT_R_EXPORT },
710a47c91cSRobert Mustacchi 	{ "dx", EDX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
720a47c91cSRobert Mustacchi 	{ "dh", EDX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
730a47c91cSRobert Mustacchi 	{ "dl", EDX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
747c478bd9Sstevel@tonic-gate 	{ "ecx", ECX, MDB_TGT_R_EXPORT },
750a47c91cSRobert Mustacchi 	{ "cx", ECX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
760a47c91cSRobert Mustacchi 	{ "ch", ECX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
770a47c91cSRobert Mustacchi 	{ "cl", ECX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
787c478bd9Sstevel@tonic-gate 	{ "eax", EAX, MDB_TGT_R_EXPORT },
790a47c91cSRobert Mustacchi 	{ "ax", EAX, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
800a47c91cSRobert Mustacchi 	{ "ah", EAX, MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
810a47c91cSRobert Mustacchi 	{ "al", EAX, MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
827c478bd9Sstevel@tonic-gate 	{ "trapno", TRAPNO, MDB_TGT_R_EXPORT },
837c478bd9Sstevel@tonic-gate 	{ "err", ERR, MDB_TGT_R_EXPORT },
847c478bd9Sstevel@tonic-gate 	{ "eip", EIP, MDB_TGT_R_EXPORT },
857c478bd9Sstevel@tonic-gate 	{ "cs", CS, MDB_TGT_R_EXPORT },
867c478bd9Sstevel@tonic-gate 	{ "eflags", EFL, MDB_TGT_R_EXPORT },
877c478bd9Sstevel@tonic-gate 	{ "esp", UESP, MDB_TGT_R_EXPORT },
880a47c91cSRobert Mustacchi 	{ "sp", UESP, MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
897c478bd9Sstevel@tonic-gate 	{ "ss", SS, MDB_TGT_R_EXPORT },
907c478bd9Sstevel@tonic-gate 	{ NULL, 0, 0 }
917c478bd9Sstevel@tonic-gate };
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * We cannot rely on pr_instr, because if we hit a breakpoint or the user has
957c478bd9Sstevel@tonic-gate  * artifically modified memory, it will no longer be correct.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate static uint8_t
pt_read_instr(mdb_tgt_t * t)987c478bd9Sstevel@tonic-gate pt_read_instr(mdb_tgt_t *t)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
1017c478bd9Sstevel@tonic-gate 	uint8_t ret = 0;
1027c478bd9Sstevel@tonic-gate 
103*9c3024a3SHans Rosenfeld 	(void) mdb_tgt_aread(t, MDB_TGT_AS_VIRT_I, &ret, sizeof (ret),
104*9c3024a3SHans Rosenfeld 	    psp->pr_reg[EIP]);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	return (ret);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1107c478bd9Sstevel@tonic-gate int
pt_regs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1117c478bd9Sstevel@tonic-gate pt_regs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb.m_target;
1147c478bd9Sstevel@tonic-gate 	mdb_tgt_tid_t tid;
1157c478bd9Sstevel@tonic-gate 	prgregset_t grs;
1167c478bd9Sstevel@tonic-gate 	prgreg_t eflags;
1178f88a51fSJoshua M. Clulow 	boolean_t from_ucontext = B_FALSE;
1187c478bd9Sstevel@tonic-gate 
1198f88a51fSJoshua M. Clulow 	if (mdb_getopts(argc, argv,
1208f88a51fSJoshua M. Clulow 	    'u', MDB_OPT_SETBITS, B_TRUE, &from_ucontext, NULL) != argc) {
1217c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1228f88a51fSJoshua M. Clulow 	}
1238f88a51fSJoshua M. Clulow 
1248f88a51fSJoshua M. Clulow 	if (from_ucontext) {
1258f88a51fSJoshua M. Clulow 		int off;
1268f88a51fSJoshua M. Clulow 		int o0, o1;
1278f88a51fSJoshua M. Clulow 
1288f88a51fSJoshua M. Clulow 		if (!(flags & DCMD_ADDRSPEC)) {
1298f88a51fSJoshua M. Clulow 			mdb_warn("-u requires a ucontext_t address\n");
1308f88a51fSJoshua M. Clulow 			return (DCMD_ERR);
1318f88a51fSJoshua M. Clulow 		}
1328f88a51fSJoshua M. Clulow 
1338f88a51fSJoshua M. Clulow 		o0 = mdb_ctf_offsetof_by_name("ucontext_t", "uc_mcontext");
1348f88a51fSJoshua M. Clulow 		o1 = mdb_ctf_offsetof_by_name("mcontext_t", "gregs");
1358f88a51fSJoshua M. Clulow 		if (o0 == -1 || o1 == -1) {
1368f88a51fSJoshua M. Clulow 			off = offsetof(ucontext_t, uc_mcontext) +
1378f88a51fSJoshua M. Clulow 			    offsetof(mcontext_t, gregs);
1388f88a51fSJoshua M. Clulow 		} else {
1398f88a51fSJoshua M. Clulow 			off = o0 + o1;
1408f88a51fSJoshua M. Clulow 		}
1418f88a51fSJoshua M. Clulow 
1428f88a51fSJoshua M. Clulow 		if (mdb_vread(&grs, sizeof (grs), addr + off) != sizeof (grs)) {
1438f88a51fSJoshua M. Clulow 			mdb_warn("failed to read from ucontext_t %p", addr);
1448f88a51fSJoshua M. Clulow 			return (DCMD_ERR);
1458f88a51fSJoshua M. Clulow 		}
1468f88a51fSJoshua M. Clulow 		goto print_regs;
1478f88a51fSJoshua M. Clulow 	}
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	if (t->t_pshandle == NULL || Pstate(t->t_pshandle) == PS_UNDEAD) {
1507c478bd9Sstevel@tonic-gate 		mdb_warn("no process active\n");
1517c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1527c478bd9Sstevel@tonic-gate 	}
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) == PS_LOST) {
1557c478bd9Sstevel@tonic-gate 		mdb_warn("debugger has lost control of process\n");
1567c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1577c478bd9Sstevel@tonic-gate 	}
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
1607c478bd9Sstevel@tonic-gate 		tid = (mdb_tgt_tid_t)addr;
1617c478bd9Sstevel@tonic-gate 	else
1627c478bd9Sstevel@tonic-gate 		tid = PTL_TID(t);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if (PTL_GETREGS(t, tid, grs) != 0) {
1657c478bd9Sstevel@tonic-gate 		mdb_warn("failed to get current register set");
1667c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1677c478bd9Sstevel@tonic-gate 	}
1687c478bd9Sstevel@tonic-gate 
1698f88a51fSJoshua M. Clulow print_regs:
1707c478bd9Sstevel@tonic-gate 	eflags = grs[EFL];
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	mdb_printf("%%cs = 0x%04x\t\t%%eax = 0x%0?p %A\n",
1737c478bd9Sstevel@tonic-gate 	    grs[CS], grs[EAX], grs[EAX]);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	mdb_printf("%%ds = 0x%04x\t\t%%ebx = 0x%0?p %A\n",
1767c478bd9Sstevel@tonic-gate 	    grs[DS], grs[EBX], grs[EBX]);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	mdb_printf("%%ss = 0x%04x\t\t%%ecx = 0x%0?p %A\n",
1797c478bd9Sstevel@tonic-gate 	    grs[SS], grs[ECX], grs[ECX]);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	mdb_printf("%%es = 0x%04x\t\t%%edx = 0x%0?p %A\n",
1827c478bd9Sstevel@tonic-gate 	    grs[ES], grs[EDX], grs[EDX]);
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	mdb_printf("%%fs = 0x%04x\t\t%%esi = 0x%0?p %A\n",
1857c478bd9Sstevel@tonic-gate 	    grs[FS], grs[ESI], grs[ESI]);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	mdb_printf("%%gs = 0x%04x\t\t%%edi = 0x%0?p %A\n\n",
1887c478bd9Sstevel@tonic-gate 	    grs[GS], grs[EDI], grs[EDI]);
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	mdb_printf(" %%eip = 0x%0?p %A\n", grs[EIP], grs[EIP]);
1917c478bd9Sstevel@tonic-gate 	mdb_printf(" %%ebp = 0x%0?p\n", grs[EBP]);
1927c478bd9Sstevel@tonic-gate 	mdb_printf("%%kesp = 0x%0?p\n\n", grs[ESP]);
1937c478bd9Sstevel@tonic-gate 	mdb_printf("%%eflags = 0x%08x\n", eflags);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	mdb_printf("  id=%u vip=%u vif=%u ac=%u vm=%u rf=%u nt=%u iopl=0x%x\n",
1967c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_ID_MASK) >> KREG_EFLAGS_ID_SHIFT,
1977c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_VIP_MASK) >> KREG_EFLAGS_VIP_SHIFT,
1987c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_VIF_MASK) >> KREG_EFLAGS_VIF_SHIFT,
1997c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_AC_MASK) >> KREG_EFLAGS_AC_SHIFT,
2007c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_VM_MASK) >> KREG_EFLAGS_VM_SHIFT,
2017c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_RF_MASK) >> KREG_EFLAGS_RF_SHIFT,
2027c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_NT_MASK) >> KREG_EFLAGS_NT_SHIFT,
2037c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_IOPL_MASK) >> KREG_EFLAGS_IOPL_SHIFT);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	mdb_printf("  status=<%s,%s,%s,%s,%s,%s,%s,%s,%s>\n\n",
2067c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_OF_MASK) ? "OF" : "of",
2077c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_DF_MASK) ? "DF" : "df",
2087c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_IF_MASK) ? "IF" : "if",
2097c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_TF_MASK) ? "TF" : "tf",
2107c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_SF_MASK) ? "SF" : "sf",
2117c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_ZF_MASK) ? "ZF" : "zf",
2127c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_AF_MASK) ? "AF" : "af",
2137c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_PF_MASK) ? "PF" : "pf",
2147c478bd9Sstevel@tonic-gate 	    (eflags & KREG_EFLAGS_CF_MASK) ? "CF" : "cf");
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	mdb_printf("   %%esp = 0x%0?x\n", grs[UESP]);
2177c478bd9Sstevel@tonic-gate 	mdb_printf("%%trapno = 0x%x\n", grs[TRAPNO]);
2187c478bd9Sstevel@tonic-gate 	mdb_printf("   %%err = 0x%x\n", grs[ERR]);
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate static const char *
fpcw2str(uint32_t cw,char * buf,size_t nbytes)2247c478bd9Sstevel@tonic-gate fpcw2str(uint32_t cw, char *buf, size_t nbytes)
2257c478bd9Sstevel@tonic-gate {
2267c478bd9Sstevel@tonic-gate 	char *end = buf + nbytes;
2277c478bd9Sstevel@tonic-gate 	char *p = buf;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	/*
23231779036SDoma Gergő Mihály 	 * Decode all exception masks in the x87 FPU Control Word.
23331779036SDoma Gergő Mihály 	 *
23431779036SDoma Gergő Mihály 	 * See here:
23531779036SDoma Gergő Mihály 	 * Intel® 64 and IA-32 Architectures Software Developer’s Manual,
23631779036SDoma Gergő Mihály 	 * Volume 1: Basic Architecture, 8.1.5 x87 FPU Control Word
2377c478bd9Sstevel@tonic-gate 	 */
23831779036SDoma Gergő Mihály 	if (cw & FPIM)	/* Invalid operation mask. */
2397c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IM");
24031779036SDoma Gergő Mihály 	if (cw & FPDM)	/* Denormalized operand mask. */
2417c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DM");
24231779036SDoma Gergő Mihály 	if (cw & FPZM)	/* Zero divide mask. */
2437c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZM");
24431779036SDoma Gergő Mihály 	if (cw & FPOM)	/* Overflow mask. */
2457c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OM");
24631779036SDoma Gergő Mihály 	if (cw & FPUM)	/* Underflow mask. */
2477c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UM");
24831779036SDoma Gergő Mihály 	if (cw & FPPM)	/* Precision mask. */
2497c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PM");
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	/*
25231779036SDoma Gergő Mihály 	 * Decode precision control options.
2537c478bd9Sstevel@tonic-gate 	 */
25431779036SDoma Gergő Mihály 	switch (cw & FPPC) {
25531779036SDoma Gergő Mihály 	case FPSIG24:
25631779036SDoma Gergő Mihály 		/* 24-bit significand, single precision. */
25731779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|SIG24");
25831779036SDoma Gergő Mihály 		break;
25931779036SDoma Gergő Mihály 	case FPSIG53:
26031779036SDoma Gergő Mihály 		/* 53-bit significand, double precision. */
2617c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|SIG53");
26231779036SDoma Gergő Mihály 		break;
26331779036SDoma Gergő Mihály 	case FPSIG64:
26431779036SDoma Gergő Mihály 		/* 64-bit significand, double extended precision. */
2657c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|SIG64");
26631779036SDoma Gergő Mihály 		break;
26731779036SDoma Gergő Mihály 	default:
26831779036SDoma Gergő Mihály 		/*
26931779036SDoma Gergő Mihály 		 * Should never happen.
27031779036SDoma Gergő Mihály 		 * Value 0x00000100 is 'Reserved'.
27131779036SDoma Gergő Mihály 		 */
27231779036SDoma Gergő Mihály 		break;
27331779036SDoma Gergő Mihály 	}
2747c478bd9Sstevel@tonic-gate 
27531779036SDoma Gergő Mihály 	/*
27631779036SDoma Gergő Mihály 	 * Decode rounding control options.
27731779036SDoma Gergő Mihály 	 */
27831779036SDoma Gergő Mihály 	switch (cw & FPRC) {
27931779036SDoma Gergő Mihály 	case FPRTN:
28031779036SDoma Gergő Mihály 		/* Round to nearest, or to even if equidistant. */
28131779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|RTN");
28231779036SDoma Gergő Mihály 		break;
28331779036SDoma Gergő Mihály 	case FPRD:
28431779036SDoma Gergő Mihály 		/* Round down. */
2857c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RD");
28631779036SDoma Gergő Mihály 		break;
28731779036SDoma Gergő Mihály 	case FPRU:
28831779036SDoma Gergő Mihály 		/* Round up. */
2897c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RU");
29031779036SDoma Gergő Mihály 		break;
29131779036SDoma Gergő Mihály 	case FPCHOP:
29231779036SDoma Gergő Mihály 		/* Truncate. */
29331779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|RTZ");
29431779036SDoma Gergő Mihály 		break;
29531779036SDoma Gergő Mihály 	default:
29631779036SDoma Gergő Mihály 		/*
29731779036SDoma Gergő Mihály 		 * This is a two-bit field.
29831779036SDoma Gergő Mihály 		 * No other options left.
29931779036SDoma Gergő Mihály 		 */
30031779036SDoma Gergő Mihály 		break;
30131779036SDoma Gergő Mihály 	}
3027c478bd9Sstevel@tonic-gate 
30331779036SDoma Gergő Mihály 	/*
30431779036SDoma Gergő Mihály 	 * Decode infinity control options.
30531779036SDoma Gergő Mihály 	 *
30631779036SDoma Gergő Mihály 	 * This field has been retained for compatibility with
30731779036SDoma Gergő Mihály 	 * the 287 and earlier co-processors.
30831779036SDoma Gergő Mihály 	 * In the more modern FPUs, this bit is disregarded and
30931779036SDoma Gergő Mihály 	 * both -infinity and +infinity are respected.
31031779036SDoma Gergő Mihály 	 * Comment source: SIMPLY FPU by Raymond Filiatreault
31131779036SDoma Gergő Mihály 	 */
31231779036SDoma Gergő Mihály 	switch (cw & FPIC) {
31331779036SDoma Gergő Mihály 	case FPP:
31431779036SDoma Gergő Mihály 		/*
31531779036SDoma Gergő Mihály 		 * Projective infinity.
31631779036SDoma Gergő Mihály 		 * Both -infinity and +infinity are treated as
31731779036SDoma Gergő Mihály 		 * unsigned infinity.
31831779036SDoma Gergő Mihály 		 */
3197c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|P");
32031779036SDoma Gergő Mihály 		break;
32131779036SDoma Gergő Mihály 	case FPA:
32231779036SDoma Gergő Mihály 		/*
32331779036SDoma Gergő Mihály 		 * Affine infinity.
32431779036SDoma Gergő Mihály 		 * Respects both -infinity and +infinity.
32531779036SDoma Gergő Mihály 		 */
32631779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|A");
32731779036SDoma Gergő Mihály 		break;
32831779036SDoma Gergő Mihály 	default:
32931779036SDoma Gergő Mihály 		/*
33031779036SDoma Gergő Mihály 		 * This is a one-bit field.
33131779036SDoma Gergő Mihály 		 * No other options left.
33231779036SDoma Gergő Mihály 		 */
33331779036SDoma Gergő Mihály 		break;
33431779036SDoma Gergő Mihály 	}
33531779036SDoma Gergő Mihály 
3367c478bd9Sstevel@tonic-gate 	if (cw & WFPB17)
3377c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|WFPB17");
3387c478bd9Sstevel@tonic-gate 	if (cw & WFPB24)
3397c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|WFPB24");
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	if (buf[0] == '|')
3427c478bd9Sstevel@tonic-gate 		return (buf + 1);
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	return ("0");
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate static const char *
fpsw2str(uint32_t cw,char * buf,size_t nbytes)3487c478bd9Sstevel@tonic-gate fpsw2str(uint32_t cw, char *buf, size_t nbytes)
3497c478bd9Sstevel@tonic-gate {
3507c478bd9Sstevel@tonic-gate 	char *end = buf + nbytes;
3517c478bd9Sstevel@tonic-gate 	char *p = buf;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	/*
3567c478bd9Sstevel@tonic-gate 	 * Decode all masks in the 80387 status word.
3577c478bd9Sstevel@tonic-gate 	 */
3587c478bd9Sstevel@tonic-gate 	if (cw & FPS_IE)
3597c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IE");
3607c478bd9Sstevel@tonic-gate 	if (cw & FPS_DE)
3617c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DE");
3627c478bd9Sstevel@tonic-gate 	if (cw & FPS_ZE)
3637c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZE");
3647c478bd9Sstevel@tonic-gate 	if (cw & FPS_OE)
3657c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OE");
3667c478bd9Sstevel@tonic-gate 	if (cw & FPS_UE)
3677c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UE");
3687c478bd9Sstevel@tonic-gate 	if (cw & FPS_PE)
3697c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PE");
3707c478bd9Sstevel@tonic-gate 	if (cw & FPS_SF)
3717c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|SF");
3727c478bd9Sstevel@tonic-gate 	if (cw & FPS_ES)
3737c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ES");
3747c478bd9Sstevel@tonic-gate 	if (cw & FPS_C0)
3757c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C0");
3767c478bd9Sstevel@tonic-gate 	if (cw & FPS_C1)
3777c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C1");
3787c478bd9Sstevel@tonic-gate 	if (cw & FPS_C2)
3797c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C2");
3807c478bd9Sstevel@tonic-gate 	if (cw & FPS_C3)
3817c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C3");
3827c478bd9Sstevel@tonic-gate 	if (cw & FPS_B)
3837c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|B");
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	if (buf[0] == '|')
3867c478bd9Sstevel@tonic-gate 		return (buf + 1);
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	return ("0");
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate static const char *
fpmxcsr2str(uint32_t mxcsr,char * buf,size_t nbytes)3927c478bd9Sstevel@tonic-gate fpmxcsr2str(uint32_t mxcsr, char *buf, size_t nbytes)
3937c478bd9Sstevel@tonic-gate {
3947c478bd9Sstevel@tonic-gate 	char *end = buf + nbytes;
3957c478bd9Sstevel@tonic-gate 	char *p = buf;
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	/*
4007c478bd9Sstevel@tonic-gate 	 * Decode the MXCSR word
4017c478bd9Sstevel@tonic-gate 	 */
4027c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_IE)
4037c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IE");
4047c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_DE)
4057c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DE");
4067c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_ZE)
4077c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZE");
4087c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_OE)
4097c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OE");
4107c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_UE)
4117c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UE");
4127c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_PE)
4137c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PE");
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_DAZ)
4167c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DAZ");
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_IM)
4197c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IM");
4207c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_DM)
4217c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DM");
4227c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_ZM)
4237c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZM");
4247c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_OM)
4257c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OM");
4267c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_UM)
4277c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UM");
4287c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_PM)
4297c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PM");
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	if ((mxcsr & SSE_RC) == (SSE_RD|SSE_RU))
4327c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RTZ");
4337c478bd9Sstevel@tonic-gate 	else if (mxcsr & SSE_RD)
4347c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RD");
4357c478bd9Sstevel@tonic-gate 	else if (mxcsr & SSE_RU)
4367c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RU");
4377c478bd9Sstevel@tonic-gate 	else
4387c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RTN");
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_FZ)
4417c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|FZ");
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	if (buf[0] == '|')
4447c478bd9Sstevel@tonic-gate 		return (buf + 1);
4457c478bd9Sstevel@tonic-gate 	return ("0");
4467c478bd9Sstevel@tonic-gate }
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4497c478bd9Sstevel@tonic-gate int
pt_fpregs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4507c478bd9Sstevel@tonic-gate pt_fpregs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4517c478bd9Sstevel@tonic-gate {
4527c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb.m_target;
4537c478bd9Sstevel@tonic-gate 	mdb_tgt_tid_t tid;
4547c478bd9Sstevel@tonic-gate 	uint32_t hw = FP_NO;
4557c478bd9Sstevel@tonic-gate 	uint_t sse = 0;
4567c478bd9Sstevel@tonic-gate 	prfpregset_t fprs;
4577c478bd9Sstevel@tonic-gate 	struct _fpstate fps;
4587c478bd9Sstevel@tonic-gate 	char buf[256];
4597c478bd9Sstevel@tonic-gate 	uint_t top;
4607c478bd9Sstevel@tonic-gate 	int i;
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	/*
4637c478bd9Sstevel@tonic-gate 	 * Union for overlaying _fpreg structure on to quad-precision
4647c478bd9Sstevel@tonic-gate 	 * floating-point value (long double).
4657c478bd9Sstevel@tonic-gate 	 */
4667c478bd9Sstevel@tonic-gate 	union {
4677c478bd9Sstevel@tonic-gate 		struct _fpreg reg;
4687c478bd9Sstevel@tonic-gate 		long double ld;
4697c478bd9Sstevel@tonic-gate 	} fpru;
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	/*
4727c478bd9Sstevel@tonic-gate 	 * Array of strings corresponding to FPU tag word values (see
4737c478bd9Sstevel@tonic-gate 	 * section 7.3.6 of the Intel Programmer's Reference Manual).
4747c478bd9Sstevel@tonic-gate 	 */
4757c478bd9Sstevel@tonic-gate 	const char *tag_strings[] = { "valid", "zero", "special", "empty" };
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	if (argc != 0)
4787c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	if (t->t_pshandle == NULL || Pstate(t->t_pshandle) == PS_UNDEAD) {
4817c478bd9Sstevel@tonic-gate 		mdb_warn("no process active\n");
4827c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4837c478bd9Sstevel@tonic-gate 	}
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) == PS_LOST) {
4867c478bd9Sstevel@tonic-gate 		mdb_warn("debugger has lost control of process\n");
4877c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4887c478bd9Sstevel@tonic-gate 	}
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
4917c478bd9Sstevel@tonic-gate 		tid = (mdb_tgt_tid_t)addr;
4927c478bd9Sstevel@tonic-gate 	else
4937c478bd9Sstevel@tonic-gate 		tid = PTL_TID(t);
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 	if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &hw,
4967c478bd9Sstevel@tonic-gate 	    sizeof (hw), "libc.so", "_fp_hw") < 0 &&
4977c478bd9Sstevel@tonic-gate 	    mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &hw,
4987c478bd9Sstevel@tonic-gate 	    sizeof (hw), MDB_TGT_OBJ_EXEC, "_fp_hw") < 0)
4997c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read _fp_hw value");
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &sse,
5027c478bd9Sstevel@tonic-gate 	    sizeof (sse), "libc.so", "_sse_hw") < 0 &&
5037c478bd9Sstevel@tonic-gate 	    mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &sse,
5047c478bd9Sstevel@tonic-gate 	    sizeof (sse), MDB_TGT_OBJ_EXEC, "_sse_hw") < 0)
5057c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read _sse_hw value");
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	mdb_printf("_fp_hw 0x%02x (", hw);
5087c478bd9Sstevel@tonic-gate 	switch (hw) {
5097c478bd9Sstevel@tonic-gate 	case FP_SW:
5107c478bd9Sstevel@tonic-gate 		mdb_printf("80387 software emulator");
5117c478bd9Sstevel@tonic-gate 		break;
5127c478bd9Sstevel@tonic-gate 	case FP_287:
5137c478bd9Sstevel@tonic-gate 		mdb_printf("80287 chip");
5147c478bd9Sstevel@tonic-gate 		break;
5157c478bd9Sstevel@tonic-gate 	case FP_387:
5167c478bd9Sstevel@tonic-gate 		mdb_printf("80387 chip");
5177c478bd9Sstevel@tonic-gate 		break;
5187c478bd9Sstevel@tonic-gate 	case FP_486:
5197c478bd9Sstevel@tonic-gate 		mdb_printf("80486 chip");
5207c478bd9Sstevel@tonic-gate 		break;
5217c478bd9Sstevel@tonic-gate 	default:
5227c478bd9Sstevel@tonic-gate 		mdb_printf("no floating point support");
5237c478bd9Sstevel@tonic-gate 		break;
5247c478bd9Sstevel@tonic-gate 	}
5257c478bd9Sstevel@tonic-gate 	if (sse)
5267c478bd9Sstevel@tonic-gate 		mdb_printf(" with SSE");
5277c478bd9Sstevel@tonic-gate 	mdb_printf(")\n");
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	if (!(hw & FP_HW))
5307c478bd9Sstevel@tonic-gate 		return (DCMD_OK); /* just abort if no hardware present */
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	if (PTL_GETFPREGS(t, tid, &fprs) != 0) {
5337c478bd9Sstevel@tonic-gate 		mdb_warn("failed to get floating point registers");
5347c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5357c478bd9Sstevel@tonic-gate 	}
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	bcopy(&fprs.fp_reg_set.fpchip_state, &fps, sizeof (fps));
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	fps.cw &= 0xffff;	/* control word is really 16 bits */
5407c478bd9Sstevel@tonic-gate 	fps.sw &= 0xffff;	/* status word is really 16 bits */
5417c478bd9Sstevel@tonic-gate 	fps.status &= 0xffff;	/* saved status word is really 16 bits */
5427c478bd9Sstevel@tonic-gate 	fps.cssel &= 0xffff;	/* %cs is really 16-bits */
5437c478bd9Sstevel@tonic-gate 	fps.datasel &= 0xffff;	/* %ds is really 16-bits too */
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	mdb_printf("cw     0x%04x (%s)\n", fps.cw,
5467c478bd9Sstevel@tonic-gate 	    fpcw2str(fps.cw, buf, sizeof (buf)));
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	top = (fps.sw & FPS_TOP) >> 11;
5497c478bd9Sstevel@tonic-gate 	mdb_printf("sw     0x%04x (TOP=0t%u) (%s)\n", fps.sw,
5507c478bd9Sstevel@tonic-gate 	    top, fpsw2str(fps.sw, buf, sizeof (buf)));
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	mdb_printf("xcp sw 0x%04x (%s)\n\n", fps.status,
5537c478bd9Sstevel@tonic-gate 	    fpsw2str(fps.status, buf, sizeof (buf)));
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	mdb_printf("ipoff  %a\n", fps.ipoff);
5567c478bd9Sstevel@tonic-gate 	mdb_printf("cssel  0x%x\n", fps.cssel);
5577c478bd9Sstevel@tonic-gate 	mdb_printf("dtoff  %a\n", fps.dataoff);
5587c478bd9Sstevel@tonic-gate 	mdb_printf("dtsel  0x%x\n\n", fps.datasel);
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
5617c478bd9Sstevel@tonic-gate 		/*
5627c478bd9Sstevel@tonic-gate 		 * Recall that we need to use the current TOP-of-stack value to
5637c478bd9Sstevel@tonic-gate 		 * associate the _st[] index back to a physical register number,
5647c478bd9Sstevel@tonic-gate 		 * since tag word indices are physical register numbers.  Then
5657c478bd9Sstevel@tonic-gate 		 * to get the tag value, we shift over two bits for each tag
5667c478bd9Sstevel@tonic-gate 		 * index, and then grab the bottom two bits.
5677c478bd9Sstevel@tonic-gate 		 */
5687c478bd9Sstevel@tonic-gate 		uint_t tag_index = (i + top) & 7;
5697c478bd9Sstevel@tonic-gate 		uint_t tag_value = (fps.tag >> (tag_index * 2)) & 3;
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 		fpru.reg = fps._st[i];
5727c478bd9Sstevel@tonic-gate 		mdb_printf("%%st%d   0x%04x.%04x%04x%04x%04x = %lg %s\n",
5737c478bd9Sstevel@tonic-gate 		    i, fpru.reg.exponent,
5747c478bd9Sstevel@tonic-gate 		    fpru.reg.significand[3], fpru.reg.significand[2],
5757c478bd9Sstevel@tonic-gate 		    fpru.reg.significand[1], fpru.reg.significand[0],
5767c478bd9Sstevel@tonic-gate 		    fpru.ld, tag_strings[tag_value]);
5777c478bd9Sstevel@tonic-gate 	}
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 	if (!sse)
5807c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	mdb_printf("\nmxcsr  0x%04x (%s)\n", fps.mxcsr,
5837c478bd9Sstevel@tonic-gate 	    fpmxcsr2str(fps.mxcsr, buf, sizeof (buf)));
5847c478bd9Sstevel@tonic-gate 	mdb_printf("xcp    0x%04x (%s)\n\n", fps.xstatus,
5857c478bd9Sstevel@tonic-gate 	    fpmxcsr2str(fps.xstatus, buf, sizeof (buf)));
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++)
5887c478bd9Sstevel@tonic-gate 		mdb_printf("%%xmm%d  0x%08x%08x%08x%08x\n", i,
5897c478bd9Sstevel@tonic-gate 		    fps.xmm[i][3], fps.xmm[i][2],
5907c478bd9Sstevel@tonic-gate 		    fps.xmm[i][1], fps.xmm[i][0]);
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5967c478bd9Sstevel@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)5977c478bd9Sstevel@tonic-gate pt_getfpreg(mdb_tgt_t *t, mdb_tgt_tid_t tid, ushort_t rd_num,
5987c478bd9Sstevel@tonic-gate     ushort_t rd_flags, mdb_tgt_reg_t *rp)
5997c478bd9Sstevel@tonic-gate {
6007c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6047c478bd9Sstevel@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)6057c478bd9Sstevel@tonic-gate pt_putfpreg(mdb_tgt_t *t, mdb_tgt_tid_t tid, ushort_t rd_num,
6067c478bd9Sstevel@tonic-gate     ushort_t rd_flags, mdb_tgt_reg_t rval)
6077c478bd9Sstevel@tonic-gate {
6087c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6127c478bd9Sstevel@tonic-gate void
pt_addfpregs(mdb_tgt_t * t)6137c478bd9Sstevel@tonic-gate pt_addfpregs(mdb_tgt_t *t)
6147c478bd9Sstevel@tonic-gate {
6157c478bd9Sstevel@tonic-gate 	/* not implemented */
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6197c478bd9Sstevel@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)6207c478bd9Sstevel@tonic-gate pt_frameregs(void *arglim, uintptr_t pc, uint_t argc, const long *argv,
6217c478bd9Sstevel@tonic-gate     const mdb_tgt_gregset_t *gregs, boolean_t pc_faked)
6227c478bd9Sstevel@tonic-gate {
6237c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6277c478bd9Sstevel@tonic-gate const char *
pt_disasm(const GElf_Ehdr * ehp)6287c478bd9Sstevel@tonic-gate pt_disasm(const GElf_Ehdr *ehp)
6297c478bd9Sstevel@tonic-gate {
6307c478bd9Sstevel@tonic-gate 	return ("ia32");
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate /*
6347c478bd9Sstevel@tonic-gate  * Determine the return address for the current frame.
6357c478bd9Sstevel@tonic-gate  */
6367c478bd9Sstevel@tonic-gate int
pt_step_out(mdb_tgt_t * t,uintptr_t * p)6377c478bd9Sstevel@tonic-gate pt_step_out(mdb_tgt_t *t, uintptr_t *p)
6387c478bd9Sstevel@tonic-gate {
6397c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) != PS_STOP)
6427c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_TGTBUSY));
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	return (mdb_ia32_step_out(t, p, psp->pr_reg[EIP], psp->pr_reg[EBP],
6457c478bd9Sstevel@tonic-gate 	    psp->pr_reg[UESP], pt_read_instr(t)));
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate  * Return the address of the next instruction following a call, or return -1
6507c478bd9Sstevel@tonic-gate  * and set errno to EAGAIN if the target should just single-step.
6517c478bd9Sstevel@tonic-gate  */
6527c478bd9Sstevel@tonic-gate int
pt_next(mdb_tgt_t * t,uintptr_t * p)6537c478bd9Sstevel@tonic-gate pt_next(mdb_tgt_t *t, uintptr_t *p)
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) != PS_STOP)
6587c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_TGTBUSY));
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	return (mdb_ia32_next(t, p, psp->pr_reg[EIP], pt_read_instr(t)));
6617c478bd9Sstevel@tonic-gate }
662