xref: /titanic_51/usr/src/lib/libproc/common/P32ton.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/regset.h>
32*7c478bd9Sstevel@tonic-gate #include <string.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #if defined(__amd64)
35*7c478bd9Sstevel@tonic-gate #include <sys/fp.h>
36*7c478bd9Sstevel@tonic-gate #include <ieeefp.h>
37*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #include "P32ton.h"
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate dev_t
42*7c478bd9Sstevel@tonic-gate prexpldev(dev32_t d)
43*7c478bd9Sstevel@tonic-gate {
44*7c478bd9Sstevel@tonic-gate 	if (d != (dev32_t)-1L)
45*7c478bd9Sstevel@tonic-gate 		return (makedev((d >> NBITSMINOR32) & MAXMAJ32, d & MAXMIN32));
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	return ((dev_t)PRNODEV);
48*7c478bd9Sstevel@tonic-gate }
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate dev32_t
52*7c478bd9Sstevel@tonic-gate prcmpldev(dev_t d)
53*7c478bd9Sstevel@tonic-gate {
54*7c478bd9Sstevel@tonic-gate #ifdef _LP64
55*7c478bd9Sstevel@tonic-gate 	if (d == PRNODEV) {
56*7c478bd9Sstevel@tonic-gate 		return (PRNODEV32);
57*7c478bd9Sstevel@tonic-gate 	} else {
58*7c478bd9Sstevel@tonic-gate 		major_t maj = major(d);
59*7c478bd9Sstevel@tonic-gate 		minor_t min = minor(d);
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 		if (maj == (major_t)PRNODEV || min == (minor_t)PRNODEV)
62*7c478bd9Sstevel@tonic-gate 			return (PRNODEV32);
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 		return ((dev32_t)((maj << NBITSMINOR32) | min));
65*7c478bd9Sstevel@tonic-gate 	}
66*7c478bd9Sstevel@tonic-gate #else
67*7c478bd9Sstevel@tonic-gate 	return ((dev32_t)d);
68*7c478bd9Sstevel@tonic-gate #endif
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate #ifdef _LP64
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate void
74*7c478bd9Sstevel@tonic-gate timestruc_32_to_n(const timestruc32_t *src, timestruc_t *dst)
75*7c478bd9Sstevel@tonic-gate {
76*7c478bd9Sstevel@tonic-gate 	dst->tv_sec = (time_t)(uint32_t)src->tv_sec;
77*7c478bd9Sstevel@tonic-gate 	dst->tv_nsec = (long)(uint32_t)src->tv_nsec;
78*7c478bd9Sstevel@tonic-gate }
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate void
81*7c478bd9Sstevel@tonic-gate stack_32_to_n(const stack32_t *src, stack_t *dst)
82*7c478bd9Sstevel@tonic-gate {
83*7c478bd9Sstevel@tonic-gate 	dst->ss_sp = (caddr_t)(uintptr_t)src->ss_sp;
84*7c478bd9Sstevel@tonic-gate 	dst->ss_size = src->ss_size;
85*7c478bd9Sstevel@tonic-gate 	dst->ss_flags = src->ss_flags;
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate void
89*7c478bd9Sstevel@tonic-gate sigaction_32_to_n(const struct sigaction32 *src, struct sigaction *dst)
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (struct sigaction));
92*7c478bd9Sstevel@tonic-gate 	dst->sa_flags = src->sa_flags;
93*7c478bd9Sstevel@tonic-gate 	dst->sa_handler = (void (*)())(uintptr_t)src->sa_handler;
94*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->sa_mask, &src->sa_mask, sizeof (dst->sa_mask));
95*7c478bd9Sstevel@tonic-gate }
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate void
98*7c478bd9Sstevel@tonic-gate siginfo_32_to_n(const siginfo32_t *src, siginfo_t *dst)
99*7c478bd9Sstevel@tonic-gate {
100*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (siginfo_t));
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/*
103*7c478bd9Sstevel@tonic-gate 	 * The absolute minimum content is si_signo and si_code.
104*7c478bd9Sstevel@tonic-gate 	 */
105*7c478bd9Sstevel@tonic-gate 	dst->si_signo = src->si_signo;
106*7c478bd9Sstevel@tonic-gate 	if ((dst->si_code = src->si_code) == SI_NOINFO)
107*7c478bd9Sstevel@tonic-gate 		return;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	/*
110*7c478bd9Sstevel@tonic-gate 	 * A siginfo generated by user level is structured
111*7c478bd9Sstevel@tonic-gate 	 * differently from one generated by the kernel.
112*7c478bd9Sstevel@tonic-gate 	 */
113*7c478bd9Sstevel@tonic-gate 	if (SI_FROMUSER(src)) {
114*7c478bd9Sstevel@tonic-gate 		dst->si_pid = src->si_pid;
115*7c478bd9Sstevel@tonic-gate 		dst->si_ctid = src->si_ctid;
116*7c478bd9Sstevel@tonic-gate 		dst->si_zoneid = src->si_zoneid;
117*7c478bd9Sstevel@tonic-gate 		dst->si_uid = src->si_uid;
118*7c478bd9Sstevel@tonic-gate 		if (SI_CANQUEUE(src->si_code)) {
119*7c478bd9Sstevel@tonic-gate 			dst->si_value.sival_int =
120*7c478bd9Sstevel@tonic-gate 			    (long)(uint32_t)src->si_value.sival_int;
121*7c478bd9Sstevel@tonic-gate 		}
122*7c478bd9Sstevel@tonic-gate 		return;
123*7c478bd9Sstevel@tonic-gate 	}
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	dst->si_errno = src->si_errno;
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	switch (src->si_signo) {
128*7c478bd9Sstevel@tonic-gate 	default:
129*7c478bd9Sstevel@tonic-gate 		dst->si_pid = src->si_pid;
130*7c478bd9Sstevel@tonic-gate 		dst->si_ctid = src->si_ctid;
131*7c478bd9Sstevel@tonic-gate 		dst->si_zoneid = src->si_zoneid;
132*7c478bd9Sstevel@tonic-gate 		dst->si_uid = src->si_uid;
133*7c478bd9Sstevel@tonic-gate 		dst->si_value.sival_int =
134*7c478bd9Sstevel@tonic-gate 		    (long)(uint32_t)src->si_value.sival_int;
135*7c478bd9Sstevel@tonic-gate 		break;
136*7c478bd9Sstevel@tonic-gate 	case SIGCLD:
137*7c478bd9Sstevel@tonic-gate 		dst->si_pid = src->si_pid;
138*7c478bd9Sstevel@tonic-gate 		dst->si_ctid = src->si_ctid;
139*7c478bd9Sstevel@tonic-gate 		dst->si_zoneid = src->si_zoneid;
140*7c478bd9Sstevel@tonic-gate 		dst->si_status = src->si_status;
141*7c478bd9Sstevel@tonic-gate 		dst->si_stime = src->si_stime;
142*7c478bd9Sstevel@tonic-gate 		dst->si_utime = src->si_utime;
143*7c478bd9Sstevel@tonic-gate 		break;
144*7c478bd9Sstevel@tonic-gate 	case SIGSEGV:
145*7c478bd9Sstevel@tonic-gate 	case SIGBUS:
146*7c478bd9Sstevel@tonic-gate 	case SIGILL:
147*7c478bd9Sstevel@tonic-gate 	case SIGTRAP:
148*7c478bd9Sstevel@tonic-gate 	case SIGFPE:
149*7c478bd9Sstevel@tonic-gate 	case SIGEMT:
150*7c478bd9Sstevel@tonic-gate 		dst->si_addr = (void *)(uintptr_t)src->si_addr;
151*7c478bd9Sstevel@tonic-gate 		dst->si_trapno = src->si_trapno;
152*7c478bd9Sstevel@tonic-gate 		dst->si_pc = (void *)(uintptr_t)src->si_pc;
153*7c478bd9Sstevel@tonic-gate 		break;
154*7c478bd9Sstevel@tonic-gate 	case SIGPOLL:
155*7c478bd9Sstevel@tonic-gate 	case SIGXFSZ:
156*7c478bd9Sstevel@tonic-gate 		dst->si_fd = src->si_fd;
157*7c478bd9Sstevel@tonic-gate 		dst->si_band = src->si_band;
158*7c478bd9Sstevel@tonic-gate 		break;
159*7c478bd9Sstevel@tonic-gate 	case SIGPROF:
160*7c478bd9Sstevel@tonic-gate 		dst->si_faddr = (void *)(uintptr_t)src->si_faddr;
161*7c478bd9Sstevel@tonic-gate 		dst->si_tstamp.tv_sec = src->si_tstamp.tv_sec;
162*7c478bd9Sstevel@tonic-gate 		dst->si_tstamp.tv_nsec = src->si_tstamp.tv_nsec;
163*7c478bd9Sstevel@tonic-gate 		dst->si_syscall = src->si_syscall;
164*7c478bd9Sstevel@tonic-gate 		dst->si_nsysarg = src->si_nsysarg;
165*7c478bd9Sstevel@tonic-gate 		dst->si_fault = src->si_fault;
166*7c478bd9Sstevel@tonic-gate 		break;
167*7c478bd9Sstevel@tonic-gate 	}
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate void
171*7c478bd9Sstevel@tonic-gate auxv_32_to_n(const auxv32_t *src, auxv_t *dst)
172*7c478bd9Sstevel@tonic-gate {
173*7c478bd9Sstevel@tonic-gate 	/*
174*7c478bd9Sstevel@tonic-gate 	 * This is a little sketchy: we have three types of values stored
175*7c478bd9Sstevel@tonic-gate 	 * in an auxv (long, void *, and void (*)()) so the only sign-extension
176*7c478bd9Sstevel@tonic-gate 	 * issue is with the long.  We could case on all possible AT_* types,
177*7c478bd9Sstevel@tonic-gate 	 * but this seems silly since currently none of the types which use
178*7c478bd9Sstevel@tonic-gate 	 * a_un.a_val actually use negative numbers as a value.  For this
179*7c478bd9Sstevel@tonic-gate 	 * reason, it seems simpler to just do an unsigned expansion for now.
180*7c478bd9Sstevel@tonic-gate 	 */
181*7c478bd9Sstevel@tonic-gate 	dst->a_type = src->a_type;
182*7c478bd9Sstevel@tonic-gate 	dst->a_un.a_ptr = (void *)(uintptr_t)src->a_un.a_ptr;
183*7c478bd9Sstevel@tonic-gate }
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
186*7c478bd9Sstevel@tonic-gate void
187*7c478bd9Sstevel@tonic-gate rwindow_32_to_n(const struct rwindow32 *src, struct rwindow *dst)
188*7c478bd9Sstevel@tonic-gate {
189*7c478bd9Sstevel@tonic-gate 	int i;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
192*7c478bd9Sstevel@tonic-gate 		dst->rw_local[i] = (uint64_t)(uint32_t)src->rw_local[i];
193*7c478bd9Sstevel@tonic-gate 		dst->rw_in[i] = (uint64_t)(uint32_t)src->rw_in[i];
194*7c478bd9Sstevel@tonic-gate 	}
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate void
198*7c478bd9Sstevel@tonic-gate gwindows_32_to_n(const gwindows32_t *src, gwindows_t *dst)
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate 	int i;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (gwindows_t));
203*7c478bd9Sstevel@tonic-gate 	dst->wbcnt = src->wbcnt;
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < src->wbcnt; i++) {
206*7c478bd9Sstevel@tonic-gate 		if (src->spbuf[i] != 0) {
207*7c478bd9Sstevel@tonic-gate 			rwindow_32_to_n(&src->wbuf[i], &dst->wbuf[i]);
208*7c478bd9Sstevel@tonic-gate 			dst->spbuf[i] = (greg_t *)src->spbuf[i];
209*7c478bd9Sstevel@tonic-gate 		}
210*7c478bd9Sstevel@tonic-gate 	}
211*7c478bd9Sstevel@tonic-gate }
212*7c478bd9Sstevel@tonic-gate #endif	/* __sparc */
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate void
215*7c478bd9Sstevel@tonic-gate prgregset_32_to_n(const prgreg32_t *src, prgreg_t *dst)
216*7c478bd9Sstevel@tonic-gate {
217*7c478bd9Sstevel@tonic-gate #ifdef __amd64
218*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, NPRGREG * sizeof (prgreg_t));
219*7c478bd9Sstevel@tonic-gate 	dst[REG_GS] = (uint32_t)src[GS];
220*7c478bd9Sstevel@tonic-gate 	dst[REG_FS] = (uint32_t)src[FS];
221*7c478bd9Sstevel@tonic-gate 	dst[REG_DS] = (uint32_t)src[DS];
222*7c478bd9Sstevel@tonic-gate 	dst[REG_ES] = (uint32_t)src[ES];
223*7c478bd9Sstevel@tonic-gate 	dst[REG_RDI] = (uint32_t)src[EDI];
224*7c478bd9Sstevel@tonic-gate 	dst[REG_RSI] = (uint32_t)src[ESI];
225*7c478bd9Sstevel@tonic-gate 	dst[REG_RBP] = (uint32_t)src[EBP];
226*7c478bd9Sstevel@tonic-gate 	dst[REG_RBX] = (uint32_t)src[EBX];
227*7c478bd9Sstevel@tonic-gate 	dst[REG_RDX] = (uint32_t)src[EDX];
228*7c478bd9Sstevel@tonic-gate 	dst[REG_RCX] = (uint32_t)src[ECX];
229*7c478bd9Sstevel@tonic-gate 	dst[REG_RAX] = (uint32_t)src[EAX];
230*7c478bd9Sstevel@tonic-gate 	dst[REG_TRAPNO] = (uint32_t)src[TRAPNO];
231*7c478bd9Sstevel@tonic-gate 	dst[REG_ERR] = (uint32_t)src[ERR];
232*7c478bd9Sstevel@tonic-gate 	dst[REG_RIP] = (uint32_t)src[EIP];
233*7c478bd9Sstevel@tonic-gate 	dst[REG_CS] = (uint32_t)src[CS];
234*7c478bd9Sstevel@tonic-gate 	dst[REG_RFL] = (uint32_t)src[EFL];
235*7c478bd9Sstevel@tonic-gate 	dst[REG_RSP] = (uint32_t)src[UESP];
236*7c478bd9Sstevel@tonic-gate 	dst[REG_SS] = (uint32_t)src[SS];
237*7c478bd9Sstevel@tonic-gate #else
238*7c478bd9Sstevel@tonic-gate 	int i;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NPRGREG; i++)
241*7c478bd9Sstevel@tonic-gate 		dst[i] = (prgreg_t)(uint32_t)src[i];
242*7c478bd9Sstevel@tonic-gate #endif
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate void
246*7c478bd9Sstevel@tonic-gate prfpregset_32_to_n(const prfpregset32_t *src, prfpregset_t *dst)
247*7c478bd9Sstevel@tonic-gate {
248*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
249*7c478bd9Sstevel@tonic-gate 	int i;
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (prfpregset_t));
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 32; i++)
254*7c478bd9Sstevel@tonic-gate 		dst->pr_fr.pr_regs[i] = src->pr_fr.pr_regs[i];
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 	/*
257*7c478bd9Sstevel@tonic-gate 	 * We deliberately do not convert pr_qcnt or pr_q because it is a long-
258*7c478bd9Sstevel@tonic-gate 	 * standing /proc bug that this information is not exported, and another
259*7c478bd9Sstevel@tonic-gate 	 * bug further caused these values to be returned as uninitialized data
260*7c478bd9Sstevel@tonic-gate 	 * when the 64-bit kernel exported them for a 32-bit process with en=0.
261*7c478bd9Sstevel@tonic-gate 	 */
262*7c478bd9Sstevel@tonic-gate 	dst->pr_filler = src->pr_filler;
263*7c478bd9Sstevel@tonic-gate 	dst->pr_fsr = src->pr_fsr;
264*7c478bd9Sstevel@tonic-gate 	dst->pr_q_entrysize = src->pr_q_entrysize;
265*7c478bd9Sstevel@tonic-gate 	dst->pr_en = src->pr_en;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate #elif defined(__amd64)
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate 	struct _fpstate32 *src32 = (struct _fpstate32 *)src;
270*7c478bd9Sstevel@tonic-gate 	struct fpchip_state *dst64 = (struct fpchip_state *)dst;
271*7c478bd9Sstevel@tonic-gate 	int i;
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	(void) memcpy(dst64->st, src32->_st, sizeof (src32->_st));
274*7c478bd9Sstevel@tonic-gate 	(void) memcpy(dst64->xmm, src32->xmm, sizeof (src32->xmm));
275*7c478bd9Sstevel@tonic-gate 	(void) memset((caddr_t)dst64->xmm + sizeof (src32->xmm), 0,
276*7c478bd9Sstevel@tonic-gate 	    sizeof (dst64->xmm) - sizeof (src32->xmm));
277*7c478bd9Sstevel@tonic-gate 	dst64->cw = (uint16_t)src32->cw;
278*7c478bd9Sstevel@tonic-gate 	dst64->sw = (uint16_t)src32->sw;
279*7c478bd9Sstevel@tonic-gate 	dst64->fop = 0;
280*7c478bd9Sstevel@tonic-gate 	dst64->rip = src32->ipoff;
281*7c478bd9Sstevel@tonic-gate 	dst64->rdp = src32->dataoff;
282*7c478bd9Sstevel@tonic-gate 	dst64->mxcsr = src32->mxcsr;
283*7c478bd9Sstevel@tonic-gate 	dst64->mxcsr_mask = 0;
284*7c478bd9Sstevel@tonic-gate 	dst64->status = src32->status;
285*7c478bd9Sstevel@tonic-gate 	dst64->xstatus = src32->xstatus;
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate 	/*
288*7c478bd9Sstevel@tonic-gate 	 * Converting from the tag field to the compressed fctw is easy.
289*7c478bd9Sstevel@tonic-gate 	 * If the two tag bits are 3, then the register is empty and we
290*7c478bd9Sstevel@tonic-gate 	 * clear the bit in fctw. Otherwise we set the bit.
291*7c478bd9Sstevel@tonic-gate 	 */
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 	dst64->fctw = 0;
294*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++)
295*7c478bd9Sstevel@tonic-gate 		if (((src32->tag >> (i * 2)) & 3) != 3)
296*7c478bd9Sstevel@tonic-gate 			dst64->fctw |= 1 << i;
297*7c478bd9Sstevel@tonic-gate #else
298*7c478bd9Sstevel@tonic-gate #error "unrecognized ISA"
299*7c478bd9Sstevel@tonic-gate #endif
300*7c478bd9Sstevel@tonic-gate }
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate void
303*7c478bd9Sstevel@tonic-gate lwpstatus_32_to_n(const lwpstatus32_t *src, lwpstatus_t *dst)
304*7c478bd9Sstevel@tonic-gate {
305*7c478bd9Sstevel@tonic-gate 	int i;
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate 	dst->pr_flags = src->pr_flags;
308*7c478bd9Sstevel@tonic-gate 	dst->pr_lwpid = src->pr_lwpid;
309*7c478bd9Sstevel@tonic-gate 	dst->pr_why = src->pr_why;
310*7c478bd9Sstevel@tonic-gate 	dst->pr_what = src->pr_what;
311*7c478bd9Sstevel@tonic-gate 	dst->pr_cursig = src->pr_cursig;
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 	siginfo_32_to_n(&src->pr_info, &dst->pr_info);
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 	dst->pr_lwppend = src->pr_lwppend;
316*7c478bd9Sstevel@tonic-gate 	dst->pr_lwphold = src->pr_lwphold;
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	sigaction_32_to_n(&src->pr_action, &dst->pr_action);
319*7c478bd9Sstevel@tonic-gate 	stack_32_to_n(&src->pr_altstack, &dst->pr_altstack);
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 	dst->pr_oldcontext = src->pr_oldcontext;
322*7c478bd9Sstevel@tonic-gate 	dst->pr_syscall = src->pr_syscall;
323*7c478bd9Sstevel@tonic-gate 	dst->pr_nsysarg = src->pr_nsysarg;
324*7c478bd9Sstevel@tonic-gate 	dst->pr_errno = src->pr_errno;
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < PRSYSARGS; i++)
327*7c478bd9Sstevel@tonic-gate 		dst->pr_sysarg[i] = (long)(uint32_t)src->pr_sysarg[i];
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate 	dst->pr_rval1 = (long)(uint32_t)src->pr_rval1;
330*7c478bd9Sstevel@tonic-gate 	dst->pr_rval2 = (long)(uint32_t)src->pr_rval2;
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
333*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_tstamp, &dst->pr_tstamp);
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 	dst->pr_ustack = src->pr_ustack;
336*7c478bd9Sstevel@tonic-gate 	dst->pr_instr = src->pr_instr;
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	prgregset_32_to_n(src->pr_reg, dst->pr_reg);
339*7c478bd9Sstevel@tonic-gate 	prfpregset_32_to_n(&src->pr_fpreg, &dst->pr_fpreg);
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate void
343*7c478bd9Sstevel@tonic-gate pstatus_32_to_n(const pstatus32_t *src, pstatus_t *dst)
344*7c478bd9Sstevel@tonic-gate {
345*7c478bd9Sstevel@tonic-gate 	dst->pr_flags = src->pr_flags;
346*7c478bd9Sstevel@tonic-gate 	dst->pr_nlwp = src->pr_nlwp;
347*7c478bd9Sstevel@tonic-gate 	dst->pr_nzomb = src->pr_nzomb;
348*7c478bd9Sstevel@tonic-gate 	dst->pr_pid = src->pr_pid;
349*7c478bd9Sstevel@tonic-gate 	dst->pr_ppid = src->pr_ppid;
350*7c478bd9Sstevel@tonic-gate 	dst->pr_pgid = src->pr_pgid;
351*7c478bd9Sstevel@tonic-gate 	dst->pr_sid = src->pr_sid;
352*7c478bd9Sstevel@tonic-gate 	dst->pr_taskid = src->pr_taskid;
353*7c478bd9Sstevel@tonic-gate 	dst->pr_projid = src->pr_projid;
354*7c478bd9Sstevel@tonic-gate 	dst->pr_zoneid = src->pr_zoneid;
355*7c478bd9Sstevel@tonic-gate 	dst->pr_aslwpid = src->pr_aslwpid;
356*7c478bd9Sstevel@tonic-gate 	dst->pr_agentid = src->pr_agentid;
357*7c478bd9Sstevel@tonic-gate 	dst->pr_sigpend = src->pr_sigpend;
358*7c478bd9Sstevel@tonic-gate 	dst->pr_brkbase = src->pr_brkbase;
359*7c478bd9Sstevel@tonic-gate 	dst->pr_brksize = src->pr_brksize;
360*7c478bd9Sstevel@tonic-gate 	dst->pr_stkbase = src->pr_stkbase;
361*7c478bd9Sstevel@tonic-gate 	dst->pr_stksize = src->pr_stksize;
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_utime, &dst->pr_utime);
364*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_stime, &dst->pr_stime);
365*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_cutime, &dst->pr_cutime);
366*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_cstime, &dst->pr_cstime);
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 	dst->pr_sigtrace = src->pr_sigtrace;
369*7c478bd9Sstevel@tonic-gate 	dst->pr_flttrace = src->pr_flttrace;
370*7c478bd9Sstevel@tonic-gate 	dst->pr_sysentry = src->pr_sysentry;
371*7c478bd9Sstevel@tonic-gate 	dst->pr_sysexit = src->pr_sysexit;
372*7c478bd9Sstevel@tonic-gate 	dst->pr_dmodel = src->pr_dmodel;
373*7c478bd9Sstevel@tonic-gate 
374*7c478bd9Sstevel@tonic-gate 	lwpstatus_32_to_n(&src->pr_lwp, &dst->pr_lwp);
375*7c478bd9Sstevel@tonic-gate }
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate void
378*7c478bd9Sstevel@tonic-gate lwpsinfo_32_to_n(const lwpsinfo32_t *src, lwpsinfo_t *dst)
379*7c478bd9Sstevel@tonic-gate {
380*7c478bd9Sstevel@tonic-gate 	dst->pr_flag = src->pr_flag;
381*7c478bd9Sstevel@tonic-gate 	dst->pr_lwpid = src->pr_lwpid;
382*7c478bd9Sstevel@tonic-gate 	dst->pr_addr = src->pr_addr;
383*7c478bd9Sstevel@tonic-gate 	dst->pr_wchan = src->pr_wchan;
384*7c478bd9Sstevel@tonic-gate 	dst->pr_stype = src->pr_stype;
385*7c478bd9Sstevel@tonic-gate 	dst->pr_state = src->pr_state;
386*7c478bd9Sstevel@tonic-gate 	dst->pr_sname = src->pr_sname;
387*7c478bd9Sstevel@tonic-gate 	dst->pr_nice = src->pr_nice;
388*7c478bd9Sstevel@tonic-gate 	dst->pr_syscall = src->pr_syscall;
389*7c478bd9Sstevel@tonic-gate 	dst->pr_oldpri = src->pr_oldpri;
390*7c478bd9Sstevel@tonic-gate 	dst->pr_cpu = src->pr_cpu;
391*7c478bd9Sstevel@tonic-gate 	dst->pr_pri = src->pr_pri;
392*7c478bd9Sstevel@tonic-gate 	dst->pr_pctcpu = src->pr_pctcpu;
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_start, &dst->pr_start);
395*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_time, &dst->pr_time);
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
398*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_name[0], &src->pr_name[0], PRFNSZ);
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 	dst->pr_onpro = src->pr_onpro;
401*7c478bd9Sstevel@tonic-gate 	dst->pr_bindpro = src->pr_bindpro;
402*7c478bd9Sstevel@tonic-gate 	dst->pr_bindpset = src->pr_bindpset;
403*7c478bd9Sstevel@tonic-gate }
404*7c478bd9Sstevel@tonic-gate 
405*7c478bd9Sstevel@tonic-gate void
406*7c478bd9Sstevel@tonic-gate psinfo_32_to_n(const psinfo32_t *src, psinfo_t *dst)
407*7c478bd9Sstevel@tonic-gate {
408*7c478bd9Sstevel@tonic-gate 	dst->pr_flag = src->pr_flag;
409*7c478bd9Sstevel@tonic-gate 	dst->pr_nlwp = src->pr_nlwp;
410*7c478bd9Sstevel@tonic-gate 	dst->pr_nzomb = src->pr_nzomb;
411*7c478bd9Sstevel@tonic-gate 	dst->pr_pid = src->pr_pid;
412*7c478bd9Sstevel@tonic-gate 	dst->pr_pgid = src->pr_pgid;
413*7c478bd9Sstevel@tonic-gate 	dst->pr_sid = src->pr_sid;
414*7c478bd9Sstevel@tonic-gate 	dst->pr_taskid = src->pr_taskid;
415*7c478bd9Sstevel@tonic-gate 	dst->pr_projid = src->pr_projid;
416*7c478bd9Sstevel@tonic-gate 	dst->pr_zoneid = src->pr_zoneid;
417*7c478bd9Sstevel@tonic-gate 	dst->pr_uid = src->pr_uid;
418*7c478bd9Sstevel@tonic-gate 	dst->pr_euid = src->pr_euid;
419*7c478bd9Sstevel@tonic-gate 	dst->pr_gid = src->pr_gid;
420*7c478bd9Sstevel@tonic-gate 	dst->pr_egid = src->pr_egid;
421*7c478bd9Sstevel@tonic-gate 	dst->pr_addr = src->pr_addr;
422*7c478bd9Sstevel@tonic-gate 	dst->pr_size = src->pr_size;
423*7c478bd9Sstevel@tonic-gate 	dst->pr_rssize = src->pr_rssize;
424*7c478bd9Sstevel@tonic-gate 
425*7c478bd9Sstevel@tonic-gate 	dst->pr_ttydev = prexpldev(src->pr_ttydev);
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate 	dst->pr_pctcpu = src->pr_pctcpu;
428*7c478bd9Sstevel@tonic-gate 	dst->pr_pctmem = src->pr_pctmem;
429*7c478bd9Sstevel@tonic-gate 
430*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_start, &dst->pr_start);
431*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_time, &dst->pr_time);
432*7c478bd9Sstevel@tonic-gate 	timestruc_32_to_n(&src->pr_ctime, &dst->pr_ctime);
433*7c478bd9Sstevel@tonic-gate 
434*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_fname[0], &src->pr_fname[0], PRFNSZ);
435*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_psargs[0], &src->pr_psargs[0], PRARGSZ);
436*7c478bd9Sstevel@tonic-gate 
437*7c478bd9Sstevel@tonic-gate 	dst->pr_wstat = src->pr_wstat;
438*7c478bd9Sstevel@tonic-gate 	dst->pr_argc = src->pr_argc;
439*7c478bd9Sstevel@tonic-gate 	dst->pr_argv = src->pr_argv;
440*7c478bd9Sstevel@tonic-gate 	dst->pr_envp = src->pr_envp;
441*7c478bd9Sstevel@tonic-gate 	dst->pr_dmodel = src->pr_dmodel;
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate 	lwpsinfo_32_to_n(&src->pr_lwp, &dst->pr_lwp);
444*7c478bd9Sstevel@tonic-gate }
445*7c478bd9Sstevel@tonic-gate 
446*7c478bd9Sstevel@tonic-gate void
447*7c478bd9Sstevel@tonic-gate timestruc_n_to_32(const timestruc_t *src, timestruc32_t *dst)
448*7c478bd9Sstevel@tonic-gate {
449*7c478bd9Sstevel@tonic-gate 	dst->tv_sec = (time32_t)src->tv_sec;
450*7c478bd9Sstevel@tonic-gate 	dst->tv_nsec = (int32_t)src->tv_nsec;
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate void
454*7c478bd9Sstevel@tonic-gate stack_n_to_32(const stack_t *src, stack32_t *dst)
455*7c478bd9Sstevel@tonic-gate {
456*7c478bd9Sstevel@tonic-gate 	dst->ss_sp = (caddr32_t)(uintptr_t)src->ss_sp;
457*7c478bd9Sstevel@tonic-gate 	dst->ss_size = src->ss_size;
458*7c478bd9Sstevel@tonic-gate 	dst->ss_flags = src->ss_flags;
459*7c478bd9Sstevel@tonic-gate }
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate void
462*7c478bd9Sstevel@tonic-gate sigaction_n_to_32(const struct sigaction *src, struct sigaction32 *dst)
463*7c478bd9Sstevel@tonic-gate {
464*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (struct sigaction32));
465*7c478bd9Sstevel@tonic-gate 	dst->sa_flags = src->sa_flags;
466*7c478bd9Sstevel@tonic-gate 	dst->sa_handler = (caddr32_t)(uintptr_t)src->sa_handler;
467*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->sa_mask, &src->sa_mask, sizeof (dst->sa_mask));
468*7c478bd9Sstevel@tonic-gate }
469*7c478bd9Sstevel@tonic-gate 
470*7c478bd9Sstevel@tonic-gate void
471*7c478bd9Sstevel@tonic-gate siginfo_n_to_32(const siginfo_t *src, siginfo32_t *dst)
472*7c478bd9Sstevel@tonic-gate {
473*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (siginfo32_t));
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate 	/*
476*7c478bd9Sstevel@tonic-gate 	 * The absolute minimum content is si_signo and si_code.
477*7c478bd9Sstevel@tonic-gate 	 */
478*7c478bd9Sstevel@tonic-gate 	dst->si_signo = src->si_signo;
479*7c478bd9Sstevel@tonic-gate 	if ((dst->si_code = src->si_code) == SI_NOINFO)
480*7c478bd9Sstevel@tonic-gate 		return;
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate 	/*
483*7c478bd9Sstevel@tonic-gate 	 * A siginfo generated by user level is structured
484*7c478bd9Sstevel@tonic-gate 	 * differently from one generated by the kernel.
485*7c478bd9Sstevel@tonic-gate 	 */
486*7c478bd9Sstevel@tonic-gate 	if (SI_FROMUSER(src)) {
487*7c478bd9Sstevel@tonic-gate 		dst->si_pid = src->si_pid;
488*7c478bd9Sstevel@tonic-gate 		dst->si_ctid = src->si_ctid;
489*7c478bd9Sstevel@tonic-gate 		dst->si_zoneid = src->si_zoneid;
490*7c478bd9Sstevel@tonic-gate 		dst->si_uid = src->si_uid;
491*7c478bd9Sstevel@tonic-gate 		if (SI_CANQUEUE(src->si_code)) {
492*7c478bd9Sstevel@tonic-gate 			dst->si_value.sival_int =
493*7c478bd9Sstevel@tonic-gate 			    (int32_t)src->si_value.sival_int;
494*7c478bd9Sstevel@tonic-gate 		}
495*7c478bd9Sstevel@tonic-gate 		return;
496*7c478bd9Sstevel@tonic-gate 	}
497*7c478bd9Sstevel@tonic-gate 
498*7c478bd9Sstevel@tonic-gate 	dst->si_errno = src->si_errno;
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate 	switch (src->si_signo) {
501*7c478bd9Sstevel@tonic-gate 	default:
502*7c478bd9Sstevel@tonic-gate 		dst->si_pid = src->si_pid;
503*7c478bd9Sstevel@tonic-gate 		dst->si_ctid = src->si_ctid;
504*7c478bd9Sstevel@tonic-gate 		dst->si_zoneid = src->si_zoneid;
505*7c478bd9Sstevel@tonic-gate 		dst->si_uid = src->si_uid;
506*7c478bd9Sstevel@tonic-gate 		dst->si_value.sival_int =
507*7c478bd9Sstevel@tonic-gate 		    (int32_t)src->si_value.sival_int;
508*7c478bd9Sstevel@tonic-gate 		break;
509*7c478bd9Sstevel@tonic-gate 	case SIGCLD:
510*7c478bd9Sstevel@tonic-gate 		dst->si_pid = src->si_pid;
511*7c478bd9Sstevel@tonic-gate 		dst->si_ctid = src->si_ctid;
512*7c478bd9Sstevel@tonic-gate 		dst->si_zoneid = src->si_zoneid;
513*7c478bd9Sstevel@tonic-gate 		dst->si_status = src->si_status;
514*7c478bd9Sstevel@tonic-gate 		dst->si_stime = src->si_stime;
515*7c478bd9Sstevel@tonic-gate 		dst->si_utime = src->si_utime;
516*7c478bd9Sstevel@tonic-gate 		break;
517*7c478bd9Sstevel@tonic-gate 	case SIGSEGV:
518*7c478bd9Sstevel@tonic-gate 	case SIGBUS:
519*7c478bd9Sstevel@tonic-gate 	case SIGILL:
520*7c478bd9Sstevel@tonic-gate 	case SIGTRAP:
521*7c478bd9Sstevel@tonic-gate 	case SIGFPE:
522*7c478bd9Sstevel@tonic-gate 	case SIGEMT:
523*7c478bd9Sstevel@tonic-gate 		dst->si_addr = (caddr32_t)(uintptr_t)src->si_addr;
524*7c478bd9Sstevel@tonic-gate 		dst->si_trapno = src->si_trapno;
525*7c478bd9Sstevel@tonic-gate 		dst->si_pc = (caddr32_t)(uintptr_t)src->si_pc;
526*7c478bd9Sstevel@tonic-gate 		break;
527*7c478bd9Sstevel@tonic-gate 	case SIGPOLL:
528*7c478bd9Sstevel@tonic-gate 	case SIGXFSZ:
529*7c478bd9Sstevel@tonic-gate 		dst->si_fd = src->si_fd;
530*7c478bd9Sstevel@tonic-gate 		dst->si_band = src->si_band;
531*7c478bd9Sstevel@tonic-gate 		break;
532*7c478bd9Sstevel@tonic-gate 	case SIGPROF:
533*7c478bd9Sstevel@tonic-gate 		dst->si_faddr = (caddr32_t)(uintptr_t)src->si_faddr;
534*7c478bd9Sstevel@tonic-gate 		dst->si_tstamp.tv_sec = src->si_tstamp.tv_sec;
535*7c478bd9Sstevel@tonic-gate 		dst->si_tstamp.tv_nsec = src->si_tstamp.tv_nsec;
536*7c478bd9Sstevel@tonic-gate 		dst->si_syscall = src->si_syscall;
537*7c478bd9Sstevel@tonic-gate 		dst->si_nsysarg = src->si_nsysarg;
538*7c478bd9Sstevel@tonic-gate 		dst->si_fault = src->si_fault;
539*7c478bd9Sstevel@tonic-gate 		break;
540*7c478bd9Sstevel@tonic-gate 	}
541*7c478bd9Sstevel@tonic-gate }
542*7c478bd9Sstevel@tonic-gate 
543*7c478bd9Sstevel@tonic-gate void
544*7c478bd9Sstevel@tonic-gate auxv_n_to_32(const auxv_t *src, auxv32_t *dst)
545*7c478bd9Sstevel@tonic-gate {
546*7c478bd9Sstevel@tonic-gate 	dst->a_type = src->a_type;
547*7c478bd9Sstevel@tonic-gate 	dst->a_un.a_ptr = (caddr32_t)(uintptr_t)src->a_un.a_ptr;
548*7c478bd9Sstevel@tonic-gate }
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate void
551*7c478bd9Sstevel@tonic-gate prgregset_n_to_32(const prgreg_t *src, prgreg32_t *dst)
552*7c478bd9Sstevel@tonic-gate {
553*7c478bd9Sstevel@tonic-gate #ifdef __amd64
554*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, NPRGREG32 * sizeof (prgreg32_t));
555*7c478bd9Sstevel@tonic-gate 	dst[GS] = src[REG_GS];
556*7c478bd9Sstevel@tonic-gate 	dst[FS] = src[REG_FS];
557*7c478bd9Sstevel@tonic-gate 	dst[DS] = src[REG_DS];
558*7c478bd9Sstevel@tonic-gate 	dst[ES] = src[REG_ES];
559*7c478bd9Sstevel@tonic-gate 	dst[EDI] = src[REG_RDI];
560*7c478bd9Sstevel@tonic-gate 	dst[ESI] = src[REG_RSI];
561*7c478bd9Sstevel@tonic-gate 	dst[EBP] = src[REG_RBP];
562*7c478bd9Sstevel@tonic-gate 	dst[EBX] = src[REG_RBX];
563*7c478bd9Sstevel@tonic-gate 	dst[EDX] = src[REG_RDX];
564*7c478bd9Sstevel@tonic-gate 	dst[ECX] = src[REG_RCX];
565*7c478bd9Sstevel@tonic-gate 	dst[EAX] = src[REG_RAX];
566*7c478bd9Sstevel@tonic-gate 	dst[TRAPNO] = src[REG_TRAPNO];
567*7c478bd9Sstevel@tonic-gate 	dst[ERR] = src[REG_ERR];
568*7c478bd9Sstevel@tonic-gate 	dst[EIP] = src[REG_RIP];
569*7c478bd9Sstevel@tonic-gate 	dst[CS] = src[REG_CS];
570*7c478bd9Sstevel@tonic-gate 	dst[EFL] = src[REG_RFL];
571*7c478bd9Sstevel@tonic-gate 	dst[UESP] = src[REG_RSP];
572*7c478bd9Sstevel@tonic-gate 	dst[SS] = src[REG_SS];
573*7c478bd9Sstevel@tonic-gate #else
574*7c478bd9Sstevel@tonic-gate 	int i;
575*7c478bd9Sstevel@tonic-gate 
576*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NPRGREG; i++)
577*7c478bd9Sstevel@tonic-gate 		dst[i] = (prgreg32_t)src[i];
578*7c478bd9Sstevel@tonic-gate #endif
579*7c478bd9Sstevel@tonic-gate }
580*7c478bd9Sstevel@tonic-gate 
581*7c478bd9Sstevel@tonic-gate void
582*7c478bd9Sstevel@tonic-gate prfpregset_n_to_32(const prfpregset_t *src, prfpregset32_t *dst)
583*7c478bd9Sstevel@tonic-gate {
584*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
585*7c478bd9Sstevel@tonic-gate 	int i;
586*7c478bd9Sstevel@tonic-gate 
587*7c478bd9Sstevel@tonic-gate 	(void) memset(dst, 0, sizeof (prfpregset32_t));
588*7c478bd9Sstevel@tonic-gate 
589*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 32; i++)
590*7c478bd9Sstevel@tonic-gate 		dst->pr_fr.pr_regs[i] = src->pr_fr.pr_regs[i];
591*7c478bd9Sstevel@tonic-gate 
592*7c478bd9Sstevel@tonic-gate 	dst->pr_filler = src->pr_filler;
593*7c478bd9Sstevel@tonic-gate 	dst->pr_fsr = src->pr_fsr;
594*7c478bd9Sstevel@tonic-gate 	dst->pr_q_entrysize = src->pr_q_entrysize;
595*7c478bd9Sstevel@tonic-gate 	dst->pr_en = src->pr_en;
596*7c478bd9Sstevel@tonic-gate 
597*7c478bd9Sstevel@tonic-gate #elif defined(__amd64)
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 	struct _fpstate32 *dst32 = (struct _fpstate32 *)dst;
600*7c478bd9Sstevel@tonic-gate 	struct fpchip_state *src64 = (struct fpchip_state *)src;
601*7c478bd9Sstevel@tonic-gate 	uint32_t top;
602*7c478bd9Sstevel@tonic-gate 	int i;
603*7c478bd9Sstevel@tonic-gate 
604*7c478bd9Sstevel@tonic-gate 	(void) memcpy(dst32->_st, src64->st, sizeof (dst32->_st));
605*7c478bd9Sstevel@tonic-gate 	(void) memcpy(dst32->xmm, src64->xmm, sizeof (dst32->xmm));
606*7c478bd9Sstevel@tonic-gate 	dst32->cw = src64->cw;
607*7c478bd9Sstevel@tonic-gate 	dst32->sw = src64->sw;
608*7c478bd9Sstevel@tonic-gate 	dst32->ipoff = (unsigned int)src64->rip;
609*7c478bd9Sstevel@tonic-gate 	dst32->cssel = 0;
610*7c478bd9Sstevel@tonic-gate 	dst32->dataoff = (unsigned int)src64->rdp;
611*7c478bd9Sstevel@tonic-gate 	dst32->datasel = 0;
612*7c478bd9Sstevel@tonic-gate 	dst32->status = src64->status;
613*7c478bd9Sstevel@tonic-gate 	dst32->mxcsr = src64->mxcsr;
614*7c478bd9Sstevel@tonic-gate 	dst32->xstatus = src64->xstatus;
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 	/*
617*7c478bd9Sstevel@tonic-gate 	 * AMD64 stores the tag in a compressed form. It is
618*7c478bd9Sstevel@tonic-gate 	 * necessary to extract the original 2-bit tag value.
619*7c478bd9Sstevel@tonic-gate 	 * See AMD64 Architecture Programmer's Manual Volume 2:
620*7c478bd9Sstevel@tonic-gate 	 * System Programming, Chapter 11.
621*7c478bd9Sstevel@tonic-gate 	 */
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate 	top = (src64->sw & FPS_TOP) >> 11;
624*7c478bd9Sstevel@tonic-gate 	dst32->tag = 0;
625*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
626*7c478bd9Sstevel@tonic-gate 		/*
627*7c478bd9Sstevel@tonic-gate 		 * Recall that we need to use the current TOP-of-stack value to
628*7c478bd9Sstevel@tonic-gate 		 * associate the _st[] index back to a physical register number,
629*7c478bd9Sstevel@tonic-gate 		 * since tag word indices are physical register numbers.  Then
630*7c478bd9Sstevel@tonic-gate 		 * to get the tag value, we shift over two bits for each tag
631*7c478bd9Sstevel@tonic-gate 		 * index, and then grab the bottom two bits.
632*7c478bd9Sstevel@tonic-gate 		 */
633*7c478bd9Sstevel@tonic-gate 		uint_t tag_index = (i + top) & 7;
634*7c478bd9Sstevel@tonic-gate 		uint_t tag_fctw = (src64->fctw >> tag_index) & 1;
635*7c478bd9Sstevel@tonic-gate 		uint_t tag_value;
636*7c478bd9Sstevel@tonic-gate 		uint_t exp;
637*7c478bd9Sstevel@tonic-gate 
638*7c478bd9Sstevel@tonic-gate 		/*
639*7c478bd9Sstevel@tonic-gate 		 * Union for overlaying _fpreg structure on to quad-precision
640*7c478bd9Sstevel@tonic-gate 		 * floating-point value (long double).
641*7c478bd9Sstevel@tonic-gate 		 */
642*7c478bd9Sstevel@tonic-gate 		union {
643*7c478bd9Sstevel@tonic-gate 			struct _fpreg reg;
644*7c478bd9Sstevel@tonic-gate 			long double ld;
645*7c478bd9Sstevel@tonic-gate 		} fpru;
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate 		fpru.ld = src64->st[i].__fpr_pad._q;
648*7c478bd9Sstevel@tonic-gate 		exp = fpru.reg.exponent & 0x7fff;
649*7c478bd9Sstevel@tonic-gate 
650*7c478bd9Sstevel@tonic-gate 		if (tag_fctw == 0) {
651*7c478bd9Sstevel@tonic-gate 			tag_value = 3; /* empty */
652*7c478bd9Sstevel@tonic-gate 		} else if (exp == 0) {
653*7c478bd9Sstevel@tonic-gate 			if (fpru.reg.significand[0] == 0 &&
654*7c478bd9Sstevel@tonic-gate 			    fpru.reg.significand[1] == 0 &&
655*7c478bd9Sstevel@tonic-gate 			    fpru.reg.significand[2] == 0 &&
656*7c478bd9Sstevel@tonic-gate 			    fpru.reg.significand[3] == 0)
657*7c478bd9Sstevel@tonic-gate 				tag_value = 1; /* zero */
658*7c478bd9Sstevel@tonic-gate 			else
659*7c478bd9Sstevel@tonic-gate 				tag_value = 2; /* special: denormal */
660*7c478bd9Sstevel@tonic-gate 		} else if (exp == 0x7fff) {
661*7c478bd9Sstevel@tonic-gate 			tag_value = 2; /* special: infinity or NaN */
662*7c478bd9Sstevel@tonic-gate 		} else if (fpru.reg.significand[3] & 0x8000) {
663*7c478bd9Sstevel@tonic-gate 			tag_value = 0; /* valid */
664*7c478bd9Sstevel@tonic-gate 		} else {
665*7c478bd9Sstevel@tonic-gate 			tag_value = 2; /* special: unnormal */
666*7c478bd9Sstevel@tonic-gate 		}
667*7c478bd9Sstevel@tonic-gate 		dst32->tag |= tag_value << (tag_index * 2);
668*7c478bd9Sstevel@tonic-gate 	}
669*7c478bd9Sstevel@tonic-gate #else
670*7c478bd9Sstevel@tonic-gate #error "unrecognized ISA"
671*7c478bd9Sstevel@tonic-gate #endif
672*7c478bd9Sstevel@tonic-gate }
673*7c478bd9Sstevel@tonic-gate 
674*7c478bd9Sstevel@tonic-gate void
675*7c478bd9Sstevel@tonic-gate lwpstatus_n_to_32(const lwpstatus_t *src, lwpstatus32_t *dst)
676*7c478bd9Sstevel@tonic-gate {
677*7c478bd9Sstevel@tonic-gate 	int i;
678*7c478bd9Sstevel@tonic-gate 
679*7c478bd9Sstevel@tonic-gate 	dst->pr_flags = src->pr_flags;
680*7c478bd9Sstevel@tonic-gate 	dst->pr_lwpid = src->pr_lwpid;
681*7c478bd9Sstevel@tonic-gate 	dst->pr_why = src->pr_why;
682*7c478bd9Sstevel@tonic-gate 	dst->pr_what = src->pr_what;
683*7c478bd9Sstevel@tonic-gate 	dst->pr_cursig = src->pr_cursig;
684*7c478bd9Sstevel@tonic-gate 
685*7c478bd9Sstevel@tonic-gate 	siginfo_n_to_32(&src->pr_info, &dst->pr_info);
686*7c478bd9Sstevel@tonic-gate 
687*7c478bd9Sstevel@tonic-gate 	dst->pr_lwppend = src->pr_lwppend;
688*7c478bd9Sstevel@tonic-gate 	dst->pr_lwphold = src->pr_lwphold;
689*7c478bd9Sstevel@tonic-gate 
690*7c478bd9Sstevel@tonic-gate 	sigaction_n_to_32(&src->pr_action, &dst->pr_action);
691*7c478bd9Sstevel@tonic-gate 	stack_n_to_32(&src->pr_altstack, &dst->pr_altstack);
692*7c478bd9Sstevel@tonic-gate 
693*7c478bd9Sstevel@tonic-gate 	dst->pr_oldcontext = (caddr32_t)src->pr_oldcontext;
694*7c478bd9Sstevel@tonic-gate 	dst->pr_syscall = src->pr_syscall;
695*7c478bd9Sstevel@tonic-gate 	dst->pr_nsysarg = src->pr_nsysarg;
696*7c478bd9Sstevel@tonic-gate 	dst->pr_errno = src->pr_errno;
697*7c478bd9Sstevel@tonic-gate 
698*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < PRSYSARGS; i++)
699*7c478bd9Sstevel@tonic-gate 		dst->pr_sysarg[i] = (int32_t)src->pr_sysarg[i];
700*7c478bd9Sstevel@tonic-gate 
701*7c478bd9Sstevel@tonic-gate 	dst->pr_rval1 = (int32_t)src->pr_rval1;
702*7c478bd9Sstevel@tonic-gate 	dst->pr_rval2 = (int32_t)src->pr_rval2;
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
705*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_tstamp, &dst->pr_tstamp);
706*7c478bd9Sstevel@tonic-gate 
707*7c478bd9Sstevel@tonic-gate 	dst->pr_ustack = (caddr32_t)src->pr_ustack;
708*7c478bd9Sstevel@tonic-gate 	dst->pr_instr = src->pr_instr;
709*7c478bd9Sstevel@tonic-gate 
710*7c478bd9Sstevel@tonic-gate 	prgregset_n_to_32(src->pr_reg, dst->pr_reg);
711*7c478bd9Sstevel@tonic-gate 	prfpregset_n_to_32(&src->pr_fpreg, &dst->pr_fpreg);
712*7c478bd9Sstevel@tonic-gate }
713*7c478bd9Sstevel@tonic-gate 
714*7c478bd9Sstevel@tonic-gate void
715*7c478bd9Sstevel@tonic-gate pstatus_n_to_32(const pstatus_t *src, pstatus32_t *dst)
716*7c478bd9Sstevel@tonic-gate {
717*7c478bd9Sstevel@tonic-gate 	dst->pr_flags = src->pr_flags;
718*7c478bd9Sstevel@tonic-gate 	dst->pr_nlwp = src->pr_nlwp;
719*7c478bd9Sstevel@tonic-gate 	dst->pr_nzomb = src->pr_nzomb;
720*7c478bd9Sstevel@tonic-gate 	dst->pr_pid = (pid32_t)src->pr_pid;
721*7c478bd9Sstevel@tonic-gate 	dst->pr_ppid = (pid32_t)src->pr_ppid;
722*7c478bd9Sstevel@tonic-gate 	dst->pr_pgid = (pid32_t)src->pr_pgid;
723*7c478bd9Sstevel@tonic-gate 	dst->pr_sid = (pid32_t)src->pr_sid;
724*7c478bd9Sstevel@tonic-gate 	dst->pr_taskid = (id32_t)src->pr_taskid;
725*7c478bd9Sstevel@tonic-gate 	dst->pr_projid = (id32_t)src->pr_projid;
726*7c478bd9Sstevel@tonic-gate 	dst->pr_zoneid = (id32_t)src->pr_zoneid;
727*7c478bd9Sstevel@tonic-gate 	dst->pr_aslwpid = (id32_t)src->pr_aslwpid;
728*7c478bd9Sstevel@tonic-gate 	dst->pr_agentid = (id32_t)src->pr_agentid;
729*7c478bd9Sstevel@tonic-gate 	dst->pr_sigpend = src->pr_sigpend;
730*7c478bd9Sstevel@tonic-gate 	dst->pr_brkbase = (caddr32_t)src->pr_brkbase;
731*7c478bd9Sstevel@tonic-gate 	dst->pr_brksize = (size32_t)src->pr_brksize;
732*7c478bd9Sstevel@tonic-gate 	dst->pr_stkbase = (caddr32_t)src->pr_stkbase;
733*7c478bd9Sstevel@tonic-gate 	dst->pr_stksize = (size32_t)src->pr_stksize;
734*7c478bd9Sstevel@tonic-gate 
735*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_utime, &dst->pr_utime);
736*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_stime, &dst->pr_stime);
737*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_cutime, &dst->pr_cutime);
738*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_cstime, &dst->pr_cstime);
739*7c478bd9Sstevel@tonic-gate 
740*7c478bd9Sstevel@tonic-gate 	dst->pr_sigtrace = src->pr_sigtrace;
741*7c478bd9Sstevel@tonic-gate 	dst->pr_flttrace = src->pr_flttrace;
742*7c478bd9Sstevel@tonic-gate 	dst->pr_sysentry = src->pr_sysentry;
743*7c478bd9Sstevel@tonic-gate 	dst->pr_sysexit = src->pr_sysexit;
744*7c478bd9Sstevel@tonic-gate 	dst->pr_dmodel = src->pr_dmodel;
745*7c478bd9Sstevel@tonic-gate 
746*7c478bd9Sstevel@tonic-gate 	lwpstatus_n_to_32(&src->pr_lwp, &dst->pr_lwp);
747*7c478bd9Sstevel@tonic-gate }
748*7c478bd9Sstevel@tonic-gate 
749*7c478bd9Sstevel@tonic-gate void
750*7c478bd9Sstevel@tonic-gate lwpsinfo_n_to_32(const lwpsinfo_t *src, lwpsinfo32_t *dst)
751*7c478bd9Sstevel@tonic-gate {
752*7c478bd9Sstevel@tonic-gate 	dst->pr_flag = src->pr_flag;
753*7c478bd9Sstevel@tonic-gate 	dst->pr_lwpid = (id32_t)src->pr_lwpid;
754*7c478bd9Sstevel@tonic-gate 	dst->pr_addr = (caddr32_t)src->pr_addr;
755*7c478bd9Sstevel@tonic-gate 	dst->pr_wchan = (caddr32_t)src->pr_wchan;
756*7c478bd9Sstevel@tonic-gate 	dst->pr_stype = src->pr_stype;
757*7c478bd9Sstevel@tonic-gate 	dst->pr_state = src->pr_state;
758*7c478bd9Sstevel@tonic-gate 	dst->pr_sname = src->pr_sname;
759*7c478bd9Sstevel@tonic-gate 	dst->pr_nice = src->pr_nice;
760*7c478bd9Sstevel@tonic-gate 	dst->pr_syscall = src->pr_syscall;
761*7c478bd9Sstevel@tonic-gate 	dst->pr_oldpri = src->pr_oldpri;
762*7c478bd9Sstevel@tonic-gate 	dst->pr_cpu = src->pr_cpu;
763*7c478bd9Sstevel@tonic-gate 	dst->pr_pri = src->pr_pri;
764*7c478bd9Sstevel@tonic-gate 	dst->pr_pctcpu = src->pr_pctcpu;
765*7c478bd9Sstevel@tonic-gate 
766*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_start, &dst->pr_start);
767*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_time, &dst->pr_time);
768*7c478bd9Sstevel@tonic-gate 
769*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
770*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_name[0], &src->pr_name[0], PRFNSZ);
771*7c478bd9Sstevel@tonic-gate 
772*7c478bd9Sstevel@tonic-gate 	dst->pr_onpro = src->pr_onpro;
773*7c478bd9Sstevel@tonic-gate 	dst->pr_bindpro = src->pr_bindpro;
774*7c478bd9Sstevel@tonic-gate 	dst->pr_bindpset = src->pr_bindpset;
775*7c478bd9Sstevel@tonic-gate }
776*7c478bd9Sstevel@tonic-gate 
777*7c478bd9Sstevel@tonic-gate void
778*7c478bd9Sstevel@tonic-gate psinfo_n_to_32(const psinfo_t *src, psinfo32_t *dst)
779*7c478bd9Sstevel@tonic-gate {
780*7c478bd9Sstevel@tonic-gate 	dst->pr_flag = src->pr_flag;
781*7c478bd9Sstevel@tonic-gate 	dst->pr_nlwp = src->pr_nlwp;
782*7c478bd9Sstevel@tonic-gate 	dst->pr_nzomb = src->pr_nzomb;
783*7c478bd9Sstevel@tonic-gate 	dst->pr_pid = (pid32_t)src->pr_pid;
784*7c478bd9Sstevel@tonic-gate 	dst->pr_pgid = (pid32_t)src->pr_pgid;
785*7c478bd9Sstevel@tonic-gate 	dst->pr_sid = (pid32_t)src->pr_sid;
786*7c478bd9Sstevel@tonic-gate 	dst->pr_taskid = (id32_t)src->pr_taskid;
787*7c478bd9Sstevel@tonic-gate 	dst->pr_projid = (id32_t)src->pr_projid;
788*7c478bd9Sstevel@tonic-gate 	dst->pr_zoneid = (id32_t)src->pr_zoneid;
789*7c478bd9Sstevel@tonic-gate 	dst->pr_uid = (uid32_t)src->pr_uid;
790*7c478bd9Sstevel@tonic-gate 	dst->pr_euid = (uid32_t)src->pr_euid;
791*7c478bd9Sstevel@tonic-gate 	dst->pr_gid = (gid32_t)src->pr_gid;
792*7c478bd9Sstevel@tonic-gate 	dst->pr_egid = (gid32_t)src->pr_egid;
793*7c478bd9Sstevel@tonic-gate 	dst->pr_addr = (caddr32_t)src->pr_addr;
794*7c478bd9Sstevel@tonic-gate 	dst->pr_size = (size32_t)src->pr_size;
795*7c478bd9Sstevel@tonic-gate 	dst->pr_rssize = (size32_t)src->pr_rssize;
796*7c478bd9Sstevel@tonic-gate 
797*7c478bd9Sstevel@tonic-gate 	dst->pr_ttydev = prcmpldev(src->pr_ttydev);
798*7c478bd9Sstevel@tonic-gate 
799*7c478bd9Sstevel@tonic-gate 	dst->pr_pctcpu = src->pr_pctcpu;
800*7c478bd9Sstevel@tonic-gate 	dst->pr_pctmem = src->pr_pctmem;
801*7c478bd9Sstevel@tonic-gate 
802*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_start, &dst->pr_start);
803*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_time, &dst->pr_time);
804*7c478bd9Sstevel@tonic-gate 	timestruc_n_to_32(&src->pr_ctime, &dst->pr_ctime);
805*7c478bd9Sstevel@tonic-gate 
806*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_fname[0], &src->pr_fname[0], PRFNSZ);
807*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&dst->pr_psargs[0], &src->pr_psargs[0], PRARGSZ);
808*7c478bd9Sstevel@tonic-gate 
809*7c478bd9Sstevel@tonic-gate 	dst->pr_wstat = src->pr_wstat;
810*7c478bd9Sstevel@tonic-gate 	dst->pr_argc = src->pr_argc;
811*7c478bd9Sstevel@tonic-gate 	dst->pr_argv = (caddr32_t)src->pr_argv;
812*7c478bd9Sstevel@tonic-gate 	dst->pr_envp = (caddr32_t)src->pr_envp;
813*7c478bd9Sstevel@tonic-gate 	dst->pr_dmodel = src->pr_dmodel;
814*7c478bd9Sstevel@tonic-gate 
815*7c478bd9Sstevel@tonic-gate 	lwpsinfo_n_to_32(&src->pr_lwp, &dst->pr_lwp);
816*7c478bd9Sstevel@tonic-gate }
817*7c478bd9Sstevel@tonic-gate 
818*7c478bd9Sstevel@tonic-gate 
819*7c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
820