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  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_PISADEP_H
28 #define	_PISADEP_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * Internal ISA-dependent functions.
36  *
37  * Note that some ISA-dependent functions are exposed to applications, and found
38  * in libproc.h:
39  *
40  * 	Ppltdest()
41  * 	Pissyscall_prev()
42  * 	Pstack_iter()
43  */
44 
45 /*
46  * ISA dependent function to determine if the instruction at the given address
47  * is a syscall instruction.  On x86, we have multiple system call instructions.
48  * this function returns 1 if there is a system call at the given address, 2 if
49  * there is a less preferred system call, and 0 if there is no system call
50  * there.
51  */
52 extern int Pissyscall(struct ps_prochandle *, uintptr_t);
53 /*
54  * Works the same way as Pissyscall(), except operates on an in-memory buffer.
55  */
56 extern int Pissyscall_text(struct ps_prochandle *, const void *buf,
57     size_t buflen);
58 
59 #if defined(__amd64)
60 /* amd64 stack doubleword aligned, unaligned in 32-bit mode  */
61 #define	PSTACK_ALIGN32(sp)	((sp) & ~(2 * sizeof (int64_t) - 1))
62 #define	PSTACK_ALIGN64(sp)	(sp)
63 #elif defined(__i386)
64 /* i386 stack is unaligned */
65 #define	PSTACK_ALIGN32(sp)	(sp)
66 #define	PSTACK_ALIGN64(sp)	ALIGN32(sp)
67 #elif defined(__sparc)
68 /* sparc stack is doubleword aligned for 64-bit values */
69 #define	PSTACK_ALIGN32(sp)	((sp) & ~(2 * sizeof (int32_t) - 1))
70 #define	PSTACK_ALIGN64(sp)	((sp) & ~(2 * sizeof (int64_t) - 1))
71 #else
72 #error	Unknown ISA
73 #endif
74 
75 /*
76  * Given an argument count, stack pointer, and syscall index, sets up the stack
77  * and appropriate registers.  The stack pointer should be the top of the stack
78  * area, after any space reserved for arguments passed by reference.  Returns a
79  * pointer which is later passed to Psyscall_copyargs().
80  */
81 extern uintptr_t Psyscall_setup(struct ps_prochandle *, int, int, uintptr_t);
82 
83 /*
84  * Copies all arguments out to the stack once we're stopped before the syscall.
85  */
86 extern int Psyscall_copyinargs(struct ps_prochandle *, int, argdes_t *,
87     uintptr_t);
88 
89 /*
90  * Copies out arguments to their original values.
91  */
92 extern int Psyscall_copyoutargs(struct ps_prochandle *, int, argdes_t *,
93     uintptr_t);
94 
95 #ifdef	__cplusplus
96 }
97 #endif
98 
99 #endif	/* _PISADEP_H */
100