summaryrefslogtreecommitdiff
path: root/usr/src/uts/sparc/sys/stack.h
blob: 692832f21e6c938824dd9d34cd89a94d21020009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _SYS_STACK_H
#define	_SYS_STACK_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#if !defined(_ASM)

#include <sys/types.h>

#endif

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * A stack frame looks like:
 *
 * %fp->|				|
 *	|-------------------------------|
 *	|  Locals, temps, saved floats	|
 *	|-------------------------------|
 *	|  outgoing parameters past 6	|
 *	|-------------------------------|-\
 *	|  6 words for callee to dump	| |
 *	|  register arguments		| |
 *	|-------------------------------|  > minimum stack frame
 *	|  One word struct-ret address	| |
 *	|-------------------------------| |
 *	|  16 words to save IN and	| |
 * %sp->|  LOCAL register on overflow	| |
 *	|-------------------------------|-/
 */

/*
 * Constants defining a 32-bit stack frame.
 */
#define	WINDOWSIZE32	(16*4)		/* size of window save area */
#define	ARGPUSHSIZE32	(6*4)		/* size of arg dump area */
#define	ARGPUSH32	(WINDOWSIZE32 + 4)	/* arg dump area offset */
#define	MINFRAME32	(WINDOWSIZE32 + ARGPUSHSIZE32 + 4) /* min frame */

#define	STACK_GROWTH_DOWN /* stacks grow from high to low addresses */

/*
 * Stack alignment macros.
 */
#define	STACK_ALIGN32		8
#define	STACK_ENTRY_ALIGN32	8
#define	SA32(X)			(((X)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1))

#if defined(__sparcv9)
/*
 * The 64-bit C ABI uses a stack frame that looks like:
 *
 *      |				|
 *	|-------------------------------|
 *	|  Locals, temps, saved floats	|
 *	|-------------------------------|
 *	|  outgoing parameters past 6	|
 *	|-------------------------------|-\
 *	|  outgoing parameters thru 6	| |
 *	|-------------------------------|  > minimum stack frame
 *	|  16 xwords to save IN and	| |
 *      |  LOCAL register on overflow	| |
 *	|-------------------------------|-/-\
 *      |				|   |
 *      |				|    > v9 abi bias
 *      |				|   |
 * %sp->|-------------------------------|---/
 */

/*
 * Constants defining a stack frame.
 */
#define	WINDOWSIZE64		(16*8)		/* size of window save area */
#define	ARGPUSHSIZE64		(6*8)		/* size of arg dump area */
#define	MINFRAME64		(WINDOWSIZE64 + 48)	/* min frame */
#define	ARGPUSH64		(WINDOWSIZE64)	/* arg dump area offset */
#define	V9BIAS64		(2048-1)	/* v9 abi stack bias */

#define	STACK_ALIGN64		16
#define	STACK_ENTRY_ALIGN64	16
#define	SA64(X)			(((X)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1))

#define	IS_V9STACK(x)		((((uintptr_t)(x) + V9BIAS64) & \
				(STACK_ALIGN64-1)) == 0)

#define	WINDOWSIZE		WINDOWSIZE64
#define	ARGPUSHSIZE		ARGPUSHSIZE64
#define	ARGPUSH			ARGPUSH64
#define	MINFRAME		MINFRAME64
#define	STACK_ALIGN		STACK_ALIGN64
#define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN64
#define	STACK_BIAS		V9BIAS64
#define	SA(x)			SA64(x)

#else

#define	WINDOWSIZE		WINDOWSIZE32
#define	ARGPUSHSIZE		ARGPUSHSIZE32
#define	ARGPUSH			ARGPUSH32
#define	MINFRAME		MINFRAME32
#define	STACK_ALIGN		STACK_ALIGN32
#define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN32
#define	STACK_BIAS		0
#define	SA(x)			SA32(x)
#define	STACK_V9BIAS64		(2048-1)	/* v9 abi stack bias */

#endif /* __sparcv9 */

#if defined(_KERNEL) && !defined(_ASM)

#if defined(DEBUG)
#if STACK_ALIGN == 8
#define	ASSERT_STACK_ALIGNED()						\
	{								\
		uint64_t __tmp;						\
		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
	}
#elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16)
#define	ASSERT_STACK_ALIGNED()						\
	{								\
		long double __tmp;					\
		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
	}
#endif
#else	/* DEBUG */
#define	ASSERT_STACK_ALIGNED()
#endif	/* DEBUG */

struct regs;

void flush_windows(void);
void flush_user_windows(void);
int  flush_user_windows_to_stack(caddr_t *);
void trash_user_windows(void);
void traceregs(struct regs *);
void traceback(caddr_t);

#endif	/* defined(_KERNEL) && !defined(_ASM) */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_STACK_H */