Remove PROGRESS_Refresh, always do InvalidateRect() to repaint.
[wine/hacks.git] / if1632 / relay.c
blob59eaf5cec2782b879011d3f1dffc51d964ef7abc
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 <stdio.h>
11 #include "wine/winbase16.h"
12 #include "winnt.h"
13 #include "module.h"
14 #include "stackframe.h"
15 #include "selectors.h"
16 #include "builtin16.h"
17 #include "syslevel.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(relay);
22 /***********************************************************************
23 * RELAY_Init
25 BOOL RELAY_Init(void)
27 #ifdef __i386__
28 WORD codesel;
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();
49 CallTo16_RetAddr =
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 );
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 /***********************************************************************
65 * wine_call_to_16_word (KERNEL32.@)
67 WORD WINAPI wine_call_to_16_word( FARPROC16 target, INT nArgs )
69 assert( FALSE );
72 /***********************************************************************
73 * wine_call_to_16_long (KERNEL32.@)
75 LONG WINAPI wine_call_to_16_long( FARPROC16 target, INT nArgs )
77 assert( FALSE );
80 /***********************************************************************
81 * wine_call_to_16_regs_short (KERNEL32.@)
83 void WINAPI wine_call_to_16_regs_short( CONTEXT86 *context, INT nArgs )
85 assert( FALSE );
88 /***********************************************************************
89 * wine_call_to_16_regs_long (KERNEL32.@)
91 void WINAPI wine_call_to_16_regs_long ( CONTEXT86 *context, INT nArgs )
93 assert( FALSE );
96 /***********************************************************************
97 * __wine_call_from_16_word (KERNEL32.@)
99 WORD __wine_call_from_16_word()
101 assert( FALSE );
104 /***********************************************************************
105 * __wine_call_from_16_long (KERNEL32.@)
107 LONG __wine_call_from_16_long()
109 assert( FALSE );
112 /***********************************************************************
113 * __wine_call_from_16_regs (KERNEL32.@)
115 void __wine_call_from_16_regs()
117 assert( FALSE );
120 DWORD WINAPI CALL32_CBClient( FARPROC proc, LPWORD args, DWORD *esi )
121 { assert( FALSE ); }
123 DWORD WINAPI CALL32_CBClientEx( FARPROC proc, LPWORD args, DWORD *esi, INT *nArgs )
124 { assert( FALSE ); }
125 #endif
128 /* from relay32/relay386.c */
129 extern char **debug_relay_excludelist,**debug_relay_includelist;
130 extern int RELAY_ShowDebugmsgRelay(const char *func);
133 /***********************************************************************
134 * get_entry_point
136 * Return the ordinal, name, and type info corresponding to a CS:IP address.
138 static const CALLFROM16 *get_entry_point( STACK16FRAME *frame, LPSTR name, WORD *pOrd )
140 WORD i, max_offset;
141 register BYTE *p;
142 NE_MODULE *pModule;
143 ET_BUNDLE *bundle;
144 ET_ENTRY *entry;
146 if (!(pModule = NE_GetPtr( FarGetOwner16( GlobalHandle16( frame->module_cs ) ))))
147 return NULL;
149 max_offset = 0;
150 *pOrd = 0;
151 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
154 entry = (ET_ENTRY *)((BYTE *)bundle+6);
155 for (i = bundle->first + 1; i <= bundle->last; i++)
157 if ((entry->offs < frame->entry_ip)
158 && (entry->segnum == 1) /* code segment ? */
159 && (entry->offs >= max_offset))
161 max_offset = entry->offs;
162 *pOrd = i;
164 entry++;
166 } while ( (bundle->next)
167 && (bundle = (ET_BUNDLE *)((BYTE *)pModule+bundle->next)));
169 /* Search for the name in the resident names table */
170 /* (built-in modules have no non-resident table) */
172 p = (BYTE *)pModule + pModule->name_table;
173 while (*p)
175 p += *p + 1 + sizeof(WORD);
176 if (*(WORD *)(p + *p + 1) == *pOrd) break;
179 sprintf( name, "%.*s.%d: %.*s",
180 *((BYTE *)pModule + pModule->name_table),
181 (char *)pModule + pModule->name_table + 1,
182 *pOrd, *p, (char *)(p + 1) );
184 /* Retrieve entry point call structure */
185 p = MapSL( MAKESEGPTR( frame->module_cs, frame->callfrom_ip ) );
186 /* p now points to lret, get the start of CALLFROM16 structure */
187 return (CALLFROM16 *)(p - (BYTE *)&((CALLFROM16 *)0)->lret);
191 /***********************************************************************
192 * RELAY_DebugCallFrom16
194 void RELAY_DebugCallFrom16( CONTEXT86 *context )
196 STACK16FRAME *frame;
197 WORD ordinal;
198 char *args16, funstr[80];
199 const CALLFROM16 *call;
200 int i;
202 if (!TRACE_ON(relay)) return;
204 frame = CURRENT_STACK16;
205 call = get_entry_point( frame, funstr, &ordinal );
206 if (!call) return; /* happens for the two snoop register relays */
207 if (!RELAY_ShowDebugmsgRelay(funstr)) return;
208 DPRINTF( "%08lx:Call %s(",GetCurrentThreadId(),funstr);
209 VA_START16( args16 );
211 if (call->lret == 0xcb66) /* cdecl */
213 for (i = 0; i < 20; i++)
215 int type = (call->arg_types[i / 10] >> (3 * (i % 10))) & 7;
217 if (type == ARG_NONE) break;
218 if (i) DPRINTF( "," );
219 switch(type)
221 case ARG_WORD:
222 case ARG_SWORD:
223 DPRINTF( "%04x", *(WORD *)args16 );
224 args16 += sizeof(WORD);
225 break;
226 case ARG_LONG:
227 DPRINTF( "%08x", *(int *)args16 );
228 args16 += sizeof(int);
229 break;
230 case ARG_PTR:
231 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
232 args16 += sizeof(SEGPTR);
233 break;
234 case ARG_STR:
235 DPRINTF( "%08x %s", *(int *)args16,
236 debugres_a( MapSL(*(SEGPTR *)args16 )));
237 args16 += sizeof(int);
238 break;
239 case ARG_SEGSTR:
240 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
241 debugres_a( MapSL(*(SEGPTR *)args16 )) );
242 args16 += sizeof(SEGPTR);
243 break;
244 default:
245 break;
249 else /* not cdecl */
251 /* Start with the last arg */
252 args16 += call->nArgs;
253 for (i = 0; i < 20; i++)
255 int type = (call->arg_types[i / 10] >> (3 * (i % 10))) & 7;
257 if (type == ARG_NONE) break;
258 if (i) DPRINTF( "," );
259 switch(type)
261 case ARG_WORD:
262 case ARG_SWORD:
263 args16 -= sizeof(WORD);
264 DPRINTF( "%04x", *(WORD *)args16 );
265 break;
266 case ARG_LONG:
267 args16 -= sizeof(int);
268 DPRINTF( "%08x", *(int *)args16 );
269 break;
270 case ARG_PTR:
271 args16 -= sizeof(SEGPTR);
272 DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
273 break;
274 case ARG_STR:
275 args16 -= sizeof(int);
276 DPRINTF( "%08x %s", *(int *)args16,
277 debugres_a( MapSL(*(SEGPTR *)args16 )));
278 break;
279 case ARG_SEGSTR:
280 args16 -= sizeof(SEGPTR);
281 DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
282 debugres_a( MapSL(*(SEGPTR *)args16 )) );
283 break;
284 default:
285 break;
290 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
291 VA_END16( args16 );
293 if (call->arg_types[0] & ARG_REGISTER)
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 );
299 SYSLEVEL_CheckNotLevel( 2 );
303 /***********************************************************************
304 * RELAY_DebugCallFrom16Ret
306 void RELAY_DebugCallFrom16Ret( CONTEXT86 *context, int ret_val )
308 STACK16FRAME *frame;
309 WORD ordinal;
310 char funstr[80];
311 const CALLFROM16 *call;
313 if (!TRACE_ON(relay)) return;
314 frame = CURRENT_STACK16;
315 call = get_entry_point( frame, funstr, &ordinal );
316 if (!call) return;
317 if (!RELAY_ShowDebugmsgRelay(funstr)) return;
318 DPRINTF( "%08lx:Ret %s() ",GetCurrentThreadId(),funstr);
320 if (call->arg_types[0] & ARG_REGISTER)
322 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
323 (WORD)context->SegCs, LOWORD(context->Eip), (WORD)context->SegDs);
324 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
325 AX_reg(context), BX_reg(context), CX_reg(context),
326 DX_reg(context), SI_reg(context), DI_reg(context),
327 (WORD)context->SegEs, context->EFlags );
329 else if (call->arg_types[0] & ARG_RET16)
331 DPRINTF( "retval=%04x ret=%04x:%04x ds=%04x\n",
332 ret_val & 0xffff, frame->cs, frame->ip, frame->ds );
334 else
336 DPRINTF( "retval=%08x ret=%04x:%04x ds=%04x\n",
337 ret_val, frame->cs, frame->ip, frame->ds );
339 SYSLEVEL_CheckNotLevel( 2 );
343 /***********************************************************************
344 * RELAY_DebugCallTo16
346 * 'target' contains either the function to call (normal CallTo16)
347 * or a pointer to the CONTEXT86 struct (register CallTo16).
348 * 'nb_args' is the number of argument bytes on the 16-bit stack;
349 * 'reg_func' specifies whether we have a register CallTo16 or not.
351 void RELAY_DebugCallTo16( LPVOID target, int nb_args, BOOL reg_func )
353 WORD *stack16;
354 TEB *teb;
356 if (!TRACE_ON(relay)) return;
357 teb = NtCurrentTeb();
358 stack16 = (WORD *)THREAD_STACK16(teb);
360 nb_args /= sizeof(WORD);
362 if ( reg_func )
364 CONTEXT86 *context = (CONTEXT86 *)target;
366 DPRINTF("%08lx:CallTo16(func=%04lx:%04x,ds=%04lx",
367 GetCurrentThreadId(),
368 context->SegCs, LOWORD(context->Eip), context->SegDs );
369 while (nb_args--) DPRINTF( ",%04x", *--stack16 );
370 DPRINTF(") ss:sp=%04x:%04x", SELECTOROF(teb->cur_stack),
371 OFFSETOF(teb->cur_stack) );
372 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
373 AX_reg(context), BX_reg(context), CX_reg(context),
374 DX_reg(context), SI_reg(context), DI_reg(context),
375 BP_reg(context), (WORD)context->SegEs, (WORD)context->SegFs );
377 else
379 DPRINTF("%08lx:CallTo16(func=%04x:%04x,ds=%04x",
380 GetCurrentThreadId(),
381 HIWORD(target), LOWORD(target), SELECTOROF(teb->cur_stack) );
382 while (nb_args--) DPRINTF( ",%04x", *--stack16 );
383 DPRINTF(") ss:sp=%04x:%04x\n", SELECTOROF(teb->cur_stack),
384 OFFSETOF(teb->cur_stack) );
387 SYSLEVEL_CheckNotLevel( 2 );
391 /***********************************************************************
392 * RELAY_DebugCallTo16Ret
394 void RELAY_DebugCallTo16Ret( BOOL reg_func, int ret_val )
396 if (!TRACE_ON(relay)) return;
398 if (!reg_func)
400 DPRINTF("%08lx:RetFrom16() ss:sp=%04x:%04x retval=%08x\n",
401 GetCurrentThreadId(),
402 SELECTOROF(NtCurrentTeb()->cur_stack),
403 OFFSETOF(NtCurrentTeb()->cur_stack), ret_val);
405 else
407 CONTEXT86 *context = (CONTEXT86 *)ret_val;
409 DPRINTF("%08lx:RetFrom16() ss:sp=%04x:%04x ",
410 GetCurrentThreadId(),
411 SELECTOROF(NtCurrentTeb()->cur_stack),
412 OFFSETOF(NtCurrentTeb()->cur_stack));
413 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
414 AX_reg(context), BX_reg(context), CX_reg(context),
415 DX_reg(context), BP_reg(context), LOWORD(context->Esp));
418 SYSLEVEL_CheckNotLevel( 2 );