2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Alexandre Julliard
9 #include "wine/winbase16.h"
13 #include "stackframe.h"
14 #include "selectors.h"
15 #include "builtin16.h"
18 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(relay);
24 /***********************************************************************
32 /* Allocate the code selector for CallTo16 routines */
34 extern void Call16_Ret_Start(), Call16_Ret_End();
35 extern void CallTo16_Ret();
36 extern void CALL32_CBClient_Ret();
37 extern void CALL32_CBClientEx_Ret();
38 extern SEGPTR CallTo16_RetAddr;
39 extern DWORD CallTo16_DataSelector;
40 extern SEGPTR CALL32_CBClient_RetAddr;
41 extern SEGPTR CALL32_CBClientEx_RetAddr;
43 codesel = SELECTOR_AllocBlock( (void *)Call16_Ret_Start,
44 (char *)Call16_Ret_End - (char *)Call16_Ret_Start,
45 WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
46 if (!codesel) return FALSE;
48 /* Patch the return addresses for CallTo16 routines */
50 CallTo16_DataSelector = __get_ds();
52 PTR_SEG_OFF_TO_SEGPTR( codesel, (char*)CallTo16_Ret - (char*)Call16_Ret_Start );
53 CALL32_CBClient_RetAddr =
54 PTR_SEG_OFF_TO_SEGPTR( codesel, (char*)CALL32_CBClient_Ret - (char*)Call16_Ret_Start );
55 CALL32_CBClientEx_RetAddr =
56 PTR_SEG_OFF_TO_SEGPTR( codesel, (char*)CALL32_CBClientEx_Ret - (char*)Call16_Ret_Start );
62 * Stubs for the CallTo16/CallFrom16 routines on non-Intel architectures
63 * (these will never be called but need to be present to satisfy the linker ...)
66 WORD CALLBACK CallTo16Word( FARPROC16 target, INT nArgs )
69 LONG CALLBACK CallTo16Long( FARPROC16 target, INT nArgs )
72 void CALLBACK CallTo16RegisterShort( CONTEXT86 *context, INT nArgs )
75 void CALLBACK CallTo16RegisterLong ( CONTEXT86 *context, INT nArgs )
78 /***********************************************************************
79 * __wine_call_from_16_word
81 WORD __cdecl __wine_call_from_16_word(...)
86 /***********************************************************************
87 * __wine_call_from_16_long
89 LONG __cdecl __wine_call_from_16_long(...)
94 /***********************************************************************
95 * __wine_call_from_16_regs
97 void __cdecl __wine_call_from_16_regs(...)
102 /***********************************************************************
103 * __wine_call_from_16_thunk
105 void __cdecl __wine_call_from_16_thunk(...)
110 DWORD WINAPI CALL32_CBClient( FARPROC proc, LPWORD args, DWORD *esi )
113 DWORD WINAPI CALL32_CBClientEx( FARPROC proc, LPWORD args, DWORD *esi, INT *nArgs )
118 /* from relay32/relay386.c */
119 extern char **debug_relay_excludelist,**debug_relay_includelist;
121 /***********************************************************************
122 * RELAY_DebugCallFrom16
124 void RELAY_DebugCallFrom16( CONTEXT86 *context )
128 char *args16, funstr[80];
130 int i, usecdecl, reg_func;
132 if (!TRACE_ON(relay)) return;
134 frame = CURRENT_STACK16;
135 args = BUILTIN_GetEntryPoint16( frame, funstr, &ordinal );
136 if (!args) return; /* happens for the two snoop register relays */
137 if (!RELAY_ShowDebugmsgRelay(funstr)) return;
138 DPRINTF( "Call %s(",funstr);
139 VA_START16( args16 );
141 usecdecl = ( *args == 'c' );
143 reg_func = ( memcmp( args, "regs_", 5 ) == 0
144 || memcmp( args, "intr_", 5 ) == 0 );
155 DPRINTF( "0x%04x", *(WORD *)args16 );
159 DPRINTF( "0x%08x", *(int *)args16 );
163 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
168 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
169 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )) );
174 if (*args) DPRINTF( "," );
179 /* Start with the last arg */
180 for (i = 0; args[i]; i++)
204 DPRINTF( "0x%04x", *(WORD *)args16 );
208 DPRINTF( "0x%08x", *(int *)args16 );
212 DPRINTF( "0x%08x %s", *(int *)args16,
213 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
217 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
221 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
222 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
226 if (*args) DPRINTF( "," );
230 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
234 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
235 AX_reg(context), BX_reg(context), CX_reg(context),
236 DX_reg(context), SI_reg(context), DI_reg(context),
237 (WORD)context->SegEs, context->EFlags );
239 SYSLEVEL_CheckNotLevel( 2 );
243 /***********************************************************************
244 * RELAY_DebugCallFrom16Ret
246 void RELAY_DebugCallFrom16Ret( CONTEXT86 *context, int ret_val )
253 if (!TRACE_ON(relay)) return;
254 frame = CURRENT_STACK16;
255 args = BUILTIN_GetEntryPoint16( frame, funstr, &ordinal );
257 if (!RELAY_ShowDebugmsgRelay(funstr)) return;
258 DPRINTF( "Ret %s() ",funstr);
260 if ( memcmp( args+2, "long_", 5 ) == 0 )
262 DPRINTF( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
263 ret_val, frame->cs, frame->ip, frame->ds );
265 else if ( memcmp( args+2, "word_", 5 ) == 0 )
267 DPRINTF( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
268 ret_val & 0xffff, frame->cs, frame->ip, frame->ds );
270 else if ( memcmp( args+2, "regs_", 5 ) == 0
271 || memcmp( args+2, "intr_", 5 ) == 0 )
273 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
274 (WORD)context->SegCs, LOWORD(context->Eip), (WORD)context->SegDs);
275 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
276 AX_reg(context), BX_reg(context), CX_reg(context),
277 DX_reg(context), SI_reg(context), DI_reg(context),
278 (WORD)context->SegEs, context->EFlags );
281 SYSLEVEL_CheckNotLevel( 2 );
285 /***********************************************************************
286 * RELAY_DebugCallTo16
288 * 'target' contains either the function to call (normal CallTo16)
289 * or a pointer to the CONTEXT86 struct (register CallTo16).
290 * 'nb_args' is the number of argument bytes on the 16-bit stack;
291 * 'reg_func' specifies whether we have a register CallTo16 or not.
293 void RELAY_DebugCallTo16( LPVOID target, int nb_args, BOOL reg_func )
298 if (!TRACE_ON(relay)) return;
299 teb = NtCurrentTeb();
300 stack16 = (WORD *)THREAD_STACK16(teb);
302 nb_args /= sizeof(WORD);
306 CONTEXT86 *context = (CONTEXT86 *)target;
308 DPRINTF("CallTo16(func=%04lx:%04x,ds=%04lx",
309 context->SegCs, LOWORD(context->Eip), context->SegDs );
310 while (nb_args--) DPRINTF( ",0x%04x", *--stack16 );
311 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb->cur_stack),
312 OFFSETOF(teb->cur_stack) );
313 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x BP=%04x ES=%04x FS=%04x\n",
314 AX_reg(context), BX_reg(context), CX_reg(context),
315 DX_reg(context), SI_reg(context), DI_reg(context),
316 BP_reg(context), (WORD)context->SegEs, (WORD)context->SegFs );
320 DPRINTF("CallTo16(func=%04x:%04x,ds=%04x",
321 HIWORD(target), LOWORD(target), SELECTOROF(teb->cur_stack) );
322 while (nb_args--) DPRINTF( ",0x%04x", *--stack16 );
323 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb->cur_stack),
324 OFFSETOF(teb->cur_stack) );
327 SYSLEVEL_CheckNotLevel( 2 );
331 /***********************************************************************
332 * RELAY_DebugCallTo16Ret
334 void RELAY_DebugCallTo16Ret( BOOL reg_func, int ret_val )
336 if (!TRACE_ON(relay)) return;
340 DPRINTF("CallTo16() ss:sp=%04x:%04x retval=0x%08x\n",
341 SELECTOROF(NtCurrentTeb()->cur_stack),
342 OFFSETOF(NtCurrentTeb()->cur_stack), ret_val);
346 CONTEXT86 *context = (CONTEXT86 *)ret_val;
348 DPRINTF("CallTo16() ss:sp=%04x:%04x\n",
349 SELECTOROF(NtCurrentTeb()->cur_stack),
350 OFFSETOF(NtCurrentTeb()->cur_stack));
351 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x BP=%04x SP=%04x\n",
352 AX_reg(context), BX_reg(context), CX_reg(context),
353 DX_reg(context), BP_reg(context), LOWORD(context->Esp));
356 SYSLEVEL_CheckNotLevel( 2 );