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 SEGPTR CALL32_CBClient_RetAddr
;
40 extern SEGPTR CALL32_CBClientEx_RetAddr
;
42 codesel
= SELECTOR_AllocBlock( (void *)Call16_Ret_Start
,
43 (char *)Call16_Ret_End
- (char *)Call16_Ret_Start
,
44 SEGMENT_CODE
, TRUE
, FALSE
);
45 if (!codesel
) return FALSE
;
47 /* Patch the return addresses for CallTo16 routines */
50 PTR_SEG_OFF_TO_SEGPTR( codesel
, (char*)CallTo16_Ret
- (char*)Call16_Ret_Start
);
51 CALL32_CBClient_RetAddr
=
52 PTR_SEG_OFF_TO_SEGPTR( codesel
, (char*)CALL32_CBClient_Ret
- (char*)Call16_Ret_Start
);
53 CALL32_CBClientEx_RetAddr
=
54 PTR_SEG_OFF_TO_SEGPTR( 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 WORD CALLBACK
CallTo16Word( FARPROC16 target
, INT nArgs
)
67 LONG CALLBACK
CallTo16Long( FARPROC16 target
, INT nArgs
)
70 LONG CALLBACK
CallTo16RegisterShort( const CONTEXT86
*context
, INT nArgs
)
73 LONG CALLBACK
CallTo16RegisterLong ( const CONTEXT86
*context
, INT nArgs
)
76 WORD
CallFrom16Word( void )
79 LONG
CallFrom16Long( void )
82 void CallFrom16Register( void )
85 void CallFrom16Thunk( void )
88 DWORD WINAPI
CALL32_CBClient( FARPROC proc
, LPWORD args
, DWORD
*esi
)
91 DWORD WINAPI
CALL32_CBClientEx( FARPROC proc
, LPWORD args
, DWORD
*esi
, INT
*nArgs
)
96 /* from relay32/relay386.c */
97 extern char **debug_relay_excludelist
,**debug_relay_includelist
;
99 /***********************************************************************
100 * RELAY_DebugCallFrom16
102 void RELAY_DebugCallFrom16( CONTEXT86
*context
)
106 char *args16
, funstr
[80];
108 int i
, usecdecl
, reg_func
;
110 if (!TRACE_ON(relay
)) return;
112 frame
= CURRENT_STACK16
;
113 args
= BUILTIN_GetEntryPoint16( frame
, funstr
, &ordinal
);
114 if (!args
) return; /* happens for the two snoop register relays */
115 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
116 DPRINTF( "Call %s(",funstr
);
117 VA_START16( args16
);
119 usecdecl
= ( *args
== 'c' );
121 reg_func
= ( memcmp( args
, "regs_", 5 ) == 0
122 || memcmp( args
, "intr_", 5 ) == 0 );
133 DPRINTF( "0x%04x", *(WORD
*)args16
);
137 DPRINTF( "0x%08x", *(int *)args16
);
141 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
146 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
147 debugres_a( (LPSTR
)PTR_SEG_TO_LIN(*(SEGPTR
*)args16
)) );
152 if (*args
) DPRINTF( "," );
157 /* Start with the last arg */
158 for (i
= 0; args
[i
]; i
++)
182 DPRINTF( "0x%04x", *(WORD
*)args16
);
186 DPRINTF( "0x%08x", *(int *)args16
);
190 DPRINTF( "0x%08x %s", *(int *)args16
,
191 debugres_a( (LPSTR
)PTR_SEG_TO_LIN(*(SEGPTR
*)args16
)));
195 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
199 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
200 debugres_a( (LPSTR
)PTR_SEG_TO_LIN(*(SEGPTR
*)args16
)));
204 if (*args
) DPRINTF( "," );
208 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame
->cs
, frame
->ip
, frame
->ds
);
212 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
213 AX_reg(context
), BX_reg(context
), CX_reg(context
),
214 DX_reg(context
), SI_reg(context
), DI_reg(context
),
215 (WORD
)ES_reg(context
), EFL_reg(context
) );
217 SYSLEVEL_CheckNotLevel( 2 );
221 /***********************************************************************
222 * RELAY_DebugCallFrom16Ret
224 void RELAY_DebugCallFrom16Ret( CONTEXT86
*context
, int ret_val
)
231 if (!TRACE_ON(relay
)) return;
232 frame
= CURRENT_STACK16
;
233 args
= BUILTIN_GetEntryPoint16( frame
, funstr
, &ordinal
);
235 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
236 DPRINTF( "Ret %s() ",funstr
);
238 if ( memcmp( args
+2, "long_", 5 ) == 0 )
240 DPRINTF( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
241 ret_val
, frame
->cs
, frame
->ip
, frame
->ds
);
243 else if ( memcmp( args
+2, "word_", 5 ) == 0 )
245 DPRINTF( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
246 ret_val
& 0xffff, frame
->cs
, frame
->ip
, frame
->ds
);
248 else if ( memcmp( args
+2, "regs_", 5 ) == 0
249 || memcmp( args
+2, "intr_", 5 ) == 0 )
251 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
252 (WORD
)CS_reg(context
), LOWORD(EIP_reg(context
)), (WORD
)DS_reg(context
));
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
)ES_reg(context
), EFL_reg(context
) );
259 SYSLEVEL_CheckNotLevel( 2 );
263 /***********************************************************************
264 * RELAY_Unimplemented16
266 * This function is called for unimplemented 16-bit entry points (declared
267 * as 'stub' in the spec file).
269 void RELAY_Unimplemented16(void)
273 STACK16FRAME
*frame
= CURRENT_STACK16
;
274 BUILTIN_GetEntryPoint16( frame
, name
, &ordinal
);
275 MESSAGE("FATAL: No handler for Win16 routine %s (called from %04x:%04x)\n",
276 name
, frame
->cs
, frame
->ip
);
281 /***********************************************************************
282 * RELAY_DebugCallTo16
284 * 'target' contains either the function to call (normal CallTo16)
285 * or a pointer to the CONTEXT86 struct (register CallTo16).
286 * 'nb_args' is the number of argument bytes on the 16-bit stack;
287 * 'reg_func' specifies whether we have a register CallTo16 or not.
289 void RELAY_DebugCallTo16( LPVOID target
, int nb_args
, BOOL reg_func
)
294 if (!TRACE_ON(relay
)) return;
295 teb
= NtCurrentTeb();
296 stack16
= (WORD
*)THREAD_STACK16(teb
);
298 nb_args
/= sizeof(WORD
);
302 CONTEXT86
*context
= (CONTEXT86
*)target
;
304 DPRINTF("CallTo16(func=%04lx:%04x,ds=%04lx",
305 CS_reg(context
), LOWORD(EIP_reg(context
)), DS_reg(context
) );
306 while (nb_args
--) DPRINTF( ",0x%04x", *--stack16
);
307 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb
->cur_stack
),
308 OFFSETOF(teb
->cur_stack
) );
309 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x BP=%04x ES=%04x FS=%04x\n",
310 AX_reg(context
), BX_reg(context
), CX_reg(context
),
311 DX_reg(context
), SI_reg(context
), DI_reg(context
),
312 BP_reg(context
), (WORD
)ES_reg(context
), (WORD
)FS_reg(context
) );
316 DPRINTF("CallTo16(func=%04x:%04x,ds=%04x",
317 HIWORD(target
), LOWORD(target
), SELECTOROF(teb
->cur_stack
) );
318 while (nb_args
--) DPRINTF( ",0x%04x", *--stack16
);
319 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb
->cur_stack
),
320 OFFSETOF(teb
->cur_stack
) );
323 SYSLEVEL_CheckNotLevel( 2 );
327 /***********************************************************************
328 * RELAY_DebugCallTo16Ret
330 void RELAY_DebugCallTo16Ret( int ret_val
)
332 if (!TRACE_ON(relay
)) return;
334 DPRINTF("CallTo16() ss:sp=%04x:%04x retval=0x%08x\n",
335 SELECTOROF(NtCurrentTeb()->cur_stack
),
336 OFFSETOF(NtCurrentTeb()->cur_stack
), ret_val
);
337 SYSLEVEL_CheckNotLevel( 2 );