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
26 #include "wine/port.h"
31 #include "wine/exception.h"
32 #include "wine/winbase16.h"
37 /*******************************************************************
40 static inline unsigned short get_cs(void)
42 unsigned short res = 0;
45 __asm__("movw %%cs,%w0" : "=r"(res));
46 # elif defined(_MSC_VER)
54 /*******************************************************************
57 * Output a file header with the common declarations we need.
59 static void output_file_header( FILE *outfile )
61 output_standard_file_header( outfile );
62 fprintf( outfile, "extern struct\n{\n" );
63 fprintf( outfile, " void *base[8192];\n" );
64 fprintf( outfile, " unsigned long limit[8192];\n" );
65 fprintf( outfile, " unsigned char flags[8192];\n" );
66 fprintf( outfile, "} wine_ldt_copy;\n\n" );
67 fprintf( outfile, "#define __stdcall __attribute__((__stdcall__))\n\n" );
71 /*******************************************************************
74 static int output_entry_table( unsigned char **ret_buff, DLLSPEC *spec )
76 int i, prev = 0, prev_sel = -1;
77 unsigned char *pstr, *buffer;
78 unsigned char *bundle = NULL;
80 buffer = xmalloc( spec->limit * 5 ); /* we use at most 5 bytes per entry-point */
83 for (i = 1; i <= spec->limit; i++)
87 ORDDEF *odp = spec->ordinals[i];
96 selector = 1; /* Code selector */
99 selector = 2; /* Data selector */
102 selector = 0xfe; /* Constant selector */
108 if (!bundle || prev + 1 != i || prev_sel != selector || *bundle == 255)
110 /* need to start a new bundle */
114 int skip = i - (prev + 1);
130 /* output the entry */
131 *pstr++ = 3; /* flags: exported & public data */
132 offset = odp->offset;
133 memcpy( pstr, &offset, sizeof(WORD) );
134 pstr += sizeof(WORD);
135 (*bundle)++; /* increment bundle entry count */
139 if ((pstr - buffer) & 1) *pstr++ = 0;
140 *ret_buff = xrealloc( buffer, pstr - buffer );
141 return pstr - buffer;
145 /*******************************************************************
148 static void output_bytes( FILE *outfile, const void *buffer, unsigned int size )
151 const unsigned char *ptr = buffer;
153 fprintf( outfile, " {" );
154 for (i = 0; i < size; i++)
156 if (!(i & 7)) fprintf( outfile, "\n " );
157 fprintf( outfile, " 0x%02x", *ptr++ );
158 if (i < size - 1) fprintf( outfile, "," );
160 fprintf( outfile, "\n },\n" );
164 /*******************************************************************
165 * BuildCallFrom16Func
167 * Build a 16-bit-to-Wine callback glue function.
169 * The generated routines are intended to be used as argument conversion
170 * routines to be called by the CallFrom16... core. Thus, the prototypes of
171 * the generated routines are (see also CallFrom16):
173 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
174 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
175 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
176 * CONTEXT86 *context );
178 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
179 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
180 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
181 * 'T'=segmented pointer to null-terminated string).
183 * The generated routines fetch the arguments from the 16-bit stack (pointed
184 * to by 'args'); the offsets of the single argument values are computed
185 * according to the calling convention and the argument types. Then, the
186 * 32-bit entry point is called with these arguments.
188 * For register functions, the arguments (if present) are converted just
189 * the same as for normal functions, but in addition the CONTEXT86 pointer
190 * filled with the current register values is passed to the 32-bit routine.
192 static void BuildCallFrom16Func( FILE *outfile, const char *profile, const char *prefix )
194 int i, pos, argsize = 0;
199 const char *args = profile + 7;
200 const char *ret_type;
202 /* Parse function type */
204 if (!strncmp( "c_", profile, 2 )) usecdecl = 1;
205 else if (!strncmp( "v_", profile, 2 )) varargs = usecdecl = 1;
206 else if (strncmp( "p_", profile, 2 ))
208 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
212 if (!strncmp( "word_", profile + 2, 5 )) short_ret = 1;
213 else if (!strncmp( "regs_", profile + 2, 5 )) reg_func = 1;
214 else if (strncmp( "long_", profile + 2, 5 ))
216 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
220 for ( i = 0; args[i]; i++ )
224 case 's': /* s_word */
227 case 'l': /* long or segmented pointer */
228 case 'T': /* segmented pointer to null-terminated string */
229 case 'p': /* linear pointer */
230 case 't': /* linear pointer to null-terminated string */
235 ret_type = reg_func? "void" : short_ret ? "unsigned short" : "unsigned int";
237 fprintf( outfile, "typedef %s (%s*proc_%s_t)( ",
238 ret_type, usecdecl ? "" : "__stdcall ", profile );
240 for ( i = 0; args[i]; i++ )
242 if ( i ) fprintf( outfile, ", " );
245 case 'w': fprintf( outfile, "unsigned short" ); break;
246 case 's': fprintf( outfile, "short" ); break;
247 case 'l': case 'T': fprintf( outfile, "unsigned int" ); break;
248 case 'p': case 't': fprintf( outfile, "void *" ); break;
251 if (reg_func || varargs)
252 fprintf( outfile, "%svoid *", i? ", " : "" );
254 fprintf( outfile, "void" );
255 fprintf( outfile, " );\n" );
257 fprintf( outfile, "static %s __wine_%s_CallFrom16_%s( proc_%s_t proc, unsigned char *args%s )\n",
258 ret_type, make_c_identifier(prefix), profile, profile,
259 reg_func? ", void *context" : "" );
261 fprintf( outfile, "{\n %sproc(\n", reg_func ? "" : "return " );
263 pos = !usecdecl? argsize : 0;
264 for ( i = 0; args[i]; i++ )
266 if ( i ) fprintf( outfile, ",\n" );
267 fprintf( outfile, " " );
271 if ( !usecdecl ) pos -= 2;
272 fprintf( outfile, "*(unsigned short *)(args+%d)", pos );
273 if ( usecdecl ) pos += 2;
276 case 's': /* s_word */
277 if ( !usecdecl ) pos -= 2;
278 fprintf( outfile, "*(short *)(args+%d)", pos );
279 if ( usecdecl ) pos += 2;
282 case 'l': /* long or segmented pointer */
283 case 'T': /* segmented pointer to null-terminated string */
284 if ( !usecdecl ) pos -= 4;
285 fprintf( outfile, "*(unsigned int *)(args+%d)", pos );
286 if ( usecdecl ) pos += 4;
289 case 'p': /* linear pointer */
290 case 't': /* linear pointer to null-terminated string */
291 if ( !usecdecl ) pos -= 4;
292 fprintf( outfile, "((char*)wine_ldt_copy.base[*(unsigned short*)(args+%d) >> 3] + *(unsigned short*)(args+%d))",
294 if ( usecdecl ) pos += 4;
298 fprintf( stderr, "Unknown arg type '%c'\n", args[i] );
302 fprintf( outfile, "%s context", i? ",\n" : "" );
304 fprintf( outfile, "%s args + %d", i? ",\n" : "", argsize );
305 fprintf( outfile, " );\n}\n\n" );
309 /*******************************************************************
312 static const char *get_function_name( const ORDDEF *odp )
314 static char buffer[80];
316 sprintf( buffer, "%s_%s_%s",
317 (odp->type == TYPE_PASCAL) ? "p" :
318 (odp->type == TYPE_VARARGS) ? "v" : "c",
319 (odp->flags & FLAG_REGISTER) ? "regs" :
320 (odp->flags & FLAG_RET16) ? "word" : "long",
321 odp->u.func.arg_types );
326 /*******************************************************************
329 static int Spec16TypeCompare( const void *e1, const void *e2 )
331 const ORDDEF *odp1 = *(const ORDDEF * const *)e1;
332 const ORDDEF *odp2 = *(const ORDDEF * const *)e2;
334 int type1 = odp1->type;
335 int type2 = odp2->type;
337 if (type1 == TYPE_STUB) type1 = TYPE_CDECL;
338 if (type2 == TYPE_STUB) type2 = TYPE_CDECL;
340 if ((retval = type1 - type2) != 0) return retval;
342 type1 = odp1->flags & (FLAG_RET16|FLAG_REGISTER);
343 type2 = odp2->flags & (FLAG_RET16|FLAG_REGISTER);
345 if ((retval = type1 - type2) != 0) return retval;
347 return strcmp( odp1->u.func.arg_types, odp2->u.func.arg_types );
351 /*******************************************************************
354 * Output the functions for stub entry points
356 static void output_stub_funcs( FILE *outfile, const DLLSPEC *spec )
361 for (i = 0; i <= spec->limit; i++)
363 ORDDEF *odp = spec->ordinals[i];
364 if (!odp || odp->type != TYPE_STUB) continue;
365 fprintf( outfile, "#ifdef __GNUC__\n" );
366 fprintf( outfile, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func ) __attribute__((noreturn));\n" );
367 fprintf( outfile, "#else\n" );
368 fprintf( outfile, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func );\n" );
369 fprintf( outfile, "#endif\n\n" );
372 for (i = 0; i <= spec->limit; i++)
374 ORDDEF *odp = spec->ordinals[i];
375 if (!odp || odp->type != TYPE_STUB) continue;
376 odp->link_name = xrealloc( odp->link_name, strlen(odp->name) + 13 );
377 strcpy( odp->link_name, "__wine_stub_" );
378 strcat( odp->link_name, odp->name );
379 for (p = odp->link_name; *p; p++) if (!isalnum(*p)) *p = '_';
380 fprintf( outfile, "static void %s(void) { __wine_spec_unimplemented_stub(__wine_spec16_file_name, \"%s\"); }\n",
381 odp->link_name, odp->name );
386 /*******************************************************************
389 * Build a Win16 assembly file from a spec file.
391 void BuildSpec16File( FILE *outfile, DLLSPEC *spec )
393 ORDDEF **type, **typelist;
394 int i, nFuncs, nTypes;
395 unsigned char *resdir_buffer, *resdata_buffer, *et_buffer, *data_buffer;
397 unsigned int ne_offset, segtable_offset, impnames_offset;
398 unsigned int entrypoint_size, callfrom_size;
399 unsigned int code_size, code_offset;
400 unsigned int data_size, data_offset;
401 unsigned int resnames_size, resnames_offset;
402 unsigned int resdir_size, resdir_offset;
403 unsigned int resdata_size, resdata_offset, resdata_align;
404 unsigned int et_size, et_offset;
406 char constructor[100], destructor[100];
407 unsigned short code_selector = get_cs();
411 output_file_header( outfile );
412 fprintf( outfile, "static const char __wine_spec16_file_name[] = \"%s\";\n", spec->file_name );
413 fprintf( outfile, "extern unsigned short __wine_call_from_16_word();\n" );
414 fprintf( outfile, "extern unsigned int __wine_call_from_16_long();\n" );
415 fprintf( outfile, "extern void __wine_call_from_16_regs();\n" );
416 fprintf( outfile, "extern void __wine_call_from_16_thunk();\n" );
418 data_buffer = xmalloc( 0x10000 );
419 memset( data_buffer, 0, 16 );
422 if (!spec->dll_name) /* set default name from file name */
425 spec->dll_name = xstrdup( spec->file_name );
426 if ((p = strrchr( spec->dll_name, '.' ))) *p = 0;
429 output_stub_funcs( outfile, spec );
431 /* Build sorted list of all argument types, without duplicates */
433 typelist = (ORDDEF **)calloc( spec->limit+1, sizeof(ORDDEF *) );
435 for (i = nFuncs = 0; i <= spec->limit; i++)
437 ORDDEF *odp = spec->ordinals[i];
445 typelist[nFuncs++] = odp;
452 qsort( typelist, nFuncs, sizeof(ORDDEF *), Spec16TypeCompare );
457 typelist[nTypes++] = typelist[i++];
458 while ( i < nFuncs && Spec16TypeCompare( typelist + i, typelist + nTypes-1 ) == 0 )
462 /* Output CallFrom16 routines needed by this .spec file */
463 for ( i = 0; i < nTypes; i++ )
467 strcpy( profile, get_function_name( typelist[i] ));
468 BuildCallFrom16Func( outfile, profile, spec->file_name );
471 /* compute code and data sizes, set offsets, and output prototypes */
473 entrypoint_size = 2 + 5 + 4; /* pushw bp + pushl target + call */
474 callfrom_size = 5 + 7 + 4 + 8; /* pushl relay + lcall cs:glue + lret n + args */
475 code_size = nTypes * callfrom_size;
477 for (i = 0; i <= spec->limit; i++)
479 ORDDEF *odp = spec->ordinals[i];
484 odp->offset = LOWORD(odp->u.abs.value);
487 odp->offset = data_size;
488 memcpy( data_buffer + data_size, odp->u.var.values, odp->u.var.n_values * sizeof(int) );
489 data_size += odp->u.var.n_values * sizeof(int);
494 fprintf( outfile, "extern void %s();\n", odp->link_name );
497 odp->offset = code_size;
498 code_size += entrypoint_size;
505 data_buffer = xrealloc( data_buffer, data_size ); /* free unneeded data */
507 /* Output the module structure */
511 fprintf( outfile, "\n#include \"pshpack1.h\"\n" );
512 fprintf( outfile, "static const struct module_data\n{\n" );
513 fprintf( outfile, " struct\n {\n" );
514 fprintf( outfile, " unsigned short e_magic;\n" );
515 fprintf( outfile, " unsigned short e_cblp;\n" );
516 fprintf( outfile, " unsigned short e_cp;\n" );
517 fprintf( outfile, " unsigned short e_crlc;\n" );
518 fprintf( outfile, " unsigned short e_cparhdr;\n" );
519 fprintf( outfile, " unsigned short e_minalloc;\n" );
520 fprintf( outfile, " unsigned short e_maxalloc;\n" );
521 fprintf( outfile, " unsigned short e_ss;\n" );
522 fprintf( outfile, " unsigned short e_sp;\n" );
523 fprintf( outfile, " unsigned short e_csum;\n" );
524 fprintf( outfile, " unsigned short e_ip;\n" );
525 fprintf( outfile, " unsigned short e_cs;\n" );
526 fprintf( outfile, " unsigned short e_lfarlc;\n" );
527 fprintf( outfile, " unsigned short e_ovno;\n" );
528 fprintf( outfile, " unsigned short e_res[4];\n" );
529 fprintf( outfile, " unsigned short e_oemid;\n" );
530 fprintf( outfile, " unsigned short e_oeminfo;\n" );
531 fprintf( outfile, " unsigned short e_res2[10];\n" );
532 fprintf( outfile, " unsigned int e_lfanew;\n" );
533 fprintf( outfile, " } dos_header;\n" );
538 fprintf( outfile, " struct\n {\n" );
539 fprintf( outfile, " unsigned short ne_magic;\n" );
540 fprintf( outfile, " unsigned char ne_ver;\n" );
541 fprintf( outfile, " unsigned char ne_rev;\n" );
542 fprintf( outfile, " unsigned short ne_enttab;\n" );
543 fprintf( outfile, " unsigned short ne_cbenttab;\n" );
544 fprintf( outfile, " int ne_crc;\n" );
545 fprintf( outfile, " unsigned short ne_flags;\n" );
546 fprintf( outfile, " unsigned short ne_autodata;\n" );
547 fprintf( outfile, " unsigned short ne_heap;\n" );
548 fprintf( outfile, " unsigned short ne_stack;\n" );
549 fprintf( outfile, " unsigned int ne_csip;\n" );
550 fprintf( outfile, " unsigned int ne_sssp;\n" );
551 fprintf( outfile, " unsigned short ne_cseg;\n" );
552 fprintf( outfile, " unsigned short ne_cmod;\n" );
553 fprintf( outfile, " unsigned short ne_cbnrestab;\n" );
554 fprintf( outfile, " unsigned short ne_segtab;\n" );
555 fprintf( outfile, " unsigned short ne_rsrctab;\n" );
556 fprintf( outfile, " unsigned short ne_restab;\n" );
557 fprintf( outfile, " unsigned short ne_modtab;\n" );
558 fprintf( outfile, " unsigned short ne_imptab;\n" );
559 fprintf( outfile, " unsigned int ne_nrestab;\n" );
560 fprintf( outfile, " unsigned short ne_cmovent;\n" );
561 fprintf( outfile, " unsigned short ne_align;\n" );
562 fprintf( outfile, " unsigned short ne_cres;\n" );
563 fprintf( outfile, " unsigned char ne_exetyp;\n" );
564 fprintf( outfile, " unsigned char ne_flagsothers;\n" );
565 fprintf( outfile, " unsigned short ne_pretthunks;\n" );
566 fprintf( outfile, " unsigned short ne_psegrefbytes;\n" );
567 fprintf( outfile, " unsigned short ne_swaparea;\n" );
568 fprintf( outfile, " unsigned short ne_expver;\n" );
569 fprintf( outfile, " } os2_header;\n" );
573 segtable_offset = 64;
574 fprintf( outfile, " struct\n {\n" );
575 fprintf( outfile, " unsigned short filepos;\n" );
576 fprintf( outfile, " unsigned short size;\n" );
577 fprintf( outfile, " unsigned short flags;\n" );
578 fprintf( outfile, " unsigned short minsize;\n" );
579 fprintf( outfile, " } segtable[2];\n" );
581 /* resource directory */
583 resdir_offset = segtable_offset + 2 * 8;
584 resdir_size = get_res16_directory_size( spec );
585 fprintf( outfile, " unsigned char resdir[%d];\n", resdir_size );
587 /* resident names table */
589 resnames_offset = resdir_offset + resdir_size;
590 fprintf( outfile, " struct\n {\n" );
591 fprintf( outfile, " struct { unsigned char len; char name[%d]; unsigned short ord; } name_0;\n",
592 strlen( spec->dll_name ) );
593 resnames_size = 3 + strlen( spec->dll_name );
594 for (i = 1; i <= spec->limit; i++)
596 ORDDEF *odp = spec->ordinals[i];
597 if (!odp || !odp->name[0]) continue;
598 fprintf( outfile, " struct { unsigned char len; char name[%d]; unsigned short ord; } name_%d;\n",
599 strlen(odp->name), i );
600 resnames_size += 3 + strlen( odp->name );
602 fprintf( outfile, " unsigned char name_last[%d];\n", 2 - (resnames_size & 1) );
603 resnames_size = (resnames_size + 2) & ~1;
604 fprintf( outfile, " } resnames;\n" );
606 /* imported names table */
608 impnames_offset = resnames_offset + resnames_size;
609 fprintf( outfile, " unsigned char impnames[2];\n" );
613 et_offset = impnames_offset + 2;
614 et_size = output_entry_table( &et_buffer, spec );
615 fprintf( outfile, " unsigned char entry_table[%d];\n", et_size );
619 code_offset = et_offset + et_size;
620 fprintf( outfile, " struct {\n" );
621 fprintf( outfile, " unsigned char pushl;\n" ); /* pushl $relay */
622 fprintf( outfile, " void *relay;\n" );
623 fprintf( outfile, " unsigned char lcall;\n" ); /* lcall __FLATCS__:glue */
624 fprintf( outfile, " void *glue;\n" );
625 fprintf( outfile, " unsigned short flatcs;\n" );
626 fprintf( outfile, " unsigned short lret;\n" ); /* lret $args */
627 fprintf( outfile, " unsigned short args;\n" );
628 fprintf( outfile, " unsigned int arg_types[2];\n" );
629 fprintf( outfile, " } call[%d];\n", nTypes );
630 fprintf( outfile, " struct {\n" );
631 fprintf( outfile, " unsigned short pushw_bp;\n" ); /* pushw %bp */
632 fprintf( outfile, " unsigned char pushl;\n" ); /* pushl $target */
633 fprintf( outfile, " void (*target)();\n" );
634 fprintf( outfile, " unsigned short call;\n" ); /* call CALLFROM16 */
635 fprintf( outfile, " short callfrom16;\n" );
636 fprintf( outfile, " } entry[%d];\n", nFuncs );
640 data_offset = code_offset + code_size;
641 fprintf( outfile, " unsigned char data_segment[%d];\n", data_size );
642 if (data_offset + data_size >= 0x10000)
643 fatal_error( "Not supported yet: 16-bit module data larger than 64K\n" );
647 resdata_offset = ne_offset + data_offset + data_size;
648 for (resdata_align = 0; resdata_align < 16; resdata_align++)
650 unsigned int size = get_res16_data_size( spec, resdata_offset, resdata_align );
651 if ((resdata_offset + size) >> resdata_align <= 0xffff) break;
653 output_res16_directory( &resdir_buffer, spec, resdata_offset, resdata_align );
654 resdata_size = output_res16_data( &resdata_buffer, spec, resdata_offset, resdata_align );
655 if (resdata_size) fprintf( outfile, " unsigned char resources[%d];\n", resdata_size );
657 /* Output the module data */
661 fprintf( outfile, "} module =\n{\n {\n" );
662 fprintf( outfile, " 0x%04x,\n", IMAGE_DOS_SIGNATURE ); /* e_magic */
663 fprintf( outfile, " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n" );
664 fprintf( outfile, " { 0, 0, 0, 0, }, 0, 0,\n" );
665 fprintf( outfile, " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },\n" );
666 fprintf( outfile, " sizeof(module.dos_header)\n" ); /* e_lfanew */
670 fprintf( outfile, " },\n {\n" );
671 fprintf( outfile, " 0x%04x,\n", IMAGE_OS2_SIGNATURE ); /* ne_magic */
672 fprintf( outfile, " 0, 0,\n" );
673 fprintf( outfile, " %d,\n", et_offset ); /* ne_enttab */
674 fprintf( outfile, " sizeof(module.entry_table),\n" ); /* ne_cbenttab */
675 fprintf( outfile, " 0,\n" ); /* ne_crc */
676 fprintf( outfile, " 0x%04x,\n", /* ne_flags */
677 NE_FFLAGS_SINGLEDATA | NE_FFLAGS_LIBMODULE );
678 fprintf( outfile, " 2,\n" ); /* ne_autodata */
679 fprintf( outfile, " %d,\n", spec->heap_size ); /* ne_heap */
680 fprintf( outfile, " 0, 0, 0,\n" );
681 fprintf( outfile, " 2,\n" ); /* ne_cseg */
682 fprintf( outfile, " 0,\n" ); /* ne_cmod */
683 fprintf( outfile, " 0,\n" ); /* ne_cbnrestab */
684 fprintf( outfile, " %d,\n", segtable_offset ); /* ne_segtab */
685 fprintf( outfile, " %d,\n", resdir_offset ); /* ne_rsrctab */
686 fprintf( outfile, " %d,\n", resnames_offset ); /* ne_restab */
687 fprintf( outfile, " %d,\n", impnames_offset ); /* ne_modtab */
688 fprintf( outfile, " %d,\n", impnames_offset ); /* ne_imptab */
689 fprintf( outfile, " 0,\n" ); /* ne_nrestab */
690 fprintf( outfile, " 0,\n" ); /* ne_cmovent */
691 fprintf( outfile, " 0,\n" ); /* ne_align */
692 fprintf( outfile, " 0,\n" ); /* ne_cres */
693 fprintf( outfile, " 0x%04x,\n", NE_OSFLAGS_WINDOWS ); /* ne_exetyp */
694 fprintf( outfile, " 0x%04x,\n", NE_AFLAGS_FASTLOAD ); /* ne_flagsothers */
695 fprintf( outfile, " 0,\n" ); /* ne_pretthunks */
696 fprintf( outfile, " 0,\n" ); /* ne_psegrefbytes */
697 fprintf( outfile, " 0,\n" ); /* ne_swaparea */
698 fprintf( outfile, " 0\n" ); /* ne_expver */
699 fprintf( outfile, " },\n" );
703 fprintf( outfile, " {\n" );
704 fprintf( outfile, " { %d, %d, 0x%04x, %d },\n",
705 ne_offset + code_offset, code_size, NE_SEGFLAGS_32BIT, code_size );
706 fprintf( outfile, " { %d, %d, 0x%04x, %d },\n",
707 ne_offset + data_offset, data_size, NE_SEGFLAGS_DATA, data_size );
708 fprintf( outfile, " },\n" );
710 /* resource directory */
712 output_bytes( outfile, resdir_buffer, resdir_size );
713 free( resdir_buffer );
715 /* resident names table */
717 fprintf( outfile, " {\n" );
718 strcpy( string, spec->dll_name );
719 fprintf( outfile, " { %d, \"%s\", 0 },\n", strlen(string), strupper(string) );
720 for (i = 1; i <= spec->limit; i++)
722 ORDDEF *odp = spec->ordinals[i];
723 if (!odp || !odp->name[0]) continue;
724 strcpy( string, odp->name );
725 fprintf( outfile, " { %d, \"%s\", %d },\n", strlen(string), strupper(string), i );
727 fprintf( outfile, " { 0 }\n },\n" );
729 /* imported names table */
731 fprintf( outfile, " { 0, 0 },\n" );
735 output_bytes( outfile, et_buffer, et_size );
740 fprintf( outfile, " {\n" );
741 for ( i = 0; i < nTypes; i++ )
743 char profile[101], *arg;
744 unsigned int arg_types[2];
747 strcpy( profile, get_function_name( typelist[i] ));
748 if ( typelist[i]->type == TYPE_PASCAL )
749 for ( arg = typelist[i]->u.func.arg_types; *arg; arg++ )
753 case 's': /* s_word */
756 case 'l': /* long or segmented pointer */
757 case 'T': /* segmented pointer to null-terminated string */
758 case 'p': /* linear pointer */
759 case 't': /* linear pointer to null-terminated string */
764 /* build the arg types bit fields */
765 arg_types[0] = arg_types[1] = 0;
766 for (j = 0; typelist[i]->u.func.arg_types[j]; j++)
769 switch(typelist[i]->u.func.arg_types[j])
771 case 'w': type = ARG_WORD; break;
772 case 's': type = ARG_SWORD; break;
773 case 'l': type = ARG_LONG; break;
774 case 'p': type = ARG_PTR; break;
775 case 't': type = ARG_STR; break;
776 case 'T': type = ARG_SEGSTR; break;
778 arg_types[j / 10] |= type << (3 * (j % 10));
780 if (typelist[i]->type == TYPE_VARARGS) arg_types[j / 10] |= ARG_VARARG << (3 * (j % 10));
781 if (typelist[i]->flags & FLAG_REGISTER) arg_types[0] |= ARG_REGISTER;
782 if (typelist[i]->flags & FLAG_RET16) arg_types[0] |= ARG_RET16;
784 fprintf( outfile, " { 0x68, __wine_%s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
785 make_c_identifier(spec->file_name), profile,
786 (typelist[i]->flags & FLAG_REGISTER) ? "regs":
787 (typelist[i]->flags & FLAG_RET16) ? "word" : "long" );
789 fprintf( outfile, " 0x%04x, 0xca66, %d, { 0x%08x, 0x%08x } },\n",
790 code_selector, argsize, arg_types[0], arg_types[1] );
792 fprintf( outfile, " 0x%04x, 0xcb66, 0x9090, { 0x%08x, 0x%08x } },\n",
793 code_selector, arg_types[0], arg_types[1] );
795 fprintf( outfile, " },\n {\n" );
797 for (i = 0; i <= spec->limit; i++)
799 ORDDEF *odp = spec->ordinals[i];
807 type = bsearch( &odp, typelist, nTypes, sizeof(ORDDEF *), Spec16TypeCompare );
810 fprintf( outfile, " /* %s.%d */ ", spec->dll_name, i );
812 "{ 0x5566, 0x68, %s, 0xe866, %d /* %s */ },\n",
814 (type - typelist) * callfrom_size - (odp->offset + entrypoint_size),
815 get_function_name( odp ) );
821 fprintf( outfile, " },\n" );
826 output_bytes( outfile, data_buffer, data_size );
833 output_bytes( outfile, resdata_buffer, resdata_size );
834 free( resdata_buffer );
837 fprintf( outfile, "};\n" );
838 fprintf( outfile, "#include \"poppack.h\"\n\n" );
840 /* Output the DLL constructor */
842 sprintf( constructor, "__wine_spec_%s_init", make_c_identifier(spec->file_name) );
843 sprintf( destructor, "__wine_spec_%s_fini", make_c_identifier(spec->file_name) );
848 " extern void __wine_dll_register_16( const struct module_data *, const char * );\n"
849 " __wine_dll_register_16( &module, \"%s\" );\n"
850 "}\n", constructor, spec->file_name );
854 " extern void __wine_dll_unregister_16( const struct module_data * );\n"
855 " __wine_dll_unregister_16( &module );\n"
858 fprintf( outfile, "#ifndef __GNUC__\n" );
859 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
860 fprintf( outfile, "#endif\n" );
862 output_dll_init( outfile, constructor, destructor );
864 fprintf( outfile, "#ifndef __GNUC__\n" );
865 fprintf( outfile, "}\n" );
866 fprintf( outfile, "#endif\n" );