Added ability to specify X fonts used for Helv and Tms Rmn typefaces
[wine.git] / relay32 / relay386.c
blob52873ddadb76873b94a02cb8d6741bb7b77a5c82
1 /*
2 * 386-specific Win32 relay functions
4 * Copyright 1997 Alexandre Julliard
5 */
7 #ifdef __i386__
9 #include <assert.h>
10 #include <string.h>
11 #include "winnt.h"
12 #include "windows.h"
13 #include "builtin32.h"
14 #include "selectors.h"
15 #include "debugstr.h"
16 #include "debug.h"
18 char **debug_relay_excludelist = NULL, **debug_relay_includelist = NULL;
20 /***********************************************************************
21 * RELAY_ShowDebugmsgRelay
23 * Simple function to decide if a particular debugging message is
24 * wanted. Called from RELAY_CallFrom32 and from in if1632/relay.c
26 int RELAY_ShowDebugmsgRelay(const char *func) {
28 if(debug_relay_excludelist || debug_relay_includelist) {
29 const char *term = strchr(func, ':');
30 char **listitem;
31 int len, len2, itemlen, show;
33 if(debug_relay_excludelist) {
34 show = 1;
35 listitem = debug_relay_excludelist;
36 } else {
37 show = 0;
38 listitem = debug_relay_includelist;
40 assert(term);
41 assert(strlen(term) > 2);
42 len = term - func;
43 len2 = strchr(func, '.') - func;
44 assert(len2 && len2 > 0 && len2 < 64);
45 term += 2;
46 for(; *listitem; listitem++) {
47 itemlen = strlen(*listitem);
48 if((itemlen == len && !strncmp(*listitem, func, len)) ||
49 (itemlen == len2 && !strncmp(*listitem, func, len2)) ||
50 !strcmp(*listitem, term)) {
51 show = !show;
52 break;
55 return show;
57 return 1;
60 /***********************************************************************
61 * RELAY_CallFrom32
63 * Stack layout on entry to this function:
64 * ... ...
65 * (esp+12) arg2
66 * (esp+8) arg1
67 * (esp+4) ret_addr
68 * (esp) return addr to relay code
70 int RELAY_CallFrom32( int ret_addr, ... )
72 int i, ret;
73 char buffer[80];
74 FARPROC32 func;
75 unsigned int mask, typemask;
76 WORD fs;
78 int *args = &ret_addr;
79 /* Relay addr is the return address for this function */
80 BYTE *relay_addr = (BYTE *)args[-1];
81 WORD nb_args = *(WORD *)(relay_addr + 1) / sizeof(int);
83 assert(TRACE_ON(relay));
84 func = (FARPROC32)BUILTIN32_GetEntryPoint( buffer, relay_addr - 5,
85 &typemask );
86 DPRINTF( "Call %s(", buffer );
87 args++;
88 for (i = 0, mask = 3; i < nb_args; i++, mask <<= 2)
90 if (i) DPRINTF( "," );
91 if ((typemask & mask) && HIWORD(args[i]))
93 if (typemask & (2<<(2*i)))
94 DPRINTF( "%08x L%s", args[i], debugstr_w((LPWSTR)args[i]) );
95 else
96 DPRINTF( "%08x %s", args[i], debugstr_a((LPCSTR)args[i]) );
98 else DPRINTF( "%08x", args[i] );
100 GET_FS( fs );
101 DPRINTF( ") ret=%08x fs=%04x\n", ret_addr, fs );
103 if (*relay_addr == 0xc3) /* cdecl */
105 LRESULT (*cfunc)() = (LRESULT(*)())func;
106 switch(nb_args)
108 case 0: ret = cfunc(); break;
109 case 1: ret = cfunc(args[0]); break;
110 case 2: ret = cfunc(args[0],args[1]); break;
111 case 3: ret = cfunc(args[0],args[1],args[2]); break;
112 case 4: ret = cfunc(args[0],args[1],args[2],args[3]); break;
113 case 5: ret = cfunc(args[0],args[1],args[2],args[3],args[4]); break;
114 case 6: ret = cfunc(args[0],args[1],args[2],args[3],args[4],
115 args[5]); break;
116 case 7: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
117 args[6]); break;
118 case 8: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
119 args[6],args[7]); break;
120 case 9: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
121 args[6],args[7],args[8]); break;
122 case 10: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
123 args[6],args[7],args[8],args[9]); break;
124 case 11: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
125 args[6],args[7],args[8],args[9],args[10]); break;
126 case 12: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
127 args[6],args[7],args[8],args[9],args[10],
128 args[11]); break;
129 case 13: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
130 args[6],args[7],args[8],args[9],args[10],args[11],
131 args[12]); break;
132 case 14: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
133 args[6],args[7],args[8],args[9],args[10],args[11],
134 args[12],args[13]); break;
135 case 15: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
136 args[6],args[7],args[8],args[9],args[10],args[11],
137 args[12],args[13],args[14]); break;
138 default:
139 ERR(relay, "Unsupported nb args %d\n",
140 nb_args );
141 assert(FALSE);
144 else /* stdcall */
146 switch(nb_args)
148 case 0: ret = func(); break;
149 case 1: ret = func(args[0]); break;
150 case 2: ret = func(args[0],args[1]); break;
151 case 3: ret = func(args[0],args[1],args[2]); break;
152 case 4: ret = func(args[0],args[1],args[2],args[3]); break;
153 case 5: ret = func(args[0],args[1],args[2],args[3],args[4]); break;
154 case 6: ret = func(args[0],args[1],args[2],args[3],args[4],
155 args[5]); break;
156 case 7: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
157 args[6]); break;
158 case 8: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
159 args[6],args[7]); break;
160 case 9: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
161 args[6],args[7],args[8]); break;
162 case 10: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
163 args[6],args[7],args[8],args[9]); break;
164 case 11: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
165 args[6],args[7],args[8],args[9],args[10]); break;
166 case 12: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
167 args[6],args[7],args[8],args[9],args[10],
168 args[11]); break;
169 case 13: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
170 args[6],args[7],args[8],args[9],args[10],args[11],
171 args[12]); break;
172 case 14: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
173 args[6],args[7],args[8],args[9],args[10],args[11],
174 args[12],args[13]); break;
175 case 15: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
176 args[6],args[7],args[8],args[9],args[10],args[11],
177 args[12],args[13],args[14]); break;
178 default:
179 ERR(relay, "Unsupported nb args %d\n",nb_args );
180 assert(FALSE);
183 DPRINTF( "Ret %s() retval=%08x ret=%08x fs=%04x\n",
184 buffer, ret, ret_addr, fs );
185 return ret;
189 /***********************************************************************
190 * RELAY_CallFrom32Regs
192 * 'context' contains the register contents at the point of call of
193 * the REG_ENTRY_POINT. The stack layout of the stack pointed to by
194 * ESP_reg(&context) is as follows:
196 * If debugmsg(relay) is OFF:
197 * ... ...
198 * (esp+4) args
199 * (esp) return addr to caller
200 * (esp-4) function entry point
202 * If debugmsg(relay) is ON:
203 * ... ...
204 * (esp+8) args
205 * (esp+4) return addr to caller
206 * (esp) return addr to DEBUG_ENTRY_POINT
207 * (esp-4) function entry point
209 * As the called function might change the stack layout
210 * (e.g. FT_Prolog, FT_ExitNN), we remove all modifications to the stack,
211 * so that the called function sees (in both cases):
213 * ... ...
214 * (esp+4) args
215 * (esp) return addr to caller
216 * ... >128 bytes space free to be modified (ensured by the assembly glue)
218 * NOTE: This routine makes no assumption about the relative position of
219 * its own stack to the stack pointed to by ESP_reg(&context),
220 * except that the latter must have >128 bytes space to grow.
221 * This means the assembly glue could even switch stacks completely
222 * (e.g. to allow for large stacks).
226 void RELAY_CallFrom32Regs( CONTEXT context )
228 typedef void (CALLBACK *entry_point_t)(CONTEXT *);
229 entry_point_t entry_point = *(entry_point_t*) (ESP_reg(&context) - 4);
231 __RESTORE_ES;
233 if (!TRACE_ON(relay))
235 /* Simply call the entry point */
236 entry_point( &context );
238 else
240 char buffer[80];
241 unsigned int typemask;
242 BYTE *relay_addr;
245 * Fixup the context structure because of the extra parameter
246 * pushed by the relay debugging code.
247 * Note that this implicitly does a RET on the CALL from the
248 * DEBUG_ENTRY_POINT to the REG_ENTRY_POINT; setting the EIP register
249 * ensures that the assembly glue will directly return to the
250 * caller, just as in the non-debugging case.
253 relay_addr = *(BYTE **) ESP_reg(&context);
254 if (BUILTIN32_GetEntryPoint( buffer, relay_addr - 5, &typemask )) {
255 /* correct win32 spec generated register function found.
256 * remove extra call stuff from stack
258 ESP_reg(&context) += sizeof(BYTE *);
259 EIP_reg(&context) = *(DWORD *)ESP_reg(&context);
260 DPRINTF("Call %s(regs) ret=%08x\n", buffer, *(int *)ESP_reg(&context) );
261 DPRINTF(" EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
262 EAX_reg(&context), EBX_reg(&context), ECX_reg(&context),
263 EDX_reg(&context), ESI_reg(&context), EDI_reg(&context) );
264 DPRINTF(" EBP=%08lx ESP=%08lx EIP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
265 EBP_reg(&context), ESP_reg(&context), EIP_reg(&context),
266 DS_reg(&context), ES_reg(&context), FS_reg(&context),
267 GS_reg(&context), EFL_reg(&context) );
269 /* Now call the real function */
270 entry_point( &context );
273 DPRINTF("Ret %s() retval=regs ret=%08x\n", buffer, *(int *)ESP_reg(&context) );
274 DPRINTF(" EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
275 EAX_reg(&context), EBX_reg(&context), ECX_reg(&context),
276 EDX_reg(&context), ESI_reg(&context), EDI_reg(&context) );
277 DPRINTF(" EBP=%08lx ESP=%08lx EIP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
278 EBP_reg(&context), ESP_reg(&context), EIP_reg(&context),
279 DS_reg(&context), ES_reg(&context), FS_reg(&context),
280 GS_reg(&context), EFL_reg(&context) );
281 } else
282 /* WINE internal register function found. Do not remove anything.
283 * Do not print any debuginfo (it is not a normal relayed one).
284 * Currently only used for snooping.
286 entry_point( &context );
289 #endif /* __i386__ */