Fixed some warnings.
[wine/multimedia.git] / if1632 / relay.c
blob9e4e304a0d360b4fe78738d97ca2249468067689
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 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 */
49 CallTo16_RetAddr =
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 );
55 #endif
56 return TRUE;
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 ...)
63 #ifndef __i386__
64 WORD CALLBACK CallTo16Word( FARPROC16 target, INT nArgs )
65 { assert( FALSE ); }
67 LONG CALLBACK CallTo16Long( FARPROC16 target, INT nArgs )
68 { assert( FALSE ); }
70 LONG CALLBACK CallTo16RegisterShort( const CONTEXT86 *context, INT nArgs )
71 { assert( FALSE ); }
73 LONG CALLBACK CallTo16RegisterLong ( const CONTEXT86 *context, INT nArgs )
74 { assert( FALSE ); }
76 WORD CallFrom16Word( void )
77 { assert( FALSE ); }
79 LONG CallFrom16Long( void )
80 { assert( FALSE ); }
82 void CallFrom16Register( void )
83 { assert( FALSE ); }
85 void CallFrom16Thunk( void )
86 { assert( FALSE ); }
88 DWORD WINAPI CALL32_CBClient( FARPROC proc, LPWORD args, DWORD *esi )
89 { assert( FALSE ); }
91 DWORD WINAPI CALL32_CBClientEx( FARPROC proc, LPWORD args, DWORD *esi, INT *nArgs )
92 { assert( FALSE ); }
93 #endif
96 /* from relay32/relay386.c */
97 extern char **debug_relay_excludelist,**debug_relay_includelist;
99 /***********************************************************************
100 * RELAY_DebugCallFrom16
102 void RELAY_DebugCallFrom16( CONTEXT86 *context )
104 STACK16FRAME *frame;
105 WORD ordinal;
106 char *args16, funstr[80];
107 const char *args;
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' );
120 args += 2;
121 reg_func = ( memcmp( args, "regs_", 5 ) == 0
122 || memcmp( args, "intr_", 5 ) == 0 );
123 args += 5;
125 if (usecdecl)
127 while (*args)
129 switch(*args)
131 case 'w':
132 case 's':
133 DPRINTF( "0x%04x", *(WORD *)args16 );
134 args16 += 2;
135 break;
136 case 'l':
137 DPRINTF( "0x%08x", *(int *)args16 );
138 args16 += 4;
139 break;
140 case 'p':
141 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
142 args16 += 4;
143 break;
144 case 't':
145 case 'T':
146 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
147 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )) );
148 args16 += 4;
149 break;
151 args++;
152 if (*args) DPRINTF( "," );
155 else /* not cdecl */
157 /* Start with the last arg */
158 for (i = 0; args[i]; i++)
160 switch(args[i])
162 case 'w':
163 case 's':
164 args16 += 2;
165 break;
166 case 'l':
167 case 'p':
168 case 't':
169 case 'T':
170 args16 += 4;
171 break;
175 while (*args)
177 switch(*args)
179 case 'w':
180 case 's':
181 args16 -= 2;
182 DPRINTF( "0x%04x", *(WORD *)args16 );
183 break;
184 case 'l':
185 args16 -= 4;
186 DPRINTF( "0x%08x", *(int *)args16 );
187 break;
188 case 't':
189 args16 -= 4;
190 DPRINTF( "0x%08x %s", *(int *)args16,
191 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
192 break;
193 case 'p':
194 args16 -= 4;
195 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
196 break;
197 case 'T':
198 args16 -= 4;
199 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
200 debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
201 break;
203 args++;
204 if (*args) DPRINTF( "," );
208 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
209 VA_END16( args16 );
211 if (reg_func)
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 )
226 STACK16FRAME *frame;
227 WORD ordinal;
228 char funstr[80];
229 const char *args;
231 if (!TRACE_ON(relay)) return;
232 frame = CURRENT_STACK16;
233 args = BUILTIN_GetEntryPoint16( frame, funstr, &ordinal );
234 if (!args) return;
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)
271 WORD ordinal;
272 char name[80];
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 );
277 ExitProcess(1);
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 )
291 WORD *stack16;
292 TEB *teb;
294 if (!TRACE_ON(relay)) return;
295 teb = NtCurrentTeb();
296 stack16 = (WORD *)THREAD_STACK16(teb);
298 nb_args /= sizeof(WORD);
300 if ( reg_func )
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) );
314 else
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 );