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/port.h"
16 #include "wine/exception.h"
17 #include "builtin16.h"
19 #include "stackframe.h"
24 extern unsigned short __get_cs(void);
25 __ASM_GLOBAL_FUNC( __get_cs
, "movw %cs,%ax\n\tret" );
29 /*******************************************************************
32 * Store a list of ints into a byte array.
34 static int StoreVariableCode( unsigned char *buffer
, int size
, ORDDEF
*odp
)
41 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
42 buffer
[i
] = odp
->u
.var
.values
[i
];
45 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
46 ((unsigned short *)buffer
)[i
] = odp
->u
.var
.values
[i
];
49 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
50 ((unsigned int *)buffer
)[i
] = odp
->u
.var
.values
[i
];
53 return odp
->u
.var
.n_values
* size
;
57 /*******************************************************************
60 * Build the in-memory representation of a 16-bit NE module, and dump it
61 * as a byte stream into the assembly code.
63 static int BuildModule16( FILE *outfile
, int max_code_offset
,
69 SEGTABLEENTRY
*pSegment
;
72 ET_BUNDLE
*bundle
= 0;
77 * OFSTRUCT File information
78 * SEGTABLEENTRY Segment 1 (code)
79 * SEGTABLEENTRY Segment 2 (data)
80 * WORD[2] Resource table (empty)
81 * BYTE[2] Imported names (empty)
82 * BYTE[n] Resident names table
86 buffer
= xmalloc( 0x10000 );
87 memset( buffer
, 0, 0x10000 );
89 pModule
= (NE_MODULE
*)buffer
;
90 pModule
->magic
= IMAGE_OS2_SIGNATURE
;
93 pModule
->flags
= NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_BUILTIN
| NE_FFLAGS_LIBMODULE
;
95 pModule
->heap_size
= DLLHeapSize
;
96 pModule
->stack_size
= 0;
101 pModule
->seg_count
= 2;
102 pModule
->modref_count
= 0;
103 pModule
->nrname_size
= 0;
104 pModule
->modref_table
= 0;
105 pModule
->nrname_fpos
= 0;
106 pModule
->moveable_entries
= 0;
107 pModule
->alignment
= 0;
108 pModule
->truetype
= 0;
109 pModule
->os_flags
= NE_OSFLAGS_WINDOWS
;
110 pModule
->misc_flags
= 0;
111 pModule
->dlls_to_init
= 0;
112 pModule
->nrname_handle
= 0;
113 pModule
->min_swap_area
= 0;
114 pModule
->expected_version
= 0;
115 pModule
->module32
= 0;
117 pModule
->self_loading_sel
= 0;
119 /* File information */
121 pFileInfo
= (OFSTRUCT
*)(pModule
+ 1);
122 pModule
->fileinfo
= (int)pFileInfo
- (int)pModule
;
123 memset( pFileInfo
, 0, sizeof(*pFileInfo
) - sizeof(pFileInfo
->szPathName
) );
124 pFileInfo
->cBytes
= sizeof(*pFileInfo
) - sizeof(pFileInfo
->szPathName
)
125 + strlen(DLLFileName
);
126 strcpy( pFileInfo
->szPathName
, DLLFileName
);
127 pstr
= (char *)pFileInfo
+ pFileInfo
->cBytes
+ 1;
131 pstr
= (char *)(((long)pstr
+ 3) & ~3);
132 pSegment
= (SEGTABLEENTRY
*)pstr
;
133 pModule
->seg_table
= (int)pSegment
- (int)pModule
;
134 pSegment
->filepos
= 0;
135 pSegment
->size
= max_code_offset
;
137 pSegment
->minsize
= max_code_offset
;
141 pModule
->dgroup_entry
= (int)pSegment
- (int)pModule
;
142 pSegment
->filepos
= 0;
143 pSegment
->size
= max_data_offset
;
144 pSegment
->flags
= NE_SEGFLAGS_DATA
;
145 pSegment
->minsize
= max_data_offset
;
151 pstr
= (char *)pSegment
;
152 pstr
= (char *)(((long)pstr
+ 3) & ~3);
153 pModule
->res_table
= (int)pstr
- (int)pModule
;
154 pstr
+= output_res16_directory( pstr
);
156 /* Imported names table */
158 pstr
= (char *)(((long)pstr
+ 3) & ~3);
159 pModule
->import_table
= (int)pstr
- (int)pModule
;
163 /* Resident names table */
165 pstr
= (char *)(((long)pstr
+ 3) & ~3);
166 pModule
->name_table
= (int)pstr
- (int)pModule
;
167 /* First entry is module name */
168 *pstr
= strlen( DLLName
);
169 strcpy( pstr
+ 1, DLLName
);
171 PUT_UA_WORD( pstr
, 0 );
172 pstr
+= sizeof(WORD
);
173 /* Store all ordinals */
174 for (i
= 1; i
<= Limit
; i
++)
176 ORDDEF
*odp
= Ordinals
[i
];
177 if (!odp
|| !odp
->name
[0]) continue;
178 *pstr
= strlen( odp
->name
);
179 strcpy( pstr
+ 1, odp
->name
);
180 strupper( pstr
+ 1 );
182 PUT_UA_WORD( pstr
, i
);
183 pstr
+= sizeof(WORD
);
189 pstr
= (char *)(((long)pstr
+ 3) & ~3);
190 pModule
->entry_table
= (int)pstr
- (int)pModule
;
191 for (i
= 1; i
<= Limit
; i
++)
194 ORDDEF
*odp
= Ordinals
[i
];
205 selector
= 1; /* Code selector */
209 selector
= 2; /* Data selector */
213 selector
= 0xfe; /* Constant selector */
217 selector
= 0; /* Invalid selector */
224 if ( bundle
&& bundle
->last
+1 == i
)
228 pstr
= (char *)(((long)pstr
+ 1) & ~1);
230 bundle
->next
= (char *)pstr
- (char *)pModule
;
232 bundle
= (ET_BUNDLE
*)pstr
;
236 pstr
+= sizeof(ET_BUNDLE
);
239 /* FIXME: is this really correct ?? */
240 entry
.type
= 0xff; /* movable */
241 entry
.flags
= 3; /* exported & public data */
242 entry
.segnum
= selector
;
243 entry
.offs
= odp
->offset
;
244 memcpy( pstr
, &entry
, sizeof(ET_ENTRY
) );
245 pstr
+= sizeof(ET_ENTRY
);
249 /* Dump the module content */
251 pstr
= (char *)(((long)pstr
+ 3) & ~3);
252 dump_bytes( outfile
, (char *)pModule
, (int)pstr
- (int)pModule
, "Module", 0 );
253 return (int)pstr
- (int)pModule
;
257 /*******************************************************************
258 * BuildCallFrom16Func
260 * Build a 16-bit-to-Wine callback glue function.
262 * The generated routines are intended to be used as argument conversion
263 * routines to be called by the CallFrom16... core. Thus, the prototypes of
264 * the generated routines are (see also CallFrom16):
266 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
267 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
268 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
269 * CONTEXT86 *context );
270 * extern void WINAPI PREFIX_CallFrom16_C_intr_xxx( FARPROC func, LPBYTE args,
271 * CONTEXT86 *context );
273 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
274 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
275 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
276 * 'T'=segmented pointer to null-terminated string).
278 * The generated routines fetch the arguments from the 16-bit stack (pointed
279 * to by 'args'); the offsets of the single argument values are computed
280 * according to the calling convention and the argument types. Then, the
281 * 32-bit entry point is called with these arguments.
283 * For register functions, the arguments (if present) are converted just
284 * the same as for normal functions, but in addition the CONTEXT86 pointer
285 * filled with the current register values is passed to the 32-bit routine.
286 * (An 'intr' interrupt handler routine is treated exactly like a register
287 * routine, except that upon return, the flags word pushed onto the stack
288 * by the interrupt is removed by the 16-bit call stub.)
291 static void BuildCallFrom16Func( FILE *outfile
, char *profile
, char *prefix
, int local
)
293 int i
, pos
, argsize
= 0;
297 char *args
= profile
+ 7;
300 /* Parse function type */
302 if (!strncmp( "c_", profile
, 2 )) usecdecl
= 1;
303 else if (strncmp( "p_", profile
, 2 ))
305 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
309 if (!strncmp( "word_", profile
+ 2, 5 )) short_ret
= 1;
310 else if (!strncmp( "regs_", profile
+ 2, 5 )) reg_func
= 1;
311 else if (!strncmp( "intr_", profile
+ 2, 5 )) reg_func
= 2;
312 else if (strncmp( "long_", profile
+ 2, 5 ))
314 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
318 for ( i
= 0; args
[i
]; i
++ )
322 case 's': /* s_word */
326 case 'l': /* long or segmented pointer */
327 case 'T': /* segmented pointer to null-terminated string */
328 case 'p': /* linear pointer */
329 case 't': /* linear pointer to null-terminated string */
334 ret_type
= reg_func
? "void" : short_ret
? "WORD" : "LONG";
336 fprintf( outfile
, "typedef %s WINAPI (*proc_%s_t)( ",
339 for ( i
= 0; args
[i
]; i
++ )
341 if ( i
) fprintf( outfile
, ", " );
344 case 'w': fprintf( outfile
, "WORD" ); break;
345 case 's': fprintf( outfile
, "INT16" ); break;
346 case 'l': case 'T': fprintf( outfile
, "LONG" ); break;
347 case 'p': case 't': fprintf( outfile
, "LPVOID" ); break;
351 fprintf( outfile
, "%sstruct _CONTEXT86 *", i
? ", " : "" );
353 fprintf( outfile
, "void" );
354 fprintf( outfile
, " );\n" );
356 fprintf( outfile
, "%s%s WINAPI %s_CallFrom16_%s( FARPROC proc, LPBYTE args%s )\n{\n",
357 local
? "static " : "", ret_type
, prefix
, profile
,
358 reg_func
? ", struct _CONTEXT86 *context" : "" );
360 fprintf( outfile
, " %s((proc_%s_t) proc) (\n",
361 reg_func
? "" : "return ", profile
);
363 pos
= !usecdecl
? argsize
: 0;
364 for ( i
= 0; args
[i
]; i
++ )
366 if ( i
) fprintf( outfile
, ",\n" );
367 fprintf( outfile
, " " );
371 if ( !usecdecl
) pos
-= 2;
372 fprintf( outfile
, "*(WORD *)(args+%d)", pos
);
373 if ( usecdecl
) pos
+= 2;
376 case 's': /* s_word */
377 if ( !usecdecl
) pos
-= 2;
378 fprintf( outfile
, "*(INT16 *)(args+%d)", pos
);
379 if ( usecdecl
) pos
+= 2;
382 case 'l': /* long or segmented pointer */
383 case 'T': /* segmented pointer to null-terminated string */
384 if ( !usecdecl
) pos
-= 4;
385 fprintf( outfile
, "*(LONG *)(args+%d)", pos
);
386 if ( usecdecl
) pos
+= 4;
389 case 'p': /* linear pointer */
390 case 't': /* linear pointer to null-terminated string */
391 if ( !usecdecl
) pos
-= 4;
392 fprintf( outfile
, "((char*)wine_ldt_copy.base[*(WORD*)(args+%d) >> 3] + *(WORD*)(args+%d))",
394 if ( usecdecl
) pos
+= 4;
398 fprintf( stderr
, "Unknown arg type '%c'\n", args
[i
] );
402 fprintf( outfile
, "%s context", i
? ",\n" : "" );
403 fprintf( outfile
, " );\n}\n\n" );
407 /*******************************************************************
410 * Build a Wine-to-16-bit callback glue function.
412 * Prototypes for the CallTo16 functions:
413 * extern WORD CALLBACK PREFIX_CallTo16_word_xxx( FARPROC16 func, args... );
414 * extern LONG CALLBACK PREFIX_CallTo16_long_xxx( FARPROC16 func, args... );
416 * These routines are provided solely for convenience; they simply
417 * write the arguments onto the 16-bit stack, and call the appropriate
418 * wine_call_to_16... core routine.
420 * If you have more sophisticated argument conversion requirements than
421 * are provided by these routines, you might as well call the core
422 * routines by yourself.
425 static void BuildCallTo16Func( FILE *outfile
, char *profile
, char *prefix
)
427 char *args
= profile
+ 5;
428 int i
, argsize
= 0, short_ret
= 0;
430 if (!strncmp( "word_", profile
, 5 )) short_ret
= 1;
431 else if (strncmp( "long_", profile
, 5 ))
433 fprintf( stderr
, "Invalid function name '%s'.\n", profile
);
437 fprintf( outfile
, "%s %s_CallTo16_%s( FARPROC16 proc",
438 short_ret
? "WORD" : "LONG", prefix
, profile
);
440 for ( i
= 0; args
[i
]; i
++ )
442 fprintf( outfile
, ", " );
445 case 'w': fprintf( outfile
, "WORD" ); argsize
+= 2; break;
446 case 'l': fprintf( outfile
, "LONG" ); argsize
+= 4; break;
448 fprintf( outfile
, " arg%d", i
+1 );
450 fprintf( outfile
, " )\n{\n" );
453 fprintf( outfile
, " LPBYTE args = (LPBYTE)CURRENT_STACK16;\n" );
456 for ( i
= 0; args
[i
]; i
++ )
460 case 'w': fprintf( outfile
, " args -= sizeof(WORD); *(WORD" ); break;
461 case 'l': fprintf( outfile
, " args -= sizeof(LONG); *(LONG" ); break;
462 default: fprintf( stderr
, "Unexpected case '%c' in BuildCallTo16Func\n",
465 fprintf( outfile
, " *)args = arg%d;\n", i
+1 );
468 fprintf( outfile
, " return wine_call_to_16_%s( proc, %d );\n}\n\n",
469 short_ret
? "word" : "long", argsize
);
473 /*******************************************************************
476 static int Spec16TypeCompare( const void *e1
, const void *e2
)
478 const ORDDEF
*odp1
= *(const ORDDEF
**)e1
;
479 const ORDDEF
*odp2
= *(const ORDDEF
**)e2
;
481 int type1
= (odp1
->type
== TYPE_CDECL
) ? 0
482 : (odp1
->type
== TYPE_REGISTER
) ? 3
483 : (odp1
->type
== TYPE_INTERRUPT
) ? 4
484 : (odp1
->type
== TYPE_PASCAL_16
) ? 1 : 2;
486 int type2
= (odp2
->type
== TYPE_CDECL
) ? 0
487 : (odp2
->type
== TYPE_REGISTER
) ? 3
488 : (odp2
->type
== TYPE_INTERRUPT
) ? 4
489 : (odp2
->type
== TYPE_PASCAL_16
) ? 1 : 2;
491 int retval
= type1
- type2
;
493 retval
= strcmp( odp1
->u
.func
.arg_types
, odp2
->u
.func
.arg_types
);
499 /*******************************************************************
502 * Output the functions for stub entry points
504 static void output_stub_funcs( FILE *outfile
)
509 for (i
= 0; i
<= Limit
; i
++)
511 ORDDEF
*odp
= Ordinals
[i
];
512 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
513 fprintf( outfile
, "#ifdef __GNUC__\n" );
514 fprintf( outfile
, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
515 fprintf( outfile
, "#endif\n" );
516 fprintf( outfile
, "static void __wine_unimplemented( const char *func )\n{\n" );
517 fprintf( outfile
, " struct exc_record {\n" );
518 fprintf( outfile
, " unsigned int code, flags;\n" );
519 fprintf( outfile
, " void *rec, *addr;\n" );
520 fprintf( outfile
, " unsigned int params;\n" );
521 fprintf( outfile
, " const void *info[15];\n" );
522 fprintf( outfile
, " } rec;\n" );
523 fprintf( outfile
, " extern void RtlRaiseException( struct exc_record * );\n\n" );
524 fprintf( outfile
, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB
);
525 fprintf( outfile
, " rec.flags = %d;\n", EH_NONCONTINUABLE
);
526 fprintf( outfile
, " rec.rec = 0;\n" );
527 fprintf( outfile
, " rec.params = 2;\n" );
528 fprintf( outfile
, " rec.info[0] = dllname;\n" );
529 fprintf( outfile
, " rec.info[1] = func;\n" );
530 fprintf( outfile
, "#ifdef __GNUC__\n" );
531 fprintf( outfile
, " rec.addr = __builtin_return_address(1);\n" );
532 fprintf( outfile
, "#else\n" );
533 fprintf( outfile
, " rec.addr = 0;\n" );
534 fprintf( outfile
, "#endif\n" );
535 fprintf( outfile
, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
538 for (i
= 0; i
<= Limit
; i
++)
540 ORDDEF
*odp
= Ordinals
[i
];
541 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
542 odp
->link_name
= xrealloc( odp
->link_name
, strlen(odp
->name
) + 13 );
543 strcpy( odp
->link_name
, "__wine_stub_" );
544 strcat( odp
->link_name
, odp
->name
);
545 for (p
= odp
->link_name
; *p
; p
++) if (!isalnum(*p
)) *p
= '_';
546 fprintf( outfile
, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
547 odp
->link_name
, odp
->name
);
552 /*******************************************************************
555 * Build a Win16 assembly file from a spec file.
557 void BuildSpec16File( FILE *outfile
)
559 ORDDEF
**type
, **typelist
;
560 int i
, nFuncs
, nTypes
;
561 int code_offset
, data_offset
, module_size
, res_size
;
564 unsigned short code_selector
= __get_cs();
569 fprintf( outfile
, "/* File generated automatically from %s; do not edit! */\n\n",
571 fprintf( outfile
, "#include \"builtin16.h\"\n\n" );
573 fprintf( outfile
, "extern struct\n{\n" );
574 fprintf( outfile
, " void *base[8192];\n" );
575 fprintf( outfile
, " unsigned long limit[8192];\n" );
576 fprintf( outfile
, " unsigned char flags[8192];\n" );
577 fprintf( outfile
, "} wine_ldt_copy;\n\n" );
579 data
= (unsigned char *)xmalloc( 0x10000 );
580 memset( data
, 0, 16 );
584 fprintf( outfile
, "static const char dllname[] = \"%s\";\n\n", DLLName
);
585 output_stub_funcs( outfile
);
587 /* Build sorted list of all argument types, without duplicates */
589 typelist
= (ORDDEF
**)calloc( Limit
+1, sizeof(ORDDEF
*) );
591 for (i
= nFuncs
= 0; i
<= Limit
; i
++)
593 ORDDEF
*odp
= Ordinals
[i
];
603 typelist
[nFuncs
++] = odp
;
610 qsort( typelist
, nFuncs
, sizeof(ORDDEF
*), Spec16TypeCompare
);
615 typelist
[nTypes
++] = typelist
[i
++];
616 while ( i
< nFuncs
&& Spec16TypeCompare( typelist
+ i
, typelist
+ nTypes
-1 ) == 0 )
620 /* Output CallFrom16 routines needed by this .spec file */
622 for ( i
= 0; i
< nTypes
; i
++ )
626 sprintf( profile
, "%s_%s_%s",
627 (typelist
[i
]->type
== TYPE_CDECL
) ? "c" : "p",
628 (typelist
[i
]->type
== TYPE_REGISTER
) ? "regs" :
629 (typelist
[i
]->type
== TYPE_INTERRUPT
) ? "intr" :
630 (typelist
[i
]->type
== TYPE_PASCAL_16
) ? "word" : "long",
631 typelist
[i
]->u
.func
.arg_types
);
633 BuildCallFrom16Func( outfile
, profile
, DLLName
, TRUE
);
637 /* Output the DLL functions prototypes */
639 for (i
= 0; i
<= Limit
; i
++)
641 ORDDEF
*odp
= Ordinals
[i
];
650 fprintf( outfile
, "extern void %s();\n", odp
->link_name
);
657 /* Output code segment */
659 fprintf( outfile
, "\nstatic struct\n{\n CALLFROM16 call[%d];\n"
660 " ENTRYPOINT16 entry[%d];\n} Code_Segment = \n{\n {\n",
664 for ( i
= 0; i
< nTypes
; i
++ )
666 char profile
[101], *arg
;
669 sprintf( profile
, "%s_%s_%s",
670 (typelist
[i
]->type
== TYPE_CDECL
) ? "c" : "p",
671 (typelist
[i
]->type
== TYPE_REGISTER
) ? "regs" :
672 (typelist
[i
]->type
== TYPE_INTERRUPT
) ? "intr" :
673 (typelist
[i
]->type
== TYPE_PASCAL_16
) ? "word" : "long",
674 typelist
[i
]->u
.func
.arg_types
);
676 if ( typelist
[i
]->type
!= TYPE_CDECL
)
677 for ( arg
= typelist
[i
]->u
.func
.arg_types
; *arg
; arg
++ )
681 case 's': /* s_word */
684 case 'l': /* long or segmented pointer */
685 case 'T': /* segmented pointer to null-terminated string */
686 case 'p': /* linear pointer */
687 case 't': /* linear pointer to null-terminated string */
692 if ( typelist
[i
]->type
== TYPE_INTERRUPT
)
696 fprintf( outfile
, " { 0x68, %s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
698 (typelist
[i
]->type
== TYPE_REGISTER
699 || typelist
[i
]->type
== TYPE_INTERRUPT
)? "regs":
700 typelist
[i
]->type
== TYPE_PASCAL_16
? "word" : "long" );
702 fprintf( outfile
, " 0x%04x, 0x66, 0xca, %d, \"%s\" },\n",
703 code_selector
, argsize
, profile
);
705 fprintf( outfile
, " 0x%04x, 0x66, 0xcb, 0x9090, \"%s\" },\n",
706 code_selector
, profile
);
708 fprintf( outfile
, " { \"%s\" },\n", profile
);
711 code_offset
+= sizeof(CALLFROM16
);
713 fprintf( outfile
, " },\n {\n" );
715 for (i
= 0; i
<= Limit
; i
++)
717 ORDDEF
*odp
= Ordinals
[i
];
722 odp
->offset
= LOWORD(odp
->u
.abs
.value
);
726 odp
->offset
= data_offset
;
727 data_offset
+= StoreVariableCode( data
+ data_offset
, 4, odp
);
736 type
= bsearch( &odp
, typelist
, nTypes
, sizeof(ORDDEF
*), Spec16TypeCompare
);
739 fprintf( outfile
, " /* %s.%d */ ", DLLName
, i
);
741 fprintf( outfile
, "{ 0x5566, 0x68, %s, 0xe866, %d /* %s_%s_%s */ },\n",
743 fprintf( outfile
, "{ %s, %d, /* %s_%s_%s */ },\n",
746 (type
-typelist
)*sizeof(CALLFROM16
) -
747 (code_offset
+ sizeof(ENTRYPOINT16
)),
748 (odp
->type
== TYPE_CDECL
) ? "c" : "p",
749 (odp
->type
== TYPE_REGISTER
) ? "regs" :
750 (odp
->type
== TYPE_INTERRUPT
) ? "intr" :
751 (odp
->type
== TYPE_PASCAL_16
) ? "word" : "long",
752 odp
->u
.func
.arg_types
);
754 odp
->offset
= code_offset
;
755 code_offset
+= sizeof(ENTRYPOINT16
);
759 fprintf(stderr
,"build: function type %d not available for Win16\n",
765 fprintf( outfile
, " }\n};\n" );
767 /* Output data segment */
769 dump_bytes( outfile
, data
, data_offset
, "Data_Segment", 0 );
771 /* Build the module */
773 module_size
= BuildModule16( outfile
, code_offset
, data_offset
);
774 res_size
= output_res16_data( outfile
);
776 /* Output the DLL descriptor */
778 fprintf( outfile
, "\nstatic const BUILTIN16_DESCRIPTOR descriptor = \n{\n" );
779 fprintf( outfile
, " \"%s\",\n", DLLName
);
780 fprintf( outfile
, " Module,\n" );
781 fprintf( outfile
, " sizeof(Module),\n" );
782 fprintf( outfile
, " &Code_Segment,\n" );
783 fprintf( outfile
, " Data_Segment,\n" );
784 fprintf( outfile
, " \"%s\",\n", owner_name
);
785 fprintf( outfile
, " %s\n", res_size
? "resource_data" : "0" );
786 fprintf( outfile
, "};\n" );
788 /* Output the DLL constructor */
790 fprintf( outfile
, "#ifndef __GNUC__\n" );
791 fprintf( outfile
, "static void __asm__dummy_dll_init(void) {\n" );
792 fprintf( outfile
, "#endif /* defined(__GNUC__) */\n" );
794 #if defined(__i386__)
795 fprintf( outfile
, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
796 fprintf( outfile
, " \"\\tcall " PREFIX
"__wine_spec_%s_init\\n\"\n", DLLName
);
797 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
798 #elif defined(__sparc__)
799 fprintf( outfile
, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
800 fprintf( outfile
, " \"\\tcall " PREFIX
"__wine_spec_%s_init\\n\"\n", DLLName
);
801 fprintf( outfile
, " \"\\tnop\\n\"\n" );
802 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
803 #elif defined(__PPC__)
804 fprintf( outfile
, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
805 fprintf( outfile
, " \"\\tbl " PREFIX
"__wine_spec_%s_init\\n\"\n", DLLName
);
806 fprintf( outfile
, " \"\\t.previous\\n\");\n" );
808 #error You need to define the DLL constructor for your architecture
811 fprintf( outfile
, "#ifndef __GNUC__\n" );
812 fprintf( outfile
, "}\n" );
813 fprintf( outfile
, "#endif /* defined(__GNUC__) */\n\n" );
816 "void __wine_spec_%s_init(void)\n"
818 " __wine_register_dll_16( &descriptor );\n"
823 /*******************************************************************
826 * Build the 16-bit-to-Wine/Wine-to-16-bit callback glue code
828 void BuildGlue( FILE *outfile
, FILE *infile
)
834 fprintf( outfile
, "/* File generated automatically from %s; do not edit! */\n\n",
836 fprintf( outfile
, "#include \"stackframe.h\"\n\n" );
838 fprintf( outfile
, "extern WORD WINAPI wine_call_to_16_word( FARPROC16 target, INT nArgs );\n" );
839 fprintf( outfile
, "extern LONG WINAPI wine_call_to_16_long( FARPROC16 target, INT nArgs );\n" );
841 /* Build the callback glue functions */
843 while (fgets( buffer
, sizeof(buffer
), infile
))
845 if (strstr( buffer
, "### start build ###" )) break;
847 while (fgets( buffer
, sizeof(buffer
), infile
))
850 if ( (p
= strstr( buffer
, "CallFrom16_" )) != NULL
)
852 char *q
, *profile
= p
+ strlen( "CallFrom16_" );
853 for (q
= profile
; (*q
== '_') || isalpha(*q
); q
++ )
856 for (q
= p
-1; q
> buffer
&& ((*q
== '_') || isalnum(*q
)); q
-- )
858 if ( ++q
< p
) p
[-1] = '\0'; else q
= "";
859 BuildCallFrom16Func( outfile
, profile
, q
, FALSE
);
861 if ( (p
= strstr( buffer
, "CallTo16_" )) != NULL
)
863 char *q
, *profile
= p
+ strlen( "CallTo16_" );
864 for (q
= profile
; (*q
== '_') || isalpha(*q
); q
++ )
867 for (q
= p
-1; q
> buffer
&& ((*q
== '_') || isalnum(*q
)); q
-- )
869 if ( ++q
< p
) p
[-1] = '\0'; else q
= "";
870 BuildCallTo16Func( outfile
, profile
, q
);
872 if (strstr( buffer
, "### stop build ###" )) break;