2000-06-23 20:15:35 +00: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-09 23:29:33 +00: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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-06-23 20:15:35 +00:00
|
|
|
*/
|
|
|
|
|
2001-11-06 20:57:11 +00:00
|
|
|
#include "config.h"
|
2002-04-25 21:40:56 +00:00
|
|
|
#include "wine/port.h"
|
2001-10-14 16:25:47 +00:00
|
|
|
|
2000-06-23 20:15:35 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
2009-04-09 18:58:43 +00:00
|
|
|
#define NE_FFLAGS_SINGLEDATA 0x0001
|
|
|
|
#define NE_FFLAGS_LIBMODULE 0x8000
|
|
|
|
|
|
|
|
/* argument type flags for relay debugging */
|
|
|
|
enum arg_types
|
|
|
|
{
|
|
|
|
ARG_NONE = 0, /* indicates end of arg list */
|
|
|
|
ARG_WORD, /* unsigned word */
|
|
|
|
ARG_SWORD, /* signed word */
|
|
|
|
ARG_LONG, /* long or segmented pointer */
|
|
|
|
ARG_PTR, /* linear pointer */
|
|
|
|
ARG_STR, /* linear pointer to null-terminated string */
|
|
|
|
ARG_SEGSTR, /* segmented pointer to null-terminated string */
|
|
|
|
ARG_VARARG /* start of varargs */
|
|
|
|
};
|
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* sequences of nops to fill a certain number of words */
|
|
|
|
static const char * const nop_sequence[4] =
|
|
|
|
{
|
|
|
|
".byte 0x89,0xf6", /* mov %esi,%esi */
|
|
|
|
".byte 0x8d,0x74,0x26,0x00", /* lea 0x00(%esi),%esi */
|
|
|
|
".byte 0x8d,0xb6,0x00,0x00,0x00,0x00", /* lea 0x00000000(%esi),%esi */
|
|
|
|
".byte 0x8d,0x74,0x26,0x00,0x8d,0x74,0x26,0x00" /* lea 0x00(%esi),%esi; lea 0x00(%esi),%esi */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int is_function( const ORDDEF *odp )
|
|
|
|
{
|
2009-12-28 21:42:58 +00:00
|
|
|
if (odp->flags & FLAG_EXPORT32) return 0;
|
2005-09-21 14:23:54 +00:00
|
|
|
return (odp->type == TYPE_CDECL ||
|
|
|
|
odp->type == TYPE_PASCAL ||
|
|
|
|
odp->type == TYPE_VARARGS ||
|
|
|
|
odp->type == TYPE_STUB);
|
|
|
|
}
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2001-12-14 23:14:22 +00:00
|
|
|
/*******************************************************************
|
2005-09-21 14:23:54 +00:00
|
|
|
* output_entries
|
2001-12-14 23:14:22 +00:00
|
|
|
*
|
2005-09-21 14:23:54 +00:00
|
|
|
* Output entries for individual symbols in the entry table.
|
2001-12-14 23:14:22 +00:00
|
|
|
*/
|
2006-08-11 18:41:29 +00:00
|
|
|
static void output_entries( DLLSPEC *spec, int first, int count )
|
2001-12-14 23:14:22 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[first + i];
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0x03\n" ); /* flags: exported & public data */
|
2005-09-21 14:23:54 +00:00
|
|
|
switch (odp->type)
|
|
|
|
{
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_PASCAL:
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
case TYPE_STUB:
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_%s_%u-.L__wine_spec_code_segment\n",
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword(),
|
|
|
|
make_c_identifier(spec->dll_name), first + i );
|
|
|
|
break;
|
|
|
|
case TYPE_VARIABLE:
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_%s_%u-.L__wine_spec_data_segment\n",
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword(),
|
|
|
|
make_c_identifier(spec->dll_name), first + i );
|
|
|
|
break;
|
|
|
|
case TYPE_ABS:
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s 0x%04x /* %s */\n",
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword(), odp->u.abs.value, odp->name );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2001-12-14 23:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 20:15:35 +00:00
|
|
|
/*******************************************************************
|
2005-05-18 18:21:59 +00:00
|
|
|
* output_entry_table
|
2000-06-23 20:15:35 +00:00
|
|
|
*/
|
2006-08-11 18:41:29 +00:00
|
|
|
static void output_entry_table( DLLSPEC *spec )
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
int i, prev = 0, prev_sel = -1, bundle_count = 0;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2004-02-11 06:41:01 +00:00
|
|
|
for (i = 1; i <= spec->limit; i++)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
|
|
|
int selector = 0;
|
2004-02-11 06:41:01 +00:00
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
2000-06-23 20:15:35 +00:00
|
|
|
if (!odp) continue;
|
2009-12-28 21:42:58 +00:00
|
|
|
if (odp->flags & FLAG_EXPORT32) continue;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-05-18 18:21:59 +00:00
|
|
|
switch (odp->type)
|
|
|
|
{
|
2000-06-23 20:15:35 +00:00
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_PASCAL:
|
2003-08-27 02:20:44 +00:00
|
|
|
case TYPE_VARARGS:
|
2000-06-23 20:15:35 +00:00
|
|
|
case TYPE_STUB:
|
|
|
|
selector = 1; /* Code selector */
|
|
|
|
break;
|
2000-11-26 04:31:48 +00:00
|
|
|
case TYPE_VARIABLE:
|
2000-06-23 20:15:35 +00:00
|
|
|
selector = 2; /* Data selector */
|
|
|
|
break;
|
|
|
|
case TYPE_ABS:
|
|
|
|
selector = 0xfe; /* Constant selector */
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-18 18:21:59 +00:00
|
|
|
continue;
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
if (prev + 1 != i || prev_sel != selector || bundle_count == 255)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2005-05-18 18:21:59 +00:00
|
|
|
/* need to start a new bundle */
|
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* flush previous bundle */
|
|
|
|
if (bundle_count)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t/* %s.%d - %s.%d */\n",
|
2005-09-21 14:23:54 +00:00
|
|
|
spec->dll_name, prev - bundle_count + 1, spec->dll_name, prev );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0x%02x,0x%02x\n", bundle_count, prev_sel );
|
|
|
|
output_entries( spec, prev - bundle_count + 1, bundle_count );
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
|
|
|
|
2005-05-18 18:21:59 +00:00
|
|
|
if (prev + 1 != i)
|
|
|
|
{
|
|
|
|
int skip = i - (prev + 1);
|
|
|
|
while (skip > 255)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0xff,0x00\n" );
|
2005-05-18 18:21:59 +00:00
|
|
|
skip -= 255;
|
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0x%02x,0x00\n", skip );
|
2005-05-18 18:21:59 +00:00
|
|
|
}
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
bundle_count = 0;
|
2005-05-18 18:21:59 +00:00
|
|
|
prev_sel = selector;
|
|
|
|
}
|
2005-09-21 14:23:54 +00:00
|
|
|
bundle_count++;
|
2005-05-18 18:21:59 +00:00
|
|
|
prev = i;
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
2005-09-21 14:23:54 +00:00
|
|
|
|
|
|
|
/* flush last bundle */
|
|
|
|
if (bundle_count)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0x%02x,0x%02x\n", bundle_count, prev_sel );
|
|
|
|
output_entries( spec, prev - bundle_count + 1, bundle_count );
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0x00\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_resident_name
|
|
|
|
*/
|
2006-08-11 18:41:29 +00:00
|
|
|
static void output_resident_name( const char *string, int ordinal )
|
2005-09-21 14:23:54 +00:00
|
|
|
{
|
|
|
|
unsigned int i, len = strlen(string);
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0x%02x", len );
|
|
|
|
for (i = 0; i < len; i++) output( ",0x%02x", (unsigned char)toupper(string[i]) );
|
|
|
|
output( " /* %s */\n", string );
|
|
|
|
output( "\t%s %u\n", get_asm_short_keyword(), ordinal );
|
2005-05-18 18:21:59 +00:00
|
|
|
}
|
2000-06-23 20:15:35 +00:00
|
|
|
|
|
|
|
|
2005-05-18 18:21:59 +00:00
|
|
|
/*******************************************************************
|
2005-09-21 14:23:54 +00:00
|
|
|
* get_callfrom16_name
|
2005-05-18 18:21:59 +00:00
|
|
|
*/
|
2005-09-21 14:23:54 +00:00
|
|
|
static const char *get_callfrom16_name( const ORDDEF *odp )
|
2005-05-18 18:21:59 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
static char buffer[80];
|
|
|
|
|
|
|
|
sprintf( buffer, "%s_%s_%s",
|
|
|
|
(odp->type == TYPE_PASCAL) ? "p" :
|
|
|
|
(odp->type == TYPE_VARARGS) ? "v" : "c",
|
|
|
|
(odp->flags & FLAG_REGISTER) ? "regs" :
|
|
|
|
(odp->flags & FLAG_RET16) ? "word" : "long",
|
|
|
|
odp->u.func.arg_types );
|
|
|
|
return buffer;
|
|
|
|
}
|
2005-05-18 18:21:59 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* get_relay_name
|
|
|
|
*/
|
|
|
|
static const char *get_relay_name( const ORDDEF *odp )
|
|
|
|
{
|
|
|
|
static char buffer[80];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
switch(odp->type)
|
2005-05-18 18:21:59 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
case TYPE_PASCAL:
|
|
|
|
strcpy( buffer, "p_" );
|
|
|
|
break;
|
|
|
|
case TYPE_VARARGS:
|
|
|
|
strcpy( buffer, "v_" );
|
|
|
|
break;
|
|
|
|
case TYPE_CDECL:
|
|
|
|
case TYPE_STUB:
|
|
|
|
strcpy( buffer, "c_" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
strcat( buffer, odp->u.func.arg_types );
|
|
|
|
for (p = buffer + 2; *p; p++)
|
|
|
|
{
|
|
|
|
/* map string types to the corresponding plain pointer type */
|
|
|
|
if (*p == 't') *p = 'p';
|
|
|
|
else if (*p == 'T') *p = 'l';
|
2005-05-18 18:21:59 +00:00
|
|
|
}
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->flags & FLAG_REGISTER) strcat( buffer, "_regs" );
|
|
|
|
return buffer;
|
2005-05-18 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 20:15:35 +00:00
|
|
|
/*******************************************************************
|
2005-09-21 14:23:54 +00:00
|
|
|
* get_function_argsize
|
|
|
|
*/
|
|
|
|
static int get_function_argsize( const ORDDEF *odp )
|
|
|
|
{
|
|
|
|
const char *args;
|
|
|
|
int argsize = 0;
|
|
|
|
|
|
|
|
for (args = odp->u.func.arg_types; *args; args++)
|
|
|
|
{
|
|
|
|
switch (*args)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return argsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_call16_function
|
2000-06-23 20:15:35 +00:00
|
|
|
*
|
2002-05-31 23:06:46 +00:00
|
|
|
* Build a 16-bit-to-Wine callback glue function.
|
2000-06-23 20:15:35 +00:00
|
|
|
*
|
2002-05-31 23:06:46 +00:00
|
|
|
* The generated routines are intended to be used as argument conversion
|
2000-06-23 20:15:35 +00:00
|
|
|
* routines to be called by the CallFrom16... core. Thus, the prototypes of
|
|
|
|
* the generated routines are (see also CallFrom16):
|
|
|
|
*
|
2005-09-21 14:23:54 +00:00
|
|
|
* extern WORD WINAPI __wine_spec_call16_C_xxx( FARPROC func, LPBYTE args );
|
|
|
|
* extern LONG WINAPI __wine_spec_call16_C_xxx( FARPROC func, LPBYTE args );
|
|
|
|
* extern void WINAPI __wine_spec_call16_C_xxx_regs( FARPROC func, LPBYTE args, CONTEXT86 *context );
|
2000-06-23 20:15:35 +00:00
|
|
|
*
|
2002-05-31 23:06:46 +00: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 20:15:35 +00: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-05-31 23:06:46 +00:00
|
|
|
* to by 'args'); the offsets of the single argument values are computed
|
2000-06-23 20:15:35 +00:00
|
|
|
* according to the calling convention and the argument types. Then, the
|
|
|
|
* 32-bit entry point is called with these arguments.
|
2002-05-31 23:06:46 +00:00
|
|
|
*
|
2000-06-23 20:15:35 +00:00
|
|
|
* For register functions, the arguments (if present) are converted just
|
2002-05-31 23:06:46 +00:00
|
|
|
* the same as for normal functions, but in addition the CONTEXT86 pointer
|
2000-06-23 20:15:35 +00:00
|
|
|
* filled with the current register values is passed to the 32-bit routine.
|
|
|
|
*/
|
2006-08-11 18:41:29 +00:00
|
|
|
static void output_call16_function( ORDDEF *odp )
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
char name[256];
|
2005-11-28 16:39:05 +00:00
|
|
|
int i, pos, stack_words;
|
2005-09-21 14:23:54 +00:00
|
|
|
const char *args = odp->u.func.arg_types;
|
|
|
|
int argsize = get_function_argsize( odp );
|
|
|
|
int needs_ldt = strchr( args, 'p' ) || strchr( args, 't' );
|
|
|
|
|
|
|
|
sprintf( name, ".L__wine_spec_call16_%s", get_relay_name(odp) );
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
|
|
|
output( "\t%s\n", func_declaration(name) );
|
|
|
|
output( "%s:\n", name );
|
2010-04-12 10:33:19 +00:00
|
|
|
output_cfi( ".cfi_startproc" );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tpushl %%ebp\n" );
|
2010-04-12 10:33:19 +00:00
|
|
|
output_cfi( ".cfi_adjust_cfa_offset 4" );
|
|
|
|
output_cfi( ".cfi_rel_offset %%ebp,0" );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tmovl %%esp,%%ebp\n" );
|
2010-04-12 10:33:19 +00:00
|
|
|
output_cfi( ".cfi_def_cfa_register %%ebp" );
|
2005-11-28 16:39:05 +00:00
|
|
|
stack_words = 2;
|
2005-09-21 14:23:54 +00:00
|
|
|
if (needs_ldt)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tpushl %%esi\n" );
|
2010-04-12 10:33:19 +00:00
|
|
|
output_cfi( ".cfi_rel_offset %%esi,-4" );
|
2005-11-28 16:39:05 +00:00
|
|
|
stack_words++;
|
2005-09-21 14:23:54 +00:00
|
|
|
if (UsePIC)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
|
|
|
|
output( "1:\tmovl wine_ldt_copy_ptr-1b(%%eax),%%esi\n" );
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
2005-09-21 14:23:54 +00:00
|
|
|
else
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tmovl $%s,%%esi\n", asm_name("wine_ldt_copy") );
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-11-28 16:39:05 +00:00
|
|
|
/* preserve 16-byte stack alignment */
|
|
|
|
stack_words += strlen(args);
|
|
|
|
if ((odp->flags & FLAG_REGISTER) || (odp->type == TYPE_VARARGS)) stack_words++;
|
2006-08-11 18:41:29 +00:00
|
|
|
if (stack_words % 4) output( "\tsubl $%d,%%esp\n", 16 - 4 * (stack_words % 4) );
|
2005-11-28 16:39:05 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
if (args[0] || odp->type == TYPE_VARARGS)
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tmovl 12(%%ebp),%%ecx\n" ); /* args */
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->flags & FLAG_REGISTER)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tpushl 16(%%ebp)\n" ); /* context */
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
2005-09-21 14:23:54 +00:00
|
|
|
else if (odp->type == TYPE_VARARGS)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tleal %d(%%ecx),%%eax\n", argsize );
|
|
|
|
output( "\tpushl %%eax\n" ); /* va_list16 */
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pos = (odp->type == TYPE_PASCAL) ? 0 : argsize;
|
|
|
|
for (i = strlen(args) - 1; i >= 0; i--)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
|
|
|
switch (args[i])
|
|
|
|
{
|
|
|
|
case 'w': /* word */
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type != TYPE_PASCAL) pos -= 2;
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tmovzwl %d(%%ecx),%%eax\n", pos );
|
|
|
|
output( "\tpushl %%eax\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type == TYPE_PASCAL) pos += 2;
|
2000-06-23 20:15:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* s_word */
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type != TYPE_PASCAL) pos -= 2;
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tmovswl %d(%%ecx),%%eax\n", pos );
|
|
|
|
output( "\tpushl %%eax\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type == TYPE_PASCAL) pos += 2;
|
2000-06-23 20:15:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* long or segmented pointer */
|
|
|
|
case 'T': /* segmented pointer to null-terminated string */
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type != TYPE_PASCAL) pos -= 4;
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tpushl %d(%%ecx)\n", pos );
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type == TYPE_PASCAL) pos += 4;
|
2000-06-23 20:15:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p': /* linear pointer */
|
|
|
|
case 't': /* linear pointer to null-terminated string */
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type != TYPE_PASCAL) pos -= 4;
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tmovzwl %d(%%ecx),%%edx\n", pos + 2 ); /* sel */
|
|
|
|
output( "\tshr $3,%%edx\n" );
|
|
|
|
output( "\tmovzwl %d(%%ecx),%%eax\n", pos ); /* offset */
|
|
|
|
output( "\taddl (%%esi,%%edx,4),%%eax\n" );
|
|
|
|
output( "\tpushl %%eax\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
if (odp->type == TYPE_PASCAL) pos += 4;
|
2000-06-23 20:15:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-09-21 14:23:54 +00:00
|
|
|
assert(0);
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tcall *8(%%ebp)\n" );
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2010-04-12 10:33:19 +00:00
|
|
|
if (needs_ldt)
|
|
|
|
{
|
|
|
|
output( "\tmovl -4(%%ebp),%%esi\n" );
|
|
|
|
output_cfi( ".cfi_same_value %%esi" );
|
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tleave\n" );
|
2010-04-12 10:33:19 +00:00
|
|
|
output_cfi( ".cfi_def_cfa %%esp,4" );
|
|
|
|
output_cfi( ".cfi_same_value %%ebp" );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tret\n" );
|
2010-04-12 10:33:19 +00:00
|
|
|
output_cfi( ".cfi_endproc" );
|
2006-08-11 18:41:29 +00:00
|
|
|
output_function_size( name );
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2005-09-21 14:23:54 +00:00
|
|
|
* callfrom16_type_compare
|
|
|
|
*
|
|
|
|
* Compare two callfrom16 sequences.
|
2000-06-23 20:15:35 +00:00
|
|
|
*/
|
2005-09-21 14:23:54 +00:00
|
|
|
static int callfrom16_type_compare( const void *e1, const void *e2 )
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2004-05-18 21:27:44 +00:00
|
|
|
const ORDDEF *odp1 = *(const ORDDEF * const *)e1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF * const *)e2;
|
2001-12-14 23:14:22 +00:00
|
|
|
int retval;
|
2003-08-27 02:20:44 +00:00
|
|
|
int type1 = odp1->type;
|
|
|
|
int type2 = odp2->type;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2003-08-27 02:20:44 +00:00
|
|
|
if (type1 == TYPE_STUB) type1 = TYPE_CDECL;
|
|
|
|
if (type2 == TYPE_STUB) type2 = TYPE_CDECL;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2003-08-27 02:20:44 +00:00
|
|
|
if ((retval = type1 - type2) != 0) return retval;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2004-03-15 20:09:23 +00:00
|
|
|
type1 = odp1->flags & (FLAG_RET16|FLAG_REGISTER);
|
|
|
|
type2 = odp2->flags & (FLAG_RET16|FLAG_REGISTER);
|
2001-12-14 23:14:22 +00:00
|
|
|
|
2003-08-27 02:20:44 +00:00
|
|
|
if ((retval = type1 - type2) != 0) return retval;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2003-08-27 02:20:44 +00:00
|
|
|
return strcmp( odp1->u.func.arg_types, odp2->u.func.arg_types );
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-12 03:45:55 +00:00
|
|
|
/*******************************************************************
|
2005-09-21 14:23:54 +00:00
|
|
|
* relay_type_compare
|
2000-11-12 03:45:55 +00:00
|
|
|
*
|
2005-09-21 14:23:54 +00:00
|
|
|
* Same as callfrom16_type_compare but ignores differences that don't affect the resulting relay function.
|
|
|
|
*/
|
|
|
|
static int relay_type_compare( const void *e1, const void *e2 )
|
2000-11-12 03:45:55 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
const ORDDEF *odp1 = *(const ORDDEF * const *)e1;
|
|
|
|
const ORDDEF *odp2 = *(const ORDDEF * const *)e2;
|
|
|
|
char name1[80];
|
2000-11-12 03:45:55 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
strcpy( name1, get_relay_name(odp1) );
|
|
|
|
return strcmp( name1, get_relay_name(odp2) );
|
2000-11-12 03:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 20:15:35 +00:00
|
|
|
/*******************************************************************
|
2005-09-21 14:23:54 +00:00
|
|
|
* sort_func_list
|
2000-06-23 20:15:35 +00:00
|
|
|
*
|
2005-09-21 14:23:54 +00:00
|
|
|
* Sort a list of functions, removing duplicates.
|
2000-06-23 20:15:35 +00:00
|
|
|
*/
|
2005-09-21 14:23:54 +00:00
|
|
|
static int sort_func_list( ORDDEF **list, int count,
|
|
|
|
int (*compare)(const void *, const void *) )
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
int i, j;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2008-03-03 14:19:53 +00:00
|
|
|
if (!count) return 0;
|
2005-09-21 14:23:54 +00:00
|
|
|
qsort( list, count, sizeof(*list), compare );
|
2000-08-14 14:29:22 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
for (i = j = 0; i < count; i++)
|
2002-06-21 19:15:45 +00:00
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
if (compare( &list[j], &list[i] )) list[++j] = list[i];
|
2002-06-21 19:15:45 +00:00
|
|
|
}
|
2005-09-21 14:23:54 +00:00
|
|
|
return j + 1;
|
|
|
|
}
|
2001-05-22 19:55:51 +00:00
|
|
|
|
2000-11-12 03:45:55 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/*******************************************************************
|
2009-02-24 17:02:15 +00:00
|
|
|
* output_module16
|
2005-09-21 14:23:54 +00:00
|
|
|
*
|
2009-02-24 17:02:15 +00:00
|
|
|
* Output code for a 16-bit module.
|
2005-09-21 14:23:54 +00:00
|
|
|
*/
|
2009-02-24 17:02:15 +00:00
|
|
|
static void output_module16( DLLSPEC *spec )
|
2005-09-21 14:23:54 +00:00
|
|
|
{
|
|
|
|
ORDDEF **typelist;
|
2008-03-03 14:19:53 +00:00
|
|
|
ORDDEF *entry_point = NULL;
|
2005-09-21 14:23:54 +00:00
|
|
|
int i, j, nb_funcs;
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2008-03-03 14:19:53 +00:00
|
|
|
/* store the main entry point as ordinal 0 */
|
|
|
|
|
|
|
|
if (!spec->ordinals)
|
|
|
|
{
|
2009-03-22 21:32:51 +00:00
|
|
|
assert(spec->limit == 0);
|
2008-03-03 14:19:53 +00:00
|
|
|
spec->ordinals = xmalloc( sizeof(spec->ordinals[0]) );
|
|
|
|
spec->ordinals[0] = NULL;
|
|
|
|
}
|
|
|
|
if (spec->init_func && !(spec->characteristics & IMAGE_FILE_DLL))
|
|
|
|
{
|
|
|
|
entry_point = xmalloc( sizeof(*entry_point) );
|
|
|
|
entry_point->type = TYPE_PASCAL;
|
|
|
|
entry_point->ordinal = 0;
|
|
|
|
entry_point->lineno = 0;
|
|
|
|
entry_point->flags = FLAG_REGISTER;
|
|
|
|
entry_point->name = NULL;
|
|
|
|
entry_point->link_name = xstrdup( spec->init_func );
|
|
|
|
entry_point->export_name = NULL;
|
|
|
|
entry_point->u.func.arg_types[0] = 0;
|
|
|
|
assert( !spec->ordinals[0] );
|
|
|
|
spec->ordinals[0] = entry_point;
|
|
|
|
}
|
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* Build sorted list of all argument types, without duplicates */
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
typelist = xmalloc( (spec->limit + 1) * sizeof(*typelist) );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
for (i = nb_funcs = 0; i <= spec->limit; i++)
|
2005-05-23 12:07:15 +00:00
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
2005-09-21 14:23:54 +00:00
|
|
|
if (!odp) continue;
|
|
|
|
if (is_function( odp )) typelist[nb_funcs++] = odp;
|
2005-05-23 12:07:15 +00:00
|
|
|
}
|
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
nb_funcs = sort_func_list( typelist, nb_funcs, callfrom16_type_compare );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* Output the module structure */
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n/* module data */\n\n" );
|
|
|
|
output( "\t.data\n" );
|
|
|
|
output( "\t.align %d\n", get_alignment(4) );
|
2009-02-24 16:47:09 +00:00
|
|
|
output( ".L__wine_spec_dos_header:\n" );
|
2009-04-09 18:58:43 +00:00
|
|
|
output( "\t%s 0x5a4d\n", get_asm_short_keyword() ); /* e_magic */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_cblp */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_cp */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_crlc */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_cparhdr */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_minalloc */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_maxalloc */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_ss */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_sp */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_csum */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_ip */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_cs */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_lfarlc */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_ovno */
|
|
|
|
output( "\t%s 0,0,0,0\n", get_asm_short_keyword() ); /* e_res */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_oemid */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* e_oeminfo */
|
|
|
|
output( "\t%s 0,0,0,0,0,0,0,0,0,0\n", get_asm_short_keyword() ); /* e_res2 */
|
2009-02-24 16:47:09 +00:00
|
|
|
output( "\t.long .L__wine_spec_ne_header-.L__wine_spec_dos_header\n" );/* e_lfanew */
|
2006-08-11 18:41:29 +00:00
|
|
|
|
|
|
|
output( ".L__wine_spec_ne_header:\n" );
|
2009-04-09 18:58:43 +00:00
|
|
|
output( "\t%s 0x454e\n", get_asm_short_keyword() ); /* ne_magic */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0\n" ); /* ne_ver */
|
|
|
|
output( "\t.byte 0\n" ); /* ne_rev */
|
|
|
|
output( "\t%s .L__wine_spec_ne_enttab-.L__wine_spec_ne_header\n", /* ne_enttab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_ne_enttab_end-.L__wine_spec_ne_enttab\n", /* ne_cbenttab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.long 0\n" ); /* ne_crc */
|
|
|
|
output( "\t%s 0x%04x\n", get_asm_short_keyword(), /* ne_flags */
|
2008-03-03 14:19:53 +00:00
|
|
|
NE_FFLAGS_SINGLEDATA |
|
|
|
|
((spec->characteristics & IMAGE_FILE_DLL) ? NE_FFLAGS_LIBMODULE : 0) );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s 2\n", get_asm_short_keyword() ); /* ne_autodata */
|
|
|
|
output( "\t%s %u\n", get_asm_short_keyword(), spec->heap_size ); /* ne_heap */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_stack */
|
2008-03-03 14:19:53 +00:00
|
|
|
if (!entry_point) output( "\t.long 0\n" ); /* ne_csip */
|
|
|
|
else output( "\t%s .L__wine_%s_0-.L__wine_spec_code_segment,1\n",
|
|
|
|
get_asm_short_keyword(), make_c_identifier(spec->dll_name) );
|
|
|
|
output( "\t%s 0,2\n", get_asm_short_keyword() ); /* ne_sssp */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s 2\n", get_asm_short_keyword() ); /* ne_cseg */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_cmod */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_cbnrestab */
|
|
|
|
output( "\t%s .L__wine_spec_ne_segtab-.L__wine_spec_ne_header\n", /* ne_segtab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_ne_rsrctab-.L__wine_spec_ne_header\n", /* ne_rsrctab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_ne_restab-.L__wine_spec_ne_header\n", /* ne_restab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_ne_modtab-.L__wine_spec_ne_header\n", /* ne_modtab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_ne_imptab-.L__wine_spec_ne_header\n", /* ne_imptab */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.long 0\n" ); /* ne_nrestab */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_cmovent */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_align */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_cres */
|
2009-08-15 09:21:38 +00:00
|
|
|
output( "\t.byte 0x02\n" ); /* ne_exetyp = NE_OSFLAGS_WINDOWS */
|
2009-04-09 18:58:43 +00:00
|
|
|
output( "\t.byte 0x08\n" ); /* ne_flagsothers = NE_AFLAGS_FASTLOAD */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_pretthunks */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_psegrefbytes */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_swaparea */
|
|
|
|
output( "\t%s 0\n", get_asm_short_keyword() ); /* ne_expver */
|
2001-12-14 23:14:22 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* segment table */
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n.L__wine_spec_ne_segtab:\n" );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* code segment entry */
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2009-02-24 16:47:09 +00:00
|
|
|
output( "\t%s .L__wine_spec_code_segment-.L__wine_spec_dos_header\n", /* filepos */
|
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_code_segment_end-.L__wine_spec_code_segment\n", /* size */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2009-04-09 18:58:43 +00:00
|
|
|
output( "\t%s 0x2000\n", get_asm_short_keyword() ); /* flags = NE_SEGFLAGS_32BIT */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_code_segment_end-.L__wine_spec_code_segment\n", /* minsize */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* data segment entry */
|
2005-05-23 12:07:15 +00:00
|
|
|
|
2009-02-24 16:47:09 +00:00
|
|
|
output( "\t%s .L__wine_spec_data_segment-.L__wine_spec_dos_header\n", /* filepos */
|
|
|
|
get_asm_short_keyword() );
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_data_segment_end-.L__wine_spec_data_segment\n", /* size */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2009-04-09 18:58:43 +00:00
|
|
|
output( "\t%s 0x0001\n", get_asm_short_keyword() ); /* flags = NE_SEGFLAGS_DATA */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s .L__wine_spec_data_segment_end-.L__wine_spec_data_segment\n", /* minsize */
|
2005-09-21 14:23:54 +00:00
|
|
|
get_asm_short_keyword() );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
|
|
|
/* resource directory */
|
|
|
|
|
2009-02-24 16:47:09 +00:00
|
|
|
output_res16_directory( spec );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
|
|
|
/* resident names table */
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n\t.align %d\n", get_alignment(2) );
|
|
|
|
output( ".L__wine_spec_ne_restab:\n" );
|
|
|
|
output_resident_name( spec->dll_name, 0 );
|
2005-05-23 12:07:15 +00:00
|
|
|
for (i = 1; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
if (!odp || !odp->name[0]) continue;
|
2009-12-28 21:42:58 +00:00
|
|
|
if (odp->flags & FLAG_EXPORT32) continue;
|
2006-08-11 18:41:29 +00:00
|
|
|
output_resident_name( odp->name, i );
|
2005-05-23 12:07:15 +00:00
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0\n" );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
|
|
|
/* imported names table */
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n\t.align %d\n", get_alignment(2) );
|
|
|
|
output( ".L__wine_spec_ne_modtab:\n" );
|
|
|
|
output( ".L__wine_spec_ne_imptab:\n" );
|
|
|
|
output( "\t.byte 0,0\n" );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
|
|
|
/* entry table */
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n.L__wine_spec_ne_enttab:\n" );
|
|
|
|
output_entry_table( spec );
|
|
|
|
output( ".L__wine_spec_ne_enttab_end:\n" );
|
2005-05-23 12:07:15 +00:00
|
|
|
|
|
|
|
/* code segment */
|
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n\t.align %d\n", get_alignment(2) );
|
|
|
|
output( ".L__wine_spec_code_segment:\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < nb_funcs; i++ )
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2001-12-14 23:14:22 +00:00
|
|
|
unsigned int arg_types[2];
|
2007-12-13 23:18:30 +00:00
|
|
|
int nop_words, argsize = 0;
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2003-08-27 02:20:44 +00:00
|
|
|
if ( typelist[i]->type == TYPE_PASCAL )
|
2005-09-21 14:23:54 +00:00
|
|
|
argsize = get_function_argsize( typelist[i] );
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2001-12-14 23:14:22 +00:00
|
|
|
/* 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));
|
|
|
|
}
|
2005-07-05 11:50:40 +00:00
|
|
|
if (typelist[i]->type == TYPE_VARARGS) arg_types[j / 10] |= ARG_VARARG << (3 * (j % 10));
|
2005-09-18 12:25:22 +00:00
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( ".L__wine_spec_callfrom16_%s:\n", get_callfrom16_name(typelist[i]) );
|
|
|
|
output( "\tpushl $.L__wine_spec_call16_%s\n", get_relay_name(typelist[i]) );
|
|
|
|
output( "\tlcall $0,$0\n" );
|
2005-09-18 12:25:22 +00:00
|
|
|
|
|
|
|
if (typelist[i]->flags & FLAG_REGISTER)
|
|
|
|
{
|
2005-09-21 14:23:54 +00:00
|
|
|
nop_words = 4;
|
2005-09-18 12:25:22 +00:00
|
|
|
}
|
|
|
|
else if (typelist[i]->flags & FLAG_RET16)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\torw %%ax,%%ax\n" );
|
|
|
|
output( "\tnop\n" ); /* so that the lretw is aligned */
|
2005-09-21 14:23:54 +00:00
|
|
|
nop_words = 2;
|
2005-09-18 12:25:22 +00:00
|
|
|
}
|
2000-08-14 14:29:22 +00:00
|
|
|
else
|
2005-09-18 12:25:22 +00:00
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tshld $16,%%eax,%%edx\n" );
|
|
|
|
output( "\torl %%eax,%%eax\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
nop_words = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argsize)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tlretw $%u\n", argsize );
|
2005-09-21 14:23:54 +00:00
|
|
|
nop_words--;
|
2005-09-18 12:25:22 +00:00
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
else output( "\tlretw\n" );
|
2005-09-21 14:23:54 +00:00
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
if (nop_words) output( "\t%s\n", nop_sequence[nop_words-1] );
|
2005-09-21 14:23:54 +00:00
|
|
|
|
2005-09-18 12:25:22 +00:00
|
|
|
/* the movl is here so that the code contains only valid instructions, */
|
|
|
|
/* it's never actually executed, we only care about the arg_types[] values */
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t%s 0x86c7\n", get_asm_short_keyword() );
|
|
|
|
output( "\t.long 0x%08x,0x%08x\n", arg_types[0], arg_types[1] );
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
|
|
|
|
2004-02-11 06:41:01 +00:00
|
|
|
for (i = 0; i <= spec->limit; i++)
|
2000-06-23 20:15:35 +00:00
|
|
|
{
|
2004-02-11 06:41:01 +00:00
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
2005-09-21 14:23:54 +00:00
|
|
|
if (!odp || !is_function( odp )) continue;
|
2006-08-11 18:41:29 +00:00
|
|
|
output( ".L__wine_%s_%u:\n", make_c_identifier(spec->dll_name), i );
|
|
|
|
output( "\tpushw %%bp\n" );
|
|
|
|
output( "\tpushl $%s\n",
|
2005-09-21 14:23:54 +00:00
|
|
|
asm_name( odp->type == TYPE_STUB ? get_stub_name( odp, spec ) : odp->link_name ));
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\tcallw .L__wine_spec_callfrom16_%s\n", get_callfrom16_name( odp ) );
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
output( ".L__wine_spec_code_segment_end:\n" );
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* data segment */
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n.L__wine_spec_data_segment:\n" );
|
|
|
|
output( "\t.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n" ); /* instance data */
|
2005-09-21 14:23:54 +00:00
|
|
|
for (i = 0; i <= spec->limit; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = spec->ordinals[i];
|
|
|
|
if (!odp || odp->type != TYPE_VARIABLE) continue;
|
2006-08-11 18:41:29 +00:00
|
|
|
output( ".L__wine_%s_%u:\n", make_c_identifier(spec->dll_name), i );
|
|
|
|
output( "\t.long " );
|
2005-09-21 14:23:54 +00:00
|
|
|
for (j = 0; j < odp->u.var.n_values-1; j++)
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "0x%08x,", odp->u.var.values[j] );
|
|
|
|
output( "0x%08x\n", odp->u.var.values[j] );
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
2006-08-11 18:41:29 +00:00
|
|
|
output( ".L__wine_spec_data_segment_end:\n" );
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-05-23 12:07:15 +00:00
|
|
|
/* resource data */
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
if (spec->nb_resources)
|
2005-05-23 12:07:15 +00:00
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n.L__wine_spec_resource_data:\n" );
|
|
|
|
output_res16_data( spec );
|
2005-05-23 12:07:15 +00:00
|
|
|
}
|
2001-12-14 23:14:22 +00:00
|
|
|
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\t.byte 0\n" ); /* make sure the last symbol points to something */
|
2000-10-25 20:33:58 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
/* relay functions */
|
2000-06-23 20:15:35 +00:00
|
|
|
|
2005-09-21 14:23:54 +00:00
|
|
|
nb_funcs = sort_func_list( typelist, nb_funcs, relay_type_compare );
|
|
|
|
if (nb_funcs)
|
|
|
|
{
|
2006-08-11 18:41:29 +00:00
|
|
|
output( "\n/* relay functions */\n\n" );
|
|
|
|
output( "\t.text\n" );
|
|
|
|
for ( i = 0; i < nb_funcs; i++ ) output_call16_function( typelist[i] );
|
|
|
|
output( "\t.data\n" );
|
|
|
|
output( "wine_ldt_copy_ptr:\n" );
|
|
|
|
output( "\t.long %s\n", asm_name("wine_ldt_copy") );
|
2005-09-21 14:23:54 +00:00
|
|
|
}
|
2005-06-06 15:59:50 +00:00
|
|
|
|
2009-02-24 17:02:15 +00:00
|
|
|
free( typelist );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_spec16_file
|
|
|
|
*
|
|
|
|
* Output the complete data for a spec 16-bit file.
|
|
|
|
*/
|
|
|
|
void output_spec16_file( DLLSPEC *spec16 )
|
|
|
|
{
|
|
|
|
DLLSPEC *spec32 = alloc_dll_spec();
|
|
|
|
|
|
|
|
resolve_imports( spec16 );
|
|
|
|
add_16bit_exports( spec32, spec16 );
|
|
|
|
|
|
|
|
output_standard_file_header();
|
|
|
|
output_module( spec32 );
|
|
|
|
output_module16( spec16 );
|
|
|
|
output_stubs( spec16 );
|
|
|
|
output_exports( spec32 );
|
|
|
|
output_imports( spec16 );
|
2010-01-16 14:58:48 +00:00
|
|
|
if (is_undefined( "__wine_call_from_16" )) output_asm_relays16();
|
2009-03-04 13:08:23 +00:00
|
|
|
if (spec16->main_module)
|
|
|
|
{
|
|
|
|
output( "\n\t%s\n", get_asm_string_section() );
|
|
|
|
output( ".L__wine_spec_main_module:\n" );
|
|
|
|
output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec16->main_module );
|
|
|
|
}
|
2009-02-24 17:02:15 +00:00
|
|
|
output_gnu_stack_note();
|
|
|
|
free_dll_spec( spec32 );
|
2000-06-23 20:15:35 +00:00
|
|
|
}
|
2009-08-14 12:16:38 +00:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_fake_module16
|
|
|
|
*
|
|
|
|
* Create a fake 16-bit binary module.
|
|
|
|
*/
|
2009-08-15 09:21:38 +00:00
|
|
|
void output_fake_module16( DLLSPEC *spec )
|
2009-08-14 12:16:38 +00:00
|
|
|
{
|
2009-08-15 09:21:38 +00:00
|
|
|
static const unsigned char code_segment[] = { 0x90, 0xc3 };
|
|
|
|
static const unsigned char data_segment[16] = { 0 };
|
|
|
|
static const char fakedll_signature[] = "Wine placeholder DLL";
|
|
|
|
const unsigned int cseg = 2;
|
|
|
|
const unsigned int lfanew = (0x40 + sizeof(fakedll_signature) + 15) & ~15;
|
|
|
|
const unsigned int segtab = lfanew + 0x40;
|
|
|
|
|
|
|
|
unsigned int i, rsrctab, restab, namelen, modtab, imptab, enttab, cbenttab, codeseg, dataseg, rsrcdata;
|
|
|
|
|
|
|
|
init_output_buffer();
|
|
|
|
|
|
|
|
rsrctab = lfanew;
|
|
|
|
restab = segtab + 8 * cseg;
|
|
|
|
if (spec->nb_resources)
|
|
|
|
{
|
|
|
|
output_bin_res16_directory( spec, 0 );
|
|
|
|
align_output( 2 );
|
|
|
|
rsrctab = restab;
|
|
|
|
restab += output_buffer_pos;
|
|
|
|
free( output_buffer );
|
|
|
|
init_output_buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
namelen = strlen( spec->dll_name );
|
|
|
|
modtab = restab + ((namelen + 3) & ~1);
|
|
|
|
imptab = modtab;
|
|
|
|
enttab = modtab + 2;
|
|
|
|
cbenttab = 1;
|
|
|
|
codeseg = (enttab + cbenttab + 1) & ~1;
|
|
|
|
dataseg = codeseg + sizeof(code_segment);
|
|
|
|
rsrcdata = dataseg + sizeof(data_segment);
|
|
|
|
|
|
|
|
init_output_buffer();
|
|
|
|
|
|
|
|
put_word( 0x5a4d ); /* e_magic */
|
|
|
|
put_word( 0x40 ); /* e_cblp */
|
|
|
|
put_word( 0x01 ); /* e_cp */
|
|
|
|
put_word( 0 ); /* e_crlc */
|
|
|
|
put_word( lfanew / 16 ); /* e_cparhdr */
|
|
|
|
put_word( 0x0000 ); /* e_minalloc */
|
|
|
|
put_word( 0xffff ); /* e_maxalloc */
|
|
|
|
put_word( 0x0000 ); /* e_ss */
|
|
|
|
put_word( 0x00b8 ); /* e_sp */
|
|
|
|
put_word( 0 ); /* e_csum */
|
|
|
|
put_word( 0 ); /* e_ip */
|
|
|
|
put_word( 0 ); /* e_cs */
|
|
|
|
put_word( lfanew ); /* e_lfarlc */
|
|
|
|
put_word( 0 ); /* e_ovno */
|
|
|
|
put_dword( 0 ); /* e_res */
|
|
|
|
put_dword( 0 );
|
|
|
|
put_word( 0 ); /* e_oemid */
|
|
|
|
put_word( 0 ); /* e_oeminfo */
|
|
|
|
put_dword( 0 ); /* e_res2 */
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( lfanew );
|
|
|
|
|
|
|
|
put_data( fakedll_signature, sizeof(fakedll_signature) );
|
|
|
|
align_output( 16 );
|
|
|
|
|
|
|
|
put_word( 0x454e ); /* ne_magic */
|
|
|
|
put_byte( 0 ); /* ne_ver */
|
|
|
|
put_byte( 0 ); /* ne_rev */
|
|
|
|
put_word( enttab - lfanew ); /* ne_enttab */
|
|
|
|
put_word( cbenttab ); /* ne_cbenttab */
|
|
|
|
put_dword( 0 ); /* ne_crc */
|
|
|
|
put_word( NE_FFLAGS_SINGLEDATA | /* ne_flags */
|
|
|
|
((spec->characteristics & IMAGE_FILE_DLL) ? NE_FFLAGS_LIBMODULE : 0) );
|
|
|
|
put_word( 2 ); /* ne_autodata */
|
|
|
|
put_word( spec->heap_size ); /* ne_heap */
|
|
|
|
put_word( 0 ); /* ne_stack */
|
|
|
|
put_word( 0 ); put_word( 0 ); /* ne_csip */
|
|
|
|
put_word( 0 ); put_word( 2 ); /* ne_sssp */
|
|
|
|
put_word( cseg ); /* ne_cseg */
|
|
|
|
put_word( 0 ); /* ne_cmod */
|
|
|
|
put_word( 0 ); /* ne_cbnrestab */
|
|
|
|
put_word( segtab - lfanew ); /* ne_segtab */
|
|
|
|
put_word( rsrctab - lfanew ); /* ne_rsrctab */
|
|
|
|
put_word( restab - lfanew ); /* ne_restab */
|
|
|
|
put_word( modtab - lfanew ); /* ne_modtab */
|
|
|
|
put_word( imptab - lfanew ); /* ne_imptab */
|
|
|
|
put_dword( 0 ); /* ne_nrestab */
|
|
|
|
put_word( 0 ); /* ne_cmovent */
|
|
|
|
put_word( 0 ); /* ne_align */
|
|
|
|
put_word( 0 ); /* ne_cres */
|
|
|
|
put_byte( 2 /*NE_OSFLAGS_WINDOWS*/ ); /* ne_exetyp */
|
|
|
|
put_byte( 8 /*NE_AFLAGS_FASTLOAD*/ ); /* ne_flagsothers */
|
|
|
|
put_word( 0 ); /* ne_pretthunks */
|
|
|
|
put_word( 0 ); /* ne_psegrefbytes */
|
|
|
|
put_word( 0 ); /* ne_swaparea */
|
|
|
|
put_word( 0 ); /* ne_expver */
|
|
|
|
|
|
|
|
/* segment table */
|
|
|
|
put_word( codeseg );
|
|
|
|
put_word( sizeof(code_segment) );
|
|
|
|
put_word( 0x2000 /* NE_SEGFLAGS_32BIT */ );
|
|
|
|
put_word( sizeof(code_segment) );
|
|
|
|
put_word( dataseg );
|
|
|
|
put_word( sizeof(data_segment) );
|
|
|
|
put_word( 0x0001 /* NE_SEGFLAGS_DATA */ );
|
|
|
|
put_word( sizeof(data_segment) );
|
|
|
|
|
|
|
|
/* resource directory */
|
|
|
|
if (spec->nb_resources)
|
|
|
|
{
|
|
|
|
output_bin_res16_directory( spec, rsrcdata );
|
|
|
|
align_output( 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* resident names table */
|
|
|
|
put_byte( namelen );
|
|
|
|
for (i = 0; i < namelen; i++) put_byte( toupper(spec->dll_name[i]) );
|
|
|
|
put_byte( 0 );
|
|
|
|
align_output( 2 );
|
|
|
|
|
|
|
|
/* imported names table */
|
|
|
|
put_word( 0 );
|
|
|
|
|
|
|
|
/* entry table */
|
|
|
|
put_byte( 0 );
|
|
|
|
align_output( 2 );
|
|
|
|
|
|
|
|
/* code segment */
|
|
|
|
put_data( code_segment, sizeof(code_segment) );
|
|
|
|
|
|
|
|
/* data segment */
|
|
|
|
put_data( data_segment, sizeof(data_segment) );
|
|
|
|
|
|
|
|
/* resource data */
|
|
|
|
output_bin_res16_data( spec );
|
|
|
|
|
|
|
|
flush_output_buffer();
|
2009-08-14 12:16:38 +00:00
|
|
|
}
|