17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#ifndef _SYS_STACK_H
287c478bdstevel@tonic-gate#define	_SYS_STACK_H
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#if !defined(_ASM)
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate#include <sys/types.h>
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#endif
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate#ifdef	__cplusplus
397c478bdstevel@tonic-gateextern "C" {
407c478bdstevel@tonic-gate#endif
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate/*
437c478bdstevel@tonic-gate * A stack frame looks like:
447c478bdstevel@tonic-gate *
457c478bdstevel@tonic-gate * %fp->|				|
467c478bdstevel@tonic-gate *	|-------------------------------|
477c478bdstevel@tonic-gate *	|  Locals, temps, saved floats	|
487c478bdstevel@tonic-gate *	|-------------------------------|
497c478bdstevel@tonic-gate *	|  outgoing parameters past 6	|
507c478bdstevel@tonic-gate *	|-------------------------------|-\
517c478bdstevel@tonic-gate *	|  6 words for callee to dump	| |
527c478bdstevel@tonic-gate *	|  register arguments		| |
537c478bdstevel@tonic-gate *	|-------------------------------|  > minimum stack frame
547c478bdstevel@tonic-gate *	|  One word struct-ret address	| |
557c478bdstevel@tonic-gate *	|-------------------------------| |
567c478bdstevel@tonic-gate *	|  16 words to save IN and	| |
577c478bdstevel@tonic-gate * %sp->|  LOCAL register on overflow	| |
587c478bdstevel@tonic-gate *	|-------------------------------|-/
597c478bdstevel@tonic-gate */
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gate/*
627c478bdstevel@tonic-gate * Constants defining a 32-bit stack frame.
637c478bdstevel@tonic-gate */
647c478bdstevel@tonic-gate#define	WINDOWSIZE32	(16*4)		/* size of window save area */
657c478bdstevel@tonic-gate#define	ARGPUSHSIZE32	(6*4)		/* size of arg dump area */
667c478bdstevel@tonic-gate#define	ARGPUSH32	(WINDOWSIZE32 + 4)	/* arg dump area offset */
677c478bdstevel@tonic-gate#define	MINFRAME32	(WINDOWSIZE32 + ARGPUSHSIZE32 + 4) /* min frame */
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate#define	STACK_GROWTH_DOWN /* stacks grow from high to low addresses */
707c478bdstevel@tonic-gate
717c478bdstevel@tonic-gate/*
727c478bdstevel@tonic-gate * Stack alignment macros.
737c478bdstevel@tonic-gate */
747c478bdstevel@tonic-gate#define	STACK_ALIGN32		8
757c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN32	8
767c478bdstevel@tonic-gate#define	SA32(X)			(((X)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1))
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate#if defined(__sparcv9)
797c478bdstevel@tonic-gate/*
807c478bdstevel@tonic-gate * The 64-bit C ABI uses a stack frame that looks like:
817c478bdstevel@tonic-gate *
827c478bdstevel@tonic-gate *      |				|
837c478bdstevel@tonic-gate *	|-------------------------------|
847c478bdstevel@tonic-gate *	|  Locals, temps, saved floats	|
857c478bdstevel@tonic-gate *	|-------------------------------|
867c478bdstevel@tonic-gate *	|  outgoing parameters past 6	|
877c478bdstevel@tonic-gate *	|-------------------------------|-\
887c478bdstevel@tonic-gate *	|  outgoing parameters thru 6	| |
897c478bdstevel@tonic-gate *	|-------------------------------|  > minimum stack frame
907c478bdstevel@tonic-gate *	|  16 xwords to save IN and	| |
917c478bdstevel@tonic-gate *      |  LOCAL register on overflow	| |
927c478bdstevel@tonic-gate *	|-------------------------------|-/-\
937c478bdstevel@tonic-gate *      |				|   |
947c478bdstevel@tonic-gate *      |				|    > v9 abi bias
957c478bdstevel@tonic-gate *      |				|   |
967c478bdstevel@tonic-gate * %sp->|-------------------------------|---/
977c478bdstevel@tonic-gate */
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gate/*
1007c478bdstevel@tonic-gate * Constants defining a stack frame.
1017c478bdstevel@tonic-gate */
1027c478bdstevel@tonic-gate#define	WINDOWSIZE64		(16*8)		/* size of window save area */
1037c478bdstevel@tonic-gate#define	ARGPUSHSIZE64		(6*8)		/* size of arg dump area */
1047c478bdstevel@tonic-gate#define	MINFRAME64		(WINDOWSIZE64 + 48)	/* min frame */
1057c478bdstevel@tonic-gate#define	ARGPUSH64		(WINDOWSIZE64)	/* arg dump area offset */
1067c478bdstevel@tonic-gate#define	V9BIAS64		(2048-1)	/* v9 abi stack bias */
1077c478bdstevel@tonic-gate
1087c478bdstevel@tonic-gate#define	STACK_ALIGN64		16
1097c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN64	16
1107c478bdstevel@tonic-gate#define	SA64(X)			(((X)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1))
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gate#define	IS_V9STACK(x)		((((uintptr_t)(x) + V9BIAS64) & \
1137c478bdstevel@tonic-gate				(STACK_ALIGN64-1)) == 0)
1147c478bdstevel@tonic-gate
1157c478bdstevel@tonic-gate#define	WINDOWSIZE		WINDOWSIZE64
1167c478bdstevel@tonic-gate#define	ARGPUSHSIZE		ARGPUSHSIZE64
1177c478bdstevel@tonic-gate#define	ARGPUSH			ARGPUSH64
1187c478bdstevel@tonic-gate#define	MINFRAME		MINFRAME64
1197c478bdstevel@tonic-gate#define	STACK_ALIGN		STACK_ALIGN64
1207c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN64
1217c478bdstevel@tonic-gate#define	STACK_BIAS		V9BIAS64
1227c478bdstevel@tonic-gate#define	SA(x)			SA64(x)
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gate#else
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gate#define	WINDOWSIZE		WINDOWSIZE32
1277c478bdstevel@tonic-gate#define	ARGPUSHSIZE		ARGPUSHSIZE32
1287c478bdstevel@tonic-gate#define	ARGPUSH			ARGPUSH32
1297c478bdstevel@tonic-gate#define	MINFRAME		MINFRAME32
1307c478bdstevel@tonic-gate#define	STACK_ALIGN		STACK_ALIGN32
1317c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN32
1327c478bdstevel@tonic-gate#define	STACK_BIAS		0
1337c478bdstevel@tonic-gate#define	SA(x)			SA32(x)
1347c478bdstevel@tonic-gate#define	STACK_V9BIAS64		(2048-1)	/* v9 abi stack bias */
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gate#endif /* __sparcv9 */
1377c478bdstevel@tonic-gate
1387c478bdstevel@tonic-gate#if defined(_KERNEL) && !defined(_ASM)
1397c478bdstevel@tonic-gate
1407c478bdstevel@tonic-gate#if defined(DEBUG)
1417c478bdstevel@tonic-gate#if STACK_ALIGN == 8
1427c478bdstevel@tonic-gate#define	ASSERT_STACK_ALIGNED()						\
1437c478bdstevel@tonic-gate	{								\
1447c478bdstevel@tonic-gate		uint64_t __tmp;						\
1457c478bdstevel@tonic-gate		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
1467c478bdstevel@tonic-gate	}
1477c478bdstevel@tonic-gate#elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16)
1487c478bdstevel@tonic-gate#define	ASSERT_STACK_ALIGNED()						\
1497c478bdstevel@tonic-gate	{								\
1507c478bdstevel@tonic-gate		long double __tmp;					\
1517c478bdstevel@tonic-gate		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
1527c478bdstevel@tonic-gate	}
1537c478bdstevel@tonic-gate#endif
1547c478bdstevel@tonic-gate#else	/* DEBUG */
1557c478bdstevel@tonic-gate#define	ASSERT_STACK_ALIGNED()
1567c478bdstevel@tonic-gate#endif	/* DEBUG */
1577c478bdstevel@tonic-gate
1587c478bdstevel@tonic-gatestruct regs;
1597c478bdstevel@tonic-gate
1607c478bdstevel@tonic-gatevoid flush_windows(void);
1617c478bdstevel@tonic-gatevoid flush_user_windows(void);
1627c478bdstevel@tonic-gateint  flush_user_windows_to_stack(caddr_t *);
1637c478bdstevel@tonic-gatevoid trash_user_windows(void);
1647c478bdstevel@tonic-gatevoid traceregs(struct regs *);
1657c478bdstevel@tonic-gatevoid traceback(caddr_t);
1667c478bdstevel@tonic-gate
1677c478bdstevel@tonic-gate#endif	/* defined(_KERNEL) && !defined(_ASM) */
1687c478bdstevel@tonic-gate
1697c478bdstevel@tonic-gate#ifdef	__cplusplus
1707c478bdstevel@tonic-gate}
1717c478bdstevel@tonic-gate#endif
1727c478bdstevel@tonic-gate
1737c478bdstevel@tonic-gate#endif	/* _SYS_STACK_H */
174