xref: /onnv-gate/usr/src/uts/sparc/sys/stack.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _SYS_STACK_H
28*0Sstevel@tonic-gate #define	_SYS_STACK_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #if !defined(_ASM)
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <sys/types.h>
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #endif
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #ifdef	__cplusplus
39*0Sstevel@tonic-gate extern "C" {
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * A stack frame looks like:
44*0Sstevel@tonic-gate  *
45*0Sstevel@tonic-gate  * %fp->|				|
46*0Sstevel@tonic-gate  *	|-------------------------------|
47*0Sstevel@tonic-gate  *	|  Locals, temps, saved floats	|
48*0Sstevel@tonic-gate  *	|-------------------------------|
49*0Sstevel@tonic-gate  *	|  outgoing parameters past 6	|
50*0Sstevel@tonic-gate  *	|-------------------------------|-\
51*0Sstevel@tonic-gate  *	|  6 words for callee to dump	| |
52*0Sstevel@tonic-gate  *	|  register arguments		| |
53*0Sstevel@tonic-gate  *	|-------------------------------|  > minimum stack frame
54*0Sstevel@tonic-gate  *	|  One word struct-ret address	| |
55*0Sstevel@tonic-gate  *	|-------------------------------| |
56*0Sstevel@tonic-gate  *	|  16 words to save IN and	| |
57*0Sstevel@tonic-gate  * %sp->|  LOCAL register on overflow	| |
58*0Sstevel@tonic-gate  *	|-------------------------------|-/
59*0Sstevel@tonic-gate  */
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate /*
62*0Sstevel@tonic-gate  * Constants defining a 32-bit stack frame.
63*0Sstevel@tonic-gate  */
64*0Sstevel@tonic-gate #define	WINDOWSIZE32	(16*4)		/* size of window save area */
65*0Sstevel@tonic-gate #define	ARGPUSHSIZE32	(6*4)		/* size of arg dump area */
66*0Sstevel@tonic-gate #define	ARGPUSH32	(WINDOWSIZE32 + 4)	/* arg dump area offset */
67*0Sstevel@tonic-gate #define	MINFRAME32	(WINDOWSIZE32 + ARGPUSHSIZE32 + 4) /* min frame */
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate #define	STACK_GROWTH_DOWN /* stacks grow from high to low addresses */
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate  * Stack alignment macros.
73*0Sstevel@tonic-gate  */
74*0Sstevel@tonic-gate #define	STACK_ALIGN32		8
75*0Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN32	8
76*0Sstevel@tonic-gate #define	SA32(X)			(((X)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1))
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate #if defined(__sparcv9)
79*0Sstevel@tonic-gate /*
80*0Sstevel@tonic-gate  * The 64-bit C ABI uses a stack frame that looks like:
81*0Sstevel@tonic-gate  *
82*0Sstevel@tonic-gate  *      |				|
83*0Sstevel@tonic-gate  *	|-------------------------------|
84*0Sstevel@tonic-gate  *	|  Locals, temps, saved floats	|
85*0Sstevel@tonic-gate  *	|-------------------------------|
86*0Sstevel@tonic-gate  *	|  outgoing parameters past 6	|
87*0Sstevel@tonic-gate  *	|-------------------------------|-\
88*0Sstevel@tonic-gate  *	|  outgoing parameters thru 6	| |
89*0Sstevel@tonic-gate  *	|-------------------------------|  > minimum stack frame
90*0Sstevel@tonic-gate  *	|  16 xwords to save IN and	| |
91*0Sstevel@tonic-gate  *      |  LOCAL register on overflow	| |
92*0Sstevel@tonic-gate  *	|-------------------------------|-/-\
93*0Sstevel@tonic-gate  *      |				|   |
94*0Sstevel@tonic-gate  *      |				|    > v9 abi bias
95*0Sstevel@tonic-gate  *      |				|   |
96*0Sstevel@tonic-gate  * %sp->|-------------------------------|---/
97*0Sstevel@tonic-gate  */
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate /*
100*0Sstevel@tonic-gate  * Constants defining a stack frame.
101*0Sstevel@tonic-gate  */
102*0Sstevel@tonic-gate #define	WINDOWSIZE64		(16*8)		/* size of window save area */
103*0Sstevel@tonic-gate #define	ARGPUSHSIZE64		(6*8)		/* size of arg dump area */
104*0Sstevel@tonic-gate #define	MINFRAME64		(WINDOWSIZE64 + 48)	/* min frame */
105*0Sstevel@tonic-gate #define	ARGPUSH64		(WINDOWSIZE64)	/* arg dump area offset */
106*0Sstevel@tonic-gate #define	V9BIAS64		(2048-1)	/* v9 abi stack bias */
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate #define	STACK_ALIGN64		16
109*0Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN64	16
110*0Sstevel@tonic-gate #define	SA64(X)			(((X)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1))
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate #define	IS_V9STACK(x)		((((uintptr_t)(x) + V9BIAS64) & \
113*0Sstevel@tonic-gate 				(STACK_ALIGN64-1)) == 0)
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate #define	WINDOWSIZE		WINDOWSIZE64
116*0Sstevel@tonic-gate #define	ARGPUSHSIZE		ARGPUSHSIZE64
117*0Sstevel@tonic-gate #define	ARGPUSH			ARGPUSH64
118*0Sstevel@tonic-gate #define	MINFRAME		MINFRAME64
119*0Sstevel@tonic-gate #define	STACK_ALIGN		STACK_ALIGN64
120*0Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN64
121*0Sstevel@tonic-gate #define	STACK_BIAS		V9BIAS64
122*0Sstevel@tonic-gate #define	SA(x)			SA64(x)
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate #else
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate #define	WINDOWSIZE		WINDOWSIZE32
127*0Sstevel@tonic-gate #define	ARGPUSHSIZE		ARGPUSHSIZE32
128*0Sstevel@tonic-gate #define	ARGPUSH			ARGPUSH32
129*0Sstevel@tonic-gate #define	MINFRAME		MINFRAME32
130*0Sstevel@tonic-gate #define	STACK_ALIGN		STACK_ALIGN32
131*0Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN32
132*0Sstevel@tonic-gate #define	STACK_BIAS		0
133*0Sstevel@tonic-gate #define	SA(x)			SA32(x)
134*0Sstevel@tonic-gate #define	STACK_V9BIAS64		(2048-1)	/* v9 abi stack bias */
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate #endif /* __sparcv9 */
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM)
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate #if defined(DEBUG)
141*0Sstevel@tonic-gate #if STACK_ALIGN == 8
142*0Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()						\
143*0Sstevel@tonic-gate 	{								\
144*0Sstevel@tonic-gate 		uint64_t __tmp;						\
145*0Sstevel@tonic-gate 		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
146*0Sstevel@tonic-gate 	}
147*0Sstevel@tonic-gate #elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16)
148*0Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()						\
149*0Sstevel@tonic-gate 	{								\
150*0Sstevel@tonic-gate 		long double __tmp;					\
151*0Sstevel@tonic-gate 		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
152*0Sstevel@tonic-gate 	}
153*0Sstevel@tonic-gate #endif
154*0Sstevel@tonic-gate #else	/* DEBUG */
155*0Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()
156*0Sstevel@tonic-gate #endif	/* DEBUG */
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate struct regs;
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate void flush_windows(void);
161*0Sstevel@tonic-gate void flush_user_windows(void);
162*0Sstevel@tonic-gate int  flush_user_windows_to_stack(caddr_t *);
163*0Sstevel@tonic-gate void trash_user_windows(void);
164*0Sstevel@tonic-gate void traceregs(struct regs *);
165*0Sstevel@tonic-gate void traceback(caddr_t);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate #endif	/* defined(_KERNEL) && !defined(_ASM) */
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate #ifdef	__cplusplus
170*0Sstevel@tonic-gate }
171*0Sstevel@tonic-gate #endif
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate #endif	/* _SYS_STACK_H */
174