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/winbase16.h"
36 /*******************************************************************
39 * Output a file header with the common declarations we need.
41 static void output_file_header( FILE *outfile )
43 output_standard_file_header( outfile );
44 fprintf( outfile, "extern struct\n{\n" );
45 fprintf( outfile, " void *base[8192];\n" );
46 fprintf( outfile, " unsigned long limit[8192];\n" );
47 fprintf( outfile, " unsigned char flags[8192];\n" );
48 fprintf( outfile, "} wine_ldt_copy;\n\n" );
49 fprintf( outfile, "#define __stdcall __attribute__((__stdcall__))\n\n" );
53 /*******************************************************************
56 static int output_entry_table( unsigned char **ret_buff, DLLSPEC *spec )
58 int i, prev = 0, prev_sel = -1;
59 unsigned char *pstr, *buffer;
60 unsigned char *bundle = NULL;
62 buffer = xmalloc( spec->limit * 5 ); /* we use at most 5 bytes per entry-point */
65 for (i = 1; i <= spec->limit; i++)
69 ORDDEF *odp = spec->ordinals[i];
78 selector = 1; /* Code selector */
81 selector = 2; /* Data selector */
84 selector = 0xfe; /* Constant selector */
90 if (!bundle || prev + 1 != i || prev_sel != selector || *bundle == 255)
92 /* need to start a new bundle */
96 int skip = i - (prev + 1);
112 /* output the entry */
113 *pstr++ = 3; /* flags: exported & public data */
114 offset = odp->offset;
115 memcpy( pstr, &offset, sizeof(WORD) );
116 pstr += sizeof(WORD);
117 (*bundle)++; /* increment bundle entry count */
121 if ((pstr - buffer) & 1) *pstr++ = 0;
122 *ret_buff = xrealloc( buffer, pstr - buffer );
123 return pstr - buffer;
127 /*******************************************************************
130 static void output_bytes( FILE *outfile, const void *buffer, unsigned int size )
133 const unsigned char *ptr = buffer;
135 fprintf( outfile, " {" );
136 for (i = 0; i < size; i++)
138 if (!(i & 7)) fprintf( outfile, "\n " );
139 fprintf( outfile, " 0x%02x", *ptr++ );
140 if (i < size - 1) fprintf( outfile, "," );
142 fprintf( outfile, "\n },\n" );
146 /*******************************************************************
147 * BuildCallFrom16Func
149 * Build a 16-bit-to-Wine callback glue function.
151 * The generated routines are intended to be used as argument conversion
152 * routines to be called by the CallFrom16... core. Thus, the prototypes of
153 * the generated routines are (see also CallFrom16):
155 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
156 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
157 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
158 * CONTEXT86 *context );
160 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
161 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
162 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
163 * 'T'=segmented pointer to null-terminated string).
165 * The generated routines fetch the arguments from the 16-bit stack (pointed
166 * to by 'args'); the offsets of the single argument values are computed
167 * according to the calling convention and the argument types. Then, the
168 * 32-bit entry point is called with these arguments.
170 * For register functions, the arguments (if present) are converted just
171 * the same as for normal functions, but in addition the CONTEXT86 pointer
172 * filled with the current register values is passed to the 32-bit routine.
174 static void BuildCallFrom16Func( FILE *outfile, const char *profile, const char *prefix )
176 int i, pos, argsize = 0;
181 const char *args = profile + 7;
182 const char *ret_type;
184 /* Parse function type */
186 if (!strncmp( "c_", profile, 2 )) usecdecl = 1;
187 else if (!strncmp( "v_", profile, 2 )) varargs = usecdecl = 1;
188 else if (strncmp( "p_", profile, 2 ))
190 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
194 if (!strncmp( "word_", profile + 2, 5 )) short_ret = 1;
195 else if (!strncmp( "regs_", profile + 2, 5 )) reg_func = 1;
196 else if (strncmp( "long_", profile + 2, 5 ))
198 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
202 for ( i = 0; args[i]; i++ )
206 case 's': /* s_word */
209 case 'l': /* long or segmented pointer */
210 case 'T': /* segmented pointer to null-terminated string */
211 case 'p': /* linear pointer */
212 case 't': /* linear pointer to null-terminated string */
217 ret_type = reg_func? "void" : short_ret ? "unsigned short" : "unsigned int";
219 fprintf( outfile, "typedef %s (%s*proc_%s_t)( ",
220 ret_type, usecdecl ? "" : "__stdcall ", profile );
222 for ( i = 0; args[i]; i++ )
224 if ( i ) fprintf( outfile, ", " );
227 case 'w': fprintf( outfile, "unsigned short" ); break;
228 case 's': fprintf( outfile, "short" ); break;
229 case 'l': case 'T': fprintf( outfile, "unsigned int" ); break;
230 case 'p': case 't': fprintf( outfile, "void *" ); break;
233 if (reg_func || varargs)
234 fprintf( outfile, "%svoid *", i? ", " : "" );
236 fprintf( outfile, "void" );
237 fprintf( outfile, " );\n" );
239 fprintf( outfile, "static %s __wine_%s_CallFrom16_%s( proc_%s_t proc, unsigned char *args%s )\n",
240 ret_type, make_c_identifier(prefix), profile, profile,
241 reg_func? ", void *context" : "" );
243 fprintf( outfile, "{\n %sproc(\n", reg_func ? "" : "return " );
245 pos = !usecdecl? argsize : 0;
246 for ( i = 0; args[i]; i++ )
248 if ( i ) fprintf( outfile, ",\n" );
249 fprintf( outfile, " " );
253 if ( !usecdecl ) pos -= 2;
254 fprintf( outfile, "*(unsigned short *)(args+%d)", pos );
255 if ( usecdecl ) pos += 2;
258 case 's': /* s_word */
259 if ( !usecdecl ) pos -= 2;
260 fprintf( outfile, "*(short *)(args+%d)", pos );
261 if ( usecdecl ) pos += 2;
264 case 'l': /* long or segmented pointer */
265 case 'T': /* segmented pointer to null-terminated string */
266 if ( !usecdecl ) pos -= 4;
267 fprintf( outfile, "*(unsigned int *)(args+%d)", pos );
268 if ( usecdecl ) pos += 4;
271 case 'p': /* linear pointer */
272 case 't': /* linear pointer to null-terminated string */
273 if ( !usecdecl ) pos -= 4;
274 fprintf( outfile, "((char*)wine_ldt_copy.base[*(unsigned short*)(args+%d) >> 3] + *(unsigned short*)(args+%d))",
276 if ( usecdecl ) pos += 4;
280 fprintf( stderr, "Unknown arg type '%c'\n", args[i] );
284 fprintf( outfile, "%s context", i? ",\n" : "" );
286 fprintf( outfile, "%s args + %d", i? ",\n" : "", argsize );
287 fprintf( outfile, " );\n}\n\n" );
291 /*******************************************************************
294 static const char *get_function_name( const ORDDEF *odp )
296 static char buffer[80];
298 sprintf( buffer, "%s_%s_%s",
299 (odp->type == TYPE_PASCAL) ? "p" :
300 (odp->type == TYPE_VARARGS) ? "v" : "c",
301 (odp->flags & FLAG_REGISTER) ? "regs" :
302 (odp->flags & FLAG_RET16) ? "word" : "long",
303 odp->u.func.arg_types );
308 /*******************************************************************
311 static int Spec16TypeCompare( const void *e1, const void *e2 )
313 const ORDDEF *odp1 = *(const ORDDEF * const *)e1;
314 const ORDDEF *odp2 = *(const ORDDEF * const *)e2;
316 int type1 = odp1->type;
317 int type2 = odp2->type;
319 if (type1 == TYPE_STUB) type1 = TYPE_CDECL;
320 if (type2 == TYPE_STUB) type2 = TYPE_CDECL;
322 if ((retval = type1 - type2) != 0) return retval;
324 type1 = odp1->flags & (FLAG_RET16|FLAG_REGISTER);
325 type2 = odp2->flags & (FLAG_RET16|FLAG_REGISTER);
327 if ((retval = type1 - type2) != 0) return retval;
329 return strcmp( odp1->u.func.arg_types, odp2->u.func.arg_types );
333 /*******************************************************************
336 * Output the functions for stub entry points
338 static void output_stub_funcs( FILE *outfile, const DLLSPEC *spec )
343 for (i = 0; i <= spec->limit; i++)
345 ORDDEF *odp = spec->ordinals[i];
346 if (!odp || odp->type != TYPE_STUB) continue;
347 fprintf( outfile, "#ifdef __GNUC__\n" );
348 fprintf( outfile, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func ) __attribute__((noreturn));\n" );
349 fprintf( outfile, "#else\n" );
350 fprintf( outfile, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func );\n" );
351 fprintf( outfile, "#endif\n\n" );
354 for (i = 0; i <= spec->limit; i++)
356 ORDDEF *odp = spec->ordinals[i];
357 if (!odp || odp->type != TYPE_STUB) continue;
358 odp->link_name = xrealloc( odp->link_name, strlen(odp->name) + 13 );
359 strcpy( odp->link_name, "__wine_stub_" );
360 strcat( odp->link_name, odp->name );
361 for (p = odp->link_name; *p; p++) if (!isalnum(*p)) *p = '_';
362 fprintf( outfile, "static void %s(void) { __wine_spec_unimplemented_stub(__wine_spec16_file_name, \"%s\"); }\n",
363 odp->link_name, odp->name );
368 /*******************************************************************
371 * Build a Win16 assembly file from a spec file.
373 void BuildSpec16File( FILE *outfile, DLLSPEC *spec )
375 ORDDEF **type, **typelist;
376 int i, nFuncs, nTypes;
377 unsigned char *resdir_buffer, *resdata_buffer, *et_buffer, *data_buffer;
379 unsigned int ne_offset, segtable_offset, impnames_offset;
380 unsigned int entrypoint_size, callfrom_size;
381 unsigned int code_size, code_offset;
382 unsigned int data_size, data_offset;
383 unsigned int resnames_size, resnames_offset;
384 unsigned int resdir_size, resdir_offset;
385 unsigned int resdata_size, resdata_offset, resdata_align;
386 unsigned int et_size, et_offset;
388 char constructor[100], destructor[100];
392 output_file_header( outfile );
393 fprintf( outfile, "static const char __wine_spec16_file_name[] = \"%s\";\n", spec->file_name );
395 data_buffer = xmalloc( 0x10000 );
396 memset( data_buffer, 0, 16 );
399 if (!spec->dll_name) /* set default name from file name */
402 spec->dll_name = xstrdup( spec->file_name );
403 if ((p = strrchr( spec->dll_name, '.' ))) *p = 0;
406 output_stub_funcs( outfile, spec );
408 /* Build sorted list of all argument types, without duplicates */
410 typelist = (ORDDEF **)calloc( spec->limit+1, sizeof(ORDDEF *) );
412 for (i = nFuncs = 0; i <= spec->limit; i++)
414 ORDDEF *odp = spec->ordinals[i];
422 typelist[nFuncs++] = odp;
429 qsort( typelist, nFuncs, sizeof(ORDDEF *), Spec16TypeCompare );
434 typelist[nTypes++] = typelist[i++];
435 while ( i < nFuncs && Spec16TypeCompare( typelist + i, typelist + nTypes-1 ) == 0 )
439 /* Output CallFrom16 routines needed by this .spec file */
440 for ( i = 0; i < nTypes; i++ )
444 strcpy( profile, get_function_name( typelist[i] ));
445 BuildCallFrom16Func( outfile, profile, spec->file_name );
448 /* compute code and data sizes, set offsets, and output prototypes */
450 entrypoint_size = 2 + 5 + 4; /* pushw bp + pushl target + call */
451 callfrom_size = 5 + 7 + 10 + 2 + 8; /* pushl relay + lcall cs:glue + ret sequence + movl + args */
452 code_size = nTypes * callfrom_size;
454 for (i = 0; i <= spec->limit; i++)
456 ORDDEF *odp = spec->ordinals[i];
461 odp->offset = LOWORD(odp->u.abs.value);
464 odp->offset = data_size;
465 memcpy( data_buffer + data_size, odp->u.var.values, odp->u.var.n_values * sizeof(int) );
466 data_size += odp->u.var.n_values * sizeof(int);
471 fprintf( outfile, "extern void %s();\n", odp->link_name );
474 odp->offset = code_size;
475 code_size += entrypoint_size;
482 data_buffer = xrealloc( data_buffer, data_size ); /* free unneeded data */
484 /* Output the module structure */
488 fprintf( outfile, "\n#pragma pack(1)\n" );
489 fprintf( outfile, "static const struct module_data\n{\n" );
490 fprintf( outfile, " struct\n {\n" );
491 fprintf( outfile, " unsigned short e_magic;\n" );
492 fprintf( outfile, " unsigned short e_cblp;\n" );
493 fprintf( outfile, " unsigned short e_cp;\n" );
494 fprintf( outfile, " unsigned short e_crlc;\n" );
495 fprintf( outfile, " unsigned short e_cparhdr;\n" );
496 fprintf( outfile, " unsigned short e_minalloc;\n" );
497 fprintf( outfile, " unsigned short e_maxalloc;\n" );
498 fprintf( outfile, " unsigned short e_ss;\n" );
499 fprintf( outfile, " unsigned short e_sp;\n" );
500 fprintf( outfile, " unsigned short e_csum;\n" );
501 fprintf( outfile, " unsigned short e_ip;\n" );
502 fprintf( outfile, " unsigned short e_cs;\n" );
503 fprintf( outfile, " unsigned short e_lfarlc;\n" );
504 fprintf( outfile, " unsigned short e_ovno;\n" );
505 fprintf( outfile, " unsigned short e_res[4];\n" );
506 fprintf( outfile, " unsigned short e_oemid;\n" );
507 fprintf( outfile, " unsigned short e_oeminfo;\n" );
508 fprintf( outfile, " unsigned short e_res2[10];\n" );
509 fprintf( outfile, " unsigned int e_lfanew;\n" );
510 fprintf( outfile, " } dos_header;\n" );
515 fprintf( outfile, " struct\n {\n" );
516 fprintf( outfile, " unsigned short ne_magic;\n" );
517 fprintf( outfile, " unsigned char ne_ver;\n" );
518 fprintf( outfile, " unsigned char ne_rev;\n" );
519 fprintf( outfile, " unsigned short ne_enttab;\n" );
520 fprintf( outfile, " unsigned short ne_cbenttab;\n" );
521 fprintf( outfile, " int ne_crc;\n" );
522 fprintf( outfile, " unsigned short ne_flags;\n" );
523 fprintf( outfile, " unsigned short ne_autodata;\n" );
524 fprintf( outfile, " unsigned short ne_heap;\n" );
525 fprintf( outfile, " unsigned short ne_stack;\n" );
526 fprintf( outfile, " unsigned int ne_csip;\n" );
527 fprintf( outfile, " unsigned int ne_sssp;\n" );
528 fprintf( outfile, " unsigned short ne_cseg;\n" );
529 fprintf( outfile, " unsigned short ne_cmod;\n" );
530 fprintf( outfile, " unsigned short ne_cbnrestab;\n" );
531 fprintf( outfile, " unsigned short ne_segtab;\n" );
532 fprintf( outfile, " unsigned short ne_rsrctab;\n" );
533 fprintf( outfile, " unsigned short ne_restab;\n" );
534 fprintf( outfile, " unsigned short ne_modtab;\n" );
535 fprintf( outfile, " unsigned short ne_imptab;\n" );
536 fprintf( outfile, " unsigned int ne_nrestab;\n" );
537 fprintf( outfile, " unsigned short ne_cmovent;\n" );
538 fprintf( outfile, " unsigned short ne_align;\n" );
539 fprintf( outfile, " unsigned short ne_cres;\n" );
540 fprintf( outfile, " unsigned char ne_exetyp;\n" );
541 fprintf( outfile, " unsigned char ne_flagsothers;\n" );
542 fprintf( outfile, " unsigned short ne_pretthunks;\n" );
543 fprintf( outfile, " unsigned short ne_psegrefbytes;\n" );
544 fprintf( outfile, " unsigned short ne_swaparea;\n" );
545 fprintf( outfile, " unsigned short ne_expver;\n" );
546 fprintf( outfile, " } os2_header;\n" );
550 segtable_offset = 64;
551 fprintf( outfile, " struct\n {\n" );
552 fprintf( outfile, " unsigned short filepos;\n" );
553 fprintf( outfile, " unsigned short size;\n" );
554 fprintf( outfile, " unsigned short flags;\n" );
555 fprintf( outfile, " unsigned short minsize;\n" );
556 fprintf( outfile, " } segtable[2];\n" );
558 /* resource directory */
560 resdir_offset = segtable_offset + 2 * 8;
561 resdir_size = get_res16_directory_size( spec );
562 fprintf( outfile, " unsigned char resdir[%d];\n", resdir_size );
564 /* resident names table */
566 resnames_offset = resdir_offset + resdir_size;
567 fprintf( outfile, " struct\n {\n" );
568 fprintf( outfile, " struct { unsigned char len; char name[%d]; unsigned short ord; } name_0;\n",
569 strlen( spec->dll_name ) );
570 resnames_size = 3 + strlen( spec->dll_name );
571 for (i = 1; i <= spec->limit; i++)
573 ORDDEF *odp = spec->ordinals[i];
574 if (!odp || !odp->name[0]) continue;
575 fprintf( outfile, " struct { unsigned char len; char name[%d]; unsigned short ord; } name_%d;\n",
576 strlen(odp->name), i );
577 resnames_size += 3 + strlen( odp->name );
579 fprintf( outfile, " unsigned char name_last[%d];\n", 2 - (resnames_size & 1) );
580 resnames_size = (resnames_size + 2) & ~1;
581 fprintf( outfile, " } resnames;\n" );
583 /* imported names table */
585 impnames_offset = resnames_offset + resnames_size;
586 fprintf( outfile, " unsigned char impnames[2];\n" );
590 et_offset = impnames_offset + 2;
591 et_size = output_entry_table( &et_buffer, spec );
592 fprintf( outfile, " unsigned char entry_table[%d];\n", et_size );
596 code_offset = et_offset + et_size;
597 fprintf( outfile, " struct {\n" );
598 fprintf( outfile, " unsigned char pushl;\n" ); /* pushl $relay */
599 fprintf( outfile, " void *relay;\n" );
600 fprintf( outfile, " unsigned char lcall;\n" ); /* lcall __FLATCS__:glue */
601 fprintf( outfile, " void *glue;\n" );
602 fprintf( outfile, " unsigned short flatcs;\n" );
603 fprintf( outfile, " unsigned short ret[5];\n" ); /* return sequence */
604 fprintf( outfile, " unsigned short movl;\n" ); /* movl arg_types[1],arg_types[0](%esi) */
605 fprintf( outfile, " unsigned int arg_types[2];\n" );
606 fprintf( outfile, " } call[%d];\n", nTypes );
607 fprintf( outfile, " struct {\n" );
608 fprintf( outfile, " unsigned short pushw_bp;\n" ); /* pushw %bp */
609 fprintf( outfile, " unsigned char pushl;\n" ); /* pushl $target */
610 fprintf( outfile, " void (*target)();\n" );
611 fprintf( outfile, " unsigned short call;\n" ); /* call CALLFROM16 */
612 fprintf( outfile, " short callfrom16;\n" );
613 fprintf( outfile, " } entry[%d];\n", nFuncs );
617 data_offset = code_offset + code_size;
618 fprintf( outfile, " unsigned char data_segment[%d];\n", data_size );
619 if (data_offset + data_size >= 0x10000)
620 fatal_error( "Not supported yet: 16-bit module data larger than 64K\n" );
624 resdata_offset = ne_offset + data_offset + data_size;
625 for (resdata_align = 0; resdata_align < 16; resdata_align++)
627 unsigned int size = get_res16_data_size( spec, resdata_offset, resdata_align );
628 if ((resdata_offset + size) >> resdata_align <= 0xffff) break;
630 output_res16_directory( &resdir_buffer, spec, resdata_offset, resdata_align );
631 resdata_size = output_res16_data( &resdata_buffer, spec, resdata_offset, resdata_align );
632 if (resdata_size) fprintf( outfile, " unsigned char resources[%d];\n", resdata_size );
634 /* Output the module data */
638 fprintf( outfile, "} module =\n{\n {\n" );
639 fprintf( outfile, " 0x%04x,\n", IMAGE_DOS_SIGNATURE ); /* e_magic */
640 fprintf( outfile, " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n" );
641 fprintf( outfile, " { 0, 0, 0, 0, }, 0, 0,\n" );
642 fprintf( outfile, " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },\n" );
643 fprintf( outfile, " sizeof(module.dos_header)\n" ); /* e_lfanew */
647 fprintf( outfile, " },\n {\n" );
648 fprintf( outfile, " 0x%04x,\n", IMAGE_OS2_SIGNATURE ); /* ne_magic */
649 fprintf( outfile, " 0, 0,\n" );
650 fprintf( outfile, " %d,\n", et_offset ); /* ne_enttab */
651 fprintf( outfile, " sizeof(module.entry_table),\n" ); /* ne_cbenttab */
652 fprintf( outfile, " 0,\n" ); /* ne_crc */
653 fprintf( outfile, " 0x%04x,\n", /* ne_flags */
654 NE_FFLAGS_SINGLEDATA | NE_FFLAGS_LIBMODULE );
655 fprintf( outfile, " 2,\n" ); /* ne_autodata */
656 fprintf( outfile, " %d,\n", spec->heap_size ); /* ne_heap */
657 fprintf( outfile, " 0, 0, 0,\n" );
658 fprintf( outfile, " 2,\n" ); /* ne_cseg */
659 fprintf( outfile, " 0,\n" ); /* ne_cmod */
660 fprintf( outfile, " 0,\n" ); /* ne_cbnrestab */
661 fprintf( outfile, " %d,\n", segtable_offset ); /* ne_segtab */
662 fprintf( outfile, " %d,\n", resdir_offset ); /* ne_rsrctab */
663 fprintf( outfile, " %d,\n", resnames_offset ); /* ne_restab */
664 fprintf( outfile, " %d,\n", impnames_offset ); /* ne_modtab */
665 fprintf( outfile, " %d,\n", impnames_offset ); /* ne_imptab */
666 fprintf( outfile, " 0,\n" ); /* ne_nrestab */
667 fprintf( outfile, " 0,\n" ); /* ne_cmovent */
668 fprintf( outfile, " 0,\n" ); /* ne_align */
669 fprintf( outfile, " 0,\n" ); /* ne_cres */
670 fprintf( outfile, " 0x%04x,\n", NE_OSFLAGS_WINDOWS ); /* ne_exetyp */
671 fprintf( outfile, " 0x%04x,\n", NE_AFLAGS_FASTLOAD ); /* ne_flagsothers */
672 fprintf( outfile, " 0,\n" ); /* ne_pretthunks */
673 fprintf( outfile, " 0,\n" ); /* ne_psegrefbytes */
674 fprintf( outfile, " 0,\n" ); /* ne_swaparea */
675 fprintf( outfile, " 0\n" ); /* ne_expver */
676 fprintf( outfile, " },\n" );
680 fprintf( outfile, " {\n" );
681 fprintf( outfile, " { %d, %d, 0x%04x, %d },\n",
682 ne_offset + code_offset, code_size, NE_SEGFLAGS_32BIT, code_size );
683 fprintf( outfile, " { %d, %d, 0x%04x, %d },\n",
684 ne_offset + data_offset, data_size, NE_SEGFLAGS_DATA, data_size );
685 fprintf( outfile, " },\n" );
687 /* resource directory */
689 output_bytes( outfile, resdir_buffer, resdir_size );
690 free( resdir_buffer );
692 /* resident names table */
694 fprintf( outfile, " {\n" );
695 strcpy( string, spec->dll_name );
696 fprintf( outfile, " { %d, \"%s\", 0 },\n", strlen(string), strupper(string) );
697 for (i = 1; i <= spec->limit; i++)
699 ORDDEF *odp = spec->ordinals[i];
700 if (!odp || !odp->name[0]) continue;
701 strcpy( string, odp->name );
702 fprintf( outfile, " { %d, \"%s\", %d },\n", strlen(string), strupper(string), i );
704 fprintf( outfile, " { 0 }\n },\n" );
706 /* imported names table */
708 fprintf( outfile, " { 0, 0 },\n" );
712 output_bytes( outfile, et_buffer, et_size );
717 fprintf( outfile, " {\n" );
718 for ( i = 0; i < nTypes; i++ )
720 char profile[101], *arg;
721 unsigned int arg_types[2];
724 strcpy( profile, get_function_name( typelist[i] ));
725 if ( typelist[i]->type == TYPE_PASCAL )
726 for ( arg = typelist[i]->u.func.arg_types; *arg; arg++ )
730 case 's': /* s_word */
733 case 'l': /* long or segmented pointer */
734 case 'T': /* segmented pointer to null-terminated string */
735 case 'p': /* linear pointer */
736 case 't': /* linear pointer to null-terminated string */
741 /* build the arg types bit fields */
742 arg_types[0] = arg_types[1] = 0;
743 for (j = 0; typelist[i]->u.func.arg_types[j]; j++)
746 switch(typelist[i]->u.func.arg_types[j])
748 case 'w': type = ARG_WORD; break;
749 case 's': type = ARG_SWORD; break;
750 case 'l': type = ARG_LONG; break;
751 case 'p': type = ARG_PTR; break;
752 case 't': type = ARG_STR; break;
753 case 'T': type = ARG_SEGSTR; break;
755 arg_types[j / 10] |= type << (3 * (j % 10));
757 if (typelist[i]->type == TYPE_VARARGS) arg_types[j / 10] |= ARG_VARARG << (3 * (j % 10));
759 fprintf( outfile, " { 0x68, __wine_%s_CallFrom16_%s, 0x9a, 0, 0,\n ",
760 make_c_identifier(spec->file_name), profile );
762 if (typelist[i]->flags & FLAG_REGISTER)
764 /* ret sequence: ret $n; nop */
766 fprintf( outfile, "{ 0xca66, %d, 0xb68d, 0x0000, 0x0000 },", argsize );
768 fprintf( outfile, "{ 0xcb66, 0x748d, 0x0026, 0x748d, 0x0026 }," );
770 else if (typelist[i]->flags & FLAG_RET16)
772 /* ret sequence: orl %eax,%eax; ret $n; nop */
774 fprintf( outfile, "{ 0xc009, 0xca66, %d, 0x748d, 0x0026 },", argsize );
776 fprintf( outfile, "{ 0xc009, 0xcb66, 0xb68d, 0x0000, 0x0000 }," );
780 /* ret sequence: shld $16,%eax,%edx; orl %eax,%eax; ret $n [; nop] */
782 fprintf( outfile, "{ 0xa40f, 0x10c2, 0xc009, 0xca66, %d },", argsize );
784 fprintf( outfile, "{ 0xa40f, 0x10c2, 0xc009, 0xcb66, 0xf689 }," );
786 /* the movl is here so that the code contains only valid instructions, */
787 /* it's never actually executed, we only care about the arg_types[] values */
788 fprintf( outfile, " 0x86c7, { 0x%08x, 0x%08x } },\n", arg_types[0], arg_types[1] );
790 fprintf( outfile, " },\n {\n" );
792 for (i = 0; i <= spec->limit; i++)
794 ORDDEF *odp = spec->ordinals[i];
802 type = bsearch( &odp, typelist, nTypes, sizeof(ORDDEF *), Spec16TypeCompare );
805 fprintf( outfile, " /* %s.%d */ ", spec->dll_name, i );
807 "{ 0x5566, 0x68, %s, 0xe866, %d /* %s */ },\n",
809 (type - typelist) * callfrom_size - (odp->offset + entrypoint_size),
810 get_function_name( odp ) );
816 fprintf( outfile, " },\n" );
821 output_bytes( outfile, data_buffer, data_size );
828 output_bytes( outfile, resdata_buffer, resdata_size );
829 free( resdata_buffer );
832 fprintf( outfile, "};\n" );
833 fprintf( outfile, "#pragma pack()\n\n" );
835 /* Output the DLL constructor */
837 sprintf( constructor, "__wine_spec_%s_init", make_c_identifier(spec->file_name) );
838 sprintf( destructor, "__wine_spec_%s_fini", make_c_identifier(spec->file_name) );
843 " extern void __wine_dll_register_16( const struct module_data *, const char * );\n"
844 " __wine_dll_register_16( &module, \"%s\" );\n"
845 "}\n", constructor, spec->file_name );
849 " extern void __wine_dll_unregister_16( const struct module_data * );\n"
850 " __wine_dll_unregister_16( &module );\n"
853 fprintf( outfile, "#ifndef __GNUC__\n" );
854 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
855 fprintf( outfile, "#endif\n" );
857 output_dll_init( outfile, constructor, destructor );
859 fprintf( outfile, "#ifndef __GNUC__\n" );
860 fprintf( outfile, "}\n" );
861 fprintf( outfile, "#endif\n" );