Mac OS X Support : PPC asm code fix for darwin's ld

Pierre d'Herbemont stegefin at free.fr
Sat May 3 14:49:33 CDT 2003


On Saturday, May 3, 2003, at 09:40 PM, Pierre d'Herbemont wrote:

> Hi,
> Here is an other patch which fix Mac OS X's ld way for handling 
> PowerPC assembler mnemonics.
>
> Cheers,
>
> Pierre
>
> Modified files:
> include/winnt.h, scheduler/sysdeps.c, winebuild/import.c, 
> winebuild/spec32.c
>
> ChangeLog
> Take care of Mac OS X's ld way for handling PowerPC assembler 
> mnemonics. Also move TEB to r13 on darwin.
>
>

Please use this patch instead I missed something :( and send the whole 
Mac OS X support patch. sorry.

Thanks.

-------------- next part --------------
Index: include/winnt.h
===================================================================
RCS file: /home/wine/wine/include/winnt.h,v
retrieving revision 1.157
diff -u -r1.157 winnt.h
--- include/winnt.h	10 Apr 2003 00:19:25 -0000	1.157
+++ include/winnt.h	3 May 2003 19:19:55 -0000
@@ -1632,7 +1632,11 @@
 extern inline struct _TEB * WINAPI NtCurrentTeb(void)
 {
     struct _TEB *teb;
+# ifdef __darwin__
+    __asm__("\tmr %0, r13" : "=r" (teb));
+# else
     __asm__("\tmr %0, 2" : "=r" (teb));
+# endif
     return teb;
 }
 #else

Index: scheduler/sysdeps.c
===================================================================
RCS file: /home/wine/wine/scheduler/sysdeps.c,v
retrieving revision 1.65
diff -u -r1.65 sysdeps.c
--- scheduler/sysdeps.c	13 Apr 2003 01:04:25 -0000	1.65
+++ scheduler/sysdeps.c	3 May 2003 19:26:55 -0000
@@ -89,7 +89,11 @@
     wine_ldt_init_fs( teb->teb_sel, &fs_entry );
 #elif defined(__powerpc__)
     /* On PowerPC, the current TEB is in the gpr13 register */
+# ifdef __darwin__
+    __asm__ __volatile__("mr r13, %0" : : "r" (teb));
+# else /* __darwin__ */
     __asm__ __volatile__("mr 2, %0" : : "r" (teb));
+# endif
 #elif defined(HAVE__LWP_CREATE)
     /* On non-i386 Solaris, we use the LWP private pointer */
     _lwp_setprivate( teb );
@@ -465,7 +469,11 @@
     return (struct _TEB *)_lwp_getprivate();
 }
 #elif defined(__powerpc__)
+# ifdef __darwin__
+__ASM_GLOBAL_FUNC( NtCurrentTeb, "\n\tmr r3,r13\n\tblr" );
+# else
 __ASM_GLOBAL_FUNC( NtCurrentTeb, "\n\tmr 3,2\n\tblr" );
+# endif
 #else
 # error NtCurrentTeb not defined for this architecture
 #endif  /* __i386__ */
Index: tools/winebuild/import.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/import.c,v
retrieving revision 1.49
diff -u -r1.49 import.c
--- tools/winebuild/import.c	10 Apr 2003 18:36:40 -0000	1.49
+++ tools/winebuild/import.c	3 May 2003 19:20:15 -0000
@@ -819,6 +819,28 @@
             }
 
 #elif defined(__PPC__)
+/* Darwin's ld doesn't like the same asm code as linux linker... */
+# ifdef __darwin__
+            fprintf(outfile, "\taddi r1, r1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw r9, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw r8, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw r7, 0(r1)\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlis r9,ha16(_imports+%d)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tla r8,lo16(_imports+%d)(r9)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tlwz r7, 0(r8)\\n\"\n");
+            fprintf(outfile, "\t\"\\tmtctr r7\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlwz r7, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz r8, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz r9, 0(r1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi r1, r1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tbctr\\n");
+# else /* __darwin__ */
             fprintf(outfile, "\taddi 1, 1, -0x4\\n\"\n");
             fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n");
             fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
@@ -838,6 +860,7 @@
             fprintf(outfile, "\t\"\\tlwz 9, 0(1)\\n\"\n");
             fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
             fprintf(outfile, "\t\"\\tbctr\\n");
+# endif /* __darwin__ */
 #else
 #error You need to define import thunks for your architecture!
 #endif
@@ -845,7 +868,13 @@
         }
         pos += 4;
     }
+
+/* darwin and Mach-o have a different behavior */
+#ifdef __darwin__
+    fprintf( outfile, "\".text\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
+#else
     fprintf( outfile, "\".section\\t\\\".text\\\"\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
+#endif /* __darwin__ */
 
  done:
     return nb_imm;
@@ -968,6 +997,11 @@
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_delay_import(void) {\n" );
     fprintf( outfile, "#endif\n" );
+    
+#ifdef __darwin__
+    /* darwin likes this one */
+    fprintf( outfile, " Ê Ê\"\\t.data\\n\"" );
+#endif
 
     fprintf( outfile, "asm(\".align %d\\n\"\n", get_alignment(8) );
     fprintf( outfile, "    \"\\t" __ASM_FUNC("__wine_delay_load_asm") "\\n\"\n" );
@@ -982,6 +1016,53 @@
     fprintf( outfile, "    \"\\tmov %%g1, %%o0\\n\"\n" );
     fprintf( outfile, "    \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
 #elif defined(__PPC__)
+# ifdef __darwin__
+    /* Save all callee saved registers into a stackframe. */
+    fprintf( outfile, "    \"\\tstwu r1, -48(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr3, 4(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr4, 8(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr5, 12(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr6, 16(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr7, 20(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr8, 24(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr9, 28(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr10, 32(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr11, 36(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr12, 40(r1)\\n\"\n" );
+
+    /* r0 -> r3 (arg1) */
+    fprintf( outfile, " Ê Ê\"\\tmr Êr3, r0\\n\"\n" );
+
+    /* save return address */
+    fprintf( outfile, " Ê Ê\"\\tmflr Êr0\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tstw Êr0, 44(r1)\\n\"\n" );
+
+    /* Call the __wine_delay_load function, arg1 is arg1. */
+    fprintf( outfile, " Ê Ê\"\\tbl __wine_delay_load\\n\"\n" );
+
+    /* Load return value from call into ctr register */
+    fprintf( outfile, " Ê Ê\"\\tmtctr r3\\n\"\n" );
+
+    /* restore all saved registers and drop stackframe. */
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr3, 4(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr4, 8(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr5, 12(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr6, 16(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr7, 20(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr8, 24(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr9, 28(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr10, 32(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr11, 36(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr12, 40(r1)\\n\"\n" );
+
+    /* Load return value from call into return register */
+    fprintf( outfile, " Ê Ê\"\\tlwz Êr0, 44(r1)\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\tmtlr r0\\n\"\n" );
+    fprintf( outfile, " Ê Ê\"\\taddi r1, r1, 48\\n\"\n" );
+
+    /* branch to ctr register. */
+    fprintf( outfile, " Ê Ê\"\\tbctr\\n\"\n" );
+# else /* __darwin__ */
     /* Save all callee saved registers into a stackframe. */
     fprintf( outfile, "    \"\\tstwu %%r1, -48(%%r1)\\n\"\n" );
     fprintf( outfile, "    \"\\tstw  %%r3, 4(%%r1)\\n\"\n" );
@@ -1025,7 +1106,7 @@
     fprintf( outfile, "    \"\\taddi %%r1, %%r1, 48\\n\"\n" );
     /* branch to ctr register. */
     fprintf( outfile, "    \"\\tbctr\\n\"\n" );
-
+# endif /* __darwin__ */
 #else
 #error You need to defined delayed import thunks for your architecture!
 #endif
@@ -1092,6 +1173,29 @@
             }
 
 #elif defined(__PPC__)
+# ifdef __darwin
+            fprintf(outfile, "\t\"addi 1, 1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw 8, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tstw 7, 0(1)\\n\"\n");
+
+            fprintf(outfile, "\t\"\\tlis 9,ha16(_delay_imports+%d)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tla 8,lo16(_delay_imports+%d)(9)\\n\"\n", pos);
+            fprintf(outfile, "\t\"\\tlwz 7, 0(8)\\n\"\n");
+            fprintf(outfile, "\t\"\\tmtctr 7\\n\"\n");
+
+Ê           fprintf(outfile, "\t\"\\tlwz 7, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz 8, 0(1)\\n\"\n");
+            fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tlwz 9, 0(1)\\n\"\n");
+
+Ê
+            fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n");
+            fprintf(outfile, "\t\"\\tbctr\\n\"");
+# else /* __darwine__*/ 
             fprintf(outfile, "\t\"addi 1, 1, -0x4\\n\"\n");
             fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n");
             fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n");
@@ -1116,12 +1220,20 @@
             fprintf(outfile, "\t\"lwz r0, %d(r0)\\n\\t\"\n", pos);
             fprintf(outfile, "\t\"mtctr r0\\n\\t\"\n");
             fprintf(outfile, "\t\"bctr\\n\"");*/
+# endif /* __darwin__ */
 #else
 #error You need to define delayed import thunks for your architecture!
 #endif
             fprintf( outfile, "\n" );
         }
     }
+    
+#ifdef __darwin__
+    fprintf( outfile, "\".text\");\n" );
+#else /* __darwin__ */
+    fprintf( outfile, "\".section \\\".text\\\"\");\n" );
+#endif /* __darwin__ */
+
     fprintf( outfile, "\".section \\\".text\\\"\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
Index: tools/winebuild/spec32.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/spec32.c,v
retrieving revision 1.65
diff -u -r1.65 spec32.c
--- tools/winebuild/spec32.c	3 Apr 2003 18:05:17 -0000	1.65
+++ tools/winebuild/spec32.c	3 May 2003 19:20:18 -0000
@@ -429,6 +429,20 @@
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
 #elif defined(__PPC__)
+# ifdef __darwin__
+    if (constructor)
+    {
+        fprintf( outfile, "asm(\"\\t.section .init,ax\\n\"\n" );
+        fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", constructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+    if (destructor)
+    {
+        fprintf( outfile, "asm(\"\\t.section .fini,ax\\n\"\n" );
+        fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+# else /* __darwin__ */
     if (constructor)
     {
         fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
@@ -441,6 +455,7 @@
         fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor );
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
+# endif /* __darwin__ */
 #else
 #error You need to define the DLL constructor for your architecture
 #endif
@@ -489,9 +504,17 @@
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_header(void) {\n" );
     fprintf( outfile, "#endif\n" );
+#ifdef __darwin__
+    fprintf( outfile, "asm(\".text\\n\\t\"\n" );
+#else
     fprintf( outfile, "asm(\".section \\\".text\\\"\\n\\t\"\n" );
+#endif
     fprintf( outfile, "    \".align %d\\n\"\n", get_alignment(page_size) );
+#ifdef __darwin__
+    fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\n\\t\");\n" );
+#else
     fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\t.skip 65536\\n\\t\");\n" );
+#endif
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
     fprintf( outfile, "#endif\n" );
@@ -546,7 +569,11 @@
         else
         {
             fprintf( outfile, "#ifdef __GNUC__\n" );
+            fprintf( outfile, "# ifdef __darwin__\n" );
+            fprintf( outfile, "extern void DllMain() __attribute__((weak_import));\n" );
+            fprintf( outfile, "# else\n" );
             fprintf( outfile, "extern void DllMain() __attribute__((weak));\n" );
+            fprintf( outfile, "# endif\n" );
             fprintf( outfile, "#else\n" );
             fprintf( outfile, "extern void DllMain();\n" );
             fprintf( outfile, "static void __asm__dummy_dllmain(void)" );
@@ -920,7 +947,11 @@
     fprintf( outfile, "    \"\\tbl " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
     fprintf( outfile, "    \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
     fprintf( outfile, "    \"\\tbl " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
+# ifdef __darwin__
+    fprintf( outfile, " Ê Ê\"\\t.text\\n\");\n" );
+# else
     fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
+# endif
 #else
 #error You need to define the DLL constructor for your architecture
 #endif
-------------- next part --------------



More information about the wine-patches mailing list