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 /*
27161294feSRobert Mustacchi  * Copyright (c) 2018, Joyent, Inc.
2831779036SDoma Gergő Mihály  * Copyright 2019 Doma Gergő Mihály <doma.gergo.mihaly@gmail.com>
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_amd64util.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 	{ "r15",	REG_R15,	MDB_TGT_R_EXPORT },
550a47c91cSRobert Mustacchi 	{ "r15d",	REG_R15,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
560a47c91cSRobert Mustacchi 	{ "r15w",	REG_R15,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
570a47c91cSRobert Mustacchi 	{ "r15l",	REG_R15,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
587c478bd9Sstevel@tonic-gate 	{ "r14",	REG_R14,	MDB_TGT_R_EXPORT },
590a47c91cSRobert Mustacchi 	{ "r14d",	REG_R14,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
600a47c91cSRobert Mustacchi 	{ "r14w",	REG_R14,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
610a47c91cSRobert Mustacchi 	{ "r14l",	REG_R14,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
627c478bd9Sstevel@tonic-gate 	{ "r13",	REG_R13,	MDB_TGT_R_EXPORT },
630a47c91cSRobert Mustacchi 	{ "r13d",	REG_R13,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
640a47c91cSRobert Mustacchi 	{ "r13w",	REG_R13,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
650a47c91cSRobert Mustacchi 	{ "r13l",	REG_R13,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
667c478bd9Sstevel@tonic-gate 	{ "r12",	REG_R12,	MDB_TGT_R_EXPORT },
670a47c91cSRobert Mustacchi 	{ "r12d",	REG_R12,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
680a47c91cSRobert Mustacchi 	{ "r12w",	REG_R12,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
690a47c91cSRobert Mustacchi 	{ "r12l",	REG_R12,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
707c478bd9Sstevel@tonic-gate 	{ "r11",	REG_R11,	MDB_TGT_R_EXPORT },
710a47c91cSRobert Mustacchi 	{ "r11d",	REG_R11,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
720a47c91cSRobert Mustacchi 	{ "r11w",	REG_R11,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
730a47c91cSRobert Mustacchi 	{ "r11l",	REG_R11,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
747c478bd9Sstevel@tonic-gate 	{ "r10",	REG_R10,	MDB_TGT_R_EXPORT },
750a47c91cSRobert Mustacchi 	{ "r10d",	REG_R10,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
760a47c91cSRobert Mustacchi 	{ "r10w",	REG_R10,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
770a47c91cSRobert Mustacchi 	{ "r10l",	REG_R10,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
787c478bd9Sstevel@tonic-gate 	{ "r9",		REG_R9,		MDB_TGT_R_EXPORT },
79161294feSRobert Mustacchi 	{ "r9d",	REG_R9,		MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
80161294feSRobert Mustacchi 	{ "r9w",	REG_R9,		MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
81161294feSRobert Mustacchi 	{ "r9l",	REG_R9,		MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
827c478bd9Sstevel@tonic-gate 	{ "r8",		REG_R8,		MDB_TGT_R_EXPORT },
830a47c91cSRobert Mustacchi 	{ "r8d",	REG_R8,		MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
840a47c91cSRobert Mustacchi 	{ "r8w",	REG_R8,		MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
850a47c91cSRobert Mustacchi 	{ "r8l",	REG_R8,		MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
867c478bd9Sstevel@tonic-gate 	{ "rdi",	REG_RDI,	MDB_TGT_R_EXPORT },
870a47c91cSRobert Mustacchi 	{ "edi",	REG_RDI,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
880a47c91cSRobert Mustacchi 	{ "di",		REG_RDI,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
890a47c91cSRobert Mustacchi 	{ "dil",	REG_RDI,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
907c478bd9Sstevel@tonic-gate 	{ "rsi",	REG_RSI,	MDB_TGT_R_EXPORT },
910a47c91cSRobert Mustacchi 	{ "esi",	REG_RSI,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
920a47c91cSRobert Mustacchi 	{ "si",		REG_RSI,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
930a47c91cSRobert Mustacchi 	{ "sil",	REG_RSI,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
947c478bd9Sstevel@tonic-gate 	{ "rbp",	REG_RBP,	MDB_TGT_R_EXPORT },
950a47c91cSRobert Mustacchi 	{ "ebp",	REG_RBP,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
960a47c91cSRobert Mustacchi 	{ "bp",		REG_RBP,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
970a47c91cSRobert Mustacchi 	{ "bpl",	REG_RBP,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
987c478bd9Sstevel@tonic-gate 	{ "rbx",	REG_RBX,	MDB_TGT_R_EXPORT },
990a47c91cSRobert Mustacchi 	{ "ebx",	REG_RBX,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
1000a47c91cSRobert Mustacchi 	{ "bx",		REG_RBX,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
1010a47c91cSRobert Mustacchi 	{ "bh",		REG_RBX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
1020a47c91cSRobert Mustacchi 	{ "bl",		REG_RBX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
1037c478bd9Sstevel@tonic-gate 	{ "rdx",	REG_RDX,	MDB_TGT_R_EXPORT },
1040a47c91cSRobert Mustacchi 	{ "edx",	REG_RDX,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
1050a47c91cSRobert Mustacchi 	{ "dx",		REG_RDX,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
1060a47c91cSRobert Mustacchi 	{ "dh",		REG_RDX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
1070a47c91cSRobert Mustacchi 	{ "dl",		REG_RDX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
1087c478bd9Sstevel@tonic-gate 	{ "rcx",	REG_RCX,	MDB_TGT_R_EXPORT },
1090a47c91cSRobert Mustacchi 	{ "ecx",	REG_RCX,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
1100a47c91cSRobert Mustacchi 	{ "cx",		REG_RCX,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
1110a47c91cSRobert Mustacchi 	{ "ch",		REG_RCX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
1120a47c91cSRobert Mustacchi 	{ "cl",		REG_RCX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
1137c478bd9Sstevel@tonic-gate 	{ "rax",	REG_RAX,	MDB_TGT_R_EXPORT },
1140a47c91cSRobert Mustacchi 	{ "eax",	REG_RAX,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
1150a47c91cSRobert Mustacchi 	{ "ax",		REG_RAX,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
1160a47c91cSRobert Mustacchi 	{ "ah",		REG_RAX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8H },
1170a47c91cSRobert Mustacchi 	{ "al",		REG_RAX,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
1187c478bd9Sstevel@tonic-gate 	{ "trapno",	REG_TRAPNO,	MDB_TGT_R_EXPORT },
1197c478bd9Sstevel@tonic-gate 	{ "err",	REG_ERR,	MDB_TGT_R_EXPORT },
1207c478bd9Sstevel@tonic-gate 	{ "rip",	REG_RIP,	MDB_TGT_R_EXPORT },
1217c478bd9Sstevel@tonic-gate 	{ "cs",		REG_CS,		MDB_TGT_R_EXPORT },
1227c478bd9Sstevel@tonic-gate 	{ "rflags",	REG_RFL,	MDB_TGT_R_EXPORT },
1230a47c91cSRobert Mustacchi 	{ "eflags",	REG_RFL,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
1247c478bd9Sstevel@tonic-gate 	{ "rsp",	REG_RSP,	MDB_TGT_R_EXPORT },
1250a47c91cSRobert Mustacchi 	{ "esp",	REG_RSP,	MDB_TGT_R_EXPORT | MDB_TGT_R_32 },
1260a47c91cSRobert Mustacchi 	{ "sp",		REG_RSP,	MDB_TGT_R_EXPORT | MDB_TGT_R_16 },
1270a47c91cSRobert Mustacchi 	{ "spl",	REG_RSP,	MDB_TGT_R_EXPORT | MDB_TGT_R_8L },
1287c478bd9Sstevel@tonic-gate 	{ "ss",		REG_SS,		MDB_TGT_R_EXPORT },
1297c478bd9Sstevel@tonic-gate 	{ "fs",		REG_FS,		MDB_TGT_R_EXPORT },
1307c478bd9Sstevel@tonic-gate 	{ "gs",		REG_GS,		MDB_TGT_R_EXPORT },
1317c478bd9Sstevel@tonic-gate 	{ "es",		REG_ES,		MDB_TGT_R_EXPORT },
1327c478bd9Sstevel@tonic-gate 	{ "ds",		REG_DS,		MDB_TGT_R_EXPORT },
1337c478bd9Sstevel@tonic-gate 	{ "fsbase",	REG_FSBASE,	MDB_TGT_R_EXPORT },
1347c478bd9Sstevel@tonic-gate 	{ "gsbase",	REG_GSBASE,	MDB_TGT_R_EXPORT },
1357c478bd9Sstevel@tonic-gate 	{ NULL, 0, 0 }
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * We cannot rely on pr_instr, because if we hit a breakpoint or the user has
1407c478bd9Sstevel@tonic-gate  * artifically modified memory, it will no longer be correct.
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate static uint8_t
pt_read_instr(mdb_tgt_t * t)1437c478bd9Sstevel@tonic-gate pt_read_instr(mdb_tgt_t *t)
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
1467c478bd9Sstevel@tonic-gate 	uint8_t ret = 0;
1477c478bd9Sstevel@tonic-gate 
148*9c3024a3SHans Rosenfeld 	(void) mdb_tgt_aread(t, MDB_TGT_AS_VIRT_I, &ret, sizeof (ret),
149*9c3024a3SHans Rosenfeld 	    psp->pr_reg[REG_RIP]);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	return (ret);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1557c478bd9Sstevel@tonic-gate int
pt_regs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1567c478bd9Sstevel@tonic-gate pt_regs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb.m_target;
1597c478bd9Sstevel@tonic-gate 	mdb_tgt_tid_t tid;
1607c478bd9Sstevel@tonic-gate 	prgregset_t grs;
1617c478bd9Sstevel@tonic-gate 	prgreg_t rflags;
1628f88a51fSJoshua M. Clulow 	boolean_t from_ucontext = B_FALSE;
1637c478bd9Sstevel@tonic-gate 
1648f88a51fSJoshua M. Clulow 	if (mdb_getopts(argc, argv,
1658f88a51fSJoshua M. Clulow 	    'u', MDB_OPT_SETBITS, B_TRUE, &from_ucontext, NULL) != argc) {
1667c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1678f88a51fSJoshua M. Clulow 	}
1688f88a51fSJoshua M. Clulow 
1698f88a51fSJoshua M. Clulow 	if (from_ucontext) {
1708f88a51fSJoshua M. Clulow 		int off;
1718f88a51fSJoshua M. Clulow 		int o0, o1;
1728f88a51fSJoshua M. Clulow 
1738f88a51fSJoshua M. Clulow 		if (!(flags & DCMD_ADDRSPEC)) {
1748f88a51fSJoshua M. Clulow 			mdb_warn("-u requires a ucontext_t address\n");
1758f88a51fSJoshua M. Clulow 			return (DCMD_ERR);
1768f88a51fSJoshua M. Clulow 		}
1778f88a51fSJoshua M. Clulow 
1788f88a51fSJoshua M. Clulow 		o0 = mdb_ctf_offsetof_by_name("ucontext_t", "uc_mcontext");
1798f88a51fSJoshua M. Clulow 		o1 = mdb_ctf_offsetof_by_name("mcontext_t", "gregs");
1808f88a51fSJoshua M. Clulow 		if (o0 == -1 || o1 == -1) {
1818f88a51fSJoshua M. Clulow 			off = offsetof(ucontext_t, uc_mcontext) +
1828f88a51fSJoshua M. Clulow 			    offsetof(mcontext_t, gregs);
1838f88a51fSJoshua M. Clulow 		} else {
1848f88a51fSJoshua M. Clulow 			off = o0 + o1;
1858f88a51fSJoshua M. Clulow 		}
1868f88a51fSJoshua M. Clulow 
1878f88a51fSJoshua M. Clulow 		if (mdb_vread(&grs, sizeof (grs), addr + off) != sizeof (grs)) {
1888f88a51fSJoshua M. Clulow 			mdb_warn("failed to read from ucontext_t %p", addr);
1898f88a51fSJoshua M. Clulow 			return (DCMD_ERR);
1908f88a51fSJoshua M. Clulow 		}
1918f88a51fSJoshua M. Clulow 		goto print_regs;
1928f88a51fSJoshua M. Clulow 	}
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	if (t->t_pshandle == NULL || Pstate(t->t_pshandle) == PS_UNDEAD) {
1957c478bd9Sstevel@tonic-gate 		mdb_warn("no process active\n");
1967c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) == PS_LOST) {
2007c478bd9Sstevel@tonic-gate 		mdb_warn("debugger has lost control of process\n");
2017c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2027c478bd9Sstevel@tonic-gate 	}
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
2057c478bd9Sstevel@tonic-gate 		tid = (mdb_tgt_tid_t)addr;
2067c478bd9Sstevel@tonic-gate 	else
2077c478bd9Sstevel@tonic-gate 		tid = PTL_TID(t);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	if (PTL_GETREGS(t, tid, grs) != 0) {
2107c478bd9Sstevel@tonic-gate 		mdb_warn("failed to get current register set");
2117c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate 
2148f88a51fSJoshua M. Clulow print_regs:
2157c478bd9Sstevel@tonic-gate 	rflags = grs[REG_RFL];
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	mdb_printf("%%rax = 0x%0?p\t%%r8  = 0x%0?p\n",
2187c478bd9Sstevel@tonic-gate 	    grs[REG_RAX], grs[REG_R8]);
2197c478bd9Sstevel@tonic-gate 	mdb_printf("%%rbx = 0x%0?p\t%%r9  = 0x%0?p\n",
2207c478bd9Sstevel@tonic-gate 	    grs[REG_RBX], grs[REG_R9]);
2217c478bd9Sstevel@tonic-gate 	mdb_printf("%%rcx = 0x%0?p\t%%r10 = 0x%0?p\n",
2227c478bd9Sstevel@tonic-gate 	    grs[REG_RCX], grs[REG_R10]);
2237c478bd9Sstevel@tonic-gate 	mdb_printf("%%rdx = 0x%0?p\t%%r11 = 0x%0?p\n",
2247c478bd9Sstevel@tonic-gate 	    grs[REG_RDX], grs[REG_R11]);
2257c478bd9Sstevel@tonic-gate 	mdb_printf("%%rsi = 0x%0?p\t%%r12 = 0x%0?p\n",
2267c478bd9Sstevel@tonic-gate 	    grs[REG_RSI], grs[REG_R12]);
2277c478bd9Sstevel@tonic-gate 	mdb_printf("%%rdi = 0x%0?p\t%%r13 = 0x%0?p\n",
2287c478bd9Sstevel@tonic-gate 	    grs[REG_RDI], grs[REG_R13]);
2297c478bd9Sstevel@tonic-gate 	mdb_printf("         %?s\t%%r14 = 0x%0?p\n",
2307c478bd9Sstevel@tonic-gate 	    "", grs[REG_R14]);
2317c478bd9Sstevel@tonic-gate 	mdb_printf("         %?s\t%%r15 = 0x%0?p\n",
2327c478bd9Sstevel@tonic-gate 	    "", grs[REG_R15]);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	mdb_printf("%%cs = 0x%04x\t%%fs = 0x%04x\t%%gs = 0x%04x\n",
2377c478bd9Sstevel@tonic-gate 	    grs[REG_CS], grs[REG_FS], grs[REG_GS]);
2387c478bd9Sstevel@tonic-gate 	mdb_printf("%%ds = 0x%04x\t%%es = 0x%04x\t%%ss = 0x%04x\n",
2397c478bd9Sstevel@tonic-gate 	    grs[REG_DS], grs[REG_ES], grs[REG_SS]);
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	mdb_printf("%%rip = 0x%0?p %A\n", grs[REG_RIP], grs[REG_RIP]);
2447c478bd9Sstevel@tonic-gate 	mdb_printf("%%rbp = 0x%0?p\n", grs[REG_RBP], grs[REG_RBP]);
2457c478bd9Sstevel@tonic-gate 	mdb_printf("%%rsp = 0x%0?p\n", grs[REG_RSP], grs[REG_RSP]);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	mdb_printf("%%rflags = 0x%08x\n", rflags);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	mdb_printf("  id=%u vip=%u vif=%u ac=%u vm=%u rf=%u nt=%u iopl=0x%x\n",
2527c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_ID_MASK) >> KREG_EFLAGS_ID_SHIFT,
2537c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_VIP_MASK) >> KREG_EFLAGS_VIP_SHIFT,
2547c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_VIF_MASK) >> KREG_EFLAGS_VIF_SHIFT,
2557c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_AC_MASK) >> KREG_EFLAGS_AC_SHIFT,
2567c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_VM_MASK) >> KREG_EFLAGS_VM_SHIFT,
2577c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_RF_MASK) >> KREG_EFLAGS_RF_SHIFT,
2587c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_NT_MASK) >> KREG_EFLAGS_NT_SHIFT,
2597c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_IOPL_MASK) >> KREG_EFLAGS_IOPL_SHIFT);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	mdb_printf("  status=<%s,%s,%s,%s,%s,%s,%s,%s,%s>\n",
2627c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_OF_MASK) ? "OF" : "of",
2637c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_DF_MASK) ? "DF" : "df",
2647c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_IF_MASK) ? "IF" : "if",
2657c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_TF_MASK) ? "TF" : "tf",
2667c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_SF_MASK) ? "SF" : "sf",
2677c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_ZF_MASK) ? "ZF" : "zf",
2687c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_AF_MASK) ? "AF" : "af",
2697c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_PF_MASK) ? "PF" : "pf",
2707c478bd9Sstevel@tonic-gate 	    (rflags & KREG_EFLAGS_CF_MASK) ? "CF" : "cf");
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	mdb_printf("%%gsbase = 0x%0?p\n", grs[REG_GSBASE]);
2757c478bd9Sstevel@tonic-gate 	mdb_printf("%%fsbase = 0x%0?p\n", grs[REG_FSBASE]);
2767c478bd9Sstevel@tonic-gate 	mdb_printf("%%trapno = 0x%x\n", grs[REG_TRAPNO]);
2777c478bd9Sstevel@tonic-gate 	mdb_printf("   %%err = 0x%x\n", grs[REG_ERR]);
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate static const char *
fpcw2str(uint32_t cw,char * buf,size_t nbytes)2837c478bd9Sstevel@tonic-gate fpcw2str(uint32_t cw, char *buf, size_t nbytes)
2847c478bd9Sstevel@tonic-gate {
2857c478bd9Sstevel@tonic-gate 	char *end = buf + nbytes;
2867c478bd9Sstevel@tonic-gate 	char *p = buf;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	/*
29131779036SDoma Gergő Mihály 	 * Decode all exception masks in the x87 FPU Control Word.
29231779036SDoma Gergő Mihály 	 *
29331779036SDoma Gergő Mihály 	 * See here:
29431779036SDoma Gergő Mihály 	 * Intel® 64 and IA-32 Architectures Software Developer’s Manual,
29531779036SDoma Gergő Mihály 	 * Volume 1: Basic Architecture, 8.1.5 x87 FPU Control Word
2967c478bd9Sstevel@tonic-gate 	 */
29731779036SDoma Gergő Mihály 	if (cw & FPIM)	/* Invalid operation mask. */
2987c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IM");
29931779036SDoma Gergő Mihály 	if (cw & FPDM)	/* Denormalized operand mask. */
3007c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DM");
30131779036SDoma Gergő Mihály 	if (cw & FPZM)	/* Zero divide mask. */
3027c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZM");
30331779036SDoma Gergő Mihály 	if (cw & FPOM)	/* Overflow mask. */
3047c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OM");
30531779036SDoma Gergő Mihály 	if (cw & FPUM)	/* Underflow mask. */
3067c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UM");
30731779036SDoma Gergő Mihály 	if (cw & FPPM)	/* Precision mask. */
3087c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PM");
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	/*
31131779036SDoma Gergő Mihály 	 * Decode precision control options.
3127c478bd9Sstevel@tonic-gate 	 */
31331779036SDoma Gergő Mihály 	switch (cw & FPPC) {
31431779036SDoma Gergő Mihály 	case FPSIG24:
31531779036SDoma Gergő Mihály 		/* 24-bit significand, single precision. */
31631779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|SIG24");
31731779036SDoma Gergő Mihály 		break;
31831779036SDoma Gergő Mihály 	case FPSIG53:
31931779036SDoma Gergő Mihály 		/* 53-bit significand, double precision. */
3207c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|SIG53");
32131779036SDoma Gergő Mihály 		break;
32231779036SDoma Gergő Mihály 	case FPSIG64:
32331779036SDoma Gergő Mihály 		/* 64-bit significand, double extended precision. */
3247c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|SIG64");
32531779036SDoma Gergő Mihály 		break;
32631779036SDoma Gergő Mihály 	default:
32731779036SDoma Gergő Mihály 		/*
32831779036SDoma Gergő Mihály 		 * Should never happen.
32931779036SDoma Gergő Mihály 		 * Value 0x00000100 is 'Reserved'.
33031779036SDoma Gergő Mihály 		 */
33131779036SDoma Gergő Mihály 		break;
33231779036SDoma Gergő Mihály 	}
3337c478bd9Sstevel@tonic-gate 
33431779036SDoma Gergő Mihály 	/*
33531779036SDoma Gergő Mihály 	 * Decode rounding control options.
33631779036SDoma Gergő Mihály 	 */
33731779036SDoma Gergő Mihály 	switch (cw & FPRC) {
33831779036SDoma Gergő Mihály 	case FPRTN:
33931779036SDoma Gergő Mihály 		/* Round to nearest, or to even if equidistant. */
34031779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|RTN");
34131779036SDoma Gergő Mihály 		break;
34231779036SDoma Gergő Mihály 	case FPRD:
34331779036SDoma Gergő Mihály 		/* Round down. */
3447c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RD");
34531779036SDoma Gergő Mihály 		break;
34631779036SDoma Gergő Mihály 	case FPRU:
34731779036SDoma Gergő Mihály 		/* Round up. */
3487c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RU");
34931779036SDoma Gergő Mihály 		break;
35031779036SDoma Gergő Mihály 	case FPCHOP:
35131779036SDoma Gergő Mihály 		/* Truncate. */
35231779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|RTZ");
35331779036SDoma Gergő Mihály 		break;
35431779036SDoma Gergő Mihály 	default:
35531779036SDoma Gergő Mihály 		/*
35631779036SDoma Gergő Mihály 		 * This is a two-bit field.
35731779036SDoma Gergő Mihály 		 * No other options left.
35831779036SDoma Gergő Mihály 		 */
35931779036SDoma Gergő Mihály 		break;
36031779036SDoma Gergő Mihály 	}
3617c478bd9Sstevel@tonic-gate 
36231779036SDoma Gergő Mihály 	/*
36331779036SDoma Gergő Mihály 	 * Decode infinity control options.
36431779036SDoma Gergő Mihály 	 *
36531779036SDoma Gergő Mihály 	 * This field has been retained for compatibility with
36631779036SDoma Gergő Mihály 	 * the 287 and earlier co-processors.
36731779036SDoma Gergő Mihály 	 * In the more modern FPUs, this bit is disregarded and
36831779036SDoma Gergő Mihály 	 * both -infinity and +infinity are respected.
36931779036SDoma Gergő Mihály 	 * Comment source: SIMPLY FPU by Raymond Filiatreault
37031779036SDoma Gergő Mihály 	 */
37131779036SDoma Gergő Mihály 	switch (cw & FPIC) {
37231779036SDoma Gergő Mihály 	case FPP:
37331779036SDoma Gergő Mihály 		/*
37431779036SDoma Gergő Mihály 		 * Projective infinity.
37531779036SDoma Gergő Mihály 		 * Both -infinity and +infinity are treated as
37631779036SDoma Gergő Mihály 		 * unsigned infinity.
37731779036SDoma Gergő Mihály 		 */
3787c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|P");
37931779036SDoma Gergő Mihály 		break;
38031779036SDoma Gergő Mihály 	case FPA:
38131779036SDoma Gergő Mihály 		/*
38231779036SDoma Gergő Mihály 		 * Affine infinity.
38331779036SDoma Gergő Mihály 		 * Respects both -infinity and +infinity.
38431779036SDoma Gergő Mihály 		 */
38531779036SDoma Gergő Mihály 		p += mdb_snprintf(p, (size_t)(end - p), "|A");
38631779036SDoma Gergő Mihály 		break;
38731779036SDoma Gergő Mihály 	default:
38831779036SDoma Gergő Mihály 		/*
38931779036SDoma Gergő Mihály 		 * This is a one-bit field.
39031779036SDoma Gergő Mihály 		 * No other options left.
39131779036SDoma Gergő Mihály 		 */
39231779036SDoma Gergő Mihály 		break;
39331779036SDoma Gergő Mihály 	}
39431779036SDoma Gergő Mihály 
3957c478bd9Sstevel@tonic-gate 	if (cw & WFPB17)
3967c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|WFPB17");
3977c478bd9Sstevel@tonic-gate 	if (cw & WFPB24)
3987c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|WFPB24");
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	if (buf[0] == '|')
4017c478bd9Sstevel@tonic-gate 		return (buf + 1);
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 	return ("0");
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate static const char *
fpsw2str(uint32_t cw,char * buf,size_t nbytes)4077c478bd9Sstevel@tonic-gate fpsw2str(uint32_t cw, char *buf, size_t nbytes)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate 	char *end = buf + nbytes;
4107c478bd9Sstevel@tonic-gate 	char *p = buf;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	/*
4157c478bd9Sstevel@tonic-gate 	 * Decode all masks in the 80387 status word.
4167c478bd9Sstevel@tonic-gate 	 */
4177c478bd9Sstevel@tonic-gate 	if (cw & FPS_IE)
4187c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IE");
4197c478bd9Sstevel@tonic-gate 	if (cw & FPS_DE)
4207c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DE");
4217c478bd9Sstevel@tonic-gate 	if (cw & FPS_ZE)
4227c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZE");
4237c478bd9Sstevel@tonic-gate 	if (cw & FPS_OE)
4247c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OE");
4257c478bd9Sstevel@tonic-gate 	if (cw & FPS_UE)
4267c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UE");
4277c478bd9Sstevel@tonic-gate 	if (cw & FPS_PE)
4287c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PE");
4297c478bd9Sstevel@tonic-gate 	if (cw & FPS_SF)
4307c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|SF");
4317c478bd9Sstevel@tonic-gate 	if (cw & FPS_ES)
4327c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ES");
4337c478bd9Sstevel@tonic-gate 	if (cw & FPS_C0)
4347c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C0");
4357c478bd9Sstevel@tonic-gate 	if (cw & FPS_C1)
4367c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C1");
4377c478bd9Sstevel@tonic-gate 	if (cw & FPS_C2)
4387c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C2");
4397c478bd9Sstevel@tonic-gate 	if (cw & FPS_C3)
4407c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|C3");
4417c478bd9Sstevel@tonic-gate 	if (cw & FPS_B)
4427c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|B");
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	if (buf[0] == '|')
4457c478bd9Sstevel@tonic-gate 		return (buf + 1);
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	return ("0");
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate static const char *
fpmxcsr2str(uint32_t mxcsr,char * buf,size_t nbytes)4517c478bd9Sstevel@tonic-gate fpmxcsr2str(uint32_t mxcsr, char *buf, size_t nbytes)
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate 	char *end = buf + nbytes;
4547c478bd9Sstevel@tonic-gate 	char *p = buf;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	/*
4597c478bd9Sstevel@tonic-gate 	 * Decode the MXCSR word
4607c478bd9Sstevel@tonic-gate 	 */
4617c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_IE)
4627c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IE");
4637c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_DE)
4647c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DE");
4657c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_ZE)
4667c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZE");
4677c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_OE)
4687c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OE");
4697c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_UE)
4707c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UE");
4717c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_PE)
4727c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PE");
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_DAZ)
4757c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DAZ");
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_IM)
4787c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|IM");
4797c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_DM)
4807c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|DM");
4817c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_ZM)
4827c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|ZM");
4837c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_OM)
4847c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|OM");
4857c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_UM)
4867c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|UM");
4877c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_PM)
4887c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|PM");
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	if ((mxcsr & SSE_RC) == (SSE_RD|SSE_RU))
4917c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RTZ");
4927c478bd9Sstevel@tonic-gate 	else if (mxcsr & SSE_RD)
4937c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RD");
4947c478bd9Sstevel@tonic-gate 	else if (mxcsr & SSE_RU)
4957c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RU");
4967c478bd9Sstevel@tonic-gate 	else
4977c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|RTN");
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	if (mxcsr & SSE_FZ)
5007c478bd9Sstevel@tonic-gate 		p += mdb_snprintf(p, (size_t)(end - p), "|FZ");
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	if (buf[0] == '|')
5037c478bd9Sstevel@tonic-gate 		return (buf + 1);
5047c478bd9Sstevel@tonic-gate 	return ("0");
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5087c478bd9Sstevel@tonic-gate int
pt_fpregs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5097c478bd9Sstevel@tonic-gate pt_fpregs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5107c478bd9Sstevel@tonic-gate {
5117c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb.m_target;
5127c478bd9Sstevel@tonic-gate 	mdb_tgt_tid_t tid;
5137c478bd9Sstevel@tonic-gate 	prfpregset_t fprs;
514bc0e9132SGordon Ross 	struct _fpchip_state fps;
5157c478bd9Sstevel@tonic-gate 	char buf[256];
5167c478bd9Sstevel@tonic-gate 	uint_t top;
5177c478bd9Sstevel@tonic-gate 	int i;
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	/*
5207c478bd9Sstevel@tonic-gate 	 * Union for overlaying _fpreg structure on to quad-precision
5217c478bd9Sstevel@tonic-gate 	 * floating-point value (long double).
5227c478bd9Sstevel@tonic-gate 	 */
5237c478bd9Sstevel@tonic-gate 	union {
5247c478bd9Sstevel@tonic-gate 		struct _fpreg reg;
5257c478bd9Sstevel@tonic-gate 		long double ld;
5267c478bd9Sstevel@tonic-gate 	} fpru;
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	/*
5297c478bd9Sstevel@tonic-gate 	 * Array of strings corresponding to FPU tag word values (see
5307c478bd9Sstevel@tonic-gate 	 * section 7.3.6 of the Intel Programmer's Reference Manual).
5317c478bd9Sstevel@tonic-gate 	 */
5327c478bd9Sstevel@tonic-gate 	const char *tag_strings[] = { "valid", "zero", "special", "empty" };
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	if (argc != 0)
5357c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	if (t->t_pshandle == NULL || Pstate(t->t_pshandle) == PS_UNDEAD) {
5387c478bd9Sstevel@tonic-gate 		mdb_warn("no process active\n");
5397c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5407c478bd9Sstevel@tonic-gate 	}
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) == PS_LOST) {
5437c478bd9Sstevel@tonic-gate 		mdb_warn("debugger has lost control of process\n");
5447c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5457c478bd9Sstevel@tonic-gate 	}
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
5487c478bd9Sstevel@tonic-gate 		tid = (mdb_tgt_tid_t)addr;
5497c478bd9Sstevel@tonic-gate 	else
5507c478bd9Sstevel@tonic-gate 		tid = PTL_TID(t);
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	mdb_printf("AMD64 (80486 chip with SSE)\n");
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	if (PTL_GETFPREGS(t, tid, &fprs) != 0) {
5557c478bd9Sstevel@tonic-gate 		mdb_warn("failed to get floating point registers");
5567c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5577c478bd9Sstevel@tonic-gate 	}
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	bcopy(&fprs.fp_reg_set.fpchip_state, &fps, sizeof (fps));
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	fps.status &= 0xffff;	/* saved status word is really 16 bits */
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 	mdb_printf("cw     0x%04x (%s)\n", fps.cw,
5647c478bd9Sstevel@tonic-gate 	    fpcw2str(fps.cw, buf, sizeof (buf)));
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	top = (fps.sw & FPS_TOP) >> 11;
5677c478bd9Sstevel@tonic-gate 	mdb_printf("sw     0x%04x (TOP=0t%u) (%s)\n", fps.sw,
5687c478bd9Sstevel@tonic-gate 	    top, fpsw2str(fps.sw, buf, sizeof (buf)));
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 	mdb_printf("xcp sw 0x%04x (%s)\n\n", fps.status,
5717c478bd9Sstevel@tonic-gate 	    fpsw2str(fps.status, buf, sizeof (buf)));
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	mdb_printf("fop    0x%x\n", fps.fop);
5747c478bd9Sstevel@tonic-gate 	mdb_printf("rip    0x%x\n", fps.rip);
5757c478bd9Sstevel@tonic-gate 	mdb_printf("rdp    0x%x\n\n", fps.rdp);
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
5787c478bd9Sstevel@tonic-gate 		/*
5797c478bd9Sstevel@tonic-gate 		 * Recall that we need to use the current TOP-of-stack value to
5807c478bd9Sstevel@tonic-gate 		 * associate the _st[] index back to a physical register number,
5817c478bd9Sstevel@tonic-gate 		 * since tag word indices are physical register numbers.  Then
5827c478bd9Sstevel@tonic-gate 		 * to get the tag value, we shift over two bits for each tag
5837c478bd9Sstevel@tonic-gate 		 * index, and then grab the bottom two bits.
5847c478bd9Sstevel@tonic-gate 		 */
5857c478bd9Sstevel@tonic-gate 		uint_t tag_index = (i + top) & 7;
5867c478bd9Sstevel@tonic-gate 		uint_t tag_fctw = (fps.fctw >> tag_index) & 1;
5877c478bd9Sstevel@tonic-gate 		uint_t tag_value;
5887c478bd9Sstevel@tonic-gate 		uint_t exp;
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 		/*
5917c478bd9Sstevel@tonic-gate 		 * AMD64 stores the tag in a compressed form. It is
5927c478bd9Sstevel@tonic-gate 		 * necessary to extract the original 2-bit tag value.
5937c478bd9Sstevel@tonic-gate 		 * See AMD64 Architecture Programmer's Manual Volume 2:
5947c478bd9Sstevel@tonic-gate 		 * System Programming, Chapter 11.
5957c478bd9Sstevel@tonic-gate 		 */
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 		fpru.ld = fps.st[i].__fpr_pad._q;
5987c478bd9Sstevel@tonic-gate 		exp = fpru.reg.exponent & 0x7fff;
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 		if (tag_fctw == 0) {
6017c478bd9Sstevel@tonic-gate 			tag_value = 3; /* empty */
6027c478bd9Sstevel@tonic-gate 		} else if (exp == 0) {
6037c478bd9Sstevel@tonic-gate 			if (fpru.reg.significand[0] == 0 &&
6047c478bd9Sstevel@tonic-gate 			    fpru.reg.significand[1] == 0 &&
6057c478bd9Sstevel@tonic-gate 			    fpru.reg.significand[2] == 0 &&
6067c478bd9Sstevel@tonic-gate 			    fpru.reg.significand[3] == 0)
6077c478bd9Sstevel@tonic-gate 				tag_value = 1; /* zero */
6087c478bd9Sstevel@tonic-gate 			else
6097c478bd9Sstevel@tonic-gate 				tag_value = 2; /* special: denormal */
6107c478bd9Sstevel@tonic-gate 		} else if (exp == 0x7fff) {
6117c478bd9Sstevel@tonic-gate 			tag_value = 2; /* special: infinity or NaN */
6127c478bd9Sstevel@tonic-gate 		} else if (fpru.reg.significand[3] & 0x8000) {
6137c478bd9Sstevel@tonic-gate 			tag_value = 0; /* valid */
6147c478bd9Sstevel@tonic-gate 		} else {
6157c478bd9Sstevel@tonic-gate 			tag_value = 2; /* special: unnormal */
6167c478bd9Sstevel@tonic-gate 		}
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 		mdb_printf("%%st%d   0x%04x.%04x%04x%04x%04x = %lg %s\n",
6197c478bd9Sstevel@tonic-gate 		    i, fpru.reg.exponent,
6207c478bd9Sstevel@tonic-gate 		    fpru.reg.significand[3], fpru.reg.significand[2],
6217c478bd9Sstevel@tonic-gate 		    fpru.reg.significand[1], fpru.reg.significand[0],
6227c478bd9Sstevel@tonic-gate 		    fpru.ld, tag_strings[tag_value]);
6237c478bd9Sstevel@tonic-gate 	}
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	mdb_printf("\nmxcsr  0x%04x (%s)\n", fps.mxcsr,
6267c478bd9Sstevel@tonic-gate 	    fpmxcsr2str(fps.mxcsr, buf, sizeof (buf)));
6277c478bd9Sstevel@tonic-gate 	mdb_printf("xcp    0x%04x (%s)\n\n", fps.xstatus,
6287c478bd9Sstevel@tonic-gate 	    fpmxcsr2str(fps.xstatus, buf, sizeof (buf)));
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++)
6317c478bd9Sstevel@tonic-gate 		mdb_printf("%%xmm%d  0x%08x%08x%08x%08x\n", i,
6327c478bd9Sstevel@tonic-gate 		    fps.xmm[i]._l[3], fps.xmm[i]._l[2],
6337c478bd9Sstevel@tonic-gate 		    fps.xmm[i]._l[1], fps.xmm[i]._l[0]);
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
6367c478bd9Sstevel@tonic-gate }
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6397c478bd9Sstevel@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)6407c478bd9Sstevel@tonic-gate pt_getfpreg(mdb_tgt_t *t, mdb_tgt_tid_t tid, ushort_t rd_num,
6417c478bd9Sstevel@tonic-gate     ushort_t rd_flags, mdb_tgt_reg_t *rp)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6477c478bd9Sstevel@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)6487c478bd9Sstevel@tonic-gate pt_putfpreg(mdb_tgt_t *t, mdb_tgt_tid_t tid, ushort_t rd_num,
6497c478bd9Sstevel@tonic-gate     ushort_t rd_flags, mdb_tgt_reg_t rval)
6507c478bd9Sstevel@tonic-gate {
6517c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6557c478bd9Sstevel@tonic-gate void
pt_addfpregs(mdb_tgt_t * t)6567c478bd9Sstevel@tonic-gate pt_addfpregs(mdb_tgt_t *t)
6577c478bd9Sstevel@tonic-gate {
6587c478bd9Sstevel@tonic-gate 	/* not implemented */
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6627c478bd9Sstevel@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)6637c478bd9Sstevel@tonic-gate pt_frameregs(void *arglim, uintptr_t pc, uint_t argc, const long *argv,
6647c478bd9Sstevel@tonic-gate     const mdb_tgt_gregset_t *gregs, boolean_t pc_faked)
6657c478bd9Sstevel@tonic-gate {
6667c478bd9Sstevel@tonic-gate 	return (set_errno(ENOTSUP));
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6707c478bd9Sstevel@tonic-gate const char *
pt_disasm(const GElf_Ehdr * ehp)6717c478bd9Sstevel@tonic-gate pt_disasm(const GElf_Ehdr *ehp)
6727c478bd9Sstevel@tonic-gate {
6737c478bd9Sstevel@tonic-gate 	return ("amd64");
6747c478bd9Sstevel@tonic-gate }
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate /*
6777c478bd9Sstevel@tonic-gate  * Determine the return address for the current frame.
6787c478bd9Sstevel@tonic-gate  */
6797c478bd9Sstevel@tonic-gate int
pt_step_out(mdb_tgt_t * t,uintptr_t * p)6807c478bd9Sstevel@tonic-gate pt_step_out(mdb_tgt_t *t, uintptr_t *p)
6817c478bd9Sstevel@tonic-gate {
6827c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) != PS_STOP)
6857c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_TGTBUSY));
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 	return (mdb_amd64_step_out(t, p, psp->pr_reg[EIP], psp->pr_reg[EBP],
6887c478bd9Sstevel@tonic-gate 	    psp->pr_reg[UESP], psp->pr_instr));
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate /*
6927c478bd9Sstevel@tonic-gate  * Return the address of the next instruction following a call, or return -1
6937c478bd9Sstevel@tonic-gate  * and set errno to EAGAIN if the target should just single-step.
6947c478bd9Sstevel@tonic-gate  */
6957c478bd9Sstevel@tonic-gate int
pt_next(mdb_tgt_t * t,uintptr_t * p)6967c478bd9Sstevel@tonic-gate pt_next(mdb_tgt_t *t, uintptr_t *p)
6977c478bd9Sstevel@tonic-gate {
6987c478bd9Sstevel@tonic-gate 	const lwpstatus_t *psp = &Pstatus(t->t_pshandle)->pr_lwp;
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	if (Pstate(t->t_pshandle) != PS_STOP)
7017c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_TGTBUSY));
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	return (mdb_amd64_next(t, p, psp->pr_reg[REG_RIP], pt_read_instr(t)));
7047c478bd9Sstevel@tonic-gate }
705