2000-06-23 22:15:35 +02:00
|
|
|
/*
|
|
|
|
* 16-bit spec files
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Martin von Loewis
|
|
|
|
* Copyright 1995, 1996, 1997 Alexandre Julliard
|
|
|
|
* Copyright 1997 Eric Youngdale
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-23 22:15:35 +02:00
|
|
|
*/
|
|
|
|
|
2001-11-06 21:57:11 +01:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:25:47 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2000-11-12 04:45:55 +01:00
|
|
|
#include "wine/exception.h"
|
2003-08-28 21:57:35 +02:00
|
|
|
#include "stackframe.h"
|
2000-06-23 22:15:35 +02:00
|
|
|
#include "builtin16.h"
|
|
|
|
#include "module.h"
|
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
|
2003-03-24 20:44:20 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* get_cs
|
|
|
|
*/
|
|
|
|
#ifdef __i386__
|
|
|
|
static inline unsigned short get_cs(void)
|
|
|
|
{
|
|
|
|
unsigned short res;
|
|
|
|
#ifdef __GNUC__
|
|
|
|
__asm__("movw %%cs,%w0" : "=r"(res));
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
__asm { mov res, cs }
|
|
|
|
#else
|
|
|
|
res = 0;
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* output_file_header
|
|
|
|
*
|
|
|
|
* Output a file header with the common declarations we need.
|
|
|
|
*/
|
|
|
|
static void output_file_header( FILE *outfile )
|
|
|
|
{
|
2002-03-10 00:29:33 +01:00
|
|
|
output_standard_file_header( outfile );
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "extern struct\n{\n" );
|
|
|
|
fprintf( outfile, " void *base[8192];\n" );
|
|
|
|
fprintf( outfile, " unsigned long limit[8192];\n" );
|
|
|
|
fprintf( outfile, " unsigned char flags[8192];\n" );
|
|
|
|
fprintf( outfile, "} wine_ldt_copy;\n\n" );
|
|
|
|
#ifdef __i386__
|
|
|
|
fprintf( outfile, "#define __stdcall __attribute__((__stdcall__))\n\n" );
|
|
|
|
#else
|
|
|
|
fprintf( outfile, "#define __stdcall\n\n" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* StoreVariableCode
|
|
|
|
*
|
|
|
|
* Store a list of ints into a byte array.
|
|
|
|
*/
|
|
|
|
static int StoreVariableCode( unsigned char *buffer, int size, ORDDEF *odp )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch(size)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
for (i = 0; i < odp->u.var.n_values; i++)
|
|
|
|
buffer[i] = odp->u.var.values[i];
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
for (i = 0; i < odp->u.var.n_values; i++)
|
|
|
|
((unsigned short *)buffer)[i] = odp->u.var.values[i];
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
for (i = 0; i < odp->u.var.n_values; i++)
|
|
|
|
((unsigned int *)buffer)[i] = odp->u.var.values[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return odp->u.var.n_values * size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* BuildModule16
|
|
|
|
*
|
|
|
|
* Build the in-memory representation of a 16-bit NE module, and dump it
|
|
|
|
* as a byte stream into the assembly code.
|
|
|
|
*/
|
|
|
|
static int BuildModule16( FILE *outfile, int max_code_offset,
|
|
|
|
int max_data_offset )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *buffer;
|
|
|
|
NE_MODULE *pModule;
|
|
|
|
SEGTABLEENTRY *pSegment;
|
|
|
|
OFSTRUCT *pFileInfo;
|
|
|
|
BYTE *pstr;
|
|
|
|
ET_BUNDLE *bundle = 0;
|
2000-12-29 06:17:33 +01:00
|
|
|
ET_ENTRY entry;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* Module layout:
|
|
|
|
* NE_MODULE Module
|
|
|
|
* OFSTRUCT File information
|
|
|
|
* SEGTABLEENTRY Segment 1 (code)
|
|
|
|
* SEGTABLEENTRY Segment 2 (data)
|
|
|
|
* WORD[2] Resource table (empty)
|
|
|
|
* BYTE[2] Imported names (empty)
|
|
|
|
* BYTE[n] Resident names table
|
|
|
|
* BYTE[n] Entry table
|
|
|
|
*/
|
|
|
|
|
|
|
|
buffer = xmalloc( 0x10000 );
|
2000-12-29 06:17:33 +01:00
|
|
|
memset( buffer, 0, 0x10000 );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
pModule = (NE_MODULE *)buffer;
|
|
|
|
pModule->magic = IMAGE_OS2_SIGNATURE;
|
|
|
|
pModule->count = 1;
|
|
|
|
pModule->next = 0;
|
|
|
|
pModule->flags = NE_FFLAGS_SINGLEDATA | NE_FFLAGS_BUILTIN | NE_FFLAGS_LIBMODULE;
|
|
|
|
pModule->dgroup = 2;
|
|
|
|
pModule->heap_size = DLLHeapSize;
|
|
|
|
pModule->stack_size = 0;
|
|
|
|
pModule->ip = 0;
|
|
|
|
pModule->cs = 0;
|
|
|
|
pModule->sp = 0;
|
|
|
|
pModule->ss = 0;
|
|
|
|
pModule->seg_count = 2;
|
|
|
|
pModule->modref_count = 0;
|
|
|
|
pModule->nrname_size = 0;
|
|
|
|
pModule->modref_table = 0;
|
|
|
|
pModule->nrname_fpos = 0;
|
|
|
|
pModule->moveable_entries = 0;
|
|
|
|
pModule->alignment = 0;
|
|
|
|
pModule->truetype = 0;
|
|
|
|
pModule->os_flags = NE_OSFLAGS_WINDOWS;
|
|
|
|
pModule->misc_flags = 0;
|
|
|
|
pModule->dlls_to_init = 0;
|
|
|
|
pModule->nrname_handle = 0;
|
|
|
|
pModule->min_swap_area = 0;
|
|
|
|
pModule->expected_version = 0;
|
|
|
|
pModule->module32 = 0;
|
|
|
|
pModule->self = 0;
|
|
|
|
pModule->self_loading_sel = 0;
|
|
|
|
|
|
|
|
/* File information */
|
|
|
|
|
|
|
|
pFileInfo = (OFSTRUCT *)(pModule + 1);
|
|
|
|
pModule->fileinfo = (int)pFileInfo - (int)pModule;
|
|
|
|
memset( pFileInfo, 0, sizeof(*pFileInfo) - sizeof(pFileInfo->szPathName) );
|
|
|
|
pFileInfo->cBytes = sizeof(*pFileInfo) - sizeof(pFileInfo->szPathName)
|
2003-03-23 02:12:30 +01:00
|
|
|
+ strlen(dll_file_name);
|
|
|
|
strcpy( pFileInfo->szPathName, dll_file_name );
|
2000-06-23 22:15:35 +02:00
|
|
|
pstr = (char *)pFileInfo + pFileInfo->cBytes + 1;
|
|
|
|
|
|
|
|
/* Segment table */
|
|
|
|
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 3) & ~3);
|
2000-06-23 22:15:35 +02:00
|
|
|
pSegment = (SEGTABLEENTRY *)pstr;
|
|
|
|
pModule->seg_table = (int)pSegment - (int)pModule;
|
|
|
|
pSegment->filepos = 0;
|
|
|
|
pSegment->size = max_code_offset;
|
|
|
|
pSegment->flags = 0;
|
|
|
|
pSegment->minsize = max_code_offset;
|
|
|
|
pSegment->hSeg = 0;
|
|
|
|
pSegment++;
|
|
|
|
|
|
|
|
pModule->dgroup_entry = (int)pSegment - (int)pModule;
|
|
|
|
pSegment->filepos = 0;
|
|
|
|
pSegment->size = max_data_offset;
|
|
|
|
pSegment->flags = NE_SEGFLAGS_DATA;
|
|
|
|
pSegment->minsize = max_data_offset;
|
|
|
|
pSegment->hSeg = 0;
|
|
|
|
pSegment++;
|
|
|
|
|
|
|
|
/* Resource table */
|
|
|
|
|
2000-10-25 22:33:58 +02:00
|
|
|
pstr = (char *)pSegment;
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 3) & ~3);
|
2000-10-25 22:33:58 +02:00
|
|
|
pModule->res_table = (int)pstr - (int)pModule;
|
|
|
|
pstr += output_res16_directory( pstr );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* Imported names table */
|
|
|
|
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 3) & ~3);
|
2000-06-23 22:15:35 +02:00
|
|
|
pModule->import_table = (int)pstr - (int)pModule;
|
|
|
|
*pstr++ = 0;
|
|
|
|
*pstr++ = 0;
|
|
|
|
|
|
|
|
/* Resident names table */
|
|
|
|
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 3) & ~3);
|
2000-06-23 22:15:35 +02:00
|
|
|
pModule->name_table = (int)pstr - (int)pModule;
|
|
|
|
/* First entry is module name */
|
2003-03-23 02:12:30 +01:00
|
|
|
*pstr = strlen( dll_name );
|
|
|
|
strcpy( pstr + 1, dll_name );
|
2002-06-21 21:15:45 +02:00
|
|
|
strupper( pstr + 1 );
|
2000-06-23 22:15:35 +02:00
|
|
|
pstr += *pstr + 1;
|
2002-05-23 04:53:10 +02:00
|
|
|
*pstr++ = 0;
|
|
|
|
*pstr++ = 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
/* Store all ordinals */
|
|
|
|
for (i = 1; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
2002-05-23 04:53:10 +02:00
|
|
|
WORD ord = i;
|
2000-06-23 22:15:35 +02:00
|
|
|
if (!odp || !odp->name[0]) continue;
|
|
|
|
*pstr = strlen( odp->name );
|
|
|
|
strcpy( pstr + 1, odp->name );
|
|
|
|
strupper( pstr + 1 );
|
|
|
|
pstr += *pstr + 1;
|
2002-05-23 04:53:10 +02:00
|
|
|
memcpy( pstr, &ord, sizeof(WORD) );
|
2000-06-23 22:15:35 +02:00
|
|
|
pstr += sizeof(WORD);
|
|
|
|
}
|
|
|
|
*pstr++ = 0;
|
|
|
|
|
|
|
|
/* Entry table */
|
|
|
|
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 3) & ~3);
|
2000-06-23 22:15:35 +02:00
|
|
|
pModule->entry_table = (int)pstr - (int)pModule;
|
|
|
|
for (i = 1; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
int selector = 0;
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
|
|
|
if (!odp) continue;
|
|
|
|
|
|
|
|
switch (odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_PASCAL:
|
2003-08-27 04:20:44 +02:00
|
|
|
case TYPE_VARARGS:
|
2000-06-23 22:15:35 +02:00
|
|
|
case TYPE_STUB:
|
|
|
|
selector = 1; /* Code selector */
|
|
|
|
break;
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
case TYPE_VARIABLE:
|
2000-06-23 22:15:35 +02:00
|
|
|
selector = 2; /* Data selector */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_ABS:
|
|
|
|
selector = 0xfe; /* Constant selector */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
selector = 0; /* Invalid selector */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !selector )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( bundle && bundle->last+1 == i )
|
|
|
|
bundle->last++;
|
|
|
|
else
|
|
|
|
{
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 1) & ~1);
|
2000-06-23 22:15:35 +02:00
|
|
|
if ( bundle )
|
|
|
|
bundle->next = (char *)pstr - (char *)pModule;
|
|
|
|
|
|
|
|
bundle = (ET_BUNDLE *)pstr;
|
|
|
|
bundle->first = i-1;
|
|
|
|
bundle->last = i;
|
|
|
|
bundle->next = 0;
|
|
|
|
pstr += sizeof(ET_BUNDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: is this really correct ?? */
|
2000-12-29 06:17:33 +01:00
|
|
|
entry.type = 0xff; /* movable */
|
|
|
|
entry.flags = 3; /* exported & public data */
|
|
|
|
entry.segnum = selector;
|
|
|
|
entry.offs = odp->offset;
|
|
|
|
memcpy( pstr, &entry, sizeof(ET_ENTRY) );
|
2000-06-23 22:15:35 +02:00
|
|
|
pstr += sizeof(ET_ENTRY);
|
|
|
|
}
|
|
|
|
*pstr++ = 0;
|
|
|
|
|
|
|
|
/* Dump the module content */
|
|
|
|
|
2000-12-29 06:17:33 +01:00
|
|
|
pstr = (char *)(((long)pstr + 3) & ~3);
|
2000-10-25 22:33:58 +02:00
|
|
|
dump_bytes( outfile, (char *)pModule, (int)pstr - (int)pModule, "Module", 0 );
|
2000-06-23 22:15:35 +02:00
|
|
|
return (int)pstr - (int)pModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* BuildCallFrom16Func
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Build a 16-bit-to-Wine callback glue function.
|
2000-06-23 22:15:35 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* The generated routines are intended to be used as argument conversion
|
2000-06-23 22:15:35 +02:00
|
|
|
* routines to be called by the CallFrom16... core. Thus, the prototypes of
|
|
|
|
* the generated routines are (see also CallFrom16):
|
|
|
|
*
|
|
|
|
* extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
|
|
|
|
* extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
|
2002-06-01 01:06:46 +02:00
|
|
|
* extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
|
2000-06-23 22:15:35 +02:00
|
|
|
* CONTEXT86 *context );
|
2002-06-01 01:06:46 +02:00
|
|
|
* extern void WINAPI PREFIX_CallFrom16_C_intr_xxx( FARPROC func, LPBYTE args,
|
2000-06-23 22:15:35 +02:00
|
|
|
* CONTEXT86 *context );
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
|
|
|
|
* and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
|
2000-06-23 22:15:35 +02:00
|
|
|
* 'p'=linear pointer, 't'=linear pointer to null-terminated string,
|
|
|
|
* 'T'=segmented pointer to null-terminated string).
|
|
|
|
*
|
|
|
|
* The generated routines fetch the arguments from the 16-bit stack (pointed
|
2002-06-01 01:06:46 +02:00
|
|
|
* to by 'args'); the offsets of the single argument values are computed
|
2000-06-23 22:15:35 +02:00
|
|
|
* according to the calling convention and the argument types. Then, the
|
|
|
|
* 32-bit entry point is called with these arguments.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-06-23 22:15:35 +02:00
|
|
|
* For register functions, the arguments (if present) are converted just
|
2002-06-01 01:06:46 +02:00
|
|
|
* the same as for normal functions, but in addition the CONTEXT86 pointer
|
2000-06-23 22:15:35 +02:00
|
|
|
* filled with the current register values is passed to the 32-bit routine.
|
2002-06-01 01:06:46 +02:00
|
|
|
* (An 'intr' interrupt handler routine is treated exactly like a register
|
|
|
|
* routine, except that upon return, the flags word pushed onto the stack
|
2000-06-23 22:15:35 +02:00
|
|
|
* by the interrupt is removed by the 16-bit call stub.)
|
|
|
|
*
|
|
|
|
*/
|
2002-05-16 20:44:06 +02:00
|
|
|
static void BuildCallFrom16Func( FILE *outfile, const char *profile, const char *prefix )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
int i, pos, argsize = 0;
|
|
|
|
int short_ret = 0;
|
|
|
|
int reg_func = 0;
|
|
|
|
int usecdecl = 0;
|
2003-08-27 04:20:44 +02:00
|
|
|
int varargs = 0;
|
2002-05-16 20:44:06 +02:00
|
|
|
const char *args = profile + 7;
|
2000-06-23 22:15:35 +02:00
|
|
|
char *ret_type;
|
|
|
|
|
|
|
|
/* Parse function type */
|
|
|
|
|
|
|
|
if (!strncmp( "c_", profile, 2 )) usecdecl = 1;
|
2003-08-27 04:20:44 +02:00
|
|
|
else if (!strncmp( "v_", profile, 2 )) varargs = usecdecl = 1;
|
2000-06-23 22:15:35 +02:00
|
|
|
else if (strncmp( "p_", profile, 2 ))
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strncmp( "word_", profile + 2, 5 )) short_ret = 1;
|
|
|
|
else if (!strncmp( "regs_", profile + 2, 5 )) reg_func = 1;
|
|
|
|
else if (!strncmp( "intr_", profile + 2, 5 )) reg_func = 2;
|
|
|
|
else if (strncmp( "long_", profile + 2, 5 ))
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; args[i]; i++ )
|
|
|
|
switch ( args[i] )
|
|
|
|
{
|
|
|
|
case 'w': /* word */
|
|
|
|
case 's': /* s_word */
|
|
|
|
argsize += 2;
|
|
|
|
break;
|
|
|
|
case 'l': /* long or segmented pointer */
|
|
|
|
case 'T': /* segmented pointer to null-terminated string */
|
|
|
|
case 'p': /* linear pointer */
|
|
|
|
case 't': /* linear pointer to null-terminated string */
|
|
|
|
argsize += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
ret_type = reg_func? "void" : short_ret ? "unsigned short" : "unsigned int";
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-08-27 04:20:44 +02:00
|
|
|
fprintf( outfile, "typedef %s (%s*proc_%s_t)( ",
|
|
|
|
ret_type, usecdecl ? "" : "__stdcall ", profile );
|
2000-06-23 22:15:35 +02:00
|
|
|
args = profile + 7;
|
|
|
|
for ( i = 0; args[i]; i++ )
|
|
|
|
{
|
|
|
|
if ( i ) fprintf( outfile, ", " );
|
|
|
|
switch (args[i])
|
|
|
|
{
|
2001-12-15 00:14:22 +01:00
|
|
|
case 'w': fprintf( outfile, "unsigned short" ); break;
|
|
|
|
case 's': fprintf( outfile, "short" ); break;
|
|
|
|
case 'l': case 'T': fprintf( outfile, "unsigned int" ); break;
|
|
|
|
case 'p': case 't': fprintf( outfile, "void *" ); break;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-27 04:20:44 +02:00
|
|
|
if (reg_func || varargs)
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "%svoid *", i? ", " : "" );
|
2000-06-23 22:15:35 +02:00
|
|
|
else if ( !i )
|
|
|
|
fprintf( outfile, "void" );
|
|
|
|
fprintf( outfile, " );\n" );
|
|
|
|
|
2002-05-16 20:44:06 +02:00
|
|
|
fprintf( outfile, "static %s __stdcall __wine_%s_CallFrom16_%s( proc_%s_t proc, unsigned char *args%s )\n",
|
|
|
|
ret_type, make_c_identifier(prefix), profile, profile,
|
2001-12-15 00:14:22 +01:00
|
|
|
reg_func? ", void *context" : "" );
|
|
|
|
|
|
|
|
fprintf( outfile, "{\n %sproc(\n", reg_func ? "" : "return " );
|
2000-06-23 22:15:35 +02:00
|
|
|
args = profile + 7;
|
|
|
|
pos = !usecdecl? argsize : 0;
|
|
|
|
for ( i = 0; args[i]; i++ )
|
|
|
|
{
|
|
|
|
if ( i ) fprintf( outfile, ",\n" );
|
|
|
|
fprintf( outfile, " " );
|
|
|
|
switch (args[i])
|
|
|
|
{
|
|
|
|
case 'w': /* word */
|
|
|
|
if ( !usecdecl ) pos -= 2;
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "*(unsigned short *)(args+%d)", pos );
|
2000-06-23 22:15:35 +02:00
|
|
|
if ( usecdecl ) pos += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* s_word */
|
|
|
|
if ( !usecdecl ) pos -= 2;
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "*(short *)(args+%d)", pos );
|
2000-06-23 22:15:35 +02:00
|
|
|
if ( usecdecl ) pos += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* long or segmented pointer */
|
|
|
|
case 'T': /* segmented pointer to null-terminated string */
|
|
|
|
if ( !usecdecl ) pos -= 4;
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "*(unsigned int *)(args+%d)", pos );
|
2000-06-23 22:15:35 +02:00
|
|
|
if ( usecdecl ) pos += 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p': /* linear pointer */
|
|
|
|
case 't': /* linear pointer to null-terminated string */
|
|
|
|
if ( !usecdecl ) pos -= 4;
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "((char*)wine_ldt_copy.base[*(unsigned short*)(args+%d) >> 3] + *(unsigned short*)(args+%d))",
|
2000-11-14 02:54:49 +01:00
|
|
|
pos + 2, pos );
|
2000-06-23 22:15:35 +02:00
|
|
|
if ( usecdecl ) pos += 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf( stderr, "Unknown arg type '%c'\n", args[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( reg_func )
|
|
|
|
fprintf( outfile, "%s context", i? ",\n" : "" );
|
2003-08-27 04:20:44 +02:00
|
|
|
else if (varargs)
|
|
|
|
fprintf( outfile, "%s args + %d", i? ",\n" : "", argsize );
|
2000-06-23 22:15:35 +02:00
|
|
|
fprintf( outfile, " );\n}\n\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* get_function_name
|
|
|
|
*/
|
|
|
|
static const char *get_function_name( const ORDDEF *odp )
|
|
|
|
{
|
|
|
|
static char buffer[80];
|
|
|
|
|
|
|
|
sprintf( buffer, "%s_%s_%s",
|
2003-08-27 04:20:44 +02:00
|
|
|
(odp->type == TYPE_PASCAL) ? "p" :
|
|
|
|
(odp->type == TYPE_VARARGS) ? "v" : "c",
|
2001-12-15 00:14:22 +01:00
|
|
|
(odp->flags & FLAG_REGISTER) ? "regs" :
|
|
|
|
(odp->flags & FLAG_INTERRUPT) ? "intr" :
|
2003-08-27 04:20:44 +02:00
|
|
|
(odp->flags & FLAG_RET16) ? "word" : "long",
|
2001-12-15 00:14:22 +01:00
|
|
|
odp->u.func.arg_types );
|
|
|
|
return buffer;
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* Spec16TypeCompare
|
|
|
|
*/
|
|
|
|
static int Spec16TypeCompare( const void *e1, const void *e2 )
|
|
|
|
{
|
|
|
|
const ORDDEF *odp1 = *(const ORDDEF **)e1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF **)e2;
|
2001-12-15 00:14:22 +01:00
|
|
|
int retval;
|
2003-08-27 04:20:44 +02:00
|
|
|
int type1 = odp1->type;
|
|
|
|
int type2 = odp2->type;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-08-27 04:20:44 +02:00
|
|
|
if (type1 == TYPE_STUB) type1 = TYPE_CDECL;
|
|
|
|
if (type2 == TYPE_STUB) type2 = TYPE_CDECL;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-08-27 04:20:44 +02:00
|
|
|
if ((retval = type1 - type2) != 0) return retval;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-08-27 04:20:44 +02:00
|
|
|
type1 = odp1->flags & (FLAG_RET16|FLAG_REGISTER|FLAG_INTERRUPT);
|
|
|
|
type2 = odp2->flags & (FLAG_RET16|FLAG_REGISTER|FLAG_INTERRUPT);
|
2001-12-15 00:14:22 +01:00
|
|
|
|
2003-08-27 04:20:44 +02:00
|
|
|
if ((retval = type1 - type2) != 0) return retval;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2003-08-27 04:20:44 +02:00
|
|
|
return strcmp( odp1->u.func.arg_types, odp2->u.func.arg_types );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-12 04:45:55 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* output_stub_funcs
|
|
|
|
*
|
|
|
|
* Output the functions for stub entry points
|
|
|
|
*/
|
|
|
|
static void output_stub_funcs( FILE *outfile )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
for (i = 0; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
|
|
|
if (!odp || odp->type != TYPE_STUB) continue;
|
|
|
|
fprintf( outfile, "#ifdef __GNUC__\n" );
|
|
|
|
fprintf( outfile, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
|
|
|
|
fprintf( outfile, "#endif\n" );
|
|
|
|
fprintf( outfile, "static void __wine_unimplemented( const char *func )\n{\n" );
|
|
|
|
fprintf( outfile, " struct exc_record {\n" );
|
|
|
|
fprintf( outfile, " unsigned int code, flags;\n" );
|
|
|
|
fprintf( outfile, " void *rec, *addr;\n" );
|
|
|
|
fprintf( outfile, " unsigned int params;\n" );
|
|
|
|
fprintf( outfile, " const void *info[15];\n" );
|
2001-05-22 21:55:51 +02:00
|
|
|
fprintf( outfile, " } rec;\n\n" );
|
|
|
|
fprintf( outfile, " extern void __stdcall RtlRaiseException( struct exc_record * );\n\n" );
|
2000-11-12 04:45:55 +01:00
|
|
|
fprintf( outfile, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB );
|
|
|
|
fprintf( outfile, " rec.flags = %d;\n", EH_NONCONTINUABLE );
|
|
|
|
fprintf( outfile, " rec.rec = 0;\n" );
|
|
|
|
fprintf( outfile, " rec.params = 2;\n" );
|
2003-03-23 02:12:30 +01:00
|
|
|
fprintf( outfile, " rec.info[0] = \"%s\";\n", dll_file_name );
|
2000-11-12 04:45:55 +01:00
|
|
|
fprintf( outfile, " rec.info[1] = func;\n" );
|
|
|
|
fprintf( outfile, "#ifdef __GNUC__\n" );
|
|
|
|
fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
|
|
|
|
fprintf( outfile, "#else\n" );
|
|
|
|
fprintf( outfile, " rec.addr = 0;\n" );
|
|
|
|
fprintf( outfile, "#endif\n" );
|
|
|
|
fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
|
|
|
if (!odp || odp->type != TYPE_STUB) continue;
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name = xrealloc( odp->link_name, strlen(odp->name) + 13 );
|
|
|
|
strcpy( odp->link_name, "__wine_stub_" );
|
|
|
|
strcat( odp->link_name, odp->name );
|
|
|
|
for (p = odp->link_name; *p; p++) if (!isalnum(*p)) *p = '_';
|
2000-11-12 04:45:55 +01:00
|
|
|
fprintf( outfile, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name, odp->name );
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* BuildSpec16File
|
|
|
|
*
|
|
|
|
* Build a Win16 assembly file from a spec file.
|
|
|
|
*/
|
|
|
|
void BuildSpec16File( FILE *outfile )
|
|
|
|
{
|
|
|
|
ORDDEF **type, **typelist;
|
|
|
|
int i, nFuncs, nTypes;
|
2000-10-25 22:33:58 +02:00
|
|
|
int code_offset, data_offset, module_size, res_size;
|
2000-06-23 22:15:35 +02:00
|
|
|
unsigned char *data;
|
2002-06-15 01:42:53 +02:00
|
|
|
char constructor[100], destructor[100];
|
2000-12-29 06:17:33 +01:00
|
|
|
#ifdef __i386__
|
2003-03-24 20:44:20 +01:00
|
|
|
unsigned short code_selector = get_cs();
|
2000-12-29 06:17:33 +01:00
|
|
|
#endif
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* File header */
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
output_file_header( outfile );
|
|
|
|
fprintf( outfile, "extern unsigned short __wine_call_from_16_word();\n" );
|
|
|
|
fprintf( outfile, "extern unsigned int __wine_call_from_16_long();\n" );
|
|
|
|
fprintf( outfile, "extern void __wine_call_from_16_regs();\n" );
|
|
|
|
fprintf( outfile, "extern void __wine_call_from_16_thunk();\n" );
|
2000-08-14 16:29:22 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
data = (unsigned char *)xmalloc( 0x10000 );
|
|
|
|
memset( data, 0, 16 );
|
|
|
|
data_offset = 16;
|
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
if (!dll_name) /* set default name from file name */
|
2002-06-21 21:15:45 +02:00
|
|
|
{
|
|
|
|
char *p;
|
2003-03-23 02:12:30 +01:00
|
|
|
dll_name = xstrdup( dll_file_name );
|
|
|
|
if ((p = strrchr( dll_name, '.' ))) *p = 0;
|
2002-06-21 21:15:45 +02:00
|
|
|
}
|
2001-05-22 21:55:51 +02:00
|
|
|
|
2000-11-12 04:45:55 +01:00
|
|
|
output_stub_funcs( outfile );
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* Build sorted list of all argument types, without duplicates */
|
|
|
|
|
|
|
|
typelist = (ORDDEF **)calloc( Limit+1, sizeof(ORDDEF *) );
|
|
|
|
|
|
|
|
for (i = nFuncs = 0; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
|
|
|
if (!odp) continue;
|
|
|
|
switch (odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_PASCAL:
|
2003-08-27 04:20:44 +02:00
|
|
|
case TYPE_VARARGS:
|
2000-06-23 22:15:35 +02:00
|
|
|
case TYPE_STUB:
|
|
|
|
typelist[nFuncs++] = odp;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort( typelist, nFuncs, sizeof(ORDDEF *), Spec16TypeCompare );
|
|
|
|
|
|
|
|
i = nTypes = 0;
|
|
|
|
while ( i < nFuncs )
|
|
|
|
{
|
|
|
|
typelist[nTypes++] = typelist[i++];
|
|
|
|
while ( i < nFuncs && Spec16TypeCompare( typelist + i, typelist + nTypes-1 ) == 0 )
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output CallFrom16 routines needed by this .spec file */
|
2000-12-29 06:17:33 +01:00
|
|
|
#ifdef __i386__
|
2000-06-23 22:15:35 +02:00
|
|
|
for ( i = 0; i < nTypes; i++ )
|
|
|
|
{
|
|
|
|
char profile[101];
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
strcpy( profile, get_function_name( typelist[i] ));
|
2003-03-23 02:12:30 +01:00
|
|
|
BuildCallFrom16Func( outfile, profile, dll_file_name );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2000-12-29 06:17:33 +01:00
|
|
|
#endif
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* Output the DLL functions prototypes */
|
|
|
|
|
|
|
|
for (i = 0; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
|
|
|
if (!odp) continue;
|
|
|
|
switch(odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_PASCAL:
|
2003-08-27 04:20:44 +02:00
|
|
|
case TYPE_VARARGS:
|
2000-12-16 00:04:40 +01:00
|
|
|
fprintf( outfile, "extern void %s();\n", odp->link_name );
|
2000-06-23 22:15:35 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output code segment */
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "\n#include \"pshpack1.h\"\n" );
|
|
|
|
fprintf( outfile, "\nstatic struct code_segment\n{\n" );
|
|
|
|
fprintf( outfile, " struct {\n" );
|
|
|
|
#ifdef __i386__
|
|
|
|
fprintf( outfile, " unsigned char pushl;\n" ); /* pushl $relay */
|
|
|
|
fprintf( outfile, " void *relay;\n" );
|
|
|
|
fprintf( outfile, " unsigned char lcall;\n" ); /* lcall __FLATCS__:glue */
|
|
|
|
fprintf( outfile, " void *glue;\n" );
|
|
|
|
fprintf( outfile, " unsigned short flatcs;\n" );
|
|
|
|
#endif
|
|
|
|
fprintf( outfile, " unsigned short lret;\n" ); /* lret $args */
|
|
|
|
fprintf( outfile, " unsigned short args;\n" );
|
|
|
|
fprintf( outfile, " unsigned int arg_types[2];\n" );
|
|
|
|
fprintf( outfile, " } call[%d];\n", nTypes );
|
|
|
|
fprintf( outfile, " struct {\n" );
|
|
|
|
#ifdef __i386__
|
|
|
|
fprintf( outfile, " unsigned short pushw_bp;\n" ); /* pushw %bp */
|
|
|
|
fprintf( outfile, " unsigned char pushl;\n" ); /* pushl $target */
|
|
|
|
#endif
|
|
|
|
fprintf( outfile, " void (*target)();\n" );
|
|
|
|
fprintf( outfile, " unsigned short call;\n" ); /* call CALLFROM16 */
|
|
|
|
fprintf( outfile, " short callfrom16;\n" );
|
|
|
|
fprintf( outfile, " } entry[%d];\n", nFuncs );
|
|
|
|
fprintf( outfile, "} code_segment =\n{\n {\n" );
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
code_offset = 0;
|
|
|
|
|
|
|
|
for ( i = 0; i < nTypes; i++ )
|
|
|
|
{
|
|
|
|
char profile[101], *arg;
|
2001-12-15 00:14:22 +01:00
|
|
|
unsigned int arg_types[2];
|
|
|
|
int j, argsize = 0;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
strcpy( profile, get_function_name( typelist[i] ));
|
2003-08-27 04:20:44 +02:00
|
|
|
if ( typelist[i]->type == TYPE_PASCAL )
|
2000-06-23 22:15:35 +02:00
|
|
|
for ( arg = typelist[i]->u.func.arg_types; *arg; arg++ )
|
|
|
|
switch ( *arg )
|
|
|
|
{
|
|
|
|
case 'w': /* word */
|
|
|
|
case 's': /* s_word */
|
|
|
|
argsize += 2;
|
|
|
|
break;
|
|
|
|
case 'l': /* long or segmented pointer */
|
|
|
|
case 'T': /* segmented pointer to null-terminated string */
|
|
|
|
case 'p': /* linear pointer */
|
|
|
|
case 't': /* linear pointer to null-terminated string */
|
|
|
|
argsize += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
if (typelist[i]->flags & FLAG_INTERRUPT) argsize += 2;
|
|
|
|
|
|
|
|
/* build the arg types bit fields */
|
|
|
|
arg_types[0] = arg_types[1] = 0;
|
|
|
|
for (j = 0; typelist[i]->u.func.arg_types[j]; j++)
|
|
|
|
{
|
|
|
|
int type = 0;
|
|
|
|
switch(typelist[i]->u.func.arg_types[j])
|
|
|
|
{
|
|
|
|
case 'w': type = ARG_WORD; break;
|
|
|
|
case 's': type = ARG_SWORD; break;
|
|
|
|
case 'l': type = ARG_LONG; break;
|
|
|
|
case 'p': type = ARG_PTR; break;
|
|
|
|
case 't': type = ARG_STR; break;
|
|
|
|
case 'T': type = ARG_SEGSTR; break;
|
|
|
|
}
|
|
|
|
arg_types[j / 10] |= type << (3 * (j % 10));
|
|
|
|
}
|
|
|
|
if (typelist[i]->flags & (FLAG_REGISTER|FLAG_INTERRUPT)) arg_types[0] |= ARG_REGISTER;
|
2003-08-27 04:20:44 +02:00
|
|
|
if (typelist[i]->flags & FLAG_RET16) arg_types[0] |= ARG_RET16;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2000-12-29 06:17:33 +01:00
|
|
|
#ifdef __i386__
|
2002-05-16 20:44:06 +02:00
|
|
|
fprintf( outfile, " { 0x68, __wine_%s_CallFrom16_%s, 0x9a, __wine_call_from_16_%s,\n",
|
2003-03-23 02:12:30 +01:00
|
|
|
make_c_identifier(dll_file_name), profile,
|
2001-12-15 00:14:22 +01:00
|
|
|
(typelist[i]->flags & (FLAG_REGISTER|FLAG_INTERRUPT)) ? "regs":
|
2003-08-27 04:20:44 +02:00
|
|
|
(typelist[i]->flags & FLAG_RET16) ? "word" : "long" );
|
2000-08-14 16:29:22 +02:00
|
|
|
if (argsize)
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, " 0x%04x, 0xca66, %d, { 0x%08x, 0x%08x } },\n",
|
|
|
|
code_selector, argsize, arg_types[0], arg_types[1] );
|
2000-08-14 16:29:22 +02:00
|
|
|
else
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, " 0x%04x, 0xcb66, 0x9090, { 0x%08x, 0x%08x } },\n",
|
|
|
|
code_selector, arg_types[0], arg_types[1] );
|
2000-12-29 06:17:33 +01:00
|
|
|
#else
|
2001-12-15 00:14:22 +01:00
|
|
|
if (argsize)
|
|
|
|
fprintf( outfile, " { 0xca66, %d, { 0x%08x, 0x%08x } },\n",
|
|
|
|
argsize, arg_types[0], arg_types[1] );
|
|
|
|
else
|
|
|
|
fprintf( outfile, " { 0xcb66, 0x9090, { 0x%08x, 0x%08x } },\n",
|
|
|
|
arg_types[0], arg_types[1] );
|
2000-12-29 06:17:33 +01:00
|
|
|
#endif
|
2000-06-23 22:15:35 +02:00
|
|
|
code_offset += sizeof(CALLFROM16);
|
|
|
|
}
|
2000-08-14 16:29:22 +02:00
|
|
|
fprintf( outfile, " },\n {\n" );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
for (i = 0; i <= Limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = Ordinals[i];
|
|
|
|
if (!odp) continue;
|
|
|
|
switch (odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_ABS:
|
|
|
|
odp->offset = LOWORD(odp->u.abs.value);
|
|
|
|
break;
|
|
|
|
|
2000-11-26 05:31:48 +01:00
|
|
|
case TYPE_VARIABLE:
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->offset = data_offset;
|
|
|
|
data_offset += StoreVariableCode( data + data_offset, 4, odp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_PASCAL:
|
2003-08-27 04:20:44 +02:00
|
|
|
case TYPE_VARARGS:
|
2000-06-23 22:15:35 +02:00
|
|
|
case TYPE_STUB:
|
|
|
|
type = bsearch( &odp, typelist, nTypes, sizeof(ORDDEF *), Spec16TypeCompare );
|
|
|
|
assert( type );
|
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
fprintf( outfile, " /* %s.%d */ ", dll_name, i );
|
2000-12-29 06:17:33 +01:00
|
|
|
#ifdef __i386__
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "{ 0x5566, 0x68, %s, 0xe866, %d /* %s */ },\n",
|
2000-12-29 06:17:33 +01:00
|
|
|
#else
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "{ %s, 0xe866, %d, /* %s */ },\n",
|
2000-12-29 06:17:33 +01:00
|
|
|
#endif
|
2000-12-16 00:04:40 +01:00
|
|
|
odp->link_name,
|
2000-11-12 04:45:55 +01:00
|
|
|
(type-typelist)*sizeof(CALLFROM16) -
|
|
|
|
(code_offset + sizeof(ENTRYPOINT16)),
|
2001-12-15 00:14:22 +01:00
|
|
|
get_function_name( odp ) );
|
2000-12-29 06:17:33 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
odp->offset = code_offset;
|
|
|
|
code_offset += sizeof(ENTRYPOINT16);
|
|
|
|
break;
|
2000-11-12 04:45:55 +01:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
default:
|
|
|
|
fprintf(stderr,"build: function type %d not available for Win16\n",
|
|
|
|
odp->type);
|
|
|
|
exit(1);
|
2000-11-12 04:45:55 +01:00
|
|
|
}
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( outfile, " }\n};\n" );
|
|
|
|
|
|
|
|
/* Output data segment */
|
|
|
|
|
2000-10-25 22:33:58 +02:00
|
|
|
dump_bytes( outfile, data, data_offset, "Data_Segment", 0 );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* Build the module */
|
|
|
|
|
|
|
|
module_size = BuildModule16( outfile, code_offset, data_offset );
|
2000-10-25 22:33:58 +02:00
|
|
|
res_size = output_res16_data( outfile );
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
/* Output the DLL descriptor */
|
|
|
|
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, "#include \"poppack.h\"\n\n" );
|
|
|
|
|
|
|
|
fprintf( outfile, "static const struct dll_descriptor\n{\n" );
|
|
|
|
fprintf( outfile, " unsigned char *module_start;\n" );
|
|
|
|
fprintf( outfile, " int module_size;\n" );
|
|
|
|
fprintf( outfile, " struct code_segment *code_start;\n" );
|
|
|
|
fprintf( outfile, " unsigned char *data_start;\n" );
|
|
|
|
fprintf( outfile, " const char *owner;\n" );
|
|
|
|
fprintf( outfile, " const unsigned char *rsrc;\n" );
|
|
|
|
fprintf( outfile, "} descriptor =\n{\n" );
|
2000-06-23 22:15:35 +02:00
|
|
|
fprintf( outfile, " Module,\n" );
|
|
|
|
fprintf( outfile, " sizeof(Module),\n" );
|
2001-12-15 00:14:22 +01:00
|
|
|
fprintf( outfile, " &code_segment,\n" );
|
2000-10-29 02:28:30 +01:00
|
|
|
fprintf( outfile, " Data_Segment,\n" );
|
2000-07-28 02:07:18 +02:00
|
|
|
fprintf( outfile, " \"%s\",\n", owner_name );
|
2000-10-25 22:33:58 +02:00
|
|
|
fprintf( outfile, " %s\n", res_size ? "resource_data" : "0" );
|
2000-06-23 22:15:35 +02:00
|
|
|
fprintf( outfile, "};\n" );
|
2000-10-25 22:33:58 +02:00
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* Output the DLL constructor */
|
|
|
|
|
2003-03-23 02:12:30 +01:00
|
|
|
sprintf( constructor, "__wine_spec_%s_init", make_c_identifier(dll_file_name) );
|
|
|
|
sprintf( destructor, "__wine_spec_%s_fini", make_c_identifier(dll_file_name) );
|
2002-06-15 01:42:53 +02:00
|
|
|
output_dll_init( outfile, constructor, destructor );
|
2000-12-29 06:17:33 +01:00
|
|
|
|
2000-12-06 21:18:35 +01:00
|
|
|
fprintf( outfile,
|
2002-06-15 01:42:53 +02:00
|
|
|
"void %s(void)\n"
|
2000-12-06 21:18:35 +01:00
|
|
|
"{\n"
|
2001-12-15 00:14:22 +01:00
|
|
|
" extern void __wine_register_dll_16( const struct dll_descriptor *descr );\n"
|
2000-12-06 21:18:35 +01:00
|
|
|
" __wine_register_dll_16( &descriptor );\n"
|
2002-06-15 01:42:53 +02:00
|
|
|
"}\n", constructor );
|
|
|
|
fprintf( outfile,
|
|
|
|
"void %s(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" extern void __wine_unregister_dll_16( const struct dll_descriptor *descr );\n"
|
|
|
|
" __wine_unregister_dll_16( &descriptor );\n"
|
|
|
|
"}\n", destructor );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|