xref: /illumos-gate/usr/src/lib/abi/apptrace/common/mach.h (revision 86d949f9497332fe19be6b5d711d265eb957439f)
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 _MACH_H
28 #define	_MACH_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/reg.h>
35 #include <sys/types.h>
36 
37 #if defined(__sparc)
38 
39 #define	GETARG0(regset)		regset->lr_rego0
40 #define	GETARG1(regset)		regset->lr_rego1
41 #define	GETARG2(regset)		regset->lr_rego2
42 #define	GETARG3(regset)		regset->lr_rego3
43 #define	GETARG4(regset)		regset->lr_rego4
44 #define	GETARG5(regset)		regset->lr_rego5
45 
46 #define	GETARG_6NUP(i, regset)	(((ulong_t *)regset->lr_rego6)[23+i-6])
47 
48 #define	GETFRAME(regset)	regset->lr_rego6
49 #define	GETPREVPC(regset)	regset->lr_rego7
50 
51 #elif defined(__amd64)
52 
53 #define	GETARG0(regset)		regset->lr_rdi
54 #define	GETARG1(regset)		regset->lr_rsi
55 #define	GETARG2(regset)		regset->lr_rdx
56 #define	GETARG3(regset)		regset->lr_rcx
57 #define	GETARG4(regset)		regset->lr_r8
58 #define	GETARG5(regset)		regset->lr_r9
59 
60 #define	GETARG_6NUP(i, regset)	(((ulong_t *)regset->lr_rsp)[i+1-6])
61 
62 #define	GETFRAME(regset)	(regset->lr_rbp)
63 #define	GETPREVPC(regset)	(*(uintptr_t *)regset->lr_rsp)
64 
65 #elif defined(i386)
66 
67 #define	GETARG0(regset)		(((ulong_t *)regset->lr_esp)[1])
68 #define	GETARG1(regset)		(((ulong_t *)regset->lr_esp)[2])
69 #define	GETARG2(regset)		(((ulong_t *)regset->lr_esp)[3])
70 #define	GETARG3(regset)		(((ulong_t *)regset->lr_esp)[4])
71 #define	GETARG4(regset)		(((ulong_t *)regset->lr_esp)[5])
72 #define	GETARG5(regset)		(((ulong_t *)regset->lr_esp)[6])
73 
74 #define	GETARG_6NUP(i, regset)	(((ulong_t *)regset->lr_esp)[i+1])
75 
76 #define	GETFRAME(regset)	(regset->lr_ebp)
77 #define	GETPREVPC(regset)	(*(uintptr_t *)regset->lr_esp)
78 #else
79 #error	unsupported architecture!
80 #endif
81 
82 #ifdef	__cplusplus
83 }
84 #endif
85 
86 #endif /* _MACH_H */
87