src/ssx/ssx/ssx_stack_init.c
/// Initialize a stack area.
///
/// \param stack A pointer to the smallest legal address of the stack.  The
/// stack address is modified as the stack is aligned and initialized.
///
/// \param size A pointer to the size of the stack (in bytes).  The size is
/// modified as the stack is aligned and initialized.  At exit this is the
/// final usable stack area size aligned to the size of the SSX_STACK_TYPE.
///
/// SSX makes no assumptions about size or alignment of the area provided as a
/// stack, and carefully aligns and initializes the stack.  Regardless of how
/// the stack grows, the \a stack parameter is considered to be the lowest
/// legal address of the stack.
Initialize a stack area.
\param stack A pointer to the smallest legal address of the stack.  The
stack address is modified as the stack is aligned and initialized.

\param size A pointer to the size of the stack (in bytes).  The size is
modified as the stack is aligned and initialized.  At exit this is the
final usable stack area size aligned to the size of the SSX_STACK_TYPE.

SSX makes no assumptions about size or alignment of the area provided as a
stack, and carefully aligns and initializes the stack.  Regardless of how
the stack grows, the \a stack parameter is considered to be the lowest
legal address of the stack.
Initialize a stack area . \ param stack A pointer to the smallest legal address of the stack . The stack address is modified as the stack is aligned and initialized . \ param size A pointer to the size of the stack ( in bytes ) . The size is modified as the stack is aligned and initialized . At exit this is the final usable stack area size aligned to the size of the SSX_STACK_TYPE . SSX makes no assumptions about size or alignment of the area provided as a stack and carefully aligns and initializes the stack . Regardless of how the stack grows the \ a stack parameter is considered to be the lowest legal address of the stack .
int
__ssx_stack_init(SsxAddress* stack,
                 size_t*     size)
{
    SsxAddress mask;
    size_t excess, i, count;
    SSX_STACK_TYPE* p;
    if (SSX_STACK_DIRECTION < 0)
    {
        *stack += *size;
        if (!SSX_STACK_PRE_DECREMENT)
        {
            *stack -= sizeof(SSX_STACK_TYPE);
            *size -= sizeof(SSX_STACK_TYPE);
        }
        mask = SSX_STACK_ALIGNMENT - 1;
        excess = *stack & mask;
        *stack -= excess;
        *size -= excess;
        *size = (*size / sizeof(SSX_STACK_TYPE)) * sizeof(SSX_STACK_TYPE);
        if (SSX_STACK_CHECK)
        {
            p = (SSX_STACK_TYPE*)(*stack);
            count = *size / sizeof(SSX_STACK_TYPE);
            for (i = 0; i < count; i++)
            {
                if (SSX_STACK_PRE_DECREMENT)
                {
                    *(--p) = SSX_STACK_PATTERN;
                }
                else
                {
                    *(p--) = SSX_STACK_PATTERN;
                }
            }
        }
        __ssx_stack_create_initial_frame(stack, size);
    }
    else
    {
        SSX_PANIC(SSX_UNIMPLEMENTED);
    }
    return SSX_OK;
}
int __ssx_stack_init ( SsxAddress * stack , size_t * size ) { SsxAddress mask ; size_t excess , i , count ; SSX_STACK_TYPE * p ; if ( SSX_STACK_DIRECTION < 0 ) { * stack += * size ; if ( ! SSX_STACK_PRE_DECREMENT ) { * stack -= sizeof ( SSX_STACK_TYPE ) ; * size -= sizeof ( SSX_STACK_TYPE ) ; } mask = SSX_STACK_ALIGNMENT - 1 ; excess = * stack & mask ; * stack -= excess ; * size -= excess ; * size = ( * size / sizeof ( SSX_STACK_TYPE ) ) * sizeof ( SSX_STACK_TYPE ) ; if ( SSX_STACK_CHECK ) { p = ( SSX_STACK_TYPE * ) ( * stack ) ; count = * size / sizeof ( SSX_STACK_TYPE ) ; for ( i = 0 ; i < count ; i ++ ) { if ( SSX_STACK_PRE_DECREMENT ) { * ( -- p ) = SSX_STACK_PATTERN ; } else { * ( p -- ) = SSX_STACK_PATTERN ; } } } __ssx_stack_create_initial_frame ( stack , size ) ; } else { SSX_PANIC ( SSX_UNIMPLEMENTED ) ; } return SSX_OK ; }
Initialize a stack area.
Initialize a stack area .
// Stacks grow down.  The initial stack pointer is set to just above // the last allocated stack address.  This is legal for pre-decrement // stacks, otherwise the initial address is first brought into range // before alignment.  The stack is aligned downward, then the size is // adjusted to a multiple of the stack type.  Stacks are optionally // prepatterned. Alignment is assumed to be a power of 2.