1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Fixed the stack swapping function which, for reasons unknown, ceased to work.

git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14746 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2004-10-02 15:56:13 +00:00
parent 7038751f6b
commit 3f19d52557
4 changed files with 38 additions and 68 deletions

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.os4,v 1.9 2004-09-29 14:17:44 obarthel Exp $
# $Id: GNUmakefile.os4,v 1.10 2004-10-02 15:56:12 obarthel Exp $
#
# :ts=8
#
@ -105,7 +105,7 @@ WARNINGS = \
INCLUDES = -Iinclude -I. -I$(SDK_INCLUDE)
OPTIONS = -DNDEBUG -DUSE_64_BIT_INTS -fno-builtin -D__USE_INLINE__ -Wa,-mregnames
OPTIMIZE = -O3 -fomit-frame-pointer -funroll-loops
OPTIMIZE = -O -fomit-frame-pointer -funroll-loops
#DEBUG = -g
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(CODE_TYPE) $(INCLUDES)
@ -708,7 +708,7 @@ clean:
realclean:
$(MAKE) clean
-$(DELETE) lib small_data large_data
-$(DELETE) lib small_data large_data large_data_softfloat
##############################################################################

View File

@ -31,6 +31,9 @@ c.lib 1.177 (29.9.2004)
- The socket exit code now calls the common stdio function which
flushes and shuts down all buffered and unbuffered files.
- Fixed the stack swapping function which, for reasons unknown, ceased
to work...
- The start time used by clock() is now initialized by a constructor
function.

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_main.c,v 1.4 2004-09-29 19:57:58 obarthel Exp $
* $Id: stdlib_main.c,v 1.5 2004-10-02 15:56:13 obarthel Exp $
*
* :ts=4
*
@ -415,37 +415,36 @@ _main(void)
{
struct StackSwapStruct * stk;
unsigned int stack_size;
ULONG lower,upper;
APTR new_stack;
/* Make the stack size a multiple of 16 bytes. */
stack_size = (__stack_size + 15UL) & ~15UL;
/* Make the stack size a multiple of 32 bytes. */
stack_size = 32 + ((__stack_size + 31UL) & ~31UL);
/* We allocate a little more memory so that we can align
the stack to a 128 bit boundary. The extra 20 bytes are
to mimic the Task stack setup in dos.library/CreateProc. */
stk = AllocVec(sizeof(*stk) + 15 + 20 + stack_size,MEMF_PUBLIC|MEMF_ANY);
/* Allocate the stack swapping data structure
and the stack space separately. */
stk = AllocVec(sizeof(*stk),MEMF_PUBLIC|MEMF_ANY);
if(stk == NULL)
goto out;
/* Align the lower stack bound to a 128 bit boundary, then
fix up the upper bound, which is guaranteed to be on
a 128 bit boundary, too, on account of the stack size
having being rounded to that boundary. */
lower = (((ULONG)(stk+1)) + 15UL) & ~15UL;
upper = lower + stack_size;
new_stack = AllocMem(stack_size,MEMF_PUBLIC|MEMF_ANY);
if(new_stack == NULL)
{
FreeVec(stk);
goto out;
}
/* Fill in the lower and upper bounds, then take care of
the stack pointer itself. This layout mimics the process
creation code in dos.library. */
stk->stk_Lower = (APTR)lower;
stk->stk_Upper = upper - 4;
stk->stk_Pointer = (APTR)(upper - 20);
the stack pointer itself. */
stk->stk_Lower = new_stack;
stk->stk_Upper = (ULONG)(new_stack) + stack_size;
stk->stk_Pointer = (APTR)(stk->stk_Upper - 32);
/* If necessary, set up for stack size usage measurement. */
__stack_usage_init(stk);
return_code = __swap_stack_and_call(stk,(APTR)call_main);
FreeMem(new_stack, stack_size);
FreeVec(stk);
}
else

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_swapstack.c,v 1.1.1.1 2004-07-26 16:32:11 obarthel Exp $
* $Id: stdlib_swapstack.c,v 1.2 2004-10-02 15:56:13 obarthel Exp $
*
* :ts=4
*
@ -94,51 +94,19 @@ ___swap_stack_and_call: \n\
/****************************************************************************/
__asm(" \n\
\n\
.text \n\
.align 2 \n\
\n\
.set MainInterface, 632 \n\
.set IExec_StackSwap, 272 \n\
\n\
.globl SysBase \n\
.globl __swap_stack_and_call \n\
\n\
__swap_stack_and_call: \n\
stwu r1, -32(r1) # Make a stack frame \n\
mflr r0 \n\
stw r0, 36(r1) \n\
stmw r29, 8(r1) # Get us three GPRs \n\
# r29 will store IExec \n\
mr r4, r31 # Backup ptr to function to call \n\
mr r3, r30 # Backup ptr to StackSwapStruct \n\
\n\
lis r3, SysBase@ha # Retrieve sysbase pointer \n\
lwz r3, SysBase@l(r3) \n\
lwz r29, MainInterface(r3) # Get IExec \n\
\n\
addi r3, r29, IExec_StackSwap # StackSwap entry \n\
mr r4, r30 # StackSwap struct in r4 \n\
mtlr r3 \n\
blrl # IExec->StackSwap(r4) \n\
\n\
mtlr r31 # Call payload \n\
blrl \n\
\n\
addi r3, r29, IExec_StackSwap # Revert to old stack \n\
mr r4, r30 \n\
mtlr r3 \n\
blrl \n\
\n\
lmw r29, 8(r1) # Restore registers \n\
lwz r0, 36(r1) \n\
mtlr r0 \n\
addi r1, r1, 32 # Clean up stack \n\
\n\
blr \n\
\n\
");
/* Swap the current stack configuration out, call a function provided,
swap the stack configuration back and return. */
int
__swap_stack_and_call(struct StackSwapStruct * stk,APTR function)
{
register int result;
StackSwap(stk);
result = ((int (*)(void))function)();
StackSwap(stk);
return(result);
}
/****************************************************************************/