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"
17 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(relay
);
22 /***********************************************************************
30 /* Allocate the code selector for CallTo16 routines */
32 extern void Call16_Ret_Start(), Call16_Ret_End();
33 extern void CallTo16_Ret();
34 extern void CALL32_CBClient_Ret();
35 extern void CALL32_CBClientEx_Ret();
36 extern SEGPTR CallTo16_RetAddr
;
37 extern DWORD CallTo16_DataSelector
;
38 extern SEGPTR CALL32_CBClient_RetAddr
;
39 extern SEGPTR CALL32_CBClientEx_RetAddr
;
41 codesel
= SELECTOR_AllocBlock( (void *)Call16_Ret_Start
,
42 (char *)Call16_Ret_End
- (char *)Call16_Ret_Start
,
43 WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
44 if (!codesel
) return FALSE
;
46 /* Patch the return addresses for CallTo16 routines */
48 CallTo16_DataSelector
= __get_ds();
50 MAKESEGPTR( codesel
, (char*)CallTo16_Ret
- (char*)Call16_Ret_Start
);
51 CALL32_CBClient_RetAddr
=
52 MAKESEGPTR( codesel
, (char*)CALL32_CBClient_Ret
- (char*)Call16_Ret_Start
);
53 CALL32_CBClientEx_RetAddr
=
54 MAKESEGPTR( codesel
, (char*)CALL32_CBClientEx_Ret
- (char*)Call16_Ret_Start
);
60 * Stubs for the CallTo16/CallFrom16 routines on non-Intel architectures
61 * (these will never be called but need to be present to satisfy the linker ...)
64 /***********************************************************************
65 * wine_call_to_16_word (KERNEL32.@)
67 WORD WINAPI
wine_call_to_16_word( FARPROC16 target
, INT nArgs
)
72 /***********************************************************************
73 * wine_call_to_16_long (KERNEL32.@)
75 LONG WINAPI
wine_call_to_16_long( FARPROC16 target
, INT nArgs
)
80 /***********************************************************************
81 * wine_call_to_16_regs_short (KERNEL32.@)
83 void WINAPI
wine_call_to_16_regs_short( CONTEXT86
*context
, INT nArgs
)
88 /***********************************************************************
89 * wine_call_to_16_regs_long (KERNEL32.@)
91 void WINAPI
wine_call_to_16_regs_long ( CONTEXT86
*context
, INT nArgs
)
96 /***********************************************************************
97 * __wine_call_from_16_word (KERNEL32.@)
99 WORD __cdecl
__wine_call_from_16_word(void)
104 /***********************************************************************
105 * __wine_call_from_16_long (KERNEL32.@)
107 LONG __cdecl
__wine_call_from_16_long(void)
112 /***********************************************************************
113 * __wine_call_from_16_regs (KERNEL32.@)
115 void __cdecl
__wine_call_from_16_regs(void)
120 /***********************************************************************
121 * __wine_call_from_16_thunk (KERNEL32.@)
123 void __cdecl
__wine_call_from_16_thunk(void)
128 DWORD WINAPI
CALL32_CBClient( FARPROC proc
, LPWORD args
, DWORD
*esi
)
131 DWORD WINAPI
CALL32_CBClientEx( FARPROC proc
, LPWORD args
, DWORD
*esi
, INT
*nArgs
)
136 /* from relay32/relay386.c */
137 extern char **debug_relay_excludelist
,**debug_relay_includelist
;
138 extern int RELAY_ShowDebugmsgRelay(const char *func
);
140 /***********************************************************************
141 * RELAY_DebugCallFrom16
143 void RELAY_DebugCallFrom16( CONTEXT86
*context
)
147 char *args16
, funstr
[80];
149 int i
, usecdecl
, reg_func
;
151 if (!TRACE_ON(relay
)) return;
153 frame
= CURRENT_STACK16
;
154 args
= BUILTIN_GetEntryPoint16( frame
, funstr
, &ordinal
);
155 if (!args
) return; /* happens for the two snoop register relays */
156 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
157 DPRINTF( "Call %s(",funstr
);
158 VA_START16( args16
);
160 usecdecl
= ( *args
== 'c' );
162 reg_func
= ( memcmp( args
, "regs_", 5 ) == 0
163 || memcmp( args
, "intr_", 5 ) == 0 );
174 DPRINTF( "0x%04x", *(WORD
*)args16
);
178 DPRINTF( "0x%08x", *(int *)args16
);
182 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
187 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
188 debugres_a( MapSL(*(SEGPTR
*)args16
)) );
193 if (*args
) DPRINTF( "," );
198 /* Start with the last arg */
199 for (i
= 0; args
[i
]; i
++)
223 DPRINTF( "0x%04x", *(WORD
*)args16
);
227 DPRINTF( "0x%08x", *(int *)args16
);
231 DPRINTF( "0x%08x %s", *(int *)args16
,
232 debugres_a( MapSL(*(SEGPTR
*)args16
)));
236 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
240 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
241 debugres_a( MapSL(*(SEGPTR
*)args16
)));
245 if (*args
) DPRINTF( "," );
249 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame
->cs
, frame
->ip
, frame
->ds
);
253 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
254 AX_reg(context
), BX_reg(context
), CX_reg(context
),
255 DX_reg(context
), SI_reg(context
), DI_reg(context
),
256 (WORD
)context
->SegEs
, context
->EFlags
);
258 SYSLEVEL_CheckNotLevel( 2 );
262 /***********************************************************************
263 * RELAY_DebugCallFrom16Ret
265 void RELAY_DebugCallFrom16Ret( CONTEXT86
*context
, int ret_val
)
272 if (!TRACE_ON(relay
)) return;
273 frame
= CURRENT_STACK16
;
274 args
= BUILTIN_GetEntryPoint16( frame
, funstr
, &ordinal
);
276 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
277 DPRINTF( "Ret %s() ",funstr
);
279 if ( memcmp( args
+2, "long_", 5 ) == 0 )
281 DPRINTF( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
282 ret_val
, frame
->cs
, frame
->ip
, frame
->ds
);
284 else if ( memcmp( args
+2, "word_", 5 ) == 0 )
286 DPRINTF( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
287 ret_val
& 0xffff, frame
->cs
, frame
->ip
, frame
->ds
);
289 else if ( memcmp( args
+2, "regs_", 5 ) == 0
290 || memcmp( args
+2, "intr_", 5 ) == 0 )
292 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
293 (WORD
)context
->SegCs
, LOWORD(context
->Eip
), (WORD
)context
->SegDs
);
294 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
295 AX_reg(context
), BX_reg(context
), CX_reg(context
),
296 DX_reg(context
), SI_reg(context
), DI_reg(context
),
297 (WORD
)context
->SegEs
, context
->EFlags
);
300 SYSLEVEL_CheckNotLevel( 2 );
304 /***********************************************************************
305 * RELAY_DebugCallTo16
307 * 'target' contains either the function to call (normal CallTo16)
308 * or a pointer to the CONTEXT86 struct (register CallTo16).
309 * 'nb_args' is the number of argument bytes on the 16-bit stack;
310 * 'reg_func' specifies whether we have a register CallTo16 or not.
312 void RELAY_DebugCallTo16( LPVOID target
, int nb_args
, BOOL reg_func
)
317 if (!TRACE_ON(relay
)) return;
318 teb
= NtCurrentTeb();
319 stack16
= (WORD
*)THREAD_STACK16(teb
);
321 nb_args
/= sizeof(WORD
);
325 CONTEXT86
*context
= (CONTEXT86
*)target
;
327 DPRINTF("CallTo16(func=%04lx:%04x,ds=%04lx",
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("CallTo16(func=%04x:%04x,ds=%04x",
340 HIWORD(target
), LOWORD(target
), SELECTOROF(teb
->cur_stack
) );
341 while (nb_args
--) DPRINTF( ",0x%04x", *--stack16
);
342 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb
->cur_stack
),
343 OFFSETOF(teb
->cur_stack
) );
346 SYSLEVEL_CheckNotLevel( 2 );
350 /***********************************************************************
351 * RELAY_DebugCallTo16Ret
353 void RELAY_DebugCallTo16Ret( BOOL reg_func
, int ret_val
)
355 if (!TRACE_ON(relay
)) return;
359 DPRINTF("CallTo16() ss:sp=%04x:%04x retval=0x%08x\n",
360 SELECTOROF(NtCurrentTeb()->cur_stack
),
361 OFFSETOF(NtCurrentTeb()->cur_stack
), ret_val
);
365 CONTEXT86
*context
= (CONTEXT86
*)ret_val
;
367 DPRINTF("CallTo16() ss:sp=%04x:%04x\n",
368 SELECTOROF(NtCurrentTeb()->cur_stack
),
369 OFFSETOF(NtCurrentTeb()->cur_stack
));
370 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x BP=%04x SP=%04x\n",
371 AX_reg(context
), BX_reg(context
), CX_reg(context
),
372 DX_reg(context
), BP_reg(context
), LOWORD(context
->Esp
));
375 SYSLEVEL_CheckNotLevel( 2 );