1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _IA32_SYS_STACK_H 28*0Sstevel@tonic-gate #define _IA32_SYS_STACK_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #if !defined(_ASM) 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include <sys/types.h> 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #endif 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #ifdef __cplusplus 39*0Sstevel@tonic-gate extern "C" { 40*0Sstevel@tonic-gate #endif 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate /* 43*0Sstevel@tonic-gate * In the x86 world, a stack frame looks like this: 44*0Sstevel@tonic-gate * 45*0Sstevel@tonic-gate * |--------------------------| 46*0Sstevel@tonic-gate * 4n+8(%ebp) ->| argument word n | 47*0Sstevel@tonic-gate * | ... | (Previous frame) 48*0Sstevel@tonic-gate * 8(%ebp) ->| argument word 0 | 49*0Sstevel@tonic-gate * |--------------------------|-------------------- 50*0Sstevel@tonic-gate * 4(%ebp) ->| return address | 51*0Sstevel@tonic-gate * |--------------------------| 52*0Sstevel@tonic-gate * 0(%ebp) ->| previous %ebp (optional) | 53*0Sstevel@tonic-gate * |--------------------------| 54*0Sstevel@tonic-gate * -4(%ebp) ->| unspecified | (Current frame) 55*0Sstevel@tonic-gate * | ... | 56*0Sstevel@tonic-gate * 0(%esp) ->| variable size | 57*0Sstevel@tonic-gate * |--------------------------| 58*0Sstevel@tonic-gate */ 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate /* 61*0Sstevel@tonic-gate * Stack alignment macros. 62*0Sstevel@tonic-gate */ 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate #define STACK_ALIGN32 4 65*0Sstevel@tonic-gate #define STACK_ENTRY_ALIGN32 4 66*0Sstevel@tonic-gate #define STACK_BIAS32 0 67*0Sstevel@tonic-gate #define SA32(x) (((x)+(STACK_ALIGN32-1)) & ~(STACK_ALIGN32-1)) 68*0Sstevel@tonic-gate #define STACK_RESERVE32 0 69*0Sstevel@tonic-gate #define MINFRAME32 0 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate #if defined(__amd64) 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate /* 74*0Sstevel@tonic-gate * In the amd64 world, a stack frame looks like this: 75*0Sstevel@tonic-gate * 76*0Sstevel@tonic-gate * |--------------------------| 77*0Sstevel@tonic-gate * 8n+16(%rbp)->| argument word n | 78*0Sstevel@tonic-gate * | ... | (Previous frame) 79*0Sstevel@tonic-gate * 16(%rbp) ->| argument word 0 | 80*0Sstevel@tonic-gate * |--------------------------|-------------------- 81*0Sstevel@tonic-gate * 8(%rbp) ->| return address | 82*0Sstevel@tonic-gate * |--------------------------| 83*0Sstevel@tonic-gate * 0(%rbp) ->| previous %rbp | 84*0Sstevel@tonic-gate * |--------------------------| 85*0Sstevel@tonic-gate * -8(%rbp) ->| unspecified | (Current frame) 86*0Sstevel@tonic-gate * | ... | 87*0Sstevel@tonic-gate * 0(%rsp) ->| variable size | 88*0Sstevel@tonic-gate * |--------------------------| 89*0Sstevel@tonic-gate * -128(%rsp) ->| reserved for function | 90*0Sstevel@tonic-gate * |--------------------------| 91*0Sstevel@tonic-gate * 92*0Sstevel@tonic-gate * The end of the input argument area must be aligned on a 16-byte 93*0Sstevel@tonic-gate * boundary; i.e. (%rsp - 8) % 16 == 0 at function entry. 94*0Sstevel@tonic-gate * 95*0Sstevel@tonic-gate * The 128-byte location beyond %rsp is considered to be reserved for 96*0Sstevel@tonic-gate * functions and is NOT modified by signal handlers. It can be used 97*0Sstevel@tonic-gate * to store temporary data that is not needed across function calls. 98*0Sstevel@tonic-gate */ 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate /* 101*0Sstevel@tonic-gate * Stack alignment macros. 102*0Sstevel@tonic-gate */ 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate #define STACK_ALIGN64 16 105*0Sstevel@tonic-gate #define STACK_ENTRY_ALIGN64 8 106*0Sstevel@tonic-gate #define STACK_BIAS64 0 107*0Sstevel@tonic-gate #define SA64(x) (((x)+(STACK_ALIGN64-1)) & ~(STACK_ALIGN64-1)) 108*0Sstevel@tonic-gate #define STACK_RESERVE64 128 109*0Sstevel@tonic-gate #define MINFRAME64 0 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate #define STACK_ALIGN STACK_ALIGN64 112*0Sstevel@tonic-gate #define STACK_ENTRY_ALIGN STACK_ENTRY_ALIGN64 113*0Sstevel@tonic-gate #define STACK_BIAS STACK_BIAS64 114*0Sstevel@tonic-gate #define SA(x) SA64(x) 115*0Sstevel@tonic-gate #define STACK_RESERVE STACK_RESERVE64 116*0Sstevel@tonic-gate #define MINFRAME MINFRAME64 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate #elif defined(__i386) 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate #define STACK_ALIGN STACK_ALIGN32 121*0Sstevel@tonic-gate #define STACK_ENTRY_ALIGN STACK_ENTRY_ALIGN32 122*0Sstevel@tonic-gate #define STACK_BIAS STACK_BIAS32 123*0Sstevel@tonic-gate #define SA(x) SA32(x) 124*0Sstevel@tonic-gate #define STACK_RESERVE STACK_RESERVE32 125*0Sstevel@tonic-gate #define MINFRAME MINFRAME32 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate #endif /* __i386 */ 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM) 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate #if defined(DEBUG) 132*0Sstevel@tonic-gate #if STACK_ALIGN == 4 133*0Sstevel@tonic-gate #define ASSERT_STACK_ALIGNED() \ 134*0Sstevel@tonic-gate { \ 135*0Sstevel@tonic-gate uint32_t __tmp; \ 136*0Sstevel@tonic-gate ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0); \ 137*0Sstevel@tonic-gate } 138*0Sstevel@tonic-gate #elif (STACK_ALIGN == 16) && (_LONG_DOUBLE_ALIGNMENT == 16) 139*0Sstevel@tonic-gate #define ASSERT_STACK_ALIGNED() \ 140*0Sstevel@tonic-gate { \ 141*0Sstevel@tonic-gate long double __tmp; \ 142*0Sstevel@tonic-gate ASSERT((((uintptr_t)&__tmp) & (STACK_ALIGN - 1)) == 0); \ 143*0Sstevel@tonic-gate } 144*0Sstevel@tonic-gate #endif 145*0Sstevel@tonic-gate #else /* DEBUG */ 146*0Sstevel@tonic-gate #define ASSERT_STACK_ALIGNED() 147*0Sstevel@tonic-gate #endif /* DEBUG */ 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate struct regs; 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate void traceregs(struct regs *); 152*0Sstevel@tonic-gate void traceback(caddr_t); 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate #endif /* defined(_KERNEL) && !defined(_ASM) */ 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate #define STACK_GROWTH_DOWN /* stacks grow from high to low addresses */ 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate #ifdef __cplusplus 159*0Sstevel@tonic-gate } 160*0Sstevel@tonic-gate #endif 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate #endif /* _IA32_SYS_STACK_H */ 163