Use correct notification for drive selection change.
[wine/multimedia.git] / tools / winebuild / relay.c
blob92061f999c302f30bfd780ae6893c0ac03440ec3
1 /*
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
25 #include "config.h"
26 #include "wine/port.h"
28 #include <ctype.h>
30 #include "thread.h"
31 #include "wine/winbase16.h"
33 #include "build.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 inline const char *data16_prefix(void)
45 return (target_platform == PLATFORM_SVR4) ? "\tdata16\n" : "";
48 /*******************************************************************
49 * BuildCallFrom16Core
51 * This routine builds the core routines used in 16->32 thunks:
52 * CallFrom16Word, CallFrom16Long, CallFrom16Register, and CallFrom16Thunk.
54 * These routines are intended to be called via a far call (with 32-bit
55 * operand size) from 16-bit code. The 16-bit code stub must push %bp,
56 * the 32-bit entry point to be called, and the argument conversion
57 * routine to be used (see stack layout below).
59 * The core routine completes the STACK16FRAME on the 16-bit stack and
60 * switches to the 32-bit stack. Then, the argument conversion routine
61 * is called; it gets passed the 32-bit entry point and a pointer to the
62 * 16-bit arguments (on the 16-bit stack) as parameters. (You can either
63 * use conversion routines automatically generated by BuildCallFrom16,
64 * or write your own for special purposes.)
66 * The conversion routine must call the 32-bit entry point, passing it
67 * the converted arguments, and return its return value to the core.
68 * After the conversion routine has returned, the core switches back
69 * to the 16-bit stack, converts the return value to the DX:AX format
70 * (CallFrom16Long), and returns to the 16-bit call stub. All parameters,
71 * including %bp, are popped off the stack.
73 * The 16-bit call stub now returns to the caller, popping the 16-bit
74 * arguments if necessary (pascal calling convention).
76 * In the case of a 'register' function, CallFrom16Register fills a
77 * CONTEXT86 structure with the values all registers had at the point
78 * the first instruction of the 16-bit call stub was about to be
79 * executed. A pointer to this CONTEXT86 is passed as third parameter
80 * to the argument conversion routine, which typically passes it on
81 * to the called 32-bit entry point.
83 * CallFrom16Thunk is a special variant used by the implementation of
84 * the Win95 16->32 thunk functions C16ThkSL and C16ThkSL01 and is
85 * implemented as follows:
86 * On entry, the EBX register is set up to contain a flat pointer to the
87 * 16-bit stack such that EBX+22 points to the first argument.
88 * Then, the entry point is called, while EBP is set up to point
89 * to the return address (on the 32-bit stack).
90 * The called function returns with CX set to the number of bytes
91 * to be popped of the caller's stack.
93 * Stack layout upon entry to the core routine (STACK16FRAME):
94 * ... ...
95 * (sp+24) word first 16-bit arg
96 * (sp+22) word cs
97 * (sp+20) word ip
98 * (sp+18) word bp
99 * (sp+14) long 32-bit entry point (reused for Win16 mutex recursion count)
100 * (sp+12) word ip of actual entry point (necessary for relay debugging)
101 * (sp+8) long relay (argument conversion) function entry point
102 * (sp+4) long cs of 16-bit entry point
103 * (sp) long ip of 16-bit entry point
105 * Added on the stack:
106 * (sp-2) word saved gs
107 * (sp-4) word saved fs
108 * (sp-6) word saved es
109 * (sp-8) word saved ds
110 * (sp-12) long saved ebp
111 * (sp-16) long saved ecx
112 * (sp-20) long saved edx
113 * (sp-24) long saved previous stack
115 static void BuildCallFrom16Core( FILE *outfile, int reg_func, int thunk )
117 /* Function header */
118 if (thunk) function_header( outfile, "__wine_call_from_16_thunk" );
119 else if (reg_func) function_header( outfile, "__wine_call_from_16_regs" );
120 else function_header( outfile, "__wine_call_from_16" );
122 /* Create STACK16FRAME (except STACK32FRAME link) */
123 fprintf( outfile, "\tpushw %%gs\n" );
124 fprintf( outfile, "\tpushw %%fs\n" );
125 fprintf( outfile, "\tpushw %%es\n" );
126 fprintf( outfile, "\tpushw %%ds\n" );
127 fprintf( outfile, "\tpushl %%ebp\n" );
128 fprintf( outfile, "\tpushl %%ecx\n" );
129 fprintf( outfile, "\tpushl %%edx\n" );
131 /* Save original EFlags register */
132 if (reg_func) fprintf( outfile, "\tpushfl\n" );
134 if ( UsePIC )
136 fprintf( outfile, "\tcall 1f\n" );
137 fprintf( outfile, "1:\tpopl %%ecx\n" );
138 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s-1b(%%ecx),%%edx\n",
139 asm_name("CallTo16_DataSelector") );
141 else
142 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s,%%edx\n", asm_name("CallTo16_DataSelector") );
144 /* Load 32-bit segment registers */
145 fprintf( outfile, "%s\tmovw %%dx, %%ds\n", data16_prefix() );
146 fprintf( outfile, "%s\tmovw %%dx, %%es\n", data16_prefix() );
148 if ( UsePIC )
149 fprintf( outfile, "\tmovw %s-1b(%%ecx), %%fs\n", asm_name("CallTo16_TebSelector") );
150 else
151 fprintf( outfile, "\tmovw %s, %%fs\n", asm_name("CallTo16_TebSelector") );
153 fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n", STRUCTOFFSET(TEB,gs_sel) );
155 /* Translate STACK16FRAME base to flat offset in %edx */
156 fprintf( outfile, "\tmovw %%ss, %%dx\n" );
157 fprintf( outfile, "\tandl $0xfff8, %%edx\n" );
158 fprintf( outfile, "\tshrl $1, %%edx\n" );
159 if (UsePIC)
161 fprintf( outfile, "\taddl wine_ldt_copy_ptr-1b(%%ecx),%%edx\n" );
162 fprintf( outfile, "\tmovl (%%edx), %%edx\n" );
164 else
165 fprintf( outfile, "\tmovl %s(%%edx), %%edx\n", asm_name("wine_ldt_copy") );
166 fprintf( outfile, "\tmovzwl %%sp, %%ebp\n" );
167 fprintf( outfile, "\tleal %d(%%ebp,%%edx), %%edx\n", reg_func ? 0 : -4 );
169 /* Get saved flags into %ecx */
170 if (reg_func) fprintf( outfile, "\tpopl %%ecx\n" );
172 /* Get the 32-bit stack pointer from the TEB and complete STACK16FRAME */
173 fprintf( outfile, "\t.byte 0x64\n\tmovl (%d), %%ebp\n", STACKOFFSET );
174 fprintf( outfile, "\tpushl %%ebp\n" );
176 /* Switch stacks */
177 fprintf( outfile, "%s\t.byte 0x64\n\tmovw %%ss, (%d)\n", data16_prefix(), STACKOFFSET + 2 );
178 fprintf( outfile, "\t.byte 0x64\n\tmovw %%sp, (%d)\n", STACKOFFSET );
179 fprintf( outfile, "\tpushl %%ds\n" );
180 fprintf( outfile, "\tpopl %%ss\n" );
181 fprintf( outfile, "\tmovl %%ebp, %%esp\n" );
182 fprintf( outfile, "\taddl $%d, %%ebp\n", STRUCTOFFSET(STACK32FRAME, ebp) );
185 /* At this point:
186 STACK16FRAME is completely set up
187 DS, ES, SS: flat data segment
188 FS: current TEB
189 ESP: points to last STACK32FRAME
190 EBP: points to ebp member of last STACK32FRAME
191 EDX: points to current STACK16FRAME
192 ECX: contains saved flags
193 all other registers: unchanged */
195 /* Special case: C16ThkSL stub */
196 if ( thunk )
198 /* Set up registers as expected and call thunk */
199 fprintf( outfile, "\tleal %d(%%edx), %%ebx\n", sizeof(STACK16FRAME)-22 );
200 fprintf( outfile, "\tleal -4(%%esp), %%ebp\n" );
202 fprintf( outfile, "\tcall *%d(%%edx)\n", STACK16OFFSET(entry_point) );
204 /* Switch stack back */
205 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
206 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
207 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
209 /* Restore registers and return directly to caller */
210 fprintf( outfile, "\taddl $8, %%esp\n" );
211 fprintf( outfile, "\tpopl %%ebp\n" );
212 fprintf( outfile, "\tpopw %%ds\n" );
213 fprintf( outfile, "\tpopw %%es\n" );
214 fprintf( outfile, "\tpopw %%fs\n" );
215 fprintf( outfile, "\tpopw %%gs\n" );
216 fprintf( outfile, "\taddl $20, %%esp\n" );
218 fprintf( outfile, "\txorb %%ch, %%ch\n" );
219 fprintf( outfile, "\tpopl %%ebx\n" );
220 fprintf( outfile, "\taddw %%cx, %%sp\n" );
221 fprintf( outfile, "\tpush %%ebx\n" );
223 fprintf( outfile, "\t.byte 0x66\n" );
224 fprintf( outfile, "\tlret\n" );
226 return;
230 /* Build register CONTEXT */
231 if ( reg_func )
233 fprintf( outfile, "\tsubl $%d, %%esp\n", sizeof(CONTEXT86) );
235 fprintf( outfile, "\tmovl %%ecx, %d(%%esp)\n", CONTEXTOFFSET(EFlags) );
237 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eax) );
238 fprintf( outfile, "\tmovl %%ebx, %d(%%esp)\n", CONTEXTOFFSET(Ebx) );
239 fprintf( outfile, "\tmovl %%esi, %d(%%esp)\n", CONTEXTOFFSET(Esi) );
240 fprintf( outfile, "\tmovl %%edi, %d(%%esp)\n", CONTEXTOFFSET(Edi) );
242 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ebp) );
243 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ebp) );
244 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ecx) );
245 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ecx) );
246 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(edx) );
247 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Edx) );
249 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ds) );
250 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegDs) );
251 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(es) );
252 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegEs) );
253 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(fs) );
254 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegFs) );
255 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(gs) );
256 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegGs) );
258 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(cs) );
259 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegCs) );
260 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ip) );
261 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eip) );
263 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET+2 );
264 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegSs) );
265 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET );
266 fprintf( outfile, "\taddl $%d, %%eax\n", STACK16OFFSET(ip) );
267 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Esp) );
268 #if 0
269 fprintf( outfile, "\tfsave %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
270 #endif
272 /* Push address of CONTEXT86 structure -- popped by the relay routine */
273 fprintf( outfile, "\tpushl %%esp\n" );
276 /* Call relay routine (which will call the API entry point) */
277 fprintf( outfile, "\tleal %d(%%edx), %%eax\n", sizeof(STACK16FRAME) );
278 fprintf( outfile, "\tpushl %%eax\n" );
279 fprintf( outfile, "\tpushl %d(%%edx)\n", STACK16OFFSET(entry_point) );
280 fprintf( outfile, "\tcall *%d(%%edx)\n", STACK16OFFSET(relay) );
282 if ( reg_func )
284 fprintf( outfile, "\tleal -%d(%%ebp), %%ebx\n",
285 sizeof(CONTEXT) + STRUCTOFFSET(STACK32FRAME, ebp) );
287 /* Switch stack back */
288 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
289 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
290 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
292 /* Get return address to CallFrom16 stub */
293 fprintf( outfile, "\taddw $%d, %%sp\n", STACK16OFFSET(callfrom_ip)-4 );
294 fprintf( outfile, "\tpopl %%eax\n" );
295 fprintf( outfile, "\tpopl %%edx\n" );
297 /* Restore all registers from CONTEXT */
298 fprintf( outfile, "\tmovw %d(%%ebx), %%ss\n", CONTEXTOFFSET(SegSs) );
299 fprintf( outfile, "\tmovl %d(%%ebx), %%esp\n", CONTEXTOFFSET(Esp) );
300 fprintf( outfile, "\taddl $4, %%esp\n" ); /* room for final return address */
302 fprintf( outfile, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(SegCs) );
303 fprintf( outfile, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(Eip) );
304 fprintf( outfile, "\tpushl %%edx\n" );
305 fprintf( outfile, "\tpushl %%eax\n" );
306 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(EFlags) );
307 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegDs) );
309 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegEs) );
310 fprintf( outfile, "\tpopl %%es\n" );
311 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegFs) );
312 fprintf( outfile, "\tpopl %%fs\n" );
313 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegGs) );
314 fprintf( outfile, "\tpopl %%gs\n" );
316 fprintf( outfile, "\tmovl %d(%%ebx), %%ebp\n", CONTEXTOFFSET(Ebp) );
317 fprintf( outfile, "\tmovl %d(%%ebx), %%esi\n", CONTEXTOFFSET(Esi) );
318 fprintf( outfile, "\tmovl %d(%%ebx), %%edi\n", CONTEXTOFFSET(Edi) );
319 fprintf( outfile, "\tmovl %d(%%ebx), %%eax\n", CONTEXTOFFSET(Eax) );
320 fprintf( outfile, "\tmovl %d(%%ebx), %%edx\n", CONTEXTOFFSET(Edx) );
321 fprintf( outfile, "\tmovl %d(%%ebx), %%ecx\n", CONTEXTOFFSET(Ecx) );
322 fprintf( outfile, "\tmovl %d(%%ebx), %%ebx\n", CONTEXTOFFSET(Ebx) );
324 fprintf( outfile, "\tpopl %%ds\n" );
325 fprintf( outfile, "\tpopfl\n" );
326 fprintf( outfile, "\tlret\n" );
328 else
330 /* Switch stack back */
331 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
332 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
333 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
335 /* Restore registers */
336 fprintf( outfile, "\tpopl %%edx\n" );
337 fprintf( outfile, "\tpopl %%ecx\n" );
338 fprintf( outfile, "\tpopl %%ebp\n" );
339 fprintf( outfile, "\tpopw %%ds\n" );
340 fprintf( outfile, "\tpopw %%es\n" );
341 fprintf( outfile, "\tpopw %%fs\n" );
342 fprintf( outfile, "\tpopw %%gs\n" );
344 /* Return to return stub which will return to caller */
345 fprintf( outfile, "\tlret $12\n" );
347 if (thunk) output_function_size( outfile, "__wine_call_from_16_thunk" );
348 else if (reg_func) output_function_size( outfile, "__wine_call_from_16_regs" );
349 else output_function_size( outfile, "__wine_call_from_16" );
353 /*******************************************************************
354 * BuildCallTo16Core
356 * This routine builds the core routines used in 32->16 thunks:
358 * extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
359 * extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
361 * These routines can be called directly from 32-bit code.
363 * All routines expect that the 16-bit stack contents (arguments) and the
364 * return address (segptr to CallTo16_Ret) were already set up by the
365 * caller; nb_args must contain the number of bytes to be conserved. The
366 * 16-bit SS:SP will be set accordinly.
368 * All other registers are either taken from the CONTEXT86 structure
369 * or else set to default values. The target routine address is either
370 * given directly or taken from the CONTEXT86.
372 static void BuildCallTo16Core( FILE *outfile, int reg_func )
374 const char *name = reg_func ? "wine_call_to_16_regs" : "wine_call_to_16";
376 /* Function header */
377 function_header( outfile, name );
379 /* Function entry sequence */
380 fprintf( outfile, "\tpushl %%ebp\n" );
381 fprintf( outfile, "\tmovl %%esp, %%ebp\n" );
383 /* Save the 32-bit registers */
384 fprintf( outfile, "\tpushl %%ebx\n" );
385 fprintf( outfile, "\tpushl %%esi\n" );
386 fprintf( outfile, "\tpushl %%edi\n" );
387 fprintf( outfile, "\t.byte 0x64\n\tmov %%gs,(%d)\n", STRUCTOFFSET(TEB,gs_sel) );
389 /* Setup exception frame */
390 fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STACKOFFSET );
391 fprintf( outfile, "\tpushl 16(%%ebp)\n" ); /* handler */
392 fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
393 fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
395 /* Call the actual CallTo16 routine (simulate a lcall) */
396 fprintf( outfile, "\tpushl %%cs\n" );
397 fprintf( outfile, "\tcall .L%s\n", name );
399 /* Remove exception frame */
400 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
401 fprintf( outfile, "\taddl $4, %%esp\n" );
402 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
404 if ( !reg_func )
406 /* Convert return value */
407 fprintf( outfile, "\tandl $0xffff,%%eax\n" );
408 fprintf( outfile, "\tshll $16,%%edx\n" );
409 fprintf( outfile, "\torl %%edx,%%eax\n" );
411 else
414 * Modify CONTEXT86 structure to contain new values
416 * NOTE: We restore only EAX, EBX, EDX, EDX, EBP, and ESP.
417 * The segment registers as well as ESI and EDI should
418 * not be modified by a well-behaved 16-bit routine in
419 * any case. [If necessary, we could restore them as well,
420 * at the cost of a somewhat less efficient return path.]
423 fprintf( outfile, "\tmovl %d(%%esp), %%edi\n", STACK32OFFSET(target) - STACK32OFFSET(edi));
424 /* everything above edi has been popped already */
426 fprintf( outfile, "\tmovl %%eax, %d(%%edi)\n", CONTEXTOFFSET(Eax) );
427 fprintf( outfile, "\tmovl %%ebx, %d(%%edi)\n", CONTEXTOFFSET(Ebx) );
428 fprintf( outfile, "\tmovl %%ecx, %d(%%edi)\n", CONTEXTOFFSET(Ecx) );
429 fprintf( outfile, "\tmovl %%edx, %d(%%edi)\n", CONTEXTOFFSET(Edx) );
430 fprintf( outfile, "\tmovl %%ebp, %d(%%edi)\n", CONTEXTOFFSET(Ebp) );
431 fprintf( outfile, "\tmovl %%esi, %d(%%edi)\n", CONTEXTOFFSET(Esp) );
432 /* The return glue code saved %esp into %esi */
435 /* Restore the 32-bit registers */
436 fprintf( outfile, "\tpopl %%edi\n" );
437 fprintf( outfile, "\tpopl %%esi\n" );
438 fprintf( outfile, "\tpopl %%ebx\n" );
440 /* Function exit sequence */
441 fprintf( outfile, "\tpopl %%ebp\n" );
442 fprintf( outfile, "\tret $12\n" );
445 /* Start of the actual CallTo16 routine */
447 fprintf( outfile, ".L%s:\n", name );
449 /* Switch to the 16-bit stack */
450 fprintf( outfile, "\tmovl %%esp,%%edx\n" );
451 fprintf( outfile, "%s\t.byte 0x64\n\tmovw (%d),%%ss\n", data16_prefix(), STACKOFFSET + 2);
452 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d),%%sp\n", STACKOFFSET );
453 fprintf( outfile, "\t.byte 0x64\n\tmovl %%edx,(%d)\n", STACKOFFSET );
455 /* Make %bp point to the previous stackframe (built by CallFrom16) */
456 fprintf( outfile, "\tmovzwl %%sp,%%ebp\n" );
457 fprintf( outfile, "\tleal %d(%%ebp),%%ebp\n", STACK16OFFSET(bp) );
459 /* Add the specified offset to the new sp */
460 fprintf( outfile, "\tsubw %d(%%edx), %%sp\n", STACK32OFFSET(nb_args) );
462 if (reg_func)
464 /* Push the called routine address */
465 fprintf( outfile, "\tmovl %d(%%edx),%%edx\n", STACK32OFFSET(target) );
466 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegCs) );
467 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(Eip) );
469 /* Get the registers */
470 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegDs) );
471 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegEs) );
472 fprintf( outfile, "\tpopl %%es\n" );
473 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegFs) );
474 fprintf( outfile, "\tpopl %%fs\n" );
475 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegGs) );
476 fprintf( outfile, "\tpopl %%gs\n" );
477 fprintf( outfile, "\tmovl %d(%%edx),%%ebp\n", CONTEXTOFFSET(Ebp) );
478 fprintf( outfile, "\tmovl %d(%%edx),%%esi\n", CONTEXTOFFSET(Esi) );
479 fprintf( outfile, "\tmovl %d(%%edx),%%edi\n", CONTEXTOFFSET(Edi) );
480 fprintf( outfile, "\tmovl %d(%%edx),%%eax\n", CONTEXTOFFSET(Eax) );
481 fprintf( outfile, "\tmovl %d(%%edx),%%ebx\n", CONTEXTOFFSET(Ebx) );
482 fprintf( outfile, "\tmovl %d(%%edx),%%ecx\n", CONTEXTOFFSET(Ecx) );
483 fprintf( outfile, "\tmovl %d(%%edx),%%edx\n", CONTEXTOFFSET(Edx) );
485 /* Get the 16-bit ds */
486 fprintf( outfile, "\tpopw %%ds\n" );
488 else /* not a register function */
490 /* Push the called routine address */
491 fprintf( outfile, "\tpushl %d(%%edx)\n", STACK32OFFSET(target) );
493 /* Set %fs and %gs to the value saved by the last CallFrom16 */
494 fprintf( outfile, "\tpushw %d(%%ebp)\n", STACK16OFFSET(fs)-STACK16OFFSET(bp) );
495 fprintf( outfile, "\tpopw %%fs\n" );
496 fprintf( outfile, "\tpushw %d(%%ebp)\n", STACK16OFFSET(gs)-STACK16OFFSET(bp) );
497 fprintf( outfile, "\tpopw %%gs\n" );
499 /* Set %ds and %es (and %ax just in case) equal to %ss */
500 fprintf( outfile, "\tmovw %%ss,%%ax\n" );
501 fprintf( outfile, "\tmovw %%ax,%%ds\n" );
502 fprintf( outfile, "\tmovw %%ax,%%es\n" );
505 /* Jump to the called routine */
506 fprintf( outfile, "\t.byte 0x66\n" );
507 fprintf( outfile, "\tlret\n" );
509 /* Function footer */
510 output_function_size( outfile, name );
514 /*******************************************************************
515 * BuildRet16Func
517 * Build the return code for 16-bit callbacks
519 static void BuildRet16Func( FILE *outfile )
521 function_header( outfile, "__wine_call_to_16_ret" );
523 /* Save %esp into %esi */
524 fprintf( outfile, "\tmovl %%esp,%%esi\n" );
526 /* Restore 32-bit segment registers */
528 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s", asm_name("CallTo16_DataSelector") );
529 fprintf( outfile, "-%s,%%edi\n", asm_name("__wine_call16_start") );
530 fprintf( outfile, "%s\tmovw %%di,%%ds\n", data16_prefix() );
531 fprintf( outfile, "%s\tmovw %%di,%%es\n", data16_prefix() );
533 fprintf( outfile, "\t.byte 0x2e\n\tmov %s", asm_name("CallTo16_TebSelector") );
534 fprintf( outfile, "-%s,%%fs\n", asm_name("__wine_call16_start") );
536 fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n", STRUCTOFFSET(TEB,gs_sel) );
538 /* Restore the 32-bit stack */
540 fprintf( outfile, "%s\tmovw %%di,%%ss\n", data16_prefix() );
541 fprintf( outfile, "\t.byte 0x64\n\tmovl (%d),%%esp\n", STACKOFFSET );
543 /* Return to caller */
545 fprintf( outfile, "\tlret\n" );
546 output_function_size( outfile, "__wine_call_to_16_ret" );
550 /*******************************************************************
551 * BuildCallTo32CBClient
553 * Call a CBClient relay stub from 32-bit code (KERNEL.620).
555 * Since the relay stub is itself 32-bit, this should not be a problem;
556 * unfortunately, the relay stubs are expected to switch back to a
557 * 16-bit stack (and 16-bit code) after completion :-(
559 * This would conflict with our 16- vs. 32-bit stack handling, so
560 * we simply switch *back* to our 32-bit stack before returning to
561 * the caller ...
563 * The CBClient relay stub expects to be called with the following
564 * 16-bit stack layout, and with ebp and ebx pointing into the 16-bit
565 * stack at the designated places:
567 * ...
568 * (ebp+14) original arguments to the callback routine
569 * (ebp+10) far return address to original caller
570 * (ebp+6) Thunklet target address
571 * (ebp+2) Thunklet relay ID code
572 * (ebp) BP (saved by CBClientGlueSL)
573 * (ebp-2) SI (saved by CBClientGlueSL)
574 * (ebp-4) DI (saved by CBClientGlueSL)
575 * (ebp-6) DS (saved by CBClientGlueSL)
577 * ... buffer space used by the 16-bit side glue for temp copies
579 * (ebx+4) far return address to 16-bit side glue code
580 * (ebx) saved 16-bit ss:sp (pointing to ebx+4)
582 * The 32-bit side glue code accesses both the original arguments (via ebp)
583 * and the temporary copies prepared by the 16-bit side glue (via ebx).
584 * After completion, the stub will load ss:sp from the buffer at ebx
585 * and perform a far return to 16-bit code.
587 * To trick the relay stub into returning to us, we replace the 16-bit
588 * return address to the glue code by a cs:ip pair pointing to our
589 * return entry point (the original return address is saved first).
590 * Our return stub thus called will then reload the 32-bit ss:esp and
591 * return to 32-bit code (by using and ss:esp value that we have also
592 * pushed onto the 16-bit stack before and a cs:eip values found at
593 * that position on the 32-bit stack). The ss:esp to be restored is
594 * found relative to the 16-bit stack pointer at:
596 * (ebx-4) ss (flat)
597 * (ebx-8) sp (32-bit stack pointer)
599 * The second variant of this routine, CALL32_CBClientEx, which is used
600 * to implement KERNEL.621, has to cope with yet another problem: Here,
601 * the 32-bit side directly returns to the caller of the CBClient thunklet,
602 * restoring registers saved by CBClientGlueSL and cleaning up the stack.
603 * As we have to return to our 32-bit code first, we have to adapt the
604 * layout of our temporary area so as to include values for the registers
605 * that are to be restored, and later (in the implementation of KERNEL.621)
606 * we *really* restore them. The return stub restores DS, DI, SI, and BP
607 * from the stack, skips the next 8 bytes (CBClient relay code / target),
608 * and then performs a lret NN, where NN is the number of arguments to be
609 * removed. Thus, we prepare our temporary area as follows:
611 * (ebx+22) 16-bit cs (this segment)
612 * (ebx+20) 16-bit ip ('16-bit' return entry point)
613 * (ebx+16) 32-bit ss (flat)
614 * (ebx+12) 32-bit sp (32-bit stack pointer)
615 * (ebx+10) 16-bit bp (points to ebx+24)
616 * (ebx+8) 16-bit si (ignored)
617 * (ebx+6) 16-bit di (ignored)
618 * (ebx+4) 16-bit ds (we actually use the flat DS here)
619 * (ebx+2) 16-bit ss (16-bit stack segment)
620 * (ebx+0) 16-bit sp (points to ebx+4)
622 * Note that we ensure that DS is not changed and remains the flat segment,
623 * and the 32-bit stack pointer our own return stub needs fits just
624 * perfectly into the 8 bytes that are skipped by the Windows stub.
625 * One problem is that we have to determine the number of removed arguments,
626 * as these have to be really removed in KERNEL.621. Thus, the BP value
627 * that we place in the temporary area to be restored, contains the value
628 * that SP would have if no arguments were removed. By comparing the actual
629 * value of SP with this value in our return stub we can compute the number
630 * of removed arguments. This is then returned to KERNEL.621.
632 * The stack layout of this function:
633 * (ebp+20) nArgs pointer to variable receiving nr. of args (Ex only)
634 * (ebp+16) esi pointer to caller's esi value
635 * (ebp+12) arg ebp value to be set for relay stub
636 * (ebp+8) func CBClient relay stub address
637 * (ebp+4) ret addr
638 * (ebp) ebp
640 static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx )
642 function_header( outfile, isEx ? "CALL32_CBClientEx" : "CALL32_CBClient" );
644 /* Entry code */
646 fprintf( outfile, "\tpushl %%ebp\n" );
647 fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
648 fprintf( outfile, "\tpushl %%edi\n" );
649 fprintf( outfile, "\tpushl %%esi\n" );
650 fprintf( outfile, "\tpushl %%ebx\n" );
652 /* Get pointer to temporary area and save the 32-bit stack pointer */
654 fprintf( outfile, "\tmovl 16(%%ebp), %%ebx\n" );
655 fprintf( outfile, "\tleal -8(%%esp), %%eax\n" );
657 if ( !isEx )
658 fprintf( outfile, "\tmovl %%eax, -8(%%ebx)\n" );
659 else
660 fprintf( outfile, "\tmovl %%eax, 12(%%ebx)\n" );
662 /* Set up registers and call CBClient relay stub (simulating a far call) */
664 fprintf( outfile, "\tmovl 20(%%ebp), %%esi\n" );
665 fprintf( outfile, "\tmovl (%%esi), %%esi\n" );
667 fprintf( outfile, "\tmovl 8(%%ebp), %%eax\n" );
668 fprintf( outfile, "\tmovl 12(%%ebp), %%ebp\n" );
670 fprintf( outfile, "\tpushl %%cs\n" );
671 fprintf( outfile, "\tcall *%%eax\n" );
673 /* Return new esi value to caller */
675 fprintf( outfile, "\tmovl 32(%%esp), %%edi\n" );
676 fprintf( outfile, "\tmovl %%esi, (%%edi)\n" );
678 /* Return argument size to caller */
679 if ( isEx )
681 fprintf( outfile, "\tmovl 36(%%esp), %%ebx\n" );
682 fprintf( outfile, "\tmovl %%ebp, (%%ebx)\n" );
685 /* Restore registers and return */
687 fprintf( outfile, "\tpopl %%ebx\n" );
688 fprintf( outfile, "\tpopl %%esi\n" );
689 fprintf( outfile, "\tpopl %%edi\n" );
690 fprintf( outfile, "\tpopl %%ebp\n" );
691 fprintf( outfile, "\tret\n" );
692 output_function_size( outfile, isEx ? "CALL32_CBClientEx" : "CALL32_CBClient" );
694 /* '16-bit' return stub */
696 function_header( outfile, isEx ? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
697 if ( !isEx )
699 fprintf( outfile, "\tmovzwl %%sp, %%ebx\n" );
700 fprintf( outfile, "\tlssl %%ss:-16(%%ebx), %%esp\n" );
702 else
704 fprintf( outfile, "\tmovzwl %%bp, %%ebx\n" );
705 fprintf( outfile, "\tsubw %%bp, %%sp\n" );
706 fprintf( outfile, "\tmovzwl %%sp, %%ebp\n" );
707 fprintf( outfile, "\tlssl %%ss:-12(%%ebx), %%esp\n" );
709 fprintf( outfile, "\tlret\n" );
710 output_function_size( outfile, isEx ? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
714 /*******************************************************************
715 * BuildCallFrom32Regs
717 * Build a 32-bit-to-Wine call-back function for a 'register' function.
718 * 'args' is the number of dword arguments.
720 * Stack layout:
721 * ...
722 * (ebp+16) first arg
723 * (ebp+12) ret addr to user code
724 * (ebp+8) eax saved by relay code
725 * (ebp+4) ret addr to relay code
726 * (ebp+0) saved ebp
727 * (ebp-128) buffer area to allow stack frame manipulation
728 * (ebp-332) CONTEXT86 struct
729 * (ebp-336) CONTEXT86 *argument
730 * .... other arguments copied from (ebp+12)
732 * The entry point routine is called with a CONTEXT* extra argument,
733 * following the normal args. In this context structure, EIP_reg
734 * contains the return address to user code, and ESP_reg the stack
735 * pointer on return (with the return address and arguments already
736 * removed).
738 static void BuildCallFrom32Regs( FILE *outfile )
740 static const int STACK_SPACE = 128 + sizeof(CONTEXT86);
742 /* Function header */
744 function_header( outfile, "__wine_call_from_32_regs" );
746 /* Allocate some buffer space on the stack */
748 fprintf( outfile, "\tpushl %%ebp\n" );
749 fprintf( outfile, "\tmovl %%esp,%%ebp\n ");
750 fprintf( outfile, "\tleal -%d(%%esp), %%esp\n", STACK_SPACE );
752 /* Build the context structure */
754 fprintf( outfile, "\tpushfl\n" );
755 fprintf( outfile, "\tpopl %%eax\n" );
756 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(EFlags) - STACK_SPACE );
757 fprintf( outfile, "\tmovl 0(%%ebp),%%eax\n" );
758 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Ebp) - STACK_SPACE );
759 fprintf( outfile, "\tmovl 8(%%ebp),%%eax\n" );
760 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eax) - STACK_SPACE );
761 fprintf( outfile, "\tmovl %%ebx,%d(%%ebp)\n", CONTEXTOFFSET(Ebx) - STACK_SPACE );
762 fprintf( outfile, "\tmovl %%ecx,%d(%%ebp)\n", CONTEXTOFFSET(Ecx) - STACK_SPACE );
763 fprintf( outfile, "\tmovl %%edx,%d(%%ebp)\n", CONTEXTOFFSET(Edx) - STACK_SPACE );
764 fprintf( outfile, "\tmovl %%esi,%d(%%ebp)\n", CONTEXTOFFSET(Esi) - STACK_SPACE );
765 fprintf( outfile, "\tmovl %%edi,%d(%%ebp)\n", CONTEXTOFFSET(Edi) - STACK_SPACE );
767 fprintf( outfile, "\txorl %%eax,%%eax\n" );
768 fprintf( outfile, "\tmovw %%cs,%%ax\n" );
769 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegCs) - STACK_SPACE );
770 fprintf( outfile, "\tmovw %%es,%%ax\n" );
771 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegEs) - STACK_SPACE );
772 fprintf( outfile, "\tmovw %%fs,%%ax\n" );
773 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegFs) - STACK_SPACE );
774 fprintf( outfile, "\tmovw %%gs,%%ax\n" );
775 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegGs) - STACK_SPACE );
776 fprintf( outfile, "\tmovw %%ss,%%ax\n" );
777 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegSs) - STACK_SPACE );
778 fprintf( outfile, "\tmovw %%ds,%%ax\n" );
779 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegDs) - STACK_SPACE );
780 fprintf( outfile, "\tmovw %%ax,%%es\n" ); /* set %es equal to %ds just in case */
782 fprintf( outfile, "\tmovl $0x%x,%%eax\n", CONTEXT86_FULL );
783 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(ContextFlags) - STACK_SPACE );
785 fprintf( outfile, "\tmovl 12(%%ebp),%%eax\n" ); /* Get %eip at time of call */
786 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eip) - STACK_SPACE );
788 /* Transfer the arguments */
790 fprintf( outfile, "\tmovl 4(%%ebp),%%ebx\n" ); /* get relay code addr */
791 fprintf( outfile, "\tpushl %%esp\n" ); /* push ptr to context struct */
792 fprintf( outfile, "\tmovzbl 4(%%ebx),%%ecx\n" ); /* fetch number of args to copy */
793 fprintf( outfile, "\tjecxz 1f\n" );
794 fprintf( outfile, "\tsubl %%ecx,%%esp\n" );
795 fprintf( outfile, "\tleal 16(%%ebp),%%esi\n" ); /* get %esp at time of call */
796 fprintf( outfile, "\tmovl %%esp,%%edi\n" );
797 fprintf( outfile, "\tshrl $2,%%ecx\n" );
798 fprintf( outfile, "\tcld\n" );
799 fprintf( outfile, "\trep\n\tmovsl\n" ); /* copy args */
801 fprintf( outfile, "1:\tmovzbl 5(%%ebx),%%eax\n" ); /* fetch number of args to remove */
802 fprintf( outfile, "\tleal 16(%%ebp,%%eax),%%eax\n" );
803 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Esp) - STACK_SPACE );
805 /* Call the entry point */
807 fprintf( outfile, "\taddl (%%ebx),%%ebx\n" );
808 fprintf( outfile, "\tcall *%%ebx\n" );
809 fprintf( outfile, "\tleal -%d(%%ebp),%%ecx\n", STACK_SPACE );
811 /* Restore the context structure */
813 fprintf( outfile, "2:\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegEs) );
814 fprintf( outfile, "\tpopl %%es\n" );
815 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegFs) );
816 fprintf( outfile, "\tpopl %%fs\n" );
817 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegGs) );
818 fprintf( outfile, "\tpopl %%gs\n" );
820 fprintf( outfile, "\tmovl %d(%%ecx),%%edi\n", CONTEXTOFFSET(Edi) );
821 fprintf( outfile, "\tmovl %d(%%ecx),%%esi\n", CONTEXTOFFSET(Esi) );
822 fprintf( outfile, "\tmovl %d(%%ecx),%%edx\n", CONTEXTOFFSET(Edx) );
823 fprintf( outfile, "\tmovl %d(%%ecx),%%ebx\n", CONTEXTOFFSET(Ebx) );
824 fprintf( outfile, "\tmovl %d(%%ecx),%%eax\n", CONTEXTOFFSET(Eax) );
825 fprintf( outfile, "\tmovl %d(%%ecx),%%ebp\n", CONTEXTOFFSET(Ebp) );
827 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegSs) );
828 fprintf( outfile, "\tpopl %%ss\n" );
829 fprintf( outfile, "\tmovl %d(%%ecx),%%esp\n", CONTEXTOFFSET(Esp) );
831 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(EFlags) );
832 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegCs) );
833 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(Eip) );
834 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegDs) );
835 fprintf( outfile, "\tmovl %d(%%ecx),%%ecx\n", CONTEXTOFFSET(Ecx) );
837 fprintf( outfile, "\tpopl %%ds\n" );
838 fprintf( outfile, "\tiret\n" );
839 output_function_size( outfile, "__wine_call_from_32_regs" );
841 function_header( outfile, "__wine_call_from_32_restore_regs" );
842 fprintf( outfile, "\tleal 4(%%esp),%%ecx\n" );
843 fprintf( outfile, "\tjmp 2b\n" );
844 output_function_size( outfile, "__wine_call_from_32_restore_regs" );
848 /*******************************************************************
849 * BuildPendingEventCheck
851 * Build a function that checks whether there are any
852 * pending DPMI events.
854 * Stack layout:
856 * (sp+12) long eflags
857 * (sp+6) long cs
858 * (sp+2) long ip
859 * (sp) word fs
861 * On entry to function, fs register points to a valid TEB.
862 * On exit from function, stack will be popped.
864 static void BuildPendingEventCheck( FILE *outfile )
866 /* Function header */
868 function_header( outfile, "DPMI_PendingEventCheck" );
870 /* Check for pending events. */
872 fprintf( outfile, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
873 STRUCTOFFSET(TEB,vm86_pending) );
874 fprintf( outfile, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
876 fprintf( outfile, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
877 STRUCTOFFSET(TEB,dpmi_vif) );
879 fprintf( outfile, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
881 /* Process pending events. */
883 fprintf( outfile, "\tsti\n" );
885 /* Start cleanup. Restore fs register. */
887 fprintf( outfile, "%s\n", asm_globl("DPMI_PendingEventCheck_Cleanup") );
888 fprintf( outfile, "\tpopw %%fs\n" );
890 /* Return from function. */
892 fprintf( outfile, "%s\n", asm_globl("DPMI_PendingEventCheck_Return") );
893 fprintf( outfile, "\tiret\n" );
895 output_function_size( outfile, "DPMI_PendingEventCheck" );
899 /*******************************************************************
900 * BuildRelays16
902 * Build all the 16-bit relay callbacks
904 void BuildRelays16( FILE *outfile )
906 if (target_cpu != CPU_x86)
908 fprintf( outfile, "/* File not used with this architecture. Do not edit! */\n\n" );
909 return;
912 /* File header */
914 fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
915 fprintf( outfile, "\t.text\n" );
917 fprintf( outfile, "%s:\n\n", asm_name("__wine_spec_thunk_text_16") );
919 fprintf( outfile, "%s\n", asm_globl("__wine_call16_start") );
921 /* Standard CallFrom16 routine */
922 BuildCallFrom16Core( outfile, FALSE, FALSE );
924 /* Register CallFrom16 routine */
925 BuildCallFrom16Core( outfile, TRUE, FALSE );
927 /* C16ThkSL CallFrom16 routine */
928 BuildCallFrom16Core( outfile, FALSE, TRUE );
930 /* Standard CallTo16 routine */
931 BuildCallTo16Core( outfile, 0 );
933 /* Register CallTo16 routine */
934 BuildCallTo16Core( outfile, 1 );
936 /* Standard CallTo16 return stub */
937 BuildRet16Func( outfile );
939 /* CBClientThunkSL routine */
940 BuildCallTo32CBClient( outfile, FALSE );
942 /* CBClientThunkSLEx routine */
943 BuildCallTo32CBClient( outfile, TRUE );
945 /* Pending DPMI events check stub */
946 BuildPendingEventCheck( outfile );
948 fprintf( outfile, "%s\n", asm_globl("__wine_call16_end") );
949 output_function_size( outfile, "__wine_spec_thunk_text_16" );
951 /* Declare the return address and data selector variables */
952 fprintf( outfile, "\n\t.data\n\t.align %d\n", get_alignment(4) );
953 fprintf( outfile, "%s\n\t.long 0\n", asm_globl("CallTo16_DataSelector") );
954 fprintf( outfile, "%s\n\t.long 0\n", asm_globl("CallTo16_TebSelector") );
955 if (UsePIC) fprintf( outfile, "wine_ldt_copy_ptr:\t.long %s\n", asm_name("wine_ldt_copy") );
958 /*******************************************************************
959 * BuildRelays32
961 * Build all the 32-bit relay callbacks
963 void BuildRelays32( FILE *outfile )
965 if (target_cpu != CPU_x86)
967 fprintf( outfile, "/* File not used with this architecture. Do not edit! */\n\n" );
968 return;
971 /* File header */
973 fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
974 fprintf( outfile, "\t.text\n" );
975 fprintf( outfile, "%s:\n\n", asm_name("__wine_spec_thunk_text_32") );
977 /* 32-bit register entry point */
978 BuildCallFrom32Regs( outfile );
980 output_function_size( outfile, "__wine_spec_thunk_text_32" );