2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Alexandre Julliard
9 #include "wine/winbase16.h"
12 #include "stackframe.h"
13 #include "selectors.h"
14 #include "builtin16.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(relay
);
21 /***********************************************************************
29 /* Allocate the code selector for CallTo16 routines */
31 extern void Call16_Ret_Start(), Call16_Ret_End();
32 extern void CallTo16_Ret();
33 extern void CALL32_CBClient_Ret();
34 extern void CALL32_CBClientEx_Ret();
35 extern SEGPTR CallTo16_RetAddr
;
36 extern DWORD CallTo16_DataSelector
;
37 extern SEGPTR CALL32_CBClient_RetAddr
;
38 extern SEGPTR CALL32_CBClientEx_RetAddr
;
40 codesel
= SELECTOR_AllocBlock( (void *)Call16_Ret_Start
,
41 (char *)Call16_Ret_End
- (char *)Call16_Ret_Start
,
42 WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
43 if (!codesel
) return FALSE
;
45 /* Patch the return addresses for CallTo16 routines */
47 CallTo16_DataSelector
= __get_ds();
49 MAKESEGPTR( codesel
, (char*)CallTo16_Ret
- (char*)Call16_Ret_Start
);
50 CALL32_CBClient_RetAddr
=
51 MAKESEGPTR( codesel
, (char*)CALL32_CBClient_Ret
- (char*)Call16_Ret_Start
);
52 CALL32_CBClientEx_RetAddr
=
53 MAKESEGPTR( codesel
, (char*)CALL32_CBClientEx_Ret
- (char*)Call16_Ret_Start
);
59 * Stubs for the CallTo16/CallFrom16 routines on non-Intel architectures
60 * (these will never be called but need to be present to satisfy the linker ...)
63 /***********************************************************************
64 * wine_call_to_16_word (KERNEL32.@)
66 WORD WINAPI
wine_call_to_16_word( FARPROC16 target
, INT nArgs
)
71 /***********************************************************************
72 * wine_call_to_16_long (KERNEL32.@)
74 LONG WINAPI
wine_call_to_16_long( FARPROC16 target
, INT nArgs
)
79 /***********************************************************************
80 * wine_call_to_16_regs_short (KERNEL32.@)
82 void WINAPI
wine_call_to_16_regs_short( CONTEXT86
*context
, INT nArgs
)
87 /***********************************************************************
88 * wine_call_to_16_regs_long (KERNEL32.@)
90 void WINAPI
wine_call_to_16_regs_long ( CONTEXT86
*context
, INT nArgs
)
95 /***********************************************************************
96 * __wine_call_from_16_word (KERNEL32.@)
98 WORD
__wine_call_from_16_word()
103 /***********************************************************************
104 * __wine_call_from_16_long (KERNEL32.@)
106 LONG
__wine_call_from_16_long()
111 /***********************************************************************
112 * __wine_call_from_16_regs (KERNEL32.@)
114 void __wine_call_from_16_regs()
119 /***********************************************************************
120 * __wine_call_from_16_thunk (KERNEL32.@)
122 void __wine_call_from_16_thunk()
127 DWORD WINAPI
CALL32_CBClient( FARPROC proc
, LPWORD args
, DWORD
*esi
)
130 DWORD WINAPI
CALL32_CBClientEx( FARPROC proc
, LPWORD args
, DWORD
*esi
, INT
*nArgs
)
135 /* from relay32/relay386.c */
136 extern char **debug_relay_excludelist
,**debug_relay_includelist
;
137 extern int RELAY_ShowDebugmsgRelay(const char *func
);
139 /***********************************************************************
140 * RELAY_DebugCallFrom16
142 void RELAY_DebugCallFrom16( CONTEXT86
*context
)
146 char *args16
, funstr
[80];
148 int i
, usecdecl
, reg_func
;
150 if (!TRACE_ON(relay
)) return;
152 frame
= CURRENT_STACK16
;
153 args
= BUILTIN_GetEntryPoint16( frame
, funstr
, &ordinal
);
154 if (!args
) return; /* happens for the two snoop register relays */
155 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
156 DPRINTF( "%08lx:Call %s(",GetCurrentThreadId(),funstr
);
157 VA_START16( args16
);
159 usecdecl
= ( *args
== 'c' );
161 reg_func
= ( memcmp( args
, "regs_", 5 ) == 0
162 || memcmp( args
, "intr_", 5 ) == 0 );
173 DPRINTF( "0x%04x", *(WORD
*)args16
);
177 DPRINTF( "0x%08x", *(int *)args16
);
181 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
186 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
187 debugres_a( MapSL(*(SEGPTR
*)args16
)) );
192 if (*args
) DPRINTF( "," );
197 /* Start with the last arg */
198 for (i
= 0; args
[i
]; i
++)
222 DPRINTF( "0x%04x", *(WORD
*)args16
);
226 DPRINTF( "0x%08x", *(int *)args16
);
230 DPRINTF( "0x%08x %s", *(int *)args16
,
231 debugres_a( MapSL(*(SEGPTR
*)args16
)));
235 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
239 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
240 debugres_a( MapSL(*(SEGPTR
*)args16
)));
244 if (*args
) DPRINTF( "," );
248 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame
->cs
, frame
->ip
, frame
->ds
);
252 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
253 AX_reg(context
), BX_reg(context
), CX_reg(context
),
254 DX_reg(context
), SI_reg(context
), DI_reg(context
),
255 (WORD
)context
->SegEs
, context
->EFlags
);
257 SYSLEVEL_CheckNotLevel( 2 );
261 /***********************************************************************
262 * RELAY_DebugCallFrom16Ret
264 void RELAY_DebugCallFrom16Ret( CONTEXT86
*context
, int ret_val
)
271 if (!TRACE_ON(relay
)) return;
272 frame
= CURRENT_STACK16
;
273 args
= BUILTIN_GetEntryPoint16( frame
, funstr
, &ordinal
);
275 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
276 DPRINTF( "%08lx:Ret %s() ",GetCurrentThreadId(),funstr
);
278 if ( memcmp( args
+2, "long_", 5 ) == 0 )
280 DPRINTF( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
281 ret_val
, frame
->cs
, frame
->ip
, frame
->ds
);
283 else if ( memcmp( args
+2, "word_", 5 ) == 0 )
285 DPRINTF( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
286 ret_val
& 0xffff, frame
->cs
, frame
->ip
, frame
->ds
);
288 else if ( memcmp( args
+2, "regs_", 5 ) == 0
289 || memcmp( args
+2, "intr_", 5 ) == 0 )
291 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
292 (WORD
)context
->SegCs
, LOWORD(context
->Eip
), (WORD
)context
->SegDs
);
293 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
294 AX_reg(context
), BX_reg(context
), CX_reg(context
),
295 DX_reg(context
), SI_reg(context
), DI_reg(context
),
296 (WORD
)context
->SegEs
, context
->EFlags
);
299 SYSLEVEL_CheckNotLevel( 2 );
303 /***********************************************************************
304 * RELAY_DebugCallTo16
306 * 'target' contains either the function to call (normal CallTo16)
307 * or a pointer to the CONTEXT86 struct (register CallTo16).
308 * 'nb_args' is the number of argument bytes on the 16-bit stack;
309 * 'reg_func' specifies whether we have a register CallTo16 or not.
311 void RELAY_DebugCallTo16( LPVOID target
, int nb_args
, BOOL reg_func
)
316 if (!TRACE_ON(relay
)) return;
317 teb
= NtCurrentTeb();
318 stack16
= (WORD
*)THREAD_STACK16(teb
);
320 nb_args
/= sizeof(WORD
);
324 CONTEXT86
*context
= (CONTEXT86
*)target
;
326 DPRINTF("%08lx:CallTo16(func=%04lx:%04x,ds=%04lx",
327 GetCurrentThreadId(),
328 context
->SegCs
, LOWORD(context
->Eip
), context
->SegDs
);
329 while (nb_args
--) DPRINTF( ",0x%04x", *--stack16
);
330 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb
->cur_stack
),
331 OFFSETOF(teb
->cur_stack
) );
332 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x BP=%04x ES=%04x FS=%04x\n",
333 AX_reg(context
), BX_reg(context
), CX_reg(context
),
334 DX_reg(context
), SI_reg(context
), DI_reg(context
),
335 BP_reg(context
), (WORD
)context
->SegEs
, (WORD
)context
->SegFs
);
339 DPRINTF("%08lx:CallTo16(func=%04x:%04x,ds=%04x",
340 GetCurrentThreadId(),
341 HIWORD(target
), LOWORD(target
), SELECTOROF(teb
->cur_stack
) );
342 while (nb_args
--) DPRINTF( ",0x%04x", *--stack16
);
343 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb
->cur_stack
),
344 OFFSETOF(teb
->cur_stack
) );
347 SYSLEVEL_CheckNotLevel( 2 );
351 /***********************************************************************
352 * RELAY_DebugCallTo16Ret
354 void RELAY_DebugCallTo16Ret( BOOL reg_func
, int ret_val
)
356 if (!TRACE_ON(relay
)) return;
360 DPRINTF("%08lx:RetFrom16() ss:sp=%04x:%04x retval=0x%08x\n",
361 GetCurrentThreadId(),
362 SELECTOROF(NtCurrentTeb()->cur_stack
),
363 OFFSETOF(NtCurrentTeb()->cur_stack
), ret_val
);
367 CONTEXT86
*context
= (CONTEXT86
*)ret_val
;
369 DPRINTF("%08lx:RetFrom16() ss:sp=%04x:%04x\n",
370 GetCurrentThreadId(),
371 SELECTOROF(NtCurrentTeb()->cur_stack
),
372 OFFSETOF(NtCurrentTeb()->cur_stack
));
373 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x BP=%04x SP=%04x\n",
374 AX_reg(context
), BX_reg(context
), CX_reg(context
),
375 DX_reg(context
), BP_reg(context
), LOWORD(context
->Esp
));
378 SYSLEVEL_CheckNotLevel( 2 );