2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Alexandre Julliard
10 #include "registers.h"
11 #include "stackframe.h"
14 /* #define DEBUG_RELAY */
18 /* Make make_debug think these were really used */
23 /***********************************************************************
26 BOOL32
RELAY_Init(void)
30 /* Allocate the code selector for CallTo16 routines */
32 extern void CALLTO16_Start(), CALLTO16_End();
33 extern void CALLTO16_Ret_word(), CALLTO16_Ret_long();
34 extern DWORD CALLTO16_RetAddr_word
, CALLTO16_RetAddr_long
;
36 codesel
= GLOBAL_CreateBlock( GMEM_FIXED
, (void *)CALLTO16_Start
,
37 (int)CALLTO16_End
- (int)CALLTO16_Start
,
38 0, TRUE
, TRUE
, FALSE
, NULL
);
39 if (!codesel
) return FALSE
;
41 /* Patch the return addresses for CallTo16 routines */
43 CALLTO16_RetAddr_word
=MAKELONG( (int)CALLTO16_Ret_word
-(int)CALLTO16_Start
,
45 CALLTO16_RetAddr_long
=MAKELONG( (int)CALLTO16_Ret_long
-(int)CALLTO16_Start
,
51 /***********************************************************************
52 * RELAY_DebugCallFrom16
54 void RELAY_DebugCallFrom16( int func_type
, char *args
,
55 void *entry_point
, SIGCONTEXT
*context
)
62 if (!debugging_relay
) return;
64 frame
= CURRENT_STACK16
;
65 printf( "Call %s(", BUILTIN_GetEntryPoint16( frame
->entry_cs
,
68 args16
= (char *)frame
->args
;
69 for (i
= 0; i
< strlen(args
); i
++)
91 printf( "0x%04x", *(WORD
*)args16
);
95 printf( "0x%08x", *(int *)args16
);
99 printf( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
103 if (*args
) printf( "," );
105 printf( ") ret=%04x:%04x ds=%04x\n", frame
->cs
, frame
->ip
, frame
->ds
);
107 if (func_type
== 2) /* register function */
108 printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
109 AX_reg(context
), BX_reg(context
), CX_reg(context
),
110 DX_reg(context
), SI_reg(context
), DI_reg(context
),
111 ES_reg(context
), EFL_reg(context
) );
115 /***********************************************************************
116 * RELAY_DebugCallFrom16Ret
118 void RELAY_DebugCallFrom16Ret( int func_type
, int ret_val
, SIGCONTEXT
*context
)
123 if (*(DWORD
*)PTR_SEG_TO_LIN(IF1632_Stack32_base
) != 0xDEADBEEF)
125 fprintf(stderr
, "Wine wrote past the end of the 32 bit stack. Please report this.\n");
126 exit(1); /* There's probably no point in going on */
128 if (!debugging_relay
) return;
130 frame
= CURRENT_STACK16
;
131 printf( "Ret %s() ", BUILTIN_GetEntryPoint16( frame
->entry_cs
,
137 printf( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
138 ret_val
, frame
->cs
, frame
->ip
, frame
->ds
);
141 printf( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
142 ret_val
& 0xffff, frame
->cs
, frame
->ip
, frame
->ds
);
145 printf( "retval=none ret=%04x:%04x ds=%04x\n",
146 frame
->cs
, frame
->ip
, frame
->ds
);
147 printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
148 AX_reg(context
), BX_reg(context
), CX_reg(context
),
149 DX_reg(context
), SI_reg(context
), DI_reg(context
),
150 ES_reg(context
), EFL_reg(context
) );
156 /***********************************************************************
157 * RELAY_Unimplemented16
159 * This function is called for unimplemented 16-bit entry points (declared
160 * as 'stub' in the spec file).
162 void RELAY_Unimplemented16(void)
165 STACK16FRAME
*frame
= CURRENT_STACK16
;
166 fprintf(stderr
,"No handler for Win16 routine %s (called from %04x:%04x)\n",
167 BUILTIN_GetEntryPoint16(frame
->entry_cs
,frame
->entry_ip
,&ordinal
),
168 frame
->cs
, frame
->ip
);
169 TASK_KillCurrentTask(1);
173 /***********************************************************************
174 * RELAY_Unimplemented32
176 * This function is called for unimplemented 32-bit entry points (declared
177 * as 'stub' in the spec file).
178 * (The args are the same than for RELAY_DebugCallFrom32).
180 void RELAY_Unimplemented32( int nb_args
, void *relay_addr
,
181 void *entry_point
, int ebp
, int ret_addr
)
183 fprintf( stderr
, "No handler for Win32 routine %s (called from %08x)\n",
184 BUILTIN_GetEntryPoint32( relay_addr
), ret_addr
);
185 TASK_KillCurrentTask(1);
189 /***********************************************************************
190 * RELAY_DebugCallTo16
192 * 'stack' points to the called function address on the 32-bit stack.
197 * (stack+4) 16-bit ds
198 * (stack) func to call
200 void RELAY_DebugCallTo16( int* stack
, int nbargs
)
202 if (!debugging_relay
) return;
204 printf( "CallTo16(func=%04x:%04x,ds=%04x",
205 HIWORD(stack
[0]), LOWORD(stack
[0]), LOWORD(stack
[1]) );
207 while (nbargs
--) printf( ",0x%04x", *stack
++ );
212 /***********************************************************************
213 * RELAY_DebugCallFrom32
215 * 'stack' points to the saved ebp on the stack.
222 * (stack-4) entry point
223 * (stack-8) relay addr
225 void RELAY_DebugCallFrom32( int *stack
, int nb_args
)
229 if (!debugging_relay
) return;
230 printf( "Call %s(", BUILTIN_GetEntryPoint32( (void *)stack
[-2] ));
233 for (parg
= &stack
[2]; nb_args
; parg
++, nb_args
--)
235 printf( "%08x", *parg
);
236 if (nb_args
> 1) printf( "," );
239 printf( ") ret=%08x\n", stack
[1] );
240 if (nb_args
== -1) /* Register function */
242 CONTEXT
*context
= (CONTEXT
*)((BYTE
*)stack
- sizeof(CONTEXT
) - 12);
243 printf( " EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
244 context
->Eax
, context
->Ebx
, context
->Ecx
, context
->Edx
,
245 context
->Esi
, context
->Edi
);
246 printf( " EBP=%08lx ESP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
247 context
->Ebp
, context
->Esp
, context
->SegDs
, context
->SegEs
,
248 context
->SegFs
, context
->SegGs
, context
->EFlags
);
253 /***********************************************************************
254 * RELAY_DebugCallFrom32Ret
256 * 'stack' points to the saved ebp on the stack.
263 * (stack-4) entry point
264 * (stack-8) relay addr
266 void RELAY_DebugCallFrom32Ret( int *stack
, int nb_args
, int ret_val
)
268 if (!debugging_relay
) return;
269 printf( "Ret %s() retval=%08x ret=%08x\n",
270 BUILTIN_GetEntryPoint32( (void *)stack
[-2] ), ret_val
, stack
[1] );
271 if (nb_args
== -1) /* Register function */
273 CONTEXT
*context
= (CONTEXT
*)((BYTE
*)stack
- sizeof(CONTEXT
) - 12);
274 printf( " EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
275 context
->Eax
, context
->Ebx
, context
->Ecx
, context
->Edx
,
276 context
->Esi
, context
->Edi
);
277 printf( " EBP=%08lx ESP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
278 context
->Ebp
, context
->Esp
, context
->SegDs
, context
->SegEs
,
279 context
->SegFs
, context
->SegGs
, context
->EFlags
);
284 /***********************************************************************
285 * RELAY_DebugCallTo32
287 void RELAY_DebugCallTo32( unsigned int func
, int nbargs
, unsigned int arg1
)
289 unsigned int *argptr
;
291 if (!debugging_relay
) return;
293 printf( "CallTo32(func=%08x", func
);
294 for (argptr
= &arg1
; nbargs
; nbargs
--, argptr
++)
295 printf( ",%08x", *argptr
);
300 /**********************************************************************
303 INT16
Catch( LPCATCHBUF lpbuf
)
305 STACK16FRAME
*pFrame
= CURRENT_STACK16
;
307 /* Note: we don't save the current ss, as the catch buffer is */
308 /* only 9 words long. Hopefully no one will have the silly */
309 /* idea to change the current stack before calling Throw()... */
322 /* FIXME: we need to save %si and %di */
324 lpbuf
[0] = IF1632_Saved16_sp
;
325 lpbuf
[1] = LOWORD(IF1632_Saved32_esp
);
326 lpbuf
[2] = HIWORD(IF1632_Saved32_esp
);
327 lpbuf
[3] = pFrame
->saved_ss
;
328 lpbuf
[4] = pFrame
->saved_sp
;
329 lpbuf
[5] = pFrame
->ds
;
330 lpbuf
[6] = pFrame
->bp
;
331 lpbuf
[7] = pFrame
->ip
;
332 lpbuf
[8] = pFrame
->cs
;
337 /**********************************************************************
340 INT16
Throw( LPCATCHBUF lpbuf
, INT16 retval
)
342 STACK16FRAME
*pFrame
;
343 WORD es
= CURRENT_STACK16
->es
;
345 IF1632_Saved16_sp
= lpbuf
[0] - sizeof(WORD
);
346 IF1632_Saved32_esp
= MAKELONG( lpbuf
[1], lpbuf
[2] );
347 pFrame
= CURRENT_STACK16
;
348 pFrame
->saved_ss
= lpbuf
[3];
349 pFrame
->saved_sp
= lpbuf
[4];
350 pFrame
->ds
= lpbuf
[5];
351 pFrame
->bp
= lpbuf
[6];
352 pFrame
->ip
= lpbuf
[7];
353 pFrame
->cs
= lpbuf
[8];
355 if (debugging_relay
) /* Make sure we have a valid entry point address */
357 static FARPROC16 entryPoint
= NULL
;
359 if (!entryPoint
) /* Get entry point for Throw() */
360 entryPoint
= MODULE_GetEntryPoint( GetModuleHandle("KERNEL"), 56 );
361 pFrame
->entry_cs
= SELECTOROF(entryPoint
);
362 pFrame
->entry_ip
= OFFSETOF(entryPoint
);