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 _IA32_SYS_STACK_H
287c478bdstevel@tonic-gate#define	_IA32_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 * In the x86 world, a stack frame looks like this:
447c478bdstevel@tonic-gate *
457c478bdstevel@tonic-gate *		|--------------------------|
467c478bdstevel@tonic-gate * 4n+8(%ebp) ->| argument word n	   |
477c478bdstevel@tonic-gate *		| ...			   |	(Previous frame)
487c478bdstevel@tonic-gate *    8(%ebp) ->| argument word 0	   |
497c478bdstevel@tonic-gate *		|--------------------------|--------------------
507c478bdstevel@tonic-gate *    4(%ebp) ->| return address	   |
517c478bdstevel@tonic-gate *		|--------------------------|
527c478bdstevel@tonic-gate *    0(%ebp) ->| previous %ebp (optional) |
537c478bdstevel@tonic-gate * 		|--------------------------|
547c478bdstevel@tonic-gate *   -4(%ebp) ->| unspecified		   |	(Current frame)
557c478bdstevel@tonic-gate *		| ...			   |
567c478bdstevel@tonic-gate *    0(%esp) ->| variable size		   |
577c478bdstevel@tonic-gate * 		|--------------------------|
587c478bdstevel@tonic-gate */
597c478bdstevel@tonic-gate
607c478bdstevel@tonic-gate/*
617c478bdstevel@tonic-gate * Stack alignment macros.
627c478bdstevel@tonic-gate */
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate#define	STACK_ALIGN32		4
657c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN32	4
667c478bdstevel@tonic-gate#define	STACK_BIAS32		0
677c478bdstevel@tonic-gate#define	SA32(x)			(((x)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1))
687c478bdstevel@tonic-gate#define	STACK_RESERVE32		0
697c478bdstevel@tonic-gate#define	MINFRAME32		0
707c478bdstevel@tonic-gate
717c478bdstevel@tonic-gate#if defined(__amd64)
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gate/*
747c478bdstevel@tonic-gate * In the amd64 world, a stack frame looks like this:
757c478bdstevel@tonic-gate *
767c478bdstevel@tonic-gate *		|--------------------------|
777c478bdstevel@tonic-gate * 8n+16(%rbp)->| argument word n	   |
787c478bdstevel@tonic-gate *		| ...			   |	(Previous frame)
797c478bdstevel@tonic-gate *   16(%rbp) ->| argument word 0	   |
807c478bdstevel@tonic-gate *		|--------------------------|--------------------
817c478bdstevel@tonic-gate *    8(%rbp) ->| return address	   |
827c478bdstevel@tonic-gate *		|--------------------------|
837c478bdstevel@tonic-gate *    0(%rbp) ->| previous %rbp            |
847c478bdstevel@tonic-gate * 		|--------------------------|
857c478bdstevel@tonic-gate *   -8(%rbp) ->| unspecified		   |	(Current frame)
867c478bdstevel@tonic-gate *		| ...			   |
877c478bdstevel@tonic-gate *    0(%rsp) ->| variable size		   |
887c478bdstevel@tonic-gate * 		|--------------------------|
897c478bdstevel@tonic-gate * -128(%rsp) ->| reserved for function	   |
907c478bdstevel@tonic-gate * 		|--------------------------|
917c478bdstevel@tonic-gate *
927c478bdstevel@tonic-gate * The end of the input argument area must be aligned on a 16-byte
937c478bdstevel@tonic-gate * boundary; i.e. (%rsp - 8) % 16 == 0 at function entry.
947c478bdstevel@tonic-gate *
957c478bdstevel@tonic-gate * The 128-byte location beyond %rsp is considered to be reserved for
967c478bdstevel@tonic-gate * functions and is NOT modified by signal handlers.  It can be used
977c478bdstevel@tonic-gate * to store temporary data that is not needed across function calls.
987c478bdstevel@tonic-gate */
997c478bdstevel@tonic-gate
1007c478bdstevel@tonic-gate/*
1017c478bdstevel@tonic-gate * Stack alignment macros.
1027c478bdstevel@tonic-gate */
1037c478bdstevel@tonic-gate
1047c478bdstevel@tonic-gate#define	STACK_ALIGN64		16
1057c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN64 	8
1067c478bdstevel@tonic-gate#define	STACK_BIAS64		0
1077c478bdstevel@tonic-gate#define	SA64(x)			(((x)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1))
1087c478bdstevel@tonic-gate#define	STACK_RESERVE64		128
1097c478bdstevel@tonic-gate#define	MINFRAME64		0
1107c478bdstevel@tonic-gate
1117c478bdstevel@tonic-gate#define	STACK_ALIGN		STACK_ALIGN64
1127c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN64
1137c478bdstevel@tonic-gate#define	STACK_BIAS		STACK_BIAS64
1147c478bdstevel@tonic-gate#define	SA(x)			SA64(x)
1157c478bdstevel@tonic-gate#define	STACK_RESERVE		STACK_RESERVE64
1167c478bdstevel@tonic-gate#define	MINFRAME		MINFRAME64
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gate#elif defined(__i386)
1197c478bdstevel@tonic-gate
1207c478bdstevel@tonic-gate#define	STACK_ALIGN		STACK_ALIGN32
1217c478bdstevel@tonic-gate#define	STACK_ENTRY_ALIGN	STACK_ENTRY_ALIGN32
1227c478bdstevel@tonic-gate#define	STACK_BIAS		STACK_BIAS32
1237c478bdstevel@tonic-gate#define	SA(x)			SA32(x)
1247c478bdstevel@tonic-gate#define	STACK_RESERVE		STACK_RESERVE32
1257c478bdstevel@tonic-gate#define	MINFRAME		MINFRAME32
1267c478bdstevel@tonic-gate
1277c478bdstevel@tonic-gate#endif	/* __i386 */
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gate#if defined(_KERNEL) && !defined(_ASM)
1307c478bdstevel@tonic-gate
1317c478bdstevel@tonic-gate#if defined(DEBUG)
1327c478bdstevel@tonic-gate#if STACK_ALIGN == 4
1337c478bdstevel@tonic-gate#define	ASSERT_STACK_ALIGNED()						\
1347c478bdstevel@tonic-gate	{								\
1357c478bdstevel@tonic-gate		uint32_t __tmp;						\
1367c478bdstevel@tonic-gate		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
1377c478bdstevel@tonic-gate	}
1387c478bdstevel@tonic-gate#elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16)
1397c478bdstevel@tonic-gate#define	ASSERT_STACK_ALIGNED()						\
1407c478bdstevel@tonic-gate	{								\
1417c478bdstevel@tonic-gate		long double __tmp;					\
1427c478bdstevel@tonic-gate		ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0);	\
1437c478bdstevel@tonic-gate	}
1447c478bdstevel@tonic-gate#endif
1457c478bdstevel@tonic-gate#else	/* DEBUG */
1467c478bdstevel@tonic-gate#define	ASSERT_STACK_ALIGNED()
1477c478bdstevel@tonic-gate#endif	/* DEBUG */
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gatestruct regs;
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gatevoid traceregs(struct regs *);
1527c478bdstevel@tonic-gatevoid traceback(caddr_t);
1537c478bdstevel@tonic-gate
1547c478bdstevel@tonic-gate#endif /* defined(_KERNEL) && !defined(_ASM) */
1557c478bdstevel@tonic-gate
1567c478bdstevel@tonic-gate#define	STACK_GROWTH_DOWN /* stacks grow from high to low addresses */
1577c478bdstevel@tonic-gate
1587c478bdstevel@tonic-gate#ifdef	__cplusplus
1597c478bdstevel@tonic-gate}
1607c478bdstevel@tonic-gate#endif
1617c478bdstevel@tonic-gate
1627c478bdstevel@tonic-gate#endif	/* _IA32_SYS_STACK_H */
163