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 "stackframe.h"
33 #include "builtin16.h"
39 /*******************************************************************
43 static inline unsigned short get_cs(void)
47 __asm__("movw %%cs,%w0" : "=r"(res
));
48 #elif defined(_MSC_VER)
58 /*******************************************************************
61 * Output a file header with the common declarations we need.
63 static void output_file_header( FILE *outfile
)
65 output_standard_file_header( outfile
);
66 fprintf( outfile
, "extern struct\n{\n" );
67 fprintf( outfile
, " void *base[8192];\n" );
68 fprintf( outfile
, " unsigned long limit[8192];\n" );
69 fprintf( outfile
, " unsigned char flags[8192];\n" );
70 fprintf( outfile
, "} wine_ldt_copy;\n\n" );
72 fprintf( outfile
, "#define __stdcall __attribute__((__stdcall__))\n\n" );
74 fprintf( outfile
, "#define __stdcall\n\n" );
79 /*******************************************************************
82 * Store a list of ints into a byte array.
84 static int StoreVariableCode( unsigned char *buffer
, int size
, ORDDEF
*odp
)
91 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
92 buffer
[i
] = odp
->u
.var
.values
[i
];
95 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
96 ((unsigned short *)buffer
)[i
] = odp
->u
.var
.values
[i
];
99 for (i
= 0; i
< odp
->u
.var
.n_values
; i
++)
100 ((unsigned int *)buffer
)[i
] = odp
->u
.var
.values
[i
];
103 return odp
->u
.var
.n_values
* size
;
107 /*******************************************************************
110 * Build the in-memory representation of a 16-bit NE module, and dump it
111 * as a byte stream into the assembly code.
113 static int BuildModule16( FILE *outfile
, int max_code_offset
,
114 int max_data_offset
)
119 SEGTABLEENTRY
*pSegment
;
122 ET_BUNDLE
*bundle
= 0;
127 * OFSTRUCT File information
128 * SEGTABLEENTRY Segment 1 (code)
129 * SEGTABLEENTRY Segment 2 (data)
130 * WORD[2] Resource table (empty)
131 * BYTE[2] Imported names (empty)
132 * BYTE[n] Resident names table
133 * BYTE[n] Entry table
136 buffer
= xmalloc( 0x10000 );
137 memset( buffer
, 0, 0x10000 );
139 pModule
= (NE_MODULE
*)buffer
;
140 pModule
->magic
= IMAGE_OS2_SIGNATURE
;
143 pModule
->flags
= NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_BUILTIN
| NE_FFLAGS_LIBMODULE
;
145 pModule
->heap_size
= DLLHeapSize
;
146 pModule
->stack_size
= 0;
151 pModule
->seg_count
= 2;
152 pModule
->modref_count
= 0;
153 pModule
->nrname_size
= 0;
154 pModule
->modref_table
= 0;
155 pModule
->nrname_fpos
= 0;
156 pModule
->moveable_entries
= 0;
157 pModule
->alignment
= 0;
158 pModule
->truetype
= 0;
159 pModule
->os_flags
= NE_OSFLAGS_WINDOWS
;
160 pModule
->misc_flags
= 0;
161 pModule
->dlls_to_init
= 0;
162 pModule
->nrname_handle
= 0;
163 pModule
->min_swap_area
= 0;
164 pModule
->expected_version
= 0;
165 pModule
->module32
= 0;
167 pModule
->self_loading_sel
= 0;
169 /* File information */
171 pFileInfo
= (OFSTRUCT
*)(pModule
+ 1);
172 pModule
->fileinfo
= (int)pFileInfo
- (int)pModule
;
173 memset( pFileInfo
, 0, sizeof(*pFileInfo
) - sizeof(pFileInfo
->szPathName
) );
174 pFileInfo
->cBytes
= sizeof(*pFileInfo
) - sizeof(pFileInfo
->szPathName
)
175 + strlen(dll_file_name
);
176 strcpy( pFileInfo
->szPathName
, dll_file_name
);
177 pstr
= (char *)pFileInfo
+ pFileInfo
->cBytes
+ 1;
181 pstr
= (char *)(((long)pstr
+ 3) & ~3);
182 pSegment
= (SEGTABLEENTRY
*)pstr
;
183 pModule
->seg_table
= (int)pSegment
- (int)pModule
;
184 pSegment
->filepos
= 0;
185 pSegment
->size
= max_code_offset
;
187 pSegment
->minsize
= max_code_offset
;
191 pModule
->dgroup_entry
= (int)pSegment
- (int)pModule
;
192 pSegment
->filepos
= 0;
193 pSegment
->size
= max_data_offset
;
194 pSegment
->flags
= NE_SEGFLAGS_DATA
;
195 pSegment
->minsize
= max_data_offset
;
201 pstr
= (char *)pSegment
;
202 pstr
= (char *)(((long)pstr
+ 3) & ~3);
203 pModule
->res_table
= (int)pstr
- (int)pModule
;
204 pstr
+= output_res16_directory( pstr
);
206 /* Imported names table */
208 pstr
= (char *)(((long)pstr
+ 3) & ~3);
209 pModule
->import_table
= (int)pstr
- (int)pModule
;
213 /* Resident names table */
215 pstr
= (char *)(((long)pstr
+ 3) & ~3);
216 pModule
->name_table
= (int)pstr
- (int)pModule
;
217 /* First entry is module name */
218 *pstr
= strlen( dll_name
);
219 strcpy( pstr
+ 1, dll_name
);
220 strupper( pstr
+ 1 );
224 /* Store all ordinals */
225 for (i
= 1; i
<= Limit
; i
++)
227 ORDDEF
*odp
= Ordinals
[i
];
229 if (!odp
|| !odp
->name
[0]) continue;
230 *pstr
= strlen( odp
->name
);
231 strcpy( pstr
+ 1, odp
->name
);
232 strupper( pstr
+ 1 );
234 memcpy( pstr
, &ord
, sizeof(WORD
) );
235 pstr
+= sizeof(WORD
);
241 pstr
= (char *)(((long)pstr
+ 3) & ~3);
242 pModule
->entry_table
= (int)pstr
- (int)pModule
;
243 for (i
= 1; i
<= Limit
; i
++)
246 ORDDEF
*odp
= Ordinals
[i
];
255 selector
= 1; /* Code selector */
259 selector
= 2; /* Data selector */
263 selector
= 0xfe; /* Constant selector */
267 selector
= 0; /* Invalid selector */
274 if ( bundle
&& bundle
->last
+1 == i
)
278 pstr
= (char *)(((long)pstr
+ 1) & ~1);
280 bundle
->next
= (char *)pstr
- (char *)pModule
;
282 bundle
= (ET_BUNDLE
*)pstr
;
286 pstr
+= sizeof(ET_BUNDLE
);
289 /* FIXME: is this really correct ?? */
290 entry
.type
= 0xff; /* movable */
291 entry
.flags
= 3; /* exported & public data */
292 entry
.segnum
= selector
;
293 entry
.offs
= odp
->offset
;
294 memcpy( pstr
, &entry
, sizeof(ET_ENTRY
) );
295 pstr
+= sizeof(ET_ENTRY
);
299 /* Dump the module content */
301 pstr
= (char *)(((long)pstr
+ 3) & ~3);
302 dump_bytes( outfile
, (char *)pModule
, (int)pstr
- (int)pModule
, "Module", 0 );
303 return (int)pstr
- (int)pModule
;
307 /*******************************************************************
308 * BuildCallFrom16Func
310 * Build a 16-bit-to-Wine callback glue function.
312 * The generated routines are intended to be used as argument conversion
313 * routines to be called by the CallFrom16... core. Thus, the prototypes of
314 * the generated routines are (see also CallFrom16):
316 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
317 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
318 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
319 * CONTEXT86 *context );
320 * extern void WINAPI PREFIX_CallFrom16_C_intr_xxx( FARPROC func, LPBYTE args,
321 * CONTEXT86 *context );
323 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
324 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
325 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
326 * 'T'=segmented pointer to null-terminated string).
328 * The generated routines fetch the arguments from the 16-bit stack (pointed
329 * to by 'args'); the offsets of the single argument values are computed
330 * according to the calling convention and the argument types. Then, the
331 * 32-bit entry point is called with these arguments.
333 * For register functions, the arguments (if present) are converted just
334 * the same as for normal functions, but in addition the CONTEXT86 pointer
335 * filled with the current register values is passed to the 32-bit routine.
336 * (An 'intr' interrupt handler routine is treated exactly like a register
337 * routine, except that upon return, the flags word pushed onto the stack
338 * by the interrupt is removed by the 16-bit call stub.)
341 static void BuildCallFrom16Func( FILE *outfile
, const char *profile
, const char *prefix
)
343 int i
, pos
, argsize
= 0;
348 const char *args
= profile
+ 7;
349 const char *ret_type
;
351 /* Parse function type */
353 if (!strncmp( "c_", profile
, 2 )) usecdecl
= 1;
354 else if (!strncmp( "v_", profile
, 2 )) varargs
= usecdecl
= 1;
355 else if (strncmp( "p_", profile
, 2 ))
357 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
361 if (!strncmp( "word_", profile
+ 2, 5 )) short_ret
= 1;
362 else if (!strncmp( "regs_", profile
+ 2, 5 )) reg_func
= 1;
363 else if (!strncmp( "intr_", profile
+ 2, 5 )) reg_func
= 2;
364 else if (strncmp( "long_", profile
+ 2, 5 ))
366 fprintf( stderr
, "Invalid function name '%s', ignored\n", profile
);
370 for ( i
= 0; args
[i
]; i
++ )
374 case 's': /* s_word */
377 case 'l': /* long or segmented pointer */
378 case 'T': /* segmented pointer to null-terminated string */
379 case 'p': /* linear pointer */
380 case 't': /* linear pointer to null-terminated string */
385 ret_type
= reg_func
? "void" : short_ret
? "unsigned short" : "unsigned int";
387 fprintf( outfile
, "typedef %s (%s*proc_%s_t)( ",
388 ret_type
, usecdecl
? "" : "__stdcall ", profile
);
390 for ( i
= 0; args
[i
]; i
++ )
392 if ( i
) fprintf( outfile
, ", " );
395 case 'w': fprintf( outfile
, "unsigned short" ); break;
396 case 's': fprintf( outfile
, "short" ); break;
397 case 'l': case 'T': fprintf( outfile
, "unsigned int" ); break;
398 case 'p': case 't': fprintf( outfile
, "void *" ); break;
401 if (reg_func
|| varargs
)
402 fprintf( outfile
, "%svoid *", i
? ", " : "" );
404 fprintf( outfile
, "void" );
405 fprintf( outfile
, " );\n" );
407 fprintf( outfile
, "static %s __stdcall __wine_%s_CallFrom16_%s( proc_%s_t proc, unsigned char *args%s )\n",
408 ret_type
, make_c_identifier(prefix
), profile
, profile
,
409 reg_func
? ", void *context" : "" );
411 fprintf( outfile
, "{\n %sproc(\n", reg_func
? "" : "return " );
413 pos
= !usecdecl
? argsize
: 0;
414 for ( i
= 0; args
[i
]; i
++ )
416 if ( i
) fprintf( outfile
, ",\n" );
417 fprintf( outfile
, " " );
421 if ( !usecdecl
) pos
-= 2;
422 fprintf( outfile
, "*(unsigned short *)(args+%d)", pos
);
423 if ( usecdecl
) pos
+= 2;
426 case 's': /* s_word */
427 if ( !usecdecl
) pos
-= 2;
428 fprintf( outfile
, "*(short *)(args+%d)", pos
);
429 if ( usecdecl
) pos
+= 2;
432 case 'l': /* long or segmented pointer */
433 case 'T': /* segmented pointer to null-terminated string */
434 if ( !usecdecl
) pos
-= 4;
435 fprintf( outfile
, "*(unsigned int *)(args+%d)", pos
);
436 if ( usecdecl
) pos
+= 4;
439 case 'p': /* linear pointer */
440 case 't': /* linear pointer to null-terminated string */
441 if ( !usecdecl
) pos
-= 4;
442 fprintf( outfile
, "((char*)wine_ldt_copy.base[*(unsigned short*)(args+%d) >> 3] + *(unsigned short*)(args+%d))",
444 if ( usecdecl
) pos
+= 4;
448 fprintf( stderr
, "Unknown arg type '%c'\n", args
[i
] );
452 fprintf( outfile
, "%s context", i
? ",\n" : "" );
454 fprintf( outfile
, "%s args + %d", i
? ",\n" : "", argsize
);
455 fprintf( outfile
, " );\n}\n\n" );
459 /*******************************************************************
462 static const char *get_function_name( const ORDDEF
*odp
)
464 static char buffer
[80];
466 sprintf( buffer
, "%s_%s_%s",
467 (odp
->type
== TYPE_PASCAL
) ? "p" :
468 (odp
->type
== TYPE_VARARGS
) ? "v" : "c",
469 (odp
->flags
& FLAG_REGISTER
) ? "regs" :
470 (odp
->flags
& FLAG_INTERRUPT
) ? "intr" :
471 (odp
->flags
& FLAG_RET16
) ? "word" : "long",
472 odp
->u
.func
.arg_types
);
477 /*******************************************************************
480 static int Spec16TypeCompare( const void *e1
, const void *e2
)
482 const ORDDEF
*odp1
= *(const ORDDEF
**)e1
;
483 const ORDDEF
*odp2
= *(const ORDDEF
**)e2
;
485 int type1
= odp1
->type
;
486 int type2
= odp2
->type
;
488 if (type1
== TYPE_STUB
) type1
= TYPE_CDECL
;
489 if (type2
== TYPE_STUB
) type2
= TYPE_CDECL
;
491 if ((retval
= type1
- type2
) != 0) return retval
;
493 type1
= odp1
->flags
& (FLAG_RET16
|FLAG_REGISTER
|FLAG_INTERRUPT
);
494 type2
= odp2
->flags
& (FLAG_RET16
|FLAG_REGISTER
|FLAG_INTERRUPT
);
496 if ((retval
= type1
- type2
) != 0) return retval
;
498 return strcmp( odp1
->u
.func
.arg_types
, odp2
->u
.func
.arg_types
);
502 /*******************************************************************
505 * Output the functions for stub entry points
507 static void output_stub_funcs( FILE *outfile
)
512 for (i
= 0; i
<= Limit
; i
++)
514 ORDDEF
*odp
= Ordinals
[i
];
515 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
516 fprintf( outfile
, "#ifdef __GNUC__\n" );
517 fprintf( outfile
, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
518 fprintf( outfile
, "#endif\n" );
519 fprintf( outfile
, "static void __wine_unimplemented( const char *func )\n{\n" );
520 fprintf( outfile
, " struct exc_record {\n" );
521 fprintf( outfile
, " unsigned int code, flags;\n" );
522 fprintf( outfile
, " void *rec, *addr;\n" );
523 fprintf( outfile
, " unsigned int params;\n" );
524 fprintf( outfile
, " const void *info[15];\n" );
525 fprintf( outfile
, " } rec;\n\n" );
526 fprintf( outfile
, " extern void __stdcall RtlRaiseException( struct exc_record * );\n\n" );
527 fprintf( outfile
, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB
);
528 fprintf( outfile
, " rec.flags = %d;\n", EH_NONCONTINUABLE
);
529 fprintf( outfile
, " rec.rec = 0;\n" );
530 fprintf( outfile
, " rec.params = 2;\n" );
531 fprintf( outfile
, " rec.info[0] = \"%s\";\n", dll_file_name
);
532 fprintf( outfile
, " rec.info[1] = func;\n" );
533 fprintf( outfile
, "#ifdef __GNUC__\n" );
534 fprintf( outfile
, " rec.addr = __builtin_return_address(1);\n" );
535 fprintf( outfile
, "#else\n" );
536 fprintf( outfile
, " rec.addr = 0;\n" );
537 fprintf( outfile
, "#endif\n" );
538 fprintf( outfile
, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
541 for (i
= 0; i
<= Limit
; i
++)
543 ORDDEF
*odp
= Ordinals
[i
];
544 if (!odp
|| odp
->type
!= TYPE_STUB
) continue;
545 odp
->link_name
= xrealloc( odp
->link_name
, strlen(odp
->name
) + 13 );
546 strcpy( odp
->link_name
, "__wine_stub_" );
547 strcat( odp
->link_name
, odp
->name
);
548 for (p
= odp
->link_name
; *p
; p
++) if (!isalnum(*p
)) *p
= '_';
549 fprintf( outfile
, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
550 odp
->link_name
, odp
->name
);
555 /*******************************************************************
558 * Build a Win16 assembly file from a spec file.
560 void BuildSpec16File( FILE *outfile
)
562 ORDDEF
**type
, **typelist
;
563 int i
, nFuncs
, nTypes
;
564 int code_offset
, data_offset
, module_size
, res_size
;
566 char constructor
[100], destructor
[100];
568 unsigned short code_selector
= get_cs();
573 output_file_header( outfile
);
574 fprintf( outfile
, "extern unsigned short __wine_call_from_16_word();\n" );
575 fprintf( outfile
, "extern unsigned int __wine_call_from_16_long();\n" );
576 fprintf( outfile
, "extern void __wine_call_from_16_regs();\n" );
577 fprintf( outfile
, "extern void __wine_call_from_16_thunk();\n" );
579 data
= (unsigned char *)xmalloc( 0x10000 );
580 memset( data
, 0, 16 );
583 if (!dll_name
) /* set default name from file name */
586 dll_name
= xstrdup( dll_file_name
);
587 if ((p
= strrchr( dll_name
, '.' ))) *p
= 0;
590 output_stub_funcs( outfile
);
592 /* Build sorted list of all argument types, without duplicates */
594 typelist
= (ORDDEF
**)calloc( Limit
+1, sizeof(ORDDEF
*) );
596 for (i
= nFuncs
= 0; i
<= Limit
; i
++)
598 ORDDEF
*odp
= Ordinals
[i
];
606 typelist
[nFuncs
++] = odp
;
613 qsort( typelist
, nFuncs
, sizeof(ORDDEF
*), Spec16TypeCompare
);
618 typelist
[nTypes
++] = typelist
[i
++];
619 while ( i
< nFuncs
&& Spec16TypeCompare( typelist
+ i
, typelist
+ nTypes
-1 ) == 0 )
623 /* Output CallFrom16 routines needed by this .spec file */
625 for ( i
= 0; i
< nTypes
; i
++ )
629 strcpy( profile
, get_function_name( typelist
[i
] ));
630 BuildCallFrom16Func( outfile
, profile
, dll_file_name
);
634 /* Output the DLL functions prototypes */
636 for (i
= 0; i
<= Limit
; i
++)
638 ORDDEF
*odp
= Ordinals
[i
];
645 fprintf( outfile
, "extern void %s();\n", odp
->link_name
);
652 /* Output code segment */
654 fprintf( outfile
, "\n#include \"pshpack1.h\"\n" );
655 fprintf( outfile
, "\nstatic struct code_segment\n{\n" );
656 fprintf( outfile
, " struct {\n" );
658 fprintf( outfile
, " unsigned char pushl;\n" ); /* pushl $relay */
659 fprintf( outfile
, " void *relay;\n" );
660 fprintf( outfile
, " unsigned char lcall;\n" ); /* lcall __FLATCS__:glue */
661 fprintf( outfile
, " void *glue;\n" );
662 fprintf( outfile
, " unsigned short flatcs;\n" );
664 fprintf( outfile
, " unsigned short lret;\n" ); /* lret $args */
665 fprintf( outfile
, " unsigned short args;\n" );
666 fprintf( outfile
, " unsigned int arg_types[2];\n" );
667 fprintf( outfile
, " } call[%d];\n", nTypes
);
668 fprintf( outfile
, " struct {\n" );
670 fprintf( outfile
, " unsigned short pushw_bp;\n" ); /* pushw %bp */
671 fprintf( outfile
, " unsigned char pushl;\n" ); /* pushl $target */
673 fprintf( outfile
, " void (*target)();\n" );
674 fprintf( outfile
, " unsigned short call;\n" ); /* call CALLFROM16 */
675 fprintf( outfile
, " short callfrom16;\n" );
676 fprintf( outfile
, " } entry[%d];\n", nFuncs
);
677 fprintf( outfile
, "} code_segment =\n{\n {\n" );
681 for ( i
= 0; i
< nTypes
; i
++ )
683 char profile
[101], *arg
;
684 unsigned int arg_types
[2];
687 strcpy( profile
, get_function_name( typelist
[i
] ));
688 if ( typelist
[i
]->type
== TYPE_PASCAL
)
689 for ( arg
= typelist
[i
]->u
.func
.arg_types
; *arg
; arg
++ )
693 case 's': /* s_word */
696 case 'l': /* long or segmented pointer */
697 case 'T': /* segmented pointer to null-terminated string */
698 case 'p': /* linear pointer */
699 case 't': /* linear pointer to null-terminated string */
704 if (typelist
[i
]->flags
& FLAG_INTERRUPT
) argsize
+= 2;
706 /* build the arg types bit fields */
707 arg_types
[0] = arg_types
[1] = 0;
708 for (j
= 0; typelist
[i
]->u
.func
.arg_types
[j
]; j
++)
711 switch(typelist
[i
]->u
.func
.arg_types
[j
])
713 case 'w': type
= ARG_WORD
; break;
714 case 's': type
= ARG_SWORD
; break;
715 case 'l': type
= ARG_LONG
; break;
716 case 'p': type
= ARG_PTR
; break;
717 case 't': type
= ARG_STR
; break;
718 case 'T': type
= ARG_SEGSTR
; break;
720 arg_types
[j
/ 10] |= type
<< (3 * (j
% 10));
722 if (typelist
[i
]->flags
& (FLAG_REGISTER
|FLAG_INTERRUPT
)) arg_types
[0] |= ARG_REGISTER
;
723 if (typelist
[i
]->flags
& FLAG_RET16
) arg_types
[0] |= ARG_RET16
;
726 fprintf( outfile
, " { 0x68, __wine_%s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
727 make_c_identifier(dll_file_name
), profile
,
728 (typelist
[i
]->flags
& (FLAG_REGISTER
|FLAG_INTERRUPT
)) ? "regs":
729 (typelist
[i
]->flags
& FLAG_RET16
) ? "word" : "long" );
731 fprintf( outfile
, " 0x%04x, 0xca66, %d, { 0x%08x, 0x%08x } },\n",
732 code_selector
, argsize
, arg_types
[0], arg_types
[1] );
734 fprintf( outfile
, " 0x%04x, 0xcb66, 0x9090, { 0x%08x, 0x%08x } },\n",
735 code_selector
, arg_types
[0], arg_types
[1] );
738 fprintf( outfile
, " { 0xca66, %d, { 0x%08x, 0x%08x } },\n",
739 argsize
, arg_types
[0], arg_types
[1] );
741 fprintf( outfile
, " { 0xcb66, 0x9090, { 0x%08x, 0x%08x } },\n",
742 arg_types
[0], arg_types
[1] );
744 code_offset
+= sizeof(CALLFROM16
);
746 fprintf( outfile
, " },\n {\n" );
748 for (i
= 0; i
<= Limit
; i
++)
750 ORDDEF
*odp
= Ordinals
[i
];
755 odp
->offset
= LOWORD(odp
->u
.abs
.value
);
759 odp
->offset
= data_offset
;
760 data_offset
+= StoreVariableCode( data
+ data_offset
, 4, odp
);
767 type
= bsearch( &odp
, typelist
, nTypes
, sizeof(ORDDEF
*), Spec16TypeCompare
);
770 fprintf( outfile
, " /* %s.%d */ ", dll_name
, i
);
772 fprintf( outfile
, "{ 0x5566, 0x68, %s, 0xe866, %d /* %s */ },\n",
774 fprintf( outfile
, "{ %s, 0xe866, %d, /* %s */ },\n",
777 (type
-typelist
)*sizeof(CALLFROM16
) -
778 (code_offset
+ sizeof(ENTRYPOINT16
)),
779 get_function_name( odp
) );
781 odp
->offset
= code_offset
;
782 code_offset
+= sizeof(ENTRYPOINT16
);
786 fprintf(stderr
,"build: function type %d not available for Win16\n",
792 fprintf( outfile
, " }\n};\n" );
794 /* Output data segment */
796 dump_bytes( outfile
, data
, data_offset
, "Data_Segment", 0 );
798 /* Build the module */
800 module_size
= BuildModule16( outfile
, code_offset
, data_offset
);
801 res_size
= output_res16_data( outfile
);
803 /* Output the DLL descriptor */
805 fprintf( outfile
, "#include \"poppack.h\"\n\n" );
807 fprintf( outfile
, "static const struct dll_descriptor\n{\n" );
808 fprintf( outfile
, " unsigned char *module_start;\n" );
809 fprintf( outfile
, " int module_size;\n" );
810 fprintf( outfile
, " struct code_segment *code_start;\n" );
811 fprintf( outfile
, " unsigned char *data_start;\n" );
812 fprintf( outfile
, " const char *owner;\n" );
813 fprintf( outfile
, " const unsigned char *rsrc;\n" );
814 fprintf( outfile
, "} descriptor =\n{\n" );
815 fprintf( outfile
, " Module,\n" );
816 fprintf( outfile
, " sizeof(Module),\n" );
817 fprintf( outfile
, " &code_segment,\n" );
818 fprintf( outfile
, " Data_Segment,\n" );
819 fprintf( outfile
, " \"%s\",\n", owner_name
);
820 fprintf( outfile
, " %s\n", res_size
? "resource_data" : "0" );
821 fprintf( outfile
, "};\n" );
823 /* Output the DLL constructor */
825 sprintf( constructor
, "__wine_spec_%s_init", make_c_identifier(dll_file_name
) );
826 sprintf( destructor
, "__wine_spec_%s_fini", make_c_identifier(dll_file_name
) );
827 output_dll_init( outfile
, constructor
, destructor
);
832 " extern void __wine_register_dll_16( const struct dll_descriptor *descr );\n"
833 " __wine_register_dll_16( &descriptor );\n"
834 "}\n", constructor
);
838 " extern void __wine_unregister_dll_16( const struct dll_descriptor *descr );\n"
839 " __wine_unregister_dll_16( &descriptor );\n"