xref: /illumos-gate/usr/src/uts/sparc/sys/stack.h (revision 7c478bd9)
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 #ifndef _SYS_STACK_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_STACK_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #if !defined(_ASM)
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * A stack frame looks like:
44*7c478bd9Sstevel@tonic-gate  *
45*7c478bd9Sstevel@tonic-gate  * %fp->|				|
46*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|
47*7c478bd9Sstevel@tonic-gate  *	|  Locals, temps, saved floats	|
48*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|
49*7c478bd9Sstevel@tonic-gate  *	|  outgoing parameters past 6	|
50*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|-\
51*7c478bd9Sstevel@tonic-gate  *	|  6 words for callee to dump	| |
52*7c478bd9Sstevel@tonic-gate  *	|  register arguments		| |
53*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|  > minimum stack frame
54*7c478bd9Sstevel@tonic-gate  *	|  One word struct-ret address	| |
55*7c478bd9Sstevel@tonic-gate  *	|-------------------------------| |
56*7c478bd9Sstevel@tonic-gate  *	|  16 words to save IN and	| |
57*7c478bd9Sstevel@tonic-gate  * %sp->|  LOCAL register on overflow	| |
58*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|-/
59*7c478bd9Sstevel@tonic-gate  */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Constants defining a 32-bit stack frame.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate #define	WINDOWSIZE32	(16*4)		/* size of window save area */
65*7c478bd9Sstevel@tonic-gate #define	ARGPUSHSIZE32	(6*4)		/* size of arg dump area */
66*7c478bd9Sstevel@tonic-gate #define	ARGPUSH32	(WINDOWSIZE32 + 4)	/* arg dump area offset */
67*7c478bd9Sstevel@tonic-gate #define	MINFRAME32	(WINDOWSIZE32 + ARGPUSHSIZE32 + 4) /* min frame */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #define	STACK_GROWTH_DOWN /* stacks grow from high to low addresses */
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate /*
72*7c478bd9Sstevel@tonic-gate  * Stack alignment macros.
73*7c478bd9Sstevel@tonic-gate  */
74*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN32		8
75*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN32	8
76*7c478bd9Sstevel@tonic-gate #define	SA32(X)			(((X)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1))
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate #if defined(__sparcv9)
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate  * The 64-bit C ABI uses a stack frame that looks like:
81*7c478bd9Sstevel@tonic-gate  *
82*7c478bd9Sstevel@tonic-gate  *      |				|
83*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|
84*7c478bd9Sstevel@tonic-gate  *	|  Locals, temps, saved floats	|
85*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|
86*7c478bd9Sstevel@tonic-gate  *	|  outgoing parameters past 6	|
87*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|-\
88*7c478bd9Sstevel@tonic-gate  *	|  outgoing parameters thru 6	| |
89*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|  > minimum stack frame
90*7c478bd9Sstevel@tonic-gate  *	|  16 xwords to save IN and	| |
91*7c478bd9Sstevel@tonic-gate  *      |  LOCAL register on overflow	| |
92*7c478bd9Sstevel@tonic-gate  *	|-------------------------------|-/-\
93*7c478bd9Sstevel@tonic-gate  *      |				|   |
94*7c478bd9Sstevel@tonic-gate  *      |				|    > v9 abi bias
95*7c478bd9Sstevel@tonic-gate  *      |				|   |
96*7c478bd9Sstevel@tonic-gate  * %sp->|-------------------------------|---/
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate  * Constants defining a stack frame.
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate #define	WINDOWSIZE64		(16*8)		/* size of window save area */
103*7c478bd9Sstevel@tonic-gate #define	ARGPUSHSIZE64		(6*8)		/* size of arg dump area */
104*7c478bd9Sstevel@tonic-gate #define	MINFRAME64		(WINDOWSIZE64 + 48)	/* min frame */
105*7c478bd9Sstevel@tonic-gate #define	ARGPUSH64		(WINDOWSIZE64)	/* arg dump area offset */
106*7c478bd9Sstevel@tonic-gate #define	V9BIAS64		(2048-1)	/* v9 abi stack bias */
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN64		16
109*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN64	16
110*7c478bd9Sstevel@tonic-gate #define	SA64(X)			(((X)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1))
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate #define	IS_V9STACK(x)		((((uintptr_t)(x) + V9BIAS64) & \
113*7c478bd9Sstevel@tonic-gate 				(STACK_ALIGN64-1)) == 0)
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate #define	WINDOWSIZE		WINDOWSIZE64
116*7c478bd9Sstevel@tonic-gate #define	ARGPUSHSIZE		ARGPUSHSIZE64
117*7c478bd9Sstevel@tonic-gate #define	ARGPUSH			ARGPUSH64
118*7c478bd9Sstevel@tonic-gate #define	MINFRAME		MINFRAME64
119*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN		STACK_ALIGN64
120*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN64
121*7c478bd9Sstevel@tonic-gate #define	STACK_BIAS		V9BIAS64
122*7c478bd9Sstevel@tonic-gate #define	SA(x)			SA64(x)
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate #else
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate #define	WINDOWSIZE		WINDOWSIZE32
127*7c478bd9Sstevel@tonic-gate #define	ARGPUSHSIZE		ARGPUSHSIZE32
128*7c478bd9Sstevel@tonic-gate #define	ARGPUSH			ARGPUSH32
129*7c478bd9Sstevel@tonic-gate #define	MINFRAME		MINFRAME32
130*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN		STACK_ALIGN32
131*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN32
132*7c478bd9Sstevel@tonic-gate #define	STACK_BIAS		0
133*7c478bd9Sstevel@tonic-gate #define	SA(x)			SA32(x)
134*7c478bd9Sstevel@tonic-gate #define	STACK_V9BIAS64		(2048-1)	/* v9 abi stack bias */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM)
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate #if defined(DEBUG)
141*7c478bd9Sstevel@tonic-gate #if STACK_ALIGN == 8
142*7c478bd9Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()						\
143*7c478bd9Sstevel@tonic-gate 	{								\
144*7c478bd9Sstevel@tonic-gate 		uint64_t __tmp;						\
145*7c478bd9Sstevel@tonic-gate 		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
146*7c478bd9Sstevel@tonic-gate 	}
147*7c478bd9Sstevel@tonic-gate #elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16)
148*7c478bd9Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()						\
149*7c478bd9Sstevel@tonic-gate 	{								\
150*7c478bd9Sstevel@tonic-gate 		long double __tmp;					\
151*7c478bd9Sstevel@tonic-gate 		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
152*7c478bd9Sstevel@tonic-gate 	}
153*7c478bd9Sstevel@tonic-gate #endif
154*7c478bd9Sstevel@tonic-gate #else	/* DEBUG */
155*7c478bd9Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()
156*7c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate struct regs;
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate void flush_windows(void);
161*7c478bd9Sstevel@tonic-gate void flush_user_windows(void);
162*7c478bd9Sstevel@tonic-gate int  flush_user_windows_to_stack(caddr_t *);
163*7c478bd9Sstevel@tonic-gate void trash_user_windows(void);
164*7c478bd9Sstevel@tonic-gate void traceregs(struct regs *);
165*7c478bd9Sstevel@tonic-gate void traceback(caddr_t);
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) && !defined(_ASM) */
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
170*7c478bd9Sstevel@tonic-gate }
171*7c478bd9Sstevel@tonic-gate #endif
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_STACK_H */
174