Mac OS X Support : Asm syntax support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Here is a patch which should add support for Mac OS X ppc asm syntax, and some Mach-O quirk (like text section).
I hope it will be ok. It mainly relay on Macro which are stored in build.h (any better place?).


Cheers,

Pierre

ChangeLog:
- Add support for Mac OS X assembler syntax

Modified Files:
- spec32.c
- import.c
- build.h

? tools/winebuild/.DS_Store
Index: tools/winebuild/build.h
===================================================================
RCS file: /home/wine/wine/tools/winebuild/build.h,v
retrieving revision 1.42
diff -u -r1.42 build.h
--- tools/winebuild/build.h	23 Mar 2003 01:12:30 -0000	1.42
+++ tools/winebuild/build.h	25 Jun 2003 12:31:38 -0000
@@ -122,6 +122,96 @@
 
 #define MAX_ORDINALS  65535
 
+#define ASM_OUT(out, content)		fprintf(out,"\"" content "\\n\"\n")
+#define ASM_OUT2(out, content, arg)	fprintf(out,"\"" content "\\n\"\n", arg)
+
+/* 
+ * Here are Macros for different syntax (like Mach-O vs Elf)
+ * LD_*
+ */
+#ifdef __darwin__
+# define LD_SECTION_TEXT  ".text"
+# define LD_SKIP(i)
+#endif
+
+#ifndef LD_SECTION_TEXT
+# define LD_SECTION_TEXT  ".section \".text\""
+#endif
+#ifndef LD_SKIP
+# define LD_SKIP(i)  ".skip " #i
+#endif
+
+/* 
+ * Here are Macros in order to get a compatibility with different assembler syntax
+ * PPC_*
+ */
+ 
+#ifdef __darwin__
+/* Access an integer register */
+# define PPC_REG(i)	          "r" #i
+/* Access he highest half-word of an expression */
+# define PPC_HIGH(mem)        "ha16(" mem ")"
+/* Access he lowest half-word of an expression */
+# define PPC_LOW(mem,index)   "lo16(" mem ")(" PPC_REG(index) ")"
+# define PPC_SYM(sym_name)    "_" #sym_name
+#endif /* __darwin__ */
+
+#ifndef PPC_REG
+# define PPC_REG(i)	      #i
+#endif
+#ifndef PPC_HIGH
+# define PPC_HIGH(mem)        "(" mem ")@hi"
+#endif
+#ifndef PPC_LOW
+# define PPC_LOW(mem,index)   "(" mem ")@l(##index)"
+#endif
+
+#ifndef PPC_SYM
+# define PPC_SYM(sym_name)    #sym_name
+#endif
+#ifndef PPC_ADDI
+# define PPC_ADDI(out, ra, rb, i) ASM_OUT(out, "addi " PPC_REG(ra) "," PPC_REG(rb) "," #i)
+#endif
+#ifndef PPC_ADDIS
+# define PPC_ADDIS(out, ra, i) ASM_OUT(out, "addis " PPC_REG(ra) "," #i)
+#endif
+#ifndef PPC_STW
+# define PPC_STW(out, ra, i, rb) ASM_OUT(out, "stw " PPC_REG(ra) "," #i "(" PPC_REG(rb) ")")
+#endif
+#ifndef PPC_STWU
+# define PPC_STWU(out, ra, i, rb) ASM_OUT(out, "stwu " PPC_REG(ra) "," #i "(" PPC_REG(rb) ")")
+#endif
+#ifndef PPC_LWZ
+# define PPC_LWZ(out, ra, i, rb) ASM_OUT(out, "lwz " PPC_REG(ra) "," #i "(" PPC_REG(rb) ")")
+#endif
+#ifndef PPC_LIS
+# define PPC_LIS(out, ra, mem) ASM_OUT(out, "lis " PPC_REG(ra) "," mem)
+#endif
+#ifndef PPC_LA
+# define PPC_LA(out, ra, mem) ASM_OUT(out, "la " PPC_REG(ra) "," mem)
+#endif
+#ifndef PPC_BCTR
+# define PPC_BCTR(out) ASM_OUT(out, "bctr ")
+#endif
+#ifndef PPC_MTLR
+# define PPC_MTLR(out, ra) ASM_OUT(out, "mtlr " PPC_REG(ra))
+#endif
+#ifndef PPC_MTCTR
+# define PPC_MTCTR(out, ra) ASM_OUT(out, "mtctr " PPC_REG(ra))
+#endif
+#ifndef PPC_MFLR
+# define PPC_MFLR(out, ra) ASM_OUT(out, "mflr " PPC_REG(ra))
+#endif
+#ifndef PPC_MR
+# define PPC_MR(out, ra, rb) ASM_OUT(out, "mr " PPC_REG(ra) "," PPC_REG(rb))
+#endif
+#ifndef PPC_B
+# define PPC_B(out, sym) ASM_OUT(out, "b " PPC_SYM(sym))
+#endif
+#ifndef PPC_BL
+# define PPC_BL(out, sym) ASM_OUT(out, "bl " PPC_SYM(sym))
+#endif
+
 /* global functions */
 
 extern void *xmalloc (size_t size);
Index: tools/winebuild/import.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/import.c,v
retrieving revision 1.50
diff -u -r1.50 import.c
--- tools/winebuild/import.c	14 May 2003 19:36:28 -0000	1.50
+++ tools/winebuild/import.c	25 Jun 2003 12:31:42 -0000
@@ -819,25 +819,30 @@
             }
 
 #elif defined(__PPC__)
-            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");
-            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,imports+%d@ha\\n\"\n", pos);
-            fprintf(outfile, "\t\"\\tla 8,imports+%d@l(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");
+            /* Because we need to return because of before */
+            fprintf( outfile, "\"\n" );
+            PPC_ADDI(outfile, 1, 1, -0x4); /* addi r1, r1, -0x4 */
+            PPC_STW( outfile, 9, 0, 1);    /* stw  r9, 0(r1) */
+            PPC_ADDI(outfile, 1, 1, -0x4);
+            PPC_STW( outfile, 8, 0, 1);
+            PPC_ADDI(outfile, 1, 1, -0x4);
+            PPC_STW( outfile, 7, 0, 1);
+
+            ASM_OUT2(outfile, "lis " PPC_REG(9) "," PPC_HIGH(PPC_SYM(imports) "+" "%d"), pos); /* lis r9,ha16(_imports+pos) */
+            ASM_OUT2(outfile, "la  " PPC_REG(8) ","PPC_LOW(PPC_SYM(imports) "+" "%d", 9), pos); /* la 8,lo16(imports+%d)(9) */
+            
+            PPC_LWZ  (outfile, 7, 0, 8); /* lwz  r7, 0(r8) */
+            PPC_MTCTR(outfile, 7);       /* mtctr 7 */
+            
+            PPC_LWZ( outfile, 7, 0, 1);    /* lwz  r7, 0(r1) */
+            PPC_ADDI(outfile, 1, 1, 0x4); /* addi r1, r1, 0x4 */
+            PPC_LWZ( outfile, 8, 0, 1);
+            PPC_ADDI(outfile, 1, 1, 0x4);
+            PPC_LWZ( outfile, 9, 0, 1);
+            PPC_ADDI(outfile, 1, 1, 0x4);
+            PPC_BCTR(outfile);
+            /* Because the is a " ending just after */
+            fprintf( outfile, "\"" );
 #else
 #error You need to define import thunks for your architecture!
 #endif
@@ -845,7 +850,7 @@
         }
         pos += 4;
     }
-    fprintf( outfile, "\".section\\t\\\".text\\\"\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
+    fprintf( outfile, "\"" LD_SECTION_TEXT "\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
 
  done:
     return nb_imm;
@@ -983,49 +988,50 @@
     fprintf( outfile, "    \"\\tjmp %%o0\\n\\trestore\\n\"\n" );
 #elif defined(__PPC__)
     /* 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" );
+    PPC_STWU( outfile, 1, -48, 1);
+    PPC_STW( outfile, 3, 4, 1);
+    PPC_STW( outfile, 4, 8, 1);
+    PPC_STW( outfile, 5, 12, 1);
+    PPC_STW( outfile, 6, 16, 1);
+    PPC_STW( outfile, 7, 20, 1);
+    PPC_STW( outfile, 8, 24, 1);
+    PPC_STW( outfile, 9, 28, 1);
+    PPC_STW( outfile, 10, 32, 1);
+    PPC_STW( outfile, 11, 36, 1);
+    PPC_STW( outfile, 12, 40, 1);
 
     /* r0 -> r3 (arg1) */
-    fprintf( outfile, "    \"\\tmr  %%r3, %%r0\\n\"\n" );
+    PPC_MR( outfile, 3, 0);
 
     /* save return address */
-    fprintf( outfile, "    \"\\tmflr  %%r0\\n\"\n" );
-    fprintf( outfile, "    \"\\tstw  %%r0, 44(%%r1)\\n\"\n" );
+    PPC_MFLR( outfile, 0);
+    PPC_STW( outfile, 0, 44, 1);
 
     /* Call the __wine_delay_load function, arg1 is arg1. */
-    fprintf( outfile, "    \"\\tbl __wine_delay_load\\n\"\n" );
+    PPC_BL( outfile, __wine_delay_load);
 
     /* Load return value from call into ctr register */
-    fprintf( outfile, "    \"\\tmtctr %%r3\\n\"\n" );
+    PPC_MTCTR( outfile, 3);
 
     /* 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" );
+    PPC_LWZ( outfile, 3, 4, 1);
+    PPC_LWZ( outfile, 4, 8, 1);
+    PPC_LWZ( outfile, 5, 12, 1);
+    PPC_LWZ( outfile, 6, 16, 1);
+    PPC_LWZ( outfile, 7, 20, 1);
+    PPC_LWZ( outfile, 8, 24, 1);
+    PPC_LWZ( outfile, 9, 28, 1);
+    PPC_LWZ( outfile, 10, 32, 1);
+    PPC_LWZ( outfile, 11, 36, 1);
+    PPC_LWZ( outfile, 12, 40, 1);
+
     /* 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" );
+    PPC_LWZ( outfile, 0, 44, 1);
+    PPC_MTLR(outfile, 0);
+    PPC_ADDI(outfile, 1, 1, 48);
 
+    /* branch to ctr register. */
+    PPC_BCTR( outfile );
 #else
 #error You need to defined delayed import thunks for your architecture!
 #endif
@@ -1047,8 +1053,10 @@
             fprintf( outfile, "    \"\\tb,a __wine_delay_load_asm\\n\"\n" );
 #elif defined(__PPC__)
 	    /* g0 is a function scratch register or so I understand. */
-	    fprintf( outfile, "    \"\\tli  %%r0, %d\\n\"\n", (idx << 16) | j  );
-	    fprintf( outfile, "    \"\\tb  __wine_delay_load_asm\\n\"\n" );
+            /* First load the upper half-word, and then the lower part */
+            ASM_OUT2( outfile, "addis " PPC_REG(0) ", 0x%x", idx);
+            ASM_OUT2( outfile, "addis " PPC_REG(0) ", 0x%x", j);
+	    PPC_B( outfile, __wine_delay_load_asm);
 #else
 #error You need to defined delayed import thunks for your architecture!
 #endif
@@ -1092,37 +1100,34 @@
             }
 
 #elif defined(__PPC__)
-            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,delay_imports+%d@ha\\n\"\n", pos);
-            fprintf(outfile, "\t\"\\tla 8,delay_imports+%d@l(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\"");
-
-            /*fprintf(outfile, "\t\"li r0,delay_imports\\n\\t\"\n" );
-            fprintf(outfile, "\t\"lwz r0, %d(r0)\\n\\t\"\n", pos);
-            fprintf(outfile, "\t\"mtctr r0\\n\\t\"\n");
-            fprintf(outfile, "\t\"bctr\\n\"");*/
+            fprintf( outfile, "\n");
+            PPC_ADDI(outfile, 1, 1, -0x4); /* addi r1, r1, -0x4 */
+            PPC_STW( outfile, 9, 0, 1);    /* stw  r9, 0(r1) */
+            PPC_ADDI(outfile, 1, 1, -0x4);
+            PPC_STW( outfile, 8, 0, 1);
+            PPC_ADDI(outfile, 1, 1, -0x4);
+            PPC_STW( outfile, 7, 0, 1);
+
+            ASM_OUT2(outfile, "lis " PPC_REG(9) "," PPC_HIGH(PPC_SYM(imports) "+" "%d"), pos); /* lis r9,ha16(_imports+pos) */
+            ASM_OUT2(outfile, "la " PPC_REG(8) "," PPC_LOW(PPC_SYM(imports) "+" "%d", 9), pos); /* la 8,lo16(imports+%d)(9) */
+            
+            PPC_LWZ  (outfile, 7, 0, 8); /* lwz  r7, 0(r8) */
+            PPC_MTCTR(outfile, 7);       /* mtctr 7 */
+            
+            PPC_LWZ( outfile, 7, 0, 1);    /* lwz  r7, 0(r1) */
+            PPC_ADDI(outfile, 1, 1, 0x4);  /* addi r1, r1, 0x4 */
+            PPC_LWZ( outfile, 8, 0, 1);
+            PPC_ADDI(outfile, 1, 1, 0x4);
+            PPC_LWZ( outfile, 9, 0, 1);
+            PPC_ADDI(outfile, 1, 1, 0x4);
+            PPC_BCTR(outfile);
 #else
 #error You need to define delayed import thunks for your architecture!
 #endif
             fprintf( outfile, "\n" );
         }
     }
-    fprintf( outfile, "\".section \\\".text\\\"\");\n" );
+    fprintf( outfile, "\"" LD_SECTION_TEXT "\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
     fprintf( outfile, "#endif\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	25 Jun 2003 12:31:45 -0000
@@ -429,6 +429,19 @@
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
 #elif defined(__PPC__)
+# ifdef __darwin__
+/* Mach-O don't have a init section */
+    if (constructor)
+    {
+        fprintf( outfile, "asm(\"\\t.section __DATA,__wine_init\\n\"\n" );
+        fprintf( outfile, "    \"\\t.asciz \\\"%s\\\"\\n\"\n", constructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+    if (destructor)
+    {
+        fprintf( outfile, "void %s(void) __attribute__((destructor));\n", constructor );
+    }
+# else /* __darwin__ */
     if (constructor)
     {
         fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
@@ -441,6 +454,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 +503,9 @@
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_header(void) {\n" );
     fprintf( outfile, "#endif\n" );
-    fprintf( outfile, "asm(\".section \\\".text\\\"\\n\\t\"\n" );
+    fprintf( outfile, "asm(\"" LD_SECTION_TEXT "\\n\\t\"\n" );
     fprintf( outfile, "    \".align %d\\n\"\n", get_alignment(page_size) );
-    fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\t.skip 65536\\n\\t\");\n" );
+    fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\t" LD_SKIP(65536) "\\n\\t\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
     fprintf( outfile, "#endif\n" );
@@ -546,7 +560,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 +938,7 @@
     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 );
-    fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
+    fprintf( outfile, "    \"\\t" LD_SECTION_TEXT "\\n\");\n" );
 #else
 #error You need to define the DLL constructor for your architecture
 #endif

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux