Distinguish between IMPORTS and LIBRARIES.
[wine.git] / if1632 / relay.c
blobda947f5bdcdff409d3008ef2954fae3d15170b7f
1 /*
2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Alexandre Julliard
4 */
6 #include <assert.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "wine/winbase16.h"
10 #include "winnt.h"
11 #include "heap.h"
12 #include "module.h"
13 #include "stackframe.h"
14 #include "selectors.h"
15 #include "builtin16.h"
16 #include "task.h"
17 #include "syslevel.h"
18 #include "debugtools.h"
19 #include "main.h"
20 #include "callback.h"
22 DEFAULT_DEBUG_CHANNEL(relay);
24 /***********************************************************************
25 * RELAY_Init
27 BOOL RELAY_Init(void)
29 #ifdef __i386__
30 WORD codesel;
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();
51 CallTo16_RetAddr =
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 );
57 #endif
58 return TRUE;
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 ...)
65 #ifndef __i386__
66 WORD CALLBACK CallTo16Word( FARPROC16 target, INT nArgs )
67 { assert( FALSE ); }
69 LONG CALLBACK CallTo16Long( FARPROC16 target, INT nArgs )
70 { assert( FALSE ); }
72 void CALLBACK CallTo16RegisterShort( CONTEXT86 *context, INT nArgs )
73 { assert( FALSE ); }
75 void CALLBACK CallTo16RegisterLong ( CONTEXT86 *context, INT nArgs )
76 { assert( FALSE ); }
78 WORD __wine_call_from_16_word() { assert( FALSE ); }
79 LONG __wine_call_from_16_long() { assert( FALSE ); }
80 void __wine_call_from_16_regs() { assert( FALSE ); }
81 void __wine_call_from_16_thunk() { assert( FALSE ); }
83 DWORD WINAPI CALL32_CBClient( FARPROC proc, LPWORD args, DWORD *esi )
84 { assert( FALSE ); }
86 DWORD WINAPI CALL32_CBClientEx( FARPROC proc, LPWORD args, DWORD *esi, INT *nArgs )
87 { assert( FALSE ); }
88 #endif
91 /* from relay32/relay386.c */
92 extern char **debug_relay_excludelist,**debug_relay_includelist;
94 /***********************************************************************
95 * RELAY_DebugCallFrom16
97 void RELAY_DebugCallFrom16( CONTEXT86 *context )
99 STACK16FRAME *frame;
100 WORD ordinal;
101 char *args16, funstr[80];
102 const char *args;
103 int i, usecdecl, reg_func;
105 if (!TRACE_ON(relay)) return;
107 frame = CURRENT_STACK16;
108 args = BUILTIN_GetEntryPoint16( frame, funstr, &ordinal );
109 if (!args) return; /* happens for the two snoop register relays */
110 if (!RELAY_ShowDebugmsgRelay(funstr)) return;
111 DPRINTF( "Call %s(",funstr);
112 VA_START16( args16 );
114 usecdecl = ( *args == 'c' );
115 args += 2;
116 reg_func = ( memcmp( args, "regs_", 5 ) == 0
117 || memcmp( args, "intr_", 5 ) == 0 );
118 args += 5;
120 if (usecdecl)
122 while (*args)
124 switch(*args)
126 case 'w':
127 case 's':
128 DPRINTF( "0x%04x", *(WORD *)args16 );
129 args16 += 2;
130 break;
131 case 'l':
132 DPRINTF( "0x%08x", *(int *)args16 );
133 args16 += 4;
134 break;
135 case 'p':
136 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
137 args16 += 4;
138 break;
139 case 't':
140 case 'T':
141 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
142 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )) );
143 args16 += 4;
144 break;
146 args++;
147 if (*args) DPRINTF( "," );
150 else /* not cdecl */
152 /* Start with the last arg */
153 for (i = 0; args[i]; i++)
155 switch(args[i])
157 case 'w':
158 case 's':
159 args16 += 2;
160 break;
161 case 'l':
162 case 'p':
163 case 't':
164 case 'T':
165 args16 += 4;
166 break;
170 while (*args)
172 switch(*args)
174 case 'w':
175 case 's':
176 args16 -= 2;
177 DPRINTF( "0x%04x", *(WORD *)args16 );
178 break;
179 case 'l':
180 args16 -= 4;
181 DPRINTF( "0x%08x", *(int *)args16 );
182 break;
183 case 't':
184 args16 -= 4;
185 DPRINTF( "0x%08x %s", *(int *)args16,
186 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
187 break;
188 case 'p':
189 args16 -= 4;
190 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
191 break;
192 case 'T':
193 args16 -= 4;
194 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
195 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
196 break;
198 args++;
199 if (*args) DPRINTF( "," );
203 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
204 VA_END16( args16 );
206 if (reg_func)
207 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
208 AX_reg(context), BX_reg(context), CX_reg(context),
209 DX_reg(context), SI_reg(context), DI_reg(context),
210 (WORD)context->SegEs, context->EFlags );
212 SYSLEVEL_CheckNotLevel( 2 );
216 /***********************************************************************
217 * RELAY_DebugCallFrom16Ret
219 void RELAY_DebugCallFrom16Ret( CONTEXT86 *context, int ret_val )
221 STACK16FRAME *frame;
222 WORD ordinal;
223 char funstr[80];
224 const char *args;
226 if (!TRACE_ON(relay)) return;
227 frame = CURRENT_STACK16;
228 args = BUILTIN_GetEntryPoint16( frame, funstr, &ordinal );
229 if (!args) return;
230 if (!RELAY_ShowDebugmsgRelay(funstr)) return;
231 DPRINTF( "Ret %s() ",funstr);
233 if ( memcmp( args+2, "long_", 5 ) == 0 )
235 DPRINTF( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
236 ret_val, frame->cs, frame->ip, frame->ds );
238 else if ( memcmp( args+2, "word_", 5 ) == 0 )
240 DPRINTF( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
241 ret_val & 0xffff, frame->cs, frame->ip, frame->ds );
243 else if ( memcmp( args+2, "regs_", 5 ) == 0
244 || memcmp( args+2, "intr_", 5 ) == 0 )
246 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
247 (WORD)context->SegCs, LOWORD(context->Eip), (WORD)context->SegDs);
248 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
249 AX_reg(context), BX_reg(context), CX_reg(context),
250 DX_reg(context), SI_reg(context), DI_reg(context),
251 (WORD)context->SegEs, context->EFlags );
254 SYSLEVEL_CheckNotLevel( 2 );
258 /***********************************************************************
259 * RELAY_DebugCallTo16
261 * 'target' contains either the function to call (normal CallTo16)
262 * or a pointer to the CONTEXT86 struct (register CallTo16).
263 * 'nb_args' is the number of argument bytes on the 16-bit stack;
264 * 'reg_func' specifies whether we have a register CallTo16 or not.
266 void RELAY_DebugCallTo16( LPVOID target, int nb_args, BOOL reg_func )
268 WORD *stack16;
269 TEB *teb;
271 if (!TRACE_ON(relay)) return;
272 teb = NtCurrentTeb();
273 stack16 = (WORD *)THREAD_STACK16(teb);
275 nb_args /= sizeof(WORD);
277 if ( reg_func )
279 CONTEXT86 *context = (CONTEXT86 *)target;
281 DPRINTF("CallTo16(func=%04lx:%04x,ds=%04lx",
282 context->SegCs, LOWORD(context->Eip), context->SegDs );
283 while (nb_args--) DPRINTF( ",0x%04x", *--stack16 );
284 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb->cur_stack),
285 OFFSETOF(teb->cur_stack) );
286 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x BP=%04x ES=%04x FS=%04x\n",
287 AX_reg(context), BX_reg(context), CX_reg(context),
288 DX_reg(context), SI_reg(context), DI_reg(context),
289 BP_reg(context), (WORD)context->SegEs, (WORD)context->SegFs );
291 else
293 DPRINTF("CallTo16(func=%04x:%04x,ds=%04x",
294 HIWORD(target), LOWORD(target), SELECTOROF(teb->cur_stack) );
295 while (nb_args--) DPRINTF( ",0x%04x", *--stack16 );
296 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb->cur_stack),
297 OFFSETOF(teb->cur_stack) );
300 SYSLEVEL_CheckNotLevel( 2 );
304 /***********************************************************************
305 * RELAY_DebugCallTo16Ret
307 void RELAY_DebugCallTo16Ret( BOOL reg_func, int ret_val )
309 if (!TRACE_ON(relay)) return;
311 if (!reg_func)
313 DPRINTF("CallTo16() ss:sp=%04x:%04x retval=0x%08x\n",
314 SELECTOROF(NtCurrentTeb()->cur_stack),
315 OFFSETOF(NtCurrentTeb()->cur_stack), ret_val);
317 else
319 CONTEXT86 *context = (CONTEXT86 *)ret_val;
321 DPRINTF("CallTo16() ss:sp=%04x:%04x\n",
322 SELECTOROF(NtCurrentTeb()->cur_stack),
323 OFFSETOF(NtCurrentTeb()->cur_stack));
324 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x BP=%04x SP=%04x\n",
325 AX_reg(context), BX_reg(context), CX_reg(context),
326 DX_reg(context), BP_reg(context), LOWORD(context->Esp));
329 SYSLEVEL_CheckNotLevel( 2 );