2 * Relay calls helper routines
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/winbase16.h"
34 static void function_header( FILE *outfile
, const char *name
)
36 fprintf( outfile
, "\n\t.align %d\n", get_alignment(4) );
37 fprintf( outfile
, "\t%s\n", func_declaration(name
) );
38 fprintf( outfile
, "%s\n", asm_globl(name
) );
42 static inline const char *data16_prefix(void)
44 return (target_platform
== PLATFORM_SVR4
) ? "\tdata16\n" : "";
47 /*******************************************************************
50 * This routine builds the core routines used in 16->32 thunks:
51 * CallFrom16Word, CallFrom16Long, CallFrom16Register, and CallFrom16Thunk.
53 * These routines are intended to be called via a far call (with 32-bit
54 * operand size) from 16-bit code. The 16-bit code stub must push %bp,
55 * the 32-bit entry point to be called, and the argument conversion
56 * routine to be used (see stack layout below).
58 * The core routine completes the STACK16FRAME on the 16-bit stack and
59 * switches to the 32-bit stack. Then, the argument conversion routine
60 * is called; it gets passed the 32-bit entry point and a pointer to the
61 * 16-bit arguments (on the 16-bit stack) as parameters. (You can either
62 * use conversion routines automatically generated by BuildCallFrom16,
63 * or write your own for special purposes.)
65 * The conversion routine must call the 32-bit entry point, passing it
66 * the converted arguments, and return its return value to the core.
67 * After the conversion routine has returned, the core switches back
68 * to the 16-bit stack, converts the return value to the DX:AX format
69 * (CallFrom16Long), and returns to the 16-bit call stub. All parameters,
70 * including %bp, are popped off the stack.
72 * The 16-bit call stub now returns to the caller, popping the 16-bit
73 * arguments if necessary (pascal calling convention).
75 * In the case of a 'register' function, CallFrom16Register fills a
76 * CONTEXT86 structure with the values all registers had at the point
77 * the first instruction of the 16-bit call stub was about to be
78 * executed. A pointer to this CONTEXT86 is passed as third parameter
79 * to the argument conversion routine, which typically passes it on
80 * to the called 32-bit entry point.
82 * CallFrom16Thunk is a special variant used by the implementation of
83 * the Win95 16->32 thunk functions C16ThkSL and C16ThkSL01 and is
84 * implemented as follows:
85 * On entry, the EBX register is set up to contain a flat pointer to the
86 * 16-bit stack such that EBX+22 points to the first argument.
87 * Then, the entry point is called, while EBP is set up to point
88 * to the return address (on the 32-bit stack).
89 * The called function returns with CX set to the number of bytes
90 * to be popped of the caller's stack.
92 * Stack layout upon entry to the core routine (STACK16FRAME):
94 * (sp+24) word first 16-bit arg
98 * (sp+14) long 32-bit entry point (reused for Win16 mutex recursion count)
99 * (sp+12) word ip of actual entry point (necessary for relay debugging)
100 * (sp+8) long relay (argument conversion) function entry point
101 * (sp+4) long cs of 16-bit entry point
102 * (sp) long ip of 16-bit entry point
104 * Added on the stack:
105 * (sp-2) word saved gs
106 * (sp-4) word saved fs
107 * (sp-6) word saved es
108 * (sp-8) word saved ds
109 * (sp-12) long saved ebp
110 * (sp-16) long saved ecx
111 * (sp-20) long saved edx
112 * (sp-24) long saved previous stack
114 static void BuildCallFrom16Core( FILE *outfile
, int reg_func
, int thunk
)
116 /* Function header */
117 if (thunk
) function_header( outfile
, "__wine_call_from_16_thunk" );
118 else if (reg_func
) function_header( outfile
, "__wine_call_from_16_regs" );
119 else function_header( outfile
, "__wine_call_from_16" );
121 /* Create STACK16FRAME (except STACK32FRAME link) */
122 fprintf( outfile
, "\tpushw %%gs\n" );
123 fprintf( outfile
, "\tpushw %%fs\n" );
124 fprintf( outfile
, "\tpushw %%es\n" );
125 fprintf( outfile
, "\tpushw %%ds\n" );
126 fprintf( outfile
, "\tpushl %%ebp\n" );
127 fprintf( outfile
, "\tpushl %%ecx\n" );
128 fprintf( outfile
, "\tpushl %%edx\n" );
130 /* Save original EFlags register */
131 if (reg_func
) fprintf( outfile
, "\tpushfl\n" );
135 fprintf( outfile
, "\tcall 1f\n" );
136 fprintf( outfile
, "1:\tpopl %%ecx\n" );
137 fprintf( outfile
, "\t.byte 0x2e\n\tmovl %s-1b(%%ecx),%%edx\n",
138 asm_name("CallTo16_DataSelector") );
141 fprintf( outfile
, "\t.byte 0x2e\n\tmovl %s,%%edx\n", asm_name("CallTo16_DataSelector") );
143 /* Load 32-bit segment registers */
144 fprintf( outfile
, "%s\tmovw %%dx, %%ds\n", data16_prefix() );
145 fprintf( outfile
, "%s\tmovw %%dx, %%es\n", data16_prefix() );
148 fprintf( outfile
, "\tmovw %s-1b(%%ecx), %%fs\n", asm_name("CallTo16_TebSelector") );
150 fprintf( outfile
, "\tmovw %s, %%fs\n", asm_name("CallTo16_TebSelector") );
152 fprintf( outfile
, "\t.byte 0x64\n\tmov (%d),%%gs\n", STRUCTOFFSET(TEB
,gs_sel
) );
154 /* Translate STACK16FRAME base to flat offset in %edx */
155 fprintf( outfile
, "\tmovw %%ss, %%dx\n" );
156 fprintf( outfile
, "\tandl $0xfff8, %%edx\n" );
157 fprintf( outfile
, "\tshrl $1, %%edx\n" );
160 fprintf( outfile
, "\taddl wine_ldt_copy_ptr-1b(%%ecx),%%edx\n" );
161 fprintf( outfile
, "\tmovl (%%edx), %%edx\n" );
164 fprintf( outfile
, "\tmovl %s(%%edx), %%edx\n", asm_name("wine_ldt_copy") );
165 fprintf( outfile
, "\tmovzwl %%sp, %%ebp\n" );
166 fprintf( outfile
, "\tleal %d(%%ebp,%%edx), %%edx\n", reg_func
? 0 : -4 );
168 /* Get saved flags into %ecx */
169 if (reg_func
) fprintf( outfile
, "\tpopl %%ecx\n" );
171 /* Get the 32-bit stack pointer from the TEB and complete STACK16FRAME */
172 fprintf( outfile
, "\t.byte 0x64\n\tmovl (%d), %%ebp\n", STACKOFFSET
);
173 fprintf( outfile
, "\tpushl %%ebp\n" );
176 fprintf( outfile
, "%s\t.byte 0x64\n\tmovw %%ss, (%d)\n", data16_prefix(), STACKOFFSET
+ 2 );
177 fprintf( outfile
, "\t.byte 0x64\n\tmovw %%sp, (%d)\n", STACKOFFSET
);
178 fprintf( outfile
, "\tpushl %%ds\n" );
179 fprintf( outfile
, "\tpopl %%ss\n" );
180 fprintf( outfile
, "\tmovl %%ebp, %%esp\n" );
181 fprintf( outfile
, "\taddl $%d, %%ebp\n", STRUCTOFFSET(STACK32FRAME
, ebp
) );
185 STACK16FRAME is completely set up
186 DS, ES, SS: flat data segment
188 ESP: points to last STACK32FRAME
189 EBP: points to ebp member of last STACK32FRAME
190 EDX: points to current STACK16FRAME
191 ECX: contains saved flags
192 all other registers: unchanged */
194 /* Special case: C16ThkSL stub */
197 /* Set up registers as expected and call thunk */
198 fprintf( outfile
, "\tleal %d(%%edx), %%ebx\n", sizeof(STACK16FRAME
)-22 );
199 fprintf( outfile
, "\tleal -4(%%esp), %%ebp\n" );
201 fprintf( outfile
, "\tcall *%d(%%edx)\n", STACK16OFFSET(entry_point
) );
203 /* Switch stack back */
204 fprintf( outfile
, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET
+2 );
205 fprintf( outfile
, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET
);
206 fprintf( outfile
, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET
);
208 /* Restore registers and return directly to caller */
209 fprintf( outfile
, "\taddl $8, %%esp\n" );
210 fprintf( outfile
, "\tpopl %%ebp\n" );
211 fprintf( outfile
, "\tpopw %%ds\n" );
212 fprintf( outfile
, "\tpopw %%es\n" );
213 fprintf( outfile
, "\tpopw %%fs\n" );
214 fprintf( outfile
, "\tpopw %%gs\n" );
215 fprintf( outfile
, "\taddl $20, %%esp\n" );
217 fprintf( outfile
, "\txorb %%ch, %%ch\n" );
218 fprintf( outfile
, "\tpopl %%ebx\n" );
219 fprintf( outfile
, "\taddw %%cx, %%sp\n" );
220 fprintf( outfile
, "\tpush %%ebx\n" );
222 fprintf( outfile
, "\t.byte 0x66\n" );
223 fprintf( outfile
, "\tlret\n" );
229 /* Build register CONTEXT */
232 fprintf( outfile
, "\tsubl $%d, %%esp\n", sizeof(CONTEXT86
) );
234 fprintf( outfile
, "\tmovl %%ecx, %d(%%esp)\n", CONTEXTOFFSET(EFlags
) );
236 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eax
) );
237 fprintf( outfile
, "\tmovl %%ebx, %d(%%esp)\n", CONTEXTOFFSET(Ebx
) );
238 fprintf( outfile
, "\tmovl %%esi, %d(%%esp)\n", CONTEXTOFFSET(Esi
) );
239 fprintf( outfile
, "\tmovl %%edi, %d(%%esp)\n", CONTEXTOFFSET(Edi
) );
241 fprintf( outfile
, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ebp
) );
242 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ebp
) );
243 fprintf( outfile
, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ecx
) );
244 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ecx
) );
245 fprintf( outfile
, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(edx
) );
246 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Edx
) );
248 fprintf( outfile
, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ds
) );
249 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegDs
) );
250 fprintf( outfile
, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(es
) );
251 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegEs
) );
252 fprintf( outfile
, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(fs
) );
253 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegFs
) );
254 fprintf( outfile
, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(gs
) );
255 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegGs
) );
257 fprintf( outfile
, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(cs
) );
258 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegCs
) );
259 fprintf( outfile
, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ip
) );
260 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eip
) );
262 fprintf( outfile
, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET
+2 );
263 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegSs
) );
264 fprintf( outfile
, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET
);
265 fprintf( outfile
, "\taddl $%d, %%eax\n", STACK16OFFSET(ip
) );
266 fprintf( outfile
, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Esp
) );
268 fprintf( outfile
, "\tfsave %d(%%esp)\n", CONTEXTOFFSET(FloatSave
) );
271 /* Push address of CONTEXT86 structure -- popped by the relay routine */
272 fprintf( outfile
, "\tmovl %%esp,%%eax\n" );
273 fprintf( outfile
, "\tandl $~15,%%esp\n" );
274 fprintf( outfile
, "\tsubl $4,%%esp\n" );
275 fprintf( outfile
, "\tpushl %%eax\n" );
279 fprintf( outfile
, "\tsubl $8,%%esp\n" );
280 fprintf( outfile
, "\tandl $~15,%%esp\n" );
281 fprintf( outfile
, "\taddl $8,%%esp\n" );
284 /* Call relay routine (which will call the API entry point) */
285 fprintf( outfile
, "\tleal %d(%%edx), %%eax\n", sizeof(STACK16FRAME
) );
286 fprintf( outfile
, "\tpushl %%eax\n" );
287 fprintf( outfile
, "\tpushl %d(%%edx)\n", STACK16OFFSET(entry_point
) );
288 fprintf( outfile
, "\tcall *%d(%%edx)\n", STACK16OFFSET(relay
) );
292 fprintf( outfile
, "\tleal -%d(%%ebp), %%ebx\n",
293 sizeof(CONTEXT
) + STRUCTOFFSET(STACK32FRAME
, ebp
) );
295 /* Switch stack back */
296 fprintf( outfile
, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET
+2 );
297 fprintf( outfile
, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET
);
298 fprintf( outfile
, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET
);
300 /* Get return address to CallFrom16 stub */
301 fprintf( outfile
, "\taddw $%d, %%sp\n", STACK16OFFSET(callfrom_ip
)-4 );
302 fprintf( outfile
, "\tpopl %%eax\n" );
303 fprintf( outfile
, "\tpopl %%edx\n" );
305 /* Restore all registers from CONTEXT */
306 fprintf( outfile
, "\tmovw %d(%%ebx), %%ss\n", CONTEXTOFFSET(SegSs
) );
307 fprintf( outfile
, "\tmovl %d(%%ebx), %%esp\n", CONTEXTOFFSET(Esp
) );
308 fprintf( outfile
, "\taddl $4, %%esp\n" ); /* room for final return address */
310 fprintf( outfile
, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(SegCs
) );
311 fprintf( outfile
, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(Eip
) );
312 fprintf( outfile
, "\tpushl %%edx\n" );
313 fprintf( outfile
, "\tpushl %%eax\n" );
314 fprintf( outfile
, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(EFlags
) );
315 fprintf( outfile
, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegDs
) );
317 fprintf( outfile
, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegEs
) );
318 fprintf( outfile
, "\tpopl %%es\n" );
319 fprintf( outfile
, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegFs
) );
320 fprintf( outfile
, "\tpopl %%fs\n" );
321 fprintf( outfile
, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegGs
) );
322 fprintf( outfile
, "\tpopl %%gs\n" );
324 fprintf( outfile
, "\tmovl %d(%%ebx), %%ebp\n", CONTEXTOFFSET(Ebp
) );
325 fprintf( outfile
, "\tmovl %d(%%ebx), %%esi\n", CONTEXTOFFSET(Esi
) );
326 fprintf( outfile
, "\tmovl %d(%%ebx), %%edi\n", CONTEXTOFFSET(Edi
) );
327 fprintf( outfile
, "\tmovl %d(%%ebx), %%eax\n", CONTEXTOFFSET(Eax
) );
328 fprintf( outfile
, "\tmovl %d(%%ebx), %%edx\n", CONTEXTOFFSET(Edx
) );
329 fprintf( outfile
, "\tmovl %d(%%ebx), %%ecx\n", CONTEXTOFFSET(Ecx
) );
330 fprintf( outfile
, "\tmovl %d(%%ebx), %%ebx\n", CONTEXTOFFSET(Ebx
) );
332 fprintf( outfile
, "\tpopl %%ds\n" );
333 fprintf( outfile
, "\tpopfl\n" );
334 fprintf( outfile
, "\tlret\n" );
338 /* Switch stack back */
339 fprintf( outfile
, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET
+2 );
340 fprintf( outfile
, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET
);
341 fprintf( outfile
, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET
);
343 /* Restore registers */
344 fprintf( outfile
, "\tpopl %%edx\n" );
345 fprintf( outfile
, "\tpopl %%ecx\n" );
346 fprintf( outfile
, "\tpopl %%ebp\n" );
347 fprintf( outfile
, "\tpopw %%ds\n" );
348 fprintf( outfile
, "\tpopw %%es\n" );
349 fprintf( outfile
, "\tpopw %%fs\n" );
350 fprintf( outfile
, "\tpopw %%gs\n" );
352 /* Return to return stub which will return to caller */
353 fprintf( outfile
, "\tlret $12\n" );
355 if (thunk
) output_function_size( outfile
, "__wine_call_from_16_thunk" );
356 else if (reg_func
) output_function_size( outfile
, "__wine_call_from_16_regs" );
357 else output_function_size( outfile
, "__wine_call_from_16" );
361 /*******************************************************************
364 * This routine builds the core routines used in 32->16 thunks:
366 * extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
367 * extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
369 * These routines can be called directly from 32-bit code.
371 * All routines expect that the 16-bit stack contents (arguments) and the
372 * return address (segptr to CallTo16_Ret) were already set up by the
373 * caller; nb_args must contain the number of bytes to be conserved. The
374 * 16-bit SS:SP will be set accordinly.
376 * All other registers are either taken from the CONTEXT86 structure
377 * or else set to default values. The target routine address is either
378 * given directly or taken from the CONTEXT86.
380 static void BuildCallTo16Core( FILE *outfile
, int reg_func
)
382 const char *name
= reg_func
? "wine_call_to_16_regs" : "wine_call_to_16";
384 /* Function header */
385 function_header( outfile
, name
);
387 /* Function entry sequence */
388 fprintf( outfile
, "\tpushl %%ebp\n" );
389 fprintf( outfile
, "\tmovl %%esp, %%ebp\n" );
391 /* Save the 32-bit registers */
392 fprintf( outfile
, "\tpushl %%ebx\n" );
393 fprintf( outfile
, "\tpushl %%esi\n" );
394 fprintf( outfile
, "\tpushl %%edi\n" );
395 fprintf( outfile
, "\t.byte 0x64\n\tmov %%gs,(%d)\n", STRUCTOFFSET(TEB
,gs_sel
) );
397 /* Setup exception frame */
398 fprintf( outfile
, "\t.byte 0x64\n\tpushl (%d)\n", STACKOFFSET
);
399 fprintf( outfile
, "\tpushl 16(%%ebp)\n" ); /* handler */
400 fprintf( outfile
, "\t.byte 0x64\n\tpushl (%d)\n", STRUCTOFFSET(TEB
,Tib
.ExceptionList
) );
401 fprintf( outfile
, "\t.byte 0x64\n\tmovl %%esp,(%d)\n", STRUCTOFFSET(TEB
,Tib
.ExceptionList
) );
403 /* Call the actual CallTo16 routine (simulate a lcall) */
404 fprintf( outfile
, "\tpushl %%cs\n" );
405 fprintf( outfile
, "\tcall .L%s\n", name
);
407 /* Remove exception frame */
408 fprintf( outfile
, "\t.byte 0x64\n\tpopl (%d)\n", STRUCTOFFSET(TEB
,Tib
.ExceptionList
) );
409 fprintf( outfile
, "\taddl $4, %%esp\n" );
410 fprintf( outfile
, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET
);
414 /* Convert return value */
415 fprintf( outfile
, "\tandl $0xffff,%%eax\n" );
416 fprintf( outfile
, "\tshll $16,%%edx\n" );
417 fprintf( outfile
, "\torl %%edx,%%eax\n" );
422 * Modify CONTEXT86 structure to contain new values
424 * NOTE: We restore only EAX, EBX, EDX, EDX, EBP, and ESP.
425 * The segment registers as well as ESI and EDI should
426 * not be modified by a well-behaved 16-bit routine in
427 * any case. [If necessary, we could restore them as well,
428 * at the cost of a somewhat less efficient return path.]
431 fprintf( outfile
, "\tmovl %d(%%esp), %%edi\n", STACK32OFFSET(target
) - STACK32OFFSET(edi
));
432 /* everything above edi has been popped already */
434 fprintf( outfile
, "\tmovl %%eax, %d(%%edi)\n", CONTEXTOFFSET(Eax
) );
435 fprintf( outfile
, "\tmovl %%ebx, %d(%%edi)\n", CONTEXTOFFSET(Ebx
) );
436 fprintf( outfile
, "\tmovl %%ecx, %d(%%edi)\n", CONTEXTOFFSET(Ecx
) );
437 fprintf( outfile
, "\tmovl %%edx, %d(%%edi)\n", CONTEXTOFFSET(Edx
) );
438 fprintf( outfile
, "\tmovl %%ebp, %d(%%edi)\n", CONTEXTOFFSET(Ebp
) );
439 fprintf( outfile
, "\tmovl %%esi, %d(%%edi)\n", CONTEXTOFFSET(Esp
) );
440 /* The return glue code saved %esp into %esi */
443 /* Restore the 32-bit registers */
444 fprintf( outfile
, "\tpopl %%edi\n" );
445 fprintf( outfile
, "\tpopl %%esi\n" );
446 fprintf( outfile
, "\tpopl %%ebx\n" );
448 /* Function exit sequence */
449 fprintf( outfile
, "\tpopl %%ebp\n" );
450 fprintf( outfile
, "\tret $12\n" );
453 /* Start of the actual CallTo16 routine */
455 fprintf( outfile
, ".L%s:\n", name
);
457 /* Switch to the 16-bit stack */
458 fprintf( outfile
, "\tmovl %%esp,%%edx\n" );
459 fprintf( outfile
, "%s\t.byte 0x64\n\tmovw (%d),%%ss\n", data16_prefix(), STACKOFFSET
+ 2);
460 fprintf( outfile
, "\t.byte 0x64\n\tmovw (%d),%%sp\n", STACKOFFSET
);
461 fprintf( outfile
, "\t.byte 0x64\n\tmovl %%edx,(%d)\n", STACKOFFSET
);
463 /* Make %bp point to the previous stackframe (built by CallFrom16) */
464 fprintf( outfile
, "\tmovzwl %%sp,%%ebp\n" );
465 fprintf( outfile
, "\tleal %d(%%ebp),%%ebp\n", STACK16OFFSET(bp
) );
467 /* Add the specified offset to the new sp */
468 fprintf( outfile
, "\tsubw %d(%%edx), %%sp\n", STACK32OFFSET(nb_args
) );
472 /* Push the called routine address */
473 fprintf( outfile
, "\tmovl %d(%%edx),%%edx\n", STACK32OFFSET(target
) );
474 fprintf( outfile
, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegCs
) );
475 fprintf( outfile
, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(Eip
) );
477 /* Get the registers */
478 fprintf( outfile
, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegDs
) );
479 fprintf( outfile
, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegEs
) );
480 fprintf( outfile
, "\tpopl %%es\n" );
481 fprintf( outfile
, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegFs
) );
482 fprintf( outfile
, "\tpopl %%fs\n" );
483 fprintf( outfile
, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegGs
) );
484 fprintf( outfile
, "\tpopl %%gs\n" );
485 fprintf( outfile
, "\tmovl %d(%%edx),%%ebp\n", CONTEXTOFFSET(Ebp
) );
486 fprintf( outfile
, "\tmovl %d(%%edx),%%esi\n", CONTEXTOFFSET(Esi
) );
487 fprintf( outfile
, "\tmovl %d(%%edx),%%edi\n", CONTEXTOFFSET(Edi
) );
488 fprintf( outfile
, "\tmovl %d(%%edx),%%eax\n", CONTEXTOFFSET(Eax
) );
489 fprintf( outfile
, "\tmovl %d(%%edx),%%ebx\n", CONTEXTOFFSET(Ebx
) );
490 fprintf( outfile
, "\tmovl %d(%%edx),%%ecx\n", CONTEXTOFFSET(Ecx
) );
491 fprintf( outfile
, "\tmovl %d(%%edx),%%edx\n", CONTEXTOFFSET(Edx
) );
493 /* Get the 16-bit ds */
494 fprintf( outfile
, "\tpopw %%ds\n" );
496 else /* not a register function */
498 /* Push the called routine address */
499 fprintf( outfile
, "\tpushl %d(%%edx)\n", STACK32OFFSET(target
) );
501 /* Set %fs and %gs to the value saved by the last CallFrom16 */
502 fprintf( outfile
, "\tpushw %d(%%ebp)\n", STACK16OFFSET(fs
)-STACK16OFFSET(bp
) );
503 fprintf( outfile
, "\tpopw %%fs\n" );
504 fprintf( outfile
, "\tpushw %d(%%ebp)\n", STACK16OFFSET(gs
)-STACK16OFFSET(bp
) );
505 fprintf( outfile
, "\tpopw %%gs\n" );
507 /* Set %ds and %es (and %ax just in case) equal to %ss */
508 fprintf( outfile
, "\tmovw %%ss,%%ax\n" );
509 fprintf( outfile
, "\tmovw %%ax,%%ds\n" );
510 fprintf( outfile
, "\tmovw %%ax,%%es\n" );
513 /* Jump to the called routine */
514 fprintf( outfile
, "\t.byte 0x66\n" );
515 fprintf( outfile
, "\tlret\n" );
517 /* Function footer */
518 output_function_size( outfile
, name
);
522 /*******************************************************************
525 * Build the return code for 16-bit callbacks
527 static void BuildRet16Func( FILE *outfile
)
529 function_header( outfile
, "__wine_call_to_16_ret" );
531 /* Save %esp into %esi */
532 fprintf( outfile
, "\tmovl %%esp,%%esi\n" );
534 /* Restore 32-bit segment registers */
536 fprintf( outfile
, "\t.byte 0x2e\n\tmovl %s", asm_name("CallTo16_DataSelector") );
537 fprintf( outfile
, "-%s,%%edi\n", asm_name("__wine_call16_start") );
538 fprintf( outfile
, "%s\tmovw %%di,%%ds\n", data16_prefix() );
539 fprintf( outfile
, "%s\tmovw %%di,%%es\n", data16_prefix() );
541 fprintf( outfile
, "\t.byte 0x2e\n\tmov %s", asm_name("CallTo16_TebSelector") );
542 fprintf( outfile
, "-%s,%%fs\n", asm_name("__wine_call16_start") );
544 fprintf( outfile
, "\t.byte 0x64\n\tmov (%d),%%gs\n", STRUCTOFFSET(TEB
,gs_sel
) );
546 /* Restore the 32-bit stack */
548 fprintf( outfile
, "%s\tmovw %%di,%%ss\n", data16_prefix() );
549 fprintf( outfile
, "\t.byte 0x64\n\tmovl (%d),%%esp\n", STACKOFFSET
);
551 /* Return to caller */
553 fprintf( outfile
, "\tlret\n" );
554 output_function_size( outfile
, "__wine_call_to_16_ret" );
558 /*******************************************************************
559 * BuildCallTo32CBClient
561 * Call a CBClient relay stub from 32-bit code (KERNEL.620).
563 * Since the relay stub is itself 32-bit, this should not be a problem;
564 * unfortunately, the relay stubs are expected to switch back to a
565 * 16-bit stack (and 16-bit code) after completion :-(
567 * This would conflict with our 16- vs. 32-bit stack handling, so
568 * we simply switch *back* to our 32-bit stack before returning to
571 * The CBClient relay stub expects to be called with the following
572 * 16-bit stack layout, and with ebp and ebx pointing into the 16-bit
573 * stack at the designated places:
576 * (ebp+14) original arguments to the callback routine
577 * (ebp+10) far return address to original caller
578 * (ebp+6) Thunklet target address
579 * (ebp+2) Thunklet relay ID code
580 * (ebp) BP (saved by CBClientGlueSL)
581 * (ebp-2) SI (saved by CBClientGlueSL)
582 * (ebp-4) DI (saved by CBClientGlueSL)
583 * (ebp-6) DS (saved by CBClientGlueSL)
585 * ... buffer space used by the 16-bit side glue for temp copies
587 * (ebx+4) far return address to 16-bit side glue code
588 * (ebx) saved 16-bit ss:sp (pointing to ebx+4)
590 * The 32-bit side glue code accesses both the original arguments (via ebp)
591 * and the temporary copies prepared by the 16-bit side glue (via ebx).
592 * After completion, the stub will load ss:sp from the buffer at ebx
593 * and perform a far return to 16-bit code.
595 * To trick the relay stub into returning to us, we replace the 16-bit
596 * return address to the glue code by a cs:ip pair pointing to our
597 * return entry point (the original return address is saved first).
598 * Our return stub thus called will then reload the 32-bit ss:esp and
599 * return to 32-bit code (by using and ss:esp value that we have also
600 * pushed onto the 16-bit stack before and a cs:eip values found at
601 * that position on the 32-bit stack). The ss:esp to be restored is
602 * found relative to the 16-bit stack pointer at:
605 * (ebx-8) sp (32-bit stack pointer)
607 * The second variant of this routine, CALL32_CBClientEx, which is used
608 * to implement KERNEL.621, has to cope with yet another problem: Here,
609 * the 32-bit side directly returns to the caller of the CBClient thunklet,
610 * restoring registers saved by CBClientGlueSL and cleaning up the stack.
611 * As we have to return to our 32-bit code first, we have to adapt the
612 * layout of our temporary area so as to include values for the registers
613 * that are to be restored, and later (in the implementation of KERNEL.621)
614 * we *really* restore them. The return stub restores DS, DI, SI, and BP
615 * from the stack, skips the next 8 bytes (CBClient relay code / target),
616 * and then performs a lret NN, where NN is the number of arguments to be
617 * removed. Thus, we prepare our temporary area as follows:
619 * (ebx+22) 16-bit cs (this segment)
620 * (ebx+20) 16-bit ip ('16-bit' return entry point)
621 * (ebx+16) 32-bit ss (flat)
622 * (ebx+12) 32-bit sp (32-bit stack pointer)
623 * (ebx+10) 16-bit bp (points to ebx+24)
624 * (ebx+8) 16-bit si (ignored)
625 * (ebx+6) 16-bit di (ignored)
626 * (ebx+4) 16-bit ds (we actually use the flat DS here)
627 * (ebx+2) 16-bit ss (16-bit stack segment)
628 * (ebx+0) 16-bit sp (points to ebx+4)
630 * Note that we ensure that DS is not changed and remains the flat segment,
631 * and the 32-bit stack pointer our own return stub needs fits just
632 * perfectly into the 8 bytes that are skipped by the Windows stub.
633 * One problem is that we have to determine the number of removed arguments,
634 * as these have to be really removed in KERNEL.621. Thus, the BP value
635 * that we place in the temporary area to be restored, contains the value
636 * that SP would have if no arguments were removed. By comparing the actual
637 * value of SP with this value in our return stub we can compute the number
638 * of removed arguments. This is then returned to KERNEL.621.
640 * The stack layout of this function:
641 * (ebp+20) nArgs pointer to variable receiving nr. of args (Ex only)
642 * (ebp+16) esi pointer to caller's esi value
643 * (ebp+12) arg ebp value to be set for relay stub
644 * (ebp+8) func CBClient relay stub address
648 static void BuildCallTo32CBClient( FILE *outfile
, BOOL isEx
)
650 function_header( outfile
, isEx
? "CALL32_CBClientEx" : "CALL32_CBClient" );
654 fprintf( outfile
, "\tpushl %%ebp\n" );
655 fprintf( outfile
, "\tmovl %%esp,%%ebp\n" );
656 fprintf( outfile
, "\tpushl %%edi\n" );
657 fprintf( outfile
, "\tpushl %%esi\n" );
658 fprintf( outfile
, "\tpushl %%ebx\n" );
660 /* Get pointer to temporary area and save the 32-bit stack pointer */
662 fprintf( outfile
, "\tmovl 16(%%ebp), %%ebx\n" );
663 fprintf( outfile
, "\tleal -8(%%esp), %%eax\n" );
666 fprintf( outfile
, "\tmovl %%eax, -8(%%ebx)\n" );
668 fprintf( outfile
, "\tmovl %%eax, 12(%%ebx)\n" );
670 /* Set up registers and call CBClient relay stub (simulating a far call) */
672 fprintf( outfile
, "\tmovl 20(%%ebp), %%esi\n" );
673 fprintf( outfile
, "\tmovl (%%esi), %%esi\n" );
675 fprintf( outfile
, "\tmovl 8(%%ebp), %%eax\n" );
676 fprintf( outfile
, "\tmovl 12(%%ebp), %%ebp\n" );
678 fprintf( outfile
, "\tpushl %%cs\n" );
679 fprintf( outfile
, "\tcall *%%eax\n" );
681 /* Return new esi value to caller */
683 fprintf( outfile
, "\tmovl 32(%%esp), %%edi\n" );
684 fprintf( outfile
, "\tmovl %%esi, (%%edi)\n" );
686 /* Return argument size to caller */
689 fprintf( outfile
, "\tmovl 36(%%esp), %%ebx\n" );
690 fprintf( outfile
, "\tmovl %%ebp, (%%ebx)\n" );
693 /* Restore registers and return */
695 fprintf( outfile
, "\tpopl %%ebx\n" );
696 fprintf( outfile
, "\tpopl %%esi\n" );
697 fprintf( outfile
, "\tpopl %%edi\n" );
698 fprintf( outfile
, "\tpopl %%ebp\n" );
699 fprintf( outfile
, "\tret\n" );
700 output_function_size( outfile
, isEx
? "CALL32_CBClientEx" : "CALL32_CBClient" );
702 /* '16-bit' return stub */
704 function_header( outfile
, isEx
? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
707 fprintf( outfile
, "\tmovzwl %%sp, %%ebx\n" );
708 fprintf( outfile
, "\tlssl %%ss:-16(%%ebx), %%esp\n" );
712 fprintf( outfile
, "\tmovzwl %%bp, %%ebx\n" );
713 fprintf( outfile
, "\tsubw %%bp, %%sp\n" );
714 fprintf( outfile
, "\tmovzwl %%sp, %%ebp\n" );
715 fprintf( outfile
, "\tlssl %%ss:-12(%%ebx), %%esp\n" );
717 fprintf( outfile
, "\tlret\n" );
718 output_function_size( outfile
, isEx
? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
722 /*******************************************************************
723 * BuildCallFrom32Regs
725 * Build a 32-bit-to-Wine call-back function for a 'register' function.
726 * 'args' is the number of dword arguments.
731 * (ebp+12) ret addr to user code
732 * (ebp+8) eax saved by relay code
733 * (ebp+4) ret addr to relay code
735 * (ebp-128) buffer area to allow stack frame manipulation
736 * (ebp-332) CONTEXT86 struct
737 * (ebp-336) padding for stack alignment
738 * (ebp-336-n) CONTEXT86 *argument
739 * .... other arguments copied from (ebp+12)
741 * The entry point routine is called with a CONTEXT* extra argument,
742 * following the normal args. In this context structure, EIP_reg
743 * contains the return address to user code, and ESP_reg the stack
744 * pointer on return (with the return address and arguments already
747 static void BuildCallFrom32Regs( FILE *outfile
)
749 static const int STACK_SPACE
= 128 + sizeof(CONTEXT86
);
751 /* Function header */
753 function_header( outfile
, "__wine_call_from_32_regs" );
755 /* Allocate some buffer space on the stack */
757 fprintf( outfile
, "\tpushl %%ebp\n" );
758 fprintf( outfile
, "\tmovl %%esp,%%ebp\n ");
759 fprintf( outfile
, "\tleal -%d(%%esp), %%esp\n", STACK_SPACE
+ 4 /* for context arg */);
761 /* Build the context structure */
763 fprintf( outfile
, "\tpushfl\n" );
764 fprintf( outfile
, "\tpopl %%eax\n" );
765 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(EFlags
) - STACK_SPACE
);
766 fprintf( outfile
, "\tmovl 0(%%ebp),%%eax\n" );
767 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Ebp
) - STACK_SPACE
);
768 fprintf( outfile
, "\tmovl 8(%%ebp),%%eax\n" );
769 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eax
) - STACK_SPACE
);
770 fprintf( outfile
, "\tmovl %%ebx,%d(%%ebp)\n", CONTEXTOFFSET(Ebx
) - STACK_SPACE
);
771 fprintf( outfile
, "\tmovl %%ecx,%d(%%ebp)\n", CONTEXTOFFSET(Ecx
) - STACK_SPACE
);
772 fprintf( outfile
, "\tmovl %%edx,%d(%%ebp)\n", CONTEXTOFFSET(Edx
) - STACK_SPACE
);
773 fprintf( outfile
, "\tmovl %%esi,%d(%%ebp)\n", CONTEXTOFFSET(Esi
) - STACK_SPACE
);
774 fprintf( outfile
, "\tmovl %%edi,%d(%%ebp)\n", CONTEXTOFFSET(Edi
) - STACK_SPACE
);
776 fprintf( outfile
, "\txorl %%eax,%%eax\n" );
777 fprintf( outfile
, "\tmovw %%cs,%%ax\n" );
778 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegCs
) - STACK_SPACE
);
779 fprintf( outfile
, "\tmovw %%es,%%ax\n" );
780 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegEs
) - STACK_SPACE
);
781 fprintf( outfile
, "\tmovw %%fs,%%ax\n" );
782 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegFs
) - STACK_SPACE
);
783 fprintf( outfile
, "\tmovw %%gs,%%ax\n" );
784 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegGs
) - STACK_SPACE
);
785 fprintf( outfile
, "\tmovw %%ss,%%ax\n" );
786 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegSs
) - STACK_SPACE
);
787 fprintf( outfile
, "\tmovw %%ds,%%ax\n" );
788 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegDs
) - STACK_SPACE
);
789 fprintf( outfile
, "\tmovw %%ax,%%es\n" ); /* set %es equal to %ds just in case */
791 fprintf( outfile
, "\tmovl $0x%x,%%eax\n", CONTEXT86_FULL
);
792 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(ContextFlags
) - STACK_SPACE
);
794 fprintf( outfile
, "\tmovl 12(%%ebp),%%eax\n" ); /* Get %eip at time of call */
795 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eip
) - STACK_SPACE
);
797 /* Transfer the arguments */
799 fprintf( outfile
, "\tmovl 4(%%ebp),%%ebx\n" ); /* get relay code addr */
800 fprintf( outfile
, "\tmovzbl 4(%%ebx),%%ecx\n" ); /* fetch number of args to copy */
801 fprintf( outfile
, "\tsubl %%ecx,%%esp\n" );
802 fprintf( outfile
, "\tandl $~15,%%esp\n" );
803 fprintf( outfile
, "\tleal 16(%%ebp),%%esi\n" ); /* get %esp at time of call */
804 fprintf( outfile
, "\tmovl %%esp,%%edi\n" );
805 fprintf( outfile
, "\tshrl $2,%%ecx\n" );
806 fprintf( outfile
, "\tjz 1f\n" );
807 fprintf( outfile
, "\tcld\n" );
808 fprintf( outfile
, "\trep\n\tmovsl\n" ); /* copy args */
809 fprintf( outfile
, "1:\tleal %d(%%ebp),%%eax\n", -STACK_SPACE
); /* get addr of context struct */
810 fprintf( outfile
, "\tmovl %%eax,(%%edi)\n" ); /* and pass it as extra arg */
811 fprintf( outfile
, "\tmovzbl 5(%%ebx),%%eax\n" ); /* fetch number of args to remove */
812 fprintf( outfile
, "\tleal 16(%%ebp,%%eax),%%eax\n" );
813 fprintf( outfile
, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Esp
) - STACK_SPACE
);
815 /* Call the entry point */
817 fprintf( outfile
, "\taddl (%%ebx),%%ebx\n" );
818 fprintf( outfile
, "\tcall *%%ebx\n" );
819 fprintf( outfile
, "\tleal -%d(%%ebp),%%ecx\n", STACK_SPACE
);
821 /* Restore the context structure */
823 fprintf( outfile
, "2:\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegEs
) );
824 fprintf( outfile
, "\tpopl %%es\n" );
825 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegFs
) );
826 fprintf( outfile
, "\tpopl %%fs\n" );
827 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegGs
) );
828 fprintf( outfile
, "\tpopl %%gs\n" );
830 fprintf( outfile
, "\tmovl %d(%%ecx),%%edi\n", CONTEXTOFFSET(Edi
) );
831 fprintf( outfile
, "\tmovl %d(%%ecx),%%esi\n", CONTEXTOFFSET(Esi
) );
832 fprintf( outfile
, "\tmovl %d(%%ecx),%%edx\n", CONTEXTOFFSET(Edx
) );
833 fprintf( outfile
, "\tmovl %d(%%ecx),%%ebx\n", CONTEXTOFFSET(Ebx
) );
834 fprintf( outfile
, "\tmovl %d(%%ecx),%%eax\n", CONTEXTOFFSET(Eax
) );
835 fprintf( outfile
, "\tmovl %d(%%ecx),%%ebp\n", CONTEXTOFFSET(Ebp
) );
837 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegSs
) );
838 fprintf( outfile
, "\tpopl %%ss\n" );
839 fprintf( outfile
, "\tmovl %d(%%ecx),%%esp\n", CONTEXTOFFSET(Esp
) );
841 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(EFlags
) );
842 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegCs
) );
843 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(Eip
) );
844 fprintf( outfile
, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegDs
) );
845 fprintf( outfile
, "\tmovl %d(%%ecx),%%ecx\n", CONTEXTOFFSET(Ecx
) );
847 fprintf( outfile
, "\tpopl %%ds\n" );
848 fprintf( outfile
, "\tiret\n" );
849 output_function_size( outfile
, "__wine_call_from_32_regs" );
851 function_header( outfile
, "__wine_call_from_32_restore_regs" );
852 fprintf( outfile
, "\tleal 4(%%esp),%%ecx\n" );
853 fprintf( outfile
, "\tjmp 2b\n" );
854 output_function_size( outfile
, "__wine_call_from_32_restore_regs" );
858 /*******************************************************************
859 * BuildPendingEventCheck
861 * Build a function that checks whether there are any
862 * pending DPMI events.
866 * (sp+12) long eflags
871 * On entry to function, fs register points to a valid TEB.
872 * On exit from function, stack will be popped.
874 static void BuildPendingEventCheck( FILE *outfile
)
876 /* Function header */
878 function_header( outfile
, "DPMI_PendingEventCheck" );
880 /* Check for pending events. */
882 fprintf( outfile
, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
883 STRUCTOFFSET(TEB
,vm86_pending
) );
884 fprintf( outfile
, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
886 fprintf( outfile
, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
887 STRUCTOFFSET(TEB
,dpmi_vif
) );
889 fprintf( outfile
, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
891 /* Process pending events. */
893 fprintf( outfile
, "\tsti\n" );
895 /* Start cleanup. Restore fs register. */
897 fprintf( outfile
, "%s\n", asm_globl("DPMI_PendingEventCheck_Cleanup") );
898 fprintf( outfile
, "\tpopw %%fs\n" );
900 /* Return from function. */
902 fprintf( outfile
, "%s\n", asm_globl("DPMI_PendingEventCheck_Return") );
903 fprintf( outfile
, "\tiret\n" );
905 output_function_size( outfile
, "DPMI_PendingEventCheck" );
909 /*******************************************************************
912 * Build all the 16-bit relay callbacks
914 void BuildRelays16( FILE *outfile
)
916 if (target_cpu
!= CPU_x86
)
918 fprintf( outfile
, "/* File not used with this architecture. Do not edit! */\n\n" );
924 fprintf( outfile
, "/* File generated automatically. Do not edit! */\n\n" );
925 fprintf( outfile
, "\t.text\n" );
927 fprintf( outfile
, "%s:\n\n", asm_name("__wine_spec_thunk_text_16") );
929 fprintf( outfile
, "%s\n", asm_globl("__wine_call16_start") );
931 /* Standard CallFrom16 routine */
932 BuildCallFrom16Core( outfile
, FALSE
, FALSE
);
934 /* Register CallFrom16 routine */
935 BuildCallFrom16Core( outfile
, TRUE
, FALSE
);
937 /* C16ThkSL CallFrom16 routine */
938 BuildCallFrom16Core( outfile
, FALSE
, TRUE
);
940 /* Standard CallTo16 routine */
941 BuildCallTo16Core( outfile
, 0 );
943 /* Register CallTo16 routine */
944 BuildCallTo16Core( outfile
, 1 );
946 /* Standard CallTo16 return stub */
947 BuildRet16Func( outfile
);
949 /* CBClientThunkSL routine */
950 BuildCallTo32CBClient( outfile
, FALSE
);
952 /* CBClientThunkSLEx routine */
953 BuildCallTo32CBClient( outfile
, TRUE
);
955 /* Pending DPMI events check stub */
956 BuildPendingEventCheck( outfile
);
958 fprintf( outfile
, "%s\n", asm_globl("__wine_call16_end") );
959 output_function_size( outfile
, "__wine_spec_thunk_text_16" );
961 /* Declare the return address and data selector variables */
962 fprintf( outfile
, "\n\t.data\n\t.align %d\n", get_alignment(4) );
963 fprintf( outfile
, "%s\n\t.long 0\n", asm_globl("CallTo16_DataSelector") );
964 fprintf( outfile
, "%s\n\t.long 0\n", asm_globl("CallTo16_TebSelector") );
965 if (UsePIC
) fprintf( outfile
, "wine_ldt_copy_ptr:\t.long %s\n", asm_name("wine_ldt_copy") );
968 /*******************************************************************
971 * Build all the 32-bit relay callbacks
973 void BuildRelays32( FILE *outfile
)
975 if (target_cpu
!= CPU_x86
)
977 fprintf( outfile
, "/* File not used with this architecture. Do not edit! */\n\n" );
983 fprintf( outfile
, "/* File generated automatically. Do not edit! */\n\n" );
984 fprintf( outfile
, "\t.text\n" );
985 fprintf( outfile
, "%s:\n\n", asm_name("__wine_spec_thunk_text_32") );
987 /* 32-bit register entry point */
988 BuildCallFrom32Regs( outfile
);
990 output_function_size( outfile
, "__wine_spec_thunk_text_32" );