2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Alexandre Julliard
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/port.h"
29 #include "wine/winbase16.h"
31 #include "stackframe.h"
32 #include "selectors.h"
33 #include "builtin16.h"
35 #include "wine/library.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(relay
);
41 * Stubs for the CallTo16/CallFrom16 routines on non-Intel architectures
42 * (these will never be called but need to be present to satisfy the linker ...)
45 /***********************************************************************
46 * __wine_call_from_16_word (KERNEL32.@)
48 WORD
__wine_call_from_16_word()
53 /***********************************************************************
54 * __wine_call_from_16_long (KERNEL32.@)
56 LONG
__wine_call_from_16_long()
61 /***********************************************************************
62 * __wine_call_from_16_regs (KERNEL32.@)
64 void __wine_call_from_16_regs()
69 DWORD WINAPI
CALL32_CBClient( FARPROC proc
, LPWORD args
, DWORD
*esi
)
72 DWORD WINAPI
CALL32_CBClientEx( FARPROC proc
, LPWORD args
, DWORD
*esi
, INT
*nArgs
)
77 /***********************************************************************
78 * RELAY_ShowDebugmsgRelay
80 * Simple function to decide if a particular debugging message is
83 static int RELAY_ShowDebugmsgRelay(const char *func
)
85 /* from relay32/relay386.c */
86 extern const char **debug_relay_excludelist
,**debug_relay_includelist
;
88 if(debug_relay_excludelist
|| debug_relay_includelist
) {
89 const char *term
= strchr(func
, ':');
90 const char **listitem
;
91 int len
, len2
, itemlen
, show
;
93 if(debug_relay_excludelist
) {
95 listitem
= debug_relay_excludelist
;
98 listitem
= debug_relay_includelist
;
101 assert(strlen(term
) > 2);
103 len2
= strchr(func
, '.') - func
;
104 assert(len2
&& len2
> 0 && len2
< 64);
106 for(; *listitem
; listitem
++) {
107 itemlen
= strlen(*listitem
);
108 if((itemlen
== len
&& !strncasecmp(*listitem
, func
, len
)) ||
109 (itemlen
== len2
&& !strncasecmp(*listitem
, func
, len2
)) ||
110 !strcasecmp(*listitem
, term
)) {
121 /***********************************************************************
124 * Return the ordinal, name, and type info corresponding to a CS:IP address.
126 static const CALLFROM16
*get_entry_point( STACK16FRAME
*frame
, LPSTR name
, WORD
*pOrd
)
134 if (!(pModule
= NE_GetPtr( FarGetOwner16( GlobalHandle16( frame
->module_cs
) ))))
139 bundle
= (ET_BUNDLE
*)((BYTE
*)pModule
+ pModule
->entry_table
);
142 entry
= (ET_ENTRY
*)((BYTE
*)bundle
+6);
143 for (i
= bundle
->first
+ 1; i
<= bundle
->last
; i
++)
145 if ((entry
->offs
< frame
->entry_ip
)
146 && (entry
->segnum
== 1) /* code segment ? */
147 && (entry
->offs
>= max_offset
))
149 max_offset
= entry
->offs
;
154 } while ( (bundle
->next
)
155 && (bundle
= (ET_BUNDLE
*)((BYTE
*)pModule
+bundle
->next
)));
157 /* Search for the name in the resident names table */
158 /* (built-in modules have no non-resident table) */
160 p
= (BYTE
*)pModule
+ pModule
->name_table
;
163 p
+= *p
+ 1 + sizeof(WORD
);
164 if (*(WORD
*)(p
+ *p
+ 1) == *pOrd
) break;
167 sprintf( name
, "%.*s.%d: %.*s",
168 *((BYTE
*)pModule
+ pModule
->name_table
),
169 (char *)pModule
+ pModule
->name_table
+ 1,
170 *pOrd
, *p
, (char *)(p
+ 1) );
172 /* Retrieve entry point call structure */
173 p
= MapSL( MAKESEGPTR( frame
->module_cs
, frame
->callfrom_ip
) );
174 /* p now points to lret, get the start of CALLFROM16 structure */
175 return (CALLFROM16
*)(p
- (BYTE
*)&((CALLFROM16
*)0)->lret
);
179 /***********************************************************************
180 * RELAY_DebugCallFrom16
182 void RELAY_DebugCallFrom16( CONTEXT86
*context
)
186 char *args16
, funstr
[80];
187 const CALLFROM16
*call
;
190 if (!TRACE_ON(relay
)) return;
192 frame
= CURRENT_STACK16
;
193 call
= get_entry_point( frame
, funstr
, &ordinal
);
194 if (!call
) return; /* happens for the two snoop register relays */
195 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
196 DPRINTF( "%04lx:Call %s(",GetCurrentThreadId(),funstr
);
197 VA_START16( args16
);
199 if (call
->lret
== 0xcb66) /* cdecl */
201 for (i
= 0; i
< 20; i
++)
203 int type
= (call
->arg_types
[i
/ 10] >> (3 * (i
% 10))) & 7;
205 if (type
== ARG_NONE
) break;
206 if (i
) DPRINTF( "," );
211 DPRINTF( "%04x", *(WORD
*)args16
);
212 args16
+= sizeof(WORD
);
215 DPRINTF( "%08x", *(int *)args16
);
216 args16
+= sizeof(int);
219 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
220 args16
+= sizeof(SEGPTR
);
223 DPRINTF( "%08x %s", *(int *)args16
,
224 debugstr_a( MapSL(*(SEGPTR
*)args16
)));
225 args16
+= sizeof(int);
228 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
229 debugstr_a( MapSL(*(SEGPTR
*)args16
)) );
230 args16
+= sizeof(SEGPTR
);
239 /* Start with the last arg */
240 args16
+= call
->nArgs
;
241 for (i
= 0; i
< 20; i
++)
243 int type
= (call
->arg_types
[i
/ 10] >> (3 * (i
% 10))) & 7;
245 if (type
== ARG_NONE
) break;
246 if (i
) DPRINTF( "," );
251 args16
-= sizeof(WORD
);
252 DPRINTF( "%04x", *(WORD
*)args16
);
255 args16
-= sizeof(int);
256 DPRINTF( "%08x", *(int *)args16
);
259 args16
-= sizeof(SEGPTR
);
260 DPRINTF( "%04x:%04x", *(WORD
*)(args16
+2), *(WORD
*)args16
);
263 args16
-= sizeof(int);
264 DPRINTF( "%08x %s", *(int *)args16
,
265 debugstr_a( MapSL(*(SEGPTR
*)args16
)));
268 args16
-= sizeof(SEGPTR
);
269 DPRINTF( "%04x:%04x %s", *(WORD
*)(args16
+2), *(WORD
*)args16
,
270 debugstr_a( MapSL(*(SEGPTR
*)args16
)) );
278 DPRINTF( ") ret=%04x:%04x ds=%04x\n", frame
->cs
, frame
->ip
, frame
->ds
);
281 if (call
->arg_types
[0] & ARG_REGISTER
)
282 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
283 (WORD
)context
->Eax
, (WORD
)context
->Ebx
, (WORD
)context
->Ecx
,
284 (WORD
)context
->Edx
, (WORD
)context
->Esi
, (WORD
)context
->Edi
,
285 (WORD
)context
->SegEs
, context
->EFlags
);
287 SYSLEVEL_CheckNotLevel( 2 );
291 /***********************************************************************
292 * RELAY_DebugCallFrom16Ret
294 void RELAY_DebugCallFrom16Ret( CONTEXT86
*context
, int ret_val
)
299 const CALLFROM16
*call
;
301 if (!TRACE_ON(relay
)) return;
302 frame
= CURRENT_STACK16
;
303 call
= get_entry_point( frame
, funstr
, &ordinal
);
305 if (!RELAY_ShowDebugmsgRelay(funstr
)) return;
306 DPRINTF( "%04lx:Ret %s() ",GetCurrentThreadId(),funstr
);
308 if (call
->arg_types
[0] & ARG_REGISTER
)
310 DPRINTF("retval=none ret=%04x:%04x ds=%04x\n",
311 (WORD
)context
->SegCs
, LOWORD(context
->Eip
), (WORD
)context
->SegDs
);
312 DPRINTF(" AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
313 (WORD
)context
->Eax
, (WORD
)context
->Ebx
, (WORD
)context
->Ecx
,
314 (WORD
)context
->Edx
, (WORD
)context
->Esi
, (WORD
)context
->Edi
,
315 (WORD
)context
->SegEs
, context
->EFlags
);
317 else if (call
->arg_types
[0] & ARG_RET16
)
319 DPRINTF( "retval=%04x ret=%04x:%04x ds=%04x\n",
320 ret_val
& 0xffff, frame
->cs
, frame
->ip
, frame
->ds
);
324 DPRINTF( "retval=%08x ret=%04x:%04x ds=%04x\n",
325 ret_val
, frame
->cs
, frame
->ip
, frame
->ds
);
327 SYSLEVEL_CheckNotLevel( 2 );