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