| Anonymous | Login | Signup for a new account | 2013-05-21 15:48 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | |||||||
| 0005179 | OCaml | OCaml general | public | 2010-11-24 09:14 | 2012-05-03 21:07 | |||||||
| Reporter | cullmann | |||||||||||
| Assigned To | ||||||||||||
| Priority | normal | Severity | feature | Reproducibility | always | |||||||
| Status | resolved | Resolution | fixed | |||||||||
| Platform | OS | OS Version | ||||||||||
| Product Version | 3.12.1+dev | |||||||||||
| Target Version | Fixed in Version | 3.13.0+dev | ||||||||||
| Summary | 0005179: Port OCaml to mingw-w64 to have 64bit OCaml without MSVC Toolchain | |||||||||||
| Description | Hi, I tried to compile OCaml 3.12 on Windows with mingw-w64, the 64bit successor of the old mingw toolchain (which is based on gcc 4.5 and higher). The 32bit version of mingw-w64 compiles ocaml okay (even if using msys/mingw-64, as now they support @reponsefile and co.) The 64bit version lacks the generation of 64bit gasm and flexlink support. I patched flexlink to work (at least it seems so) and patched a bit the asm stuff to have a linking variant, still got segfaults, guess I mixed it up somewhere. Anyone willing to help me in the porting effort? Our company will test the port extensively after being done by using it for some dev version of Astree. Attached current diffs to 3.12-SVN. Btw., mingw-w64 project: http://mingw-w64.sourceforge.net/ [^] | |||||||||||
| Tags | No tags attached. | |||||||||||
| Attached Files | diff --combined ocaml/3.12/asmrun/Makefile.nt
index 7d72312,f9ed767..0000000
--- a/ocaml/3.12/asmrun/Makefile.nt
+++ b/ocaml/3.12/asmrun/Makefile.nt
@@@ -54,9 -54,6 +54,9 @@@ amd64nt.obj: amd64nt.as
i386.o: i386.S
$(CC) -c -DSYS_$(SYSTEM) i386.S
+amd64.o: amd64.S
+ $(CC) -c -DSYS_$(SYSTEM) amd64.S
+
install:
cp libasmrun.$(A) $(LIBDIR)
diff --combined ocaml/3.12/asmrun/amd64.S
index abf74ee,8eb4ebf..0000000
--- a/ocaml/3.12/asmrun/amd64.S
+++ b/ocaml/3.12/asmrun/amd64.S
@@@ -31,21 -31,6 +31,21 @@@
.align FUNCTION_ALIGN; \
name:
+#elif defined(SYS_mingw64)
+
+#undef __PIC__
+
+#define G(r) r
+#define GREL(r) r
+#define GCALL(r) r
+#define FUNCTION_ALIGN 16
+#define EIGHT_ALIGN 8
+#define SIXTEEN_ALIGN 16
+#define FUNCTION(name) \
+ .globl name; \
+ .align FUNCTION_ALIGN; \
+ name:
+
#else
#define G(r) r
@@@ -106,7 -91,7 +106,7 @@@
popq %r11
#else
-
+
/* Non-PIC operations on global variables. Slightly faster. */
#define STORE_VAR(srcreg,dstlabel) \
@@@ -179,13 -164,7 +179,13 @@@ FUNCTION(G(caml_call_gc)
movlpd %xmm14, 14*8(%rsp)
movlpd %xmm15, 15*8(%rsp)
/* Call the garbage collector */
+#ifdef SYS_mingw64
+ subq $32, %rsp /* PR#5008: bottom 32 bytes are reserved for callee */
+#endif
call GCALL(caml_garbage_collection)
+#ifdef SYS_mingw64
+ addq $32, %rsp /* PR#5008 */
+#endif
/* Restore caml_young_ptr, caml_exception_pointer */
LOAD_VAR(caml_young_ptr, %r15)
LOAD_VAR(caml_exception_pointer, %r14)
@@@ -298,28 -277,6 +298,28 @@@ FUNCTION(G(caml_c_call)
/* Start the Caml program */
FUNCTION(G(caml_start_program))
+#ifdef SYS_mingw64
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movapd %xmm6, 0*16(%rsp)
+ movapd %xmm7, 1*16(%rsp)
+ movapd %xmm8, 2*16(%rsp)
+ movapd %xmm9, 3*16(%rsp)
+ movapd %xmm10, 4*16(%rsp)
+ movapd %xmm11, 5*16(%rsp)
+ movapd %xmm12, 6*16(%rsp)
+ movapd %xmm13, 7*16(%rsp)
+ movapd %xmm14, 8*16(%rsp)
+ movapd %xmm15, 9*16(%rsp)
+#else
/* Save callee-save registers */
pushq %rbx
pushq %rbp
@@@ -328,7 -285,6 +328,7 @@@
pushq %r14
pushq %r15
subq $8, %rsp /* stack 16-aligned */
+#endif
/* Initial entry point is G(caml_program) */
leaq GCALL(caml_program)(%rip), %r12
/* Common code for caml_start_program and caml_callback* */
@@@ -361,28 -317,6 +361,28 @@@
POP_VAR(caml_last_return_address)
POP_VAR(caml_gc_regs)
addq $8, %rsp
+#ifdef SYS_mingw64
+ /* Restore callee-save registers. */
+ movapd 0*16(%rsp), %xmm6
+ movapd 1*16(%rsp), %xmm7
+ movapd 2*16(%rsp), %xmm8
+ movapd 3*16(%rsp), %xmm9
+ movapd 4*16(%rsp), %xmm10
+ movapd 5*16(%rsp), %xmm11
+ movapd 6*16(%rsp), %xmm12
+ movapd 7*16(%rsp), %xmm13
+ movapd 8*16(%rsp), %xmm14
+ movapd 9*16(%rsp), %xmm15
+ addq $(8+10*16), %rsp
+ popq %r15
+ popq %r14
+ popq %r13
+ popq %r12
+ popq %rdi
+ popq %rsi
+ popq %rbp
+ popq %rbx
+#else
/* Restore callee-save registers. */
addq $8, %rsp
popq %r15
@@@ -391,7 -325,6 +391,7 @@@
popq %r12
popq %rbp
popq %rbx
+#endif
/* Return to caller. */
ret
.L108:
@@@ -409,20 -342,11 +409,20 @@@ FUNCTION(G(caml_raise_exn)
popq %r14
ret
.L110:
+#ifdef SYS_mingw64
+ movq %rax, %r12 /* Save exception bucket in r12 */
+ movq %rax, %rcx /* Arg 1: exception bucket */
+ movq 0(%rsp), %rdx /* arg 2: pc of raise */
+ leaq 8(%rsp), %r8 /* arg 3: sp of raise */
+ movq %r14, %r9 /* arg 4: sp of handler */
+ subq $32, %rsp /* PR#5008: bottom 32 bytes are reserved for callee */
+#else
movq %rax, %r12 /* Save exception bucket */
movq %rax, %rdi /* arg 1: exception bucket */
movq 0(%rsp), %rsi /* arg 2: pc of raise */
leaq 8(%rsp), %rdx /* arg 3: sp of raise */
movq %r14, %rcx /* arg 4: sp of handler */
+#endif
call GCALL(caml_stash_backtrace)
movq %r12, %rax /* Recover exception bucket */
movq %r14, %rsp
@@@ -434,30 -358,17 +434,30 @@@
FUNCTION(G(caml_raise_exception))
TESTL_VAR($1, caml_backtrace_active)
jne .L111
+#ifdef SYS_mingw64
+ movq %rcx, %rax
+#else
movq %rdi, %rax
+#endif
LOAD_VAR(caml_exception_pointer, %rsp) /* Cut stack */
popq %r14 /* Recover previous exception handler */
LOAD_VAR(caml_young_ptr, %r15) /* Reload alloc ptr */
ret
.L111:
+#ifdef SYS_mingw64
+ movq %rcx, %r12 /* Save exception bucket */
+ /* arg 1: exception bucket */
+ LOAD_VAR(caml_last_return_address,%rdx) /* arg 2: pc of raise */
+ LOAD_VAR(caml_bottom_of_stack,%r8) /* arg 3: sp of raise */
+ LOAD_VAR(caml_exception_pointer,%r9) /* arg 4: sp of handler */
+ subq $32, %rsp /* PR#5008: bottom 32 bytes are reserved for callee */
+#else
movq %rdi, %r12 /* Save exception bucket */
/* arg 1: exception bucket */
- LOAD_VAR(caml_last_return_address,%rsi) /* arg 2: pc of raise */
+ LOAD_VAR(caml_last_return_address,%rsi) /* arg 2: pc of raise */
LOAD_VAR(caml_bottom_of_stack,%rdx) /* arg 3: sp of raise */
LOAD_VAR(caml_exception_pointer,%rcx) /* arg 4: sp of handler */
+#endif
call GCALL(caml_stash_backtrace)
movq %r12, %rax /* Recover exception bucket */
LOAD_VAR(caml_exception_pointer,%rsp)
@@@ -468,31 -379,6 +468,31 @@@
/* Callback from C to Caml */
FUNCTION(G(caml_callback_exn))
+#ifdef SYS_mingw64
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movapd %xmm6, 0*16(%rsp)
+ movapd %xmm7, 1*16(%rsp)
+ movapd %xmm8, 2*16(%rsp)
+ movapd %xmm9, 3*16(%rsp)
+ movapd %xmm10, 4*16(%rsp)
+ movapd %xmm11, 5*16(%rsp)
+ movapd %xmm12, 6*16(%rsp)
+ movapd %xmm13, 7*16(%rsp)
+ movapd %xmm14, 8*16(%rsp)
+ movapd %xmm15, 9*16(%rsp)
+ /* Initial loading of arguments */
+ movq %rcx, %rbx /* closure */
+ movq %rdx, %rax /* argument */
+#else
/* Save callee-save registers */
pushq %rbx
pushq %rbp
@@@ -500,41 -386,14 +500,41 @@@
pushq %r13
pushq %r14
pushq %r15
- subq $8, %rsp /* stack 16-aligned */
+ subq $8, %rsp /* stack 16-aligned */
/* Initial loading of arguments */
movq %rdi, %rbx /* closure */
movq %rsi, %rax /* argument */
+#endif
movq 0(%rbx), %r12 /* code pointer */
jmp .Lcaml_start_program
FUNCTION(G(caml_callback2_exn))
+#ifdef SYS_mingw64
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movapd %xmm6, 0*16(%rsp)
+ movapd %xmm7, 1*16(%rsp)
+ movapd %xmm8, 2*16(%rsp)
+ movapd %xmm9, 3*16(%rsp)
+ movapd %xmm10, 4*16(%rsp)
+ movapd %xmm11, 5*16(%rsp)
+ movapd %xmm12, 6*16(%rsp)
+ movapd %xmm13, 7*16(%rsp)
+ movapd %xmm14, 8*16(%rsp)
+ movapd %xmm15, 9*16(%rsp)
+ /* Initial loading of arguments */
+ movq %rcx, %rdi /* closure */
+ movq %rdx, %rax /* first argument */
+ movq %r8, %rbx /* second argument */
+#else
/* Save callee-save registers */
pushq %rbx
pushq %rbp
@@@ -542,43 -401,15 +542,43 @@@
pushq %r13
pushq %r14
pushq %r15
- subq $8, %rsp /* stack 16-aligned */
+ subq $8, %rsp /* stack 16-aligned */
/* Initial loading of arguments */
/* closure stays in %rdi */
movq %rsi, %rax /* first argument */
movq %rdx, %rbx /* second argument */
+#endif
leaq GCALL(caml_apply2)(%rip), %r12 /* code pointer */
jmp .Lcaml_start_program
FUNCTION(G(caml_callback3_exn))
+#ifdef SYS_mingw64
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movapd %xmm6, 0*16(%rsp)
+ movapd %xmm7, 1*16(%rsp)
+ movapd %xmm8, 2*16(%rsp)
+ movapd %xmm9, 3*16(%rsp)
+ movapd %xmm10, 4*16(%rsp)
+ movapd %xmm11, 5*16(%rsp)
+ movapd %xmm12, 6*16(%rsp)
+ movapd %xmm13, 7*16(%rsp)
+ movapd %xmm14, 8*16(%rsp)
+ movapd %xmm15, 9*16(%rsp)
+ /* Initial loading of arguments */
+ movq %rcx, %rsi /* closure */
+ movq %rdx, %rax /* first argument */
+ movq %r8, %rbx /* second argument */
+ movq %r9, %rdi /* third argument */
+#else
/* Save callee-save registers */
pushq %rbx
pushq %rbp
@@@ -586,13 -417,12 +586,13 @@@
pushq %r13
pushq %r14
pushq %r15
- subq $8, %rsp /* stack 16-aligned */
+ subq $8, %rsp /* stack 16-aligned */
/* Initial loading of arguments */
movq %rsi, %rax /* first argument */
movq %rdx, %rbx /* second argument */
movq %rdi, %rsi /* closure */
movq %rcx, %rdi /* third argument */
+#endif
leaq GCALL(caml_apply3)(%rip), %r12 /* code pointer */
jmp .Lcaml_start_program
@@@ -612,7 -442,7 +612,7 @@@ G(caml_system__frametable)
#ifdef SYS_macosx
.literal16
-#else
+#elif defined(SYS_linux)
.section .rodata.cst8,"a",@progbits
#endif
.globl G(caml_negf_mask)
diff --git a/ocaml/3.12/asmcomp/amd64/emit_mingw64.mlp b/ocaml/3.12/asmcomp/amd64/emit_mingw64.mlp
new file mode 100644
index 0000000..6bc0bdf
--- /dev/null
+++ b/ocaml/3.12/asmcomp/amd64/emit_mingw64.mlp
@@ -0,0 +1,791 @@
+(***********************************************************************)
+(* *)
+(* Objective Caml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: emit.mlp 10488 2010-06-02 08:55:35Z xleroy $ *)
+
+(* Emission of x86-64 (AMD 64) assembly code *)
+
+open Misc
+open Cmm
+open Arch
+open Proc
+open Reg
+open Mach
+open Linearize
+open Emitaux
+
+let macosx =
+ match Config.system with
+ | "macosx" -> true
+ | _ -> false
+
+
+(* Tradeoff between code size and code speed *)
+
+let fastcode_flag = ref true
+
+let stack_offset = ref 0
+
+(* Layout of the stack frame *)
+
+let frame_required () =
+ !contains_calls || num_stack_slots.(0) > 0 || num_stack_slots.(1) > 0
+
+let frame_size () = (* includes return address *)
+ if frame_required() then begin
+ let sz =
+ (!stack_offset + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + 8)
+ in Misc.align sz 16
+ end else
+ !stack_offset + 8
+
+let slot_offset loc cl =
+ match loc with
+ Incoming n -> frame_size() + n
+ | Local n ->
+ if cl = 0
+ then !stack_offset + n * 8
+ else !stack_offset + (num_stack_slots.(0) + n) * 8
+ | Outgoing n -> n
+
+(* Symbols *)
+
+let emit_symbol s =
+ if macosx then emit_string "_";
+ Emitaux.emit_symbol '$' s
+
+let emit_call s =
+ `call {emit_symbol s}`
+
+let emit_jump s =
+ `jmp {emit_symbol s}`
+
+let load_symbol_addr s =
+ if !pic_code
+ then `leaq {emit_symbol s}(%rip)`
+ else `movq ${emit_symbol s}`
+
+(* Output a label *)
+
+let emit_label lbl =
+ emit_string ".L"; emit_int lbl
+
+(* Output a .align directive. *)
+
+let emit_align n =
+ let n = if macosx then Misc.log2 n else n in
+ ` .align {emit_int n}\n`
+
+let emit_Llabel fallthrough lbl =
+ if not fallthrough && !fastcode_flag then emit_align 4;
+ emit_label lbl
+
+(* Output a pseudo-register *)
+
+let emit_reg = function
+ { loc = Reg r } ->
+ emit_string (register_name r)
+ | { loc = Stack s } as r ->
+ let ofs = slot_offset s (register_class r) in
+ `{emit_int ofs}(%rsp)`
+ | { loc = Unknown } ->
+ assert false
+
+(* Output a reference to the lower 8, 16 or 32 bits of a register *)
+
+let reg_low_8_name =
+ [| "%al"; "%bl"; "%dil"; "%sil"; "%dl"; "%cl"; "%r8b"; "%r9b";
+ "%r10b"; "%r11b"; "%bpl"; "%r12b"; "%r13b" |]
+let reg_low_16_name =
+ [| "%ax"; "%bx"; "%di"; "%si"; "%dx"; "%cx"; "%r8w"; "%r9w";
+ "%r10w"; "%r11w"; "%bp"; "%r12w"; "%r13w" |]
+let reg_low_32_name =
+ [| "%eax"; "%ebx"; "%edi"; "%esi"; "%edx"; "%ecx"; "%r8d"; "%r9d";
+ "%r10d"; "%r11d"; "%ebp"; "%r12d"; "%r13d" |]
+
+let emit_subreg tbl r =
+ match r.loc with
+ Reg r when r < 13 ->
+ emit_string tbl.(r)
+ | Stack s ->
+ let ofs = slot_offset s (register_class r) in
+ `{emit_int ofs}(%rsp)`
+ | _ ->
+ assert false
+
+let emit_reg8 r = emit_subreg reg_low_8_name r
+let emit_reg16 r = emit_subreg reg_low_16_name r
+let emit_reg32 r = emit_subreg reg_low_32_name r
+
+(* Output an addressing mode *)
+
+let emit_addressing addr r n =
+ match addr with
+ | Ibased _ when !Clflags.dlcode -> assert false
+ | Ibased(s, d) ->
+ `{emit_symbol s}`;
+ if d <> 0 then ` + {emit_int d}`;
+ `(%rip)`
+ | Iindexed d ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)})`
+ | Iindexed2 d ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)}, {emit_reg r.(n+1)})`
+ | Iscaled(2, d) ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)}, {emit_reg r.(n)})`
+ | Iscaled(scale, d) ->
+ if d <> 0 then emit_int d;
+ `(, {emit_reg r.(n)}, {emit_int scale})`
+ | Iindexed2scaled(scale, d) ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)}, {emit_reg r.(n+1)}, {emit_int scale})`
+
+(* Record live pointers at call points -- see Emitaux *)
+
+let record_frame_label live dbg =
+ let lbl = new_label() in
+ let live_offset = ref [] in
+ Reg.Set.iter
+ (function
+ {typ = Addr; loc = Reg r} ->
+ live_offset := ((r lsl 1) + 1) :: !live_offset
+ | {typ = Addr; loc = Stack s} as reg ->
+ live_offset := slot_offset s (register_class reg) :: !live_offset
+ | _ -> ())
+ live;
+ frame_descriptors :=
+ { fd_lbl = lbl;
+ fd_frame_size = frame_size();
+ fd_live_offset = !live_offset;
+ fd_debuginfo = dbg } :: !frame_descriptors;
+ lbl
+
+let record_frame live dbg =
+ let lbl = record_frame_label live dbg in `{emit_label lbl}:\n`
+
+(* Record calls to the GC -- we've moved them out of the way *)
+
+type gc_call =
+ { gc_lbl: label; (* Entry label *)
+ gc_return_lbl: label; (* Where to branch after GC *)
+ gc_frame: label } (* Label of frame descriptor *)
+
+let call_gc_sites = ref ([] : gc_call list)
+
+let emit_call_gc gc =
+ `{emit_label gc.gc_lbl}: {emit_call "caml_call_gc"}\n`;
+ `{emit_label gc.gc_frame}: jmp {emit_label gc.gc_return_lbl}\n`
+
+(* Record calls to caml_ml_array_bound_error.
+ In -g mode, we maintain one call to caml_ml_array_bound_error
+ per bound check site. Without -g, we can share a single call. *)
+
+type bound_error_call =
+ { bd_lbl: label; (* Entry label *)
+ bd_frame: label } (* Label of frame descriptor *)
+
+let bound_error_sites = ref ([] : bound_error_call list)
+let bound_error_call = ref 0
+
+let bound_error_label dbg =
+ if !Clflags.debug then begin
+ let lbl_bound_error = new_label() in
+ let lbl_frame = record_frame_label Reg.Set.empty dbg in
+ bound_error_sites :=
+ { bd_lbl = lbl_bound_error; bd_frame = lbl_frame } :: !bound_error_sites;
+ lbl_bound_error
+ end else begin
+ if !bound_error_call = 0 then bound_error_call := new_label();
+ !bound_error_call
+ end
+
+let emit_call_bound_error bd =
+ `{emit_label bd.bd_lbl}: {emit_call "caml_ml_array_bound_error"}\n`;
+ `{emit_label bd.bd_frame}:\n`
+
+let emit_call_bound_errors () =
+ List.iter emit_call_bound_error !bound_error_sites;
+ if !bound_error_call > 0 then
+ `{emit_label !bound_error_call}: {emit_call "caml_ml_array_bound_error"}\n`
+
+(* Names for instructions *)
+
+let instr_for_intop = function
+ Iadd -> "addq"
+ | Isub -> "subq"
+ | Imul -> "imulq"
+ | Iand -> "andq"
+ | Ior -> "orq"
+ | Ixor -> "xorq"
+ | Ilsl -> "salq"
+ | Ilsr -> "shrq"
+ | Iasr -> "sarq"
+ | _ -> assert false
+
+let instr_for_floatop = function
+ Iaddf -> "addsd"
+ | Isubf -> "subsd"
+ | Imulf -> "mulsd"
+ | Idivf -> "divsd"
+ | _ -> assert false
+
+let instr_for_floatarithmem = function
+ Ifloatadd -> "addsd"
+ | Ifloatsub -> "subsd"
+ | Ifloatmul -> "mulsd"
+ | Ifloatdiv -> "divsd"
+
+let name_for_cond_branch = function
+ Isigned Ceq -> "e" | Isigned Cne -> "ne"
+ | Isigned Cle -> "le" | Isigned Cgt -> "g"
+ | Isigned Clt -> "l" | Isigned Cge -> "ge"
+ | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne"
+ | Iunsigned Cle -> "be" | Iunsigned Cgt -> "a"
+ | Iunsigned Clt -> "b" | Iunsigned Cge -> "ae"
+
+(* Output an = 0 or <> 0 test. *)
+
+let output_test_zero arg =
+ match arg.loc with
+ Reg r -> ` testq {emit_reg arg}, {emit_reg arg}\n`
+ | _ -> ` cmpq $0, {emit_reg arg}\n`
+
+(* Output a floating-point compare and branch *)
+
+let emit_float_test cmp neg arg lbl =
+ (* Effect of comisd on flags and conditional branches:
+ ZF PF CF cond. branches taken
+ unordered 1 1 1 je, jb, jbe, jp
+ > 0 0 0 jne, jae, ja
+ < 0 0 1 jne, jbe, jb
+ = 1 0 0 je, jae, jbe.
+ If FP traps are on (they are off by default),
+ comisd traps on QNaN and SNaN but ucomisd traps on SNaN only.
+ *)
+ match (cmp, neg) with
+ | (Ceq, false) | (Cne, true) ->
+ let next = new_label() in
+ ` ucomisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`;
+ ` jp {emit_label next}\n`; (* skip if unordered *)
+ ` je {emit_label lbl}\n`; (* branch taken if x=y *)
+ `{emit_label next}:\n`
+ | (Cne, false) | (Ceq, true) ->
+ ` ucomisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`;
+ ` jp {emit_label lbl}\n`; (* branch taken if unordered *)
+ ` jne {emit_label lbl}\n` (* branch taken if x<y or x>y *)
+ | (Clt, _) ->
+ ` comisd {emit_reg arg.(0)}, {emit_reg arg.(1)}\n`; (* swap compare *)
+ if not neg then
+ ` ja {emit_label lbl}\n` (* branch taken if y>x i.e. x<y *)
+ else
+ ` jbe {emit_label lbl}\n` (* taken if unordered or y<=x i.e. !(x<y) *)
+ | (Cle, _) ->
+ ` comisd {emit_reg arg.(0)}, {emit_reg arg.(1)}\n`; (* swap compare *)
+ if not neg then
+ ` jae {emit_label lbl}\n` (* branch taken if y>=x i.e. x<=y *)
+ else
+ ` jb {emit_label lbl}\n` (* taken if unordered or y<x i.e. !(x<=y) *)
+ | (Cgt, _) ->
+ ` comisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`;
+ if not neg then
+ ` ja {emit_label lbl}\n` (* branch taken if x>y *)
+ else
+ ` jbe {emit_label lbl}\n` (* taken if unordered or x<=y i.e. !(x>y) *)
+ | (Cge, _) ->
+ ` comisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`; (* swap compare *)
+ if not neg then
+ ` jae {emit_label lbl}\n` (* branch taken if x>=y *)
+ else
+ ` jb {emit_label lbl}\n` (* taken if unordered or x<y i.e. !(x>=y) *)
+
+(* Deallocate the stack frame before a return or tail call *)
+
+let output_epilogue () =
+ if frame_required() then begin
+ let n = frame_size() - 8 in
+ ` addq ${emit_int n}, %rsp\n`
+ end
+
+(* Output the assembly code for an instruction *)
+
+(* Name of current function *)
+let function_name = ref ""
+(* Entry point for tail recursive calls *)
+let tailrec_entry_point = ref 0
+
+let float_constants = ref ([] : (int * string) list)
+
+let emit_instr fallthrough i =
+ match i.desc with
+ Lend -> ()
+ | Lop(Imove | Ispill | Ireload) ->
+ let src = i.arg.(0) and dst = i.res.(0) in
+ if src.loc <> dst.loc then begin
+ if src.typ = Float then
+ ` movsd {emit_reg src}, {emit_reg dst}\n`
+ else
+ ` movq {emit_reg src}, {emit_reg dst}\n`
+ end
+ | Lop(Iconst_int n) ->
+ if n = 0n then begin
+ match i.res.(0).loc with
+ Reg n -> ` xorq {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
+ | _ -> ` movq $0, {emit_reg i.res.(0)}\n`
+ end else if n <= 0x7FFFFFFFn && n >= -0x80000000n then
+ ` movq ${emit_nativeint n}, {emit_reg i.res.(0)}\n`
+ else
+ ` movabsq ${emit_nativeint n}, {emit_reg i.res.(0)}\n`
+ | Lop(Iconst_float s) ->
+ begin match Int64.bits_of_float (float_of_string s) with
+ | 0x0000_0000_0000_0000L -> (* +0.0 *)
+ ` xorpd {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
+ | _ ->
+ let lbl = new_label() in
+ float_constants := (lbl, s) :: !float_constants;
+ ` movlpd {emit_label lbl}(%rip), {emit_reg i.res.(0)}\n`
+ end
+ | Lop(Iconst_symbol s) ->
+ ` {load_symbol_addr s}, {emit_reg i.res.(0)}\n`
+ | Lop(Icall_ind) ->
+ ` call *{emit_reg i.arg.(0)}\n`;
+ record_frame i.live i.dbg
+ | Lop(Icall_imm(s)) ->
+ ` {emit_call s}\n`;
+ record_frame i.live i.dbg
+ | Lop(Itailcall_ind) ->
+ output_epilogue();
+ ` jmp *{emit_reg i.arg.(0)}\n`
+ | Lop(Itailcall_imm s) ->
+ if s = !function_name then
+ ` jmp {emit_label !tailrec_entry_point}\n`
+ else begin
+ output_epilogue();
+ ` {emit_jump s}\n`
+ end
+ | Lop(Iextcall(s, alloc)) ->
+ if alloc then begin
+ ` {load_symbol_addr s}, %rax\n`;
+ ` {emit_call "caml_c_call"}\n`;
+ record_frame i.live i.dbg
+ end else begin
+ ` {emit_call s}\n`
+ end
+ | Lop(Istackoffset n) ->
+ if n < 0
+ then ` addq ${emit_int(-n)}, %rsp\n`
+ else ` subq ${emit_int(n)}, %rsp\n`;
+ stack_offset := !stack_offset + n
+ | Lop(Iload(chunk, addr)) ->
+ let dest = i.res.(0) in
+ begin match chunk with
+ | Word ->
+ ` movq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Byte_unsigned ->
+ ` movzbq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Byte_signed ->
+ ` movsbq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Sixteen_unsigned ->
+ ` movzwq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Sixteen_signed ->
+ ` movswq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Thirtytwo_unsigned ->
+ ` movl {emit_addressing addr i.arg 0}, {emit_reg32 dest}\n`
+ | Thirtytwo_signed ->
+ ` movslq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Single ->
+ ` cvtss2sd {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Double | Double_u ->
+ ` movlpd {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ end
+ | Lop(Istore(chunk, addr)) ->
+ begin match chunk with
+ | Word ->
+ ` movq {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Byte_unsigned | Byte_signed ->
+ ` movb {emit_reg8 i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Sixteen_unsigned | Sixteen_signed ->
+ ` movw {emit_reg16 i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Thirtytwo_signed | Thirtytwo_unsigned ->
+ ` movl {emit_reg32 i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Single ->
+ ` cvtsd2ss {emit_reg i.arg.(0)}, %xmm15\n`;
+ ` movss %xmm15, {emit_addressing addr i.arg 1}\n`
+ | Double | Double_u ->
+ ` movlpd {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ end
+ | Lop(Ialloc n) ->
+ if !fastcode_flag then begin
+ let lbl_redo = new_label() in
+ `{emit_label lbl_redo}: subq ${emit_int n}, %r15\n`;
+ if !Clflags.dlcode then begin
+ ` {load_symbol_addr "caml_young_limit"}, %rax\n`;
+ ` cmpq (%rax), %r15\n`;
+ end else
+ ` cmpq {emit_symbol "caml_young_limit"}(%rip), %r15\n`;
+ let lbl_call_gc = new_label() in
+ let lbl_frame = record_frame_label i.live Debuginfo.none in
+ ` jb {emit_label lbl_call_gc}\n`;
+ ` leaq 8(%r15), {emit_reg i.res.(0)}\n`;
+ call_gc_sites :=
+ { gc_lbl = lbl_call_gc;
+ gc_return_lbl = lbl_redo;
+ gc_frame = lbl_frame } :: !call_gc_sites
+ end else begin
+ begin match n with
+ 16 -> ` {emit_call "caml_alloc1"}\n`
+ | 24 -> ` {emit_call "caml_alloc2"}\n`
+ | 32 -> ` {emit_call "caml_alloc3"}\n`
+ | _ -> ` movq ${emit_int n}, %rax\n`;
+ ` {emit_call "caml_allocN"}\n`
+ end;
+ `{record_frame i.live Debuginfo.none} leaq 8(%r15), {emit_reg i.res.(0)}\n`
+ end
+ | Lop(Iintop(Icomp cmp)) ->
+ ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` set{emit_string b} %al\n`;
+ ` movzbq %al, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Icomp cmp, n)) ->
+ ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` set{emit_string b} %al\n`;
+ ` movzbq %al, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop Icheckbound) ->
+ let lbl = bound_error_label i.dbg in
+ ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`;
+ ` jbe {emit_label lbl}\n`
+ | Lop(Iintop_imm(Icheckbound, n)) ->
+ let lbl = bound_error_label i.dbg in
+ ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`;
+ ` jbe {emit_label lbl}\n`
+ | Lop(Iintop(Idiv | Imod)) ->
+ ` cqto\n`;
+ ` idivq {emit_reg i.arg.(1)}\n`
+ | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) ->
+ (* We have i.arg.(0) = i.res.(0) and i.arg.(1) = %rcx *)
+ ` {emit_string(instr_for_intop op)} %cl, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop op) ->
+ (* We have i.arg.(0) = i.res.(0) *)
+ ` {emit_string(instr_for_intop op)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Iadd, n)) when i.arg.(0).loc <> i.res.(0).loc ->
+ ` leaq {emit_int n}({emit_reg i.arg.(0)}), {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Iadd, 1) | Iintop_imm(Isub, -1)) ->
+ ` incq {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) ->
+ ` decq {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Idiv, n)) ->
+ (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
+ let l = Misc.log2 n in
+ ` movq {emit_reg i.arg.(0)}, %rax\n`;
+ ` addq ${emit_int(n-1)}, {emit_reg i.arg.(0)}\n`;
+ ` testq %rax, %rax\n`;
+ ` cmovns %rax, {emit_reg i.arg.(0)}\n`;
+ ` sarq ${emit_int l}, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Imod, n)) ->
+ (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
+ ` movq {emit_reg i.arg.(0)}, %rax\n`;
+ ` testq %rax, %rax\n`;
+ ` leaq {emit_int(n-1)}(%rax), %rax\n`;
+ ` cmovns {emit_reg i.arg.(0)}, %rax\n`;
+ ` andq ${emit_int (-n)}, %rax\n`;
+ ` subq %rax, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(op, n)) ->
+ (* We have i.arg.(0) = i.res.(0) *)
+ ` {emit_string(instr_for_intop op)} ${emit_int n}, {emit_reg i.res.(0)}\n`
+ | Lop(Inegf) ->
+ ` xorpd {emit_symbol "caml_negf_mask"}(%rip), {emit_reg i.res.(0)}\n`
+ | Lop(Iabsf) ->
+ ` andpd {emit_symbol "caml_absf_mask"}(%rip), {emit_reg i.res.(0)}\n`
+ | Lop(Iaddf | Isubf | Imulf | Idivf as floatop) ->
+ ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n`
+ | Lop(Ifloatofint) ->
+ ` cvtsi2sdq {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`
+ | Lop(Iintoffloat) ->
+ ` cvttsd2siq {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`
+ | Lop(Ispecific(Ilea addr)) ->
+ ` leaq {emit_addressing addr i.arg 0}, {emit_reg i.res.(0)}\n`
+ | Lop(Ispecific(Istore_int(n, addr))) ->
+ ` movq ${emit_nativeint n}, {emit_addressing addr i.arg 0}\n`
+ | Lop(Ispecific(Istore_symbol(s, addr))) ->
+ assert (not !pic_code && not !Clflags.dlcode);
+ ` movq ${emit_symbol s}, {emit_addressing addr i.arg 0}\n`
+ | Lop(Ispecific(Ioffset_loc(n, addr))) ->
+ ` addq ${emit_int n}, {emit_addressing addr i.arg 0}\n`
+ | Lop(Ispecific(Ifloatarithmem(op, addr))) ->
+ ` {emit_string(instr_for_floatarithmem op)} {emit_addressing addr i.arg 1}, {emit_reg i.res.(0)}\n`
+ | Lreloadretaddr ->
+ ()
+ | Lreturn ->
+ output_epilogue();
+ ` ret\n`
+ | Llabel lbl ->
+ `{emit_Llabel fallthrough lbl}:\n`
+ | Lbranch lbl ->
+ ` jmp {emit_label lbl}\n`
+ | Lcondbranch(tst, lbl) ->
+ begin match tst with
+ Itruetest ->
+ output_test_zero i.arg.(0);
+ ` jne {emit_label lbl}\n`
+ | Ifalsetest ->
+ output_test_zero i.arg.(0);
+ ` je {emit_label lbl}\n`
+ | Iinttest cmp ->
+ ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` j{emit_string b} {emit_label lbl}\n`
+ | Iinttest_imm((Isigned Ceq | Isigned Cne |
+ Iunsigned Ceq | Iunsigned Cne) as cmp, 0) ->
+ output_test_zero i.arg.(0);
+ let b = name_for_cond_branch cmp in
+ ` j{emit_string b} {emit_label lbl}\n`
+ | Iinttest_imm(cmp, n) ->
+ ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` j{emit_string b} {emit_label lbl}\n`
+ | Ifloattest(cmp, neg) ->
+ emit_float_test cmp neg i.arg lbl
+ | Ioddtest ->
+ ` testb $1, {emit_reg8 i.arg.(0)}\n`;
+ ` jne {emit_label lbl}\n`
+ | Ieventest ->
+ ` testb $1, {emit_reg8 i.arg.(0)}\n`;
+ ` je {emit_label lbl}\n`
+ end
+ | Lcondbranch3(lbl0, lbl1, lbl2) ->
+ ` cmpq $1, {emit_reg i.arg.(0)}\n`;
+ begin match lbl0 with
+ None -> ()
+ | Some lbl -> ` jb {emit_label lbl}\n`
+ end;
+ begin match lbl1 with
+ None -> ()
+ | Some lbl -> ` je {emit_label lbl}\n`
+ end;
+ begin match lbl2 with
+ None -> ()
+ | Some lbl -> ` jg {emit_label lbl}\n`
+ end
+ | Lswitch jumptbl ->
+ let lbl = new_label() in
+ (* rax and rdx are clobbered by the Lswitch,
+ meaning that no variable that is live across the Lswitch
+ is assigned to rax or rdx. However, the argument to Lswitch
+ can still be assigned to one of these two registers, so
+ we must be careful not to clobber it before use. *)
+ let (tmp1, tmp2) =
+ if i.arg.(0).loc = Reg 0 (* rax *)
+ then (phys_reg 4 (*rdx*), phys_reg 0 (*rax*))
+ else (phys_reg 0 (*rax*), phys_reg 4 (*rdx*)) in
+ ` leaq {emit_label lbl}(%rip), {emit_reg tmp1}\n`;
+ ` movslq ({emit_reg tmp1}, {emit_reg i.arg.(0)}, 4), {emit_reg tmp2}\n`;
+ ` addq {emit_reg tmp2}, {emit_reg tmp1}\n`;
+ ` jmp *{emit_reg tmp1}\n`;
+ if macosx
+ then ` .const\n`
+ else ` .section .rodata\n`;
+ emit_align 4;
+ `{emit_label lbl}:`;
+ for i = 0 to Array.length jumptbl - 1 do
+ ` .long {emit_label jumptbl.(i)} - {emit_label lbl}\n`
+ done;
+ ` .text\n`
+ | Lsetuptrap lbl ->
+ ` call {emit_label lbl}\n`
+ | Lpushtrap ->
+ ` pushq %r14\n`;
+ ` movq %rsp, %r14\n`;
+ stack_offset := !stack_offset + 16
+ | Lpoptrap ->
+ ` popq %r14\n`;
+ ` addq $8, %rsp\n`;
+ stack_offset := !stack_offset - 16
+ | Lraise ->
+ if !Clflags.debug then begin
+ ` {emit_call "caml_raise_exn"}\n`;
+ record_frame Reg.Set.empty i.dbg
+ end else begin
+ ` movq %r14, %rsp\n`;
+ ` popq %r14\n`;
+ ` ret\n`
+ end
+
+let rec emit_all fallthrough i =
+ match i.desc with
+ | Lend -> ()
+ | _ ->
+ emit_instr fallthrough i;
+ emit_all (Linearize.has_fallthrough i.desc) i.next
+
+(* Emission of the floating-point constants *)
+
+let emit_float_constant (lbl, cst) =
+ `{emit_label lbl}:`;
+ emit_float64_directive ".quad" cst
+
+(* Emission of the profiling prelude *)
+
+let emit_profile () =
+ match Config.system with
+ | "linux" | "gnu" ->
+ (* mcount preserves rax, rcx, rdx, rsi, rdi, r8, r9 explicitly
+ and rbx, rbp, r12-r15 like all C functions.
+ We need to preserve r10 and r11 ourselves, since Caml can
+ use them for argument passing. *)
+ ` pushq %r10\n`;
+ ` movq %rsp, %rbp\n`;
+ ` pushq %r11\n`;
+ ` {emit_call "mcount"}\n`;
+ ` popq %r11\n`;
+ ` popq %r10\n`
+ | _ ->
+ () (*unsupported yet*)
+
+(* Emission of a function declaration *)
+
+let fundecl fundecl =
+ function_name := fundecl.fun_name;
+ fastcode_flag := fundecl.fun_fast;
+ tailrec_entry_point := new_label();
+ stack_offset := 0;
+ float_constants := [];
+ call_gc_sites := [];
+ bound_error_sites := [];
+ bound_error_call := 0;
+ ` .text\n`;
+ emit_align 16;
+ if macosx
+ && not !Clflags.output_c_object
+ && is_generic_function fundecl.fun_name
+ then (* PR#4690 *)
+ ` .private_extern {emit_symbol fundecl.fun_name}\n`
+ else
+ ` .globl {emit_symbol fundecl.fun_name}\n`;
+ `{emit_symbol fundecl.fun_name}:\n`;
+ if !Clflags.gprofile then emit_profile();
+ if frame_required() then begin
+ let n = frame_size() - 8 in
+ ` subq ${emit_int n}, %rsp\n`
+ end;
+ `{emit_label !tailrec_entry_point}:\n`;
+ emit_all true fundecl.fun_body;
+ List.iter emit_call_gc !call_gc_sites;
+ emit_call_bound_errors ();
+ if !float_constants <> [] then begin
+ if macosx
+ then ` .literal8\n`
+ else ` .section .rodata.cst8,\"a\"\n`;
+ List.iter emit_float_constant !float_constants
+ end;
+ match Config.system with
+ "linux" | "gnu" ->
+ ` .size {emit_symbol fundecl.fun_name},.-{emit_symbol fundecl.fun_name}\n`
+ | _ -> ()
+
+(* Emission of data *)
+
+let emit_item = function
+ Cglobal_symbol s ->
+ ` .globl {emit_symbol s}\n`;
+ | Cdefine_symbol s ->
+ `{emit_symbol s}:\n`
+ | Cdefine_label lbl ->
+ `{emit_label (100000 + lbl)}:\n`
+ | Cint8 n ->
+ ` .byte {emit_int n}\n`
+ | Cint16 n ->
+ ` .word {emit_int n}\n`
+ | Cint32 n ->
+ ` .long {emit_nativeint n}\n`
+ | Cint n ->
+ ` .quad {emit_nativeint n}\n`
+ | Csingle f ->
+ emit_float32_directive ".long" f
+ | Cdouble f ->
+ emit_float64_directive ".quad" f
+ | Csymbol_address s ->
+ ` .quad {emit_symbol s}\n`
+ | Clabel_address lbl ->
+ ` .quad {emit_label (100000 + lbl)}\n`
+ | Cstring s ->
+ emit_string_directive " .ascii " s
+ | Cskip n ->
+ if n > 0 then ` .space {emit_int n}\n`
+ | Calign n ->
+ emit_align n
+
+let data l =
+ ` .data\n`;
+ List.iter emit_item l
+
+(* Beginning / end of an assembly file *)
+
+let begin_assembly() =
+ if !Clflags.dlcode then begin
+ (* from amd64.S; could emit these constants on demand *)
+ if macosx then
+ ` .literal16\n`
+ else
+ ` .section .rodata.cst8,\"a\"\n`;
+ emit_align 16;
+ `{emit_symbol "caml_negf_mask"}: .quad 0x8000000000000000, 0\n`;
+ emit_align 16;
+ `{emit_symbol "caml_absf_mask"}: .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF\n`
+ end;
+ let lbl_begin = Compilenv.make_symbol (Some "data_begin") in
+ ` .data\n`;
+ ` .globl {emit_symbol lbl_begin}\n`;
+ `{emit_symbol lbl_begin}:\n`;
+ let lbl_begin = Compilenv.make_symbol (Some "code_begin") in
+ ` .text\n`;
+ ` .globl {emit_symbol lbl_begin}\n`;
+ `{emit_symbol lbl_begin}:\n`;
+ if macosx then ` nop\n` (* PR#4690 *)
+
+let end_assembly() =
+ let lbl_end = Compilenv.make_symbol (Some "code_end") in
+ ` .text\n`;
+ if macosx then ` nop\n`; (* suppress "ld warning: atom sorting error" *)
+ ` .globl {emit_symbol lbl_end}\n`;
+ `{emit_symbol lbl_end}:\n`;
+ ` .data\n`;
+ let lbl_end = Compilenv.make_symbol (Some "data_end") in
+ ` .globl {emit_symbol lbl_end}\n`;
+ `{emit_symbol lbl_end}:\n`;
+ ` .long 0\n`;
+ let lbl = Compilenv.make_symbol (Some "frametable") in
+ ` .globl {emit_symbol lbl}\n`;
+ `{emit_symbol lbl}:\n`;
+ emit_frames
+ { efa_label = (fun l -> ` .quad {emit_label l}\n`);
+ efa_16 = (fun n -> ` .word {emit_int n}\n`);
+ efa_32 = (fun n -> ` .long {emit_int32 n}\n`);
+ efa_word = (fun n -> ` .quad {emit_int n}\n`);
+ efa_align = emit_align;
+ efa_label_rel =
+ if macosx then begin
+ let setcnt = ref 0 in
+ fun lbl ofs ->
+ incr setcnt;
+ ` .set L$set${emit_int !setcnt}, ({emit_label lbl} - .) + {emit_int32 ofs}\n`;
+ ` .long L$set${emit_int !setcnt}\n`
+ end else begin
+ fun lbl ofs ->
+ ` .long ({emit_label lbl} - .) + {emit_int32 ofs}\n`
+ end;
+ efa_def_label = (fun l -> `{emit_label l}:\n`);
+ efa_string = (fun s -> emit_string_directive " .asciz " s) };
+ if Config.system = "linux" then
+ (* Mark stack as non-executable, PR#4564 *)
+ ` .section .note.GNU-stack,\"\"\n`
diff --git a/ocaml/3.12/asmcomp/amd64/proc_mingw64.ml b/ocaml/3.12/asmcomp/amd64/proc_mingw64.ml
new file mode 100644
index 0000000..338e169
--- /dev/null
+++ b/ocaml/3.12/asmcomp/amd64/proc_mingw64.ml
@@ -0,0 +1,233 @@
+(***********************************************************************)
+(* *)
+(* Objective Caml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 2000 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: proc.ml 9547 2010-01-22 12:48:24Z doligez $ *)
+
+(* Description of the AMD64 processor with Win64 conventions *)
+
+open Misc
+open Arch
+open Cmm
+open Reg
+open Mach
+
+(* Registers available for register allocation *)
+
+(* Register map:
+ rax 0 rax - r11: Caml function arguments
+ rbx 1 rcx - r9: C function arguments
+ rdi 2 rax: Caml and C function results
+ rsi 3 rbx, rbp, rsi, rdi r12-r15 are preserved by C
+ rdx 4
+ rcx 5
+ r8 6
+ r9 7
+ r10 8
+ r11 9
+ rbp 10
+ r12 11
+ r13 12
+ r14 trap pointer
+ r15 allocation pointer
+
+ xmm0 - xmm15 100 - 115 xmm0 - xmm9: Caml function arguments
+ xmm0 - xmm3: C function arguments
+ xmm0: Caml and C function results
+ xmm6-xmm15 are preserved by C *)
+
+let int_reg_name =
+ [| "%rax"; "%rbx"; "%rdi"; "%rsi"; "%rdx"; "%rcx"; "%r8"; "%r9";
+ "%r10"; "%r11"; "%rbp"; "%r12"; "%r13" |]
+
+let float_reg_name =
+ [| "%xmm0"; "%xmm1"; "%xmm2"; "%xmm3"; "%xmm4"; "%xmm5"; "%xmm6"; "%xmm7";
+ "%xmm8"; "%xmm9"; "%xmm10"; "%xmm11";
+ "%xmm12"; "%xmm13"; "%xmm14"; "%xmm15" |]
+
+let num_register_classes = 2
+
+let register_class r =
+ match r.typ with
+ Int -> 0
+ | Addr -> 0
+ | Float -> 1
+
+let num_available_registers = [| 13; 16 |]
+
+let first_available_register = [| 0; 100 |]
+
+let register_name r =
+ if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100)
+
+(* Pack registers starting at %rax so as to reduce the number of REX
+ prefixes and thus improve code density *)
+let rotate_registers = false
+
+(* Representation of hard registers by pseudo-registers *)
+
+let hard_int_reg =
+ let v = Array.create 13 Reg.dummy in
+ for i = 0 to 12 do v.(i) <- Reg.at_location Int (Reg i) done;
+ v
+
+let hard_float_reg =
+ let v = Array.create 16 Reg.dummy in
+ for i = 0 to 15 do v.(i) <- Reg.at_location Float (Reg (100 + i)) done;
+ v
+
+let all_phys_regs =
+ Array.append hard_int_reg hard_float_reg
+
+let phys_reg n =
+ if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100)
+
+let rax = phys_reg 0
+let rcx = phys_reg 5
+let rdx = phys_reg 4
+let r11 = phys_reg 9
+let rxmm15 = phys_reg 115
+
+let stack_slot slot ty =
+ Reg.at_location ty (Stack slot)
+
+(* Instruction selection *)
+
+let word_addressed = false
+
+(* Calling conventions *)
+
+let calling_conventions first_int last_int first_float last_float make_stack
+ arg =
+ let loc = Array.create (Array.length arg) Reg.dummy in
+ let int = ref first_int in
+ let float = ref first_float in
+ let ofs = ref 0 in
+ for i = 0 to Array.length arg - 1 do
+ match arg.(i).typ with
+ Int | Addr as ty ->
+ if !int <= last_int then begin
+ loc.(i) <- phys_reg !int;
+ incr int
+ end else begin
+ loc.(i) <- stack_slot (make_stack !ofs) ty;
+ ofs := !ofs + size_int
+ end
+ | Float ->
+ if !float <= last_float then begin
+ loc.(i) <- phys_reg !float;
+ incr float
+ end else begin
+ loc.(i) <- stack_slot (make_stack !ofs) Float;
+ ofs := !ofs + size_float
+ end
+ done;
+ (loc, Misc.align !ofs 16) (* keep stack 16-aligned *)
+
+let incoming ofs = Incoming ofs
+let outgoing ofs = Outgoing ofs
+let not_supported ofs = fatal_error "Proc.loc_results: cannot call"
+
+let loc_arguments arg =
+ calling_conventions 0 9 100 109 outgoing arg
+let loc_parameters arg =
+ let (loc, ofs) = calling_conventions 0 9 100 109 incoming arg in loc
+let loc_results res =
+ let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc
+
+(* C calling conventions (Win64):
+ first integer args in rcx, rdx, r8, r9 (4 - 7)
+ first float args in xmm0 ... xmm3 (100 - 103)
+ each integer arg consumes a float reg, and conversely
+ remaining args on stack
+ always 32 bytes reserved at bottom of stack.
+ Return value in rax or xmm0
+*)
+
+let loc_external_results res =
+ let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc
+
+let int_external_arguments =
+ [| 5 (*rcx*); 4 (*rdx*); 6 (*r8*); 7 (*r9*) |]
+let float_external_arguments =
+ [| 100 (*xmm0*); 101 (*xmm1*); 102 (*xmm2*); 103 (*xmm3*) |]
+
+let loc_external_arguments arg =
+ let loc = Array.create (Array.length arg) Reg.dummy in
+ let reg = ref 0
+ and ofs = ref 32 in
+ for i = 0 to Array.length arg - 1 do
+ match arg.(i).typ with
+ Int | Addr as ty ->
+ if !reg < 4 then begin
+ loc.(i) <- phys_reg int_external_arguments.(!reg);
+ incr reg
+ end else begin
+ loc.(i) <- stack_slot (Outgoing !ofs) ty;
+ ofs := !ofs + size_int
+ end
+ | Float ->
+ if !reg < 4 then begin
+ loc.(i) <- phys_reg float_external_arguments.(!reg);
+ incr reg
+ end else begin
+ loc.(i) <- stack_slot (Outgoing !ofs) Float;
+ ofs := !ofs + size_float
+ end
+ done;
+ (loc, Misc.align !ofs 16) (* keep stack 16-aligned *)
+
+let loc_exn_bucket = rax
+
+(* Registers destroyed by operations *)
+
+let destroyed_at_c_call =
+ (* Win64: rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 preserved *)
+ Array.of_list(List.map phys_reg
+ [0;4;5;6;7;8;9;
+ 100;101;102;103;104;105])
+
+let destroyed_at_oper = function
+ Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs
+ | Iop(Iextcall(_, false)) -> destroyed_at_c_call
+ | Iop(Iintop(Idiv | Imod)) -> [| rax; rdx |]
+ | Iop(Istore(Single, _)) -> [| rxmm15 |]
+ | Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _))
+ -> [| rax |]
+ | Iswitch(_, _) when !pic_code -> [| r11 |]
+ | _ -> [||]
+
+let destroyed_at_raise = all_phys_regs
+
+(* Maximal register pressure *)
+
+let safe_register_pressure = function
+ Iextcall(_,_) -> 8
+ | _ -> 11
+
+let max_register_pressure = function
+ Iextcall(_, _) -> [| 8; 10 |]
+ | Iintop(Idiv | Imod) -> [| 11; 16 |]
+ | Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _)
+ -> [| 12; 16 |]
+ | Istore(Single, _) -> [| 13; 15 |]
+ | _ -> [| 13; 16 |]
+
+(* Layout of the stack frame *)
+
+let num_stack_slots = [| 0; 0 |]
+let contains_calls = ref false
+
+(* Calling the assembler *)
+
+let assemble_file infile outfile =
+ Ccomp.command (Config.asm ^ " -o " ^
+ Filename.quote outfile ^ " " ^ Filename.quote infile)
diff --git a/ocaml/3.12/build.sh b/ocaml/3.12/build.sh
new file mode 100755
index 0000000..a26083e
--- /dev/null
+++ b/ocaml/3.12/build.sh
@@ -0,0 +1,15 @@
+# fix settings
+cp config/m-nt.h config/m.h || exit 1
+cp config/s-nt.h config/s.h || exit 1
+cp config/Makefile.mingw64 config/Makefile || exit 1
+
+# fix asmcomp
+cp asmcomp/amd64/emit_mingw64.mlp asmcomp/amd64/emit.mlp || exit 1
+cp asmcomp/amd64/proc_mingw64.ml asmcomp/amd64/proc.ml || exit 1
+
+# run make
+gmake -f Makefile.nt world || exit 1
+gmake -f Makefile.nt bootstrap || exit 1
+gmake -f Makefile.nt opt || exit 1
+gmake -f Makefile.nt opt.opt || exit 1
+gmake -f Makefile.nt install || exit 1
\ No newline at end of file
diff --git a/ocaml/3.12/config/Makefile.mingw64 b/ocaml/3.12/config/Makefile.mingw64
new file mode 100644
index 0000000..cf17d41
--- /dev/null
+++ b/ocaml/3.12/config/Makefile.mingw64
@@ -0,0 +1,158 @@
+#########################################################################
+# #
+# Objective Caml #
+# #
+# Xavier Leroy, projet Cristal, INRIA Rocquencourt #
+# #
+# Copyright 1999 Institut National de Recherche en Informatique et #
+# en Automatique. All rights reserved. This file is distributed #
+# under the terms of the GNU Library General Public License, with #
+# the special exception on linking described in file ../LICENSE. #
+# #
+#########################################################################
+
+# $Id: Makefile.mingw 10461 2010-05-25 10:00:39Z frisch $
+
+# Configuration for Windows, Mingw compiler
+
+######### General configuration
+
+PREFIX=C:/ocamlmgw
+
+### Where to install the binaries
+BINDIR=$(PREFIX)/bin
+
+### Where to install the standard library
+LIBDIR=$(PREFIX)/lib
+
+### Where to install the stub DLLs
+STUBLIBDIR=$(LIBDIR)/stublibs
+
+### Where to install the info files
+DISTRIB=$(PREFIX)
+
+### Where to install the man pages
+MANDIR=$(PREFIX)/man
+
+########## Toolchain and OS dependencies
+
+TOOLCHAIN=mingw
+CCOMPTYPE=cc
+O=o
+A=a
+S=s
+SO=s.o
+DO=d.o
+EXE=.exe
+EXT_DLL=.dll
+EXT_OBJ=.$(O)
+EXT_LIB=.$(A)
+EXT_ASM=.$(S)
+MANEXT=1
+SHARPBANGSCRIPTS=false
+PTHREAD_LINK=
+X11_INCLUDES=
+X11_LINK=
+DBM_INCLUDES=
+DBM_LINK=
+BYTECCRPATH=
+SUPPORTS_SHARED_LIBRARIES=true
+SHAREDCCCOMPOPTS=
+MKSHAREDLIBRPATH=
+NATIVECCPROFOPTS=
+NATIVECCRPATH=
+ASM=as
+ASPP=gcc
+ASPPPROFFLAGS=
+PROFILING=noprof
+DYNLINKOPTS=
+DEBUGGER=ocamldebugger
+CC_PROFILE=
+SYSTHREAD_SUPPORT=true
+EXTRALIBS=
+NATDYNLINK=true
+CMXS=cmxs
+
+########## Configuration for the bytecode compiler
+
+### Which C compiler to use for the bytecode interpreter.
+BYTECC=gcc -mno-cygwin
+
+### Additional compile-time options for $(BYTECC). (For static linking.)
+BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+
+### Additional link-time options for $(BYTECC). (For static linking.)
+BYTECCLINKOPTS=
+
+### Additional compile-time options for $(BYTECC). (For building a DLL.)
+DLLCCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused -DCAML_DLL
+
+### Libraries needed
+BYTECCLIBS=-lws2_32
+NATIVECCLIBS=-lws2_32
+
+### How to invoke the C preprocessor
+CPP=$(BYTECC) -E
+
+### Flexlink
+FLEXLINK=flexlink -chain mingw64 -LC:/mingw64/x86_64-w64-mingw32/lib
+FLEXDIR=$(shell $(FLEXLINK) -where)
+IFLEXDIR=-I"$(FLEXDIR)"
+MKDLL=$(FLEXLINK)
+MKEXE=$(FLEXLINK) -exe
+MKMAINDLL=$(FLEXLINK) -maindll
+
+### How to build a static library
+MKLIB=rm -f $(1); ar rcs $(1) $(2)
+#ml let mklib out files opts = Printf.sprintf "rm -f %s && ar rcs %s %s %s" out opts out files;;
+
+### Canonicalize the name of a system library
+SYSLIB=-l$(1)
+#ml let syslib x = "-l"^x;;
+
+### The ranlib command
+RANLIB=ranlib
+RANLIBCMD=ranlib
+
+############# Configuration for the native-code compiler
+
+### Name of architecture for the native-code compiler
+ARCH=amd64
+
+### Name of architecture model for the native-code compiler.
+MODEL=default
+
+### Name of operating system family for the native-code compiler.
+SYSTEM=mingw64
+
+### Which C compiler to use for the native-code compiler.
+NATIVECC=$(BYTECC)
+
+### Additional compile-time options for $(NATIVECC).
+NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+
+### Additional link-time options for $(NATIVECC)
+NATIVECCLINKOPTS=
+
+### Build partially-linked object file
+PACKLD=ld -r $(NATIVECCLINKOPTS) -o #there must be a space after this '-o'
+
+############# Configuration for the contributed libraries
+
+OTHERLIBRARIES=win32unix str num win32graph dynlink bigarray systhreads
+
+### Name of the target architecture for the "num" library
+BNG_ARCH=generic
+BNG_ASM_LEVEL=0
+
+### Configuration for LablTk
+# Set TK_ROOT to the directory where you installed TCL/TK 8.5
+# There must be no spaces or special characters in $(TK_ROOT)
+TK_ROOT=c:/tcl
+TK_DEFS=-I$(TK_ROOT)/include
+TK_LINK=$(TK_ROOT)/bin/tk85.dll $(TK_ROOT)/bin/tcl85.dll -lws2_32
+
+############# Aliases for common commands
+
+MAKEREC=$(MAKE) -f Makefile.nt
+MAKECMD=$(MAKE)
diff --combined ocaml/flexdll/cmdline.ml
index eccd13e,ae96a0e..0000000
--- a/ocaml/flexdll/cmdline.ml
+++ b/ocaml/flexdll/cmdline.ml
@@@ -18,7 -18,7 +18,7 @@@ let use_default_libs = ref tru
let subsystem = ref "console"
let explain = ref false
let builtin_linker = ref false
-let toolchain : [ `MSVC | `MSVC64 | `MINGW | `CYGWIN | `LIGHTLD ] ref = ref `MSVC
+let toolchain : [ `MSVC | `MSVC64 | `MINGW | `MINGW64 | `CYGWIN | `LIGHTLD ] ref = ref `MSVC
let save_temps = ref false
let show_exports = ref false
let show_imports = ref false
@@@ -87,7 -87,7 +87,7 @@@ let specs =
"-l", Arg.String (fun s -> files := ("-l" ^ s) :: !files),
"<lib> Library file";
- "-chain", Arg.Symbol (["msvc";"msvc64";"cygwin";"mingw";"ld"],
+ "-chain", Arg.Symbol (["msvc";"msvc64";"cygwin";"mingw";"mingw64";"ld"],
(fun s ->
machine := `x86; underscore := true;
toolchain := match s with
@@@ -95,7 -95,6 +95,7 @@@
| "msvc64" -> machine := `x64; underscore := false; `MSVC64
| "cygwin" -> `CYGWIN
| "mingw" -> `MINGW
+ | "mingw64" -> machine := `x64; underscore := false; `MINGW64
| "ld" -> `LIGHTLD
| _ -> assert false)),
" Choose which linker to use";
diff --combined ocaml/flexdll/reloc.ml
index eb331dc,9a37b5b..0000000
--- a/ocaml/flexdll/reloc.ml
+++ b/ocaml/flexdll/reloc.ml
@@@ -112,7 -112,7 +112,7 @@@ type cmdline =
let new_cmdline () =
let rf = match !toolchain with
| `MSVC | `MSVC64 | `LIGHTLD -> true
- | `MINGW | `CYGWIN -> false
+ | `MINGW | `MINGW64 | `CYGWIN -> false
in
{
may_use_response_file = rf;
@@@ -160,7 -160,7 +160,7 @@@ let cygpath l
let gcclib () =
let extra = match !toolchain with
- | `MINGW -> "-mno-cygwin "
+ | `MINGW | `MINGW64 -> "-mno-cygwin "
| _ -> ""
in
Filename.dirname (get_output1 ~use_bash:(!toolchain = `CYGWIN) (Printf.sprintf "gcc %s-print-libgcc-file-name" extra))
@@@ -492,7 -492,7 +492,7 @@@ let parse_dll_exports fn
let dll_exports fn = match !toolchain with
| `MSVC | `MSVC64 | `LIGHTLD ->
failwith "Creation of import library not supported for this toolchain"
- | `CYGWIN | `MINGW ->
+ | `CYGWIN | `MINGW | `MINGW64 ->
let dmp = temp_file "dyndll" ".dmp" in
if cmd_verbose (Printf.sprintf "objdump -p %s > %s" fn dmp) <> 0
then failwith "Error while extracting exports from a DLL";
@@@ -898,7 -898,7 +898,7 @@@ let build_dll link_exe output_file file
files
def_file
extra_args
- | `MINGW ->
+ | `MINGW | `MINGW64 ->
let def_file =
if main_pgm then ""
else
@@@ -911,7 -911,7 +911,7 @@@
"gcc -mno-cygwin -m%s %s%s -L. %s %s -o %s %s %s %s %s %s"
!subsystem
(if link_exe = `EXE then "" else "-shared ")
- (if main_pgm then "" else if !noentry then "-Wl,-e0 " else "-Wl,-e_FlexDLLiniter@12 ")
+ (if main_pgm then "" else if !noentry then "-Wl,-e0 " else match !machine with | `x86 -> "-Wl,-e_FlexDLLiniter@12 " | `x64 -> "-Wl,-e_FlexDLLiniter " )
(mk_dirs_opt "-I")
(mk_dirs_opt "-L")
(Filename.quote output_file)
@@@ -983,7 -983,7 +983,7 @@@ let setup_toolchain ()
parse_libpath (try Sys.getenv "LIB" with Not_found -> "");
if not !custom_crt then
default_libs := ["msvcrt.lib"]
- | `MINGW ->
+ | `MINGW | `MINGW64 ->
search_path :=
!dirs @
[ "/lib/mingw";
@@@ -1015,7 -1015,7 +1015,7 @@@ let compile_if_needed file
(Filename.quote tmp_obj)
(mk_dirs_opt "-I")
file
- | `MINGW ->
+ | `MINGW | `MINGW64 ->
Printf.sprintf
"gcc -mno-cygwin -c -o %s %s %s"
(Filename.quote tmp_obj)
@@@ -1054,7 -1054,6 +1054,7 @@@ let all_files ()
| `MSVC -> "msvc.obj"
| `MSVC64 -> "msvc64.obj"
| `CYGWIN -> "cygwin.o"
+ | `MINGW64 -> "mingw64.o"
| `MINGW | `LIGHTLD -> "mingw.o" in
if !exe_mode <> `DLL then
if !add_flexdll_obj then f ("flexdll_" ^ tc) :: files
@@@ -1073,7 -1072,7 +1073,7 @@@ let main ()
| _, `Yes -> true
| _, `No -> false
| `CYGWIN, `None -> (Sys.command "cygpath -v 2>/dev/null >/dev/null" = 0)
- | `MINGW, `None -> (Sys.command "cygpath -v 2>NUL >NUL" = 0)
+ | (`MINGW|`MINGW64), `None -> (Sys.command "cygpath -v 2>NUL >NUL" = 0)
| (`MSVC|`MSVC64|`LIGHTLD), `None -> false
end;
diff --git a/ocaml/flexdll/version.ml b/ocaml/flexdll/version.ml
new file mode 100755
index 0000000..47eaa2f
--- /dev/null
+++ b/ocaml/flexdll/version.ml
@@ -0,0 +1 @@
+let version = "0.26"
Index: cmdline.ml
===================================================================
--- cmdline.ml (revision 195)
+++ cmdline.ml (working copy)
@@ -18,7 +18,7 @@
let subsystem = ref "console"
let explain = ref false
let builtin_linker = ref false
-let toolchain : [ `MSVC | `MSVC64 | `MINGW | `CYGWIN | `LIGHTLD ] ref = ref `MSVC
+let toolchain : [ `MSVC | `MSVC64 | `MINGW | `MINGW64 | `CYGWIN | `LIGHTLD ] ref = ref `MSVC
let save_temps = ref false
let show_exports = ref false
let show_imports = ref false
@@ -87,7 +87,7 @@
"-l", Arg.String (fun s -> files := ("-l" ^ s) :: !files),
"<lib> Library file";
- "-chain", Arg.Symbol (["msvc";"msvc64";"cygwin";"mingw";"ld"],
+ "-chain", Arg.Symbol (["msvc";"msvc64";"cygwin";"mingw";"mingw64";"ld"],
(fun s ->
machine := `x86; underscore := true;
toolchain := match s with
@@ -95,6 +95,7 @@
| "msvc64" -> machine := `x64; underscore := false; `MSVC64
| "cygwin" -> `CYGWIN
| "mingw" -> `MINGW
+ | "mingw64" -> machine := `x64; underscore := false; `MINGW64
| "ld" -> `LIGHTLD
| _ -> assert false)),
" Choose which linker to use";
Index: reloc.ml
===================================================================
--- reloc.ml (revision 195)
+++ reloc.ml (working copy)
@@ -112,7 +112,7 @@
let new_cmdline () =
let rf = match !toolchain with
| `MSVC | `MSVC64 | `LIGHTLD -> true
- | `MINGW | `CYGWIN -> false
+ | `MINGW | `MINGW64 | `CYGWIN -> false
in
{
may_use_response_file = rf;
@@ -160,10 +160,11 @@
let gcclib () =
let extra = match !toolchain with
- | `MINGW -> "-mno-cygwin "
+ | `MINGW -> "i686-w64-mingw32-"
+ | `MINGW64 -> "x86_64-w64-mingw32-"
| _ -> ""
in
- Filename.dirname (get_output1 ~use_bash:(!toolchain = `CYGWIN) (Printf.sprintf "gcc %s-print-libgcc-file-name" extra))
+ Filename.dirname (get_output1 ~use_bash:(!toolchain = `CYGWIN) (Printf.sprintf "%sgcc -print-libgcc-file-name" extra))
let file_exists fn =
if Sys.file_exists fn && not (Sys.is_directory fn) then Some fn
@@ -301,6 +302,7 @@
| `x64, 0x04 -> 0x0001 (* rel32 *)
| `x64, 0x05 -> 0x0004 (* rel32_1 *)
| `x64, 0x08 -> 0x0003 (* rel32_4 *)
+ | `x64, 0x06 -> 0x0005 (* rel32_2 *)
| `x86, (0x0a | 0x0b) -> 0x0100 (* debug relocs: ignore *)
| _, k ->
let msg =
@@ -492,9 +494,10 @@
let dll_exports fn = match !toolchain with
| `MSVC | `MSVC64 | `LIGHTLD ->
failwith "Creation of import library not supported for this toolchain"
- | `CYGWIN | `MINGW ->
+ | `CYGWIN | `MINGW | `MINGW64 ->
let dmp = temp_file "dyndll" ".dmp" in
- if cmd_verbose (Printf.sprintf "objdump -p %s > %s" fn dmp) <> 0
+ let pre = if !toolchain = `MINGW64 then "x86_64-w64-mingw32-" else "" in
+ if cmd_verbose (Printf.sprintf "%sobjdump -p %s > %s" pre fn dmp) <> 0
then failwith "Error while extracting exports from a DLL";
parse_dll_exports dmp
@@ -898,7 +901,7 @@
files
def_file
extra_args
- | `MINGW ->
+ | `MINGW | `MINGW64 ->
let def_file =
if main_pgm then ""
else
@@ -908,10 +911,11 @@
Filename.quote def_file
in
Printf.sprintf
- "gcc -mno-cygwin -m%s %s%s -L. %s %s -o %s %s %s %s %s %s"
+ "%s-w64-mingw32-gcc -m%s %s%s -L. %s %s -o %s %s %s %s %s %s"
+ (if !toolchain = `MINGW then "i686" else "x86_64")
!subsystem
(if link_exe = `EXE then "" else "-shared ")
- (if main_pgm then "" else if !noentry then "-Wl,-e0 " else "-Wl,-e_FlexDLLiniter@12 ")
+ (if main_pgm then "" else if !noentry then "-Wl,-e0 " else if !machine = `x86 then "-Wl,-e_FlexDLLiniter@12 " else "-Wl,-eFlexDLLiniter ")
(mk_dirs_opt "-I")
(mk_dirs_opt "-L")
(Filename.quote output_file)
@@ -983,13 +987,18 @@
parse_libpath (try Sys.getenv "LIB" with Not_found -> "");
if not !custom_crt then
default_libs := ["msvcrt.lib"]
- | `MINGW ->
+ | `MINGW | `MINGW64 ->
search_path :=
!dirs @
+ (if !toolchain = `MINGW then
[ "/lib/mingw";
"/lib";
- "/lib/w32api";
- gcclib () ];
+ "/lib/w32api";
+ "/usr/i686-w64-mingw32/sys-root/mingw/lib" ]
+ else
+ [ "/usr/x86_64-w64-mingw32/sys-root/mingw/lib" ]
+ ) @
+ [ gcclib () ];
default_libs :=
["-lmingw32"; "-lgcc"; "-lmoldname"; "-lmingwex"; "-lmsvcrt";
"-luser32"; "-lkernel32"; "-ladvapi32"; "-lshell32" ];
@@ -1015,12 +1024,13 @@
(Filename.quote tmp_obj)
(mk_dirs_opt "-I")
file
- | `MINGW ->
+ | `MINGW | `MINGW64 ->
Printf.sprintf
- "gcc -mno-cygwin -c -o %s %s %s"
+ "%s-w64-mingw32-gcc -c -o %s %s %s"
+ (if !toolchain = `MINGW then "i686" else "x86_64")
(Filename.quote tmp_obj)
(mk_dirs_opt "-I")
- file
+ (Filename.quote file)
| `LIGHTLD ->
failwith "Compilation of C code is not supported for this toolchain"
in
@@ -1054,6 +1064,7 @@
| `MSVC -> "msvc.obj"
| `MSVC64 -> "msvc64.obj"
| `CYGWIN -> "cygwin.o"
+ | `MINGW64 -> "mingw64.o"
| `MINGW | `LIGHTLD -> "mingw.o" in
if !exe_mode <> `DLL then
if !add_flexdll_obj then f ("flexdll_" ^ tc) :: files
@@ -1072,7 +1083,7 @@
| _, `Yes -> true
| _, `No -> false
| `CYGWIN, `None -> (Sys.command "cygpath -v 2>/dev/null >/dev/null" = 0)
- | `MINGW, `None -> (Sys.command "cygpath -v 2>NUL >NUL" = 0)
+ | (`MINGW|`MINGW64), `None -> (Sys.command "cygpath -v 2>NUL >NUL" = 0)
| (`MSVC|`MSVC64|`LIGHTLD), `None -> false
end;
Index: flexdll.c
===================================================================
--- flexdll.c (revision 195)
+++ flexdll.c (working copy)
@@ -21,6 +21,7 @@
#define RELOC_ABS 0x0002
#define RELOC_REL32_4 0x0003
#define RELOC_REL32_1 0x0004
+#define RELOC_REL32_2 0x0005
#define RELOC_DONE 0x0100
typedef struct { UINT_PTR kind; char *name; UINT_PTR *addr; } reloc_entry;
@@ -143,7 +144,7 @@
pagesize = si.dwPageSize;
}
- begin -= (uintnat) begin % pagesize;
+ begin -= (size_t) begin % pagesize;
res = VirtualProtect(begin, end - begin, new, (uintnat*) old);
if (0 == res) {
fprintf(stderr, "natdynlink: VirtualProtect failed (%s), begin = 0x%p, end = 0x%p\n", ll_dlerror(), begin, end);
@@ -211,6 +212,15 @@
}
*((UINT32*) ptr->addr) = s;
break;
+ case RELOC_REL32_2:
+ s -= (INT_PTR)(ptr -> addr) + 6;
+ if (s != (INT32) s) {
+ printf("flexdll error: cannot relocate, target is too far: %p\n", s);
+ fflush(stdout);
+ exit(1);
+ }
+ *((UINT32*) ptr->addr) = s;
+ break;
default:
fprintf(stderr, "flexdll: unknown relocation kind");
exit(2);
Index: Makefile
===================================================================
--- Makefile (revision 195)
+++ Makefile (working copy)
@@ -1,4 +1,4 @@
-VERSION = 0.26
+VERSION = 0.26+mingw64
all: flexlink.exe support
include $(shell cygpath -ad "$(shell ocamlopt -where)/Makefile.config")
@@ -9,7 +9,8 @@
# Supported tool-chains
-CHAINS = mingw cygwin msvc msvc64
+#CHAINS = mingw mingw64 cygwin msvc msvc64
+CHAINS = mingw mingw64 cygwin
# Compilers
@@ -33,7 +34,9 @@
MSVCC = $(MSVCC_ROOT)/cl.exe /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
MSVCC64 = $(MSVCC_ROOT)/amd64/cl.exe /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
CYGCC = gcc
-MINCC = gcc -mno-cygwin
+#MINCC = gcc -mno-cygwin
+MINCC = i686-w64-mingw32-gcc
+MIN64CC = x86_64-w64-mingw32-gcc
OCAMLOPT = ocamlopt
#OCAMLOPT = FLEXLINKFLAGS=-real-manifest ocamlopt
#LINKFLAGS = unix.cmxa
@@ -51,15 +54,19 @@
build_msvc64: flexdll_msvc64.obj flexdll_initer_msvc64.obj
build_cygwin: flexdll_cygwin.o flexdll_initer_cygwin.o
build_mingw: flexdll_mingw.o flexdll_initer_mingw.o
+build_mingw64: flexdll_mingw64.o flexdll_initer_mingw64.o
OBJS = version.ml coff.ml cmdline.ml create_dll.ml reloc.ml
-flexlink.exe: $(OBJS)
+flexlink.exe: $(OBJS) version_res.o
@echo Building flexlink.exe with TOOLCHAIN=$(TOOLCHAIN)
rm -f flexlink.exe
- windres version.rc version_res.o
$(OCAMLOPT) -o flexlink.exe $(LINKFLAGS) $(OBJS)
+version_res.o: version.rc
+ windres version.rc version_res.o
+
+
flexdll_msvc.obj: flexdll.h flexdll.c
$(MSVC_PREFIX) $(MSVCC) /DMSVC -c /Fo"flexdll_msvc.obj" flexdll.c
@@ -72,6 +79,9 @@
flexdll_mingw.o: flexdll.h flexdll.c
$(MINCC) -c -DMINGW -o flexdll_mingw.o flexdll.c
+flexdll_mingw64.o: flexdll.h flexdll.c
+ $(MIN64CC) -c -DMINGW -o flexdll_mingw64.o flexdll.c
+
flexdll_initer_msvc.obj: flexdll_initer.c
$(MSVC_PREFIX) $(MSVCC) -c /Fo"flexdll_initer_msvc.obj" flexdll_initer.c
@@ -84,6 +94,10 @@
flexdll_initer_mingw.o: flexdll_initer.c
$(MINCC) -c -o flexdll_initer_mingw.o flexdll_initer.c
+flexdll_initer_mingw64.o: flexdll_initer.c
+ $(MIN64CC) -c -o flexdll_initer_mingw64.o flexdll_initer.c
+
+
demo_msvc: flexlink.exe flexdll_msvc.obj flexdll_initer_msvc.obj
(cd test && $(MSVC_PREFIX) $(MAKE) clean demo CHAIN=msvc CC="$(MSVCC)" O=obj)
@@ -93,6 +107,9 @@
demo_mingw: flexlink.exe flexdll_mingw.o flexdll_initer_mingw.o
(cd test && $(MAKE) clean demo CHAIN=mingw CC="$(MINCC)" O=o)
+demo_mingw64: flexlink.exe flexdll_mingw64.o flexdll_initer_mingw64.o
+ (cd test && $(MAKE) clean demo CHAIN=mingw64 CC="$(MIN64CC)" O=o)
+
#demo_msvc64: flexlink.exe flexdll_msvc.obj flexdll_initer_msvc.obj
# (cd test && $(MAKE) clean demo CHAIN=msvc CC="$(MSVCC)" O=obj EXTRA_OPTS="-x64 bufferoverflowu.lib")
Index: asmcomp/amd64/emit_mingw64.mlp
===================================================================
--- asmcomp/amd64/emit_mingw64.mlp (revision 0)
+++ asmcomp/amd64/emit_mingw64.mlp (revision 0)
@@ -0,0 +1,752 @@
+(***********************************************************************)
+(* *)
+(* Objective Caml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: emit.mlp 10488 2010-06-02 08:55:35Z xleroy $ *)
+
+(* Emission of x86-64 (AMD 64) assembly code *)
+
+open Misc
+open Cmm
+open Arch
+open Proc
+open Reg
+open Mach
+open Linearize
+open Emitaux
+
+
+(* Tradeoff between code size and code speed *)
+
+let fastcode_flag = ref true
+
+let stack_offset = ref 0
+
+(* Layout of the stack frame *)
+
+let frame_required () =
+ !contains_calls || num_stack_slots.(0) > 0 || num_stack_slots.(1) > 0
+
+let frame_size () = (* includes return address *)
+ if frame_required() then begin
+ let sz =
+ (!stack_offset + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + 8)
+ in Misc.align sz 16
+ end else
+ !stack_offset + 8
+
+let slot_offset loc cl =
+ match loc with
+ Incoming n -> frame_size() + n
+ | Local n ->
+ if cl = 0
+ then !stack_offset + n * 8
+ else !stack_offset + (num_stack_slots.(0) + n) * 8
+ | Outgoing n -> n
+
+(* Symbols *)
+
+let emit_symbol s =
+ Emitaux.emit_symbol '$' s
+
+let emit_call s =
+ `call {emit_symbol s}`
+
+let emit_jump s =
+ `jmp {emit_symbol s}`
+
+let load_symbol_addr s =
+ if !pic_code
+ then `leaq {emit_symbol s}(%rip)`
+ else `movq ${emit_symbol s}`
+
+(* Output a label *)
+
+let emit_label lbl =
+ emit_string ".L"; emit_int lbl
+
+(* Output a .align directive. *)
+
+let emit_align n =
+ ` .align {emit_int n}\n`
+
+let emit_Llabel fallthrough lbl =
+ if not fallthrough && !fastcode_flag then emit_align 4;
+ emit_label lbl
+
+(* Output a pseudo-register *)
+
+let emit_reg = function
+ { loc = Reg r } ->
+ emit_string (register_name r)
+ | { loc = Stack s } as r ->
+ let ofs = slot_offset s (register_class r) in
+ `{emit_int ofs}(%rsp)`
+ | { loc = Unknown } ->
+ assert false
+
+(* Output a reference to the lower 8, 16 or 32 bits of a register *)
+
+let reg_low_8_name =
+ [| "%al"; "%bl"; "%dil"; "%sil"; "%dl"; "%cl"; "%r8b"; "%r9b";
+ "%r10b"; "%r11b"; "%bpl"; "%r12b"; "%r13b" |]
+let reg_low_16_name =
+ [| "%ax"; "%bx"; "%di"; "%si"; "%dx"; "%cx"; "%r8w"; "%r9w";
+ "%r10w"; "%r11w"; "%bp"; "%r12w"; "%r13w" |]
+let reg_low_32_name =
+ [| "%eax"; "%ebx"; "%edi"; "%esi"; "%edx"; "%ecx"; "%r8d"; "%r9d";
+ "%r10d"; "%r11d"; "%ebp"; "%r12d"; "%r13d" |]
+
+let emit_subreg tbl r =
+ match r.loc with
+ Reg r when r < 13 ->
+ emit_string tbl.(r)
+ | Stack s ->
+ let ofs = slot_offset s (register_class r) in
+ `{emit_int ofs}(%rsp)`
+ | _ ->
+ assert false
+
+let emit_reg8 r = emit_subreg reg_low_8_name r
+let emit_reg16 r = emit_subreg reg_low_16_name r
+let emit_reg32 r = emit_subreg reg_low_32_name r
+
+(* Output an addressing mode *)
+
+let emit_addressing addr r n =
+ match addr with
+ | Ibased(s, d) ->
+ `{emit_symbol s}`;
+ if d <> 0 then ` + {emit_int d}`;
+ `(%rip)`
+ | Iindexed d ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)})`
+ | Iindexed2 d ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)}, {emit_reg r.(n+1)})`
+ | Iscaled(2, d) ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)}, {emit_reg r.(n)})`
+ | Iscaled(scale, d) ->
+ if d <> 0 then emit_int d;
+ `(, {emit_reg r.(n)}, {emit_int scale})`
+ | Iindexed2scaled(scale, d) ->
+ if d <> 0 then emit_int d;
+ `({emit_reg r.(n)}, {emit_reg r.(n+1)}, {emit_int scale})`
+
+(* Record live pointers at call points -- see Emitaux *)
+
+let record_frame_label live dbg =
+ let lbl = new_label() in
+ let live_offset = ref [] in
+ Reg.Set.iter
+ (function
+ {typ = Addr; loc = Reg r} ->
+ live_offset := ((r lsl 1) + 1) :: !live_offset
+ | {typ = Addr; loc = Stack s} as reg ->
+ live_offset := slot_offset s (register_class reg) :: !live_offset
+ | _ -> ())
+ live;
+ frame_descriptors :=
+ { fd_lbl = lbl;
+ fd_frame_size = frame_size();
+ fd_live_offset = !live_offset;
+ fd_debuginfo = dbg } :: !frame_descriptors;
+ lbl
+
+let record_frame live dbg =
+ let lbl = record_frame_label live dbg in `{emit_label lbl}:\n`
+
+(* Record calls to the GC -- we've moved them out of the way *)
+
+type gc_call =
+ { gc_lbl: label; (* Entry label *)
+ gc_return_lbl: label; (* Where to branch after GC *)
+ gc_frame: label } (* Label of frame descriptor *)
+
+let call_gc_sites = ref ([] : gc_call list)
+
+let emit_call_gc gc =
+ `{emit_label gc.gc_lbl}: {emit_call "caml_call_gc"}\n`;
+ `{emit_label gc.gc_frame}: jmp {emit_label gc.gc_return_lbl}\n`
+
+(* Record calls to caml_ml_array_bound_error.
+ In -g mode, we maintain one call to caml_ml_array_bound_error
+ per bound check site. Without -g, we can share a single call. *)
+
+type bound_error_call =
+ { bd_lbl: label; (* Entry label *)
+ bd_frame: label } (* Label of frame descriptor *)
+
+let bound_error_sites = ref ([] : bound_error_call list)
+let bound_error_call = ref 0
+
+let bound_error_label dbg =
+ if !Clflags.debug then begin
+ let lbl_bound_error = new_label() in
+ let lbl_frame = record_frame_label Reg.Set.empty dbg in
+ bound_error_sites :=
+ { bd_lbl = lbl_bound_error; bd_frame = lbl_frame } :: !bound_error_sites;
+ lbl_bound_error
+ end else begin
+ if !bound_error_call = 0 then bound_error_call := new_label();
+ !bound_error_call
+ end
+
+let emit_call_bound_error bd =
+ `{emit_label bd.bd_lbl}: {emit_call "caml_ml_array_bound_error"}\n`;
+ `{emit_label bd.bd_frame}:\n`
+
+let emit_call_bound_errors () =
+ List.iter emit_call_bound_error !bound_error_sites;
+ if !bound_error_call > 0 then
+ `{emit_label !bound_error_call}: {emit_call "caml_ml_array_bound_error"}\n`
+
+(* Names for instructions *)
+
+let instr_for_intop = function
+ Iadd -> "addq"
+ | Isub -> "subq"
+ | Imul -> "imulq"
+ | Iand -> "andq"
+ | Ior -> "orq"
+ | Ixor -> "xorq"
+ | Ilsl -> "salq"
+ | Ilsr -> "shrq"
+ | Iasr -> "sarq"
+ | _ -> assert false
+
+let instr_for_floatop = function
+ Iaddf -> "addsd"
+ | Isubf -> "subsd"
+ | Imulf -> "mulsd"
+ | Idivf -> "divsd"
+ | _ -> assert false
+
+let instr_for_floatarithmem = function
+ Ifloatadd -> "addsd"
+ | Ifloatsub -> "subsd"
+ | Ifloatmul -> "mulsd"
+ | Ifloatdiv -> "divsd"
+
+let name_for_cond_branch = function
+ Isigned Ceq -> "e" | Isigned Cne -> "ne"
+ | Isigned Cle -> "le" | Isigned Cgt -> "g"
+ | Isigned Clt -> "l" | Isigned Cge -> "ge"
+ | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne"
+ | Iunsigned Cle -> "be" | Iunsigned Cgt -> "a"
+ | Iunsigned Clt -> "b" | Iunsigned Cge -> "ae"
+
+(* Output an = 0 or <> 0 test. *)
+
+let output_test_zero arg =
+ match arg.loc with
+ Reg r -> ` testq {emit_reg arg}, {emit_reg arg}\n`
+ | _ -> ` cmpq $0, {emit_reg arg}\n`
+
+(* Output a floating-point compare and branch *)
+
+let emit_float_test cmp neg arg lbl =
+ (* Effect of comisd on flags and conditional branches:
+ ZF PF CF cond. branches taken
+ unordered 1 1 1 je, jb, jbe, jp
+ > 0 0 0 jne, jae, ja
+ < 0 0 1 jne, jbe, jb
+ = 1 0 0 je, jae, jbe.
+ If FP traps are on (they are off by default),
+ comisd traps on QNaN and SNaN but ucomisd traps on SNaN only.
+ *)
+ match (cmp, neg) with
+ | (Ceq, false) | (Cne, true) ->
+ let next = new_label() in
+ ` ucomisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`;
+ ` jp {emit_label next}\n`; (* skip if unordered *)
+ ` je {emit_label lbl}\n`; (* branch taken if x=y *)
+ `{emit_label next}:\n`
+ | (Cne, false) | (Ceq, true) ->
+ ` ucomisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`;
+ ` jp {emit_label lbl}\n`; (* branch taken if unordered *)
+ ` jne {emit_label lbl}\n` (* branch taken if x<y or x>y *)
+ | (Clt, _) ->
+ ` comisd {emit_reg arg.(0)}, {emit_reg arg.(1)}\n`; (* swap compare *)
+ if not neg then
+ ` ja {emit_label lbl}\n` (* branch taken if y>x i.e. x<y *)
+ else
+ ` jbe {emit_label lbl}\n` (* taken if unordered or y<=x i.e. !(x<y) *)
+ | (Cle, _) ->
+ ` comisd {emit_reg arg.(0)}, {emit_reg arg.(1)}\n`; (* swap compare *)
+ if not neg then
+ ` jae {emit_label lbl}\n` (* branch taken if y>=x i.e. x<=y *)
+ else
+ ` jb {emit_label lbl}\n` (* taken if unordered or y<x i.e. !(x<=y) *)
+ | (Cgt, _) ->
+ ` comisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`;
+ if not neg then
+ ` ja {emit_label lbl}\n` (* branch taken if x>y *)
+ else
+ ` jbe {emit_label lbl}\n` (* taken if unordered or x<=y i.e. !(x>y) *)
+ | (Cge, _) ->
+ ` comisd {emit_reg arg.(1)}, {emit_reg arg.(0)}\n`; (* swap compare *)
+ if not neg then
+ ` jae {emit_label lbl}\n` (* branch taken if x>=y *)
+ else
+ ` jb {emit_label lbl}\n` (* taken if unordered or x<y i.e. !(x>=y) *)
+
+(* Deallocate the stack frame before a return or tail call *)
+
+let output_epilogue () =
+ if frame_required() then begin
+ let n = frame_size() - 8 in
+ ` addq ${emit_int n}, %rsp\n`
+ end
+
+(* Output the assembly code for an instruction *)
+
+(* Name of current function *)
+let function_name = ref ""
+(* Entry point for tail recursive calls *)
+let tailrec_entry_point = ref 0
+
+let float_constants = ref ([] : (int * string) list)
+
+let emit_instr fallthrough i =
+ match i.desc with
+ Lend -> ()
+ | Lop(Imove | Ispill | Ireload) ->
+ let src = i.arg.(0) and dst = i.res.(0) in
+ if src.loc <> dst.loc then begin
+ match src.typ, src.loc, dst.loc with
+ Float, Reg _, Reg _ ->
+ ` movapd {emit_reg src}, {emit_reg dst}\n`
+ | Float, _, _ ->
+ ` movsd {emit_reg src}, {emit_reg dst}\n`
+ | _ ->
+ ` movq {emit_reg src}, {emit_reg dst}\n`
+ end
+ | Lop(Iconst_int n) ->
+ if n = 0n then begin
+ match i.res.(0).loc with
+ Reg n -> ` xorq {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
+ | _ -> ` movq $0, {emit_reg i.res.(0)}\n`
+ end else if n <= 0x7FFFFFFFn && n >= -0x80000000n then
+ ` movq ${emit_nativeint n}, {emit_reg i.res.(0)}\n`
+ else
+ ` movabsq ${emit_nativeint n}, {emit_reg i.res.(0)}\n`
+ | Lop(Iconst_float s) ->
+ begin match Int64.bits_of_float (float_of_string s) with
+ | 0x0000_0000_0000_0000L -> (* +0.0 *)
+ ` xorpd {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
+ | _ ->
+ let lbl = new_label() in
+ float_constants := (lbl, s) :: !float_constants;
+ ` movsd {emit_label lbl}(%rip), {emit_reg i.res.(0)}\n`
+ end
+ | Lop(Iconst_symbol s) ->
+ ` {load_symbol_addr s}, {emit_reg i.res.(0)}\n`
+ | Lop(Icall_ind) ->
+ ` call *{emit_reg i.arg.(0)}\n`;
+ record_frame i.live i.dbg
+ | Lop(Icall_imm(s)) ->
+ ` {emit_call s}\n`;
+ record_frame i.live i.dbg
+ | Lop(Itailcall_ind) ->
+ output_epilogue();
+ ` jmp *{emit_reg i.arg.(0)}\n`
+ | Lop(Itailcall_imm s) ->
+ if s = !function_name then
+ ` jmp {emit_label !tailrec_entry_point}\n`
+ else begin
+ output_epilogue();
+ ` {emit_jump s}\n`
+ end
+ | Lop(Iextcall(s, alloc)) ->
+ if alloc then begin
+ ` {load_symbol_addr s}, %rax\n`;
+ ` {emit_call "caml_c_call"}\n`;
+ record_frame i.live i.dbg
+ end else begin
+ ` {emit_call s}\n`
+ end
+ | Lop(Istackoffset n) ->
+ if n < 0
+ then ` addq ${emit_int(-n)}, %rsp\n`
+ else ` subq ${emit_int(n)}, %rsp\n`;
+ stack_offset := !stack_offset + n
+ | Lop(Iload(chunk, addr)) ->
+ let dest = i.res.(0) in
+ begin match chunk with
+ | Word ->
+ ` movq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Byte_unsigned ->
+ ` movzbq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Byte_signed ->
+ ` movsbq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Sixteen_unsigned ->
+ ` movzwq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Sixteen_signed ->
+ ` movswq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Thirtytwo_unsigned ->
+ ` movl {emit_addressing addr i.arg 0}, {emit_reg32 dest}\n`
+ | Thirtytwo_signed ->
+ ` movslq {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Single ->
+ ` cvtss2sd {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ | Double | Double_u ->
+ ` movsd {emit_addressing addr i.arg 0}, {emit_reg dest}\n`
+ end
+ | Lop(Istore(chunk, addr)) ->
+ begin match chunk with
+ | Word ->
+ ` movq {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Byte_unsigned | Byte_signed ->
+ ` movb {emit_reg8 i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Sixteen_unsigned | Sixteen_signed ->
+ ` movw {emit_reg16 i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Thirtytwo_signed | Thirtytwo_unsigned ->
+ ` movl {emit_reg32 i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ | Single ->
+ ` cvtsd2ss {emit_reg i.arg.(0)}, %xmm15\n`;
+ ` movss %xmm15, {emit_addressing addr i.arg 1}\n`
+ | Double | Double_u ->
+ ` movsd {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n`
+ end
+ | Lop(Ialloc n) ->
+ if !fastcode_flag then begin
+ let lbl_redo = new_label() in
+ `{emit_label lbl_redo}: subq ${emit_int n}, %r15\n`;
+ ` cmpq {emit_symbol "caml_young_limit"}(%rip), %r15\n`;
+ let lbl_call_gc = new_label() in
+ let lbl_frame = record_frame_label i.live Debuginfo.none in
+ ` jb {emit_label lbl_call_gc}\n`;
+ ` leaq 8(%r15), {emit_reg i.res.(0)}\n`;
+ call_gc_sites :=
+ { gc_lbl = lbl_call_gc;
+ gc_return_lbl = lbl_redo;
+ gc_frame = lbl_frame } :: !call_gc_sites
+ end else begin
+ begin match n with
+ 16 -> ` {emit_call "caml_alloc1"}\n`
+ | 24 -> ` {emit_call "caml_alloc2"}\n`
+ | 32 -> ` {emit_call "caml_alloc3"}\n`
+ | _ -> ` movq ${emit_int n}, %rax\n`;
+ ` {emit_call "caml_allocN"}\n`
+ end;
+ `{record_frame i.live Debuginfo.none} leaq 8(%r15), {emit_reg i.res.(0)}\n`
+ end
+ | Lop(Iintop(Icomp cmp)) ->
+ ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` set{emit_string b} %al\n`;
+ ` movzbq %al, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Icomp cmp, n)) ->
+ ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` set{emit_string b} %al\n`;
+ ` movzbq %al, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop Icheckbound) ->
+ let lbl = bound_error_label i.dbg in
+ ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`;
+ ` jbe {emit_label lbl}\n`
+ | Lop(Iintop_imm(Icheckbound, n)) ->
+ let lbl = bound_error_label i.dbg in
+ ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`;
+ ` jbe {emit_label lbl}\n`
+ | Lop(Iintop(Idiv | Imod)) ->
+ ` cqto\n`;
+ ` idivq {emit_reg i.arg.(1)}\n`
+ | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) ->
+ (* We have i.arg.(0) = i.res.(0) and i.arg.(1) = %rcx *)
+ ` {emit_string(instr_for_intop op)} %cl, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop op) ->
+ (* We have i.arg.(0) = i.res.(0) *)
+ ` {emit_string(instr_for_intop op)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Iadd, n)) when i.arg.(0).loc <> i.res.(0).loc ->
+ ` leaq {emit_int n}({emit_reg i.arg.(0)}), {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Iadd, 1) | Iintop_imm(Isub, -1)) ->
+ ` incq {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) ->
+ ` decq {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Idiv, n)) ->
+ (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
+ let l = Misc.log2 n in
+ ` movq {emit_reg i.arg.(0)}, %rax\n`;
+ ` addq ${emit_int(n-1)}, {emit_reg i.arg.(0)}\n`;
+ ` testq %rax, %rax\n`;
+ ` cmovns %rax, {emit_reg i.arg.(0)}\n`;
+ ` sarq ${emit_int l}, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(Imod, n)) ->
+ (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *)
+ ` movq {emit_reg i.arg.(0)}, %rax\n`;
+ ` testq %rax, %rax\n`;
+ ` leaq {emit_int(n-1)}(%rax), %rax\n`;
+ ` cmovns {emit_reg i.arg.(0)}, %rax\n`;
+ ` andq ${emit_int (-n)}, %rax\n`;
+ ` subq %rax, {emit_reg i.res.(0)}\n`
+ | Lop(Iintop_imm(op, n)) ->
+ (* We have i.arg.(0) = i.res.(0) *)
+ ` {emit_string(instr_for_intop op)} ${emit_int n}, {emit_reg i.res.(0)}\n`
+ | Lop(Inegf) ->
+ ` xorpd {emit_symbol "caml_negf_mask"}(%rip), {emit_reg i.res.(0)}\n`
+ | Lop(Iabsf) ->
+ ` andpd {emit_symbol "caml_absf_mask"}(%rip), {emit_reg i.res.(0)}\n`
+ | Lop(Iaddf | Isubf | Imulf | Idivf as floatop) ->
+ ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n`
+ | Lop(Ifloatofint) ->
+ ` cvtsi2sdq {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`
+ | Lop(Iintoffloat) ->
+ ` cvttsd2siq {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`
+ | Lop(Ispecific(Ilea addr)) ->
+ ` leaq {emit_addressing addr i.arg 0}, {emit_reg i.res.(0)}\n`
+ | Lop(Ispecific(Istore_int(n, addr))) ->
+ ` movq ${emit_nativeint n}, {emit_addressing addr i.arg 0}\n`
+ | Lop(Ispecific(Istore_symbol(s, addr))) ->
+ assert (not !pic_code);
+ ` movq ${emit_symbol s}, {emit_addressing addr i.arg 0}\n`
+ | Lop(Ispecific(Ioffset_loc(n, addr))) ->
+ ` addq ${emit_int n}, {emit_addressing addr i.arg 0}\n`
+ | Lop(Ispecific(Ifloatarithmem(op, addr))) ->
+ ` {emit_string(instr_for_floatarithmem op)} {emit_addressing addr i.arg 1}, {emit_reg i.res.(0)}\n`
+ | Lreloadretaddr ->
+ ()
+ | Lreturn ->
+ output_epilogue();
+ ` ret\n`
+ | Llabel lbl ->
+ `{emit_Llabel fallthrough lbl}:\n`
+ | Lbranch lbl ->
+ ` jmp {emit_label lbl}\n`
+ | Lcondbranch(tst, lbl) ->
+ begin match tst with
+ Itruetest ->
+ output_test_zero i.arg.(0);
+ ` jne {emit_label lbl}\n`
+ | Ifalsetest ->
+ output_test_zero i.arg.(0);
+ ` je {emit_label lbl}\n`
+ | Iinttest cmp ->
+ ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` j{emit_string b} {emit_label lbl}\n`
+ | Iinttest_imm((Isigned Ceq | Isigned Cne |
+ Iunsigned Ceq | Iunsigned Cne) as cmp, 0) ->
+ output_test_zero i.arg.(0);
+ let b = name_for_cond_branch cmp in
+ ` j{emit_string b} {emit_label lbl}\n`
+ | Iinttest_imm(cmp, n) ->
+ ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`;
+ let b = name_for_cond_branch cmp in
+ ` j{emit_string b} {emit_label lbl}\n`
+ | Ifloattest(cmp, neg) ->
+ emit_float_test cmp neg i.arg lbl
+ | Ioddtest ->
+ ` testb $1, {emit_reg8 i.arg.(0)}\n`;
+ ` jne {emit_label lbl}\n`
+ | Ieventest ->
+ ` testb $1, {emit_reg8 i.arg.(0)}\n`;
+ ` je {emit_label lbl}\n`
+ end
+ | Lcondbranch3(lbl0, lbl1, lbl2) ->
+ ` cmpq $1, {emit_reg i.arg.(0)}\n`;
+ begin match lbl0 with
+ None -> ()
+ | Some lbl -> ` jb {emit_label lbl}\n`
+ end;
+ begin match lbl1 with
+ None -> ()
+ | Some lbl -> ` je {emit_label lbl}\n`
+ end;
+ begin match lbl2 with
+ None -> ()
+ | Some lbl -> ` jg {emit_label lbl}\n`
+ end
+ | Lswitch jumptbl ->
+ assert(i.arg.(0).loc <> Reg 9); (* not %r11 *)
+ let lbl = new_label() in
+ ` leaq {emit_label lbl}, %r11\n`;
+ ` jmp *(%r11, {emit_reg i.arg.(0)}, 8)\n`;
+ ` .section .rodata\n`;
+ emit_align 8;
+ `{emit_label lbl}:`;
+ for i = 0 to Array.length jumptbl - 1 do
+ ` .quad {emit_label jumptbl.(i)}\n`
+ done;
+ ` .text\n`
+
+ | Lsetuptrap lbl ->
+ ` call {emit_label lbl}\n`
+ | Lpushtrap ->
+ ` pushq %r14\n`;
+ ` movq %rsp, %r14\n`;
+ stack_offset := !stack_offset + 16
+ | Lpoptrap ->
+ ` popq %r14\n`;
+ ` addq $8, %rsp\n`;
+ stack_offset := !stack_offset - 16
+ | Lraise ->
+ if !Clflags.debug then begin
+ ` {emit_call "caml_raise_exn"}\n`;
+ record_frame Reg.Set.empty i.dbg
+ end else begin
+ ` movq %r14, %rsp\n`;
+ ` popq %r14\n`;
+ ` ret\n`
+ end
+
+let rec emit_all fallthrough i =
+ match i.desc with
+ | Lend -> ()
+ | _ ->
+ emit_instr fallthrough i;
+ emit_all (Linearize.has_fallthrough i.desc) i.next
+
+(* Emission of the floating-point constants *)
+
+let emit_float_constant (lbl, cst) =
+ `{emit_label lbl}:`;
+ emit_float64_directive ".quad" cst
+
+(* Emission of the profiling prelude *)
+
+let emit_profile () =
+ match Config.system with
+ | "linux" | "gnu" ->
+ (* mcount preserves rax, rcx, rdx, rsi, rdi, r8, r9 explicitly
+ and rbx, rbp, r12-r15 like all C functions.
+ We need to preserve r10 and r11 ourselves, since Caml can
+ use them for argument passing. *)
+ ` pushq %r10\n`;
+ ` movq %rsp, %rbp\n`;
+ ` pushq %r11\n`;
+ ` {emit_call "mcount"}\n`;
+ ` popq %r11\n`;
+ ` popq %r10\n`
+ | _ ->
+ () (*unsupported yet*)
+
+(* Emission of a function declaration *)
+
+let fundecl fundecl =
+ function_name := fundecl.fun_name;
+ fastcode_flag := fundecl.fun_fast;
+ tailrec_entry_point := new_label();
+ stack_offset := 0;
+ float_constants := [];
+ call_gc_sites := [];
+ bound_error_sites := [];
+ bound_error_call := 0;
+ ` .text\n`;
+ emit_align 16;
+ ` .globl {emit_symbol fundecl.fun_name}\n`;
+ `{emit_symbol fundecl.fun_name}:\n`;
+ if !Clflags.gprofile then emit_profile();
+ if frame_required() then begin
+ let n = frame_size() - 8 in
+ ` subq ${emit_int n}, %rsp\n`
+ end;
+ `{emit_label !tailrec_entry_point}:\n`;
+ emit_all true fundecl.fun_body;
+ List.iter emit_call_gc !call_gc_sites;
+ emit_call_bound_errors ();
+ if !float_constants <> [] then begin
+ ` .section .rodata.cst8,\"a\"\n`;
+ List.iter emit_float_constant !float_constants
+ end;
+ match Config.system with
+ "linux" | "gnu" ->
+ ` .size {emit_symbol fundecl.fun_name},.-{emit_symbol fundecl.fun_name}\n`
+ | _ -> ()
+
+(* Emission of data *)
+
+let emit_item = function
+ Cglobal_symbol s ->
+ ` .globl {emit_symbol s}\n`;
+ | Cdefine_symbol s ->
+ `{emit_symbol s}:\n`
+ | Cdefine_label lbl ->
+ `{emit_label (100000 + lbl)}:\n`
+ | Cint8 n ->
+ ` .byte {emit_int n}\n`
+ | Cint16 n ->
+ ` .word {emit_int n}\n`
+ | Cint32 n ->
+ ` .long {emit_nativeint n}\n`
+ | Cint n ->
+ ` .quad {emit_nativeint n}\n`
+ | Csingle f ->
+ emit_float32_directive ".long" f
+ | Cdouble f ->
+ emit_float64_directive ".quad" f
+ | Csymbol_address s ->
+ ` .quad {emit_symbol s}\n`
+ | Clabel_address lbl ->
+ ` .quad {emit_label (100000 + lbl)}\n`
+ | Cstring s ->
+ emit_string_directive " .ascii " s
+ | Cskip n ->
+ if n > 0 then ` .space {emit_int n}\n`
+ | Calign n ->
+ emit_align n
+
+let data l =
+ ` .data\n`;
+ List.iter emit_item l
+
+(* Beginning / end of an assembly file *)
+
+let begin_assembly() =
+ if !Clflags.dlcode then begin
+ (* from amd64.S; could emit these constants on demand *)
+ ` .section .rodata.cst8,\"a\"\n`;
+ emit_align 16;
+ `{emit_symbol "caml_negf_mask"}: .quad 0x8000000000000000, 0\n`;
+ emit_align 16;
+ `{emit_symbol "caml_absf_mask"}: .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF\n`
+ end;
+ let lbl_begin = Compilenv.make_symbol (Some "data_begin") in
+ ` .data\n`;
+ ` .globl {emit_symbol lbl_begin}\n`;
+ `{emit_symbol lbl_begin}:\n`;
+ let lbl_begin = Compilenv.make_symbol (Some "code_begin") in
+ ` .text\n`;
+ ` .globl {emit_symbol lbl_begin}\n`;
+ `{emit_symbol lbl_begin}:\n`
+
+let end_assembly() =
+ let lbl_end = Compilenv.make_symbol (Some "code_end") in
+ ` .text\n`;
+ ` .globl {emit_symbol lbl_end}\n`;
+ `{emit_symbol lbl_end}:\n`;
+ ` .data\n`;
+ let lbl_end = Compilenv.make_symbol (Some "data_end") in
+ ` .globl {emit_symbol lbl_end}\n`;
+ `{emit_symbol lbl_end}:\n`;
+ ` .long 0\n`;
+ let lbl = Compilenv.make_symbol (Some "frametable") in
+ ` .globl {emit_symbol lbl}\n`;
+ `{emit_symbol lbl}:\n`;
+ emit_frames
+ { efa_label = (fun l -> ` .quad {emit_label l}\n`);
+ efa_16 = (fun n -> ` .word {emit_int n}\n`);
+ efa_32 = (fun n -> ` .long {emit_int32 n}\n`);
+ efa_word = (fun n -> ` .quad {emit_int n}\n`);
+ efa_align = emit_align;
+ efa_label_rel =
+ begin
+ fun lbl ofs ->
+ ` .long ({emit_label lbl} - .) + {emit_int32 ofs}\n`
+ end;
+ efa_def_label = (fun l -> `{emit_label l}:\n`);
+ efa_string = (fun s -> emit_string_directive " .asciz " s) };
+ if Config.system = "linux" then
+ (* Mark stack as non-executable, PR#4564 *)
+ ` .section .note.GNU-stack,\"\"\n`
Property changes on: asmcomp/amd64/emit_mingw64.mlp
___________________________________________________________________
Added: svn:executable
+ *
Index: asmcomp/amd64/proc_mingw64.ml
===================================================================
--- asmcomp/amd64/proc_mingw64.ml (revision 0)
+++ asmcomp/amd64/proc_mingw64.ml (revision 0)
@@ -0,0 +1,234 @@
+(***********************************************************************)
+(* *)
+(* Objective Caml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 2000 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id: proc.ml 9547 2010-01-22 12:48:24Z doligez $ *)
+
+(* Description of the AMD64 processor with Win64 conventions *)
+
+open Misc
+open Arch
+open Cmm
+open Reg
+open Mach
+
+(* Registers available for register allocation *)
+
+(* Register map:
+ rax 0 rax - r11: Caml function arguments
+ rbx 1 rcx - r9: C function arguments
+ rdi 2 rax: Caml and C function results
+ rsi 3 rbx, rbp, rsi, rdi r12-r15 are preserved by C
+ rdx 4
+ rcx 5
+ r8 6
+ r9 7
+ r10 8
+ r11 9
+ rbp 10
+ r12 11
+ r13 12
+ r14 trap pointer
+ r15 allocation pointer
+
+ xmm0 - xmm15 100 - 115 xmm0 - xmm9: Caml function arguments
+ xmm0 - xmm3: C function arguments
+ xmm0: Caml and C function results
+ xmm6-xmm15 are preserved by C *)
+
+let int_reg_name =
+ [| "%rax"; "%rbx"; "%rdi"; "%rsi"; "%rdx"; "%rcx"; "%r8"; "%r9";
+ "%r10"; "%r11"; "%rbp"; "%r12"; "%r13" |]
+
+let float_reg_name =
+ [| "%xmm0"; "%xmm1"; "%xmm2"; "%xmm3"; "%xmm4"; "%xmm5"; "%xmm6"; "%xmm7";
+ "%xmm8"; "%xmm9"; "%xmm10"; "%xmm11";
+ "%xmm12"; "%xmm13"; "%xmm14"; "%xmm15" |]
+
+let num_register_classes = 2
+
+let register_class r =
+ match r.typ with
+ Int -> 0
+ | Addr -> 0
+ | Float -> 1
+
+let num_available_registers = [| 13; 16 |]
+
+let first_available_register = [| 0; 100 |]
+
+let register_name r =
+ if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100)
+
+(* Pack registers starting at %rax so as to reduce the number of REX
+ prefixes and thus improve code density *)
+let rotate_registers = false
+
+(* Representation of hard registers by pseudo-registers *)
+
+let hard_int_reg =
+ let v = Array.create 13 Reg.dummy in
+ for i = 0 to 12 do v.(i) <- Reg.at_location Int (Reg i) done;
+ v
+
+let hard_float_reg =
+ let v = Array.create 16 Reg.dummy in
+ for i = 0 to 15 do v.(i) <- Reg.at_location Float (Reg (100 + i)) done;
+ v
+
+let all_phys_regs =
+ Array.append hard_int_reg hard_float_reg
+
+let phys_reg n =
+ if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100)
+
+let rax = phys_reg 0
+let rcx = phys_reg 5
+let rdx = phys_reg 4
+let r11 = phys_reg 9
+let rxmm15 = phys_reg 115
+
+let stack_slot slot ty =
+ Reg.at_location ty (Stack slot)
+
+(* Instruction selection *)
+
+let word_addressed = false
+
+(* Calling conventions *)
+
+let calling_conventions first_int last_int first_float last_float make_stack
+ arg =
+ let loc = Array.create (Array.length arg) Reg.dummy in
+ let int = ref first_int in
+ let float = ref first_float in
+ let ofs = ref 0 in
+ for i = 0 to Array.length arg - 1 do
+ match arg.(i).typ with
+ Int | Addr as ty ->
+ if !int <= last_int then begin
+ loc.(i) <- phys_reg !int;
+ incr int
+ end else begin
+ loc.(i) <- stack_slot (make_stack !ofs) ty;
+ ofs := !ofs + size_int
+ end
+ | Float ->
+ if !float <= last_float then begin
+ loc.(i) <- phys_reg !float;
+ incr float
+ end else begin
+ loc.(i) <- stack_slot (make_stack !ofs) Float;
+ ofs := !ofs + size_float
+ end
+ done;
+ (loc, Misc.align !ofs 16) (* keep stack 16-aligned *)
+
+let incoming ofs = Incoming ofs
+let outgoing ofs = Outgoing ofs
+let not_supported ofs = fatal_error "Proc.loc_results: cannot call"
+
+let loc_arguments arg =
+ calling_conventions 0 9 100 109 outgoing arg
+let loc_parameters arg =
+ let (loc, ofs) = calling_conventions 0 9 100 109 incoming arg in loc
+let loc_results res =
+ let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc
+
+(* C calling conventions (Win64):
+ first integer args in rcx, rdx, r8, r9 (4 - 7)
+ first float args in xmm0 ... xmm3 (100 - 103)
+ each integer arg consumes a float reg, and conversely
+ remaining args on stack
+ always 32 bytes reserved at bottom of stack.
+ Return value in rax or xmm0
+*)
+
+let loc_external_results res =
+ let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc
+
+let int_external_arguments =
+ [| 5 (*rcx*); 4 (*rdx*); 6 (*r8*); 7 (*r9*) |]
+let float_external_arguments =
+ [| 100 (*xmm0*); 101 (*xmm1*); 102 (*xmm2*); 103 (*xmm3*) |]
+
+let loc_external_arguments arg =
+ let loc = Array.create (Array.length arg) Reg.dummy in
+ let reg = ref 0
+ and ofs = ref 32 in
+ for i = 0 to Array.length arg - 1 do
+ match arg.(i).typ with
+ Int | Addr as ty ->
+ if !reg < 4 then begin
+ loc.(i) <- phys_reg int_external_arguments.(!reg);
+ incr reg
+ end else begin
+ loc.(i) <- stack_slot (Outgoing !ofs) ty;
+ ofs := !ofs + size_int
+ end
+ | Float ->
+ if !reg < 4 then begin
+ loc.(i) <- phys_reg float_external_arguments.(!reg);
+ incr reg
+ end else begin
+ loc.(i) <- stack_slot (Outgoing !ofs) Float;
+ ofs := !ofs + size_float
+ end
+ done;
+ (loc, Misc.align !ofs 16) (* keep stack 16-aligned *)
+
+let loc_exn_bucket = rax
+
+(* Registers destroyed by operations *)
+
+let destroyed_at_c_call =
+ (* Win64: rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 preserved *)
+ Array.of_list(List.map phys_reg
+ [0;4;5;6;7;8;9;
+ 100;101;102;103;104;105])
+
+let destroyed_at_oper = function
+ Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs
+ | Iop(Iextcall(_, false)) -> destroyed_at_c_call
+ | Iop(Iintop(Idiv | Imod)) -> [| rax; rdx |]
+ | Iop(Istore(Single, _)) -> [| rxmm15 |]
+ | Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _))
+ -> [| rax |]
+ | Iswitch(_, _) -> [| r11 |]
+ | _ -> [||]
+
+let destroyed_at_raise = all_phys_regs
+
+(* Maximal register pressure *)
+
+let safe_register_pressure = function
+ Iextcall(_,_) -> 8
+ | _ -> 11
+
+let max_register_pressure = function
+ Iextcall(_, _) -> [| 8; 10 |]
+ | Iintop(Idiv | Imod) -> [| 11; 16 |]
+ | Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _)
+ -> [| 12; 16 |]
+ | Istore(Single, _) -> [| 13; 15 |]
+ | _ -> [| 13; 16 |]
+
+(* Layout of the stack frame *)
+
+let num_stack_slots = [| 0; 0 |]
+let contains_calls = ref false
+
+(* Calling the assembler *)
+
+let assemble_file infile outfile =
+ Ccomp.command (Config.asm ^ " -o " ^
+ Filename.quote outfile ^ " " ^ Filename.quote infile)
+
Property changes on: asmcomp/amd64/proc_mingw64.ml
___________________________________________________________________
Added: svn:executable
+ *
Index: win32caml/menu.c
===================================================================
--- win32caml/menu.c (revision 11067)
+++ win32caml/menu.c (working copy)
@@ -240,7 +240,7 @@
strcpy(CurrentFontName, CurrentFont.lfFaceName);
CurrentFontFamily = lf.lfPitchAndFamily;
CurrentFontStyle = lf.lfWeight;
- hwndChild = (HWND) GetWindowLongPtr(hwndSession, DWLP_USER);
+ hwndChild = (HWND) GetWindowLong(hwndSession, DWLP_USER);
SendMessage(hwndChild,WM_SETFONT,(WPARAM)ProgramParams.hFont,0);
ForceRepaint();
return (1);
@@ -259,7 +259,7 @@
int result;
result = DialogBoxParam(hInst, MAKEINTRESOURCE(id), GetActiveWindow(),
- fn, 0);
+ fn, 0);
return result;
}
@@ -338,7 +338,7 @@
{
HWND hEdit;
- hEdit = (HWND)GetWindowLongPtr(hwnd,DWLP_USER);
+ hEdit = (HWND)GetWindowLong(hwnd,DWLP_USER);
SendMessage(hEdit,EM_UNDO,0,0);
}
@@ -352,7 +352,7 @@
------------------------------------------------------------------------*/
void ForceRepaint(void)
{
- HWND hwndEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hwndEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
InvalidateRect(hwndEdit,NULL,1);
}
@@ -365,7 +365,7 @@
------------------------------------------------------------------------*/
static void Add_Char_To_Queue(int c)
{
- HWND hwndEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hwndEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
SendMessage(hwndEdit,WM_CHAR,c,1);
}
@@ -386,7 +386,7 @@
if (*buf == 0)
return;
- hEditCtrl = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ hEditCtrl = (HWND)GetWindowLong(hwndSession,DWLP_USER);
GotoEOF();
@@ -419,7 +419,7 @@
if((*buf) == 0)
return;
- hEditCtrl = (HWND)GetWindowLongPtr(hwndSession, DWLP_USER);
+ hEditCtrl = (HWND)GetWindowLong(hwndSession, DWLP_USER);
GotoEOF();
SendMessage(hEditCtrl ,EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)buf);
@@ -521,7 +521,7 @@
static void SaveText(char *fname)
{
int i,len;
- HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0);
FILE *f;
char *buf = SafeMalloc(8192);
@@ -665,7 +665,7 @@
------------------------------------------------------------------------*/
static void CopyToClipboard(HWND hwnd)
{
- HWND hwndEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hwndEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
SendMessage(hwndEdit,WM_COPY,0,0);
}
@@ -678,7 +678,7 @@
------------------------------------------------------------------------*/
int ResetText(void)
{
- HWND hwndEdit = (HWND) GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hwndEdit = (HWND) GetWindowLong(hwndSession,DWLP_USER);
TEXTRANGE cr;
int len = SendMessage(hwndEdit,WM_GETTEXTLENGTH,0,0);
char *tmp = malloc(len+10),*p;
Index: win32caml/ocaml.c
===================================================================
--- win32caml/ocaml.c (revision 11067)
+++ win32caml/ocaml.c (working copy)
@@ -329,7 +329,7 @@
void GotoEOF(void)
{
- HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0);
int lineindex = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0);
int lastLineLength = SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0);
@@ -348,7 +348,7 @@
------------------------------------------------------------------------*/
void GotoPrompt(void)
{
- HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0)+2;
SendMessage(hEdit,EM_SETSEL,lineindex,lineindex);
}
@@ -452,7 +452,7 @@
void RewriteCurrentEditBuffer(void)
{
// get the editbox's handle
- HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
// calculate what to highlight
int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0);
@@ -489,7 +489,7 @@
void RefreshCurrentEditBuffer(void)
{
// get the editbox's handle
- HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ HWND hEdit = (HWND)GetWindowLong(hwndSession,DWLP_USER);
// get the last line index
int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0) - 1;
@@ -1077,7 +1077,7 @@
// a neat little trick we can do is compare the point at which
// the ;; is and where the first (* can be found, if the ;; is
// before the (* ocaml.exe ignores the comment
- if((unsigned int)firstSemiColonSemiColon < (unsigned int)firstComment)
+ if(firstSemiColonSemiColon < firstComment)
{
free(line);
return TRUE;
@@ -1223,7 +1223,6 @@
HWND hwndChild;
RECT rc;
HDC hDC;
-
switch(msg) {
case WM_CREATE:
GetClientRect(hwnd,&rc);
@@ -1241,19 +1240,19 @@
(HMENU) EditControls++,
hInst,
NULL);
- SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) hwndChild);
+ SetWindowLong(hwnd, DWLP_USER, (LONG_PTR) hwndChild);
SendMessage(hwndChild, WM_SETFONT, (WPARAM) ProgramParams.hFont, 0L);
SendMessage(hwndChild,EM_LIMITTEXT,0xffffffff,0);
SubClassEditField(hwndChild);
break;
// Resize the edit control
case WM_SIZE:
- hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER);
+ hwndChild = (HWND) GetWindowLong(hwnd, DWLP_USER);
MoveWindow(hwndChild, 0, 0, LOWORD(lparam), HIWORD(lparam), TRUE);
break;
// Always set the focus to the edit control.
case WM_SETFOCUS:
- hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER);
+ hwndChild = (HWND) GetWindowLong(hwnd, DWLP_USER);
SetFocus(hwndChild);
break;
// Repainting of the edit control about to happen.
@@ -1285,7 +1284,7 @@
if (busy)
break;
- hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER);
+ hwndChild = (HWND) GetWindowLong(hwnd, DWLP_USER);
// add what they wrote to the edit buffer
AppendToEditBuffer(hwndChild);
@@ -1308,7 +1307,7 @@
// has written something in its end of the pipe.
case WM_TIMERTICK:
/** Modified by Chris Watford 21 Sept 2003 **/
- hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER);
+ hwndChild = (HWND) GetWindowLong(hwnd, DWLP_USER);
if (ReadToLineBuffer())
{
@@ -1509,7 +1508,7 @@
{
HWND hEditCtrl;
- hEditCtrl = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER);
+ hEditCtrl = (HWND)GetWindowLong(hwndSession,DWLP_USER);
return SendMessage(hEditCtrl,EM_REPLACESEL,0,(LPARAM)lineBuffer);
}
Index: win32caml/Makefile
===================================================================
--- win32caml/Makefile (revision 11067)
+++ win32caml/Makefile (working copy)
@@ -40,7 +40,7 @@
rm -f ocaml.res
endif
ifeq ($(TOOLCHAIN),mingw)
- windres -i ocaml.rc -o $@
+ $(TOOLPREF)windres -i ocaml.rc -o $@
endif
$(OBJS): inria.h inriares.h history.h editbuffer.h
Index: boot/ocamldep
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: boot/ocamllex
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: boot/ocamlc
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: bytecomp/bytelink.ml
===================================================================
--- bytecomp/bytelink.ml (revision 11067)
+++ bytecomp/bytelink.ml (working copy)
@@ -512,7 +512,11 @@
extern \"C\" {\n\
#endif\n\
#ifdef _WIN64\n\
+ #ifdef __MINGW32__\n\
+ typedef long long value;\n\
+ #else\n\
typedef __int64 value;\n\
+ #endif\n\
#else\n\
typedef long value;\n\
#endif\n";
Index: Makefile.nt
===================================================================
--- Makefile.nt (revision 11067)
+++ Makefile.nt (working copy)
@@ -445,9 +445,14 @@
ASMCOMP_PROC=asmcomp/$(ARCH)/proc_nt.ml
ASMCOMP_EMIT=asmcomp/$(ARCH)/emit_nt.mlp
else
+ifeq ($(ARCH),amd64)
+ASMCOMP_PROC=asmcomp/$(ARCH)/proc_mingw64.ml
+ASMCOMP_EMIT=asmcomp/$(ARCH)/emit_mingw64.mlp
+else
ASMCOMP_PROC=asmcomp/$(ARCH)/proc.ml
ASMCOMP_EMIT=asmcomp/$(ARCH)/emit.mlp
endif
+endif
asmcomp/proc.ml: $(ASMCOMP_PROC)
cp $(ASMCOMP_PROC) asmcomp/proc.ml
Index: asmrun/amd64mingw64.S
===================================================================
--- asmrun/amd64mingw64.S (revision 0)
+++ asmrun/amd64mingw64.S (revision 0)
@@ -0,0 +1,462 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 2003 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License, with */
+/* the special exception on linking described in file ../LICENSE. */
+/* */
+/***********************************************************************/
+
+/* $Id: amd64.S 10862 2010-11-27 17:19:24Z xleroy $ */
+
+/* Asm part of the runtime system, AMD64 processor, mingw64 host */
+/* Must be preprocessed by cpp */
+
+
+
+
+ .text
+
+/* Allocation */
+
+ .globl caml_call_gc
+ .align 16
+caml_call_gc:
+ /* Record lowest stack address and return address */
+ movq 0(%rsp), %rax
+ movq %rax, caml_last_return_address(%rip)
+ leaq 8(%rsp), %rax
+ movq %rax, caml_bottom_of_stack(%rip)
+.Lcaml_call_gc:
+ /* Save caml_young_ptr, caml_exception_pointer */
+ movq %r15, caml_young_ptr(%rip)
+ movq %r14, caml_exception_pointer(%rip)
+ /* Build array of registers, save it into caml_gc_regs */
+ pushq %r13
+ pushq %r12
+ pushq %rbp
+ pushq %r11
+ pushq %r10
+ pushq %r9
+ pushq %r8
+ pushq %rcx
+ pushq %rdx
+ pushq %rsi
+ pushq %rdi
+ pushq %rbx
+ pushq %rax
+ mov %rsp, caml_gc_regs(%rip)
+ /* Save floating-point registers */
+ subq $(16*8), %rsp
+ movsd %xmm0, 0*8(%rsp)
+ movsd %xmm1, 1*8(%rsp)
+ movsd %xmm2, 2*8(%rsp)
+ movsd %xmm3, 3*8(%rsp)
+ movsd %xmm4, 4*8(%rsp)
+ movsd %xmm5, 5*8(%rsp)
+ movsd %xmm6, 6*8(%rsp)
+ movsd %xmm7, 7*8(%rsp)
+ movsd %xmm8, 8*8(%rsp)
+ movsd %xmm9, 9*8(%rsp)
+ movsd %xmm10, 10*8(%rsp)
+ movsd %xmm11, 11*8(%rsp)
+ movsd %xmm12, 12*8(%rsp)
+ movsd %xmm13, 13*8(%rsp)
+ movsd %xmm14, 14*8(%rsp)
+ movsd %xmm15, 15*8(%rsp)
+ /* Call the garbage collector */
+ subq $32, %rsp
+ call caml_garbage_collection
+ addq $32, %rsp
+ /* Restore all regs used by the code generator */
+ movsd 0*8(%rsp), %xmm0
+ movsd 1*8(%rsp), %xmm1
+ movsd 2*8(%rsp), %xmm2
+ movsd 3*8(%rsp), %xmm3
+ movsd 4*8(%rsp), %xmm4
+ movsd 5*8(%rsp), %xmm5
+ movsd 6*8(%rsp), %xmm6
+ movsd 7*8(%rsp), %xmm7
+ movsd 8*8(%rsp), %xmm8
+ movsd 9*8(%rsp), %xmm9
+ movsd 10*8(%rsp), %xmm10
+ movsd 11*8(%rsp), %xmm11
+ movsd 12*8(%rsp), %xmm12
+ movsd 13*8(%rsp), %xmm13
+ movsd 14*8(%rsp), %xmm14
+ movsd 15*8(%rsp), %xmm15
+ addq $(16*8), %rsp
+ popq %rax
+ popq %rbx
+ popq %rdi
+ popq %rsi
+ popq %rdx
+ popq %rcx
+ popq %r8
+ popq %r9
+ popq %r10
+ popq %r11
+ popq %rbp
+ popq %r12
+ popq %r13
+ /* Restore caml_young_ptr, caml_exception_pointer */
+ movq caml_young_ptr(%rip), %r15
+ movq caml_exception_pointer(%rip), %r14
+ /* Return to caller */
+ ret
+
+
+ .globl caml_alloc1
+ .align 16
+caml_alloc1:
+ subq $16, %r15
+ cmpq caml_young_limit(%rip), %r15
+ jb .L100
+ ret
+.L100:
+ movq 0(%rsp), %rax
+ movq %rax, caml_last_return_address(%rip)
+ leaq 8(%rsp), %rax
+ movq %rax, caml_bottom_of_stack(%rip)
+ subq $8, %rsp
+ call .Lcaml_call_gc
+ addq $8, %rsp
+ jmp caml_alloc1
+
+
+ .globl caml_alloc2
+ .align 16
+caml_alloc2:
+ subq $24, %r15
+ cmpq caml_young_limit(%rip), %r15
+ jb .L101
+ ret
+.L101:
+ movq 0(%rsp), %rax
+ movq %rax, caml_last_return_address(%rip)
+ leaq 8(%rsp), %rax
+ movq %rax, caml_bottom_of_stack(%rip)
+ subq $8, %rsp
+ call .Lcaml_call_gc
+ addq $8, %rsp
+ jmp caml_alloc2
+
+
+ .globl caml_alloc3
+ .align 16
+caml_alloc3:
+ subq $32, %r15
+ cmpq caml_young_limit(%rip), %r15
+ jb .L102
+ ret
+.L102:
+ movq 0(%rsp), %rax
+ movq %rax, caml_last_return_address(%rip)
+ leaq 8(%rsp), %rax
+ movq %rax, caml_bottom_of_stack(%rip)
+ subq $8, %rsp
+ call .Lcaml_call_gc
+ addq $8, %rsp
+ jmp caml_alloc3
+
+
+ .globl caml_allocN
+ .align 16
+caml_allocN:
+ subq %rax, %r15
+ cmpq caml_young_limit(%rip), %r15
+ jb .L103
+ ret
+.L103:
+ pushq %rax
+ movq 8(%rsp), %rax
+ movq %rax, caml_last_return_address(%rip)
+ leaq 16(%rsp), %rax
+ movq %rax, caml_bottom_of_stack(%rip)
+ call .Lcaml_call_gc
+ popq %rax
+ jmp caml_allocN
+
+
+ .globl caml_c_call
+ .align 16
+caml_c_call:
+ /* Record lowest stack address and return address */
+ popq %r12
+ movq %r12, caml_last_return_address(%rip)
+ movq %rsp, caml_bottom_of_stack(%rip)
+ /* Make the exception handler and alloc ptr available to the C code */
+ mov %r15, caml_young_ptr(%rip)
+ mov %r14, caml_exception_pointer(%rip)
+ /* Call the function (address in rax) */
+ subq $32, %rsp
+ call *%rax
+ addq $32, %rsp
+ /* Reload alloc ptr */
+ movq caml_young_ptr(%rip), %r15
+ /* Return to caller */
+ pushq %r12
+ ret
+
+
+/* Start the Caml program */
+
+ .globl caml_start_program
+ .align 16
+caml_start_program:
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movupd %xmm6, 0*16(%rsp)
+ movupd %xmm7, 1*16(%rsp)
+ movupd %xmm8, 2*16(%rsp)
+ movupd %xmm9, 3*16(%rsp)
+ movupd %xmm10, 4*16(%rsp)
+ movupd %xmm11, 5*16(%rsp)
+ movupd %xmm12, 6*16(%rsp)
+ movupd %xmm13, 7*16(%rsp)
+ movupd %xmm14, 8*16(%rsp)
+ movupd %xmm15, 9*16(%rsp)
+ /* Initial entry point is caml_program */
+ leaq caml_program(%rip), %r12
+ /* Common code for caml_start_program and caml_callback */
+.Lcaml_start_program:
+ /* Build a callback link */
+ subq $8, %rsp /* stack 16-aligned */
+ pushq caml_gc_regs(%rip)
+ pushq caml_last_return_address(%rip)
+ pushq caml_bottom_of_stack(%rip)
+ /* Setup alloc ptr and exception ptr */
+ movq caml_young_ptr(%rip), %r15
+ movq caml_exception_pointer(%rip), %r14
+ /* Build an exception handler */
+ leaq .L108(%rip), %r13
+ pushq %r13
+ pushq %r14
+ movq %rsp, %r14
+ /* Call the Caml code */
+ call *%r12
+.L107:
+ /* Pop the exception handler */
+ popq %r14
+ popq %r12 /* dummy register */
+.L109:
+ /* Update alloc ptr and exception ptr */
+ movq %r15, caml_young_ptr(%rip)
+ movq %r14, caml_exception_pointer(%rip)
+ /* Pop the callback link, restoring the global variables */
+ popq caml_bottom_of_stack(%rip)
+ popq caml_last_return_address(%rip)
+ popq caml_gc_regs(%rip)
+ addq $8, %rsp
+ /* Restore callee-save registers. */
+ movupd 0*16(%rsp), %xmm6
+ movupd 1*16(%rsp), %xmm7
+ movupd 2*16(%rsp), %xmm8
+ movupd 3*16(%rsp), %xmm9
+ movupd 4*16(%rsp), %xmm10
+ movupd 5*16(%rsp), %xmm11
+ movupd 6*16(%rsp), %xmm12
+ movupd 7*16(%rsp), %xmm13
+ movupd 8*16(%rsp), %xmm14
+ movupd 9*16(%rsp), %xmm15
+ addq $(8+10*16), %rsp
+ popq %r15
+ popq %r14
+ popq %r13
+ popq %r12
+ popq %rdi
+ popq %rsi
+ popq %rbp
+ popq %rbx
+ /* Return to caller. */
+ ret
+.L108:
+ /* Exception handler */
+ /* Mark the bucket as an exception result and return it */
+ orq $2, %rax
+ jmp .L109
+
+
+/* Raise an exception from Caml */
+
+ .globl caml_raise_exn
+ .align 16
+caml_raise_exn:
+ testq $1, caml_backtrace_active(%rip)
+ jne .L110
+ movq %r14, %rsp
+ popq %r14
+ ret
+.L110:
+ movq %rax, %r12 /* Save exception bucket */
+ movq %rax, %rcx /* arg 1: exception bucket */
+ movq 0(%rsp), %rdx /* arg 2: pc of raise */
+ leaq 8(%rsp), %r8 /* arg 3: sp of raise */
+ movq %r14, %r9 /* arg 4: sp of handler */
+ subq $32, %rsp
+ call caml_stash_backtrace
+ movq %r12, %rax /* Recover exception bucket */
+ movq %r14, %rsp
+ popq %r14
+ ret
+
+/* Raise an exception from C */
+
+ .globl caml_raise_exception
+ .align 16
+caml_raise_exception:
+ testq $1, caml_backtrace_active(%rip)
+ jne .L111
+ movq %rcx, %rax
+ movq caml_exception_pointer(%rip), %rsp
+ popq %r14 /* Recover previous exception handler */
+ movq caml_young_ptr(%rip), %r15 /* Reload alloc ptr */
+ ret
+.L111:
+ movq %rcx, %r12 /* Save exception bucket */
+ /* arg 1: exception bucket */
+ movq caml_last_return_address(%rip),%rdx /* arg 2: pc of raise */
+ movq caml_bottom_of_stack(%rip),%r8 /* arg 3: sp of raise */
+ movq caml_exception_pointer(%rip),%r9 /* arg 4: sp of handler */
+ subq $32, %rsp
+ call caml_stash_backtrace
+ movq %r12, %rax /* Recover exception bucket */
+ movq caml_exception_pointer(%rip),%rsp
+ popq %r14 /* Recover previous exception handler */
+ movq caml_young_ptr(%rip),%r15 /* Reload alloc ptr */
+ ret
+
+/* Callback from C to Caml */
+
+ .globl caml_callback_exn
+ .align 16
+caml_callback_exn:
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movupd %xmm6, 0*16(%rsp)
+ movupd %xmm7, 1*16(%rsp)
+ movupd %xmm8, 2*16(%rsp)
+ movupd %xmm9, 3*16(%rsp)
+ movupd %xmm10, 4*16(%rsp)
+ movupd %xmm11, 5*16(%rsp)
+ movupd %xmm12, 6*16(%rsp)
+ movupd %xmm13, 7*16(%rsp)
+ movupd %xmm14, 8*16(%rsp)
+ movupd %xmm15, 9*16(%rsp)
+ /* Initial loading of arguments */
+ movq %rcx, %rbx /* closure */
+ movq %rdx, %rax /* argument */
+ movq 0(%rbx), %r12 /* code pointer */
+ jmp .Lcaml_start_program
+
+
+ .globl caml_callback2_exn
+ .align 16
+caml_callback2_exn:
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movupd %xmm6, 0*16(%rsp)
+ movupd %xmm7, 1*16(%rsp)
+ movupd %xmm8, 2*16(%rsp)
+ movupd %xmm9, 3*16(%rsp)
+ movupd %xmm10, 4*16(%rsp)
+ movupd %xmm11, 5*16(%rsp)
+ movupd %xmm12, 6*16(%rsp)
+ movupd %xmm13, 7*16(%rsp)
+ movupd %xmm14, 8*16(%rsp)
+ movupd %xmm15, 9*16(%rsp)
+ /* Initial loading of arguments */
+ movq %rcx, %rdi /* closure */
+ movq %rdx, %rax /* first argument */
+ movq %r8, %rbx /* second argument */
+ leaq caml_apply2(%rip), %r12 /* code pointer */
+ jmp .Lcaml_start_program
+
+
+ .globl caml_callback3_exn
+ .align 16
+caml_callback3_exn:
+ /* Save callee-save registers */
+ pushq %rbx
+ pushq %rbp
+ pushq %rsi
+ pushq %rdi
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ subq $(8+10*16), %rsp /* stack 16-aligned + 10 saved xmm regs */
+ movupd %xmm6, 0*16(%rsp)
+ movupd %xmm7, 1*16(%rsp)
+ movupd %xmm8, 2*16(%rsp)
+ movupd %xmm9, 3*16(%rsp)
+ movupd %xmm10, 4*16(%rsp)
+ movupd %xmm11, 5*16(%rsp)
+ movupd %xmm12, 6*16(%rsp)
+ movupd %xmm13, 7*16(%rsp)
+ movupd %xmm14, 8*16(%rsp)
+ movupd %xmm15, 9*16(%rsp)
+ /* Initial loading of arguments */
+ movq %rcx, %rsi /* closure */
+ movq %rdx, %rax /* first argument */
+ movq %r8, %rbx /* second argument */
+ movq %r9, %rdi /* third argument */
+ leaq caml_apply3(%rip), %r12 /* code pointer */
+ jmp .Lcaml_start_program
+
+
+ .globl caml_ml_array_bound_error
+ .align 16
+caml_ml_array_bound_error:
+ leaq caml_array_bound_error(%rip), %rax
+ jmp caml_c_call
+
+ .data
+ .globl caml_system__frametable
+ .align 8
+caml_system__frametable:
+ .quad 1 /* one descriptor */
+ .quad .L107 /* return address into callback */
+ .value -1 /* negative frame size => use callback link */
+ .value 0 /* no roots here */
+ .align 8
+
+ .section .rodata.cst8,"a"
+
+ .globl caml_negf_mask
+ .align 16
+caml_negf_mask:
+ .quad 0x8000000000000000, 0
+ .globl caml_absf_mask
+ .align 16
+caml_absf_mask:
+ .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF
+
Property changes on: asmrun/amd64mingw64.S
___________________________________________________________________
Added: svn:executable
+ *
Index: asmrun/Makefile.nt
===================================================================
--- asmrun/Makefile.nt (revision 11067)
+++ asmrun/Makefile.nt (working copy)
@@ -33,7 +33,11 @@
dynlink.c signals.c debugger.c
ifeq ($(TOOLCHAIN),mingw)
+ifeq ($(ARCH),amd64)
+ASMOBJS=$(ARCH)mingw64.o
+else
ASMOBJS=$(ARCH).o
+endif
else
ASMOBJS=$(ARCH)nt.obj
endif
@@ -54,6 +58,9 @@
i386.o: i386.S
$(CC) -c -DSYS_$(SYSTEM) i386.S
+amd64mingw64.o: amd64mingw64.S
+ $(CC) -c -DSYS_$(SYSTEM) amd64mingw64.S
+
install:
cp libasmrun.$(A) $(LIBDIR)
Index: config/Makefile.mingw64
===================================================================
--- config/Makefile.mingw64 (revision 0)
+++ config/Makefile.mingw64 (revision 0)
@@ -0,0 +1,162 @@
+#########################################################################
+# #
+# Objective Caml #
+# #
+# Xavier Leroy, projet Cristal, INRIA Rocquencourt #
+# #
+# Copyright 1999 Institut National de Recherche en Informatique et #
+# en Automatique. All rights reserved. This file is distributed #
+# under the terms of the GNU Library General Public License, with #
+# the special exception on linking described in file ../LICENSE. #
+# #
+#########################################################################
+
+# $Id: Makefile.mingw 10461 2010-05-25 10:00:39Z frisch $
+
+# Configuration for Windows, Mingw64 compiler
+
+######### General configuration
+
+PREFIX=C:/ocamlmgw64
+
+### Where to install the binaries
+BINDIR=$(PREFIX)/bin
+
+### Where to install the standard library
+LIBDIR=$(PREFIX)/lib
+
+### Where to install the stub DLLs
+STUBLIBDIR=$(LIBDIR)/stublibs
+
+### Where to install the info files
+DISTRIB=$(PREFIX)
+
+### Where to install the man pages
+MANDIR=$(PREFIX)/man
+
+########## Toolchain and OS dependencies
+
+TOOLCHAIN=mingw
+
+### Toolchain prefix
+TOOLPREF=x86_64-w64-mingw32-
+
+CCOMPTYPE=cc
+O=o
+A=a
+S=s
+SO=s.o
+DO=d.o
+EXE=.exe
+EXT_DLL=.dll
+EXT_OBJ=.$(O)
+EXT_LIB=.$(A)
+EXT_ASM=.$(S)
+MANEXT=1
+SHARPBANGSCRIPTS=false
+PTHREAD_LINK=
+X11_INCLUDES=
+X11_LINK=
+DBM_INCLUDES=
+DBM_LINK=
+BYTECCRPATH=
+SUPPORTS_SHARED_LIBRARIES=true
+SHAREDCCCOMPOPTS=
+MKSHAREDLIBRPATH=
+NATIVECCPROFOPTS=
+NATIVECCRPATH=
+ASM=$(TOOLPREF)as
+ASPP=gcc
+ASPPPROFFLAGS=
+PROFILING=noprof
+DYNLINKOPTS=
+DEBUGGER=ocamldebugger
+CC_PROFILE=
+SYSTHREAD_SUPPORT=true
+EXTRALIBS=
+NATDYNLINK=true
+CMXS=cmxs
+
+########## Configuration for the bytecode compiler
+
+### Which C compiler to use for the bytecode interpreter.
+BYTECC=$(TOOLPREF)gcc
+
+### Additional compile-time options for $(BYTECC). (For static linking.)
+BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+
+### Additional link-time options for $(BYTECC). (For static linking.)
+BYTECCLINKOPTS=
+
+### Additional compile-time options for $(BYTECC). (For building a DLL.)
+DLLCCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused -DCAML_DLL
+
+### Libraries needed
+BYTECCLIBS=-lws2_32
+NATIVECCLIBS=-lws2_32
+
+### How to invoke the C preprocessor
+CPP=$(BYTECC) -E
+
+### Flexlink
+FLEXLINK=flexlink -chain mingw64
+FLEXDIR=$(shell $(FLEXLINK) -where)
+IFLEXDIR=-I"$(FLEXDIR)"
+MKDLL=$(FLEXLINK)
+MKEXE=$(FLEXLINK) -exe
+MKMAINDLL=$(FLEXLINK) -maindll
+
+### How to build a static library
+MKLIB=rm -f $(1); $(TOOLPREF)ar rc $(1) $(2); $(RANLIB) $(1)
+#ml let mklib out files opts = Printf.sprintf "rm -f %s && %sar rcs %s %s %s" out toolpref opts out files;;
+
+### Canonicalize the name of a system library
+SYSLIB=-l$(1)
+#ml let syslib x = "-l"^x;;
+
+### The ranlib command
+RANLIB=$(TOOLPREF)ranlib
+RANLIBCMD=$(TOOLPREF)ranlib
+
+############# Configuration for the native-code compiler
+
+### Name of architecture for the native-code compiler
+ARCH=amd64
+
+### Name of architecture model for the native-code compiler.
+MODEL=default
+
+### Name of operating system family for the native-code compiler.
+SYSTEM=mingw64
+
+### Which C compiler to use for the native-code compiler.
+NATIVECC=$(BYTECC)
+
+### Additional compile-time options for $(NATIVECC).
+NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
+
+### Additional link-time options for $(NATIVECC)
+NATIVECCLINKOPTS=
+
+### Build partially-linked object file
+PACKLD=$(TOOLPREF)ld -r $(NATIVECCLINKOPTS) -o #there must be a space after this '-o'
+
+############# Configuration for the contributed libraries
+
+OTHERLIBRARIES=win32unix str num win32graph dynlink bigarray systhreads labltk
+
+### Name of the target architecture for the "num" library
+BNG_ARCH=generic
+BNG_ASM_LEVEL=0
+
+### Configuration for LablTk
+# Set TK_ROOT to the directory where you installed TCL/TK 8.5
+# There must be no spaces or special characters in $(TK_ROOT)
+TK_ROOT=c:/tcl64
+TK_DEFS=-I$(TK_ROOT)/include
+TK_LINK=$(TK_ROOT)/lib/tcl85 $(TK_ROOT)/lib/tk85 -lws2_32 -L $(TK_ROOT)/bin tcl85.dll tk85.dll
+
+############# Aliases for common commands
+
+MAKEREC=$(MAKE) -f Makefile.nt
+MAKECMD=$(MAKE)
Index: config/Makefile.mingw
===================================================================
--- config/Makefile.mingw (revision 11067)
+++ config/Makefile.mingw (working copy)
@@ -37,6 +37,10 @@
########## Toolchain and OS dependencies
TOOLCHAIN=mingw
+
+### Toolchain prefix
+TOOLPREF=i686-w64-mingw32-
+
CCOMPTYPE=cc
O=o
A=a
@@ -61,7 +65,7 @@
MKSHAREDLIBRPATH=
NATIVECCPROFOPTS=
NATIVECCRPATH=
-ASM=as
+ASM=$(TOOLPREF)as
ASPP=gcc
ASPPPROFFLAGS=
PROFILING=noprof
@@ -76,7 +80,7 @@
########## Configuration for the bytecode compiler
### Which C compiler to use for the bytecode interpreter.
-BYTECC=gcc -mno-cygwin
+BYTECC=$(TOOLPREF)gcc
### Additional compile-time options for $(BYTECC). (For static linking.)
BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
@@ -103,16 +107,16 @@
MKMAINDLL=$(FLEXLINK) -maindll
### How to build a static library
-MKLIB=rm -f $(1); ar rcs $(1) $(2)
-#ml let mklib out files opts = Printf.sprintf "rm -f %s && ar rcs %s %s %s" out opts out files;;
+MKLIB=rm -f $(1); $(TOOLPREF)ar rc $(1) $(2); $(RANLIB) $(1)
+#ml let mklib out files opts = Printf.sprintf "rm -f %s && %sar rcs %s %s %s" out toolpref opts out files;;
### Canonicalize the name of a system library
SYSLIB=-l$(1)
#ml let syslib x = "-l"^x;;
### The ranlib command
-RANLIB=ranlib
-RANLIBCMD=ranlib
+RANLIB=$(TOOLPREF)ranlib
+RANLIBCMD=$(TOOLPREF)ranlib
############# Configuration for the native-code compiler
@@ -135,7 +139,7 @@
NATIVECCLINKOPTS=
### Build partially-linked object file
-PACKLD=ld -r $(NATIVECCLINKOPTS) -o #there must be a space after this '-o'
+PACKLD=$(TOOLPREF)ld -r $(NATIVECCLINKOPTS) -o #there must be a space after this '-o'
############# Configuration for the contributed libraries
Index: amd64.S
===================================================================
--- amd64.S (revision 11929)
+++ amd64.S (working copy)
@@ -209,15 +209,6 @@
#endif
-#ifdef SYS_mingw64
- /* Calls from Caml to C must reserve 32 bytes of extra stack space */
-# define PREPARE_FOR_C_CALL subq $32, %rsp
-# define CLEANUP_AFTER_C_CALL addq $32, %rsp
-#else
-# define PREPARE_FOR_C_CALL
-# define CLEANUP_AFTER_C_CALL
-#endif
-
.text
/* Allocation */
@@ -262,10 +253,8 @@
movsd %xmm14, 14*8(%rsp)
movsd %xmm15, 15*8(%rsp)
/* Call the garbage collector */
- PREPARE_FOR_C_CALL
- call GCALL(caml_garbage_collection)
- CLEANUP_AFTER_C_CALL
- /* Restore caml_young_ptr, caml_exception_pointer */
+ call GCALL(caml_garbage_collection)
+ /* Restore caml_young_ptr, caml_exception_pointer */
LOAD_VAR(caml_young_ptr, %r15)
LOAD_VAR(caml_exception_pointer, %r14)
/* Restore all regs used by the code generator */
@@ -367,9 +356,7 @@
STORE_VAR(%r15, caml_young_ptr)
STORE_VAR(%r14, caml_exception_pointer)
/* Call the function (address in %rax) */
- PREPARE_FOR_C_CALL
call *%rax
- CLEANUP_AFTER_C_CALL
/* Reload alloc ptr */
LOAD_VAR(caml_young_ptr, %r15)
/* Return to caller */
@@ -451,7 +438,6 @@
movq 0(%rsp), C_ARG_2 /* arg 2: pc of raise */
leaq 8(%rsp), C_ARG_3 /* arg 3: sp of raise */
movq %r14, C_ARG_4 /* arg 4: sp of handler */
- PREPARE_FOR_C_CALL /* no need to cleanup after */
call GCALL(caml_stash_backtrace)
movq %r12, %rax /* Recover exception bucket */
movq %r14, %rsp
@@ -474,7 +460,6 @@
LOAD_VAR(caml_last_return_address,C_ARG_2) /* arg 2: pc of raise */
LOAD_VAR(caml_bottom_of_stack,C_ARG_3) /* arg 3: sp of raise */
LOAD_VAR(caml_exception_pointer,C_ARG_4) /* arg 4: sp of handler */
- PREPARE_FOR_C_CALL /* no need to cleanup after */
call GCALL(caml_stash_backtrace)
movq %r12, %rax /* Recover exception bucket */
LOAD_VAR(caml_exception_pointer,%rsp)
Index: makefiles/Makefile.several =================================================================== --- makefiles/Makefile.several (revision 11929) +++ makefiles/Makefile.several (working copy) @@ -46,7 +46,7 @@ @if [ -f `basename $(FILE) ml`checker ]; then \ sh `basename $(FILE) ml`checker; \ else \ - diff -q `basename $(FILE) ml`reference `basename $(FILE) ml`result > /dev/null || (echo " => failed" && exit 1); \ + diff --strip-trailing-cr -q `basename $(FILE) ml`reference `basename $(FILE) ml`result > /dev/null || (echo " => failed" && exit 1); \ fi promote: defaultpromote | |||||||||||
Notes |
|
|
(0006004) Antoine Mine (reporter) 2011-06-11 18:34 |
Hi, For what it's worth, I've managed to compile a recent OCaml 3.12 dev branch (svn revision r11067) that generates MinGW64 code, with the patches I just added. It requires a recent Cygwin with the mingw64-x86_64 gcc packages, a patch to flexdll (against svn revision r195), a working 32-bit OCaml to compile the patched flexdll, and a 64-bit version of ActiveTcl. The compilation is then performed as usual, using the new config/Makeifle.mingw64 instead of config/Makefile.mingw. By the way, the patch also updates the MinGW (non-64) port to use the new mingw64-i686 32-bit gcc packages. Unfortunately, I will not be able to give much support to a MinGW64 OCaml as I don't intend to use it personally. Furthermore, there seems to be no more interest in maintaining a MinGW64 version of Astrée. I'm releasing this as-is in case it might be useful for others, and will gladly answer any question regarding the submitted patches - Antoine |
|
(0006234) frisch (developer) 2011-12-12 09:38 |
Antoine: thanks for this patch. Concerning the 32-bit "mingw" package: do you have any reason to prefer the i686-w64-mingw32-gcc toolchain (from the mingw64 project) over the i686-pc-mingw32-gcc one (from the mingw project)? Both are available under Windows, and it's not clear to me which one should be preferred. |
|
(0006235) frisch (developer) 2011-12-12 10:57 edited on: 2011-12-12 10:57 |
Antoine, concerning your changes to win32caml/: what is the reason for changing GetWindowLongPtr to GetWindowLong? According to: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584%28v=vs.85%29.aspx [^] << Note: If you are retrieving a pointer or a handle, this function has been superseded by the GetWindowLongPtr function. (Pointers and handles are 32 bits on 32-bit Windows and 64 bits on 64-bit Windows.) To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetWindowLongPtr. >> |
|
(0006236) frisch (developer) 2011-12-12 12:41 |
flexdll 0.27 is now based on the mingw-w64 project (for its mingw and mingw64 toolchains). Commit 11300: the offical (32-bit) mingw port of OCaml is now based on this compiler. The 64-bit mingw port has not been committed yet. |
|
(0006237) Camarade_Tux (reporter) 2011-12-12 12:53 |
I think I've already stated this but it's worth mentionning it again: I've found mingw-w64 to be _much_ more responsive than mingw.org. Actually, when I tried compiling ocaml with mingw-w64 for the first time, I stumbled on 3 bugs in mingw-w-4 in the process; all have been resolved in less than a day (the first one being solved in a matter of minutes). |
|
(0006246) Antoine Mine (reporter) 2011-12-12 18:53 |
Hi Alain, That's nice to see this patch used! I had no real preference on i686-w64-mingw32-gcc over i686-pc-mingw32-gcc. I guess I picked the first one out of a sense of symmetry! There are so many toolchains now in mingw that I sometimes get confused... Strangely enough, I had crashes of ocamlwin until I changed the GetWindowLongPtr into GetWindowLong, not knowing it was bad to do it (but it worked better!). If there are still crashes using the right thing (i.e. GetWindowLongPtr), then maybe the problem is elsewhere (variable types, casts, or strange magic in inria.h)? |
|
(0006425) shadinger (reporter) 2011-12-20 22:55 |
Hi all, With the help of Antoine's patches and the new version 0.27 of flexdll I was able to compile ocaml 3.12.1 on mingw64-x64. The detailed instructions are posted here: https://github.com/shadinger/opalang/wiki/Compiling-ocaml-MinGW64-w64 [^] This is required for the windows port of opalang which I am trying to compile on mingw64. I had problems with Antoine's first patch as it raised an assertion failure on some code in emit.ml (line 577 - assert(i.arg.(0).loc <> Reg 9); (* not %r11 *)). I tried several combinations and ended up with Antoine's code for amd64.S, and emil.ml code from ocaml 3.13.0-devel8 which partially support mingw64. The patched ocaml-win64 is here in github: https://github.com/shadinger/ocaml-win64 [^] Thanks again to Alain and Antoine. @Alain: I had an error while using flexlink 0.27 from the binary package (Fatal Error:hd). I had to recompile it with mingw64. I didn't check further. |
|
(0006469) xleroy (administrator) 2011-12-21 17:43 |
This afternoon, in a fit of boredom, I rebooted my home PC under Windows 7, resisted the urge to play Portal 2, installed Cygwin, then Emacs, then FlexDLL, then felt a little less lonely, then merged together the various OCaml/mingw64 patches floating around, and added a bit of house dressing on it. The result is now in the SVN trunk, commit 11927. It mostly works, but not 100% yet: + can compile a working ocamlopt.opt + runs correctly a number of classic tests, e.g. KB - miscompiles tests/misc/sorts.ml (ocamlopt-generated executable crashes after a while) - miscompiles tests/misc/weaktest.ml (ocamlopt-generated executable does an Invalid_argument) - does not complete "make opt" because of a crash while compiling camlp4 (IIRC) - does not complete "make opt.opt" because of a crash while compiling ocamlbuild (IIRC). In the last two cases, it could be a stack overflow or something more sinister. I'm unable to investigate since Cygwin's gdb doesn't work over Win64 executables, and I don't (want to) know of any Windows alternative for an asm-level debugger. So, now, if this 5th Windows port of OCaml is to see public light, someone else will have to pick it up where I'm leaving it, and commit to maintain it in the future. Enjoy! |
|
(0006474) shadinger (reporter) 2011-12-21 22:21 |
Great job Xavier! I have just corrected a hard to find bug on my repository about calling conventions when calling C code in 64 bits mode with more than 4 arguments. The stack arguments were disaligned. In "asmrun/amd64.S", I really think you don't need the PREPARE_FOR_C_CALL because the stack alignment is already taken care of in emit.ml. I had some weird crashes on native code while bytecode was working ok. When removing the code reserving additional 32 bytes on the stack, everything went fine. By the way, gdb does work on Mingw64/MSYS for 64 bits which is useful because windows silently hides the segfaults - WinDBG64 from MS is also free and easy to use. I will pick up soon where you left. |
|
(0006486) xleroy (administrator) 2011-12-22 09:54 |
You're right that the PREPARE_FOR_C_CALL in camll_c_call is wrong because the Caml caller already set up the stack exactly like the C callee expects it. Fix committed in trunk (commit 11931). That could explain some of my mysterious crashes; I'll try to retest this evening. The other occurrences of PREPARE_FOR_C_CALL are needed, I believe. Esp. the one in caml_call_gc, as explained in PR#5008. |
|
(0006487) shadinger (reporter) 2011-12-22 10:12 edited on: 2011-12-22 12:10 |
After removing the PREPARE_FOR_C_CALL, the whole compilation process went ok on Mingw64-w64/MSYS out of the box. Excellent news! At leat all tests/misc are passing now (sorts.ml and weaktest.ml are ok both in bytecode and native). Yet many other tests do not pass. I have not tested using Mingw64/cygwin. Please dismiss my submitted patch for amd64.S, I must have been too brutal in removing completely PREPARE_FOR_C_CALL. I have posted also a small patch for Makefile.several to ignore windows line ending in test results. The Mingw64 versions output files using Windows convention, and reference files are using Unix conventions. ***edit: You also need to add the "--strip-trailing-cr" option in testsuite/makefiles/Makefile.one (diff command appears twice). |
|
(0006545) xleroy (administrator) 2011-12-28 11:31 |
Thanks for the testing. I think we can declare success! Concerning the test suite, it is safe to say that it isn't ready for use with the Mingw & MSVC ports of OCaml... As a first step, commit 11965 should make it possible to override the DIFF variable with something appropriate for Windows. |
|
(0006590) monate (reporter) 2012-01-04 14:42 |
Hi, thanks a lot for your efforts on the windows mess side. The documentation in Makefile.win32 should state that one has to install the package named mingw64-i686-gcc-core in addition to binutils, gcc and runtime. Otherwise the command gcc was not installed :-( With revision 11984, "make -f Makefile.nt opt" fails for both 32 and 64 bits versions with my settings. Here the exact error with some debugging stuff added: ===================== make[1]: Leaving directory `/home/lmonate/ocaml-svn/asmrun' cd stdlib ; make -f Makefile.nt allopt make[1]: Entering directory `/home/lmonate/ocaml-svn/stdlib' ../boot/ocamlrun ../ocamlopt -verbose -a -o stdlib.cmxa pervasives.cmx array.cmx list.cmx char.cmx string.cmx sys.cmx hashtbl.cmx sort.cmx marshal.cmx obj.cmx int32.cmx int64.cmx nativeint.cmx lexing.cmx parsing.cmx set.cmx map.cmx stack.cmx queue.cmx camlinternalLazy.cmx lazy.cmx stream.cmx buffer.cmx printf.cmx format.cmx scanf.cmx arg.cmx printexc.cmx gc.cmx digest.cmx random.cmx callback.cmx camlinternalOO.cmx oo.cmx camlinternalMod.cmx genlex.cmx weak.cmx filename.cmx complex.cmx arrayLabels.cmx listLabels.cmx stringLabels.cmx moreLabels.cmx stdLabels.cmx + ar rc "stdlib.a" "pervasives.o" "array.o" "list.o" "char.o" "string.o" "sys.o" "hashtbl.o" "sort.o" "marshal.o" "obj.o" "int32.o" "int64.o" "nativeint.o" "lexing.o" "parsing.o" "set.o" "map.o" "stack.o" "queue.o" "camlinternalLazy.o" "lazy.o" "stream.o" "buffer.o" "printf.o" "format.o" "scanf.o" "arg.o" "printexc.o" "gc.o" "digest.o" "random.o" "callback.o" "camlinternalOO.o" "oo.o" "camlinternalMod.o" "genlex.o" "weak.o" "filename.o" "complex.o" "arrayLabels.o" "listLabels.o" "stringLabels.o" "moreLabels.o" "stdLabels.o" 'ar' n'est pas reconnu en tant que commande interne ou externe, un programme ex?cutable ou un fichier de commandes. File "_none_", line 1: Error: Error while creating the library stdlib.a Makefile.shared:58: recipe for target `stdlib.cmxa' failed make[1]: *** [stdlib.cmxa] Error 2 make[1]: Leaving directory `/home/lmonate/ocaml-svn/stdlib' Makefile.nt:528: recipe for target `libraryopt' failed make: *** [libraryopt] Error 2 ========================= The executable ar is not prefixed by the "standard" x86_64-w64-mingw32/i686_w64-mingw32 stuff. The first cuplrit that comes to mind is line 77 in utils/ccomp.ml. Do you need more help to investigate? |
|
(0006679) xleroy (administrator) 2012-01-14 19:46 |
Benjamin's "ar" problem also reported in PR#5478. Let's continue the discussion under this other PR. |
|
(0007408) johnwhitington (reporter) 2012-05-03 16:53 |
Hi! Just a quick note to say that I've managed to build a 64 bit mingw ocaml on Windows 7 following shadinger's instructions and using his downloads on github. I've just sent a new executable of our PDF command line tools to a customer who's trying to merge 15000 PDF files together, and is running into memory limits with the 32 bit executable. We'll see how he gets on! My preliminary tests here show the executable seems to work. The only things I found missing from the instructions: a) User needs to remember to add flexdll to the PATH or ocaml won't build b) The "set OCAMLLIB=" in the instructions stops the user being able to use ocaml after he has built and installed it: solution is to close the msys command prompt and open a new one. Thanks for all your hard work. John Whitington Coherent Graphics Ltd |
|
(0007409) shadinger (reporter) 2012-05-03 21:07 |
John, thanks for the kind note. You are right, I will add and clarify the compilation instructions. I still need to find time to check 3.13.0. You may also need to tweak the stack size when compiling your application, especially with high memory usage. The bad thing with Win7 64 bits, is that a stack overflow generates a silent crash of the app whithout any apparent reason. You need to run it through GDB ou Windbg to really see if it's a stack overflow. |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2010-11-24 09:14 | cullmann | New Issue | |
| 2010-11-24 09:14 | cullmann | File Added: ocaml.3.12.diff | |
| 2010-11-24 09:15 | cullmann | File Added: flexdll.0.26.diff | |
| 2011-05-20 14:52 | doligez | Status | new => assigned |
| 2011-05-20 14:52 | doligez | Assigned To | => xleroy |
| 2011-06-11 18:04 | Antoine Mine | File Added: flexdll-dev-r195+mingw64.patch | |
| 2011-06-11 18:05 | Antoine Mine | File Added: ocaml-3.12-r11067+mingw64.patch | |
| 2011-06-11 18:34 | Antoine Mine | Note Added: 0006004 | |
| 2011-09-21 13:34 | doligez | Assigned To | xleroy => doligez |
| 2011-12-12 09:38 | frisch | Note Added: 0006234 | |
| 2011-12-12 10:49 | frisch | Assigned To | doligez => frisch |
| 2011-12-12 10:57 | frisch | Note Added: 0006235 | |
| 2011-12-12 10:57 | frisch | Note Edited: 0006235 | View Revisions |
| 2011-12-12 12:41 | frisch | Note Added: 0006236 | |
| 2011-12-12 12:53 | Camarade_Tux | Note Added: 0006237 | |
| 2011-12-12 18:53 | Antoine Mine | Note Added: 0006246 | |
| 2011-12-17 11:20 | frisch | Assigned To | frisch => |
| 2011-12-20 22:55 | shadinger | Note Added: 0006425 | |
| 2011-12-21 17:43 | xleroy | Note Added: 0006469 | |
| 2011-12-21 17:43 | xleroy | Status | assigned => feedback |
| 2011-12-21 22:21 | shadinger | Note Added: 0006474 | |
| 2011-12-22 09:27 | shadinger | File Added: amd64.S.patch | |
| 2011-12-22 09:54 | xleroy | Note Added: 0006486 | |
| 2011-12-22 10:04 | shadinger | File Added: Makefile.several.patch | |
| 2011-12-22 10:12 | shadinger | Note Added: 0006487 | |
| 2011-12-22 12:10 | shadinger | Note Edited: 0006487 | View Revisions |
| 2011-12-28 11:31 | xleroy | Note Added: 0006545 | |
| 2011-12-28 11:31 | xleroy | Status | feedback => resolved |
| 2011-12-28 11:31 | xleroy | Resolution | open => fixed |
| 2011-12-28 11:31 | xleroy | Fixed in Version | => 3.13.0+dev |
| 2012-01-04 14:42 | monate | Note Added: 0006590 | |
| 2012-01-14 19:45 | xleroy | Relationship added | duplicate of 0005478 |
| 2012-01-14 19:46 | xleroy | Note Added: 0006679 | |
| 2012-05-03 16:53 | johnwhitington | Note Added: 0007408 | |
| 2012-05-03 21:07 | shadinger | Note Added: 0007409 | |
| Copyright © 2000 - 2011 MantisBT Group |



