Created
September 3, 2011 14:31
-
-
Save ichizok/1191268 to your computer and use it in GitHub Desktop.
GNU-Prolog 1.4.0 patch for OSX (x86-64)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/EnginePl/engine1.c b/src/EnginePl/engine1.c | |
--- a/src/EnginePl/engine1.c | |
+++ b/src/EnginePl/engine1.c | |
@@ -118,6 +118,11 @@ | |
#endif | |
+#elif defined(M_x86_64_darwin) | |
+ | |
+ register WamWord *rb asm("%r12") = pl_reg_bank; | |
+ pl_ensure_reserved = (WamWord *) rb; /* to avoid gcc warning */ | |
+ | |
#endif | |
pl_ensure_reserved = reserved_stack_space; | |
diff --git a/src/EnginePl/gp_config.h.in b/src/EnginePl/gp_config.h.in | |
--- a/src/EnginePl/gp_config.h.in | |
+++ b/src/EnginePl/gp_config.h.in | |
@@ -220,6 +220,9 @@ | |
/* Define if the system is a x86-64/mingw */ | |
#undef M_x86_64_mingw | |
+/* Define if the system is a x86-64/darwin */ | |
+#undef M_x86_64_darwin | |
+ | |
/* Constant definitions */ | |
diff --git a/src/EnginePl/machine.c b/src/EnginePl/machine.c | |
--- a/src/EnginePl/machine.c | |
+++ b/src/EnginePl/machine.c | |
@@ -506,7 +506,7 @@ | |
void | |
SIGSEGV_Handler(int sig, int code, struct sigcontext *scp) | |
-#elif defined(M_x86_64_linux) || defined(M_x86_64_bsd) | |
+#elif defined(M_x86_64_linux) || defined(M_x86_64_bsd) || defined(M_x86_64_darwin) | |
void | |
SIGSEGV_Handler(int sig, siginfo_t *sip, void *scp) | |
@@ -535,7 +535,7 @@ | |
WamWord *addr = (WamWord *) scp.cr2; | |
-#elif defined(M_x86_64_linux) || defined(M_x86_64_bsd) | |
+#elif defined(M_x86_64_linux) || defined(M_x86_64_bsd) || defined(M_x86_64_darwin) | |
WamWord *addr = (WamWord *) sip->si_addr; | |
diff --git a/src/EnginePl/machine.h b/src/EnginePl/machine.h | |
--- a/src/EnginePl/machine.h | |
+++ b/src/EnginePl/machine.h | |
@@ -134,7 +134,7 @@ | |
# define M_USED_REGS {"15", "20", 0} | |
-#elif defined(M_x86_64) && !defined(_MSC_VER) | |
+#elif defined(M_x86_64) && !defined(_MSC_VER) && !defined(M_x86_64_darwin) | |
# define M_USED_REGS {"r12", "r13", "r14", "r15", 0} | |
@@ -150,9 +150,9 @@ | |
#endif | |
-//#if defined(_MSC_VER) && defined(M_x86_64) | |
-//#define NO_MACHINE_REG_FOR_REG_BANK | |
-//#endif | |
+#if defined(M_x86_64) && defined(M_x86_64_darwin) | |
+#define NO_MACHINE_REG_FOR_REG_BANK | |
+#endif | |
diff --git a/src/Ma2Asm/x86_64_any.c b/src/Ma2Asm/x86_64_any.c | |
--- a/src/Ma2Asm/x86_64_any.c | |
+++ b/src/Ma2Asm/x86_64_any.c | |
@@ -70,9 +70,23 @@ | |
* Constants * | |
*---------------------------------*/ | |
+#ifdef M_x86_64_darwin | |
+ | |
+#define STRING_PREFIX "L_.str" | |
+#define DOUBLE_PREFIX "LCPI" | |
+ | |
+#define UN "_" | |
+#define DARWIN_REG_BANK "%r12" | |
+ | |
+#else | |
+ | |
#define STRING_PREFIX ".LC" | |
#define DOUBLE_PREFIX ".LCD" | |
+#define UN | |
+ | |
+#endif | |
+ | |
#define MAX_C_ARGS_IN_C_CODE 32 /* must be a multiple of 2 */ | |
#define RESERVED_STACK_SPACE MAX_C_ARGS_IN_C_CODE * 8 | |
@@ -80,7 +94,6 @@ | |
- | |
/*---------------------------------* | |
* Type Definitions * | |
*---------------------------------*/ | |
@@ -127,7 +140,11 @@ | |
/* variables for ma_parser.c / ma2asm.c */ | |
char *comment_prefix = "#"; | |
+#ifdef M_x86_64_darwin | |
+char *local_symb_prefix = "L"; | |
+#else | |
char *local_symb_prefix = ".L"; | |
+#endif | |
int strings_need_null = 0; | |
int call_c_reverse_args = 0; | |
@@ -176,7 +193,12 @@ | |
strcpy(asm_reg_cp, Off_Reg_Bank(MAP_OFFSET_CP)); | |
#endif | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf(".section", "__TEXT,__text,regular,pure_instructions"); | |
+ Inst_Printf(".align", "4, 0x90"); | |
+#else | |
Label_Printf(".text"); | |
+#endif | |
Label("fail"); | |
Pl_Fail(); | |
@@ -194,11 +216,15 @@ | |
{ | |
static char str[20]; | |
+#ifdef M_x86_64_darwin | |
+ sprintf(str, "%d(%" DARWIN_REG_BANK ")", offset); | |
+#else | |
#ifdef NO_MACHINE_REG_FOR_REG_BANK | |
sprintf(str, ASM_REG_BANK "+%d", offset); | |
#else | |
sprintf(str, "%d(%s)", offset, ASM_REG_BANK); | |
#endif | |
+#endif | |
return str; | |
} | |
@@ -248,13 +274,17 @@ | |
nb_dbl = 0; | |
Label_Printf(""); | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf(".align", "4, 0x90"); | |
+#else | |
Inst_Printf(".align", "16"); | |
#if defined(M_x86_64_linux) || defined(M_x86_64_bsd) || defined(M_x86_64_sco) | |
Inst_Printf(".type", "%s,@function", label); | |
#endif | |
+#endif | |
if (global) | |
- Inst_Printf(".globl", "%s", label); | |
+ Inst_Printf(".globl", UN "%s", label); | |
Label(label); | |
@@ -291,7 +321,7 @@ | |
Label(char *label) | |
{ | |
Label_Printf(""); | |
- Label_Printf("%s:", label); | |
+ Label_Printf(UN "%s:", label); | |
} | |
@@ -319,7 +349,7 @@ | |
void | |
Pl_Jump(char *label) | |
{ | |
- Inst_Printf("jmp", "%s", label); | |
+ Inst_Printf("jmp", UN "%s", label); | |
} | |
@@ -332,7 +362,12 @@ | |
void | |
Prep_CP(void) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("leaq", "Ltmp%d(%%rip),%%r10", w_label); | |
+ Inst_Printf("movq", "%%r10,%s", asm_reg_cp); | |
+#else | |
Inst_Printf("movq", "$.Lcont%d,%s", w_label, asm_reg_cp); | |
+#endif | |
} | |
@@ -345,7 +380,11 @@ | |
void | |
Here_CP(void) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Label_Printf("Ltmp%d:", w_label++); | |
+#else | |
Label_Printf(".Lcont%d:", w_label++); | |
+#endif | |
} | |
@@ -408,7 +447,7 @@ | |
void | |
Jump(char *label) | |
{ | |
- Inst_Printf("jmp", "%s", label); | |
+ Inst_Printf("jmp", UN "%s", label); | |
} | |
@@ -622,7 +661,13 @@ | |
{ | |
BEFORE_ARG; | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("leaq", "%s%d(%%rip),%s", STRING_PREFIX, str_no, r_aux); | |
+ if (!r_eq_r_aux) | |
+ Inst_Printf("movq", "%s,%s", r_aux, r); | |
+#else | |
Inst_Printf("movq", "$%s%d,%s", STRING_PREFIX, str_no, r); | |
+#endif | |
AFTER_ARG; | |
@@ -639,6 +684,18 @@ | |
{ | |
BEFORE_ARG; | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_%s@GOTPCREL(%%rip),%s", name, r_aux); | |
+ if (adr_of) | |
+ { | |
+ if (index != 0) | |
+ Inst_Printf("addq", "$%d,%s", index * 8, r_aux); | |
+ } | |
+ else | |
+ Inst_Printf("movq", "%d(%s),%s", index * 8, r_aux, r_aux); | |
+ if (!r_eq_r_aux) | |
+ Inst_Printf("movq", "%s,%s", r_aux, r); | |
+#else | |
if (adr_of) | |
Inst_Printf("movq", "$" "%s+%d,%s", name, index * 8, r); | |
else | |
@@ -647,6 +704,7 @@ | |
if (!r_eq_r_aux) | |
Inst_Printf("movq", "%s,%s", r_aux, r); | |
} | |
+#endif | |
AFTER_ARG; | |
@@ -667,11 +725,15 @@ | |
{ | |
if (!r_eq_r_aux && index == 0) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "%" DARWIN_REG_BANK ",%s", r_aux); | |
+#else | |
#ifdef NO_MACHINE_REG_FOR_REG_BANK | |
Inst_Printf("movq", "$%s,%s", ASM_REG_BANK, r); | |
#else | |
Inst_Printf("movq", "%s,%s", ASM_REG_BANK, r); | |
#endif | |
+#endif | |
goto finish; | |
} | |
Inst_Printf("leaq", "%s,%s", Off_Reg_Bank(index * 8), r_aux); | |
@@ -722,6 +784,18 @@ | |
{ | |
BEFORE_ARG; | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_pl_foreign_long@GOTPCREL(%%rip), %s", r_aux); | |
+ if (adr_of) | |
+ { | |
+ if (index != 0) | |
+ Inst_Printf("addq", "$%d, %s", index * 8, r_aux); | |
+ } | |
+ else | |
+ Inst_Printf("movq", "%d(%s), %s", index * 8, r_aux, r_aux); | |
+ if (!r_eq_r_aux) | |
+ Inst_Printf("movq", "%s, %s", r_aux, r); | |
+#else | |
if (adr_of) | |
Inst_Printf("movq", "$pl_foreign_long+%d, %s", index * 8, r); | |
else | |
@@ -730,6 +804,7 @@ | |
if (!r_eq_r_aux) | |
Inst_Printf("movq", "%s, %s", r_aux, r); | |
} | |
+#endif | |
AFTER_ARG; | |
@@ -747,14 +822,27 @@ | |
if (adr_of) | |
{ | |
BEFORE_ARG; | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_pl_foreign_double@GOTPCREL(%%rip), %s", r_aux); | |
+ if (index != 0) | |
+ Inst_Printf("addq", "$%d, %s", index * 8, r_aux); | |
+ if (!r_eq_r_aux) | |
+ Inst_Printf("movq", "%s, %s", r_aux, r); | |
+#else | |
Inst_Printf("movq", "$pl_foreign_double+%d, %s", index * 8, r); | |
+#endif | |
AFTER_ARG; | |
return 1; | |
} | |
BEFORE_FPR_ARG; | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_pl_foreign_double@GOTPCREL(%%rip),%%r10"); | |
+ Inst_Printf("movsd", "%d(%%r10), %s", index * 8, r_aux); | |
+#else | |
Inst_Printf("movsd", "pl_foreign_double+%d(%%rip),%s", index * 8, r_aux); | |
+#endif | |
if (!r_eq_r_aux) | |
Inst_Printf("movsd", "%s, %s", r_aux, r); | |
@@ -771,7 +859,7 @@ | |
void | |
Call_C_Invoke(char *fct_name, int fc, int nb_args, int nb_args_in_words) | |
{ | |
- Inst_Printf("call", "%s", fct_name); | |
+ Inst_Printf("call", UN "%s", fct_name); | |
} | |
@@ -812,7 +900,7 @@ | |
Fail_Ret(void) | |
{ | |
Inst_Printf("test", "%%rax,%%rax"); | |
- Inst_Printf("je", "fail"); | |
+ Inst_Printf("je", UN "fail"); | |
} | |
@@ -825,7 +913,12 @@ | |
void | |
Move_Ret_To_Mem_L(char *name, int index) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_%s@GOTPCREL(%%rip)," "%%r10", name); | |
+ Inst_Printf("movq", "%%rax," "%d(%%r10)", index * 8); | |
+#else | |
Inst_Printf("movq", "%%rax," "%s+%d(%%rip)", name, index * 8); | |
+#endif | |
} | |
@@ -864,7 +957,12 @@ | |
void | |
Move_Ret_To_Foreign_L(int index) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_pl_foreign_long@GOTPCREL(%%rip)," "%%r10"); | |
+ Inst_Printf("movq", "%%rax," "%d(%%r10)", index * 8); | |
+#else | |
Inst_Printf("movq", "%%rax," "pl_foreign_long+%d(%%rip)", index * 8); | |
+#endif | |
} | |
@@ -877,7 +975,12 @@ | |
void | |
Move_Ret_To_Foreign_D(int index) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf("movq", "_pl_foreign_double@GOTPCREL(%%rip)," "%%r10"); | |
+ Inst_Printf("movsd", "%%xmm0," "%d(%%r10)", index * 8); | |
+#else | |
Inst_Printf("movsd", "%%xmm0," "pl_foreign_double+%d(%%rip)", index * 8); | |
+#endif | |
} | |
@@ -914,7 +1017,7 @@ | |
void | |
Jump_If_Equal(char *label) | |
{ | |
- Inst_Printf("je", "%s", label); | |
+ Inst_Printf("je", UN "%s", label); | |
} | |
@@ -927,7 +1030,7 @@ | |
void | |
Jump_If_Greater(char *label) | |
{ | |
- Inst_Printf("jg", "%s", label); | |
+ Inst_Printf("jg", UN "%s", label); | |
} | |
@@ -955,7 +1058,11 @@ | |
void | |
Dico_String_Start(int nb_consts) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf(".section", "__TEXT,__cstring,cstring_literals"); | |
+#else | |
Label_Printf(".section\t.rodata"); | |
+#endif | |
} | |
@@ -967,7 +1074,11 @@ | |
Dico_String(int str_no, char *asciiz) | |
{ | |
Label_Printf("%s%d:", STRING_PREFIX, str_no); | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf(".asciz", "%s", asciiz); | |
+#else | |
Inst_Printf(".string", "%s", asciiz); | |
+#endif | |
} | |
@@ -990,8 +1101,13 @@ | |
void | |
Dico_Long_Start(int nb_longs) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf(".section", "__DATA,__data"); | |
+ Inst_Printf(".align", "3"); | |
+#else | |
Label_Printf(".data"); | |
Inst_Printf(".align", "16"); | |
+#endif | |
} | |
@@ -1007,21 +1123,29 @@ | |
case NONE: | |
value = 1; /* then in case ARRAY_SIZE */ | |
case ARRAY_SIZE: | |
+#ifdef M_x86_64_darwin | |
+ if (!global) | |
+ Label_Printf(".zerofill __DATA,__bss,_%s,%" PL_FMT_d ",3", name, value * 8); | |
+ else | |
+ Inst_Printf(".comm", "_%s,%" PL_FMT_d ",3", name, value * 8); | |
+#else | |
#if defined(M_x86_64_linux) || defined(M_x86_64_sco) || \ | |
defined(M_x86_64_solaris) || defined(M_x86_64_bsd) | |
if (!global) | |
Inst_Printf(".local", "%s", name); | |
- Inst_Printf(".comm", "%s,%" PL_FMT_d ",8", name, value * 8); | |
#else | |
if (!global) | |
Inst_Printf(".lcomm", "%s,%" PL_FMT_d, name, value * 8); | |
+ else | |
+#endif | |
+ Inst_Printf(".comm", "%s,%" PL_FMT_d ",8", name, value * 8); | |
#endif | |
break; | |
case INITIAL_VALUE: | |
if (global) | |
- Inst_Printf(".globl", "%s", name); | |
- Label_Printf("%s:", name); | |
+ Inst_Printf(".globl", UN "%s", name); | |
+ Label_Printf(UN "%s:", name); | |
Inst_Printf(".quad", "%" PL_FMT_d, value); | |
break; | |
} | |
@@ -1035,6 +1159,9 @@ | |
void | |
Dico_Long_Stop(int nb_longs) | |
{ | |
+#ifdef M_x86_64_darwin | |
+ Label_Printf("\n\n.subsections_via_symbols"); | |
+#endif | |
} | |
@@ -1054,11 +1181,17 @@ | |
Inst_Printf(".section", ".GPLC$m"); | |
#elif defined( __CYGWIN__) || defined (_WIN32) | |
Inst_Printf(".section", ".ctors,\"aw\""); | |
+#elif defined(M_x86_64_darwin) | |
+ Inst_Printf(".section", "__DATA,__mod_init_func,mod_init_funcs"); | |
#else | |
Inst_Printf(".section", ".ctors,\"aw\",@progbits"); | |
#endif | |
+#ifdef M_x86_64_darwin | |
+ Inst_Printf(".align", "3"); | |
+#else | |
Inst_Printf(".align", "8"); | |
- Inst_Printf(".quad", "%s", initializer_fct); | |
+#endif | |
+ Inst_Printf(".quad", UN "%s", initializer_fct); | |
} | |
diff --git a/src/configure b/src/configure | |
--- a/src/configure | |
+++ b/src/configure | |
@@ -3700,8 +3700,9 @@ | |
fi | |
AS0=as | |
case "$host" in | |
- i*86*darwin10*) ASFLAGS='-arch i686';; | |
+ i*86*darwin1*) ASFLAGS='-arch i686';; | |
x86_64*solaris*) AS0=gas; ASFLAGS='--64';; | |
+ x86_64*darwin*) ASFLAGS='-arch x86_64';; | |
*) if test "$with_gas" = yes; then AS0=gas; fi;; | |
esac | |
if test -n "$ac_tool_prefix"; then | |
@@ -4377,6 +4378,10 @@ | |
$as_echo "#define M_win64 1" >>confdefs.h | |
$as_echo "#define M_x86_64_win64 1" >>confdefs.h | |
WINDOWS=64;; | |
+ x86_64*darwin*) $as_echo "#define M_x86_64 1" >>confdefs.h | |
+ $as_echo "#define M_darwin 1" >>confdefs.h | |
+ $as_echo "#define M_x86_64_darwin 1" >>confdefs.h | |
+;; | |
i*86*linux*) $as_echo "#define M_ix86 1" >>confdefs.h | |
$as_echo "#define M_linux 1" >>confdefs.h | |
$as_echo "#define M_ix86_linux 1" >>confdefs.h | |
@@ -4614,7 +4619,7 @@ | |
CFLAGS_MACHINE= | |
case "$host" in | |
- i*86*darwin10*) CFLAGS_MACHINE='-march=i686 -m32';; | |
+ i*86*darwin1*) CFLAGS_MACHINE='-march=i686 -m32';; | |
mips*irix*) CFLAGS_MACHINE='-march=4000';; | |
*sparc*sunos4.1.3) CFLAGS_MACHINE='-msupersparc';; | |
*sparc*solaris) CFLAGS_MACHINE='-msupersparc';; | |
@@ -4623,6 +4628,7 @@ | |
i*86*) CFLAGS_MACHINE='-march=i486 -m32';; | |
powerpc*darwin*) CFLAGS_MACHINE='-mpowerpc -no-cpp-precomp';; | |
x86_64*solaris*) CFLAGS_MACHINE='-m64';; | |
+ x86_64*darwin*) CFLAGS_MACHINE='-march=x86-64 -m64';; | |
esac | |
case "$host" in | |
diff --git a/src/configure.in b/src/configure.in | |
--- a/src/configure.in | |
+++ b/src/configure.in | |
@@ -330,8 +330,9 @@ | |
dnl think the user wants to override the test) | |
AS0=as | |
case "$host" in | |
- i*86*darwin10*) ASFLAGS='-arch i686';; | |
+ i*86*darwin1*) ASFLAGS='-arch i686';; | |
x86_64*solaris*) AS0=gas; ASFLAGS='--64';; | |
+ x86_64*darwin*) ASFLAGS='-arch x86_64';; | |
*) if test "$with_gas" = yes; then AS0=gas; fi;; | |
esac | |
AC_CHECK_TOOL([AS],[$AS0]) | |
@@ -387,6 +388,7 @@ | |
x86_64*solaris*) AC_DEFINE(M_x86_64) AC_DEFINE(M_solaris) AC_DEFINE(M_x86_64_solaris);; | |
x86_64*mingw*) AC_DEFINE(M_x86_64) AC_DEFINE(M_win64) AC_DEFINE(M_x86_64_win64) WINDOWS=64;; | |
x86_64*win64*) AC_DEFINE(M_x86_64) AC_DEFINE(M_win64) AC_DEFINE(M_x86_64_win64) WINDOWS=64;; | |
+ x86_64*darwin*) AC_DEFINE(M_x86_64) AC_DEFINE(M_darwin) AC_DEFINE(M_x86_64_darwin);; | |
i*86*linux*) AC_DEFINE(M_ix86) AC_DEFINE(M_linux) AC_DEFINE(M_ix86_linux);; | |
i*86*solaris*) AC_DEFINE(M_ix86) AC_DEFINE(M_solaris) AC_DEFINE(M_ix86_solaris);; | |
i*86*sco*) AC_DEFINE(M_ix86) AC_DEFINE(M_sco) AC_DEFINE(M_ix86_sco);; | |
@@ -492,7 +494,7 @@ | |
CFLAGS_MACHINE= | |
case "$host" in | |
- i*86*darwin10*) CFLAGS_MACHINE='-march=i686 -m32';; | |
+ i*86*darwin1*) CFLAGS_MACHINE='-march=i686 -m32';; | |
mips*irix*) CFLAGS_MACHINE='-march=4000';; | |
*sparc*sunos4.1.3) CFLAGS_MACHINE='-msupersparc';; | |
*sparc*solaris) CFLAGS_MACHINE='-msupersparc';; | |
@@ -501,6 +503,7 @@ | |
i*86*) CFLAGS_MACHINE='-march=i486 -m32';; | |
powerpc*darwin*) CFLAGS_MACHINE='-mpowerpc -no-cpp-precomp';; | |
x86_64*solaris*) CFLAGS_MACHINE='-m64';; | |
+ x86_64*darwin*) CFLAGS_MACHINE='-march=x86-64 -m64';; | |
esac | |
case "$host" in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment