From bba76eed9c67460941a9340f73fd4c6154808935 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Sun, 6 Jun 1999 14:49:55 +0000 Subject: [PATCH] Switch stacks in CALL32_Init(). --- include/main.h | 2 +- miscemu/main.c | 15 ++++++++------- tools/build.c | 21 +++++++++++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/main.h b/include/main.h index 6cd61abafc..6002a12666 100644 --- a/include/main.h +++ b/include/main.h @@ -17,7 +17,7 @@ extern void MAIN_ParseModeOption( char *arg ); extern BOOL RELAY_Init(void); extern int RELAY_ShowDebugmsgRelay(const char *func); -extern void* CALL32_Init(void); +extern void CALL32_Init( void *func, void *target, void *stack ); extern BOOL THUNK_Init(void); diff --git a/miscemu/main.c b/miscemu/main.c index 9c9962280d..953af4d351 100644 --- a/miscemu/main.c +++ b/miscemu/main.c @@ -158,13 +158,14 @@ int main( int argc, char *argv[] ) if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1; if ( !TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE ) ) return 1; - /* Initialize CALL32 routines */ - /* This needs to be done just before switching stacks */ - IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init(); - /* Switch to initial task */ - CURRENT_STACK16->frame32->retaddr = (DWORD)MAIN_EmulatorRun; - TASK_StartTask( PROCESS_Current()->task ); - MSG( "main: Should never happen: returned from TASK_StartTask()\n" ); + PostEvent16( PROCESS_Current()->task ); + TASK_Reschedule(); + + /* Switch stacks and jump to MAIN_EmulatorRun */ + CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, + THREAD_Current()->teb.stack_top ); + + MSG( "main: Should never happen: returned from CALL32_Init()\n" ); return 0; } diff --git a/tools/build.c b/tools/build.c index 3bd5e6dc94..6ae9601359 100644 --- a/tools/build.c +++ b/tools/build.c @@ -2488,11 +2488,20 @@ static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx ) * * The pointer to the function can be retrieved by calling CALL32_Init, * which also takes care of saving the current 32-bit stack pointer. + * Furthermore, CALL32_Init switches to a new stack and jumps to the + * specified target address. * * NOTE: The CALL32_LargeStack routine may be recursively entered by the * same thread, but not concurrently entered by several threads. * - * Stack layout: + * Stack layout of CALL32_Init: + * + * (esp+12) new stack address + * (esp+8) target address + * (esp+4) pointer to variable to receive CALL32_LargeStack address + * (esp) ret addr + * + * Stack layout of CALL32_LargeStack: * ... ... * (ebp+12) arg * (ebp+8) func @@ -2510,9 +2519,13 @@ static void BuildCallTo32LargeStack( FILE *outfile ) fprintf( outfile, "\t.globl " PREFIX "CALL32_Init\n" ); fprintf( outfile, "\t.type " PREFIX "CALL32_Init,@function\n" ); fprintf( outfile, PREFIX "CALL32_Init:\n" ); - fprintf( outfile, "\tleal -256(%%esp),%%eax\n" ); - fprintf( outfile, "\tmovl %%eax,CALL32_Original32_esp\n" ); - fprintf( outfile, "\tmovl $CALL32_LargeStack,%%eax\n" ); + fprintf( outfile, "\tmovl %%esp,CALL32_Original32_esp\n" ); + fprintf( outfile, "\tpopl %%eax\n" ); + fprintf( outfile, "\tpopl %%eax\n" ); + fprintf( outfile, "\tmovl $CALL32_LargeStack,(%%eax)\n" ); + fprintf( outfile, "\tpopl %%eax\n" ); + fprintf( outfile, "\tpopl %%esp\n" ); + fprintf( outfile, "\tpushl %%eax\n" ); fprintf( outfile, "\tret\n" ); /* Function header */ -- 2.32.0.93.g670b81a890