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
15 #include "wine/exception.h"
16 #include "builtin16.h"
18 #include "stackframe.h"
23 extern unsigned short __get_cs(void);
24 __ASM_GLOBAL_FUNC( __get_cs
, "movw %cs,%ax\n\tret" );
26 static inline unsigned short __get_cs(void) { return 0; }
30 /*******************************************************************
33 * Store a list of ints into a byte array.
35 static int StoreVariableCode( unsigned char *buffer
, int size
, ORDDEF
*odp
)
42 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
43 buffer
[i
] = odp
->u
.var
.values
[i
];
46 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
47 ((unsigned short *)buffer
)[i
] = odp
->u
.var
.values
[i
];
50 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
51 ((unsigned int *)buffer
)[i
] = odp
->u
.var
.values
[i
];
54 return odp
->u
.var
.n_values
* size
;
58 /*******************************************************************
61 * Build the in-memory representation of a 16-bit NE module, and dump it
62 * as a byte stream into the assembly code.
64 static int BuildModule16( FILE *outfile
, int max_code_offset
,
70 SEGTABLEENTRY
*pSegment
;
73 ET_BUNDLE
*bundle
= 0;
78 * OFSTRUCT File information
79 * SEGTABLEENTRY Segment 1 (code)
80 * SEGTABLEENTRY Segment 2 (data)
81 * WORD[2] Resource table (empty)
82 * BYTE[2] Imported names (empty)
83 * BYTE[n] Resident names table
87 buffer
= xmalloc( 0x10000 );
89 pModule
= (NE_MODULE
*)buffer
;
90 memset( pModule
, 0, sizeof(*pModule
) );
91 pModule
->magic
= IMAGE_OS2_SIGNATURE
;
94 pModule
->flags
= NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_BUILTIN
| NE_FFLAGS_LIBMODULE
;
96 pModule
->heap_size
= DLLHeapSize
;
97 pModule
->stack_size
= 0;
102 pModule
->seg_count
= 2;
103 pModule
->modref_count
= 0;
104 pModule
->nrname_size
= 0;
105 pModule
->modref_table
= 0;
106 pModule
->nrname_fpos
= 0;
107 pModule
->moveable_entries
= 0;
108 pModule
->alignment
= 0;
109 pModule
->truetype
= 0;
110 pModule
->os_flags
= NE_OSFLAGS_WINDOWS
;
111 pModule
->misc_flags
= 0;
112 pModule
->dlls_to_init
= 0;
113 pModule
->nrname_handle
= 0;
114 pModule
->min_swap_area
= 0;
115 pModule
->expected_version
= 0;
116 pModule
->module32
= 0;
118 pModule
->self_loading_sel
= 0;
120 /* File information */
122 pFileInfo
= (OFSTRUCT
*)(pModule
+ 1);
123 pModule
->fileinfo
= (int)pFileInfo
- (int)pModule
;
124 memset( pFileInfo
, 0, sizeof(*pFileInfo
) - sizeof(pFileInfo
->szPathName
) );
125 pFileInfo
->cBytes
= sizeof(*pFileInfo
) - sizeof(pFileInfo
->szPathName
)
126 + strlen(DLLFileName
);
127 strcpy( pFileInfo
->szPathName
, DLLFileName
);
128 pstr
= (char *)pFileInfo
+ pFileInfo
->cBytes
+ 1;
130 #ifdef __i386__ /* FIXME: Alignment problems! */
134 pSegment
= (SEGTABLEENTRY
*)pstr
;
135 pModule
->seg_table
= (int)pSegment
- (int)pModule
;
136 pSegment
->filepos
= 0;
137 pSegment
->size
= max_code_offset
;
139 pSegment
->minsize
= max_code_offset
;
143 pModule
->dgroup_entry
= (int)pSegment
- (int)pModule
;
144 pSegment
->filepos
= 0;
145 pSegment
->size
= max_data_offset
;
146 pSegment
->flags
= NE_SEGFLAGS_DATA
;
147 pSegment
->minsize
= max_data_offset
;
153 pstr
= (char *)pSegment
;
154 pModule
->res_table
= (int)pstr
- (int)pModule
;
155 pstr
+= output_res16_directory( pstr
);
157 /* Imported names table */
159 pModule
->import_table
= (int)pstr
- (int)pModule
;
163 /* Resident names table */
165 pModule
->name_table
= (int)pstr
- (int)pModule
;
166 /* First entry is module name */
167 *pstr
= strlen(DLLName
);
168 strcpy( pstr
+ 1, DLLName
);
171 pstr
+= sizeof(WORD
);
172 /* Store all ordinals */
173 for (i
= 1; i
<= Limit
; i
++)
175 ORDDEF
*odp
= Ordinals
[i
];
176 if (!odp
|| !odp
->name
[0]) continue;
177 *pstr
= strlen( odp
->name
);
178 strcpy( pstr
+ 1, odp
->name
);
179 strupper( pstr
+ 1 );
182 pstr
+= sizeof(WORD
);
188 pModule
->entry_table
= (int)pstr
- (int)pModule
;
189 for (i
= 1; i
<= Limit
; i
++)
192 ORDDEF
*odp
= Ordinals
[i
];
203 selector
= 1; /* Code selector */
207 selector
= 2; /* Data selector */
211 selector
= 0xfe; /* Constant selector */
215 selector
= 0; /* Invalid selector */
222 if ( bundle
&& bundle
->last
+1 == i
)
227 bundle
->next
= (char *)pstr
- (char *)pModule
;
229 bundle
= (ET_BUNDLE
*)pstr
;
233 pstr
+= sizeof(ET_BUNDLE
);
236 /* FIXME: is this really correct ?? */
237 entry
= (ET_ENTRY
*)pstr
;
238 entry
->type
= 0xff; /* movable */
239 entry
->flags
= 3; /* exported & public data */
240 entry
->segnum
= selector
;
241 entry
->offs
= odp
->offset
;
242 pstr
+= sizeof(ET_ENTRY
);
247 /* Dump the module content */
249 dump_bytes( outfile
, (char *)pModule
, (int)pstr
- (int)pModule
, "Module", 0 );
250 return (int)pstr
- (int)pModule
;
254 /*******************************************************************
255 * BuildCallFrom16Func
257 * Build a 16-bit-to-Wine callback glue function.
259 * The generated routines are intended to be used as argument conversion
260 * routines to be called by the CallFrom16... core. Thus, the prototypes of
261 * the generated routines are (see also CallFrom16):
263 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
264 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
265 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
266 * CONTEXT86 *context );
267 * extern void WINAPI PREFIX_CallFrom16_C_intr_xxx( FARPROC func, LPBYTE args,
268 * CONTEXT86 *context );
270 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
271 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
272 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
273 * 'T'=segmented pointer to null-terminated string).
275 * The generated routines fetch the arguments from the 16-bit stack (pointed
276 * to by 'args'); the offsets of the single argument values are computed
277 * according to the calling convention and the argument types. Then, the
278 * 32-bit entry point is called with these arguments.
280 * For register functions, the arguments (if present) are converted just
281 * the same as for normal functions, but in addition the CONTEXT86 pointer
282 * filled with the current register values is passed to the 32-bit routine.
283 * (An 'intr' interrupt handler routine is treated exactly like a register
284 * routine, except that upon return, the flags word pushed onto the stack
285 * by the interrupt is removed by the 16-bit call stub.)
288 static void BuildCallFrom16Func( FILE *outfile
, char *profile
, char *prefix
, int local
)
290 int i
, pos
, argsize
= 0;
294 char *args
= profile
+ 7;
297 /* Parse function type */
299 if (!strncmp( "c_", profile
, 2 )) usecdecl
= 1;
300 else if (strncmp( "p_", profile
, 2 ))
302 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
306 if (!strncmp( "word_", profile
+ 2, 5 )) short_ret
= 1;
307 else if (!strncmp( "regs_", profile
+ 2, 5 )) reg_func
= 1;
308 else if (!strncmp( "intr_", profile
+ 2, 5 )) reg_func
= 2;
309 else if (strncmp( "long_", profile
+ 2, 5 ))
311 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
315 for ( i
= 0; args
[i
]; i
++ )
319 case 's': /* s_word */
323 case 'l': /* long or segmented pointer */
324 case 'T': /* segmented pointer to null-terminated string */
325 case 'p': /* linear pointer */
326 case 't': /* linear pointer to null-terminated string */
331 ret_type
= reg_func
? "void" : short_ret
? "WORD" : "LONG";
333 fprintf( outfile
, "typedef %s WINAPI (*proc_%s_t)( ",
336 for ( i
= 0; args
[i
]; i
++ )
338 if ( i
) fprintf( outfile
, ", " );
341 case 'w': fprintf( outfile
, "WORD" ); break;
342 case 's': fprintf( outfile
, "INT16" ); break;
343 case 'l': case 'T': fprintf( outfile
, "LONG" ); break;
344 case 'p': case 't': fprintf( outfile
, "LPVOID" ); break;
348 fprintf( outfile
, "%sstruct _CONTEXT86 *", i
? ", " : "" );
350 fprintf( outfile
, "void" );
351 fprintf( outfile
, " );\n" );
353 fprintf( outfile
, "%s%s WINAPI %s_CallFrom16_%s( FARPROC proc, LPBYTE args%s )\n{\n",
354 local
? "static " : "", ret_type
, prefix
, profile
,
355 reg_func
? ", struct _CONTEXT86 *context" : "" );
357 fprintf( outfile
, " %s((proc_%s_t) proc) (\n",
358 reg_func
? "" : "return ", profile
);
360 pos
= !usecdecl
? argsize
: 0;
361 for ( i
= 0; args
[i
]; i
++ )
363 if ( i
) fprintf( outfile
, ",\n" );
364 fprintf( outfile
, " " );
368 if ( !usecdecl
) pos
-= 2;
369 fprintf( outfile
, "*(WORD *)(args+%d)", pos
);
370 if ( usecdecl
) pos
+= 2;
373 case 's': /* s_word */
374 if ( !usecdecl
) pos
-= 2;
375 fprintf( outfile
, "*(INT16 *)(args+%d)", pos
);
376 if ( usecdecl
) pos
+= 2;
379 case 'l': /* long or segmented pointer */
380 case 'T': /* segmented pointer to null-terminated string */
381 if ( !usecdecl
) pos
-= 4;
382 fprintf( outfile
, "*(LONG *)(args+%d)", pos
);
383 if ( usecdecl
) pos
+= 4;
386 case 'p': /* linear pointer */
387 case 't': /* linear pointer to null-terminated string */
388 if ( !usecdecl
) pos
-= 4;
389 fprintf( outfile
, "((char*)wine_ldt_copy.base[*(WORD*)(args+%d) >> 3] + *(WORD*)(args+%d))",
391 if ( usecdecl
) pos
+= 4;
395 fprintf( stderr
, "Unknown arg type '%c'\n", args
[i
] );
399 fprintf( outfile
, "%s context", i
? ",\n" : "" );
400 fprintf( outfile
, " );\n}\n\n" );
404 /*******************************************************************
407 * Build a Wine-to-16-bit callback glue function.
409 * Prototypes for the CallTo16 functions:
410 * extern WORD CALLBACK PREFIX_CallTo16_word_xxx( FARPROC16 func, args... );
411 * extern LONG CALLBACK PREFIX_CallTo16_long_xxx( FARPROC16 func, args... );
413 * These routines are provided solely for convenience; they simply
414 * write the arguments onto the 16-bit stack, and call the appropriate
415 * wine_call_to_16... core routine.
417 * If you have more sophisticated argument conversion requirements than
418 * are provided by these routines, you might as well call the core
419 * routines by yourself.
422 static void BuildCallTo16Func( FILE *outfile
, char *profile
, char *prefix
)
424 char *args
= profile
+ 5;
425 int i
, argsize
= 0, short_ret
= 0;
427 if (!strncmp( "word_", profile
, 5 )) short_ret
= 1;
428 else if (strncmp( "long_", profile
, 5 ))
430 fprintf( stderr
, "Invalid function name '%s'.\n", profile
);
434 fprintf( outfile
, "%s %s_CallTo16_%s( FARPROC16 proc",
435 short_ret
? "WORD" : "LONG", prefix
, profile
);
437 for ( i
= 0; args
[i
]; i
++ )
439 fprintf( outfile
, ", " );
442 case 'w': fprintf( outfile
, "WORD" ); argsize
+= 2; break;
443 case 'l': fprintf( outfile
, "LONG" ); argsize
+= 4; break;
445 fprintf( outfile
, " arg%d", i
+1 );
447 fprintf( outfile
, " )\n{\n" );
450 fprintf( outfile
, " LPBYTE args = (LPBYTE)CURRENT_STACK16;\n" );
453 for ( i
= 0; args
[i
]; i
++ )
457 case 'w': fprintf( outfile
, " args -= sizeof(WORD); *(WORD" ); break;
458 case 'l': fprintf( outfile
, " args -= sizeof(LONG); *(LONG" ); break;
459 default: fprintf( stderr
, "Unexpected case '%c' in BuildCallTo16Func\n",
462 fprintf( outfile
, " *)args = arg%d;\n", i
+1 );
465 fprintf( outfile
, " return wine_call_to_16_%s( proc, %d );\n}\n\n",
466 short_ret
? "word" : "long", argsize
);
470 /*******************************************************************
473 static int Spec16TypeCompare( const void *e1
, const void *e2
)
475 const ORDDEF
*odp1
= *(const ORDDEF
**)e1
;
476 const ORDDEF
*odp2
= *(const ORDDEF
**)e2
;
478 int type1
= (odp1
->type
== TYPE_CDECL
) ? 0
479 : (odp1
->type
== TYPE_REGISTER
) ? 3
480 : (odp1
->type
== TYPE_INTERRUPT
) ? 4
481 : (odp1
->type
== TYPE_PASCAL_16
) ? 1 : 2;
483 int type2
= (odp2
->type
== TYPE_CDECL
) ? 0
484 : (odp2
->type
== TYPE_REGISTER
) ? 3
485 : (odp2
->type
== TYPE_INTERRUPT
) ? 4
486 : (odp2
->type
== TYPE_PASCAL_16
) ? 1 : 2;
488 int retval
= type1
- type2
;
490 retval
= strcmp( odp1
->u
.func
.arg_types
, odp2
->u
.func
.arg_types
);
496 /*******************************************************************
499 * Output the functions for stub entry points
501 static void output_stub_funcs( FILE *outfile
)
506 for (i
= 0; i
<= Limit
; i
++)
508 ORDDEF
*odp
= Ordinals
[i
];
509 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
510 fprintf( outfile
, "#ifdef __GNUC__\n" );
511 fprintf( outfile
, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
512 fprintf( outfile
, "#endif\n" );
513 fprintf( outfile
, "static void __wine_unimplemented( const char *func )\n{\n" );
514 fprintf( outfile
, " struct exc_record {\n" );
515 fprintf( outfile
, " unsigned int code, flags;\n" );
516 fprintf( outfile
, " void *rec, *addr;\n" );
517 fprintf( outfile
, " unsigned int params;\n" );
518 fprintf( outfile
, " const void *info[15];\n" );
519 fprintf( outfile
, " } rec;\n" );
520 fprintf( outfile
, " extern void RtlRaiseException( struct exc_record * );\n\n" );
521 fprintf( outfile
, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB
);
522 fprintf( outfile
, " rec.flags = %d;\n", EH_NONCONTINUABLE
);
523 fprintf( outfile
, " rec.rec = 0;\n" );
524 fprintf( outfile
, " rec.params = 2;\n" );
525 fprintf( outfile
, " rec.info[0] = dllname;\n" );
526 fprintf( outfile
, " rec.info[1] = func;\n" );
527 fprintf( outfile
, "#ifdef __GNUC__\n" );
528 fprintf( outfile
, " rec.addr = __builtin_return_address(1);\n" );
529 fprintf( outfile
, "#else\n" );
530 fprintf( outfile
, " rec.addr = 0;\n" );
531 fprintf( outfile
, "#endif\n" );
532 fprintf( outfile
, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
535 for (i
= 0; i
<= Limit
; i
++)
537 ORDDEF
*odp
= Ordinals
[i
];
538 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
539 odp
->link_name
= xrealloc( odp
->link_name
, strlen(odp
->name
) + 13 );
540 strcpy( odp
->link_name
, "__wine_stub_" );
541 strcat( odp
->link_name
, odp
->name
);
542 for (p
= odp
->link_name
; *p
; p
++) if (!isalnum(*p
)) *p
= '_';
543 fprintf( outfile
, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
544 odp
->link_name
, odp
->name
);
549 /*******************************************************************
552 * Build a Win16 assembly file from a spec file.
554 void BuildSpec16File( FILE *outfile
)
556 ORDDEF
**type
, **typelist
;
557 int i
, nFuncs
, nTypes
;
558 int code_offset
, data_offset
, module_size
, res_size
;
560 unsigned short code_selector
= __get_cs();
564 fprintf( outfile
, "/* File generated automatically from %s; do not edit! */\n\n",
566 fprintf( outfile
, "#include \"builtin16.h\"\n\n" );
568 fprintf( outfile
, "extern struct\n{\n" );
569 fprintf( outfile
, " void *base[8192];\n" );
570 fprintf( outfile
, " unsigned long limit[8192];\n" );
571 fprintf( outfile
, " unsigned char flags[8192];\n" );
572 fprintf( outfile
, "} wine_ldt_copy;\n\n" );
574 data
= (unsigned char *)xmalloc( 0x10000 );
575 memset( data
, 0, 16 );
579 fprintf( outfile
, "static const char dllname[] = \"%s\";\n\n", DLLName
);
580 output_stub_funcs( outfile
);
582 /* Build sorted list of all argument types, without duplicates */
584 typelist
= (ORDDEF
**)calloc( Limit
+1, sizeof(ORDDEF
*) );
586 for (i
= nFuncs
= 0; i
<= Limit
; i
++)
588 ORDDEF
*odp
= Ordinals
[i
];
598 typelist
[nFuncs
++] = odp
;
605 qsort( typelist
, nFuncs
, sizeof(ORDDEF
*), Spec16TypeCompare
);
610 typelist
[nTypes
++] = typelist
[i
++];
611 while ( i
< nFuncs
&& Spec16TypeCompare( typelist
+ i
, typelist
+ nTypes
-1 ) == 0 )
615 /* Output CallFrom16 routines needed by this .spec file */
617 for ( i
= 0; i
< nTypes
; i
++ )
621 sprintf( profile
, "%s_%s_%s",
622 (typelist
[i
]->type
== TYPE_CDECL
) ? "c" : "p",
623 (typelist
[i
]->type
== TYPE_REGISTER
) ? "regs" :
624 (typelist
[i
]->type
== TYPE_INTERRUPT
) ? "intr" :
625 (typelist
[i
]->type
== TYPE_PASCAL_16
) ? "word" : "long",
626 typelist
[i
]->u
.func
.arg_types
);
628 BuildCallFrom16Func( outfile
, profile
, DLLName
, TRUE
);
631 /* Output the DLL functions prototypes */
633 for (i
= 0; i
<= Limit
; i
++)
635 ORDDEF
*odp
= Ordinals
[i
];
644 fprintf( outfile
, "extern void %s();\n", odp
->link_name
);
651 /* Output code segment */
653 fprintf( outfile
, "\nstatic struct\n{\n CALLFROM16 call[%d];\n"
654 " ENTRYPOINT16 entry[%d];\n} Code_Segment = \n{\n {\n",
658 for ( i
= 0; i
< nTypes
; i
++ )
660 char profile
[101], *arg
;
663 sprintf( profile
, "%s_%s_%s",
664 (typelist
[i
]->type
== TYPE_CDECL
) ? "c" : "p",
665 (typelist
[i
]->type
== TYPE_REGISTER
) ? "regs" :
666 (typelist
[i
]->type
== TYPE_INTERRUPT
) ? "intr" :
667 (typelist
[i
]->type
== TYPE_PASCAL_16
) ? "word" : "long",
668 typelist
[i
]->u
.func
.arg_types
);
670 if ( typelist
[i
]->type
!= TYPE_CDECL
)
671 for ( arg
= typelist
[i
]->u
.func
.arg_types
; *arg
; arg
++ )
675 case 's': /* s_word */
678 case 'l': /* long or segmented pointer */
679 case 'T': /* segmented pointer to null-terminated string */
680 case 'p': /* linear pointer */
681 case 't': /* linear pointer to null-terminated string */
686 if ( typelist
[i
]->type
== TYPE_INTERRUPT
)
689 fprintf( outfile
, " { 0x68, %s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
691 (typelist
[i
]->type
== TYPE_REGISTER
692 || typelist
[i
]->type
== TYPE_INTERRUPT
)? "regs":
693 typelist
[i
]->type
== TYPE_PASCAL_16
? "word" : "long" );
695 fprintf( outfile
, " 0x%04x, 0x66, 0xca, %d, \"%s\" },\n",
696 code_selector
, argsize
, profile
);
698 fprintf( outfile
, " 0x%04x, 0x66, 0xcb, 0x9090, \"%s\" },\n",
699 code_selector
, profile
);
701 code_offset
+= sizeof(CALLFROM16
);
703 fprintf( outfile
, " },\n {\n" );
705 for (i
= 0; i
<= Limit
; i
++)
707 ORDDEF
*odp
= Ordinals
[i
];
712 odp
->offset
= LOWORD(odp
->u
.abs
.value
);
716 odp
->offset
= data_offset
;
717 data_offset
+= StoreVariableCode( data
+ data_offset
, 4, odp
);
726 type
= bsearch( &odp
, typelist
, nTypes
, sizeof(ORDDEF
*), Spec16TypeCompare
);
729 fprintf( outfile
, " /* %s.%d */ ", DLLName
, i
);
730 fprintf( outfile
, "{ 0x5566, 0x68, %s, 0xe866, %d /* %s_%s_%s */ },\n",
732 (type
-typelist
)*sizeof(CALLFROM16
) -
733 (code_offset
+ sizeof(ENTRYPOINT16
)),
734 (odp
->type
== TYPE_CDECL
) ? "c" : "p",
735 (odp
->type
== TYPE_REGISTER
) ? "regs" :
736 (odp
->type
== TYPE_INTERRUPT
) ? "intr" :
737 (odp
->type
== TYPE_PASCAL_16
) ? "word" : "long",
738 odp
->u
.func
.arg_types
);
739 odp
->offset
= code_offset
;
740 code_offset
+= sizeof(ENTRYPOINT16
);
744 fprintf(stderr
,"build: function type %d not available for Win16\n",
750 fprintf( outfile
, " }\n};\n" );
752 /* Output data segment */
754 dump_bytes( outfile
, data
, data_offset
, "Data_Segment", 0 );
756 /* Build the module */
758 module_size
= BuildModule16( outfile
, code_offset
, data_offset
);
759 res_size
= output_res16_data( outfile
);
761 /* Output the DLL descriptor */
763 fprintf( outfile
, "\nstatic const BUILTIN16_DESCRIPTOR descriptor = \n{\n" );
764 fprintf( outfile
, " \"%s\",\n", DLLName
);
765 fprintf( outfile
, " Module,\n" );
766 fprintf( outfile
, " sizeof(Module),\n" );
767 fprintf( outfile
, " &Code_Segment,\n" );
768 fprintf( outfile
, " Data_Segment,\n" );
769 fprintf( outfile
, " \"%s\",\n", owner_name
);
770 fprintf( outfile
, " %s\n", res_size
? "resource_data" : "0" );
771 fprintf( outfile
, "};\n" );
773 /* Output the DLL constructor */
777 "static void __asm__dummy_dll_init(void) {\n"
778 "#endif /* defined(__GNUC__) */\n"
779 "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n"
780 " \"\\tcall " PREFIX
"__wine_spec_%s_init\\n\"\n"
781 " \"\\t.previous\\n\");\n"
784 "#endif /* defined(__GNUC__) */\n\n"
785 "void __wine_spec_%s_init(void)\n"
787 " __wine_register_dll_16( &descriptor );\n"
788 "}\n", DLLName
, DLLName
);
792 /*******************************************************************
795 * Build the 16-bit-to-Wine/Wine-to-16-bit callback glue code
797 void BuildGlue( FILE *outfile
, FILE *infile
)
803 fprintf( outfile
, "/* File generated automatically from %s; do not edit! */\n\n",
805 fprintf( outfile
, "#include \"stackframe.h\"\n\n" );
807 fprintf( outfile
, "extern WORD WINAPI wine_call_to_16_word( FARPROC16 target, INT nArgs );\n" );
808 fprintf( outfile
, "extern LONG WINAPI wine_call_to_16_long( FARPROC16 target, INT nArgs );\n" );
810 /* Build the callback glue functions */
812 while (fgets( buffer
, sizeof(buffer
), infile
))
814 if (strstr( buffer
, "### start build ###" )) break;
816 while (fgets( buffer
, sizeof(buffer
), infile
))
819 if ( (p
= strstr( buffer
, "CallFrom16_" )) != NULL
)
821 char *q
, *profile
= p
+ strlen( "CallFrom16_" );
822 for (q
= profile
; (*q
== '_') || isalpha(*q
); q
++ )
825 for (q
= p
-1; q
> buffer
&& ((*q
== '_') || isalnum(*q
)); q
-- )
827 if ( ++q
< p
) p
[-1] = '\0'; else q
= "";
828 BuildCallFrom16Func( outfile
, profile
, q
, FALSE
);
830 if ( (p
= strstr( buffer
, "CallTo16_" )) != NULL
)
832 char *q
, *profile
= p
+ strlen( "CallTo16_" );
833 for (q
= profile
; (*q
== '_') || isalpha(*q
); q
++ )
836 for (q
= p
-1; q
> buffer
&& ((*q
== '_') || isalnum(*q
)); q
-- )
838 if ( ++q
< p
) p
[-1] = '\0'; else q
= "";
839 BuildCallTo16Func( outfile
, profile
, q
);
841 if (strstr( buffer
, "### stop build ###" )) break;