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
12 #include "wine/port.h"
17 #include "wine/exception.h"
18 #include "builtin16.h"
20 #include "stackframe.h"
25 extern unsigned short __get_cs(void);
26 __ASM_GLOBAL_FUNC( __get_cs, "movw %cs,%ax\n\tret" );
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 );
88 memset( buffer, 0, 0x10000 );
90 pModule = (NE_MODULE *)buffer;
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;
132 pstr = (char *)(((long)pstr + 3) & ~3);
133 pSegment = (SEGTABLEENTRY *)pstr;
134 pModule->seg_table = (int)pSegment - (int)pModule;
135 pSegment->filepos = 0;
136 pSegment->size = max_code_offset;
138 pSegment->minsize = max_code_offset;
142 pModule->dgroup_entry = (int)pSegment - (int)pModule;
143 pSegment->filepos = 0;
144 pSegment->size = max_data_offset;
145 pSegment->flags = NE_SEGFLAGS_DATA;
146 pSegment->minsize = max_data_offset;
152 pstr = (char *)pSegment;
153 pstr = (char *)(((long)pstr + 3) & ~3);
154 pModule->res_table = (int)pstr - (int)pModule;
155 pstr += output_res16_directory( pstr );
157 /* Imported names table */
159 pstr = (char *)(((long)pstr + 3) & ~3);
160 pModule->import_table = (int)pstr - (int)pModule;
164 /* Resident names table */
166 pstr = (char *)(((long)pstr + 3) & ~3);
167 pModule->name_table = (int)pstr - (int)pModule;
168 /* First entry is module name */
169 *pstr = strlen( DLLName );
170 strcpy( pstr + 1, DLLName );
172 PUT_UA_WORD( pstr, 0 );
173 pstr += sizeof(WORD);
174 /* Store all ordinals */
175 for (i = 1; i <= Limit; i++)
177 ORDDEF *odp = Ordinals[i];
178 if (!odp || !odp->name[0]) continue;
179 *pstr = strlen( odp->name );
180 strcpy( pstr + 1, odp->name );
181 strupper( pstr + 1 );
183 PUT_UA_WORD( pstr, i );
184 pstr += sizeof(WORD);
190 pstr = (char *)(((long)pstr + 3) & ~3);
191 pModule->entry_table = (int)pstr - (int)pModule;
192 for (i = 1; i <= Limit; i++)
195 ORDDEF *odp = Ordinals[i];
206 selector = 1; /* Code selector */
210 selector = 2; /* Data selector */
214 selector = 0xfe; /* Constant selector */
218 selector = 0; /* Invalid selector */
225 if ( bundle && bundle->last+1 == i )
229 pstr = (char *)(((long)pstr + 1) & ~1);
231 bundle->next = (char *)pstr - (char *)pModule;
233 bundle = (ET_BUNDLE *)pstr;
237 pstr += sizeof(ET_BUNDLE);
240 /* FIXME: is this really correct ?? */
241 entry.type = 0xff; /* movable */
242 entry.flags = 3; /* exported & public data */
243 entry.segnum = selector;
244 entry.offs = odp->offset;
245 memcpy( pstr, &entry, sizeof(ET_ENTRY) );
246 pstr += sizeof(ET_ENTRY);
250 /* Dump the module content */
252 pstr = (char *)(((long)pstr + 3) & ~3);
253 dump_bytes( outfile, (char *)pModule, (int)pstr - (int)pModule, "Module", 0 );
254 return (int)pstr - (int)pModule;
258 /*******************************************************************
259 * BuildCallFrom16Func
261 * Build a 16-bit-to-Wine callback glue function.
263 * The generated routines are intended to be used as argument conversion
264 * routines to be called by the CallFrom16... core. Thus, the prototypes of
265 * the generated routines are (see also CallFrom16):
267 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
268 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
269 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
270 * CONTEXT86 *context );
271 * extern void WINAPI PREFIX_CallFrom16_C_intr_xxx( FARPROC func, LPBYTE args,
272 * CONTEXT86 *context );
274 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
275 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
276 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
277 * 'T'=segmented pointer to null-terminated string).
279 * The generated routines fetch the arguments from the 16-bit stack (pointed
280 * to by 'args'); the offsets of the single argument values are computed
281 * according to the calling convention and the argument types. Then, the
282 * 32-bit entry point is called with these arguments.
284 * For register functions, the arguments (if present) are converted just
285 * the same as for normal functions, but in addition the CONTEXT86 pointer
286 * filled with the current register values is passed to the 32-bit routine.
287 * (An 'intr' interrupt handler routine is treated exactly like a register
288 * routine, except that upon return, the flags word pushed onto the stack
289 * by the interrupt is removed by the 16-bit call stub.)
292 static void BuildCallFrom16Func( FILE *outfile, char *profile, char *prefix, int local )
294 int i, pos, argsize = 0;
298 char *args = profile + 7;
301 /* Parse function type */
303 if (!strncmp( "c_", profile, 2 )) usecdecl = 1;
304 else if (strncmp( "p_", profile, 2 ))
306 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
310 if (!strncmp( "word_", profile + 2, 5 )) short_ret = 1;
311 else if (!strncmp( "regs_", profile + 2, 5 )) reg_func = 1;
312 else if (!strncmp( "intr_", profile + 2, 5 )) reg_func = 2;
313 else if (strncmp( "long_", profile + 2, 5 ))
315 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
319 for ( i = 0; args[i]; i++ )
323 case 's': /* s_word */
327 case 'l': /* long or segmented pointer */
328 case 'T': /* segmented pointer to null-terminated string */
329 case 'p': /* linear pointer */
330 case 't': /* linear pointer to null-terminated string */
335 ret_type = reg_func? "void" : short_ret? "WORD" : "LONG";
337 fprintf( outfile, "typedef %s WINAPI (*proc_%s_t)( ",
340 for ( i = 0; args[i]; i++ )
342 if ( i ) fprintf( outfile, ", " );
345 case 'w': fprintf( outfile, "WORD" ); break;
346 case 's': fprintf( outfile, "INT16" ); break;
347 case 'l': case 'T': fprintf( outfile, "LONG" ); break;
348 case 'p': case 't': fprintf( outfile, "LPVOID" ); break;
352 fprintf( outfile, "%sstruct _CONTEXT86 *", i? ", " : "" );
354 fprintf( outfile, "void" );
355 fprintf( outfile, " );\n" );
357 fprintf( outfile, "%s%s WINAPI %s_CallFrom16_%s( FARPROC proc, LPBYTE args%s )\n{\n",
358 local? "static " : "", ret_type, prefix, profile,
359 reg_func? ", struct _CONTEXT86 *context" : "" );
361 fprintf( outfile, " %s((proc_%s_t) proc) (\n",
362 reg_func? "" : "return ", profile );
364 pos = !usecdecl? argsize : 0;
365 for ( i = 0; args[i]; i++ )
367 if ( i ) fprintf( outfile, ",\n" );
368 fprintf( outfile, " " );
372 if ( !usecdecl ) pos -= 2;
373 fprintf( outfile, "*(WORD *)(args+%d)", pos );
374 if ( usecdecl ) pos += 2;
377 case 's': /* s_word */
378 if ( !usecdecl ) pos -= 2;
379 fprintf( outfile, "*(INT16 *)(args+%d)", pos );
380 if ( usecdecl ) pos += 2;
383 case 'l': /* long or segmented pointer */
384 case 'T': /* segmented pointer to null-terminated string */
385 if ( !usecdecl ) pos -= 4;
386 fprintf( outfile, "*(LONG *)(args+%d)", pos );
387 if ( usecdecl ) pos += 4;
390 case 'p': /* linear pointer */
391 case 't': /* linear pointer to null-terminated string */
392 if ( !usecdecl ) pos -= 4;
393 fprintf( outfile, "((char*)wine_ldt_copy.base[*(WORD*)(args+%d) >> 3] + *(WORD*)(args+%d))",
395 if ( usecdecl ) pos += 4;
399 fprintf( stderr, "Unknown arg type '%c'\n", args[i] );
403 fprintf( outfile, "%s context", i? ",\n" : "" );
404 fprintf( outfile, " );\n}\n\n" );
408 /*******************************************************************
411 * Build a Wine-to-16-bit callback glue function.
413 * Prototypes for the CallTo16 functions:
414 * extern WORD CALLBACK PREFIX_CallTo16_word_xxx( FARPROC16 func, args... );
415 * extern LONG CALLBACK PREFIX_CallTo16_long_xxx( FARPROC16 func, args... );
417 * These routines are provided solely for convenience; they simply
418 * write the arguments onto the 16-bit stack, and call the appropriate
419 * wine_call_to_16... core routine.
421 * If you have more sophisticated argument conversion requirements than
422 * are provided by these routines, you might as well call the core
423 * routines by yourself.
426 static void BuildCallTo16Func( FILE *outfile, char *profile, char *prefix )
428 char *args = profile + 5;
429 int i, argsize = 0, short_ret = 0;
431 if (!strncmp( "word_", profile, 5 )) short_ret = 1;
432 else if (strncmp( "long_", profile, 5 ))
434 fprintf( stderr, "Invalid function name '%s'.\n", profile );
438 fprintf( outfile, "%s CALLBACK %s_CallTo16_%s( FARPROC16 proc",
439 short_ret? "WORD" : "LONG", prefix, profile );
441 for ( i = 0; args[i]; i++ )
443 fprintf( outfile, ", " );
446 case 'w': fprintf( outfile, "WORD" ); argsize += 2; break;
447 case 'l': fprintf( outfile, "LONG" ); argsize += 4; break;
449 fprintf( outfile, " arg%d", i+1 );
451 fprintf( outfile, " )\n{\n" );
454 fprintf( outfile, " LPBYTE args = (LPBYTE)CURRENT_STACK16;\n" );
457 for ( i = 0; args[i]; i++ )
461 case 'w': fprintf( outfile, " args -= sizeof(WORD); *(WORD" ); break;
462 case 'l': fprintf( outfile, " args -= sizeof(LONG); *(LONG" ); break;
463 default: fprintf( stderr, "Unexpected case '%c' in BuildCallTo16Func\n",
466 fprintf( outfile, " *)args = arg%d;\n", i+1 );
469 fprintf( outfile, " return wine_call_to_16_%s( proc, %d );\n}\n\n",
470 short_ret? "word" : "long", argsize );
474 /*******************************************************************
477 static int Spec16TypeCompare( const void *e1, const void *e2 )
479 const ORDDEF *odp1 = *(const ORDDEF **)e1;
480 const ORDDEF *odp2 = *(const ORDDEF **)e2;
482 int type1 = (odp1->type == TYPE_CDECL) ? 0
483 : (odp1->type == TYPE_REGISTER) ? 3
484 : (odp1->type == TYPE_INTERRUPT) ? 4
485 : (odp1->type == TYPE_PASCAL_16) ? 1 : 2;
487 int type2 = (odp2->type == TYPE_CDECL) ? 0
488 : (odp2->type == TYPE_REGISTER) ? 3
489 : (odp2->type == TYPE_INTERRUPT) ? 4
490 : (odp2->type == TYPE_PASCAL_16) ? 1 : 2;
492 int retval = type1 - type2;
494 retval = strcmp( odp1->u.func.arg_types, odp2->u.func.arg_types );
500 /*******************************************************************
503 * Output the functions for stub entry points
505 static void output_stub_funcs( FILE *outfile )
510 for (i = 0; i <= Limit; i++)
512 ORDDEF *odp = Ordinals[i];
513 if (!odp || odp->type != TYPE_STUB) continue;
514 fprintf( outfile, "#ifdef __GNUC__\n" );
515 fprintf( outfile, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
516 fprintf( outfile, "#endif\n" );
517 fprintf( outfile, "static void __wine_unimplemented( const char *func )\n{\n" );
518 fprintf( outfile, " struct exc_record {\n" );
519 fprintf( outfile, " unsigned int code, flags;\n" );
520 fprintf( outfile, " void *rec, *addr;\n" );
521 fprintf( outfile, " unsigned int params;\n" );
522 fprintf( outfile, " const void *info[15];\n" );
523 fprintf( outfile, " } rec;\n\n" );
524 fprintf( outfile, " extern void __stdcall RtlRaiseException( struct exc_record * );\n\n" );
525 fprintf( outfile, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB );
526 fprintf( outfile, " rec.flags = %d;\n", EH_NONCONTINUABLE );
527 fprintf( outfile, " rec.rec = 0;\n" );
528 fprintf( outfile, " rec.params = 2;\n" );
529 fprintf( outfile, " rec.info[0] = dllname;\n" );
530 fprintf( outfile, " rec.info[1] = func;\n" );
531 fprintf( outfile, "#ifdef __GNUC__\n" );
532 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
533 fprintf( outfile, "#else\n" );
534 fprintf( outfile, " rec.addr = 0;\n" );
535 fprintf( outfile, "#endif\n" );
536 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
539 for (i = 0; i <= Limit; i++)
541 ORDDEF *odp = Ordinals[i];
542 if (!odp || odp->type != TYPE_STUB) continue;
543 odp->link_name = xrealloc( odp->link_name, strlen(odp->name) + 13 );
544 strcpy( odp->link_name, "__wine_stub_" );
545 strcat( odp->link_name, odp->name );
546 for (p = odp->link_name; *p; p++) if (!isalnum(*p)) *p = '_';
547 fprintf( outfile, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
548 odp->link_name, odp->name );
553 /*******************************************************************
556 * Build a Win16 assembly file from a spec file.
558 void BuildSpec16File( FILE *outfile )
560 ORDDEF **type, **typelist;
561 int i, nFuncs, nTypes;
562 int code_offset, data_offset, module_size, res_size;
565 unsigned short code_selector = __get_cs();
570 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
572 fprintf( outfile, "#include \"builtin16.h\"\n\n" );
574 fprintf( outfile, "extern struct\n{\n" );
575 fprintf( outfile, " void *base[8192];\n" );
576 fprintf( outfile, " unsigned long limit[8192];\n" );
577 fprintf( outfile, " unsigned char flags[8192];\n" );
578 fprintf( outfile, "} wine_ldt_copy;\n\n" );
580 data = (unsigned char *)xmalloc( 0x10000 );
581 memset( data, 0, 16 );
585 fprintf( outfile, "static const char dllname[] = \"%s\";\n\n", DLLName );
588 fprintf( outfile, "#define __stdcall __attribute__((__stdcall__))\n\n" );
590 fprintf( outfile, "#define __stdcall\n\n" );
593 output_stub_funcs( outfile );
595 /* Build sorted list of all argument types, without duplicates */
597 typelist = (ORDDEF **)calloc( Limit+1, sizeof(ORDDEF *) );
599 for (i = nFuncs = 0; i <= Limit; i++)
601 ORDDEF *odp = Ordinals[i];
611 typelist[nFuncs++] = odp;
618 qsort( typelist, nFuncs, sizeof(ORDDEF *), Spec16TypeCompare );
623 typelist[nTypes++] = typelist[i++];
624 while ( i < nFuncs && Spec16TypeCompare( typelist + i, typelist + nTypes-1 ) == 0 )
628 /* Output CallFrom16 routines needed by this .spec file */
630 for ( i = 0; i < nTypes; i++ )
634 sprintf( profile, "%s_%s_%s",
635 (typelist[i]->type == TYPE_CDECL) ? "c" : "p",
636 (typelist[i]->type == TYPE_REGISTER) ? "regs" :
637 (typelist[i]->type == TYPE_INTERRUPT) ? "intr" :
638 (typelist[i]->type == TYPE_PASCAL_16) ? "word" : "long",
639 typelist[i]->u.func.arg_types );
641 BuildCallFrom16Func( outfile, profile, DLLName, TRUE );
645 /* Output the DLL functions prototypes */
647 for (i = 0; i <= Limit; i++)
649 ORDDEF *odp = Ordinals[i];
658 fprintf( outfile, "extern void %s();\n", odp->link_name );
665 /* Output code segment */
667 fprintf( outfile, "\nstatic struct\n{\n CALLFROM16 call[%d];\n"
668 " ENTRYPOINT16 entry[%d];\n} Code_Segment = \n{\n {\n",
672 for ( i = 0; i < nTypes; i++ )
674 char profile[101], *arg;
677 sprintf( profile, "%s_%s_%s",
678 (typelist[i]->type == TYPE_CDECL) ? "c" : "p",
679 (typelist[i]->type == TYPE_REGISTER) ? "regs" :
680 (typelist[i]->type == TYPE_INTERRUPT) ? "intr" :
681 (typelist[i]->type == TYPE_PASCAL_16) ? "word" : "long",
682 typelist[i]->u.func.arg_types );
684 if ( typelist[i]->type != TYPE_CDECL )
685 for ( arg = typelist[i]->u.func.arg_types; *arg; arg++ )
689 case 's': /* s_word */
692 case 'l': /* long or segmented pointer */
693 case 'T': /* segmented pointer to null-terminated string */
694 case 'p': /* linear pointer */
695 case 't': /* linear pointer to null-terminated string */
700 if ( typelist[i]->type == TYPE_INTERRUPT )
704 fprintf( outfile, " { 0x68, %s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
706 (typelist[i]->type == TYPE_REGISTER
707 || typelist[i]->type == TYPE_INTERRUPT)? "regs":
708 typelist[i]->type == TYPE_PASCAL_16? "word" : "long" );
710 fprintf( outfile, " 0x%04x, 0x66, 0xca, %d, \"%s\" },\n",
711 code_selector, argsize, profile );
713 fprintf( outfile, " 0x%04x, 0x66, 0xcb, 0x9090, \"%s\" },\n",
714 code_selector, profile );
716 fprintf( outfile, " { \"%s\" },\n", profile );
719 code_offset += sizeof(CALLFROM16);
721 fprintf( outfile, " },\n {\n" );
723 for (i = 0; i <= Limit; i++)
725 ORDDEF *odp = Ordinals[i];
730 odp->offset = LOWORD(odp->u.abs.value);
734 odp->offset = data_offset;
735 data_offset += StoreVariableCode( data + data_offset, 4, odp);
744 type = bsearch( &odp, typelist, nTypes, sizeof(ORDDEF *), Spec16TypeCompare );
747 fprintf( outfile, " /* %s.%d */ ", DLLName, i );
749 fprintf( outfile, "{ 0x5566, 0x68, %s, 0xe866, %d /* %s_%s_%s */ },\n",
751 fprintf( outfile, "{ %s, %d, /* %s_%s_%s */ },\n",
754 (type-typelist)*sizeof(CALLFROM16) -
755 (code_offset + sizeof(ENTRYPOINT16)),
756 (odp->type == TYPE_CDECL) ? "c" : "p",
757 (odp->type == TYPE_REGISTER) ? "regs" :
758 (odp->type == TYPE_INTERRUPT) ? "intr" :
759 (odp->type == TYPE_PASCAL_16) ? "word" : "long",
760 odp->u.func.arg_types );
762 odp->offset = code_offset;
763 code_offset += sizeof(ENTRYPOINT16);
767 fprintf(stderr,"build: function type %d not available for Win16\n",
773 fprintf( outfile, " }\n};\n" );
775 /* Output data segment */
777 dump_bytes( outfile, data, data_offset, "Data_Segment", 0 );
779 /* Build the module */
781 module_size = BuildModule16( outfile, code_offset, data_offset );
782 res_size = output_res16_data( outfile );
784 /* Output the DLL descriptor */
786 fprintf( outfile, "\nstatic const BUILTIN16_DESCRIPTOR descriptor = \n{\n" );
787 fprintf( outfile, " Module,\n" );
788 fprintf( outfile, " sizeof(Module),\n" );
789 fprintf( outfile, " &Code_Segment,\n" );
790 fprintf( outfile, " Data_Segment,\n" );
791 fprintf( outfile, " \"%s\",\n", owner_name );
792 fprintf( outfile, " %s\n", res_size ? "resource_data" : "0" );
793 fprintf( outfile, "};\n" );
795 /* Output the DLL constructor */
797 fprintf( outfile, "#ifndef __GNUC__\n" );
798 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
799 fprintf( outfile, "#endif /* defined(__GNUC__) */\n" );
801 #if defined(__i386__)
802 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
803 fprintf( outfile, " \"\\tcall " PREFIX "__wine_spec_%s_init\\n\"\n", DLLName );
804 fprintf( outfile, " \"\\t.previous\\n\");\n" );
805 #elif defined(__sparc__)
806 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
807 fprintf( outfile, " \"\\tcall " PREFIX "__wine_spec_%s_init\\n\"\n", DLLName );
808 fprintf( outfile, " \"\\tnop\\n\"\n" );
809 fprintf( outfile, " \"\\t.previous\\n\");\n" );
810 #elif defined(__PPC__)
811 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
812 fprintf( outfile, " \"\\tbl " PREFIX "__wine_spec_%s_init\\n\"\n", DLLName );
813 fprintf( outfile, " \"\\t.previous\\n\");\n" );
815 #error You need to define the DLL constructor for your architecture
818 fprintf( outfile, "#ifndef __GNUC__\n" );
819 fprintf( outfile, "}\n" );
820 fprintf( outfile, "#endif /* defined(__GNUC__) */\n\n" );
823 "void __wine_spec_%s_init(void)\n"
825 " __wine_register_dll_16( &descriptor );\n"
830 /*******************************************************************
833 * Build the 16-bit-to-Wine/Wine-to-16-bit callback glue code
835 void BuildGlue( FILE *outfile, FILE *infile )
841 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
843 fprintf( outfile, "#include \"stackframe.h\"\n\n" );
845 fprintf( outfile, "extern WORD WINAPI wine_call_to_16_word( FARPROC16 target, INT nArgs );\n" );
846 fprintf( outfile, "extern LONG WINAPI wine_call_to_16_long( FARPROC16 target, INT nArgs );\n" );
848 /* Build the callback glue functions */
850 while (fgets( buffer, sizeof(buffer), infile ))
852 if (strstr( buffer, "### start build ###" )) break;
854 while (fgets( buffer, sizeof(buffer), infile ))
857 if ( (p = strstr( buffer, "CallFrom16_" )) != NULL )
859 char *q, *profile = p + strlen( "CallFrom16_" );
860 for (q = profile; (*q == '_') || isalpha(*q); q++ )
863 for (q = p-1; q > buffer && ((*q == '_') || isalnum(*q)); q-- )
865 if ( ++q < p ) p[-1] = '\0'; else q = "";
866 BuildCallFrom16Func( outfile, profile, q, FALSE );
868 if ( (p = strstr( buffer, "CallTo16_" )) != NULL )
870 char *q, *profile = p + strlen( "CallTo16_" );
871 for (q = profile; (*q == '_') || isalpha(*q); q++ )
874 for (q = p-1; q > buffer && ((*q == '_') || isalnum(*q)); q-- )
876 if ( ++q < p ) p[-1] = '\0'; else q = "";
877 BuildCallTo16Func( outfile, profile, q );
879 if (strstr( buffer, "### stop build ###" )) break;