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
26 #include "wine/port.h"
31 #include "wine/winbase16.h"
35 static void function_header( FILE *outfile, const char *name )
37 fprintf( outfile, "\n\t.align %d\n", get_alignment(4) );
38 fprintf( outfile, "\t%s\n", func_declaration(name) );
39 fprintf( outfile, "%s\n", asm_globl(name) );
43 static void function_footer( FILE *outfile, const char *name )
45 const char *size = func_size( name );
46 if (size[0]) fprintf( outfile, "\t%s\n", size );
49 static inline const char *data16_prefix(void)
51 return (target_platform == PLATFORM_SVR4) ? "\tdata16\n" : "";
54 /*******************************************************************
57 * This routine builds the core routines used in 16->32 thunks:
58 * CallFrom16Word, CallFrom16Long, CallFrom16Register, and CallFrom16Thunk.
60 * These routines are intended to be called via a far call (with 32-bit
61 * operand size) from 16-bit code. The 16-bit code stub must push %bp,
62 * the 32-bit entry point to be called, and the argument conversion
63 * routine to be used (see stack layout below).
65 * The core routine completes the STACK16FRAME on the 16-bit stack and
66 * switches to the 32-bit stack. Then, the argument conversion routine
67 * is called; it gets passed the 32-bit entry point and a pointer to the
68 * 16-bit arguments (on the 16-bit stack) as parameters. (You can either
69 * use conversion routines automatically generated by BuildCallFrom16,
70 * or write your own for special purposes.)
72 * The conversion routine must call the 32-bit entry point, passing it
73 * the converted arguments, and return its return value to the core.
74 * After the conversion routine has returned, the core switches back
75 * to the 16-bit stack, converts the return value to the DX:AX format
76 * (CallFrom16Long), and returns to the 16-bit call stub. All parameters,
77 * including %bp, are popped off the stack.
79 * The 16-bit call stub now returns to the caller, popping the 16-bit
80 * arguments if necessary (pascal calling convention).
82 * In the case of a 'register' function, CallFrom16Register fills a
83 * CONTEXT86 structure with the values all registers had at the point
84 * the first instruction of the 16-bit call stub was about to be
85 * executed. A pointer to this CONTEXT86 is passed as third parameter
86 * to the argument conversion routine, which typically passes it on
87 * to the called 32-bit entry point.
89 * CallFrom16Thunk is a special variant used by the implementation of
90 * the Win95 16->32 thunk functions C16ThkSL and C16ThkSL01 and is
91 * implemented as follows:
92 * On entry, the EBX register is set up to contain a flat pointer to the
93 * 16-bit stack such that EBX+22 points to the first argument.
94 * Then, the entry point is called, while EBP is set up to point
95 * to the return address (on the 32-bit stack).
96 * The called function returns with CX set to the number of bytes
97 * to be popped of the caller's stack.
99 * Stack layout upon entry to the core routine (STACK16FRAME):
101 * (sp+24) word first 16-bit arg
105 * (sp+14) long 32-bit entry point (reused for Win16 mutex recursion count)
106 * (sp+12) word ip of actual entry point (necessary for relay debugging)
107 * (sp+8) long relay (argument conversion) function entry point
108 * (sp+4) long cs of 16-bit entry point
109 * (sp) long ip of 16-bit entry point
111 * Added on the stack:
112 * (sp-2) word saved gs
113 * (sp-4) word saved fs
114 * (sp-6) word saved es
115 * (sp-8) word saved ds
116 * (sp-12) long saved ebp
117 * (sp-16) long saved ecx
118 * (sp-20) long saved edx
119 * (sp-24) long saved previous stack
121 static void BuildCallFrom16Core( FILE *outfile, int reg_func, int thunk, int short_ret )
123 const char *name = thunk? "thunk" : reg_func? "regs" : short_ret? "word" : "long";
125 /* Function header */
126 if (thunk) function_header( outfile, "__wine_call_from_16_thunk" );
127 else if (reg_func) function_header( outfile, "__wine_call_from_16_regs" );
128 else if (short_ret) function_header( outfile, "__wine_call_from_16_word" );
129 else function_header( outfile, "__wine_call_from_16_long" );
131 /* Create STACK16FRAME (except STACK32FRAME link) */
132 fprintf( outfile, "\tpushw %%gs\n" );
133 fprintf( outfile, "\tpushw %%fs\n" );
134 fprintf( outfile, "\tpushw %%es\n" );
135 fprintf( outfile, "\tpushw %%ds\n" );
136 fprintf( outfile, "\tpushl %%ebp\n" );
137 fprintf( outfile, "\tpushl %%ecx\n" );
138 fprintf( outfile, "\tpushl %%edx\n" );
140 /* Save original EFlags register */
141 if (reg_func) fprintf( outfile, "\tpushfl\n" );
145 fprintf( outfile, "\tcall .Lcall_from_16_%s.getpc\n", name );
146 fprintf( outfile, ".Lcall_from_16_%s.getpc:\n", name );
147 fprintf( outfile, "\tpopl %%ecx\n" );
148 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s-.Lcall_from_16_%s.getpc(%%ecx),%%edx\n",
149 asm_name("CallTo16_DataSelector"), name );
152 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s,%%edx\n", asm_name("CallTo16_DataSelector") );
154 /* Load 32-bit segment registers */
155 fprintf( outfile, "%s\tmovw %%dx, %%ds\n", data16_prefix() );
156 fprintf( outfile, "%s\tmovw %%dx, %%es\n", data16_prefix() );
159 fprintf( outfile, "\tmovw %s-.Lcall_from_16_%s.getpc(%%ecx), %%fs\n",
160 asm_name("CallTo16_TebSelector"), name );
162 fprintf( outfile, "\tmovw %s, %%fs\n", asm_name("CallTo16_TebSelector") );
164 fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n", STRUCTOFFSET(TEB,gs_sel) );
166 /* Translate STACK16FRAME base to flat offset in %edx */
167 fprintf( outfile, "\tmovw %%ss, %%dx\n" );
168 fprintf( outfile, "\tandl $0xfff8, %%edx\n" );
169 fprintf( outfile, "\tshrl $1, %%edx\n" );
172 fprintf( outfile, "\taddl wine_ldt_copy_ptr-.Lcall_from_16_%s.getpc(%%ecx),%%edx\n", name );
173 fprintf( outfile, "\tmovl (%%edx), %%edx\n" );
176 fprintf( outfile, "\tmovl %s(%%edx), %%edx\n", asm_name("wine_ldt_copy") );
177 fprintf( outfile, "\tmovzwl %%sp, %%ebp\n" );
178 fprintf( outfile, "\tleal %d(%%ebp,%%edx), %%edx\n", reg_func ? 0 : -4 );
180 /* Get saved flags into %ecx */
181 if (reg_func) fprintf( outfile, "\tpopl %%ecx\n" );
183 /* Get the 32-bit stack pointer from the TEB and complete STACK16FRAME */
184 fprintf( outfile, "\t.byte 0x64\n\tmovl (%d), %%ebp\n", STACKOFFSET );
185 fprintf( outfile, "\tpushl %%ebp\n" );
188 fprintf( outfile, "%s\t.byte 0x64\n\tmovw %%ss, (%d)\n", data16_prefix(), STACKOFFSET + 2 );
189 fprintf( outfile, "\t.byte 0x64\n\tmovw %%sp, (%d)\n", STACKOFFSET );
190 fprintf( outfile, "\tpushl %%ds\n" );
191 fprintf( outfile, "\tpopl %%ss\n" );
192 fprintf( outfile, "\tmovl %%ebp, %%esp\n" );
193 fprintf( outfile, "\taddl $%d, %%ebp\n", STRUCTOFFSET(STACK32FRAME, ebp) );
197 STACK16FRAME is completely set up
198 DS, ES, SS: flat data segment
200 ESP: points to last STACK32FRAME
201 EBP: points to ebp member of last STACK32FRAME
202 EDX: points to current STACK16FRAME
203 ECX: contains saved flags
204 all other registers: unchanged */
206 /* Special case: C16ThkSL stub */
209 /* Set up registers as expected and call thunk */
210 fprintf( outfile, "\tleal %d(%%edx), %%ebx\n", sizeof(STACK16FRAME)-22 );
211 fprintf( outfile, "\tleal -4(%%esp), %%ebp\n" );
213 fprintf( outfile, "\tcall *%d(%%edx)\n", STACK16OFFSET(entry_point) );
215 /* Switch stack back */
216 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
217 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
218 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
220 /* Restore registers and return directly to caller */
221 fprintf( outfile, "\taddl $8, %%esp\n" );
222 fprintf( outfile, "\tpopl %%ebp\n" );
223 fprintf( outfile, "\tpopw %%ds\n" );
224 fprintf( outfile, "\tpopw %%es\n" );
225 fprintf( outfile, "\tpopw %%fs\n" );
226 fprintf( outfile, "\tpopw %%gs\n" );
227 fprintf( outfile, "\taddl $20, %%esp\n" );
229 fprintf( outfile, "\txorb %%ch, %%ch\n" );
230 fprintf( outfile, "\tpopl %%ebx\n" );
231 fprintf( outfile, "\taddw %%cx, %%sp\n" );
232 fprintf( outfile, "\tpush %%ebx\n" );
234 fprintf( outfile, "\t.byte 0x66\n" );
235 fprintf( outfile, "\tlret\n" );
241 /* Build register CONTEXT */
244 fprintf( outfile, "\tsubl $%d, %%esp\n", sizeof(CONTEXT86) );
246 fprintf( outfile, "\tmovl %%ecx, %d(%%esp)\n", CONTEXTOFFSET(EFlags) );
248 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eax) );
249 fprintf( outfile, "\tmovl %%ebx, %d(%%esp)\n", CONTEXTOFFSET(Ebx) );
250 fprintf( outfile, "\tmovl %%esi, %d(%%esp)\n", CONTEXTOFFSET(Esi) );
251 fprintf( outfile, "\tmovl %%edi, %d(%%esp)\n", CONTEXTOFFSET(Edi) );
253 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ebp) );
254 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ebp) );
255 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ecx) );
256 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ecx) );
257 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(edx) );
258 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Edx) );
260 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ds) );
261 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegDs) );
262 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(es) );
263 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegEs) );
264 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(fs) );
265 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegFs) );
266 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(gs) );
267 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegGs) );
269 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(cs) );
270 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegCs) );
271 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ip) );
272 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eip) );
274 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET+2 );
275 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegSs) );
276 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET );
277 fprintf( outfile, "\taddl $%d, %%eax\n", STACK16OFFSET(ip) );
278 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Esp) );
280 fprintf( outfile, "\tfsave %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
283 /* Push address of CONTEXT86 structure -- popped by the relay routine */
284 fprintf( outfile, "\tpushl %%esp\n" );
287 /* Call relay routine (which will call the API entry point) */
288 fprintf( outfile, "\tleal %d(%%edx), %%eax\n", sizeof(STACK16FRAME) );
289 fprintf( outfile, "\tpushl %%eax\n" );
290 fprintf( outfile, "\tpushl %d(%%edx)\n", STACK16OFFSET(entry_point) );
291 fprintf( outfile, "\tcall *%d(%%edx)\n", STACK16OFFSET(relay) );
295 fprintf( outfile, "\tleal -%d(%%ebp), %%ebx\n",
296 sizeof(CONTEXT) + STRUCTOFFSET(STACK32FRAME, ebp) );
298 /* Switch stack back */
299 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
300 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
301 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
303 /* Get return address to CallFrom16 stub */
304 fprintf( outfile, "\taddw $%d, %%sp\n", STACK16OFFSET(callfrom_ip)-4 );
305 fprintf( outfile, "\tpopl %%eax\n" );
306 fprintf( outfile, "\tpopl %%edx\n" );
308 /* Restore all registers from CONTEXT */
309 fprintf( outfile, "\tmovw %d(%%ebx), %%ss\n", CONTEXTOFFSET(SegSs) );
310 fprintf( outfile, "\tmovl %d(%%ebx), %%esp\n", CONTEXTOFFSET(Esp) );
311 fprintf( outfile, "\taddl $4, %%esp\n" ); /* room for final return address */
313 fprintf( outfile, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(SegCs) );
314 fprintf( outfile, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(Eip) );
315 fprintf( outfile, "\tpushl %%edx\n" );
316 fprintf( outfile, "\tpushl %%eax\n" );
317 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(EFlags) );
318 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegDs) );
320 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegEs) );
321 fprintf( outfile, "\tpopl %%es\n" );
322 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegFs) );
323 fprintf( outfile, "\tpopl %%fs\n" );
324 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegGs) );
325 fprintf( outfile, "\tpopl %%gs\n" );
327 fprintf( outfile, "\tmovl %d(%%ebx), %%ebp\n", CONTEXTOFFSET(Ebp) );
328 fprintf( outfile, "\tmovl %d(%%ebx), %%esi\n", CONTEXTOFFSET(Esi) );
329 fprintf( outfile, "\tmovl %d(%%ebx), %%edi\n", CONTEXTOFFSET(Edi) );
330 fprintf( outfile, "\tmovl %d(%%ebx), %%eax\n", CONTEXTOFFSET(Eax) );
331 fprintf( outfile, "\tmovl %d(%%ebx), %%edx\n", CONTEXTOFFSET(Edx) );
332 fprintf( outfile, "\tmovl %d(%%ebx), %%ecx\n", CONTEXTOFFSET(Ecx) );
333 fprintf( outfile, "\tmovl %d(%%ebx), %%ebx\n", CONTEXTOFFSET(Ebx) );
335 fprintf( outfile, "\tpopl %%ds\n" );
336 fprintf( outfile, "\tpopfl\n" );
337 fprintf( outfile, "\tlret\n" );
341 /* Switch stack back */
342 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
343 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
344 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
346 /* Restore registers */
347 fprintf( outfile, "\tpopl %%edx\n" );
348 fprintf( outfile, "\tpopl %%ecx\n" );
349 fprintf( outfile, "\tpopl %%ebp\n" );
350 fprintf( outfile, "\tpopw %%ds\n" );
351 fprintf( outfile, "\tpopw %%es\n" );
352 fprintf( outfile, "\tpopw %%fs\n" );
353 fprintf( outfile, "\tpopw %%gs\n" );
355 /* Prepare return value and set flags accordingly */
357 fprintf( outfile, "\tshldl $16, %%eax, %%edx\n" );
358 fprintf( outfile, "\torl %%eax, %%eax\n" );
360 /* Return to return stub which will return to caller */
361 fprintf( outfile, "\tlret $12\n" );
363 if (thunk) function_footer( outfile, "__wine_call_from_16_thunk" );
364 else if (reg_func) function_footer( outfile, "__wine_call_from_16_regs" );
365 else if (short_ret) function_footer( outfile, "__wine_call_from_16_word" );
366 else function_footer( outfile, "__wine_call_from_16_long" );
370 /*******************************************************************
373 * This routine builds the core routines used in 32->16 thunks:
375 * extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
376 * extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
378 * These routines can be called directly from 32-bit code.
380 * All routines expect that the 16-bit stack contents (arguments) and the
381 * return address (segptr to CallTo16_Ret) were already set up by the
382 * caller; nb_args must contain the number of bytes to be conserved. The
383 * 16-bit SS:SP will be set accordinly.
385 * All other registers are either taken from the CONTEXT86 structure
386 * or else set to default values. The target routine address is either
387 * given directly or taken from the CONTEXT86.
389 static void BuildCallTo16Core( FILE *outfile, int reg_func )
391 const char *name = reg_func ? "wine_call_to_16_regs" : "wine_call_to_16";
393 /* Function header */
394 function_header( outfile, name );
396 /* Function entry sequence */
397 fprintf( outfile, "\tpushl %%ebp\n" );
398 fprintf( outfile, "\tmovl %%esp, %%ebp\n" );
400 /* Save the 32-bit registers */
401 fprintf( outfile, "\tpushl %%ebx\n" );
402 fprintf( outfile, "\tpushl %%esi\n" );
403 fprintf( outfile, "\tpushl %%edi\n" );
404 fprintf( outfile, "\t.byte 0x64\n\tmov %%gs,(%d)\n", STRUCTOFFSET(TEB,gs_sel) );
406 /* Setup exception frame */
407 fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STACKOFFSET );
408 fprintf( outfile, "\tpushl 16(%%ebp)\n" ); /* handler */
409 fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
410 fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
412 /* Call the actual CallTo16 routine (simulate a lcall) */
413 fprintf( outfile, "\tpushl %%cs\n" );
414 fprintf( outfile, "\tcall .L%s\n", name );
416 /* Remove exception frame */
417 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
418 fprintf( outfile, "\taddl $4, %%esp\n" );
419 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
423 /* Convert return value */
424 fprintf( outfile, "\tandl $0xffff,%%eax\n" );
425 fprintf( outfile, "\tshll $16,%%edx\n" );
426 fprintf( outfile, "\torl %%edx,%%eax\n" );
431 * Modify CONTEXT86 structure to contain new values
433 * NOTE: We restore only EAX, EBX, EDX, EDX, EBP, and ESP.
434 * The segment registers as well as ESI and EDI should
435 * not be modified by a well-behaved 16-bit routine in
436 * any case. [If necessary, we could restore them as well,
437 * at the cost of a somewhat less efficient return path.]
440 fprintf( outfile, "\tmovl %d(%%esp), %%edi\n", STACK32OFFSET(target) - STACK32OFFSET(edi));
441 /* everything above edi has been popped already */
443 fprintf( outfile, "\tmovl %%eax, %d(%%edi)\n", CONTEXTOFFSET(Eax) );
444 fprintf( outfile, "\tmovl %%ebx, %d(%%edi)\n", CONTEXTOFFSET(Ebx) );
445 fprintf( outfile, "\tmovl %%ecx, %d(%%edi)\n", CONTEXTOFFSET(Ecx) );
446 fprintf( outfile, "\tmovl %%edx, %d(%%edi)\n", CONTEXTOFFSET(Edx) );
447 fprintf( outfile, "\tmovl %%ebp, %d(%%edi)\n", CONTEXTOFFSET(Ebp) );
448 fprintf( outfile, "\tmovl %%esi, %d(%%edi)\n", CONTEXTOFFSET(Esp) );
449 /* The return glue code saved %esp into %esi */
452 /* Restore the 32-bit registers */
453 fprintf( outfile, "\tpopl %%edi\n" );
454 fprintf( outfile, "\tpopl %%esi\n" );
455 fprintf( outfile, "\tpopl %%ebx\n" );
457 /* Function exit sequence */
458 fprintf( outfile, "\tpopl %%ebp\n" );
459 fprintf( outfile, "\tret $12\n" );
462 /* Start of the actual CallTo16 routine */
464 fprintf( outfile, ".L%s:\n", name );
466 /* Switch to the 16-bit stack */
467 fprintf( outfile, "\tmovl %%esp,%%edx\n" );
468 fprintf( outfile, "%s\t.byte 0x64\n\tmovw (%d),%%ss\n", data16_prefix(), STACKOFFSET + 2);
469 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d),%%sp\n", STACKOFFSET );
470 fprintf( outfile, "\t.byte 0x64\n\tmovl %%edx,(%d)\n", STACKOFFSET );
472 /* Make %bp point to the previous stackframe (built by CallFrom16) */
473 fprintf( outfile, "\tmovzwl %%sp,%%ebp\n" );
474 fprintf( outfile, "\tleal %d(%%ebp),%%ebp\n", STACK16OFFSET(bp) );
476 /* Add the specified offset to the new sp */
477 fprintf( outfile, "\tsubw %d(%%edx), %%sp\n", STACK32OFFSET(nb_args) );
481 /* Push the called routine address */
482 fprintf( outfile, "\tmovl %d(%%edx),%%edx\n", STACK32OFFSET(target) );
483 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegCs) );
484 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(Eip) );
486 /* Get the registers */
487 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegDs) );
488 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegEs) );
489 fprintf( outfile, "\tpopl %%es\n" );
490 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegFs) );
491 fprintf( outfile, "\tpopl %%fs\n" );
492 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegGs) );
493 fprintf( outfile, "\tpopl %%gs\n" );
494 fprintf( outfile, "\tmovl %d(%%edx),%%ebp\n", CONTEXTOFFSET(Ebp) );
495 fprintf( outfile, "\tmovl %d(%%edx),%%esi\n", CONTEXTOFFSET(Esi) );
496 fprintf( outfile, "\tmovl %d(%%edx),%%edi\n", CONTEXTOFFSET(Edi) );
497 fprintf( outfile, "\tmovl %d(%%edx),%%eax\n", CONTEXTOFFSET(Eax) );
498 fprintf( outfile, "\tmovl %d(%%edx),%%ebx\n", CONTEXTOFFSET(Ebx) );
499 fprintf( outfile, "\tmovl %d(%%edx),%%ecx\n", CONTEXTOFFSET(Ecx) );
500 fprintf( outfile, "\tmovl %d(%%edx),%%edx\n", CONTEXTOFFSET(Edx) );
502 /* Get the 16-bit ds */
503 fprintf( outfile, "\tpopw %%ds\n" );
505 else /* not a register function */
507 /* Push the called routine address */
508 fprintf( outfile, "\tpushl %d(%%edx)\n", STACK32OFFSET(target) );
510 /* Set %fs and %gs to the value saved by the last CallFrom16 */
511 fprintf( outfile, "\tpushw %d(%%ebp)\n", STACK16OFFSET(fs)-STACK16OFFSET(bp) );
512 fprintf( outfile, "\tpopw %%fs\n" );
513 fprintf( outfile, "\tpushw %d(%%ebp)\n", STACK16OFFSET(gs)-STACK16OFFSET(bp) );
514 fprintf( outfile, "\tpopw %%gs\n" );
516 /* Set %ds and %es (and %ax just in case) equal to %ss */
517 fprintf( outfile, "\tmovw %%ss,%%ax\n" );
518 fprintf( outfile, "\tmovw %%ax,%%ds\n" );
519 fprintf( outfile, "\tmovw %%ax,%%es\n" );
522 /* Jump to the called routine */
523 fprintf( outfile, "\t.byte 0x66\n" );
524 fprintf( outfile, "\tlret\n" );
526 /* Function footer */
527 function_footer( outfile, name );
531 /*******************************************************************
534 * Build the return code for 16-bit callbacks
536 static void BuildRet16Func( FILE *outfile )
538 function_header( outfile, "__wine_call_to_16_ret" );
540 /* Save %esp into %esi */
541 fprintf( outfile, "\tmovl %%esp,%%esi\n" );
543 /* Restore 32-bit segment registers */
545 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s", asm_name("CallTo16_DataSelector") );
546 fprintf( outfile, "-%s,%%edi\n", asm_name("__wine_call16_start") );
547 fprintf( outfile, "%s\tmovw %%di,%%ds\n", data16_prefix() );
548 fprintf( outfile, "%s\tmovw %%di,%%es\n", data16_prefix() );
550 fprintf( outfile, "\t.byte 0x2e\n\tmov %s", asm_name("CallTo16_TebSelector") );
551 fprintf( outfile, "-%s,%%fs\n", asm_name("__wine_call16_start") );
553 fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n", STRUCTOFFSET(TEB,gs_sel) );
555 /* Restore the 32-bit stack */
557 fprintf( outfile, "%s\tmovw %%di,%%ss\n", data16_prefix() );
558 fprintf( outfile, "\t.byte 0x64\n\tmovl (%d),%%esp\n", STACKOFFSET );
560 /* Return to caller */
562 fprintf( outfile, "\tlret\n" );
563 function_footer( outfile, "__wine_call_to_16_ret" );
567 /*******************************************************************
568 * BuildCallTo32CBClient
570 * Call a CBClient relay stub from 32-bit code (KERNEL.620).
572 * Since the relay stub is itself 32-bit, this should not be a problem;
573 * unfortunately, the relay stubs are expected to switch back to a
574 * 16-bit stack (and 16-bit code) after completion :-(
576 * This would conflict with our 16- vs. 32-bit stack handling, so
577 * we simply switch *back* to our 32-bit stack before returning to
580 * The CBClient relay stub expects to be called with the following
581 * 16-bit stack layout, and with ebp and ebx pointing into the 16-bit
582 * stack at the designated places:
585 * (ebp+14) original arguments to the callback routine
586 * (ebp+10) far return address to original caller
587 * (ebp+6) Thunklet target address
588 * (ebp+2) Thunklet relay ID code
589 * (ebp) BP (saved by CBClientGlueSL)
590 * (ebp-2) SI (saved by CBClientGlueSL)
591 * (ebp-4) DI (saved by CBClientGlueSL)
592 * (ebp-6) DS (saved by CBClientGlueSL)
594 * ... buffer space used by the 16-bit side glue for temp copies
596 * (ebx+4) far return address to 16-bit side glue code
597 * (ebx) saved 16-bit ss:sp (pointing to ebx+4)
599 * The 32-bit side glue code accesses both the original arguments (via ebp)
600 * and the temporary copies prepared by the 16-bit side glue (via ebx).
601 * After completion, the stub will load ss:sp from the buffer at ebx
602 * and perform a far return to 16-bit code.
604 * To trick the relay stub into returning to us, we replace the 16-bit
605 * return address to the glue code by a cs:ip pair pointing to our
606 * return entry point (the original return address is saved first).
607 * Our return stub thus called will then reload the 32-bit ss:esp and
608 * return to 32-bit code (by using and ss:esp value that we have also
609 * pushed onto the 16-bit stack before and a cs:eip values found at
610 * that position on the 32-bit stack). The ss:esp to be restored is
611 * found relative to the 16-bit stack pointer at:
614 * (ebx-8) sp (32-bit stack pointer)
616 * The second variant of this routine, CALL32_CBClientEx, which is used
617 * to implement KERNEL.621, has to cope with yet another problem: Here,
618 * the 32-bit side directly returns to the caller of the CBClient thunklet,
619 * restoring registers saved by CBClientGlueSL and cleaning up the stack.
620 * As we have to return to our 32-bit code first, we have to adapt the
621 * layout of our temporary area so as to include values for the registers
622 * that are to be restored, and later (in the implementation of KERNEL.621)
623 * we *really* restore them. The return stub restores DS, DI, SI, and BP
624 * from the stack, skips the next 8 bytes (CBClient relay code / target),
625 * and then performs a lret NN, where NN is the number of arguments to be
626 * removed. Thus, we prepare our temporary area as follows:
628 * (ebx+22) 16-bit cs (this segment)
629 * (ebx+20) 16-bit ip ('16-bit' return entry point)
630 * (ebx+16) 32-bit ss (flat)
631 * (ebx+12) 32-bit sp (32-bit stack pointer)
632 * (ebx+10) 16-bit bp (points to ebx+24)
633 * (ebx+8) 16-bit si (ignored)
634 * (ebx+6) 16-bit di (ignored)
635 * (ebx+4) 16-bit ds (we actually use the flat DS here)
636 * (ebx+2) 16-bit ss (16-bit stack segment)
637 * (ebx+0) 16-bit sp (points to ebx+4)
639 * Note that we ensure that DS is not changed and remains the flat segment,
640 * and the 32-bit stack pointer our own return stub needs fits just
641 * perfectly into the 8 bytes that are skipped by the Windows stub.
642 * One problem is that we have to determine the number of removed arguments,
643 * as these have to be really removed in KERNEL.621. Thus, the BP value
644 * that we place in the temporary area to be restored, contains the value
645 * that SP would have if no arguments were removed. By comparing the actual
646 * value of SP with this value in our return stub we can compute the number
647 * of removed arguments. This is then returned to KERNEL.621.
649 * The stack layout of this function:
650 * (ebp+20) nArgs pointer to variable receiving nr. of args (Ex only)
651 * (ebp+16) esi pointer to caller's esi value
652 * (ebp+12) arg ebp value to be set for relay stub
653 * (ebp+8) func CBClient relay stub address
657 static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx )
659 function_header( outfile, isEx ? "CALL32_CBClientEx" : "CALL32_CBClient" );
663 fprintf( outfile, "\tpushl %%ebp\n" );
664 fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
665 fprintf( outfile, "\tpushl %%edi\n" );
666 fprintf( outfile, "\tpushl %%esi\n" );
667 fprintf( outfile, "\tpushl %%ebx\n" );
669 /* Get pointer to temporary area and save the 32-bit stack pointer */
671 fprintf( outfile, "\tmovl 16(%%ebp), %%ebx\n" );
672 fprintf( outfile, "\tleal -8(%%esp), %%eax\n" );
675 fprintf( outfile, "\tmovl %%eax, -8(%%ebx)\n" );
677 fprintf( outfile, "\tmovl %%eax, 12(%%ebx)\n" );
679 /* Set up registers and call CBClient relay stub (simulating a far call) */
681 fprintf( outfile, "\tmovl 20(%%ebp), %%esi\n" );
682 fprintf( outfile, "\tmovl (%%esi), %%esi\n" );
684 fprintf( outfile, "\tmovl 8(%%ebp), %%eax\n" );
685 fprintf( outfile, "\tmovl 12(%%ebp), %%ebp\n" );
687 fprintf( outfile, "\tpushl %%cs\n" );
688 fprintf( outfile, "\tcall *%%eax\n" );
690 /* Return new esi value to caller */
692 fprintf( outfile, "\tmovl 32(%%esp), %%edi\n" );
693 fprintf( outfile, "\tmovl %%esi, (%%edi)\n" );
695 /* Return argument size to caller */
698 fprintf( outfile, "\tmovl 36(%%esp), %%ebx\n" );
699 fprintf( outfile, "\tmovl %%ebp, (%%ebx)\n" );
702 /* Restore registers and return */
704 fprintf( outfile, "\tpopl %%ebx\n" );
705 fprintf( outfile, "\tpopl %%esi\n" );
706 fprintf( outfile, "\tpopl %%edi\n" );
707 fprintf( outfile, "\tpopl %%ebp\n" );
708 fprintf( outfile, "\tret\n" );
709 function_footer( outfile, isEx ? "CALL32_CBClientEx" : "CALL32_CBClient" );
711 /* '16-bit' return stub */
713 function_header( outfile, isEx ? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
716 fprintf( outfile, "\tmovzwl %%sp, %%ebx\n" );
717 fprintf( outfile, "\tlssl %%ss:-16(%%ebx), %%esp\n" );
721 fprintf( outfile, "\tmovzwl %%bp, %%ebx\n" );
722 fprintf( outfile, "\tsubw %%bp, %%sp\n" );
723 fprintf( outfile, "\tmovzwl %%sp, %%ebp\n" );
724 fprintf( outfile, "\tlssl %%ss:-12(%%ebx), %%esp\n" );
726 fprintf( outfile, "\tlret\n" );
727 function_footer( outfile, isEx ? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
731 /*******************************************************************
732 * BuildCallFrom32Regs
734 * Build a 32-bit-to-Wine call-back function for a 'register' function.
735 * 'args' is the number of dword arguments.
740 * (ebp+12) ret addr to user code
741 * (ebp+8) eax saved by relay code
742 * (ebp+4) ret addr to relay code
744 * (ebp-128) buffer area to allow stack frame manipulation
745 * (ebp-332) CONTEXT86 struct
746 * (ebp-336) CONTEXT86 *argument
747 * .... other arguments copied from (ebp+12)
749 * The entry point routine is called with a CONTEXT* extra argument,
750 * following the normal args. In this context structure, EIP_reg
751 * contains the return address to user code, and ESP_reg the stack
752 * pointer on return (with the return address and arguments already
755 static void BuildCallFrom32Regs( FILE *outfile )
757 static const int STACK_SPACE = 128 + sizeof(CONTEXT86);
759 /* Function header */
761 function_header( outfile, "__wine_call_from_32_regs" );
763 /* Allocate some buffer space on the stack */
765 fprintf( outfile, "\tpushl %%ebp\n" );
766 fprintf( outfile, "\tmovl %%esp,%%ebp\n ");
767 fprintf( outfile, "\tleal -%d(%%esp), %%esp\n", STACK_SPACE );
769 /* Build the context structure */
771 fprintf( outfile, "\tpushfl\n" );
772 fprintf( outfile, "\tpopl %%eax\n" );
773 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(EFlags) - STACK_SPACE );
774 fprintf( outfile, "\tmovl 0(%%ebp),%%eax\n" );
775 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Ebp) - STACK_SPACE );
776 fprintf( outfile, "\tmovl 4(%%ebp),%%eax\n" );
777 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eax) - STACK_SPACE );
778 fprintf( outfile, "\tmovl %%ebx,%d(%%ebp)\n", CONTEXTOFFSET(Ebx) - STACK_SPACE );
779 fprintf( outfile, "\tmovl %%ecx,%d(%%ebp)\n", CONTEXTOFFSET(Ecx) - STACK_SPACE );
780 fprintf( outfile, "\tmovl %%edx,%d(%%ebp)\n", CONTEXTOFFSET(Edx) - STACK_SPACE );
781 fprintf( outfile, "\tmovl %%esi,%d(%%ebp)\n", CONTEXTOFFSET(Esi) - STACK_SPACE );
782 fprintf( outfile, "\tmovl %%edi,%d(%%ebp)\n", CONTEXTOFFSET(Edi) - STACK_SPACE );
784 fprintf( outfile, "\txorl %%eax,%%eax\n" );
785 fprintf( outfile, "\tmovw %%cs,%%ax\n" );
786 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegCs) - STACK_SPACE );
787 fprintf( outfile, "\tmovw %%es,%%ax\n" );
788 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegEs) - STACK_SPACE );
789 fprintf( outfile, "\tmovw %%fs,%%ax\n" );
790 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegFs) - STACK_SPACE );
791 fprintf( outfile, "\tmovw %%gs,%%ax\n" );
792 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegGs) - STACK_SPACE );
793 fprintf( outfile, "\tmovw %%ss,%%ax\n" );
794 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegSs) - STACK_SPACE );
795 fprintf( outfile, "\tmovw %%ds,%%ax\n" );
796 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegDs) - STACK_SPACE );
797 fprintf( outfile, "\tmovw %%ax,%%es\n" ); /* set %es equal to %ds just in case */
799 fprintf( outfile, "\tmovl $0x%x,%%eax\n", CONTEXT86_FULL );
800 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(ContextFlags) - STACK_SPACE );
802 fprintf( outfile, "\tmovl 12(%%ebp),%%eax\n" ); /* Get %eip at time of call */
803 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eip) - STACK_SPACE );
805 /* Transfer the arguments */
807 fprintf( outfile, "\tmovl 4(%%ebp),%%ebx\n" ); /* get relay code addr */
808 fprintf( outfile, "\tpushl %%esp\n" ); /* push ptr to context struct */
809 fprintf( outfile, "\tmovzbl 4(%%ebx),%%ecx\n" ); /* fetch number of args to copy */
810 fprintf( outfile, "\tjecxz 1f\n" );
811 fprintf( outfile, "\tsubl %%ecx,%%esp\n" );
812 fprintf( outfile, "\tleal 16(%%ebp),%%esi\n" ); /* get %esp at time of call */
813 fprintf( outfile, "\tmovl %%esp,%%edi\n" );
814 fprintf( outfile, "\tshrl $2,%%ecx\n" );
815 fprintf( outfile, "\tcld\n" );
816 fprintf( outfile, "\trep\n\tmovsl\n" ); /* copy args */
818 fprintf( outfile, "1:\tmovzbl 5(%%ebx),%%eax\n" ); /* fetch number of args to remove */
819 fprintf( outfile, "\tleal 16(%%ebp,%%eax),%%eax\n" );
820 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Esp) - STACK_SPACE );
822 /* Call the entry point */
824 fprintf( outfile, "\taddl (%%ebx),%%ebx\n" );
825 fprintf( outfile, "\tcall *%%ebx\n" );
826 fprintf( outfile, "\tleal -%d(%%ebp),%%ecx\n", STACK_SPACE );
828 /* Restore the context structure */
830 fprintf( outfile, "2:\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegEs) );
831 fprintf( outfile, "\tpopl %%es\n" );
832 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegFs) );
833 fprintf( outfile, "\tpopl %%fs\n" );
834 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegGs) );
835 fprintf( outfile, "\tpopl %%gs\n" );
837 fprintf( outfile, "\tmovl %d(%%ecx),%%edi\n", CONTEXTOFFSET(Edi) );
838 fprintf( outfile, "\tmovl %d(%%ecx),%%esi\n", CONTEXTOFFSET(Esi) );
839 fprintf( outfile, "\tmovl %d(%%ecx),%%edx\n", CONTEXTOFFSET(Edx) );
840 fprintf( outfile, "\tmovl %d(%%ecx),%%ebx\n", CONTEXTOFFSET(Ebx) );
841 fprintf( outfile, "\tmovl %d(%%ecx),%%eax\n", CONTEXTOFFSET(Eax) );
842 fprintf( outfile, "\tmovl %d(%%ecx),%%ebp\n", CONTEXTOFFSET(Ebp) );
844 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegSs) );
845 fprintf( outfile, "\tpopl %%ss\n" );
846 fprintf( outfile, "\tmovl %d(%%ecx),%%esp\n", CONTEXTOFFSET(Esp) );
848 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(EFlags) );
849 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegCs) );
850 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(Eip) );
851 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegDs) );
852 fprintf( outfile, "\tmovl %d(%%ecx),%%ecx\n", CONTEXTOFFSET(Ecx) );
854 fprintf( outfile, "\tpopl %%ds\n" );
855 fprintf( outfile, "\tiret\n" );
856 function_footer( outfile, "__wine_call_from_32_regs" );
858 function_header( outfile, "__wine_call_from_32_restore_regs" );
859 fprintf( outfile, "\tleal 4(%%esp),%%ecx\n" );
860 fprintf( outfile, "\tjmp 2b\n" );
861 function_footer( outfile, "__wine_call_from_32_restore_regs" );
865 /*******************************************************************
866 * BuildPendingEventCheck
868 * Build a function that checks whether there are any
869 * pending DPMI events.
873 * (sp+12) long eflags
878 * On entry to function, fs register points to a valid TEB.
879 * On exit from function, stack will be popped.
881 static void BuildPendingEventCheck( FILE *outfile )
883 /* Function header */
885 function_header( outfile, "DPMI_PendingEventCheck" );
887 /* Check for pending events. */
889 fprintf( outfile, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
890 STRUCTOFFSET(TEB,vm86_pending) );
891 fprintf( outfile, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
893 fprintf( outfile, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
894 STRUCTOFFSET(TEB,dpmi_vif) );
896 fprintf( outfile, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
898 /* Process pending events. */
900 fprintf( outfile, "\tsti\n" );
902 /* Start cleanup. Restore fs register. */
904 fprintf( outfile, "%s\n", asm_globl("DPMI_PendingEventCheck_Cleanup") );
905 fprintf( outfile, "\tpopw %%fs\n" );
907 /* Return from function. */
909 fprintf( outfile, "%s\n", asm_globl("DPMI_PendingEventCheck_Return") );
910 fprintf( outfile, "\tiret\n" );
912 function_footer( outfile, "DPMI_PendingEventCheck" );
916 /*******************************************************************
919 * Build all the 16-bit relay callbacks
921 void BuildRelays16( FILE *outfile )
923 if (target_cpu != CPU_x86)
925 fprintf( outfile, "/* File not used with this architecture. Do not edit! */\n\n" );
931 fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
932 fprintf( outfile, "\t.text\n" );
934 fprintf( outfile, "%s:\n\n", asm_name("__wine_spec_thunk_text_16") );
936 fprintf( outfile, "%s\n", asm_globl("__wine_call16_start") );
938 /* Standard CallFrom16 routine (WORD return) */
939 BuildCallFrom16Core( outfile, FALSE, FALSE, TRUE );
941 /* Standard CallFrom16 routine (DWORD return) */
942 BuildCallFrom16Core( outfile, FALSE, FALSE, FALSE );
944 /* Register CallFrom16 routine */
945 BuildCallFrom16Core( outfile, TRUE, FALSE, FALSE );
947 /* C16ThkSL CallFrom16 routine */
948 BuildCallFrom16Core( outfile, FALSE, TRUE, FALSE );
950 /* Standard CallTo16 routine */
951 BuildCallTo16Core( outfile, 0 );
953 /* Register CallTo16 routine */
954 BuildCallTo16Core( outfile, 1 );
956 /* Standard CallTo16 return stub */
957 BuildRet16Func( outfile );
959 /* CBClientThunkSL routine */
960 BuildCallTo32CBClient( outfile, FALSE );
962 /* CBClientThunkSLEx routine */
963 BuildCallTo32CBClient( outfile, TRUE );
965 /* Pending DPMI events check stub */
966 BuildPendingEventCheck( outfile );
968 fprintf( outfile, "%s\n", asm_globl("__wine_call16_end") );
969 function_footer( outfile, "__wine_spec_thunk_text_16" );
971 /* Declare the return address and data selector variables */
972 fprintf( outfile, "\n\t.data\n\t.align %d\n", get_alignment(4) );
973 fprintf( outfile, "%s\n\t.long 0\n", asm_globl("CallTo16_DataSelector") );
974 fprintf( outfile, "%s\n\t.long 0\n", asm_globl("CallTo16_TebSelector") );
975 if (UsePIC) fprintf( outfile, "wine_ldt_copy_ptr:\t.long %s\n", asm_name("wine_ldt_copy") );
978 /*******************************************************************
981 * Build all the 32-bit relay callbacks
983 void BuildRelays32( FILE *outfile )
985 if (target_cpu != CPU_x86)
987 fprintf( outfile, "/* File not used with this architecture. Do not edit! */\n\n" );
993 fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
994 fprintf( outfile, "\t.text\n" );
995 fprintf( outfile, "%s:\n\n", asm_name("__wine_spec_thunk_text_32") );
997 /* 32-bit register entry point */
998 BuildCallFrom32Regs( outfile );
1000 function_footer( outfile, "__wine_spec_thunk_text_32" );