xref: /titanic_52/usr/src/uts/intel/ia32/sys/stack.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 _IA32_SYS_STACK_H
28*7c478bd9Sstevel@tonic-gate #define	_IA32_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  * In the x86 world, a stack frame looks like this:
44*7c478bd9Sstevel@tonic-gate  *
45*7c478bd9Sstevel@tonic-gate  *		|--------------------------|
46*7c478bd9Sstevel@tonic-gate  * 4n+8(%ebp) ->| argument word n	   |
47*7c478bd9Sstevel@tonic-gate  *		| ...			   |	(Previous frame)
48*7c478bd9Sstevel@tonic-gate  *    8(%ebp) ->| argument word 0	   |
49*7c478bd9Sstevel@tonic-gate  *		|--------------------------|--------------------
50*7c478bd9Sstevel@tonic-gate  *    4(%ebp) ->| return address	   |
51*7c478bd9Sstevel@tonic-gate  *		|--------------------------|
52*7c478bd9Sstevel@tonic-gate  *    0(%ebp) ->| previous %ebp (optional) |
53*7c478bd9Sstevel@tonic-gate  * 		|--------------------------|
54*7c478bd9Sstevel@tonic-gate  *   -4(%ebp) ->| unspecified		   |	(Current frame)
55*7c478bd9Sstevel@tonic-gate  *		| ...			   |
56*7c478bd9Sstevel@tonic-gate  *    0(%esp) ->| variable size		   |
57*7c478bd9Sstevel@tonic-gate  * 		|--------------------------|
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate  * Stack alignment macros.
62*7c478bd9Sstevel@tonic-gate  */
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN32		4
65*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN32	4
66*7c478bd9Sstevel@tonic-gate #define	STACK_BIAS32		0
67*7c478bd9Sstevel@tonic-gate #define	SA32(x)			(((x)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1))
68*7c478bd9Sstevel@tonic-gate #define	STACK_RESERVE32		0
69*7c478bd9Sstevel@tonic-gate #define	MINFRAME32		0
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate #if defined(__amd64)
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate  * In the amd64 world, a stack frame looks like this:
75*7c478bd9Sstevel@tonic-gate  *
76*7c478bd9Sstevel@tonic-gate  *		|--------------------------|
77*7c478bd9Sstevel@tonic-gate  * 8n+16(%rbp)->| argument word n	   |
78*7c478bd9Sstevel@tonic-gate  *		| ...			   |	(Previous frame)
79*7c478bd9Sstevel@tonic-gate  *   16(%rbp) ->| argument word 0	   |
80*7c478bd9Sstevel@tonic-gate  *		|--------------------------|--------------------
81*7c478bd9Sstevel@tonic-gate  *    8(%rbp) ->| return address	   |
82*7c478bd9Sstevel@tonic-gate  *		|--------------------------|
83*7c478bd9Sstevel@tonic-gate  *    0(%rbp) ->| previous %rbp            |
84*7c478bd9Sstevel@tonic-gate  * 		|--------------------------|
85*7c478bd9Sstevel@tonic-gate  *   -8(%rbp) ->| unspecified		   |	(Current frame)
86*7c478bd9Sstevel@tonic-gate  *		| ...			   |
87*7c478bd9Sstevel@tonic-gate  *    0(%rsp) ->| variable size		   |
88*7c478bd9Sstevel@tonic-gate  * 		|--------------------------|
89*7c478bd9Sstevel@tonic-gate  * -128(%rsp) ->| reserved for function	   |
90*7c478bd9Sstevel@tonic-gate  * 		|--------------------------|
91*7c478bd9Sstevel@tonic-gate  *
92*7c478bd9Sstevel@tonic-gate  * The end of the input argument area must be aligned on a 16-byte
93*7c478bd9Sstevel@tonic-gate  * boundary; i.e. (%rsp - 8) % 16 == 0 at function entry.
94*7c478bd9Sstevel@tonic-gate  *
95*7c478bd9Sstevel@tonic-gate  * The 128-byte location beyond %rsp is considered to be reserved for
96*7c478bd9Sstevel@tonic-gate  * functions and is NOT modified by signal handlers.  It can be used
97*7c478bd9Sstevel@tonic-gate  * to store temporary data that is not needed across function calls.
98*7c478bd9Sstevel@tonic-gate  */
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate /*
101*7c478bd9Sstevel@tonic-gate  * Stack alignment macros.
102*7c478bd9Sstevel@tonic-gate  */
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN64		16
105*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN64 	8
106*7c478bd9Sstevel@tonic-gate #define	STACK_BIAS64		0
107*7c478bd9Sstevel@tonic-gate #define	SA64(x)			(((x)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1))
108*7c478bd9Sstevel@tonic-gate #define	STACK_RESERVE64		128
109*7c478bd9Sstevel@tonic-gate #define	MINFRAME64		0
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN		STACK_ALIGN64
112*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN64
113*7c478bd9Sstevel@tonic-gate #define	STACK_BIAS		STACK_BIAS64
114*7c478bd9Sstevel@tonic-gate #define	SA(x)			SA64(x)
115*7c478bd9Sstevel@tonic-gate #define	STACK_RESERVE		STACK_RESERVE64
116*7c478bd9Sstevel@tonic-gate #define	MINFRAME		MINFRAME64
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate #elif defined(__i386)
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate #define	STACK_ALIGN		STACK_ALIGN32
121*7c478bd9Sstevel@tonic-gate #define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN32
122*7c478bd9Sstevel@tonic-gate #define	STACK_BIAS		STACK_BIAS32
123*7c478bd9Sstevel@tonic-gate #define	SA(x)			SA32(x)
124*7c478bd9Sstevel@tonic-gate #define	STACK_RESERVE		STACK_RESERVE32
125*7c478bd9Sstevel@tonic-gate #define	MINFRAME		MINFRAME32
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate #endif	/* __i386 */
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM)
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate #if defined(DEBUG)
132*7c478bd9Sstevel@tonic-gate #if STACK_ALIGN == 4
133*7c478bd9Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()						\
134*7c478bd9Sstevel@tonic-gate 	{								\
135*7c478bd9Sstevel@tonic-gate 		uint32_t __tmp;						\
136*7c478bd9Sstevel@tonic-gate 		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
137*7c478bd9Sstevel@tonic-gate 	}
138*7c478bd9Sstevel@tonic-gate #elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16)
139*7c478bd9Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()						\
140*7c478bd9Sstevel@tonic-gate 	{								\
141*7c478bd9Sstevel@tonic-gate 		long double __tmp;					\
142*7c478bd9Sstevel@tonic-gate 		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
143*7c478bd9Sstevel@tonic-gate 	}
144*7c478bd9Sstevel@tonic-gate #endif
145*7c478bd9Sstevel@tonic-gate #else	/* DEBUG */
146*7c478bd9Sstevel@tonic-gate #define	ASSERT_STACK_ALIGNED()
147*7c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate struct regs;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate void traceregs(struct regs *);
152*7c478bd9Sstevel@tonic-gate void traceback(caddr_t);
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) && !defined(_ASM) */
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate #define	STACK_GROWTH_DOWN /* stacks grow from high to low addresses */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate #endif
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate #endif	/* _IA32_SYS_STACK_H */
163