winebuild: Get rid of the data16 prefix, it shouldn't be needed anymore and causes...
[wine/multimedia.git] / tools / winebuild / relay.c
blob2196a88c340320426b3dc2b787285ead3b5aed41
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 /* offset of a structure field relative to the start of the struct */
36 #define STRUCTOFFSET(type,field) ((int)FIELD_OFFSET(type,field))
38 /* offset of register relative to the start of the CONTEXT struct */
39 #define CONTEXTOFFSET(reg) STRUCTOFFSET(CONTEXT86,reg)
41 /* offset of register relative to the start of the STACK16FRAME struct */
42 #define STACK16OFFSET(reg) STRUCTOFFSET(STACK16FRAME,reg)
44 /* offset of register relative to the start of the STACK32FRAME struct */
45 #define STACK32OFFSET(reg) STRUCTOFFSET(STACK32FRAME,reg)
47 /* offset of the stack pointer relative to %fs:(0) */
48 #define STACKOFFSET 0xc0 /* STRUCTOFFSET(TEB,WOW32Reserved) */
50 /* fix this if the ntdll_thread_regs structure is changed */
51 #define GS_OFFSET 0x1b0 /* STRUCTOFFSET(TEB,SpareBytes1) + STRUCTOFFSET(ntdll_thread_regs,gs) */
53 static void function_header( FILE *outfile, const char *name )
55 fprintf( outfile, "\n\t.align %d\n", get_alignment(4) );
56 fprintf( outfile, "\t%s\n", func_declaration(name) );
57 fprintf( outfile, "%s\n", asm_globl(name) );
61 /*******************************************************************
62 * BuildCallFrom16Core
64 * This routine builds the core routines used in 16->32 thunks:
65 * CallFrom16Word, CallFrom16Long, CallFrom16Register, and CallFrom16Thunk.
67 * These routines are intended to be called via a far call (with 32-bit
68 * operand size) from 16-bit code. The 16-bit code stub must push %bp,
69 * the 32-bit entry point to be called, and the argument conversion
70 * routine to be used (see stack layout below).
72 * The core routine completes the STACK16FRAME on the 16-bit stack and
73 * switches to the 32-bit stack. Then, the argument conversion routine
74 * is called; it gets passed the 32-bit entry point and a pointer to the
75 * 16-bit arguments (on the 16-bit stack) as parameters. (You can either
76 * use conversion routines automatically generated by BuildCallFrom16,
77 * or write your own for special purposes.)
79 * The conversion routine must call the 32-bit entry point, passing it
80 * the converted arguments, and return its return value to the core.
81 * After the conversion routine has returned, the core switches back
82 * to the 16-bit stack, converts the return value to the DX:AX format
83 * (CallFrom16Long), and returns to the 16-bit call stub. All parameters,
84 * including %bp, are popped off the stack.
86 * The 16-bit call stub now returns to the caller, popping the 16-bit
87 * arguments if necessary (pascal calling convention).
89 * In the case of a 'register' function, CallFrom16Register fills a
90 * CONTEXT86 structure with the values all registers had at the point
91 * the first instruction of the 16-bit call stub was about to be
92 * executed. A pointer to this CONTEXT86 is passed as third parameter
93 * to the argument conversion routine, which typically passes it on
94 * to the called 32-bit entry point.
96 * CallFrom16Thunk is a special variant used by the implementation of
97 * the Win95 16->32 thunk functions C16ThkSL and C16ThkSL01 and is
98 * implemented as follows:
99 * On entry, the EBX register is set up to contain a flat pointer to the
100 * 16-bit stack such that EBX+22 points to the first argument.
101 * Then, the entry point is called, while EBP is set up to point
102 * to the return address (on the 32-bit stack).
103 * The called function returns with CX set to the number of bytes
104 * to be popped of the caller's stack.
106 * Stack layout upon entry to the core routine (STACK16FRAME):
107 * ... ...
108 * (sp+24) word first 16-bit arg
109 * (sp+22) word cs
110 * (sp+20) word ip
111 * (sp+18) word bp
112 * (sp+14) long 32-bit entry point (reused for Win16 mutex recursion count)
113 * (sp+12) word ip of actual entry point (necessary for relay debugging)
114 * (sp+8) long relay (argument conversion) function entry point
115 * (sp+4) long cs of 16-bit entry point
116 * (sp) long ip of 16-bit entry point
118 * Added on the stack:
119 * (sp-2) word saved gs
120 * (sp-4) word saved fs
121 * (sp-6) word saved es
122 * (sp-8) word saved ds
123 * (sp-12) long saved ebp
124 * (sp-16) long saved ecx
125 * (sp-20) long saved edx
126 * (sp-24) long saved previous stack
128 static void BuildCallFrom16Core( FILE *outfile, int reg_func, int thunk )
130 /* Function header */
131 if (thunk) function_header( outfile, "__wine_call_from_16_thunk" );
132 else if (reg_func) function_header( outfile, "__wine_call_from_16_regs" );
133 else function_header( outfile, "__wine_call_from_16" );
135 /* Create STACK16FRAME (except STACK32FRAME link) */
136 fprintf( outfile, "\tpushw %%gs\n" );
137 fprintf( outfile, "\tpushw %%fs\n" );
138 fprintf( outfile, "\tpushw %%es\n" );
139 fprintf( outfile, "\tpushw %%ds\n" );
140 fprintf( outfile, "\tpushl %%ebp\n" );
141 fprintf( outfile, "\tpushl %%ecx\n" );
142 fprintf( outfile, "\tpushl %%edx\n" );
144 /* Save original EFlags register */
145 if (reg_func) fprintf( outfile, "\tpushfl\n" );
147 if ( UsePIC )
149 fprintf( outfile, "\tcall 1f\n" );
150 fprintf( outfile, "1:\tpopl %%ecx\n" );
151 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s-1b(%%ecx),%%edx\n",
152 asm_name("CallTo16_DataSelector") );
154 else
155 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s,%%edx\n", asm_name("CallTo16_DataSelector") );
157 /* Load 32-bit segment registers */
158 fprintf( outfile, "\tmovw %%dx, %%ds\n" );
159 fprintf( outfile, "\tmovw %%dx, %%es\n" );
161 if ( UsePIC )
162 fprintf( outfile, "\tmovw %s-1b(%%ecx), %%fs\n", asm_name("CallTo16_TebSelector") );
163 else
164 fprintf( outfile, "\tmovw %s, %%fs\n", asm_name("CallTo16_TebSelector") );
166 fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n", GS_OFFSET );
168 /* Translate STACK16FRAME base to flat offset in %edx */
169 fprintf( outfile, "\tmovw %%ss, %%dx\n" );
170 fprintf( outfile, "\tandl $0xfff8, %%edx\n" );
171 fprintf( outfile, "\tshrl $1, %%edx\n" );
172 if (UsePIC)
174 fprintf( outfile, "\taddl wine_ldt_copy_ptr-1b(%%ecx),%%edx\n" );
175 fprintf( outfile, "\tmovl (%%edx), %%edx\n" );
177 else
178 fprintf( outfile, "\tmovl %s(%%edx), %%edx\n", asm_name("wine_ldt_copy") );
179 fprintf( outfile, "\tmovzwl %%sp, %%ebp\n" );
180 fprintf( outfile, "\tleal %d(%%ebp,%%edx), %%edx\n", reg_func ? 0 : -4 );
182 /* Get saved flags into %ecx */
183 if (reg_func) fprintf( outfile, "\tpopl %%ecx\n" );
185 /* Get the 32-bit stack pointer from the TEB and complete STACK16FRAME */
186 fprintf( outfile, "\t.byte 0x64\n\tmovl (%d), %%ebp\n", STACKOFFSET );
187 fprintf( outfile, "\tpushl %%ebp\n" );
189 /* Switch stacks */
190 fprintf( outfile, "\t.byte 0x64\n\tmovw %%ss, (%d)\n", STACKOFFSET + 2 );
191 fprintf( outfile, "\t.byte 0x64\n\tmovw %%sp, (%d)\n", STACKOFFSET );
192 fprintf( outfile, "\tpushl %%ds\n" );
193 fprintf( outfile, "\tpopl %%ss\n" );
194 fprintf( outfile, "\tmovl %%ebp, %%esp\n" );
195 fprintf( outfile, "\taddl $%d, %%ebp\n", STACK32OFFSET(ebp) );
198 /* At this point:
199 STACK16FRAME is completely set up
200 DS, ES, SS: flat data segment
201 FS: current TEB
202 ESP: points to last STACK32FRAME
203 EBP: points to ebp member of last STACK32FRAME
204 EDX: points to current STACK16FRAME
205 ECX: contains saved flags
206 all other registers: unchanged */
208 /* Special case: C16ThkSL stub */
209 if ( thunk )
211 /* Set up registers as expected and call thunk */
212 fprintf( outfile, "\tleal %d(%%edx), %%ebx\n", (int)sizeof(STACK16FRAME)-22 );
213 fprintf( outfile, "\tleal -4(%%esp), %%ebp\n" );
215 fprintf( outfile, "\tcall *%d(%%edx)\n", STACK16OFFSET(entry_point) );
217 /* Switch stack back */
218 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
219 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
220 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
222 /* Restore registers and return directly to caller */
223 fprintf( outfile, "\taddl $8, %%esp\n" );
224 fprintf( outfile, "\tpopl %%ebp\n" );
225 fprintf( outfile, "\tpopw %%ds\n" );
226 fprintf( outfile, "\tpopw %%es\n" );
227 fprintf( outfile, "\tpopw %%fs\n" );
228 fprintf( outfile, "\tpopw %%gs\n" );
229 fprintf( outfile, "\taddl $20, %%esp\n" );
231 fprintf( outfile, "\txorb %%ch, %%ch\n" );
232 fprintf( outfile, "\tpopl %%ebx\n" );
233 fprintf( outfile, "\taddw %%cx, %%sp\n" );
234 fprintf( outfile, "\tpush %%ebx\n" );
236 fprintf( outfile, "\t.byte 0x66\n" );
237 fprintf( outfile, "\tlret\n" );
239 return;
243 /* Build register CONTEXT */
244 if ( reg_func )
246 fprintf( outfile, "\tsubl $%d, %%esp\n", (int)sizeof(CONTEXT86) );
248 fprintf( outfile, "\tmovl %%ecx, %d(%%esp)\n", CONTEXTOFFSET(EFlags) );
250 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eax) );
251 fprintf( outfile, "\tmovl %%ebx, %d(%%esp)\n", CONTEXTOFFSET(Ebx) );
252 fprintf( outfile, "\tmovl %%esi, %d(%%esp)\n", CONTEXTOFFSET(Esi) );
253 fprintf( outfile, "\tmovl %%edi, %d(%%esp)\n", CONTEXTOFFSET(Edi) );
255 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ebp) );
256 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ebp) );
257 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(ecx) );
258 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Ecx) );
259 fprintf( outfile, "\tmovl %d(%%edx), %%eax\n", STACK16OFFSET(edx) );
260 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Edx) );
262 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ds) );
263 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegDs) );
264 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(es) );
265 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegEs) );
266 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(fs) );
267 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegFs) );
268 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(gs) );
269 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegGs) );
271 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(cs) );
272 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegCs) );
273 fprintf( outfile, "\tmovzwl %d(%%edx), %%eax\n", STACK16OFFSET(ip) );
274 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Eip) );
276 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET+2 );
277 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(SegSs) );
278 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%eax\n", STACKOFFSET );
279 fprintf( outfile, "\taddl $%d, %%eax\n", STACK16OFFSET(ip) );
280 fprintf( outfile, "\tmovl %%eax, %d(%%esp)\n", CONTEXTOFFSET(Esp) );
281 #if 0
282 fprintf( outfile, "\tfsave %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
283 #endif
285 /* Push address of CONTEXT86 structure -- popped by the relay routine */
286 fprintf( outfile, "\tmovl %%esp,%%eax\n" );
287 fprintf( outfile, "\tandl $~15,%%esp\n" );
288 fprintf( outfile, "\tsubl $4,%%esp\n" );
289 fprintf( outfile, "\tpushl %%eax\n" );
291 else
293 fprintf( outfile, "\tsubl $8,%%esp\n" );
294 fprintf( outfile, "\tandl $~15,%%esp\n" );
295 fprintf( outfile, "\taddl $8,%%esp\n" );
298 /* Call relay routine (which will call the API entry point) */
299 fprintf( outfile, "\tleal %d(%%edx), %%eax\n", (int)sizeof(STACK16FRAME) );
300 fprintf( outfile, "\tpushl %%eax\n" );
301 fprintf( outfile, "\tpushl %d(%%edx)\n", STACK16OFFSET(entry_point) );
302 fprintf( outfile, "\tcall *%d(%%edx)\n", STACK16OFFSET(relay) );
304 if ( reg_func )
306 fprintf( outfile, "\tleal -%d(%%ebp), %%ebx\n",
307 (int)sizeof(CONTEXT) + STACK32OFFSET(ebp) );
309 /* Switch stack back */
310 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
311 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
312 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
314 /* Get return address to CallFrom16 stub */
315 fprintf( outfile, "\taddw $%d, %%sp\n", STACK16OFFSET(callfrom_ip)-4 );
316 fprintf( outfile, "\tpopl %%eax\n" );
317 fprintf( outfile, "\tpopl %%edx\n" );
319 /* Restore all registers from CONTEXT */
320 fprintf( outfile, "\tmovw %d(%%ebx), %%ss\n", CONTEXTOFFSET(SegSs) );
321 fprintf( outfile, "\tmovl %d(%%ebx), %%esp\n", CONTEXTOFFSET(Esp) );
322 fprintf( outfile, "\taddl $4, %%esp\n" ); /* room for final return address */
324 fprintf( outfile, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(SegCs) );
325 fprintf( outfile, "\tpushw %d(%%ebx)\n", CONTEXTOFFSET(Eip) );
326 fprintf( outfile, "\tpushl %%edx\n" );
327 fprintf( outfile, "\tpushl %%eax\n" );
328 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(EFlags) );
329 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegDs) );
331 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegEs) );
332 fprintf( outfile, "\tpopl %%es\n" );
333 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegFs) );
334 fprintf( outfile, "\tpopl %%fs\n" );
335 fprintf( outfile, "\tpushl %d(%%ebx)\n", CONTEXTOFFSET(SegGs) );
336 fprintf( outfile, "\tpopl %%gs\n" );
338 fprintf( outfile, "\tmovl %d(%%ebx), %%ebp\n", CONTEXTOFFSET(Ebp) );
339 fprintf( outfile, "\tmovl %d(%%ebx), %%esi\n", CONTEXTOFFSET(Esi) );
340 fprintf( outfile, "\tmovl %d(%%ebx), %%edi\n", CONTEXTOFFSET(Edi) );
341 fprintf( outfile, "\tmovl %d(%%ebx), %%eax\n", CONTEXTOFFSET(Eax) );
342 fprintf( outfile, "\tmovl %d(%%ebx), %%edx\n", CONTEXTOFFSET(Edx) );
343 fprintf( outfile, "\tmovl %d(%%ebx), %%ecx\n", CONTEXTOFFSET(Ecx) );
344 fprintf( outfile, "\tmovl %d(%%ebx), %%ebx\n", CONTEXTOFFSET(Ebx) );
346 fprintf( outfile, "\tpopl %%ds\n" );
347 fprintf( outfile, "\tpopfl\n" );
348 fprintf( outfile, "\tlret\n" );
350 else
352 /* Switch stack back */
353 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d), %%ss\n", STACKOFFSET+2 );
354 fprintf( outfile, "\t.byte 0x64\n\tmovzwl (%d), %%esp\n", STACKOFFSET );
355 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
357 /* Restore registers */
358 fprintf( outfile, "\tpopl %%edx\n" );
359 fprintf( outfile, "\tpopl %%ecx\n" );
360 fprintf( outfile, "\tpopl %%ebp\n" );
361 fprintf( outfile, "\tpopw %%ds\n" );
362 fprintf( outfile, "\tpopw %%es\n" );
363 fprintf( outfile, "\tpopw %%fs\n" );
364 fprintf( outfile, "\tpopw %%gs\n" );
366 /* Return to return stub which will return to caller */
367 fprintf( outfile, "\tlret $12\n" );
369 if (thunk) output_function_size( outfile, "__wine_call_from_16_thunk" );
370 else if (reg_func) output_function_size( outfile, "__wine_call_from_16_regs" );
371 else output_function_size( outfile, "__wine_call_from_16" );
375 /*******************************************************************
376 * BuildCallTo16Core
378 * This routine builds the core routines used in 32->16 thunks:
380 * extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
381 * extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
383 * These routines can be called directly from 32-bit code.
385 * All routines expect that the 16-bit stack contents (arguments) and the
386 * return address (segptr to CallTo16_Ret) were already set up by the
387 * caller; nb_args must contain the number of bytes to be conserved. The
388 * 16-bit SS:SP will be set accordinly.
390 * All other registers are either taken from the CONTEXT86 structure
391 * or else set to default values. The target routine address is either
392 * given directly or taken from the CONTEXT86.
394 static void BuildCallTo16Core( FILE *outfile, int reg_func )
396 const char *name = reg_func ? "wine_call_to_16_regs" : "wine_call_to_16";
398 /* Function header */
399 function_header( outfile, name );
401 /* Function entry sequence */
402 fprintf( outfile, "\tpushl %%ebp\n" );
403 fprintf( outfile, "\tmovl %%esp, %%ebp\n" );
405 /* Save the 32-bit registers */
406 fprintf( outfile, "\tpushl %%ebx\n" );
407 fprintf( outfile, "\tpushl %%esi\n" );
408 fprintf( outfile, "\tpushl %%edi\n" );
409 fprintf( outfile, "\t.byte 0x64\n\tmov %%gs,(%d)\n", GS_OFFSET );
411 /* Setup exception frame */
412 fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STACKOFFSET );
413 fprintf( outfile, "\tpushl 16(%%ebp)\n" ); /* handler */
414 fprintf( outfile, "\t.byte 0x64\n\tpushl (0)\n" );
415 fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(0)\n" );
417 /* Call the actual CallTo16 routine (simulate a lcall) */
418 fprintf( outfile, "\tpushl %%cs\n" );
419 fprintf( outfile, "\tcall .L%s\n", name );
421 /* Remove exception frame */
422 fprintf( outfile, "\t.byte 0x64\n\tpopl (0)\n" );
423 fprintf( outfile, "\taddl $4, %%esp\n" );
424 fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );
426 if ( !reg_func )
428 /* Convert return value */
429 fprintf( outfile, "\tandl $0xffff,%%eax\n" );
430 fprintf( outfile, "\tshll $16,%%edx\n" );
431 fprintf( outfile, "\torl %%edx,%%eax\n" );
433 else
436 * Modify CONTEXT86 structure to contain new values
438 * NOTE: We restore only EAX, EBX, EDX, EDX, EBP, and ESP.
439 * The segment registers as well as ESI and EDI should
440 * not be modified by a well-behaved 16-bit routine in
441 * any case. [If necessary, we could restore them as well,
442 * at the cost of a somewhat less efficient return path.]
445 fprintf( outfile, "\tmovl %d(%%esp), %%edi\n", STACK32OFFSET(target) - STACK32OFFSET(edi));
446 /* everything above edi has been popped already */
448 fprintf( outfile, "\tmovl %%eax, %d(%%edi)\n", CONTEXTOFFSET(Eax) );
449 fprintf( outfile, "\tmovl %%ebx, %d(%%edi)\n", CONTEXTOFFSET(Ebx) );
450 fprintf( outfile, "\tmovl %%ecx, %d(%%edi)\n", CONTEXTOFFSET(Ecx) );
451 fprintf( outfile, "\tmovl %%edx, %d(%%edi)\n", CONTEXTOFFSET(Edx) );
452 fprintf( outfile, "\tmovl %%ebp, %d(%%edi)\n", CONTEXTOFFSET(Ebp) );
453 fprintf( outfile, "\tmovl %%esi, %d(%%edi)\n", CONTEXTOFFSET(Esp) );
454 /* The return glue code saved %esp into %esi */
457 /* Restore the 32-bit registers */
458 fprintf( outfile, "\tpopl %%edi\n" );
459 fprintf( outfile, "\tpopl %%esi\n" );
460 fprintf( outfile, "\tpopl %%ebx\n" );
462 /* Function exit sequence */
463 fprintf( outfile, "\tpopl %%ebp\n" );
464 fprintf( outfile, "\tret $12\n" );
467 /* Start of the actual CallTo16 routine */
469 fprintf( outfile, ".L%s:\n", name );
471 /* Switch to the 16-bit stack */
472 fprintf( outfile, "\tmovl %%esp,%%edx\n" );
473 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d),%%ss\n", STACKOFFSET + 2);
474 fprintf( outfile, "\t.byte 0x64\n\tmovw (%d),%%sp\n", STACKOFFSET );
475 fprintf( outfile, "\t.byte 0x64\n\tmovl %%edx,(%d)\n", STACKOFFSET );
477 /* Make %bp point to the previous stackframe (built by CallFrom16) */
478 fprintf( outfile, "\tmovzwl %%sp,%%ebp\n" );
479 fprintf( outfile, "\tleal %d(%%ebp),%%ebp\n", STACK16OFFSET(bp) );
481 /* Add the specified offset to the new sp */
482 fprintf( outfile, "\tsubw %d(%%edx), %%sp\n", STACK32OFFSET(nb_args) );
484 if (reg_func)
486 /* Push the called routine address */
487 fprintf( outfile, "\tmovl %d(%%edx),%%edx\n", STACK32OFFSET(target) );
488 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegCs) );
489 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(Eip) );
491 /* Get the registers */
492 fprintf( outfile, "\tpushw %d(%%edx)\n", CONTEXTOFFSET(SegDs) );
493 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegEs) );
494 fprintf( outfile, "\tpopl %%es\n" );
495 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegFs) );
496 fprintf( outfile, "\tpopl %%fs\n" );
497 fprintf( outfile, "\tpushl %d(%%edx)\n", CONTEXTOFFSET(SegGs) );
498 fprintf( outfile, "\tpopl %%gs\n" );
499 fprintf( outfile, "\tmovl %d(%%edx),%%ebp\n", CONTEXTOFFSET(Ebp) );
500 fprintf( outfile, "\tmovl %d(%%edx),%%esi\n", CONTEXTOFFSET(Esi) );
501 fprintf( outfile, "\tmovl %d(%%edx),%%edi\n", CONTEXTOFFSET(Edi) );
502 fprintf( outfile, "\tmovl %d(%%edx),%%eax\n", CONTEXTOFFSET(Eax) );
503 fprintf( outfile, "\tmovl %d(%%edx),%%ebx\n", CONTEXTOFFSET(Ebx) );
504 fprintf( outfile, "\tmovl %d(%%edx),%%ecx\n", CONTEXTOFFSET(Ecx) );
505 fprintf( outfile, "\tmovl %d(%%edx),%%edx\n", CONTEXTOFFSET(Edx) );
507 /* Get the 16-bit ds */
508 fprintf( outfile, "\tpopw %%ds\n" );
510 else /* not a register function */
512 /* Push the called routine address */
513 fprintf( outfile, "\tpushl %d(%%edx)\n", STACK32OFFSET(target) );
515 /* Set %fs and %gs to the value saved by the last CallFrom16 */
516 fprintf( outfile, "\tpushw %d(%%ebp)\n", STACK16OFFSET(fs)-STACK16OFFSET(bp) );
517 fprintf( outfile, "\tpopw %%fs\n" );
518 fprintf( outfile, "\tpushw %d(%%ebp)\n", STACK16OFFSET(gs)-STACK16OFFSET(bp) );
519 fprintf( outfile, "\tpopw %%gs\n" );
521 /* Set %ds and %es (and %ax just in case) equal to %ss */
522 fprintf( outfile, "\tmovw %%ss,%%ax\n" );
523 fprintf( outfile, "\tmovw %%ax,%%ds\n" );
524 fprintf( outfile, "\tmovw %%ax,%%es\n" );
527 /* Jump to the called routine */
528 fprintf( outfile, "\t.byte 0x66\n" );
529 fprintf( outfile, "\tlret\n" );
531 /* Function footer */
532 output_function_size( outfile, name );
536 /*******************************************************************
537 * BuildRet16Func
539 * Build the return code for 16-bit callbacks
541 static void BuildRet16Func( FILE *outfile )
543 function_header( outfile, "__wine_call_to_16_ret" );
545 /* Save %esp into %esi */
546 fprintf( outfile, "\tmovl %%esp,%%esi\n" );
548 /* Restore 32-bit segment registers */
550 fprintf( outfile, "\t.byte 0x2e\n\tmovl %s", asm_name("CallTo16_DataSelector") );
551 fprintf( outfile, "-%s,%%edi\n", asm_name("__wine_call16_start") );
552 fprintf( outfile, "\tmovw %%di,%%ds\n" );
553 fprintf( outfile, "\tmovw %%di,%%es\n" );
555 fprintf( outfile, "\t.byte 0x2e\n\tmov %s", asm_name("CallTo16_TebSelector") );
556 fprintf( outfile, "-%s,%%fs\n", asm_name("__wine_call16_start") );
558 fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n", GS_OFFSET );
560 /* Restore the 32-bit stack */
562 fprintf( outfile, "\tmovw %%di,%%ss\n" );
563 fprintf( outfile, "\t.byte 0x64\n\tmovl (%d),%%esp\n", STACKOFFSET );
565 /* Return to caller */
567 fprintf( outfile, "\tlret\n" );
568 output_function_size( outfile, "__wine_call_to_16_ret" );
572 /*******************************************************************
573 * BuildCallTo32CBClient
575 * Call a CBClient relay stub from 32-bit code (KERNEL.620).
577 * Since the relay stub is itself 32-bit, this should not be a problem;
578 * unfortunately, the relay stubs are expected to switch back to a
579 * 16-bit stack (and 16-bit code) after completion :-(
581 * This would conflict with our 16- vs. 32-bit stack handling, so
582 * we simply switch *back* to our 32-bit stack before returning to
583 * the caller ...
585 * The CBClient relay stub expects to be called with the following
586 * 16-bit stack layout, and with ebp and ebx pointing into the 16-bit
587 * stack at the designated places:
589 * ...
590 * (ebp+14) original arguments to the callback routine
591 * (ebp+10) far return address to original caller
592 * (ebp+6) Thunklet target address
593 * (ebp+2) Thunklet relay ID code
594 * (ebp) BP (saved by CBClientGlueSL)
595 * (ebp-2) SI (saved by CBClientGlueSL)
596 * (ebp-4) DI (saved by CBClientGlueSL)
597 * (ebp-6) DS (saved by CBClientGlueSL)
599 * ... buffer space used by the 16-bit side glue for temp copies
601 * (ebx+4) far return address to 16-bit side glue code
602 * (ebx) saved 16-bit ss:sp (pointing to ebx+4)
604 * The 32-bit side glue code accesses both the original arguments (via ebp)
605 * and the temporary copies prepared by the 16-bit side glue (via ebx).
606 * After completion, the stub will load ss:sp from the buffer at ebx
607 * and perform a far return to 16-bit code.
609 * To trick the relay stub into returning to us, we replace the 16-bit
610 * return address to the glue code by a cs:ip pair pointing to our
611 * return entry point (the original return address is saved first).
612 * Our return stub thus called will then reload the 32-bit ss:esp and
613 * return to 32-bit code (by using and ss:esp value that we have also
614 * pushed onto the 16-bit stack before and a cs:eip values found at
615 * that position on the 32-bit stack). The ss:esp to be restored is
616 * found relative to the 16-bit stack pointer at:
618 * (ebx-4) ss (flat)
619 * (ebx-8) sp (32-bit stack pointer)
621 * The second variant of this routine, CALL32_CBClientEx, which is used
622 * to implement KERNEL.621, has to cope with yet another problem: Here,
623 * the 32-bit side directly returns to the caller of the CBClient thunklet,
624 * restoring registers saved by CBClientGlueSL and cleaning up the stack.
625 * As we have to return to our 32-bit code first, we have to adapt the
626 * layout of our temporary area so as to include values for the registers
627 * that are to be restored, and later (in the implementation of KERNEL.621)
628 * we *really* restore them. The return stub restores DS, DI, SI, and BP
629 * from the stack, skips the next 8 bytes (CBClient relay code / target),
630 * and then performs a lret NN, where NN is the number of arguments to be
631 * removed. Thus, we prepare our temporary area as follows:
633 * (ebx+22) 16-bit cs (this segment)
634 * (ebx+20) 16-bit ip ('16-bit' return entry point)
635 * (ebx+16) 32-bit ss (flat)
636 * (ebx+12) 32-bit sp (32-bit stack pointer)
637 * (ebx+10) 16-bit bp (points to ebx+24)
638 * (ebx+8) 16-bit si (ignored)
639 * (ebx+6) 16-bit di (ignored)
640 * (ebx+4) 16-bit ds (we actually use the flat DS here)
641 * (ebx+2) 16-bit ss (16-bit stack segment)
642 * (ebx+0) 16-bit sp (points to ebx+4)
644 * Note that we ensure that DS is not changed and remains the flat segment,
645 * and the 32-bit stack pointer our own return stub needs fits just
646 * perfectly into the 8 bytes that are skipped by the Windows stub.
647 * One problem is that we have to determine the number of removed arguments,
648 * as these have to be really removed in KERNEL.621. Thus, the BP value
649 * that we place in the temporary area to be restored, contains the value
650 * that SP would have if no arguments were removed. By comparing the actual
651 * value of SP with this value in our return stub we can compute the number
652 * of removed arguments. This is then returned to KERNEL.621.
654 * The stack layout of this function:
655 * (ebp+20) nArgs pointer to variable receiving nr. of args (Ex only)
656 * (ebp+16) esi pointer to caller's esi value
657 * (ebp+12) arg ebp value to be set for relay stub
658 * (ebp+8) func CBClient relay stub address
659 * (ebp+4) ret addr
660 * (ebp) ebp
662 static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx )
664 function_header( outfile, isEx ? "CALL32_CBClientEx" : "CALL32_CBClient" );
666 /* Entry code */
668 fprintf( outfile, "\tpushl %%ebp\n" );
669 fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
670 fprintf( outfile, "\tpushl %%edi\n" );
671 fprintf( outfile, "\tpushl %%esi\n" );
672 fprintf( outfile, "\tpushl %%ebx\n" );
674 /* Get pointer to temporary area and save the 32-bit stack pointer */
676 fprintf( outfile, "\tmovl 16(%%ebp), %%ebx\n" );
677 fprintf( outfile, "\tleal -8(%%esp), %%eax\n" );
679 if ( !isEx )
680 fprintf( outfile, "\tmovl %%eax, -8(%%ebx)\n" );
681 else
682 fprintf( outfile, "\tmovl %%eax, 12(%%ebx)\n" );
684 /* Set up registers and call CBClient relay stub (simulating a far call) */
686 fprintf( outfile, "\tmovl 20(%%ebp), %%esi\n" );
687 fprintf( outfile, "\tmovl (%%esi), %%esi\n" );
689 fprintf( outfile, "\tmovl 8(%%ebp), %%eax\n" );
690 fprintf( outfile, "\tmovl 12(%%ebp), %%ebp\n" );
692 fprintf( outfile, "\tpushl %%cs\n" );
693 fprintf( outfile, "\tcall *%%eax\n" );
695 /* Return new esi value to caller */
697 fprintf( outfile, "\tmovl 32(%%esp), %%edi\n" );
698 fprintf( outfile, "\tmovl %%esi, (%%edi)\n" );
700 /* Return argument size to caller */
701 if ( isEx )
703 fprintf( outfile, "\tmovl 36(%%esp), %%ebx\n" );
704 fprintf( outfile, "\tmovl %%ebp, (%%ebx)\n" );
707 /* Restore registers and return */
709 fprintf( outfile, "\tpopl %%ebx\n" );
710 fprintf( outfile, "\tpopl %%esi\n" );
711 fprintf( outfile, "\tpopl %%edi\n" );
712 fprintf( outfile, "\tpopl %%ebp\n" );
713 fprintf( outfile, "\tret\n" );
714 output_function_size( outfile, isEx ? "CALL32_CBClientEx" : "CALL32_CBClient" );
716 /* '16-bit' return stub */
718 function_header( outfile, isEx ? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
719 if ( !isEx )
721 fprintf( outfile, "\tmovzwl %%sp, %%ebx\n" );
722 fprintf( outfile, "\tlssl %%ss:-16(%%ebx), %%esp\n" );
724 else
726 fprintf( outfile, "\tmovzwl %%bp, %%ebx\n" );
727 fprintf( outfile, "\tsubw %%bp, %%sp\n" );
728 fprintf( outfile, "\tmovzwl %%sp, %%ebp\n" );
729 fprintf( outfile, "\tlssl %%ss:-12(%%ebx), %%esp\n" );
731 fprintf( outfile, "\tlret\n" );
732 output_function_size( outfile, isEx ? "CALL32_CBClientEx_Ret" : "CALL32_CBClient_Ret" );
736 /*******************************************************************
737 * BuildCallFrom32Regs
739 * Build a 32-bit-to-Wine call-back function for a 'register' function.
740 * 'args' is the number of dword arguments.
742 * Stack layout:
743 * ...
744 * (ebp+16) first arg
745 * (ebp+12) ret addr to user code
746 * (ebp+8) eax saved by relay code
747 * (ebp+4) ret addr to relay code
748 * (ebp+0) saved ebp
749 * (ebp-128) buffer area to allow stack frame manipulation
750 * (ebp-332) CONTEXT86 struct
751 * (ebp-336) padding for stack alignment
752 * (ebp-336-n) CONTEXT86 *argument
753 * .... other arguments copied from (ebp+12)
755 * The entry point routine is called with a CONTEXT* extra argument,
756 * following the normal args. In this context structure, EIP_reg
757 * contains the return address to user code, and ESP_reg the stack
758 * pointer on return (with the return address and arguments already
759 * removed).
761 static void BuildCallFrom32Regs( FILE *outfile )
763 static const int STACK_SPACE = 128 + sizeof(CONTEXT86);
765 /* Function header */
767 function_header( outfile, "__wine_call_from_32_regs" );
769 /* Allocate some buffer space on the stack */
771 fprintf( outfile, "\tpushl %%ebp\n" );
772 fprintf( outfile, "\tmovl %%esp,%%ebp\n ");
773 fprintf( outfile, "\tleal -%d(%%esp), %%esp\n", STACK_SPACE + 4 /* for context arg */);
775 /* Build the context structure */
777 fprintf( outfile, "\tpushfl\n" );
778 fprintf( outfile, "\tpopl %%eax\n" );
779 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(EFlags) - STACK_SPACE );
780 fprintf( outfile, "\tmovl 0(%%ebp),%%eax\n" );
781 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Ebp) - STACK_SPACE );
782 fprintf( outfile, "\tmovl 8(%%ebp),%%eax\n" );
783 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eax) - STACK_SPACE );
784 fprintf( outfile, "\tmovl %%ebx,%d(%%ebp)\n", CONTEXTOFFSET(Ebx) - STACK_SPACE );
785 fprintf( outfile, "\tmovl %%ecx,%d(%%ebp)\n", CONTEXTOFFSET(Ecx) - STACK_SPACE );
786 fprintf( outfile, "\tmovl %%edx,%d(%%ebp)\n", CONTEXTOFFSET(Edx) - STACK_SPACE );
787 fprintf( outfile, "\tmovl %%esi,%d(%%ebp)\n", CONTEXTOFFSET(Esi) - STACK_SPACE );
788 fprintf( outfile, "\tmovl %%edi,%d(%%ebp)\n", CONTEXTOFFSET(Edi) - STACK_SPACE );
790 fprintf( outfile, "\txorl %%eax,%%eax\n" );
791 fprintf( outfile, "\tmovw %%cs,%%ax\n" );
792 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegCs) - STACK_SPACE );
793 fprintf( outfile, "\tmovw %%es,%%ax\n" );
794 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegEs) - STACK_SPACE );
795 fprintf( outfile, "\tmovw %%fs,%%ax\n" );
796 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegFs) - STACK_SPACE );
797 fprintf( outfile, "\tmovw %%gs,%%ax\n" );
798 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegGs) - STACK_SPACE );
799 fprintf( outfile, "\tmovw %%ss,%%ax\n" );
800 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegSs) - STACK_SPACE );
801 fprintf( outfile, "\tmovw %%ds,%%ax\n" );
802 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(SegDs) - STACK_SPACE );
803 fprintf( outfile, "\tmovw %%ax,%%es\n" ); /* set %es equal to %ds just in case */
805 fprintf( outfile, "\tmovl $0x%x,%%eax\n", CONTEXT86_FULL );
806 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(ContextFlags) - STACK_SPACE );
808 fprintf( outfile, "\tmovl 12(%%ebp),%%eax\n" ); /* Get %eip at time of call */
809 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Eip) - STACK_SPACE );
811 /* Transfer the arguments */
813 fprintf( outfile, "\tmovl 4(%%ebp),%%ebx\n" ); /* get relay code addr */
814 fprintf( outfile, "\tmovzbl 4(%%ebx),%%ecx\n" ); /* fetch number of args to copy */
815 fprintf( outfile, "\tsubl %%ecx,%%esp\n" );
816 fprintf( outfile, "\tandl $~15,%%esp\n" );
817 fprintf( outfile, "\tleal 16(%%ebp),%%esi\n" ); /* get %esp at time of call */
818 fprintf( outfile, "\tmovl %%esp,%%edi\n" );
819 fprintf( outfile, "\tshrl $2,%%ecx\n" );
820 fprintf( outfile, "\tjz 1f\n" );
821 fprintf( outfile, "\tcld\n" );
822 fprintf( outfile, "\trep\n\tmovsl\n" ); /* copy args */
823 fprintf( outfile, "1:\tleal %d(%%ebp),%%eax\n", -STACK_SPACE ); /* get addr of context struct */
824 fprintf( outfile, "\tmovl %%eax,(%%edi)\n" ); /* and pass it as extra arg */
825 fprintf( outfile, "\tmovzbl 5(%%ebx),%%eax\n" ); /* fetch number of args to remove */
826 fprintf( outfile, "\tleal 16(%%ebp,%%eax),%%eax\n" );
827 fprintf( outfile, "\tmovl %%eax,%d(%%ebp)\n", CONTEXTOFFSET(Esp) - STACK_SPACE );
829 /* Call the entry point */
831 fprintf( outfile, "\taddl (%%ebx),%%ebx\n" );
832 fprintf( outfile, "\tcall *%%ebx\n" );
833 fprintf( outfile, "\tleal -%d(%%ebp),%%ecx\n", STACK_SPACE );
835 /* Restore the context structure */
837 fprintf( outfile, "2:\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegEs) );
838 fprintf( outfile, "\tpopl %%es\n" );
839 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegFs) );
840 fprintf( outfile, "\tpopl %%fs\n" );
841 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegGs) );
842 fprintf( outfile, "\tpopl %%gs\n" );
844 fprintf( outfile, "\tmovl %d(%%ecx),%%edi\n", CONTEXTOFFSET(Edi) );
845 fprintf( outfile, "\tmovl %d(%%ecx),%%esi\n", CONTEXTOFFSET(Esi) );
846 fprintf( outfile, "\tmovl %d(%%ecx),%%edx\n", CONTEXTOFFSET(Edx) );
847 fprintf( outfile, "\tmovl %d(%%ecx),%%ebx\n", CONTEXTOFFSET(Ebx) );
848 fprintf( outfile, "\tmovl %d(%%ecx),%%eax\n", CONTEXTOFFSET(Eax) );
849 fprintf( outfile, "\tmovl %d(%%ecx),%%ebp\n", CONTEXTOFFSET(Ebp) );
851 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegSs) );
852 fprintf( outfile, "\tpopl %%ss\n" );
853 fprintf( outfile, "\tmovl %d(%%ecx),%%esp\n", CONTEXTOFFSET(Esp) );
855 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(EFlags) );
856 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegCs) );
857 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(Eip) );
858 fprintf( outfile, "\tpushl %d(%%ecx)\n", CONTEXTOFFSET(SegDs) );
859 fprintf( outfile, "\tmovl %d(%%ecx),%%ecx\n", CONTEXTOFFSET(Ecx) );
861 fprintf( outfile, "\tpopl %%ds\n" );
862 fprintf( outfile, "\tiret\n" );
863 output_function_size( outfile, "__wine_call_from_32_regs" );
865 function_header( outfile, "__wine_call_from_32_restore_regs" );
866 fprintf( outfile, "\tmovl 4(%%esp),%%ecx\n" );
867 fprintf( outfile, "\tjmp 2b\n" );
868 output_function_size( outfile, "__wine_call_from_32_restore_regs" );
872 /*******************************************************************
873 * BuildPendingEventCheck
875 * Build a function that checks whether there are any
876 * pending DPMI events.
878 * Stack layout:
880 * (sp+12) long eflags
881 * (sp+6) long cs
882 * (sp+2) long ip
883 * (sp) word fs
885 * On entry to function, fs register points to a valid TEB.
886 * On exit from function, stack will be popped.
888 static void BuildPendingEventCheck( FILE *outfile )
890 /* Function header */
892 function_header( outfile, "DPMI_PendingEventCheck" );
894 /* Check for pending events. */
896 fprintf( outfile, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
897 STRUCTOFFSET(TEB,vm86_pending) );
898 fprintf( outfile, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
900 fprintf( outfile, "\t.byte 0x64\n\ttestl $0xffffffff,(%d)\n",
901 STRUCTOFFSET(TEB,dpmi_vif) );
903 fprintf( outfile, "\tje %s\n", asm_name("DPMI_PendingEventCheck_Cleanup") );
905 /* Process pending events. */
907 fprintf( outfile, "\tsti\n" );
909 /* Start cleanup. Restore fs register. */
911 fprintf( outfile, "%s\n", asm_globl("DPMI_PendingEventCheck_Cleanup") );
912 fprintf( outfile, "\tpopw %%fs\n" );
914 /* Return from function. */
916 fprintf( outfile, "%s\n", asm_globl("DPMI_PendingEventCheck_Return") );
917 fprintf( outfile, "\tiret\n" );
919 output_function_size( outfile, "DPMI_PendingEventCheck" );
923 /*******************************************************************
924 * BuildRelays16
926 * Build all the 16-bit relay callbacks
928 void BuildRelays16( FILE *outfile )
930 if (target_cpu != CPU_x86)
932 fprintf( outfile, "/* File not used with this architecture. Do not edit! */\n\n" );
933 return;
936 /* File header */
938 fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
939 fprintf( outfile, "\t.text\n" );
941 fprintf( outfile, "%s:\n\n", asm_name("__wine_spec_thunk_text_16") );
943 fprintf( outfile, "%s\n", asm_globl("__wine_call16_start") );
945 /* Standard CallFrom16 routine */
946 BuildCallFrom16Core( outfile, FALSE, FALSE );
948 /* Register CallFrom16 routine */
949 BuildCallFrom16Core( outfile, TRUE, FALSE );
951 /* C16ThkSL CallFrom16 routine */
952 BuildCallFrom16Core( outfile, FALSE, TRUE );
954 /* Standard CallTo16 routine */
955 BuildCallTo16Core( outfile, 0 );
957 /* Register CallTo16 routine */
958 BuildCallTo16Core( outfile, 1 );
960 /* Standard CallTo16 return stub */
961 BuildRet16Func( outfile );
963 /* CBClientThunkSL routine */
964 BuildCallTo32CBClient( outfile, FALSE );
966 /* CBClientThunkSLEx routine */
967 BuildCallTo32CBClient( outfile, TRUE );
969 /* Pending DPMI events check stub */
970 BuildPendingEventCheck( outfile );
972 fprintf( outfile, "%s\n", asm_globl("__wine_call16_end") );
973 output_function_size( outfile, "__wine_spec_thunk_text_16" );
975 /* Declare the return address and data selector variables */
976 fprintf( outfile, "\n\t.data\n\t.align %d\n", get_alignment(4) );
977 fprintf( outfile, "%s\n\t.long 0\n", asm_globl("CallTo16_DataSelector") );
978 fprintf( outfile, "%s\n\t.long 0\n", asm_globl("CallTo16_TebSelector") );
979 if (UsePIC) fprintf( outfile, "wine_ldt_copy_ptr:\t.long %s\n", asm_name("wine_ldt_copy") );
980 output_gnu_stack_note( outfile );
983 /*******************************************************************
984 * BuildRelays32
986 * Build all the 32-bit relay callbacks
988 void BuildRelays32( FILE *outfile )
990 if (target_cpu != CPU_x86)
992 fprintf( outfile, "/* File not used with this architecture. Do not edit! */\n\n" );
993 return;
996 /* File header */
998 fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
999 fprintf( outfile, "\t.text\n" );
1000 fprintf( outfile, "%s:\n\n", asm_name("__wine_spec_thunk_text_32") );
1002 /* 32-bit register entry point */
1003 BuildCallFrom32Regs( outfile );
1005 output_function_size( outfile, "__wine_spec_thunk_text_32" );
1006 output_gnu_stack_note( outfile );