Sync to Wine-20050628:
Alexandre Julliard <julliard(a)winehq.org>
- Generate the resource data directly inside the resource directory.
- Replaced all uses of the __ASM_NAME macro by the asm_name function to
allow run-time determination of the correct format.
- Beginnings of an infrastructure to allow specifying the target CPU and
platform at run-time.
- Output the exported names as a C string so that they end up in the
correct section.
- Reuse output_dll_init for the constructor of debug files.
- Moved all assembly code to the end of the generated C files to avoid
conflicting with the compiler over section changes.
- Switch back to .data at the end of asm sections to work around an
optimization in recent gcc versions.
- Remove some i386 ifdefs for 16-bit entry points since they are no
longer used by default on other platforms anyway.
- Make import thunks position-independent to avoid text relocations.
- Generate proper PIC code for CALL32_CBClient.
- Store a relative pointer for registry entry points to avoid some text
relocations.
- Allocate ordinals in the order of the declarations in the spec file.
Wolfgang Thaller <wolfgang.thaller(a)gmx.net>
- Winebuild darwin/x86-specific fixes:
- Assembler interprets .align as power-of-two
- Add .weak_reference to output where gcc 3.3 swallows it
- Use __ASM_NAME and HAVE_ASM_DOT_SIZE in a few places in winebuild
where they have been missing (needed for Darwin/x86).
Pierre d'Herbemont <stegefin(a)free.fr>
- Use .mod_*_func sections on Mac OS X/i386 instead of the elf
constructor/destructor.
Modified: trunk/reactos/tools/winebuild/build.h
Modified: trunk/reactos/tools/winebuild/import.c
Modified: trunk/reactos/tools/winebuild/main.c
Modified: trunk/reactos/tools/winebuild/parser.c
Modified: trunk/reactos/tools/winebuild/relay.c
Modified: trunk/reactos/tools/winebuild/res32.c
Modified: trunk/reactos/tools/winebuild/spec16.c
Modified: trunk/reactos/tools/winebuild/spec32.c
Modified: trunk/reactos/tools/winebuild/utils.c
Modified: trunk/reactos/tools/winebuild/winglue.h
_____
Modified: trunk/reactos/tools/winebuild/build.h
--- trunk/reactos/tools/winebuild/build.h 2005-07-05 21:03:46 UTC
(rev 16437)
+++ trunk/reactos/tools/winebuild/build.h 2005-07-05 21:17:01 UTC
(rev 16438)
@@ -109,6 +109,19 @@
struct resource *resources; /* array of dll resources
(format differs between Win16/Win32) */
} DLLSPEC;
+enum target_cpu
+{
+ CPU_x86, CPU_SPARC, CPU_ALPHA, CPU_POWERPC
+};
+
+enum target_platform
+{
+ PLATFORM_UNSPECIFIED, PLATFORM_APPLE, PLATFORM_SVR4,
PLATFORM_WINDOWS
+};
+
+extern enum target_cpu target_cpu;
+extern enum target_platform target_platform;
+
/* entry point flags */
#define FLAG_NORELAY 0x01 /* don't use relay debugging for this
function */
#define FLAG_NONAME 0x02 /* don't import function by name */
@@ -166,7 +179,11 @@
extern DLLSPEC *alloc_dll_spec(void);
extern void free_dll_spec( DLLSPEC *spec );
extern const char *make_c_identifier( const char *str );
-extern int get_alignment(int alignBoundary);
+extern unsigned int get_alignment(unsigned int align);
+extern unsigned int get_page_size(void);
+extern const char *asm_name( const char *func );
+extern const char *func_declaration( const char *func );
+extern const char *func_size( const char *func );
extern void add_import_dll( const char *name, const char *filename );
extern void add_delayed_import( const char *name );
@@ -174,6 +191,7 @@
extern void read_undef_symbols( char **argv );
extern int resolve_imports( DLLSPEC *spec );
extern int output_imports( FILE *outfile, DLLSPEC *spec, int
*nb_delayed );
+extern void output_import_thunks( FILE *outfile, DLLSPEC *spec );
extern int load_res32_file( const char *name, DLLSPEC *spec );
extern void output_resources( FILE *outfile, DLLSPEC *spec );
extern void load_res16_file( const char *name, DLLSPEC *spec );
_____
Modified: trunk/reactos/tools/winebuild/import.c
--- trunk/reactos/tools/winebuild/import.c 2005-07-05 21:03:46 UTC
(rev 16437)
+++ trunk/reactos/tools/winebuild/import.c 2005-07-05 21:17:01 UTC
(rev 16438)
@@ -125,24 +125,17 @@
"tanh"
};
-#ifdef __powerpc__
-# ifdef __APPLE__
-# define ppc_high(mem) "ha16(" mem ")"
-# define ppc_low(mem) "lo16(" mem ")"
-static const char * const ppc_reg[32] = { "r0", "r1", "r2",
"r3", "r4",
"r5", "r6", "r7",
- "r8", "r9",
"r10","r11","r12","r13","r14","r15",
-
"r16","r17","r18","r19","r20","r21","r22","r23",
-
"r24","r25","r26","r27","r28","r29","r30","r31"
};
-# else /* __APPLE__ */
-# define ppc_high(mem) "(" mem ")@hi"
-# define ppc_low(mem) "(" mem ")@l"
-static const char * const ppc_reg[32] = { "0", "1", "2",
"3", "4", "5",
"6", "7",
- "8", "9",
"10","11","12","13","14","15",
-
"16","17","18","19","20","21","22","23",
-
"24","25","26","27","28","29","30","31"
};
-# endif /* __APPLE__ */
-#endif /* __powerpc__ */
+static inline const char *ppc_reg( int reg )
+{
+ static const char * const ppc_regs[32] = { "r0", "r1",
"r2", "r3",
"r4", "r5", "r6", "r7",
+ "r8", "r9",
"r10","r11","r12","r13","r14","r15",
+
"r16","r17","r18","r19","r20","r21","r22","r23",
+
"r24","r25","r26","r27","r28","r29","r30","r31"
};
+ if (target_platform == PLATFORM_APPLE) return ppc_regs[reg];
+ return ppc_regs[reg] + 1; /* skip the 'r' */
+}
+
/* compare function names; helper for resolve_imports */
static int name_cmp( const void *name, const void *entry )
{
@@ -191,9 +184,8 @@
inline static void output_function_size( FILE *outfile, const char
*name )
{
-#ifdef HAVE_ASM_DOT_SIZE
- fprintf( outfile, " \"\\t.size " __ASM_NAME("%s") ",
. - "
__ASM_NAME("%s") "\\n\"\n", name, name);
-#endif
+ const char *size = func_size( name );
+ if (size[0]) fprintf( outfile, " \"\\t%s\\n\"\n", size );
}
/* free an import structure */
@@ -607,15 +599,17 @@
/* read in the list of undefined symbols */
void read_undef_symbols( char **argv )
{
- static const char name_prefix[] = __ASM_NAME("");
- static const int prefix_len = sizeof(name_prefix) - 1;
+ size_t prefix_len;
FILE *f;
- char *cmd, buffer[1024];
+ char *cmd, buffer[1024], name_prefix[16];
int err;
const char *name;
if (!argv[0]) return;
+ strcpy( name_prefix, asm_name("") );
+ prefix_len = strlen( name_prefix );
+
undef_size = nb_undef_symbols = 0;
/* if we have multiple object files, link them together */
@@ -695,14 +689,120 @@
return 1;
}
+/* output a single import thunk */
+static void output_import_thunk( FILE *outfile, const char *name, const
char *table, int pos )
+{
+ fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(8)
);
+ fprintf( outfile, " \"\\t%s\\n\"\n", func_declaration(name)
);
+ fprintf( outfile, " \"\\t.globl %s\\n\"\n", asm_name(name) );
+ fprintf( outfile, " \"%s:\\n\"\n", asm_name(name) );
+
+ switch(target_cpu)
+ {
+ case CPU_x86:
+ if (!UsePIC)
+ {
+ if (strstr( name, "__wine_call_from_16" )) fprintf(
outfile, " \"\\t.byte 0x2e\\n\"\n" );
+ fprintf( outfile, " \"\\tjmp *(imports+%d)\\n\"\n",
pos
);
+ }
+ else
+ {
+ if (!strcmp( name, "__wine_call_from_32_regs" ) ||
+ !strcmp( name, "__wine_call_from_16_regs" ))
+ {
+ /* special case: need to preserve all registers */
+ fprintf( outfile, " \"\\tpushl %%eax\\n\"\n" );
+ fprintf( outfile, " \"\\tpushfl\\n\"\n" );
+ fprintf( outfile, " \"\\tcall
.L__wine_spec_%s\\n\"\n", name );
+ fprintf( outfile, " \".L__wine_spec_%s:\\n\"\n",
name );
+ fprintf( outfile, " \"\\tpopl %%eax\\n\"\n" );
+ fprintf( outfile, " \"\\taddl
$%d+%s-.L__wine_spec_%s,%%eax\\n\"\n",
+ pos, asm_name(table), name );
+ if (!strcmp( name, "__wine_call_from_16_regs" ))
+ fprintf( outfile, " \"\\t.byte 0x2e\\n\"\n"
);
+ fprintf( outfile, " \"\\tmovl
0(%%eax),%%eax\\n\"\n"
);
+ fprintf( outfile, " \"\\txchgl
4(%%esp),%%eax\\n\"\n" );
+ fprintf( outfile, " \"\\tpopfl\\n\"\n" );
+ fprintf( outfile, " \"\\tret\\n\"\n" );
+ }
+ else
+ {
+ fprintf( outfile, " \"\\tcall
.L__wine_spec_%s\\n\"\n", name );
+ fprintf( outfile, " \".L__wine_spec_%s:\\n\"\n",
name );
+ fprintf( outfile, " \"\\tpopl %%eax\\n\"\n" );
+ fprintf( outfile, " \"\\taddl
$%d+%s-.L__wine_spec_%s,%%eax\\n\"\n",
+ pos, asm_name(table), name );
+ if (strstr( name, "__wine_call_from_16" ))
+ fprintf( outfile, " \"\\t.byte 0x2e\\n\"\n"
);
+ fprintf( outfile, " \"\\tjmp *0(%%eax)\\n\"\n" );
+ }
+ }
+ break;
+ case CPU_SPARC:
+ if ( !UsePIC )
+ {
+ fprintf( outfile, " \"\\tsethi %%hi(%s+%d),
%%g1\\n\"\n", table, pos );
+ fprintf( outfile, " \"\\tld [%%g1+%%lo(%s+%d)],
%%g1\\n\"\n", table, pos );
+ fprintf( outfile, " \"\\tjmp %%g1\\n\\tnop\\n\"\n" );
+ }
+ else
+ {
+ /* Hmpf. Stupid sparc assembler always interprets global
variable
+ names as GOT offsets, so we have to do it the long way
... */
+ fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n"
);
+ fprintf( outfile, " \"0:\\tcall 1f\\n\\tnop\\n\"\n"
);
+ fprintf( outfile, " \"1:\\tsethi %%hi(%s+%d-0b),
%%g1\\n\"\n", table, pos );
+ fprintf( outfile, " \"\\tor %%g1, %%lo(%s+%d-0b),
%%g1\\n\"\n", table, pos );
+ fprintf( outfile, " \"\\tld [%%g1+%%o7], %%g1\\n\"\n"
);
+ fprintf( outfile, " \"\\tjmp
%%g1\\n\\trestore\\n\"\n"
);
+ }
+ break;
+ case CPU_ALPHA:
+ fprintf( outfile, " \"\\tlda $0,%s\\n\"\n", table );
+ fprintf( outfile, " \"\\tlda $0,%d($0)\\n\"\n", pos);
+ fprintf( outfile, " \"\\tjmp $31,($0)\\n\"\n" );
+ break;
+ case CPU_POWERPC:
+ fprintf(outfile, " \"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg(1), ppc_reg(1));
+ fprintf(outfile, " \"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg(9), ppc_reg(1));
+ fprintf(outfile, " \"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg(1), ppc_reg(1));
+ fprintf(outfile, " \"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg(8), ppc_reg(1));
+ fprintf(outfile, " \"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg(1), ppc_reg(1));
+ fprintf(outfile, " \"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg(7), ppc_reg(1));
+ if (target_platform == PLATFORM_APPLE)
+ {
+ fprintf(outfile, " \"\\tlis %s, ha16(%s+%d)\\n\"\n",
+ ppc_reg(9), asm_name(table), pos);
+ fprintf(outfile, " \"\\tla %s,
lo16(%s+%d)(%s)\\n\"\n",
+ ppc_reg(8), asm_name(table), pos, ppc_reg(9));
+ }
+ else
+ {
+ fprintf(outfile, " \"\\tlis %s, (%s+%d)@hi\\n\"\n",
+ ppc_reg(9), asm_name(table), pos);
+ fprintf(outfile, " \"\\tla %s,
(%s+%d)@l(%s)\\n\"\n",
+ ppc_reg(8), asm_name(table), pos, ppc_reg(9));
+ }
+ fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg(7),
ppc_reg(8));
+ fprintf(outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg(7));
+ fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg(7), ppc_reg(1));
+ fprintf(outfile, " \"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg(1), ppc_reg(1));
+ fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg(8), ppc_reg(1));
+ fprintf(outfile, " \"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg(1), ppc_reg(1));
+ fprintf(outfile, " \"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg(9), ppc_reg(1));
+ fprintf(outfile, " \"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg(1), ppc_reg(1));
+ fprintf(outfile, " \"\\tbctr\\n\"\n");
+ break;
+ }
+ output_function_size( outfile, name );
+}
+
/* output the import table of a Win32 module */
static int output_immediate_imports( FILE *outfile )
{
- int i, j, pos;
- int nb_imm = nb_imports - nb_delayed;
- static const char import_thunks[] = "__wine_spec_import_thunks";
+ int i, j, nb_imm = nb_imports - nb_delayed;
- if (!nb_imm) goto done;
+ if (!nb_imm) return 0;
/* main import header */
@@ -753,13 +853,23 @@
}
fprintf( outfile, " }\n};\n\n" );
- /* thunks for imported functions */
+ return nb_imm;
+}
- fprintf( outfile, "#ifndef __GNUC__\nstatic void
__asm__dummy_import(void) {\n#endif\n\n" );
+/* output the import thunks of a Win32 module */
+static void output_immediate_import_thunks( FILE *outfile )
+{
+ int i, j, pos;
+ int nb_imm = nb_imports - nb_delayed;
+ static const char import_thunks[] = "__wine_spec_import_thunks";
+
+ if (!nb_imm) return;
+
pos = (sizeof(void *) + 2*sizeof(unsigned int) + sizeof(const char
*) + sizeof(void *)) *
(nb_imm + 1); /* offset of imports.data from start of
imports */
+ fprintf( outfile, "/* immediate import thunks */\n" );
fprintf( outfile, "asm(\".text\\n\\t.align %d\\n\"\n",
get_alignment(8) );
- fprintf( outfile, " \"" __ASM_NAME("%s")
":\\n\"\n",
import_thunks);
+ fprintf( outfile, " \"%s:\\n\"\n", asm_name(import_thunks));
for (i = 0; i < nb_imports; i++)
{
@@ -767,84 +877,21 @@
for (j = 0; j < dll_imports[i]->nb_imports; j++, pos +=
sizeof(const char *))
{
ORDDEF *odp = dll_imports[i]->imports[j];
- const char *name = odp->name ? odp->name :
odp->export_name;
- fprintf( outfile, " \"\\t" __ASM_FUNC("%s")
"\\n\"\n",
name );
- fprintf( outfile, " \"\\t.globl "
__ASM_NAME("%s")
"\\n\"\n", name );
- fprintf( outfile, " \"" __ASM_NAME("%s")
":\\n\\t",
name);
-
-#ifndef __REACTOS__
-#if defined(__i386__)
- if (strstr( name, "__wine_call_from_16" ))
- fprintf( outfile, ".byte 0x2e\\n\\tjmp
*(imports+%d)\\n\\tnop\\n", pos );
- else
- fprintf( outfile, "jmp *(imports+%d)\\n\\tmovl
%%esi,%%esi\\n", pos );
-#elif defined(__sparc__)
- if ( !UsePIC )
- {
- fprintf( outfile, "sethi %%hi(imports+%d), %%g1\\n\\t",
pos );
- fprintf( outfile, "ld [%%g1+%%lo(imports+%d)],
%%g1\\n\\t", pos );
- fprintf( outfile, "jmp %%g1\\n\\tnop\\n" );
- }
- else
- {
- /* Hmpf. Stupid sparc assembler always interprets
global variable
- names as GOT offsets, so we have to do it the long
way ... */
- fprintf( outfile, "save %%sp, -96, %%sp\\n" );
- fprintf( outfile, "0:\\tcall 1f\\n\\tnop\\n" );
- fprintf( outfile, "1:\\tsethi %%hi(imports+%d-0b),
%%g1\\n\\t", pos );
- fprintf( outfile, "or %%g1, %%lo(imports+%d-0b),
%%g1\\n\\t", pos );
- fprintf( outfile, "ld [%%g1+%%o7], %%g1\\n\\t" );
- fprintf( outfile, "jmp %%g1\\n\\trestore\\n" );
- }
-
-#elif defined(__powerpc__)
- fprintf(outfile, "\taddi %s, %s, -0x4\\n\"\n", ppc_reg[1],
ppc_reg[1]);
- fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[9], ppc_reg[1]);
- fprintf(outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[8], ppc_reg[1]);
- fprintf(outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf(outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[7], ppc_reg[1]);
-
- fprintf(outfile, "\t\"\\tlis %s, "
ppc_high(__ASM_NAME("imports") "+ %d") "\\n\"\n",
ppc_reg[9], pos);
- fprintf(outfile, "\t\"\\tla %s, " ppc_low
(__ASM_NAME("imports") "+ %d") "(%s)\\n\"\n",
ppc_reg[8], pos,
ppc_reg[9]);
- fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[7], ppc_reg[8]);
- fprintf(outfile, "\t\"\\tmtctr %s\\n\"\n", ppc_reg[7]);
-
- fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[7], ppc_reg[1]);
- fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[8], ppc_reg[1]);
- fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf(outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[9], ppc_reg[1]);
- fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf(outfile, "\t\"\\tbctr\\n");
-#elif defined(__ALPHA__)
- fprintf( outfile, "\tlda $0,imports\\n\"\n" );
- fprintf( outfile, "\t\"\\tlda $0,%d($0)\\n\"\n", pos);
- fprintf( outfile, "\t\"\\tjmp $31,($0)\\n" );
-#else
-#error You need to define import thunks for your architecture!
-#endif
-#endif /*__REACTOS__*/
- fprintf( outfile, "\"\n" );
- output_function_size( outfile, name );
+ output_import_thunk( outfile, odp->name ? odp->name :
odp->export_name,
+ "imports", pos );
}
pos += 4;
}
output_function_size( outfile, import_thunks );
- fprintf( outfile, " \".text\");\n#ifndef
__GNUC__\n}\n#endif\n\n" );
-
- done:
- return nb_imm;
+ fprintf( outfile, ");\n" );
}
/* output the delayed import table of a Win32 module */
static int output_delayed_imports( FILE *outfile, const DLLSPEC *spec )
{
- int i, idx, j, pos;
- static const char delayed_import_loaders[] =
"__wine_spec_delayed_import_loaders";
- static const char delayed_import_thunks[] =
"__wine_spec_delayed_import_thunks";
+ int i, j;
- if (!nb_delayed) goto done;
+ if (!nb_delayed) return 0;
fprintf( outfile, "static void *__wine_delay_imp_hmod[%d];\n",
nb_delayed );
for (i = 0; i < nb_imports; i++)
@@ -932,83 +979,93 @@
fprintf( outfile, " RaiseException( 0x%08x, %d, 2, args );\n",
EXCEPTION_WINE_STUB, EXCEPTION_NONCONTINUABLE );
fprintf( outfile, " return 0;\n" );
- fprintf( outfile, " }\n}\n\n" );
+ fprintf( outfile, " }\n}\n" );
- fprintf( outfile, "#ifndef __GNUC__\n" );
- fprintf( outfile, "static void __asm__dummy_delay_import(void) {\n"
);
- fprintf( outfile, "#endif\n" );
+ return nb_delayed;
+}
- fprintf( outfile, "asm(\".align %d\\n\"\n", get_alignment(8) );
- fprintf( outfile, " \"" __ASM_NAME("%s")
":\\n\"\n",
delayed_import_loaders);
- fprintf( outfile, " \"\\t"
__ASM_FUNC("__wine_delay_load_asm")
"\\n\"\n" );
- fprintf( outfile, " \""
__ASM_NAME("__wine_delay_load_asm")
":\\n\"\n" );
-#if defined(__i386__)
- fprintf( outfile, " \"\\tpushl %%ecx\\n\\tpushl %%edx\\n\\tpushl
%%eax\\n\"\n" );
- fprintf( outfile, " \"\\tcall __wine_delay_load\\n\"\n" );
- fprintf( outfile, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp
*%%eax\\n\"\n" );
-#elif defined(__sparc__)
- fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
- fprintf( outfile, " \"\\tcall __wine_delay_load\\n\"\n" );
- fprintf( outfile, " \"\\tmov %%g1, %%o0\\n\"\n" );
- fprintf( outfile, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
-#elif defined(__powerpc__)
-# if defined(__APPLE__)
-/* On darwin an extra 56 bytes must be allowed for the linkage
area+param area */
-# define extra_stack_storage 56
-# else
-# define extra_stack_storage 0
-# endif
- /* Save all callee saved registers into a stackframe. */
- fprintf( outfile, " \"\\tstwu %s, -%d(%s)\\n\"\n",ppc_reg[1],
48+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[3],
4+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[4],
8+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[5],
12+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[6],
16+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[7],
20+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[8],
24+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[9],
28+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg[10],32+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg[11],36+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg[12],40+extra_stack_storage, ppc_reg[1]);
+/* output the delayed import thunks of a Win32 module */
+static void output_delayed_import_thunks( FILE *outfile, const DLLSPEC
*spec )
+{
+ int i, idx, j, pos, extra_stack_storage = 0;
+ static const char delayed_import_loaders[] =
"__wine_spec_delayed_import_loaders";
+ static const char delayed_import_thunks[] =
"__wine_spec_delayed_import_thunks";
- /* r0 -> r3 (arg1) */
- fprintf( outfile, " \"\\tmr %s, %s\\n\"\n", ppc_reg[3],
ppc_reg[0]);
+ if (!nb_delayed) return;
- /* save return address */
- fprintf( outfile, " \"\\tmflr %s\\n\"\n", ppc_reg[0]);
- fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n", ppc_reg[0],
44+extra_stack_storage, ppc_reg[1]);
+ fprintf( outfile, "/* delayed import thunks */\n" );
+ fprintf( outfile, "asm(\".text\\n\"\n" );
+ fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(8)
);
+ fprintf( outfile, " \"%s:\\n\"\n",
asm_name(delayed_import_loaders));
+ fprintf( outfile, " \"\\t%s\\n\"\n",
func_declaration("__wine_delay_load_asm") );
+ fprintf( outfile, " \"%s:\\n\"\n",
asm_name("__wine_delay_load_asm") );
+ switch(target_cpu)
+ {
+ case CPU_x86:
+ fprintf( outfile, " \"\\tpushl %%ecx\\n\\tpushl
%%edx\\n\\tpushl %%eax\\n\"\n" );
+ fprintf( outfile, " \"\\tcall %s\\n\"\n",
asm_name("__wine_delay_load") );
+ fprintf( outfile, " \"\\tpopl %%edx\\n\\tpopl %%ecx\\n\\tjmp
*%%eax\\n\"\n" );
+ break;
+ case CPU_SPARC:
+ fprintf( outfile, " \"\\tsave %%sp, -96, %%sp\\n\"\n" );
+ fprintf( outfile, " \"\\tcall %s\\n\"\n",
asm_name("__wine_delay_load") );
+ fprintf( outfile, " \"\\tmov %%g1, %%o0\\n\"\n" );
+ fprintf( outfile, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
+ break;
+ case CPU_ALPHA:
+ fprintf( outfile, " \"\\tjsr $26,%s\\n\"\n",
asm_name("__wine_delay_load") );
+ fprintf( outfile, " \"\\tjmp $31,($0)\\n\"\n" );
+ break;
+ case CPU_POWERPC:
+ if (target_platform == PLATFORM_APPLE) extra_stack_storage =
56;
- /* Call the __wine_delay_load function, arg1 is arg1. */
- fprintf( outfile, " \"\\tbl "
__ASM_NAME("__wine_delay_load")
"\\n\"\n");
+ /* Save all callee saved registers into a stackframe. */
+ fprintf( outfile, " \"\\tstwu %s,
-%d(%s)\\n\"\n",ppc_reg(1), 48+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
- /* Load return value from call into ctr register */
- fprintf( outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg[3]);
+ /* r0 -> r3 (arg1) */
+ fprintf( outfile, " \"\\tmr %s, %s\\n\"\n", ppc_reg(3),
ppc_reg(0));
- /* restore all saved registers and drop stackframe. */
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[3],
4+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[4],
8+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[5],
12+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[6],
16+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[7],
20+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[8],
24+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n", ppc_reg[9],
28+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg[10],32+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg[11],36+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg[12],40+extra_stack_storage, ppc_reg[1]);
+ /* save return address */
+ fprintf( outfile, " \"\\tmflr %s\\n\"\n", ppc_reg(0));
+ fprintf( outfile, " \"\\tstw %s, %d(%s)\\n\"\n",
ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
- /* Load return value from call into return register */
- fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg[0],
44+extra_stack_storage, ppc_reg[1]);
- fprintf( outfile, " \"\\tmtlr %s\\n\"\n", ppc_reg[0]);
- fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n", ppc_reg[1],
ppc_reg[1], 48+extra_stack_storage);
+ /* Call the __wine_delay_load function, arg1 is arg1. */
+ fprintf( outfile, " \"\\tbl %s\\n\"\n",
asm_name("__wine_delay_load") );
- /* branch to ctr register. */
- fprintf( outfile, " \"bctr\\n\"\n");
-#elif defined(__ALPHA__)
- fprintf( outfile, " \"\\tjsr $26,__wine_delay_load\\n\"\n" );
- fprintf( outfile, " \"\\tjmp $31,($0)\\n\"\n" );
-#else
-#error You need to defined delayed import thunks for your architecture!
-#endif
+ /* Load return value from call into ctr register */
+ fprintf( outfile, " \"\\tmtctr %s\\n\"\n", ppc_reg(3));
+
+ /* restore all saved registers and drop stackframe. */
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(3), 4+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(4), 8+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(5), 12+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(6), 16+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(7), 20+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(8), 24+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(9), 28+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(10),32+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(11),36+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(12),40+extra_stack_storage, ppc_reg(1));
+
+ /* Load return value from call into return register */
+ fprintf( outfile, " \"\\tlwz %s, %d(%s)\\n\"\n",
ppc_reg(0), 44+extra_stack_storage, ppc_reg(1));
+ fprintf( outfile, " \"\\tmtlr %s\\n\"\n", ppc_reg(0));
+ fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n",
ppc_reg(1), ppc_reg(1), 48+extra_stack_storage);
+
+ /* branch to ctr register. */
+ fprintf( outfile, " \"bctr\\n\"\n");
+ break;
+ }
output_function_size( outfile, "__wine_delay_load_asm" );
for (i = idx = 0; i < nb_imports; i++)
@@ -1021,43 +1078,51 @@
const char *name = odp->name ? odp->name :
odp->export_name;
sprintf( buffer, "__wine_delay_imp_%d_%s", i, name );
- fprintf( outfile, " \"\\t" __ASM_FUNC("%s")
"\\n\"\n",
buffer );
- fprintf( outfile, " \"" __ASM_NAME("%s")
":\\n\"\n",
buffer );
-#if defined(__i386__)
- fprintf( outfile, " \"\\tmovl $%d, %%eax\\n\"\n",
(idx
<< 16) | j );
- fprintf( outfile, " \"\\tjmp
__wine_delay_load_asm\\n\"\n" );
-#elif defined(__sparc__)
- fprintf( outfile, " \"\\tset %d, %%g1\\n\"\n", (idx
<<
16) | j );
- fprintf( outfile, " \"\\tb,a
__wine_delay_load_asm\\n\"\n" );
-#elif defined(__powerpc__)
-#ifdef __APPLE__
- /* On Darwin we can use r0 and r2 */
- /* Upper part in r2 */
- fprintf( outfile, " \"\\tlis %s, %d\\n\"\n",
ppc_reg[2],
idx);
- /* Lower part + r2 -> r0, Note we can't use r0 directly */
- fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n",
ppc_reg[0], ppc_reg[2], j);
- fprintf( outfile, " \"\\tb "
__ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
-#else /* __APPLE__ */
- /* On linux we can't use r2 since r2 is not a scratch
register (hold the TOC) */
- /* Save r13 on the stack */
- fprintf( outfile, " \"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, " \"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[13], ppc_reg[1]);
- /* Upper part in r13 */
- fprintf( outfile, " \"\\tlis %s, %d\\n\"\n",
ppc_reg[13], idx);
- /* Lower part + r13 -> r0, Note we can't use r0 directly */
- fprintf( outfile, " \"\\taddi %s, %s, %d\\n\"\n",
ppc_reg[0], ppc_reg[13], j);
- /* Restore r13 */
- fprintf( outfile, " \"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[13], ppc_reg[1]);
- fprintf( outfile, " \"\\taddic %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, " \"\\tb "
__ASM_NAME("__wine_delay_load_asm") "\\n\"\n");
-#endif /* __APPLE__ */
-#elif defined(__ALPHA__)
- fprintf( outfile, " \"\\tlda $0,%d($31)\\n\"\n", j);
- fprintf( outfile, " \"\\tldah $0,%d($0)\\n\"\n",
idx);
- fprintf( outfile, " \"\\tjmp
$31,__wine_delay_load_asm\\n\"\n" );
-#else
-#error You need to defined delayed import thunks for your architecture!
-#endif
+ fprintf( outfile, " \"\\t%s\\n\"\n",
func_declaration(buffer) );
+ fprintf( outfile, " \"%s:\\n\"\n", asm_name(buffer)
);
+ switch(target_cpu)
+ {
+ case CPU_x86:
+ fprintf( outfile, " \"\\tmovl $%d, %%eax\\n\"\n",
(idx << 16) | j );
+ fprintf( outfile, " \"\\tjmp %s\\n\"\n",
asm_name("__wine_delay_load_asm") );
+ break;
+ case CPU_SPARC:
+ fprintf( outfile, " \"\\tset %d, %%g1\\n\"\n",
(idx
<< 16) | j );
+ fprintf( outfile, " \"\\tb,a %s\\n\"\n",
asm_name("__wine_delay_load_asm") );
+ break;
+ case CPU_ALPHA:
+ fprintf( outfile, " \"\\tlda $0,%d($31)\\n\"\n",
j);
+ fprintf( outfile, " \"\\tldah $0,%d($0)\\n\"\n",
idx);
+ fprintf( outfile, " \"\\tjmp $31,%s\\n\"\n",
asm_name("__wine_delay_load_asm") );
+ break;
+ case CPU_POWERPC:
+ switch(target_platform)
+ {
+ case PLATFORM_APPLE:
+ /* On Darwin we can use r0 and r2 */
+ /* Upper part in r2 */
+ fprintf( outfile, " \"\\tlis %s, %d\\n\"\n",
ppc_reg(2), idx);
+ /* Lower part + r2 -> r0, Note we can't use r0
directly */
+ fprintf( outfile, " \"\\taddi %s, %s,
%d\\n\"\n", ppc_reg(0), ppc_reg(2), j);
+ fprintf( outfile, " \"\\tb %s\\n\"\n",
asm_name("__wine_delay_load_asm") );
+ break;
+ default:
+ /* On linux we can't use r2 since r2 is not a
scratch register (hold the TOC) */
+ /* Save r13 on the stack */
+ fprintf( outfile, " \"\\taddi %s, %s,
-0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
+ fprintf( outfile, " \"\\tstw %s,
0(%s)\\n\"\n",
ppc_reg(13), ppc_reg(1));
+ /* Upper part in r13 */
+ fprintf( outfile, " \"\\tlis %s, %d\\n\"\n",
ppc_reg(13), idx);
+ /* Lower part + r13 -> r0, Note we can't use r0
directly */
+ fprintf( outfile, " \"\\taddi %s, %s,
%d\\n\"\n", ppc_reg(0), ppc_reg(13), j);
+ /* Restore r13 */
+ fprintf( outfile, " \"\\tstw %s,
0(%s)\\n\"\n",
ppc_reg(13), ppc_reg(1));
+ fprintf( outfile, " \"\\taddic %s, %s,
0x4\\n\"\n", ppc_reg(1), ppc_reg(1));
+ fprintf( outfile, " \"\\tb %s\\n\"\n",
asm_name("__wine_delay_load_asm") );
+ break;
+ }
+ break;
+ }
output_function_size( outfile, name );
}
idx++;
@@ -1065,7 +1130,7 @@
output_function_size( outfile, delayed_import_loaders );
fprintf( outfile, "\n \".align %d\\n\"\n", get_alignment(8)
);
- fprintf( outfile, " \"" __ASM_NAME("%s")
":\\n\"\n",
delayed_import_thunks);
+ fprintf( outfile, " \"%s:\\n\"\n",
asm_name(delayed_import_thunks));
pos = nb_delayed * 32;
for (i = 0; i < nb_imports; i++)
{
@@ -1073,75 +1138,12 @@
for (j = 0; j < dll_imports[i]->nb_imports; j++, pos += 4)
{
ORDDEF *odp = dll_imports[i]->imports[j];
- const char *name = odp->name ? odp->name :
odp->export_name;
-
- fprintf( outfile, " \"\\t" __ASM_FUNC("%s")
"\\n\"\n",
name );
- fprintf( outfile, " \"\\t.globl "
__ASM_NAME("%s")
"\\n\"\n", name );
- fprintf( outfile, " \"" __ASM_NAME("%s")
":\\n\\t\"",
name );
-#if defined(__i386__)
- if (strstr( name, "__wine_call_from_16" ))
- fprintf( outfile, "\".byte 0x2e\\n\\tjmp
*(delay_imports+%d)\\n\\tnop\\n\"", pos );
- else
- fprintf( outfile, "\"jmp *(delay_imports+%d)\\n\\tmovl
%%esi,%%esi\\n\"", pos );
-#elif defined(__sparc__)
- if ( !UsePIC )
- {
- fprintf( outfile, "\"sethi %%hi(delay_imports+%d),
%%g1\\n\\t\"", pos );
- fprintf( outfile, "\"ld [%%g1+%%lo(delay_imports+%d)],
%%g1\\n\\t\"", pos );
- fprintf( outfile, "\"jmp %%g1\\n\\tnop\\n\"" );
- }
- else
- {
- /* Hmpf. Stupid sparc assembler always interprets
global variable
- names as GOT offsets, so we have to do it the long
way ... */
- fprintf( outfile, "\"save %%sp, -96, %%sp\\n\"" );
- fprintf( outfile, "\"0:\\tcall 1f\\n\\tnop\\n\"" );
- fprintf( outfile, "\"1:\\tsethi
%%hi(delay_imports+%d-0b), %%g1\\n\\t\"", pos );
- fprintf( outfile, "\"or %%g1,
%%lo(delay_imports+%d-0b), %%g1\\n\\t\"", pos );
- fprintf( outfile, "\"ld [%%g1+%%o7], %%g1\\n\\t\""
);
- fprintf( outfile, "\"jmp %%g1\\n\\trestore\\n\"" );
- }
-
-#elif defined(__powerpc__)
- fprintf( outfile, "\t\"addi %s, %s, -0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[9], ppc_reg[1]);
- fprintf( outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[8], ppc_reg[1]);
- fprintf( outfile, "\t\"\\taddi %s, %s, -0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, "\t\"\\tstw %s, 0(%s)\\n\"\n",
ppc_reg[7], ppc_reg[1]);
-
- fprintf( outfile, "\t\"\\tlis %s, "
ppc_high(__ASM_NAME("delay_imports") "+ %d") "\\n\"\n",
ppc_reg[9],
pos);
- fprintf( outfile, "\t\"\\tla %s, " ppc_low
(__ASM_NAME("delay_imports") "+ %d") "(%s)\\n\"\n",
ppc_reg[8], pos,
ppc_reg[9]);
- fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[7], ppc_reg[8]);
- fprintf( outfile, "\t\"\\tmtctr %s\\n\"\n", ppc_reg[7]);
-
- fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[7], ppc_reg[1]);
- fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[8], ppc_reg[1]);
- fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, "\t\"\\tlwz %s, 0(%s)\\n\"\n",
ppc_reg[9], ppc_reg[1]);
- fprintf( outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n",
ppc_reg[1], ppc_reg[1]);
- fprintf( outfile, "\t\"\\tbctr\\n\"");
-#elif defined(__ALPHA__)
- fprintf( outfile, "\t\"lda $0,delay_imports\\n\"\n" );
- fprintf( outfile, "\t\"\\tlda $0,%d($0)\\n\"\n", pos);
- fprintf( outfile, "\t\"\\tjmp $31,($0)\\n\"" );
-#else
-#error You need to define delayed import thunks for your architecture!
-#endif
- fprintf( outfile, "\n" );
- output_function_size( outfile, name );
+ output_import_thunk( outfile, odp->name ? odp->name :
odp->export_name,
+ "delay_imports", pos );
}
}
output_function_size( outfile, delayed_import_thunks );
fprintf( outfile, ");\n" );
- fprintf( outfile, "#ifndef __GNUC__\n" );
- fprintf( outfile, "}\n" );
- fprintf( outfile, "#endif\n" );
- fprintf( outfile, "\n" );
-
- done:
- return nb_delayed;
}
/* output the import and delayed import tables of a Win32 module
@@ -1152,3 +1154,10 @@
*nb_delayed = output_delayed_imports( outfile, spec );
return output_immediate_imports( outfile );
}
+
+/* output the import and delayed import thunks of a Win32 module */
+void output_import_thunks( FILE *outfile, DLLSPEC *spec )
+{
+ output_delayed_import_thunks( outfile, spec );
+ output_immediate_import_thunks( outfile );
+}
_____
Modified: trunk/reactos/tools/winebuild/main.c
--- trunk/reactos/tools/winebuild/main.c 2005-07-05 21:03:46 UTC
(rev 16437)
+++ trunk/reactos/tools/winebuild/main.c 2005-07-05 21:17:01 UTC
(rev 16438)
@@ -44,14 +44,30 @@
int nb_errors = 0;
int display_warnings = 0;
int kill_at = 0;
+int debugging = 0;
-/* we only support relay debugging on i386 */
#ifdef __i386__
-int debugging = 1;
+enum target_cpu target_cpu = CPU_x86;
+#elif defined(__sparc__)
+enum target_cpu target_cpu = CPU_SPARC;
+#elif defined(__ALPHA__)
+enum target_cpu target_cpu = CPU_ALPHA;
+#elif defined(__powerpc__)
+enum target_cpu target_cpu = CPU_POWERPC;
#else
-int debugging = 0;
+#error Unsupported CPU
#endif
+#ifdef __APPLE__
+enum target_platform target_platform = PLATFORM_APPLE;
+#elif defined(__svr4__)
+enum target_platform target_platform = PLATFORM_SVR4;
+#elif defined(_WINDOWS)
+enum target_platform target_platform = PLATFORM_WINDOWS;
+#else
+enum target_platform target_platform = PLATFORM_UNSPECIFIED;
+#endif
+
char **debug_channels = NULL;
char **lib_path = NULL;
@@ -454,6 +470,9 @@
output_file = stdout;
argv = parse_options( argc, argv, spec );
+ /* we only support relay debugging on i386 */
+ debugging = (target_cpu == CPU_x86);
+
switch(exec_mode)
{
case MODE_DLL:
_____
Modified: trunk/reactos/tools/winebuild/parser.c
--- trunk/reactos/tools/winebuild/parser.c 2005-07-05 21:03:46 UTC
(rev 16437)
+++ trunk/reactos/tools/winebuild/parser.c 2005-07-05 21:17:01 UTC
(rev 16438)
@@ -485,14 +485,12 @@
assert( 0 );
}
-#ifndef __i386__
- if (odp->flags & FLAG_I386)
+ if ((target_cpu != CPU_x86) && (odp->flags & FLAG_I386))
{
/* ignore this entry point on non-Intel archs */
spec->nb_entry_points--;
return 1;
}
-#endif
if (ordinal != -1)
{
@@ -627,17 +625,17 @@
}
/* now assign ordinals to the rest */
- for (i = 0, ordinal = spec->base; i < spec->nb_names; i++)
+ for (i = 0, ordinal = spec->base; i < spec->nb_entry_points; i++)
{
- if (spec->names[i]->ordinal != -1) continue; /* already has an
ordinal */
+ if (spec->entry_points[i].ordinal != -1) continue;
while (spec->ordinals[ordinal]) ordinal++;
if (ordinal >= MAX_ORDINALS)
{
- current_line = spec->names[i]->lineno;
+ current_line = spec->entry_points[i].lineno;
fatal_error( "Too many functions defined (max %d)\n",
MAX_ORDINALS );
}
- spec->names[i]->ordinal = ordinal;
- spec->ordinals[ordinal] = spec->names[i];
+ spec->entry_points[i].ordinal = ordinal;
+ spec->ordinals[ordinal] = &spec->entry_points[i];
}
if (ordinal > spec->limit) spec->limit = ordinal;
}
_____
Modified: trunk/reactos/tools/winebuild/relay.c
--- trunk/reactos/tools/winebuild/relay.c 2005-07-05 21:03:46 UTC
(rev 16437)
+++ trunk/reactos/tools/winebuild/relay.c 2005-07-05 21:17:01 UTC
(rev 16438)
@@ -31,22 +31,26 @@
#include "build.h"
-#ifdef __i386__
-
static void function_header( FILE *outfile, const char *name )
{
fprintf( outfile, "\n\t.align %d\n", get_alignment(4) );
- fprintf( outfile, "\t" __ASM_FUNC("%s") "\n", name );
- fprintf( outfile, "\t.globl " __ASM_NAME("%s") "\n",
name );
- fprintf( outfile, __ASM_NAME("%s") ":\n", name );
+ fprintf( outfile, "\t%s\n", func_declaration(name) );
+ fprintf( outfile, "\t.globl %s\n", asm_name(name) );
+ fprintf( outfile, "%s:\n", asm_name(name) );
}
static void function_footer( FILE *outfile, const char *name )
{
- fprintf( outfile, ".size " __ASM_NAME("%s") ", . - "
__ASM_NAME("%s") "\n", name, name );
+ const char *size = func_size( name );
+ if (size[0]) fprintf( outfile, "\t%s\n", size );
}
+static inline const char *data16_prefix(void)
+{
+ return (target_platform == PLATFORM_SVR4) ? "\tdata16\n" : "";
+}
+
/*******************************************************************
* BuildCallFrom16Core
*
@@ -147,37 +151,31 @@
if (UsePIC)
{
- fprintf( outfile, "\t.byte 0x2e\n\tmovl "
__ASM_NAME("CallTo16_DataSelector@GOT") "(%%ecx), %%edx\n" );
+ fprintf( outfile, "\t.byte 0x2e\n\tmovl %s(%%ecx), %%edx\n",
asm_name("CallTo16_DataSelector@GOT") );
fprintf( outfile, "\t.byte 0x2e\n\tmovl (%%edx), %%edx\n" );
}
else
- fprintf( outfile, "\t.byte 0x2e\n\tmovl "
__ASM_NAME("CallTo16_DataSelector") ",%%edx\n" );
+ fprintf( outfile, "\t.byte 0x2e\n\tmovl %s,%%edx\n",
asm_name("CallTo16_DataSelector") );
/* Load 32-bit segment registers */
-#ifdef __svr4__
- fprintf( outfile, "\tdata16\n");
-#endif
- fprintf( outfile, "\tmovw %%dx, %%ds\n" );
-#ifdef __svr4__
- fprintf( outfile, "\tdata16\n");
-#endif
- fprintf( outfile, "\tmovw %%dx, %%es\n" );
+ fprintf( outfile, "%s\tmovw %%dx, %%ds\n", data16_prefix() );
+ fprintf( outfile, "%s\tmovw %%dx, %%es\n", data16_prefix() );
if ( UsePIC )
{
- fprintf( outfile, "\tmovl "
__ASM_NAME("CallTo16_TebSelector@GOT") "(%%ecx), %%edx\n" );
+ fprintf( outfile, "\tmovl %s(%%ecx), %%edx\n",
asm_name("CallTo16_TebSelector@GOT") );
fprintf( outfile, "\tmovw (%%edx), %%fs\n" );
}
else
- fprintf( outfile, "\tmovw "
__ASM_NAME("CallTo16_TebSelector")
", %%fs\n" );
+ fprintf( outfile, "\tmovw %s, %%fs\n",
asm_name("CallTo16_TebSelector") );
fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n",
STRUCTOFFSET(TEB,gs_sel) );
/* Get address of wine_ldt_copy array into %ecx */
if ( UsePIC )
- fprintf( outfile, "\tmovl " __ASM_NAME("wine_ldt_copy@GOT")
"(%%ecx), %%ecx\n" );
+ fprintf( outfile, "\tmovl %s(%%ecx), %%ecx\n",
asm_name("wine_ldt_copy@GOT") );
else
- fprintf( outfile, "\tmovl $" __ASM_NAME("wine_ldt_copy")
",
%%ecx\n" );
+ fprintf( outfile, "\tmovl $%s, %%ecx\n",
asm_name("wine_ldt_copy") );
/* Translate STACK16FRAME base to flat offset in %edx */
fprintf( outfile, "\tmovw %%ss, %%dx\n" );
@@ -195,10 +193,7 @@
fprintf( outfile, "\tpushl %%ebp\n" );
/* Switch stacks */
-#ifdef __svr4__
- fprintf( outfile,"\tdata16\n");
-#endif
- fprintf( outfile, "\t.byte 0x64\n\tmovw %%ss, (%d)\n", STACKOFFSET
+ 2 );
+ fprintf( outfile, "%s\t.byte 0x64\n\tmovw %%ss, (%d)\n",
data16_prefix(), STACKOFFSET + 2 );
fprintf( outfile, "\t.byte 0x64\n\tmovw %%sp, (%d)\n", STACKOFFSET
);
fprintf( outfile, "\tpushl %%ds\n" );
fprintf( outfile, "\tpopl %%ss\n" );
@@ -320,9 +315,9 @@
fprintf( outfile, "\tpushl $0\n" );
if ( UsePIC )
- fprintf( outfile, "\tcall "
__ASM_NAME("RELAY_DebugCallFrom16@PLT") "\n ");
+ fprintf( outfile, "\tcall %s\n ",
asm_name("RELAY_DebugCallFrom16@PLT"));
else
- fprintf( outfile, "\tcall "
__ASM_NAME("RELAY_DebugCallFrom16") "\n ");
+ fprintf( outfile, "\tcall %s\n ",
asm_name("RELAY_DebugCallFrom16"));
fprintf( outfile, "\tpopl %%edx\n" );
fprintf( outfile, "\tpopl %%edx\n" );
@@ -359,9 +354,9 @@
fprintf( outfile, "\tpushl $0\n" );
if ( UsePIC )
- fprintf( outfile, "\tcall "
__ASM_NAME("RELAY_DebugCallFrom16Ret@PLT") "\n ");
+ fprintf( outfile, "\tcall %s\n ",
asm_name("RELAY_DebugCallFrom16Ret@PLT"));
else
- fprintf( outfile, "\tcall "
__ASM_NAME("RELAY_DebugCallFrom16Ret") "\n ");
+ fprintf( outfile, "\tcall %s\n ",
asm_name("RELAY_DebugCallFrom16Ret"));
fprintf( outfile, "\tpopl %%eax\n" );
fprintf( outfile, "\tpopl %%eax\n" );
@@ -545,10 +540,7 @@
/* Switch to the 16-bit stack */
fprintf( outfile, "\tmovl %%esp,%%edx\n" );
-#ifdef __svr4__
- fprintf( outfile,"\tdata16\n");
-#endif
- fprintf( outfile, "\t.byte 0x64\n\tmovw (%d),%%ss\n", STACKOFFSET +
2);
+ fprintf( outfile, "%s\t.byte 0x64\n\tmovw (%d),%%ss\n",
data16_prefix(), STACKOFFSET + 2);
fprintf( outfile, "\t.byte 0x64\n\tmovw (%d),%%sp\n", STACKOFFSET
);
fprintf( outfile, "\t.byte 0x64\n\tmovl %%edx,(%d)\n", STACKOFFSET
);
@@ -625,26 +617,19 @@
/* Restore 32-bit segment registers */
- fprintf( outfile, "\t.byte 0x2e\n\tmovl "
__ASM_NAME("CallTo16_DataSelector") "-"
__ASM_NAME("Call16_Ret_Start")
",%%edi\n" );
-#ifdef __svr4__
- fprintf( outfile, "\tdata16\n");
-#endif
- fprintf( outfile, "\tmovw %%di,%%ds\n" );
-#ifdef __svr4__
- fprintf( outfile, "\tdata16\n");
-#endif
- fprintf( outfile, "\tmovw %%di,%%es\n" );
+ fprintf( outfile, "\t.byte 0x2e\n\tmovl %s",
asm_name("CallTo16_DataSelector") );
+ fprintf( outfile, "-%s,%%edi\n", asm_name("Call16_Ret_Start") );
+ fprintf( outfile, "%s\tmovw %%di,%%ds\n", data16_prefix() );
+ fprintf( outfile, "%s\tmovw %%di,%%es\n", data16_prefix() );
- fprintf( outfile, "\t.byte 0x2e\n\tmov "
__ASM_NAME("CallTo16_TebSelector") "-"
__ASM_NAME("Call16_Ret_Start")
",%%fs\n" );
+ fprintf( outfile, "\t.byte 0x2e\n\tmov %s",
asm_name("CallTo16_TebSelector") );
+ fprintf( outfile, "-%s,%%fs\n", asm_name("Call16_Ret_Start") );
fprintf( outfile, "\t.byte 0x64\n\tmov (%d),%%gs\n",
STRUCTOFFSET(TEB,gs_sel) );
/* Restore the 32-bit stack */
-#ifdef __svr4__
- fprintf( outfile, "\tdata16\n");
-#endif
- fprintf( outfile, "\tmovw %%di,%%ss\n" );
+ fprintf( outfile, "%s\tmovw %%di,%%ss\n", data16_prefix() );
fprintf( outfile, "\t.byte 0x64\n\tmovl (%d),%%esp\n", STACKOFFSET
);
/* Return to caller */
@@ -657,10 +642,10 @@
/* Declare the return address and data selector variables */
fprintf( outfile, "\n\t.align %d\n", get_alignment(4) );
- fprintf( outfile, "\t.globl "
__ASM_NAME("CallTo16_DataSelector")
"\n" );
- fprintf( outfile, __ASM_NAME("CallTo16_DataSelector") ":\t.long
0\n" );
- fprintf( outfile, "\t.globl " __ASM_NAME("CallTo16_TebSelector")
"\n" );
- fprintf( outfile, __ASM_NAME("CallTo16_TebSelector") ":\t.long
0\n"
);
+ fprintf( outfile, "\t.globl %s\n",
asm_name("CallTo16_DataSelector") );
+ fprintf( outfile, "%s:\t.long 0\n",
asm_name("CallTo16_DataSelector") );
+ fprintf( outfile, "\t.globl %s\n",
asm_name("CallTo16_TebSelector")
);
+ fprintf( outfile, "%s:\t.long 0\n",
asm_name("CallTo16_TebSelector") );
}
@@ -756,14 +741,14 @@
*/
static void BuildCallTo32CBClient( FILE *outfile, BOOL isEx )
{
- const char *name = isEx? "CBClientEx" : "CBClient";
+ const char *name = isEx? "CALL32_CBClientEx" :
"CALL32_CBClient";
int size = isEx? 24 : 12;
/* Function header */
fprintf( outfile, "\n\t.align %d\n", get_alignment(4) );
- fprintf( outfile, "\t.globl " __ASM_NAME("CALL32_%s")
"\n", name );
- fprintf( outfile, __ASM_NAME("CALL32_%s") ":\n", name );
+ fprintf( outfile, "\t.globl %s\n", asm_name(name) );
+ fprintf( outfile, "%s:\n", asm_name(name) );
/* Entry code */
@@ -773,6 +758,15 @@
fprintf( outfile, "\tpushl %%esi\n" );
fprintf( outfile, "\tpushl %%ebx\n" );
[truncated at 1000 lines; 1404 more skipped]