4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/exception.h"
31 #include "wine/winbase16.h"
36 /*******************************************************************
39 static inline unsigned short get_cs(void)
41 unsigned short res
= 0;
44 __asm__("movw %%cs,%w0" : "=r"(res
));
45 # elif defined(_MSC_VER)
53 /*******************************************************************
56 * Output a file header with the common declarations we need.
58 static void output_file_header( FILE *outfile
)
60 output_standard_file_header( outfile
);
61 fprintf( outfile
, "extern struct\n{\n" );
62 fprintf( outfile
, " void *base[8192];\n" );
63 fprintf( outfile
, " unsigned long limit[8192];\n" );
64 fprintf( outfile
, " unsigned char flags[8192];\n" );
65 fprintf( outfile
, "} wine_ldt_copy;\n\n" );
66 fprintf( outfile
, "#define __stdcall __attribute__((__stdcall__))\n\n" );
70 /*******************************************************************
73 static int output_entry_table( unsigned char **ret_buff
, DLLSPEC
*spec
)
75 int i
, prev
= 0, prev_sel
= -1;
76 unsigned char *pstr
, *buffer
;
77 unsigned char *bundle
= NULL
;
79 buffer
= xmalloc( spec
->limit
* 5 ); /* we use at most 5 bytes per entry-point */
82 for (i
= 1; i
<= spec
->limit
; i
++)
86 ORDDEF
*odp
= spec
->ordinals
[i
];
95 selector
= 1; /* Code selector */
98 selector
= 2; /* Data selector */
101 selector
= 0xfe; /* Constant selector */
107 if (!bundle
|| prev
+ 1 != i
|| prev_sel
!= selector
|| *bundle
== 255)
109 /* need to start a new bundle */
113 int skip
= i
- (prev
+ 1);
129 /* output the entry */
130 *pstr
++ = 3; /* flags: exported & public data */
131 offset
= odp
->offset
;
132 memcpy( pstr
, &offset
, sizeof(WORD
) );
133 pstr
+= sizeof(WORD
);
134 (*bundle
)++; /* increment bundle entry count */
138 if ((pstr
- buffer
) & 1) *pstr
++ = 0;
139 *ret_buff
= xrealloc( buffer
, pstr
- buffer
);
140 return pstr
- buffer
;
144 /*******************************************************************
147 static void output_bytes( FILE *outfile
, const void *buffer
, unsigned int size
)
150 const unsigned char *ptr
= buffer
;
152 fprintf( outfile
, " {" );
153 for (i
= 0; i
< size
; i
++)
155 if (!(i
& 7)) fprintf( outfile
, "\n " );
156 fprintf( outfile
, " 0x%02x", *ptr
++ );
157 if (i
< size
- 1) fprintf( outfile
, "," );
159 fprintf( outfile
, "\n },\n" );
163 /*******************************************************************
164 * BuildCallFrom16Func
166 * Build a 16-bit-to-Wine callback glue function.
168 * The generated routines are intended to be used as argument conversion
169 * routines to be called by the CallFrom16... core. Thus, the prototypes of
170 * the generated routines are (see also CallFrom16):
172 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
173 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
174 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
175 * CONTEXT86 *context );
177 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
178 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
179 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
180 * 'T'=segmented pointer to null-terminated string).
182 * The generated routines fetch the arguments from the 16-bit stack (pointed
183 * to by 'args'); the offsets of the single argument values are computed
184 * according to the calling convention and the argument types. Then, the
185 * 32-bit entry point is called with these arguments.
187 * For register functions, the arguments (if present) are converted just
188 * the same as for normal functions, but in addition the CONTEXT86 pointer
189 * filled with the current register values is passed to the 32-bit routine.
191 static void BuildCallFrom16Func( FILE *outfile
, const char *profile
, const char *prefix
)
193 int i
, pos
, argsize
= 0;
198 const char *args
= profile
+ 7;
199 const char *ret_type
;
201 /* Parse function type */
203 if (!strncmp( "c_", profile
, 2 )) usecdecl
= 1;
204 else if (!strncmp( "v_", profile
, 2 )) varargs
= usecdecl
= 1;
205 else if (strncmp( "p_", profile
, 2 ))
207 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
211 if (!strncmp( "word_", profile
+ 2, 5 )) short_ret
= 1;
212 else if (!strncmp( "regs_", profile
+ 2, 5 )) reg_func
= 1;
213 else if (strncmp( "long_", profile
+ 2, 5 ))
215 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
219 for ( i
= 0; args
[i
]; i
++ )
223 case 's': /* s_word */
226 case 'l': /* long or segmented pointer */
227 case 'T': /* segmented pointer to null-terminated string */
228 case 'p': /* linear pointer */
229 case 't': /* linear pointer to null-terminated string */
234 ret_type
= reg_func
? "void" : short_ret
? "unsigned short" : "unsigned int";
236 fprintf( outfile
, "typedef %s (%s*proc_%s_t)( ",
237 ret_type
, usecdecl
? "" : "__stdcall ", profile
);
239 for ( i
= 0; args
[i
]; i
++ )
241 if ( i
) fprintf( outfile
, ", " );
244 case 'w': fprintf( outfile
, "unsigned short" ); break;
245 case 's': fprintf( outfile
, "short" ); break;
246 case 'l': case 'T': fprintf( outfile
, "unsigned int" ); break;
247 case 'p': case 't': fprintf( outfile
, "void *" ); break;
250 if (reg_func
|| varargs
)
251 fprintf( outfile
, "%svoid *", i
? ", " : "" );
253 fprintf( outfile
, "void" );
254 fprintf( outfile
, " );\n" );
256 fprintf( outfile
, "static %s __stdcall __wine_%s_CallFrom16_%s( proc_%s_t proc, unsigned char *args%s )\n",
257 ret_type
, make_c_identifier(prefix
), profile
, profile
,
258 reg_func
? ", void *context" : "" );
260 fprintf( outfile
, "{\n %sproc(\n", reg_func
? "" : "return " );
262 pos
= !usecdecl
? argsize
: 0;
263 for ( i
= 0; args
[i
]; i
++ )
265 if ( i
) fprintf( outfile
, ",\n" );
266 fprintf( outfile
, " " );
270 if ( !usecdecl
) pos
-= 2;
271 fprintf( outfile
, "*(unsigned short *)(args+%d)", pos
);
272 if ( usecdecl
) pos
+= 2;
275 case 's': /* s_word */
276 if ( !usecdecl
) pos
-= 2;
277 fprintf( outfile
, "*(short *)(args+%d)", pos
);
278 if ( usecdecl
) pos
+= 2;
281 case 'l': /* long or segmented pointer */
282 case 'T': /* segmented pointer to null-terminated string */
283 if ( !usecdecl
) pos
-= 4;
284 fprintf( outfile
, "*(unsigned int *)(args+%d)", pos
);
285 if ( usecdecl
) pos
+= 4;
288 case 'p': /* linear pointer */
289 case 't': /* linear pointer to null-terminated string */
290 if ( !usecdecl
) pos
-= 4;
291 fprintf( outfile
, "((char*)wine_ldt_copy.base[*(unsigned short*)(args+%d) >> 3] + *(unsigned short*)(args+%d))",
293 if ( usecdecl
) pos
+= 4;
297 fprintf( stderr
, "Unknown arg type '%c'\n", args
[i
] );
301 fprintf( outfile
, "%s context", i
? ",\n" : "" );
303 fprintf( outfile
, "%s args + %d", i
? ",\n" : "", argsize
);
304 fprintf( outfile
, " );\n}\n\n" );
308 /*******************************************************************
311 static const char *get_function_name( const ORDDEF
*odp
)
313 static char buffer
[80];
315 sprintf( buffer
, "%s_%s_%s",
316 (odp
->type
== TYPE_PASCAL
) ? "p" :
317 (odp
->type
== TYPE_VARARGS
) ? "v" : "c",
318 (odp
->flags
& FLAG_REGISTER
) ? "regs" :
319 (odp
->flags
& FLAG_RET16
) ? "word" : "long",
320 odp
->u
.func
.arg_types
);
325 /*******************************************************************
328 static int Spec16TypeCompare( const void *e1
, const void *e2
)
330 const ORDDEF
*odp1
= *(const ORDDEF
* const *)e1
;
331 const ORDDEF
*odp2
= *(const ORDDEF
* const *)e2
;
333 int type1
= odp1
->type
;
334 int type2
= odp2
->type
;
336 if (type1
== TYPE_STUB
) type1
= TYPE_CDECL
;
337 if (type2
== TYPE_STUB
) type2
= TYPE_CDECL
;
339 if ((retval
= type1
- type2
) != 0) return retval
;
341 type1
= odp1
->flags
& (FLAG_RET16
|FLAG_REGISTER
);
342 type2
= odp2
->flags
& (FLAG_RET16
|FLAG_REGISTER
);
344 if ((retval
= type1
- type2
) != 0) return retval
;
346 return strcmp( odp1
->u
.func
.arg_types
, odp2
->u
.func
.arg_types
);
350 /*******************************************************************
353 * Output the functions for stub entry points
355 static void output_stub_funcs( FILE *outfile
, const DLLSPEC
*spec
)
360 for (i
= 0; i
<= spec
->limit
; i
++)
362 ORDDEF
*odp
= spec
->ordinals
[i
];
363 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
364 fprintf( outfile
, "#ifdef __GNUC__\n" );
365 fprintf( outfile
, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
366 fprintf( outfile
, "#endif\n" );
367 fprintf( outfile
, "static void __wine_unimplemented( const char *func )\n{\n" );
368 fprintf( outfile
, " extern void __stdcall RaiseException( unsigned int, unsigned int, unsigned int, const void ** );\n" );
369 fprintf( outfile
, " const void *args[2];\n" );
370 fprintf( outfile
, " args[0] = \"%s\";\n", spec
->file_name
);
371 fprintf( outfile
, " args[1] = func;\n" );
372 fprintf( outfile
, " for (;;) RaiseException( 0x%08x, %d, 2, args );\n}\n\n",
373 EXCEPTION_WINE_STUB
, EH_NONCONTINUABLE
);
376 for (i
= 0; i
<= spec
->limit
; i
++)
378 ORDDEF
*odp
= spec
->ordinals
[i
];
379 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
380 odp
->link_name
= xrealloc( odp
->link_name
, strlen(odp
->name
) + 13 );
381 strcpy( odp
->link_name
, "__wine_stub_" );
382 strcat( odp
->link_name
, odp
->name
);
383 for (p
= odp
->link_name
; *p
; p
++) if (!isalnum(*p
)) *p
= '_';
384 fprintf( outfile
, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
385 odp
->link_name
, odp
->name
);
390 /*******************************************************************
393 * Build a Win16 assembly file from a spec file.
395 void BuildSpec16File( FILE *outfile
, DLLSPEC
*spec
)
397 ORDDEF
**type
, **typelist
;
398 int i
, nFuncs
, nTypes
;
399 unsigned char *resdir_buffer
, *resdata_buffer
, *et_buffer
, *data_buffer
;
400 unsigned char string
[256];
401 unsigned int ne_offset
, segtable_offset
, impnames_offset
;
402 unsigned int entrypoint_size
, callfrom_size
;
403 unsigned int code_size
, code_offset
;
404 unsigned int data_size
, data_offset
;
405 unsigned int resnames_size
, resnames_offset
;
406 unsigned int resdir_size
, resdir_offset
;
407 unsigned int resdata_size
, resdata_offset
, resdata_align
;
408 unsigned int et_size
, et_offset
;
410 char constructor
[100], destructor
[100];
411 unsigned short code_selector
= get_cs();
415 output_file_header( outfile
);
416 fprintf( outfile
, "extern unsigned short __wine_call_from_16_word();\n" );
417 fprintf( outfile
, "extern unsigned int __wine_call_from_16_long();\n" );
418 fprintf( outfile
, "extern void __wine_call_from_16_regs();\n" );
419 fprintf( outfile
, "extern void __wine_call_from_16_thunk();\n" );
421 data_buffer
= xmalloc( 0x10000 );
422 memset( data_buffer
, 0, 16 );
425 if (!spec
->dll_name
) /* set default name from file name */
428 spec
->dll_name
= xstrdup( spec
->file_name
);
429 if ((p
= strrchr( spec
->dll_name
, '.' ))) *p
= 0;
432 output_stub_funcs( outfile
, spec
);
434 /* Build sorted list of all argument types, without duplicates */
436 typelist
= (ORDDEF
**)calloc( spec
->limit
+1, sizeof(ORDDEF
*) );
438 for (i
= nFuncs
= 0; i
<= spec
->limit
; i
++)
440 ORDDEF
*odp
= spec
->ordinals
[i
];
448 typelist
[nFuncs
++] = odp
;
455 qsort( typelist
, nFuncs
, sizeof(ORDDEF
*), Spec16TypeCompare
);
460 typelist
[nTypes
++] = typelist
[i
++];
461 while ( i
< nFuncs
&& Spec16TypeCompare( typelist
+ i
, typelist
+ nTypes
-1 ) == 0 )
465 /* Output CallFrom16 routines needed by this .spec file */
466 for ( i
= 0; i
< nTypes
; i
++ )
470 strcpy( profile
, get_function_name( typelist
[i
] ));
471 BuildCallFrom16Func( outfile
, profile
, spec
->file_name
);
474 /* compute code and data sizes, set offsets, and output prototypes */
476 entrypoint_size
= 2 + 5 + 4; /* pushw bp + pushl target + call */
477 callfrom_size
= 5 + 7 + 4 + 8; /* pushl relay + lcall cs:glue + lret n + args */
478 code_size
= nTypes
* callfrom_size
;
480 for (i
= 0; i
<= spec
->limit
; i
++)
482 ORDDEF
*odp
= spec
->ordinals
[i
];
487 odp
->offset
= LOWORD(odp
->u
.abs
.value
);
490 odp
->offset
= data_size
;
491 memcpy( data_buffer
+ data_size
, odp
->u
.var
.values
, odp
->u
.var
.n_values
* sizeof(int) );
492 data_size
+= odp
->u
.var
.n_values
* sizeof(int);
497 fprintf( outfile
, "extern void %s();\n", odp
->link_name
);
500 odp
->offset
= code_size
;
501 code_size
+= entrypoint_size
;
508 data_buffer
= xrealloc( data_buffer
, data_size
); /* free unneeded data */
510 /* Output the module structure */
514 fprintf( outfile
, "\n#include \"pshpack1.h\"\n" );
515 fprintf( outfile
, "static const struct module_data\n{\n" );
516 fprintf( outfile
, " struct\n {\n" );
517 fprintf( outfile
, " unsigned short e_magic;\n" );
518 fprintf( outfile
, " unsigned short e_cblp;\n" );
519 fprintf( outfile
, " unsigned short e_cp;\n" );
520 fprintf( outfile
, " unsigned short e_crlc;\n" );
521 fprintf( outfile
, " unsigned short e_cparhdr;\n" );
522 fprintf( outfile
, " unsigned short e_minalloc;\n" );
523 fprintf( outfile
, " unsigned short e_maxalloc;\n" );
524 fprintf( outfile
, " unsigned short e_ss;\n" );
525 fprintf( outfile
, " unsigned short e_sp;\n" );
526 fprintf( outfile
, " unsigned short e_csum;\n" );
527 fprintf( outfile
, " unsigned short e_ip;\n" );
528 fprintf( outfile
, " unsigned short e_cs;\n" );
529 fprintf( outfile
, " unsigned short e_lfarlc;\n" );
530 fprintf( outfile
, " unsigned short e_ovno;\n" );
531 fprintf( outfile
, " unsigned short e_res[4];\n" );
532 fprintf( outfile
, " unsigned short e_oemid;\n" );
533 fprintf( outfile
, " unsigned short e_oeminfo;\n" );
534 fprintf( outfile
, " unsigned short e_res2[10];\n" );
535 fprintf( outfile
, " unsigned int e_lfanew;\n" );
536 fprintf( outfile
, " } dos_header;\n" );
541 fprintf( outfile
, " struct\n {\n" );
542 fprintf( outfile
, " unsigned short ne_magic;\n" );
543 fprintf( outfile
, " unsigned char ne_ver;\n" );
544 fprintf( outfile
, " unsigned char ne_rev;\n" );
545 fprintf( outfile
, " unsigned short ne_enttab;\n" );
546 fprintf( outfile
, " unsigned short ne_cbenttab;\n" );
547 fprintf( outfile
, " int ne_crc;\n" );
548 fprintf( outfile
, " unsigned short ne_flags;\n" );
549 fprintf( outfile
, " unsigned short ne_autodata;\n" );
550 fprintf( outfile
, " unsigned short ne_heap;\n" );
551 fprintf( outfile
, " unsigned short ne_stack;\n" );
552 fprintf( outfile
, " unsigned int ne_csip;\n" );
553 fprintf( outfile
, " unsigned int ne_sssp;\n" );
554 fprintf( outfile
, " unsigned short ne_cseg;\n" );
555 fprintf( outfile
, " unsigned short ne_cmod;\n" );
556 fprintf( outfile
, " unsigned short ne_cbnrestab;\n" );
557 fprintf( outfile
, " unsigned short ne_segtab;\n" );
558 fprintf( outfile
, " unsigned short ne_rsrctab;\n" );
559 fprintf( outfile
, " unsigned short ne_restab;\n" );
560 fprintf( outfile
, " unsigned short ne_modtab;\n" );
561 fprintf( outfile
, " unsigned short ne_imptab;\n" );
562 fprintf( outfile
, " unsigned int ne_nrestab;\n" );
563 fprintf( outfile
, " unsigned short ne_cmovent;\n" );
564 fprintf( outfile
, " unsigned short ne_align;\n" );
565 fprintf( outfile
, " unsigned short ne_cres;\n" );
566 fprintf( outfile
, " unsigned char ne_exetyp;\n" );
567 fprintf( outfile
, " unsigned char ne_flagsothers;\n" );
568 fprintf( outfile
, " unsigned short ne_pretthunks;\n" );
569 fprintf( outfile
, " unsigned short ne_psegrefbytes;\n" );
570 fprintf( outfile
, " unsigned short ne_swaparea;\n" );
571 fprintf( outfile
, " unsigned short ne_expver;\n" );
572 fprintf( outfile
, " } os2_header;\n" );
576 segtable_offset
= 64;
577 fprintf( outfile
, " struct\n {\n" );
578 fprintf( outfile
, " unsigned short filepos;\n" );
579 fprintf( outfile
, " unsigned short size;\n" );
580 fprintf( outfile
, " unsigned short flags;\n" );
581 fprintf( outfile
, " unsigned short minsize;\n" );
582 fprintf( outfile
, " } segtable[2];\n" );
584 /* resource directory */
586 resdir_offset
= segtable_offset
+ 2 * 8;
587 resdir_size
= get_res16_directory_size( spec
);
588 fprintf( outfile
, " unsigned char resdir[%d];\n", resdir_size
);
590 /* resident names table */
592 resnames_offset
= resdir_offset
+ resdir_size
;
593 fprintf( outfile
, " struct\n {\n" );
594 fprintf( outfile
, " struct { unsigned char len; char name[%d]; unsigned short ord; } name_0;\n",
595 strlen( spec
->dll_name
) );
596 resnames_size
= 3 + strlen( spec
->dll_name
);
597 for (i
= 1; i
<= spec
->limit
; i
++)
599 ORDDEF
*odp
= spec
->ordinals
[i
];
600 if (!odp
|| !odp
->name
[0]) continue;
601 fprintf( outfile
, " struct { unsigned char len; char name[%d]; unsigned short ord; } name_%d;\n",
602 strlen(odp
->name
), i
);
603 resnames_size
+= 3 + strlen( odp
->name
);
605 fprintf( outfile
, " unsigned char name_last[%d];\n", 2 - (resnames_size
& 1) );
606 resnames_size
= (resnames_size
+ 2) & ~1;
607 fprintf( outfile
, " } resnames;\n" );
609 /* imported names table */
611 impnames_offset
= resnames_offset
+ resnames_size
;
612 fprintf( outfile
, " unsigned char impnames[2];\n" );
616 et_offset
= impnames_offset
+ 2;
617 et_size
= output_entry_table( &et_buffer
, spec
);
618 fprintf( outfile
, " unsigned char entry_table[%d];\n", et_size
);
622 code_offset
= et_offset
+ et_size
;
623 fprintf( outfile
, " struct {\n" );
624 fprintf( outfile
, " unsigned char pushl;\n" ); /* pushl $relay */
625 fprintf( outfile
, " void *relay;\n" );
626 fprintf( outfile
, " unsigned char lcall;\n" ); /* lcall __FLATCS__:glue */
627 fprintf( outfile
, " void *glue;\n" );
628 fprintf( outfile
, " unsigned short flatcs;\n" );
629 fprintf( outfile
, " unsigned short lret;\n" ); /* lret $args */
630 fprintf( outfile
, " unsigned short args;\n" );
631 fprintf( outfile
, " unsigned int arg_types[2];\n" );
632 fprintf( outfile
, " } call[%d];\n", nTypes
);
633 fprintf( outfile
, " struct {\n" );
634 fprintf( outfile
, " unsigned short pushw_bp;\n" ); /* pushw %bp */
635 fprintf( outfile
, " unsigned char pushl;\n" ); /* pushl $target */
636 fprintf( outfile
, " void (*target)();\n" );
637 fprintf( outfile
, " unsigned short call;\n" ); /* call CALLFROM16 */
638 fprintf( outfile
, " short callfrom16;\n" );
639 fprintf( outfile
, " } entry[%d];\n", nFuncs
);
643 data_offset
= code_offset
+ code_size
;
644 fprintf( outfile
, " unsigned char data_segment[%d];\n", data_size
);
645 if (data_offset
+ data_size
>= 0x10000)
646 fatal_error( "Not supported yet: 16-bit module data larger than 64K\n" );
650 resdata_offset
= ne_offset
+ data_offset
+ data_size
;
651 for (resdata_align
= 0; resdata_align
< 16; resdata_align
++)
653 unsigned int size
= get_res16_data_size( spec
, resdata_offset
, resdata_align
);
654 if ((resdata_offset
+ size
) >> resdata_align
<= 0xffff) break;
656 output_res16_directory( &resdir_buffer
, spec
, resdata_offset
, resdata_align
);
657 resdata_size
= output_res16_data( &resdata_buffer
, spec
, resdata_offset
, resdata_align
);
658 if (resdata_size
) fprintf( outfile
, " unsigned char resources[%d];\n", resdata_size
);
660 /* Output the module data */
664 fprintf( outfile
, "} module =\n{\n {\n" );
665 fprintf( outfile
, " 0x%04x,\n", IMAGE_DOS_SIGNATURE
); /* e_magic */
666 fprintf( outfile
, " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n" );
667 fprintf( outfile
, " { 0, 0, 0, 0, }, 0, 0,\n" );
668 fprintf( outfile
, " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },\n" );
669 fprintf( outfile
, " sizeof(module.dos_header)\n" ); /* e_lfanew */
673 fprintf( outfile
, " },\n {\n" );
674 fprintf( outfile
, " 0x%04x,\n", IMAGE_OS2_SIGNATURE
); /* ne_magic */
675 fprintf( outfile
, " 0, 0,\n" );
676 fprintf( outfile
, " %d,\n", et_offset
); /* ne_enttab */
677 fprintf( outfile
, " sizeof(module.entry_table),\n" ); /* ne_cbenttab */
678 fprintf( outfile
, " 0,\n" ); /* ne_crc */
679 fprintf( outfile
, " 0x%04x,\n", /* ne_flags */
680 NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_LIBMODULE
);
681 fprintf( outfile
, " 2,\n" ); /* ne_autodata */
682 fprintf( outfile
, " %d,\n", spec
->heap_size
); /* ne_heap */
683 fprintf( outfile
, " 0, 0, 0,\n" );
684 fprintf( outfile
, " 2,\n" ); /* ne_cseg */
685 fprintf( outfile
, " 0,\n" ); /* ne_cmod */
686 fprintf( outfile
, " 0,\n" ); /* ne_cbnrestab */
687 fprintf( outfile
, " %d,\n", segtable_offset
); /* ne_segtab */
688 fprintf( outfile
, " %d,\n", resdir_offset
); /* ne_rsrctab */
689 fprintf( outfile
, " %d,\n", resnames_offset
); /* ne_restab */
690 fprintf( outfile
, " %d,\n", impnames_offset
); /* ne_modtab */
691 fprintf( outfile
, " %d,\n", impnames_offset
); /* ne_imptab */
692 fprintf( outfile
, " 0,\n" ); /* ne_nrestab */
693 fprintf( outfile
, " 0,\n" ); /* ne_cmovent */
694 fprintf( outfile
, " 0,\n" ); /* ne_align */
695 fprintf( outfile
, " 0,\n" ); /* ne_cres */
696 fprintf( outfile
, " 0x%04x,\n", NE_OSFLAGS_WINDOWS
); /* ne_exetyp */
697 fprintf( outfile
, " 0x%04x,\n", NE_AFLAGS_FASTLOAD
); /* ne_flagsothers */
698 fprintf( outfile
, " 0,\n" ); /* ne_pretthunks */
699 fprintf( outfile
, " 0,\n" ); /* ne_psegrefbytes */
700 fprintf( outfile
, " 0,\n" ); /* ne_swaparea */
701 fprintf( outfile
, " 0\n" ); /* ne_expver */
702 fprintf( outfile
, " },\n" );
706 fprintf( outfile
, " {\n" );
707 fprintf( outfile
, " { %d, %d, 0x%04x, %d },\n",
708 ne_offset
+ code_offset
, code_size
, NE_SEGFLAGS_32BIT
, code_size
);
709 fprintf( outfile
, " { %d, %d, 0x%04x, %d },\n",
710 ne_offset
+ data_offset
, data_size
, NE_SEGFLAGS_DATA
, data_size
);
711 fprintf( outfile
, " },\n" );
713 /* resource directory */
715 output_bytes( outfile
, resdir_buffer
, resdir_size
);
716 free( resdir_buffer
);
718 /* resident names table */
720 fprintf( outfile
, " {\n" );
721 strcpy( string
, spec
->dll_name
);
722 fprintf( outfile
, " { %d, \"%s\", 0 },\n", strlen(string
), strupper(string
) );
723 for (i
= 1; i
<= spec
->limit
; i
++)
725 ORDDEF
*odp
= spec
->ordinals
[i
];
726 if (!odp
|| !odp
->name
[0]) continue;
727 strcpy( string
, odp
->name
);
728 fprintf( outfile
, " { %d, \"%s\", %d },\n", strlen(string
), strupper(string
), i
);
730 fprintf( outfile
, " { 0 }\n },\n" );
732 /* imported names table */
734 fprintf( outfile
, " { 0, 0 },\n" );
738 output_bytes( outfile
, et_buffer
, et_size
);
743 fprintf( outfile
, " {\n" );
744 for ( i
= 0; i
< nTypes
; i
++ )
746 char profile
[101], *arg
;
747 unsigned int arg_types
[2];
750 strcpy( profile
, get_function_name( typelist
[i
] ));
751 if ( typelist
[i
]->type
== TYPE_PASCAL
)
752 for ( arg
= typelist
[i
]->u
.func
.arg_types
; *arg
; arg
++ )
756 case 's': /* s_word */
759 case 'l': /* long or segmented pointer */
760 case 'T': /* segmented pointer to null-terminated string */
761 case 'p': /* linear pointer */
762 case 't': /* linear pointer to null-terminated string */
767 /* build the arg types bit fields */
768 arg_types
[0] = arg_types
[1] = 0;
769 for (j
= 0; typelist
[i
]->u
.func
.arg_types
[j
]; j
++)
772 switch(typelist
[i
]->u
.func
.arg_types
[j
])
774 case 'w': type
= ARG_WORD
; break;
775 case 's': type
= ARG_SWORD
; break;
776 case 'l': type
= ARG_LONG
; break;
777 case 'p': type
= ARG_PTR
; break;
778 case 't': type
= ARG_STR
; break;
779 case 'T': type
= ARG_SEGSTR
; break;
781 arg_types
[j
/ 10] |= type
<< (3 * (j
% 10));
783 if (typelist
[i
]->flags
& FLAG_REGISTER
) arg_types
[0] |= ARG_REGISTER
;
784 if (typelist
[i
]->flags
& FLAG_RET16
) arg_types
[0] |= ARG_RET16
;
786 fprintf( outfile
, " { 0x68, __wine_%s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
787 make_c_identifier(spec
->file_name
), profile
,
788 (typelist
[i
]->flags
& FLAG_REGISTER
) ? "regs":
789 (typelist
[i
]->flags
& FLAG_RET16
) ? "word" : "long" );
791 fprintf( outfile
, " 0x%04x, 0xca66, %d, { 0x%08x, 0x%08x } },\n",
792 code_selector
, argsize
, arg_types
[0], arg_types
[1] );
794 fprintf( outfile
, " 0x%04x, 0xcb66, 0x9090, { 0x%08x, 0x%08x } },\n",
795 code_selector
, arg_types
[0], arg_types
[1] );
797 fprintf( outfile
, " },\n {\n" );
799 for (i
= 0; i
<= spec
->limit
; i
++)
801 ORDDEF
*odp
= spec
->ordinals
[i
];
809 type
= bsearch( &odp
, typelist
, nTypes
, sizeof(ORDDEF
*), Spec16TypeCompare
);
812 fprintf( outfile
, " /* %s.%d */ ", spec
->dll_name
, i
);
814 "{ 0x5566, 0x68, %s, 0xe866, %d /* %s */ },\n",
816 (type
- typelist
) * callfrom_size
- (odp
->offset
+ entrypoint_size
),
817 get_function_name( odp
) );
823 fprintf( outfile
, " },\n" );
828 output_bytes( outfile
, data_buffer
, data_size
);
835 output_bytes( outfile
, resdata_buffer
, resdata_size
);
836 free( resdata_buffer
);
839 fprintf( outfile
, "};\n" );
840 fprintf( outfile
, "#include \"poppack.h\"\n\n" );
842 /* Output the DLL constructor */
844 sprintf( constructor
, "__wine_spec_%s_init", make_c_identifier(spec
->file_name
) );
845 sprintf( destructor
, "__wine_spec_%s_fini", make_c_identifier(spec
->file_name
) );
850 " extern void __wine_dll_register_16( const struct module_data *, const char * );\n"
851 " __wine_dll_register_16( &module, \"%s\" );\n"
852 "}\n", constructor
, spec
->file_name
);
856 " extern void __wine_dll_unregister_16( const struct module_data * );\n"
857 " __wine_dll_unregister_16( &module );\n"
860 fprintf( outfile
, "#ifndef __GNUC__\n" );
861 fprintf( outfile
, "static void __asm__dummy_dll_init(void) {\n" );
862 fprintf( outfile
, "#endif\n" );
864 output_dll_init( outfile
, constructor
, destructor
);
866 fprintf( outfile
, "#ifndef __GNUC__\n" );
867 fprintf( outfile
, "}\n" );
868 fprintf( outfile
, "#endif\n" );