1964N/A
1964N/APatch from Fedora spec-file to add powerpc support. This patch was rejected by
1964N/Aupstream. This may not be needed on Solaris, but keeping it for consistency
1964N/Awith the RHEL package.
1964N/Ahttps://sympa.inria.fr/sympa/arc/caml-list/2007-10/msg00502.html
1964N/A
1964N/Adiff -uNr ocaml-3.10.1/asmcomp/power64/arch.ml ocaml-3.10.1.ppc64/asmcomp/power64/arch.ml
1964N/A--- ocaml-3.10.1/asmcomp/power64/arch.ml 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmcomp/power64/arch.ml 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,84 @@
1964N/A+(***********************************************************************)
1964N/A+(* *)
1964N/A+(* Objective Caml *)
1964N/A+(* *)
1964N/A+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
1964N/A+(* *)
1964N/A+(* Copyright 1996 Institut National de Recherche en Informatique et *)
1964N/A+(* en Automatique. All rights reserved. This file is distributed *)
1964N/A+(* under the terms of the Q Public License version 1.0. *)
1964N/A+(* *)
1964N/A+(***********************************************************************)
1964N/A+
1964N/A+(* $Id: arch.ml,v 1.11 2004/06/19 16:13:32 xleroy Exp $ *)
1964N/A+
1964N/A+(* Specific operations for the PowerPC processor *)
1964N/A+
1964N/A+open Misc
1964N/A+open Format
1964N/A+
1964N/A+(* Machine-specific command-line options *)
1964N/A+
1964N/A+let command_line_options = []
1964N/A+
1964N/A+(* Specific operations *)
1964N/A+
1964N/A+type specific_operation =
1964N/A+ Imultaddf (* multiply and add *)
1964N/A+ | Imultsubf (* multiply and subtract *)
1964N/A+ | Ialloc_far of int (* allocation in large functions *)
1964N/A+
1964N/A+(* Addressing modes *)
1964N/A+
1964N/A+type addressing_mode =
1964N/A+ Ibased of string * int (* symbol + displ *)
1964N/A+ | Iindexed of int (* reg + displ *)
1964N/A+ | Iindexed2 (* reg + reg *)
1964N/A+
1964N/A+(* Sizes, endianness *)
1964N/A+
1964N/A+let big_endian = true
1964N/A+
1964N/A+let size_addr = 8
1964N/A+let size_int = 8
1964N/A+let size_float = 8
1964N/A+
1964N/A+(* Operations on addressing modes *)
1964N/A+
1964N/A+let identity_addressing = Iindexed 0
1964N/A+
1964N/A+let offset_addressing addr delta =
1964N/A+ match addr with
1964N/A+ Ibased(s, n) -> Ibased(s, n + delta)
1964N/A+ | Iindexed n -> Iindexed(n + delta)
1964N/A+ | Iindexed2 -> assert false
1964N/A+
1964N/A+let num_args_addressing = function
1964N/A+ Ibased(s, n) -> 0
1964N/A+ | Iindexed n -> 1
1964N/A+ | Iindexed2 -> 2
1964N/A+
1964N/A+(* Printing operations and addressing modes *)
1964N/A+
1964N/A+let print_addressing printreg addr ppf arg =
1964N/A+ match addr with
1964N/A+ | Ibased(s, n) ->
1964N/A+ let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in
1964N/A+ fprintf ppf "\"%s\"%s" s idx
1964N/A+ | Iindexed n ->
1964N/A+ let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in
1964N/A+ fprintf ppf "%a%s" printreg arg.(0) idx
1964N/A+ | Iindexed2 ->
1964N/A+ fprintf ppf "%a + %a" printreg arg.(0) printreg arg.(1)
1964N/A+
1964N/A+let print_specific_operation printreg op ppf arg =
1964N/A+ match op with
1964N/A+ | Imultaddf ->
1964N/A+ fprintf ppf "%a *f %a +f %a"
1964N/A+ printreg arg.(0) printreg arg.(1) printreg arg.(2)
1964N/A+ | Imultsubf ->
1964N/A+ fprintf ppf "%a *f %a -f %a"
1964N/A+ printreg arg.(0) printreg arg.(1) printreg arg.(2)
1964N/A+ | Ialloc_far n ->
1964N/A+ fprintf ppf "alloc_far %d" n
1964N/A+
1964N/Adiff -uNr ocaml-3.10.1/asmcomp/power64/emit.mlp ocaml-3.10.1.ppc64/asmcomp/power64/emit.mlp
1964N/A--- ocaml-3.10.1/asmcomp/power64/emit.mlp 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmcomp/power64/emit.mlp 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,989 @@
1964N/A+(***********************************************************************)
1964N/A+(* *)
1964N/A+(* Objective Caml *)
1964N/A+(* *)
1964N/A+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
1964N/A+(* *)
1964N/A+(* Copyright 1996 Institut National de Recherche en Informatique et *)
1964N/A+(* en Automatique. All rights reserved. This file is distributed *)
1964N/A+(* under the terms of the Q Public License version 1.0. *)
1964N/A+(* *)
1964N/A+(***********************************************************************)
1964N/A+
1964N/A+(* $Id: emit.mlp,v 1.21 2004/06/19 17:39:34 xleroy Exp $ *)
1964N/A+
1964N/A+(* Emission of PowerPC assembly code *)
1964N/A+
1964N/A+module StringSet = Set.Make(struct type t = string let compare = compare end)
1964N/A+
1964N/A+open Location
1964N/A+open Misc
1964N/A+open Cmm
1964N/A+open Arch
1964N/A+open Proc
1964N/A+open Reg
1964N/A+open Mach
1964N/A+open Linearize
1964N/A+open Emitaux
1964N/A+
1964N/A+(* Layout of the stack. The stack is kept 16-aligned. *)
1964N/A+
1964N/A+let stack_size_lbl = ref 0
1964N/A+let stack_slot_lbl = ref 0
1964N/A+let stack_args_size = ref 0
1964N/A+let stack_traps_size = ref 0
1964N/A+
1964N/A+(* We have a stack frame of our own if we call other functions (including
1964N/A+ use of exceptions, or if we need more than the red zone *)
1964N/A+let has_stack_frame () =
1964N/A+ if !contains_calls or (num_stack_slots.(0) + num_stack_slots.(1)) > (288-16)/8 then
1964N/A+ true
1964N/A+ else
1964N/A+ false
1964N/A+
1964N/A+let frame_size_sans_args () =
1964N/A+ let size = 8 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + 48 in
1964N/A+ Misc.align size 16
1964N/A+
1964N/A+let slot_offset loc cls =
1964N/A+ match loc with
1964N/A+ Local n ->
1964N/A+ if cls = 0
1964N/A+ then (!stack_slot_lbl, num_stack_slots.(1) * 8 + n * 8)
1964N/A+ else (!stack_slot_lbl, n * 8)
1964N/A+ | Incoming n -> ((if has_stack_frame() then !stack_size_lbl else 0), 48 + n)
1964N/A+ | Outgoing n -> (0, n)
1964N/A+
1964N/A+(* Output a symbol *)
1964N/A+
1964N/A+let emit_symbol =
1964N/A+ match Config.system with
1964N/A+ | "elf" | "bsd" -> (fun s -> Emitaux.emit_symbol '.' s)
1964N/A+ | "rhapsody" -> (fun s -> emit_char '_'; Emitaux.emit_symbol '$' s)
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+(* Output a label *)
1964N/A+
1964N/A+let label_prefix =
1964N/A+ match Config.system with
1964N/A+ | "elf" | "bsd" -> ".L"
1964N/A+ | "rhapsody" -> "L"
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+let emit_label lbl =
1964N/A+ emit_string label_prefix; emit_int lbl
1964N/A+
1964N/A+(* Section switching *)
1964N/A+
1964N/A+let toc_space =
1964N/A+ match Config.system with
1964N/A+ | "elf" | "bsd" -> " .section \".toc\",\"aw\"\n"
1964N/A+ | "rhapsody" -> " .toc\n"
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+let data_space =
1964N/A+ match Config.system with
1964N/A+ | "elf" | "bsd" -> " .section \".data\"\n"
1964N/A+ | "rhapsody" -> " .data\n"
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+let code_space =
1964N/A+ match Config.system with
1964N/A+ | "elf" | "bsd" -> " .section \".text\"\n"
1964N/A+ | "rhapsody" -> " .text\n"
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+let rodata_space =
1964N/A+ match Config.system with
1964N/A+ | "elf" | "bsd" -> " .section \".rodata\"\n"
1964N/A+ | "rhapsody" -> " .const\n"
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+(* Output a pseudo-register *)
1964N/A+
1964N/A+let emit_reg r =
1964N/A+ match r.loc with
1964N/A+ Reg r -> emit_string (register_name r)
1964N/A+ | _ -> fatal_error "Emit.emit_reg"
1964N/A+
1964N/A+let use_full_regnames =
1964N/A+ Config.system = "rhapsody"
1964N/A+
1964N/A+let emit_gpr r =
1964N/A+ if use_full_regnames then emit_char 'r';
1964N/A+ emit_int r
1964N/A+
1964N/A+let emit_fpr r =
1964N/A+ if use_full_regnames then emit_char 'f';
1964N/A+ emit_int r
1964N/A+
1964N/A+let emit_ccr r =
1964N/A+ if use_full_regnames then emit_string "cr";
1964N/A+ emit_int r
1964N/A+
1964N/A+(* Output a stack reference *)
1964N/A+
1964N/A+let emit_stack r =
1964N/A+ match r.loc with
1964N/A+ Stack s ->
1964N/A+ let lbl, ofs = slot_offset s (register_class r) in
1964N/A+ if lbl > 0 then
1964N/A+ `{emit_label lbl}+`;
1964N/A+ `{emit_int ofs}({emit_gpr 1})`
1964N/A+ | _ -> fatal_error "Emit.emit_stack"
1964N/A+
1964N/A+(* Split a 32-bit integer constants in two 16-bit halves *)
1964N/A+
1964N/A+let low n = n land 0xFFFF
1964N/A+let high n = n asr 16
1964N/A+
1964N/A+let nativelow n = Nativeint.to_int n land 0xFFFF
1964N/A+let nativehigh n = Nativeint.to_int (Nativeint.shift_right n 16)
1964N/A+
1964N/A+let is_immediate n =
1964N/A+ n <= 32767 && n >= -32768
1964N/A+
1964N/A+let is_native_immediate n =
1964N/A+ n <= 32767n && n >= -32768n
1964N/A+
1964N/A+
1964N/A+type tocentry =
1964N/A+ TocSymOfs of (string * int)
1964N/A+ | TocLabel of int
1964N/A+ | TocInt of nativeint
1964N/A+ | TocFloat of string
1964N/A+
1964N/A+(* List of all labels in tocref (reverse order) *)
1964N/A+let tocref_entries = ref []
1964N/A+
1964N/A+(* Output a TOC reference *)
1964N/A+
1964N/A+let emit_symbol_offset (s, d) =
1964N/A+ emit_symbol s;
1964N/A+ if d > 0 then `+`;
1964N/A+ if d <> 0 then emit_int d
1964N/A+
1964N/A+let emit_tocentry entry =
1964N/A+ match entry with
1964N/A+ TocSymOfs(s,d) -> emit_symbol_offset(s,d)
1964N/A+ | TocInt i -> emit_nativeint i
1964N/A+ | TocFloat f -> emit_string f
1964N/A+ | TocLabel lbl -> emit_label lbl
1964N/A+
1964N/A+ let rec tocref_label = function
1964N/A+ ( [] , content ) ->
1964N/A+ let lbl = new_label() in
1964N/A+ tocref_entries := (lbl, content) :: !tocref_entries;
1964N/A+ lbl
1964N/A+ | ( (lbl, o_content) :: lst, content) ->
1964N/A+ if content = o_content then
1964N/A+ lbl
1964N/A+ else
1964N/A+ tocref_label (lst, content)
1964N/A+
1964N/A+let emit_tocref entry =
1964N/A+ let lbl = tocref_label (!tocref_entries,entry) in
1964N/A+ emit_label lbl; emit_string "@toc(2) #"; emit_tocentry entry
1964N/A+
1964N/A+
1964N/A+(* Output a load or store operation *)
1964N/A+
1964N/A+let valid_offset instr ofs =
1964N/A+ ofs land 3 = 0 || (instr <> "ld" && instr <> "std")
1964N/A+
1964N/A+let emit_load_store instr addressing_mode addr n arg =
1964N/A+ match addressing_mode with
1964N/A+ Ibased(s, d) ->
1964N/A+ let dd = (d + 0x8000) in (* We can only offset by -0x8000 .. +0x7fff *)
1964N/A+ let a = (dd land -0x10000) in
1964N/A+ let b = (dd land 0xffff) - 0x8000 in
1964N/A+ ` ld {emit_gpr 11}, {emit_tocref (TocSymOfs (s,a))}\n`;
1964N/A+ ` {emit_string instr} {emit_reg arg}, {emit_int b}({emit_gpr 11})\n`
1964N/A+ | Iindexed ofs ->
1964N/A+ if is_immediate ofs && valid_offset instr ofs then
1964N/A+ ` {emit_string instr} {emit_reg arg}, {emit_int ofs}({emit_reg addr.(n)})\n`
1964N/A+ else begin
1964N/A+ ` lis {emit_gpr 0}, {emit_int(high ofs)}\n`;
1964N/A+ if low ofs <> 0 then
1964N/A+ ` ori {emit_gpr 0}, {emit_gpr 0}, {emit_int(low ofs)}\n`;
1964N/A+ ` {emit_string instr}x {emit_reg arg}, {emit_reg addr.(n)}, {emit_gpr 0}\n`
1964N/A+ end
1964N/A+ | Iindexed2 ->
1964N/A+ ` {emit_string instr}x {emit_reg arg}, {emit_reg addr.(n)}, {emit_reg addr.(n+1)}\n`
1964N/A+
1964N/A+(* After a comparison, extract the result as 0 or 1 *)
1964N/A+
1964N/A+let emit_set_comp cmp res =
1964N/A+ ` mfcr {emit_gpr 0}\n`;
1964N/A+ let bitnum =
1964N/A+ match cmp with
1964N/A+ Ceq | Cne -> 2
1964N/A+ | Cgt | Cle -> 1
1964N/A+ | Clt | Cge -> 0 in
1964N/A+` rlwinm {emit_reg res}, {emit_gpr 0}, {emit_int(bitnum+1)}, 31, 31\n`;
1964N/A+ begin match cmp with
1964N/A+ Cne | Cle | Cge -> ` xori {emit_reg res}, {emit_reg res}, 1\n`
1964N/A+ | _ -> ()
1964N/A+ end
1964N/A+
1964N/A+(* Record live pointers at call points *)
1964N/A+
1964N/A+type frame_descr =
1964N/A+ { fd_lbl: int; (* Return address *)
1964N/A+ fd_frame_size_lbl: int; (* Size of stack frame *)
1964N/A+ fd_live_offset: (int * int) list } (* Offsets/regs of live addresses *)
1964N/A+
1964N/A+let frame_descriptors = ref([] : frame_descr list)
1964N/A+
1964N/A+let record_frame live =
1964N/A+ let lbl = new_label() in
1964N/A+ let live_offset = ref [] in
1964N/A+ Reg.Set.iter
1964N/A+ (function
1964N/A+ {typ = Addr; loc = Reg r} ->
1964N/A+ live_offset := (0, (r lsl 1) + 1) :: !live_offset
1964N/A+ | {typ = Addr; loc = Stack s} as reg ->
1964N/A+ live_offset := slot_offset s (register_class reg) :: !live_offset
1964N/A+ | _ -> ())
1964N/A+ live;
1964N/A+ frame_descriptors :=
1964N/A+ { fd_lbl = lbl;
1964N/A+ fd_frame_size_lbl = !stack_size_lbl; (* frame_size *)
1964N/A+ fd_live_offset = !live_offset } :: !frame_descriptors;
1964N/A+ `{emit_label lbl}:\n`
1964N/A+
1964N/A+let emit_frame fd =
1964N/A+ ` .quad {emit_label fd.fd_lbl} + 4\n`;
1964N/A+ ` .short {emit_label fd.fd_frame_size_lbl}\n`;
1964N/A+ ` .short {emit_int (List.length fd.fd_live_offset)}\n`;
1964N/A+ List.iter
1964N/A+ (fun (lbl,n) ->
1964N/A+ ` .short `;
1964N/A+ if lbl > 0 then `{emit_label lbl}+`;
1964N/A+ `{emit_int n}\n`)
1964N/A+ fd.fd_live_offset;
1964N/A+ ` .align 3\n`
1964N/A+
1964N/A+(* Record external C functions to be called in a position-independent way
1964N/A+ (for MacOSX) *)
1964N/A+
1964N/A+let pic_externals = (Config.system = "rhapsody")
1964N/A+
1964N/A+let external_functions = ref StringSet.empty
1964N/A+
1964N/A+let emit_external s =
1964N/A+ ` .non_lazy_symbol_pointer\n`;
1964N/A+ `L{emit_symbol s}$non_lazy_ptr:\n`;
1964N/A+ ` .indirect_symbol {emit_symbol s}\n`;
1964N/A+ ` .quad 0\n`
1964N/A+
1964N/A+(* Names for conditional branches after comparisons *)
1964N/A+
1964N/A+let branch_for_comparison = function
1964N/A+ Ceq -> "beq" | Cne -> "bne"
1964N/A+ | Cle -> "ble" | Cgt -> "bgt"
1964N/A+ | Cge -> "bge" | Clt -> "blt"
1964N/A+
1964N/A+let name_for_int_comparison = function
1964N/A+ Isigned cmp -> ("cmpd", branch_for_comparison cmp)
1964N/A+ | Iunsigned cmp -> ("cmpld", branch_for_comparison cmp)
1964N/A+
1964N/A+(* Names for various instructions *)
1964N/A+
1964N/A+let name_for_intop = function
1964N/A+ Iadd -> "add"
1964N/A+ | Imul -> "mulld"
1964N/A+ | Idiv -> "divd"
1964N/A+ | Iand -> "and"
1964N/A+ | Ior -> "or"
1964N/A+ | Ixor -> "xor"
1964N/A+ | Ilsl -> "sld"
1964N/A+ | Ilsr -> "srd"
1964N/A+ | Iasr -> "srad"
1964N/A+ | _ -> Misc.fatal_error "Emit.Intop"
1964N/A+
1964N/A+let name_for_intop_imm = function
1964N/A+ Iadd -> "addi"
1964N/A+ | Imul -> "mulli"
1964N/A+ | Iand -> "andi."
1964N/A+ | Ior -> "ori"
1964N/A+ | Ixor -> "xori"
1964N/A+ | Ilsl -> "sldi"
1964N/A+ | Ilsr -> "srdi"
1964N/A+ | Iasr -> "sradi"
1964N/A+ | _ -> Misc.fatal_error "Emit.Intop_imm"
1964N/A+
1964N/A+let name_for_floatop1 = function
1964N/A+ Inegf -> "fneg"
1964N/A+ | Iabsf -> "fabs"
1964N/A+ | _ -> Misc.fatal_error "Emit.Iopf1"
1964N/A+
1964N/A+let name_for_floatop2 = function
1964N/A+ Iaddf -> "fadd"
1964N/A+ | Isubf -> "fsub"
1964N/A+ | Imulf -> "fmul"
1964N/A+ | Idivf -> "fdiv"
1964N/A+ | _ -> Misc.fatal_error "Emit.Iopf2"
1964N/A+
1964N/A+let name_for_specific = function
1964N/A+ Imultaddf -> "fmadd"
1964N/A+ | Imultsubf -> "fmsub"
1964N/A+ | _ -> Misc.fatal_error "Emit.Ispecific"
1964N/A+
1964N/A+(* Name of current function *)
1964N/A+let function_name = ref ""
1964N/A+(* Entry point for tail recursive calls *)
1964N/A+let tailrec_entry_point = ref 0
1964N/A+(* Names of functions defined in the current file *)
1964N/A+let defined_functions = ref StringSet.empty
1964N/A+(* Label of glue code for calling the GC *)
1964N/A+let call_gc_label = ref 0
1964N/A+(* Label of jump table *)
1964N/A+let lbl_jumptbl = ref 0
1964N/A+(* List of all labels in jumptable (reverse order) *)
1964N/A+let jumptbl_entries = ref []
1964N/A+(* Number of jumptable entries *)
1964N/A+let num_jumptbl_entries = ref 0
1964N/A+
1964N/A+(* Fixup conditional branches that exceed hardware allowed range *)
1964N/A+
1964N/A+let load_store_size = function
1964N/A+ Ibased(s, d) -> 2
1964N/A+ | Iindexed ofs -> if is_immediate ofs then 1 else 3
1964N/A+ | Iindexed2 -> 1
1964N/A+
1964N/A+let instr_size = function
1964N/A+ Lend -> 0
1964N/A+ | Lop(Imove | Ispill | Ireload) -> 1
1964N/A+ | Lop(Iconst_int n) -> if is_native_immediate n then 1 else 2
1964N/A+ | Lop(Iconst_float s) -> 2
1964N/A+ | Lop(Iconst_symbol s) -> 2
1964N/A+ | Lop(Icall_ind) -> 6
1964N/A+ | Lop(Icall_imm s) -> 7
1964N/A+ | Lop(Itailcall_ind) -> if !contains_calls then 7 else if has_stack_frame() then 5 else 4
1964N/A+ | Lop(Itailcall_imm s) -> if s = !function_name then 1 else
1964N/A+ if !contains_calls then 8 else
1964N/A+ if has_stack_frame() then 6 else 5
1964N/A+ | Lop(Iextcall(s, true)) -> 8
1964N/A+ | Lop(Iextcall(s, false)) -> 7
1964N/A+ | Lop(Istackoffset n) -> 0
1964N/A+ | Lop(Iload(chunk, addr)) ->
1964N/A+ if chunk = Byte_signed
1964N/A+ then load_store_size addr + 1
1964N/A+ else load_store_size addr
1964N/A+ | Lop(Istore(chunk, addr)) -> load_store_size addr
1964N/A+ | Lop(Ialloc n) -> 4
1964N/A+ | Lop(Ispecific(Ialloc_far n)) -> 5
1964N/A+ | Lop(Iintop Imod) -> 3
1964N/A+ | Lop(Iintop(Icomp cmp)) -> 4
1964N/A+ | Lop(Iintop op) -> 1
1964N/A+ | Lop(Iintop_imm(Idiv, n)) -> 2
1964N/A+ | Lop(Iintop_imm(Imod, n)) -> 4
1964N/A+ | Lop(Iintop_imm(Icomp cmp, n)) -> 4
1964N/A+ | Lop(Iintop_imm(op, n)) -> 1
1964N/A+ | Lop(Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf) -> 1
1964N/A+ | Lop(Ifloatofint) -> 3
1964N/A+ | Lop(Iintoffloat) -> 3
1964N/A+ | Lop(Ispecific sop) -> 1
1964N/A+ | Lreloadretaddr -> 2
1964N/A+ | Lreturn -> if has_stack_frame() then 2 else 1
1964N/A+ | Llabel lbl -> 0
1964N/A+ | Lbranch lbl -> 1
1964N/A+ | Lcondbranch(tst, lbl) -> 2
1964N/A+ | Lcondbranch3(lbl0, lbl1, lbl2) ->
1964N/A+ 1 + (if lbl0 = None then 0 else 1)
1964N/A+ + (if lbl1 = None then 0 else 1)
1964N/A+ + (if lbl2 = None then 0 else 1)
1964N/A+ | Lswitch jumptbl -> 7
1964N/A+ | Lsetuptrap lbl -> 1
1964N/A+ | Lpushtrap -> 7
1964N/A+ | Lpoptrap -> 1
1964N/A+ | Lraise -> 6
1964N/A+
1964N/A+let label_map code =
1964N/A+ let map = Hashtbl.create 37 in
1964N/A+ let rec fill_map pc instr =
1964N/A+ match instr.desc with
1964N/A+ Lend -> (pc, map)
1964N/A+ | Llabel lbl -> Hashtbl.add map lbl pc; fill_map pc instr.next
1964N/A+ | op -> fill_map (pc + instr_size op) instr.next
1964N/A+ in fill_map 0 code
1964N/A+
1964N/A+let max_branch_offset = 8180
1964N/A+(* 14-bit signed offset in words. Remember to cut some slack
1964N/A+ for multi-word instructions where the branch can be anywhere in
1964N/A+ the middle. 12 words of slack is plenty. *)
1964N/A+
1964N/A+let branch_overflows map pc_branch lbl_dest =
1964N/A+ let pc_dest = Hashtbl.find map lbl_dest in
1964N/A+ let delta = pc_dest - (pc_branch + 1) in
1964N/A+ delta <= -max_branch_offset || delta >= max_branch_offset
1964N/A+
1964N/A+let opt_branch_overflows map pc_branch opt_lbl_dest =
1964N/A+ match opt_lbl_dest with
1964N/A+ None -> false
1964N/A+ | Some lbl_dest -> branch_overflows map pc_branch lbl_dest
1964N/A+
1964N/A+let fixup_branches codesize map code =
1964N/A+ let expand_optbranch lbl n arg next =
1964N/A+ match lbl with
1964N/A+ None -> next
1964N/A+ | Some l ->
1964N/A+ instr_cons (Lcondbranch(Iinttest_imm(Isigned Ceq, n), l))
1964N/A+ arg [||] next in
1964N/A+ let rec fixup did_fix pc instr =
1964N/A+ match instr.desc with
1964N/A+ Lend -> did_fix
1964N/A+ | Lcondbranch(test, lbl) when branch_overflows map pc lbl ->
1964N/A+ let lbl2 = new_label() in
1964N/A+ let cont =
1964N/A+ instr_cons (Lbranch lbl) [||] [||]
1964N/A+ (instr_cons (Llabel lbl2) [||] [||] instr.next) in
1964N/A+ instr.desc <- Lcondbranch(invert_test test, lbl2);
1964N/A+ instr.next <- cont;
1964N/A+ fixup true (pc + 2) instr.next
1964N/A+ | Lcondbranch3(lbl0, lbl1, lbl2)
1964N/A+ when opt_branch_overflows map pc lbl0
1964N/A+ || opt_branch_overflows map pc lbl1
1964N/A+ || opt_branch_overflows map pc lbl2 ->
1964N/A+ let cont =
1964N/A+ expand_optbranch lbl0 0 instr.arg
1964N/A+ (expand_optbranch lbl1 1 instr.arg
1964N/A+ (expand_optbranch lbl2 2 instr.arg instr.next)) in
1964N/A+ instr.desc <- cont.desc;
1964N/A+ instr.next <- cont.next;
1964N/A+ fixup true pc instr
1964N/A+ | Lop(Ialloc n) when codesize - pc >= max_branch_offset ->
1964N/A+ instr.desc <- Lop(Ispecific(Ialloc_far n));
1964N/A+ fixup true (pc + 4) instr.next
1964N/A+ | op ->
1964N/A+ fixup did_fix (pc + instr_size op) instr.next
1964N/A+ in fixup false 0 code
1964N/A+
1964N/A+(* Iterate branch expansion till all conditional branches are OK *)
1964N/A+
1964N/A+let rec branch_normalization code =
1964N/A+ let (codesize, map) = label_map code in
1964N/A+ if codesize >= max_branch_offset && fixup_branches codesize map code
1964N/A+ then branch_normalization code
1964N/A+ else ()
1964N/A+
1964N/A+
1964N/A+(* Output the assembly code for an instruction *)
1964N/A+
1964N/A+let rec emit_instr i dslot =
1964N/A+ match i.desc with
1964N/A+ Lend -> ()
1964N/A+ | Lop(Imove | Ispill | Ireload) ->
1964N/A+ let src = i.arg.(0) and dst = i.res.(0) in
1964N/A+ if src.loc <> dst.loc then begin
1964N/A+ match (src, dst) with
1964N/A+ {loc = Reg rs; typ = (Int | Addr)}, {loc = Reg rd} ->
1964N/A+ ` mr {emit_reg dst}, {emit_reg src}\n`
1964N/A+ | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Float} ->
1964N/A+ ` fmr {emit_reg dst}, {emit_reg src}\n`
1964N/A+ | {loc = Reg rs; typ = (Int | Addr)}, {loc = Stack sd} ->
1964N/A+ ` std {emit_reg src}, {emit_stack dst}\n`
1964N/A+ | {loc = Reg rs; typ = Float}, {loc = Stack sd} ->
1964N/A+ ` stfd {emit_reg src}, {emit_stack dst}\n`
1964N/A+ | {loc = Stack ss; typ = (Int | Addr)}, {loc = Reg rd} ->
1964N/A+ ` ld {emit_reg dst}, {emit_stack src}\n`
1964N/A+ | {loc = Stack ss; typ = Float}, {loc = Reg rd} ->
1964N/A+ ` lfd {emit_reg dst}, {emit_stack src}\n`
1964N/A+ | (_, _) ->
1964N/A+ fatal_error "Emit: Imove"
1964N/A+ end
1964N/A+ | Lop(Iconst_int n) ->
1964N/A+ if is_native_immediate n then
1964N/A+ ` li {emit_reg i.res.(0)}, {emit_nativeint n}\n`
1964N/A+ else if n >= -0x8000_0000n && n <= 0x7FFF_FFFFn then begin
1964N/A+ ` lis {emit_reg i.res.(0)}, {emit_int(nativehigh n)}\n`;
1964N/A+ if nativelow n <> 0 then
1964N/A+ ` ori {emit_reg i.res.(0)}, {emit_reg i.res.(0)}, {emit_int(nativelow n)}\n`
1964N/A+ end else begin
1964N/A+ ` ld {emit_reg i.res.(0)}, {emit_tocref (TocInt n)}\n`
1964N/A+ end
1964N/A+ | Lop(Iconst_float s) ->
1964N/A+ ` lfd {emit_reg i.res.(0)}, {emit_tocref (TocFloat s)}\n`
1964N/A+ | Lop(Iconst_symbol s) ->
1964N/A+ ` ld {emit_reg i.res.(0)}, {emit_tocref (TocSymOfs (s,0))}\n`
1964N/A+ | Lop(Icall_ind) ->
1964N/A+ ` std {emit_gpr 2},40({emit_gpr 1})\n`;
1964N/A+ ` ld {emit_gpr 2}, 8({emit_reg i.arg.(0)})\n`;
1964N/A+ ` ld {emit_reg i.arg.(0)}, 0({emit_reg i.arg.(0)})\n`;
1964N/A+ ` mtctr {emit_reg i.arg.(0)}\n`;
1964N/A+ record_frame i.live;
1964N/A+ ` bctrl\n`;
1964N/A+ ` ld {emit_gpr 2},40({emit_gpr 1})\n`
1964N/A+ | Lop(Icall_imm s) ->
1964N/A+ ` ld {emit_gpr 11}, {emit_tocref (TocSymOfs (s,0))}\n`;
1964N/A+ ` std {emit_gpr 2},40({emit_gpr 1})\n`;
1964N/A+ ` ld {emit_gpr 2}, 8({emit_gpr 11})\n`;
1964N/A+ ` ld {emit_gpr 11}, 0({emit_gpr 11})\n`;
1964N/A+ ` mtctr {emit_gpr 11}\n`;
1964N/A+ record_frame i.live;
1964N/A+ ` bctrl\n`;
1964N/A+ ` ld {emit_gpr 2},40({emit_gpr 1})\n`
1964N/A+ | Lop(Itailcall_ind) ->
1964N/A+ ` ld {emit_gpr 2}, 8({emit_reg i.arg.(0)})\n`;
1964N/A+ ` ld {emit_reg i.arg.(0)}, 0({emit_reg i.arg.(0)})\n`;
1964N/A+ ` mtctr {emit_reg i.arg.(0)}\n`;
1964N/A+ if has_stack_frame() then
1964N/A+ ` ld {emit_gpr 1}, 0({emit_gpr 1})\n`;
1964N/A+ if !contains_calls then begin
1964N/A+ ` ld {emit_gpr 11}, 16({emit_gpr 1})\n`;
1964N/A+ ` mtlr {emit_gpr 11}\n`
1964N/A+ end;
1964N/A+ ` bctr\n`
1964N/A+ | Lop(Itailcall_imm s) ->
1964N/A+ if s = !function_name then
1964N/A+ ` b {emit_label !tailrec_entry_point}\n`
1964N/A+ else begin
1964N/A+ if has_stack_frame() then
1964N/A+ ` ld {emit_gpr 1}, 0({emit_gpr 1})\n`;
1964N/A+ if !contains_calls then begin
1964N/A+ ` ld {emit_gpr 11}, 16({emit_gpr 1})\n`;
1964N/A+ ` mtlr {emit_gpr 11}\n`
1964N/A+ end;
1964N/A+ ` ld {emit_gpr 11}, {emit_tocref (TocSymOfs (s,0))}\n`;
1964N/A+ ` ld {emit_gpr 2}, 8({emit_gpr 11})\n`;
1964N/A+ ` ld {emit_gpr 11}, 0({emit_gpr 11})\n`;
1964N/A+ ` mtctr {emit_gpr 11}\n`;
1964N/A+ ` bctr\n`
1964N/A+ end
1964N/A+ | Lop(Iextcall(s, alloc)) ->
1964N/A+ if alloc then begin
1964N/A+ ` ld {emit_gpr 11}, {emit_tocref (TocSymOfs (s,0))}\n`;
1964N/A+ ` ld {emit_gpr 12}, {emit_tocref (TocSymOfs ("caml_c_call",0))}\n`;
1964N/A+ end else
1964N/A+ ` ld {emit_gpr 12}, {emit_tocref (TocSymOfs (s,0))}\n`;
1964N/A+ ` std {emit_gpr 2}, 40({emit_gpr 1})\n`;
1964N/A+ ` ld {emit_gpr 2}, 8({emit_gpr 12})\n`;
1964N/A+ ` ld {emit_gpr 12}, 0({emit_gpr 12})\n`;
1964N/A+ ` mtctr {emit_gpr 12}\n`;
1964N/A+ if alloc then record_frame i.live;
1964N/A+ ` bctrl\n`;
1964N/A+ ` ld {emit_gpr 2}, 40({emit_gpr 1})\n`
1964N/A+ | Lop(Istackoffset n) ->
1964N/A+ if n > !stack_args_size then
1964N/A+ stack_args_size := n
1964N/A+ | Lop(Iload(chunk, addr)) ->
1964N/A+ let loadinstr =
1964N/A+ match chunk with
1964N/A+ Byte_unsigned -> "lbz"
1964N/A+ | Byte_signed -> "lbz"
1964N/A+ | Sixteen_unsigned -> "lhz"
1964N/A+ | Sixteen_signed -> "lha"
1964N/A+ | Thirtytwo_unsigned -> "lwz"
1964N/A+ | Thirtytwo_signed -> "lwa"
1964N/A+ | Word -> "ld"
1964N/A+ | Single -> "lfs"
1964N/A+ | Double | Double_u -> "lfd" in
1964N/A+ emit_load_store loadinstr addr i.arg 0 i.res.(0);
1964N/A+ if chunk = Byte_signed then
1964N/A+ ` extsb {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
1964N/A+ | Lop(Istore(chunk, addr)) ->
1964N/A+ let storeinstr =
1964N/A+ match chunk with
1964N/A+ Byte_unsigned | Byte_signed -> "stb"
1964N/A+ | Sixteen_unsigned | Sixteen_signed -> "sth"
1964N/A+ | Thirtytwo_unsigned | Thirtytwo_signed -> "stw"
1964N/A+ | Word -> "std"
1964N/A+ | Single -> "stfs"
1964N/A+ | Double | Double_u -> "stfd" in
1964N/A+ emit_load_store storeinstr addr i.arg 1 i.arg.(0)
1964N/A+ | Lop(Ialloc n) ->
1964N/A+ if !call_gc_label = 0 then call_gc_label := new_label();
1964N/A+ ` addi {emit_gpr 31}, {emit_gpr 31}, {emit_int(-n)}\n`;
1964N/A+ ` cmpld {emit_gpr 31}, {emit_gpr 30}\n`;
1964N/A+ ` addi {emit_reg i.res.(0)}, {emit_gpr 31}, 8\n`;
1964N/A+ record_frame i.live;
1964N/A+ ` bltl {emit_label !call_gc_label}\n` (* Must be 4 insns to restart *)
1964N/A+ | Lop(Ispecific(Ialloc_far n)) ->
1964N/A+ if !call_gc_label = 0 then call_gc_label := new_label();
1964N/A+ let lbl = new_label() in
1964N/A+ ` addi {emit_gpr 31}, {emit_gpr 31}, {emit_int(-n)}\n`;
1964N/A+ ` cmpld {emit_gpr 31}, {emit_gpr 30}\n`;
1964N/A+ ` bge {emit_label lbl}\n`;
1964N/A+ record_frame i.live;
1964N/A+ ` bl {emit_label !call_gc_label}\n`; (* Must be 4 insns to restart *)
1964N/A+ `{emit_label lbl}: addi {emit_reg i.res.(0)}, {emit_gpr 31}, 4\n`
1964N/A+ | Lop(Iintop Isub) -> (* subfc has swapped arguments *)
1964N/A+ ` subfc {emit_reg i.res.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`
1964N/A+ | Lop(Iintop Imod) ->
1964N/A+ ` divd {emit_gpr 0}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`;
1964N/A+ ` mulld {emit_gpr 0}, {emit_gpr 0}, {emit_reg i.arg.(1)}\n`;
1964N/A+ ` subfc {emit_reg i.res.(0)}, {emit_gpr 0}, {emit_reg i.arg.(0)}\n`
1964N/A+ | Lop(Iintop(Icomp cmp)) ->
1964N/A+ begin match cmp with
1964N/A+ Isigned c ->
1964N/A+ ` cmpd {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`;
1964N/A+ emit_set_comp c i.res.(0)
1964N/A+ | Iunsigned c ->
1964N/A+ ` cmpld {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`;
1964N/A+ emit_set_comp c i.res.(0)
1964N/A+ end
1964N/A+ | Lop(Iintop Icheckbound) ->
1964N/A+ ` tdlle {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`
1964N/A+ | Lop(Iintop op) ->
1964N/A+ let instr = name_for_intop op in
1964N/A+ ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`
1964N/A+ | Lop(Iintop_imm(Isub, n)) ->
1964N/A+ ` addi {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int(-n)}\n`
1964N/A+ | Lop(Iintop_imm(Idiv, n)) -> (* n is guaranteed to be a power of 2 *)
1964N/A+ let l = Misc.log2 n in
1964N/A+ ` sradi {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int l}\n`;
1964N/A+ ` addze {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
1964N/A+ | Lop(Iintop_imm(Imod, n)) -> (* n is guaranteed to be a power of 2 *)
1964N/A+ let l = Misc.log2 n in
1964N/A+ ` sradi {emit_gpr 0}, {emit_reg i.arg.(0)}, {emit_int l}\n`;
1964N/A+ ` addze {emit_gpr 0}, {emit_gpr 0}\n`;
1964N/A+ ` sldi {emit_gpr 0}, {emit_gpr 0}, {emit_int l}\n`;
1964N/A+ ` subfc {emit_reg i.res.(0)}, {emit_gpr 0}, {emit_reg i.arg.(0)}\n`
1964N/A+ | Lop(Iintop_imm(Icomp cmp, n)) ->
1964N/A+ begin match cmp with
1964N/A+ Isigned c ->
1964N/A+ ` cmpdi {emit_reg i.arg.(0)}, {emit_int n}\n`;
1964N/A+ emit_set_comp c i.res.(0)
1964N/A+ | Iunsigned c ->
1964N/A+ ` cmpldi {emit_reg i.arg.(0)}, {emit_int n}\n`;
1964N/A+ emit_set_comp c i.res.(0)
1964N/A+ end
1964N/A+ | Lop(Iintop_imm(Icheckbound, n)) ->
1964N/A+ ` tdllei {emit_reg i.arg.(0)}, {emit_int n}\n`
1964N/A+ | Lop(Iintop_imm(op, n)) ->
1964N/A+ let instr = name_for_intop_imm op in
1964N/A+ ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int n}\n`
1964N/A+ | Lop(Inegf | Iabsf as op) ->
1964N/A+ let instr = name_for_floatop1 op in
1964N/A+ ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}\n`
1964N/A+ | Lop(Iaddf | Isubf | Imulf | Idivf as op) ->
1964N/A+ let instr = name_for_floatop2 op in
1964N/A+ ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`
1964N/A+ | Lop(Ifloatofint) ->
1964N/A+ let ofs = if has_stack_frame() then 16 else 8 * (2 + num_stack_slots.(0) + num_stack_slots.(1)) in
1964N/A+ ` std {emit_reg i.arg.(0)}, -{emit_int ofs}({emit_gpr 1})\n`;
1964N/A+ ` lfd {emit_reg i.res.(0)}, -{emit_int ofs}({emit_gpr 1})\n`;
1964N/A+ ` fcfid {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n`
1964N/A+ | Lop(Iintoffloat) ->
1964N/A+ let ofs = if has_stack_frame() then 16 else 8 * (2 + num_stack_slots.(0) + num_stack_slots.(1)) in
1964N/A+ ` fctidz {emit_fpr 0}, {emit_reg i.arg.(0)}\n`;
1964N/A+ ` stfd {emit_fpr 0}, -{emit_int ofs}({emit_gpr 1})\n`;
1964N/A+ ` ld {emit_reg i.res.(0)}, -{emit_int ofs}({emit_gpr 1})\n`
1964N/A+ | Lop(Ispecific sop) ->
1964N/A+ let instr = name_for_specific sop in
1964N/A+ ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.arg.(2)}\n`
1964N/A+ | Lreloadretaddr ->
1964N/A+ if has_stack_frame() then begin
1964N/A+ ` ld {emit_gpr 11}, {emit_label !stack_size_lbl}+16({emit_gpr 1})\n`;
1964N/A+ ` mtlr {emit_gpr 11}\n`
1964N/A+ end
1964N/A+ | Lreturn ->
1964N/A+ if has_stack_frame() then
1964N/A+ ` ld {emit_gpr 1}, 0({emit_gpr 1})\n`;
1964N/A+ ` blr\n`
1964N/A+ | Llabel lbl ->
1964N/A+ `{emit_label lbl}:\n`
1964N/A+ | Lbranch lbl ->
1964N/A+ ` b {emit_label lbl}\n`
1964N/A+ | Lcondbranch(tst, lbl) ->
1964N/A+ begin match tst with
1964N/A+ Itruetest ->
1964N/A+ ` cmpdi {emit_reg i.arg.(0)}, 0\n`;
1964N/A+ emit_delay dslot;
1964N/A+ ` bne {emit_label lbl}\n`
1964N/A+ | Ifalsetest ->
1964N/A+ ` cmpdi {emit_reg i.arg.(0)}, 0\n`;
1964N/A+ emit_delay dslot;
1964N/A+ ` beq {emit_label lbl}\n`
1964N/A+ | Iinttest cmp ->
1964N/A+ let (comp, branch) = name_for_int_comparison cmp in
1964N/A+ ` {emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`;
1964N/A+ emit_delay dslot;
1964N/A+ ` {emit_string branch} {emit_label lbl}\n`
1964N/A+ | Iinttest_imm(cmp, n) ->
1964N/A+ let (comp, branch) = name_for_int_comparison cmp in
1964N/A+ ` {emit_string comp}i {emit_reg i.arg.(0)}, {emit_int n}\n`;
1964N/A+ emit_delay dslot;
1964N/A+ ` {emit_string branch} {emit_label lbl}\n`
1964N/A+ | Ifloattest(cmp, neg) ->
1964N/A+ ` fcmpu {emit_ccr 0}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`;
1964N/A+ (* bit 0 = lt, bit 1 = gt, bit 2 = eq *)
1964N/A+ let (bitnum, negtst) =
1964N/A+ match cmp with
1964N/A+ Ceq -> (2, neg)
1964N/A+ | Cne -> (2, not neg)
1964N/A+ | Cle -> ` cror 3, 0, 2\n`; (* lt or eq *)
1964N/A+ (3, neg)
1964N/A+ | Cgt -> (1, neg)
1964N/A+ | Cge -> ` cror 3, 1, 2\n`; (* gt or eq *)
1964N/A+ (3, neg)
1964N/A+ | Clt -> (0, neg) in
1964N/A+ emit_delay dslot;
1964N/A+ if negtst
1964N/A+ then ` bf {emit_int bitnum}, {emit_label lbl}\n`
1964N/A+ else ` bt {emit_int bitnum}, {emit_label lbl}\n`
1964N/A+ | Ioddtest ->
1964N/A+ ` andi. {emit_gpr 0}, {emit_reg i.arg.(0)}, 1\n`;
1964N/A+ emit_delay dslot;
1964N/A+ ` bne {emit_label lbl}\n`
1964N/A+ | Ieventest ->
1964N/A+ ` andi. {emit_gpr 0}, {emit_reg i.arg.(0)}, 1\n`;
1964N/A+ emit_delay dslot;
1964N/A+ ` beq {emit_label lbl}\n`
1964N/A+ end
1964N/A+ | Lcondbranch3(lbl0, lbl1, lbl2) ->
1964N/A+ ` cmpdi {emit_reg i.arg.(0)}, 1\n`;
1964N/A+ emit_delay dslot;
1964N/A+ begin match lbl0 with
1964N/A+ None -> ()
1964N/A+ | Some lbl -> ` blt {emit_label lbl}\n`
1964N/A+ end;
1964N/A+ begin match lbl1 with
1964N/A+ None -> ()
1964N/A+ | Some lbl -> ` beq {emit_label lbl}\n`
1964N/A+ end;
1964N/A+ begin match lbl2 with
1964N/A+ None -> ()
1964N/A+ | Some lbl -> ` bgt {emit_label lbl}\n`
1964N/A+ end
1964N/A+ | Lswitch jumptbl ->
1964N/A+ if !lbl_jumptbl = 0 then lbl_jumptbl := new_label();
1964N/A+ ` ld {emit_gpr 11}, {emit_tocref (TocLabel !lbl_jumptbl)}\n`;
1964N/A+ ` addi {emit_gpr 0}, {emit_reg i.arg.(0)}, {emit_int !num_jumptbl_entries}\n`;
1964N/A+ ` sldi {emit_gpr 0}, {emit_gpr 0}, 2\n`;
1964N/A+ ` lwax {emit_gpr 0}, {emit_gpr 11}, {emit_gpr 0}\n`;
1964N/A+ ` add {emit_gpr 0}, {emit_gpr 11}, {emit_gpr 0}\n`;
1964N/A+ ` mtctr {emit_gpr 0}\n`;
1964N/A+ ` bctr\n`;
1964N/A+ for i = 0 to Array.length jumptbl - 1 do
1964N/A+ jumptbl_entries := jumptbl.(i) :: !jumptbl_entries;
1964N/A+ incr num_jumptbl_entries
1964N/A+ done
1964N/A+ | Lsetuptrap lbl ->
1964N/A+ ` bl {emit_label lbl}\n`;
1964N/A+ | Lpushtrap ->
1964N/A+ stack_traps_size := !stack_traps_size + 32;
1964N/A+ ` addi {emit_gpr 11}, {emit_gpr 1}, {emit_label !stack_size_lbl}-{emit_int !stack_traps_size}\n`;
1964N/A+ ` mflr {emit_gpr 0}\n`;
1964N/A+ ` std {emit_gpr 29}, 0({emit_gpr 11})\n`;
1964N/A+ ` std {emit_gpr 0}, 8({emit_gpr 11})\n`;
1964N/A+ ` std {emit_gpr 1}, 16({emit_gpr 11})\n`;
1964N/A+ ` std {emit_gpr 2}, 24({emit_gpr 11})\n`;
1964N/A+ ` mr {emit_gpr 29}, {emit_gpr 11}\n`
1964N/A+ | Lpoptrap ->
1964N/A+ ` ld {emit_gpr 29}, 0({emit_gpr 29})\n`
1964N/A+ | Lraise ->
1964N/A+ ` ld {emit_gpr 0}, 8({emit_gpr 29})\n`;
1964N/A+ ` ld {emit_gpr 1}, 16({emit_gpr 29})\n`;
1964N/A+ ` ld {emit_gpr 2}, 24({emit_gpr 29})\n`;
1964N/A+ ` mtlr {emit_gpr 0}\n`;
1964N/A+ ` ld {emit_gpr 29}, 0({emit_gpr 29})\n`;
1964N/A+ ` blr\n`
1964N/A+
1964N/A+and emit_delay = function
1964N/A+ None -> ()
1964N/A+ | Some i -> emit_instr i None
1964N/A+
1964N/A+(* Checks if a pseudo-instruction expands to instructions
1964N/A+ that do not branch and do not affect CR0 nor R12. *)
1964N/A+
1964N/A+let is_simple_instr i =
1964N/A+ match i.desc with
1964N/A+ Lop op ->
1964N/A+ begin match op with
1964N/A+ Icall_imm _ | Icall_ind | Itailcall_imm _ | Itailcall_ind |
1964N/A+ Iextcall(_, _) -> false
1964N/A+ | Ialloc(_) -> false
1964N/A+ | Iintop(Icomp _) -> false
1964N/A+ | Iintop_imm(Iand, _) -> false
1964N/A+ | Iintop_imm(Icomp _, _) -> false
1964N/A+ | _ -> true
1964N/A+ end
1964N/A+ | Lreloadretaddr -> true
1964N/A+ | _ -> false
1964N/A+
1964N/A+let no_interference res arg =
1964N/A+ try
1964N/A+ for i = 0 to Array.length arg - 1 do
1964N/A+ for j = 0 to Array.length res - 1 do
1964N/A+ if arg.(i).loc = res.(j).loc then raise Exit
1964N/A+ done
1964N/A+ done;
1964N/A+ true
1964N/A+ with Exit ->
1964N/A+ false
1964N/A+
1964N/A+(* Emit a sequence of instructions, trying to fill delay slots for branches *)
1964N/A+
1964N/A+let rec emit_all i =
1964N/A+ match i with
1964N/A+ {desc = Lend} -> ()
1964N/A+ | {next = {desc = (Lcondbranch(_, _) | Lcondbranch3(_, _, _))}}
1964N/A+ when is_simple_instr i & no_interference i.res i.next.arg ->
1964N/A+ emit_instr i.next (Some i);
1964N/A+ emit_all i.next.next
1964N/A+ | _ ->
1964N/A+ emit_instr i None;
1964N/A+ emit_all i.next
1964N/A+
1964N/A+(* Emission of a function declaration *)
1964N/A+
1964N/A+let fundecl fundecl =
1964N/A+ function_name := fundecl.fun_name;
1964N/A+ defined_functions := StringSet.add fundecl.fun_name !defined_functions;
1964N/A+ tailrec_entry_point := new_label();
1964N/A+ if has_stack_frame() then
1964N/A+ stack_size_lbl := new_label();
1964N/A+ stack_slot_lbl := new_label();
1964N/A+ stack_args_size := 0;
1964N/A+ stack_traps_size := 0;
1964N/A+ call_gc_label := 0;
1964N/A+ ` .globl {emit_symbol fundecl.fun_name}\n`;
1964N/A+ begin match Config.system with
1964N/A+ | "elf" | "bsd" ->
1964N/A+ ` .section \".opd\",\"aw\"\n`;
1964N/A+ ` .align 3\n`;
1964N/A+ ` .type {emit_symbol fundecl.fun_name}, @function\n`;
1964N/A+ `{emit_symbol fundecl.fun_name}:\n`;
1964N/A+ ` .quad .L.{emit_symbol fundecl.fun_name},.TOC.@tocbase\n`;
1964N/A+ ` .previous\n`;
1964N/A+ ` .align 2\n`;
1964N/A+ emit_string code_space;
1964N/A+ `.L.{emit_symbol fundecl.fun_name}:\n`
1964N/A+ | _ ->
1964N/A+ ` .align 2\n`;
1964N/A+ emit_string code_space;
1964N/A+ `{emit_symbol fundecl.fun_name}:\n`
1964N/A+ end;
1964N/A+ if !contains_calls then begin
1964N/A+ ` mflr {emit_gpr 0}\n`;
1964N/A+ ` std {emit_gpr 0}, 16({emit_gpr 1})\n`
1964N/A+ end;
1964N/A+ if has_stack_frame() then
1964N/A+ ` stdu {emit_gpr 1}, -{emit_label !stack_size_lbl}({emit_gpr 1})\n`;
1964N/A+ `{emit_label !tailrec_entry_point}:\n`;
1964N/A+ branch_normalization fundecl.fun_body;
1964N/A+ emit_all fundecl.fun_body;
1964N/A+ ` .size .L.{emit_symbol fundecl.fun_name}, . - .L.{emit_symbol fundecl.fun_name}\n`;
1964N/A+ if has_stack_frame() then begin
1964N/A+ ` .set {emit_label !stack_size_lbl},{emit_int (frame_size_sans_args() + !stack_args_size + !stack_traps_size)} # stack size including traps\n`;
1964N/A+ ` .set {emit_label !stack_slot_lbl},{emit_int (48 + !stack_args_size)} # stack slot offset\n`
1964N/A+ end else (* leave 8 bytes for float <-> conversions *)
1964N/A+ ` .set {emit_label !stack_slot_lbl},{emit_int (40-frame_size_sans_args())} # stack slot offset (negative)\n`;
1964N/A+
1964N/A+ (* Emit the glue code to call the GC *)
1964N/A+ if !call_gc_label > 0 then begin
1964N/A+ `{emit_label !call_gc_label}:\n`;
1964N/A+ ` ld {emit_gpr 12}, {emit_tocref (TocSymOfs ("caml_call_gc",0))}\n`;
1964N/A+ ` ld {emit_gpr 12}, 0({emit_gpr 12})\n`;
1964N/A+ ` mtctr {emit_gpr 12}\n`;
1964N/A+ ` bctr\n`;
1964N/A+ end
1964N/A+
1964N/A+(* Emission of data *)
1964N/A+
1964N/A+let declare_global_data s =
1964N/A+ ` .globl {emit_symbol s}\n`;
1964N/A+ if Config.system = "elf" || Config.system = "bsd" then
1964N/A+ ` .type {emit_symbol s}, @object\n`
1964N/A+
1964N/A+let emit_item = function
1964N/A+ Cglobal_symbol s ->
1964N/A+ declare_global_data s
1964N/A+ | Cdefine_symbol s ->
1964N/A+ `{emit_symbol s}:\n`;
1964N/A+ | Cdefine_label lbl ->
1964N/A+ `{emit_label (lbl + 100000)}:\n`
1964N/A+ | Cint8 n ->
1964N/A+ ` .byte {emit_int n}\n`
1964N/A+ | Cint16 n ->
1964N/A+ ` .short {emit_int n}\n`
1964N/A+ | Cint32 n ->
1964N/A+ ` .long {emit_nativeint n}\n`
1964N/A+ | Cint n ->
1964N/A+ ` .quad {emit_nativeint n}\n`
1964N/A+ | Csingle f ->
1964N/A+ ` .float 0d{emit_string f}\n`
1964N/A+ | Cdouble f ->
1964N/A+ ` .double 0d{emit_string f}\n`
1964N/A+ | Csymbol_address s ->
1964N/A+ ` .quad {emit_symbol s}\n`
1964N/A+ | Clabel_address lbl ->
1964N/A+ ` .quad {emit_label (lbl + 100000)}\n`
1964N/A+ | Cstring s ->
1964N/A+ emit_bytes_directive " .byte " s
1964N/A+ | Cskip n ->
1964N/A+ if n > 0 then ` .space {emit_int n}\n`
1964N/A+ | Calign n ->
1964N/A+ ` .align {emit_int (Misc.log2 n)}\n`
1964N/A+
1964N/A+let data l =
1964N/A+ emit_string data_space;
1964N/A+ List.iter emit_item l
1964N/A+
1964N/A+(* Beginning / end of an assembly file *)
1964N/A+
1964N/A+let begin_assembly() =
1964N/A+ defined_functions := StringSet.empty;
1964N/A+ external_functions := StringSet.empty;
1964N/A+ tocref_entries := [];
1964N/A+ num_jumptbl_entries := 0;
1964N/A+ jumptbl_entries := [];
1964N/A+ lbl_jumptbl := 0;
1964N/A+ (* Emit the beginning of the segments *)
1964N/A+ let lbl_begin = Compilenv.make_symbol (Some "data_begin") in
1964N/A+ emit_string data_space;
1964N/A+ declare_global_data lbl_begin;
1964N/A+ `{emit_symbol lbl_begin}:\n`;
1964N/A+ let lbl_begin = Compilenv.make_symbol (Some "code_begin") in
1964N/A+ emit_string code_space;
1964N/A+ declare_global_data lbl_begin;
1964N/A+ `{emit_symbol lbl_begin}:\n`
1964N/A+
1964N/A+let end_assembly() =
1964N/A+ (* Emit the jump table *)
1964N/A+ if !num_jumptbl_entries > 0 then begin
1964N/A+ emit_string code_space;
1964N/A+ `{emit_label !lbl_jumptbl}:\n`;
1964N/A+ List.iter
1964N/A+ (fun lbl -> ` .long {emit_label lbl} - {emit_label !lbl_jumptbl}\n`)
1964N/A+ (List.rev !jumptbl_entries);
1964N/A+ jumptbl_entries := []
1964N/A+ end;
1964N/A+ if !tocref_entries <> [] then begin
1964N/A+ emit_string toc_space;
1964N/A+ List.iter
1964N/A+ (fun (lbl, entry) ->
1964N/A+ `{emit_label lbl}:\n`;
1964N/A+ match entry with
1964N/A+ TocFloat f ->
1964N/A+ ` .double {emit_tocentry entry}\n`
1964N/A+ | _ ->
1964N/A+ ` .tc {emit_label lbl}[TC],{emit_tocentry entry}\n`
1964N/A+ )
1964N/A+ !tocref_entries;
1964N/A+ tocref_entries := []
1964N/A+ end;
1964N/A+ if pic_externals then
1964N/A+ (* Emit the pointers to external functions *)
1964N/A+ StringSet.iter emit_external !external_functions;
1964N/A+ (* Emit the end of the segments *)
1964N/A+ emit_string code_space;
1964N/A+ let lbl_end = Compilenv.make_symbol (Some "code_end") in
1964N/A+ declare_global_data lbl_end;
1964N/A+ `{emit_symbol lbl_end}:\n`;
1964N/A+ ` .long 0\n`;
1964N/A+ emit_string data_space;
1964N/A+ let lbl_end = Compilenv.make_symbol (Some "data_end") in
1964N/A+ declare_global_data lbl_end;
1964N/A+ `{emit_symbol lbl_end}:\n`;
1964N/A+ ` .quad 0\n`;
1964N/A+ (* Emit the frame descriptors *)
1964N/A+ emit_string rodata_space;
1964N/A+ let lbl = Compilenv.make_symbol (Some "frametable") in
1964N/A+ declare_global_data lbl;
1964N/A+ `{emit_symbol lbl}:\n`;
1964N/A+ ` .quad {emit_int (List.length !frame_descriptors)}\n`;
1964N/A+ List.iter emit_frame !frame_descriptors;
1964N/A+ frame_descriptors := []
1964N/Adiff -uNr ocaml-3.10.1/asmcomp/power64/proc.ml ocaml-3.10.1.ppc64/asmcomp/power64/proc.ml
1964N/A--- ocaml-3.10.1/asmcomp/power64/proc.ml 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmcomp/power64/proc.ml 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,245 @@
1964N/A+(***********************************************************************)
1964N/A+(* *)
1964N/A+(* Objective Caml *)
1964N/A+(* *)
1964N/A+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
1964N/A+(* *)
1964N/A+(* Copyright 1996 Institut National de Recherche en Informatique et *)
1964N/A+(* en Automatique. All rights reserved. This file is distributed *)
1964N/A+(* under the terms of the Q Public License version 1.0. *)
1964N/A+(* *)
1964N/A+(***********************************************************************)
1964N/A+
1964N/A+(* $Id: proc.ml,v 1.12 2004/06/19 17:39:35 xleroy Exp $ *)
1964N/A+
1964N/A+(* Description of the Power PC *)
1964N/A+
1964N/A+open Misc
1964N/A+open Cmm
1964N/A+open Reg
1964N/A+open Arch
1964N/A+open Mach
1964N/A+
1964N/A+(* Instruction selection *)
1964N/A+
1964N/A+let word_addressed = false
1964N/A+
1964N/A+(* Registers available for register allocation *)
1964N/A+
1964N/A+(* Integer register map:
1964N/A+ 0 temporary, null register for some operations
1964N/A+ 1 stack pointer
1964N/A+ 2 pointer to table of contents
1964N/A+ 3 - 10 function arguments and results
1964N/A+ 11 - 12 temporaries
1964N/A+ 13 pointer to small data area
1964N/A+ 14 - 28 general purpose, preserved by C
1964N/A+ 29 trap pointer
1964N/A+ 30 allocation limit
1964N/A+ 31 allocation pointer
1964N/A+ Floating-point register map:
1964N/A+ 0 temporary
1964N/A+ 1 - 13 function arguments and results
1964N/A+ 14 - 31 general purpose, preserved by C
1964N/A+*)
1964N/A+
1964N/A+let int_reg_name =
1964N/A+ if Config.system = "rhapsody" then
1964N/A+ [| "r3"; "r4"; "r5"; "r6"; "r7"; "r8"; "r9"; "r10";
1964N/A+ "r14"; "r15"; "r16"; "r17"; "r18"; "r19"; "r20"; "r21";
1964N/A+ "r22"; "r23"; "r24"; "r25"; "r26"; "r27"; "r28" |]
1964N/A+ else
1964N/A+ [| "3"; "4"; "5"; "6"; "7"; "8"; "9"; "10";
1964N/A+ "14"; "15"; "16"; "17"; "18"; "19"; "20"; "21";
1964N/A+ "22"; "23"; "24"; "25"; "26"; "27"; "28" |]
1964N/A+
1964N/A+let float_reg_name =
1964N/A+ if Config.system = "rhapsody" then
1964N/A+ [| "f1"; "f2"; "f3"; "f4"; "f5"; "f6"; "f7"; "f8";
1964N/A+ "f9"; "f10"; "f11"; "f12"; "f13"; "f14"; "f15"; "f16";
1964N/A+ "f17"; "f18"; "f19"; "f20"; "f21"; "f22"; "f23"; "f24";
1964N/A+ "f25"; "f26"; "f27"; "f28"; "f29"; "f30"; "f31" |]
1964N/A+ else
1964N/A+ [| "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8";
1964N/A+ "9"; "10"; "11"; "12"; "13"; "14"; "15"; "16";
1964N/A+ "17"; "18"; "19"; "20"; "21"; "22"; "23"; "24";
1964N/A+ "25"; "26"; "27"; "28"; "29"; "30"; "31" |]
1964N/A+
1964N/A+let num_register_classes = 2
1964N/A+
1964N/A+let register_class r =
1964N/A+ match r.typ with
1964N/A+ Int -> 0
1964N/A+ | Addr -> 0
1964N/A+ | Float -> 1
1964N/A+
1964N/A+let num_available_registers = [| 23; 31 |]
1964N/A+
1964N/A+let first_available_register = [| 0; 100 |]
1964N/A+
1964N/A+let register_name r =
1964N/A+ if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100)
1964N/A+
1964N/A+let rotate_registers = true
1964N/A+
1964N/A+(* Representation of hard registers by pseudo-registers *)
1964N/A+
1964N/A+let hard_int_reg =
1964N/A+ let v = Array.create 23 Reg.dummy in
1964N/A+ for i = 0 to 22 do v.(i) <- Reg.at_location Int (Reg i) done; v
1964N/A+
1964N/A+let hard_float_reg =
1964N/A+ let v = Array.create 31 Reg.dummy in
1964N/A+ for i = 0 to 30 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; v
1964N/A+
1964N/A+let all_phys_regs =
1964N/A+ Array.append hard_int_reg hard_float_reg
1964N/A+
1964N/A+let phys_reg n =
1964N/A+ if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100)
1964N/A+
1964N/A+let stack_slot slot ty =
1964N/A+ Reg.at_location ty (Stack slot)
1964N/A+
1964N/A+(* Calling conventions *)
1964N/A+
1964N/A+let calling_conventions
1964N/A+ first_int last_int first_float last_float make_stack stack_ofs arg =
1964N/A+ let loc = Array.create (Array.length arg) Reg.dummy in
1964N/A+ let int = ref first_int in
1964N/A+ let float = ref first_float in
1964N/A+ let ofs = ref stack_ofs in
1964N/A+ for i = 0 to Array.length arg - 1 do
1964N/A+ match arg.(i).typ with
1964N/A+ Int | Addr as ty ->
1964N/A+ if !int <= last_int then begin
1964N/A+ loc.(i) <- phys_reg !int;
1964N/A+ incr int
1964N/A+ end else begin
1964N/A+ loc.(i) <- stack_slot (make_stack !ofs) ty;
1964N/A+ end;
1964N/A+ ofs := !ofs + 8
1964N/A+ | Float ->
1964N/A+ if !float <= last_float then begin
1964N/A+ loc.(i) <- phys_reg !float;
1964N/A+ incr float
1964N/A+ end else begin
1964N/A+ loc.(i) <- stack_slot (make_stack !ofs) Float;
1964N/A+ end;
1964N/A+ ofs := !ofs + 8
1964N/A+ done;
1964N/A+ (loc, Misc.align !ofs 16)
1964N/A+ (* Keep stack 16-aligned. *)
1964N/A+
1964N/A+let incoming ofs = Incoming ofs
1964N/A+let outgoing ofs = Outgoing ofs
1964N/A+let not_supported ofs = fatal_error "Proc.loc_results: cannot call"
1964N/A+
1964N/A+let loc_arguments arg =
1964N/A+ calling_conventions 0 7 100 112 outgoing 48 arg
1964N/A+let loc_parameters arg =
1964N/A+ let (loc, ofs) = calling_conventions 0 7 100 112 incoming 0 arg in loc
1964N/A+let loc_results res =
1964N/A+ let (loc, ofs) = calling_conventions 0 7 100 112 not_supported 0 res in loc
1964N/A+
1964N/A+(* C calling conventions under PowerOpen:
1964N/A+ use GPR 3-10 and FPR 1-13 just like ML calling
1964N/A+ conventions, but always reserve stack space for all arguments.
1964N/A+ Also, using a float register automatically reserves two int registers
1964N/A+ (in 32-bit mode) or one int register (in 64-bit mode).
1964N/A+ (If we were to call a non-prototyped C function, each float argument
1964N/A+ would have to go both in a float reg and in the matching pair
1964N/A+ of integer regs.)
1964N/A+
1964N/A+ C calling conventions under SVR4:
1964N/A+ use GPR 3-10 and FPR 1-8 just like ML calling conventions.
1964N/A+ Using a float register does not affect the int registers.
1964N/A+ Always reserve 8 bytes at bottom of stack, plus whatever is needed
1964N/A+ to hold the overflow arguments. *)
1964N/A+
1964N/A+let poweropen_external_conventions first_int last_int
1964N/A+ first_float last_float arg =
1964N/A+ let loc = Array.create (Array.length arg) Reg.dummy in
1964N/A+ let int = ref first_int in
1964N/A+ let float = ref first_float in
1964N/A+ let ofs = ref 112 in
1964N/A+ for i = 0 to Array.length arg - 1 do
1964N/A+ match arg.(i).typ with
1964N/A+ Int | Addr as ty ->
1964N/A+ if !int <= last_int then begin
1964N/A+ loc.(i) <- phys_reg !int;
1964N/A+ incr int
1964N/A+ end else begin
1964N/A+ loc.(i) <- stack_slot (Outgoing !ofs) ty;
1964N/A+ ofs := !ofs + size_int
1964N/A+ end
1964N/A+ | Float ->
1964N/A+ if !float <= last_float then begin
1964N/A+ loc.(i) <- phys_reg !float;
1964N/A+ incr float
1964N/A+ end else begin
1964N/A+ loc.(i) <- stack_slot (Outgoing !ofs) Float;
1964N/A+ ofs := !ofs + size_float
1964N/A+ end;
1964N/A+ int := !int + 1
1964N/A+ done;
1964N/A+ (loc, Misc.align !ofs 16) (* Keep stack 16-aligned *)
1964N/A+
1964N/A+let loc_external_arguments =
1964N/A+ match Config.system with
1964N/A+ | "rhapsody" -> poweropen_external_conventions 0 7 100 112
1964N/A+ | "elf" | "bsd" -> calling_conventions 0 7 100 107 outgoing 8
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+let extcall_use_push = false
1964N/A+
1964N/A+(* Results are in GPR 3 and FPR 1 *)
1964N/A+
1964N/A+let loc_external_results res =
1964N/A+ let (loc, ofs) = calling_conventions 0 0 100 100 not_supported 0 res in loc
1964N/A+
1964N/A+(* Exceptions are in GPR 3 *)
1964N/A+
1964N/A+let loc_exn_bucket = phys_reg 0
1964N/A+
1964N/A+(* Registers destroyed by operations *)
1964N/A+
1964N/A+let destroyed_at_c_call =
1964N/A+ Array.of_list(List.map phys_reg
1964N/A+ [0; 1; 2; 3; 4; 5; 6; 7;
1964N/A+ 100; 101; 102; 103; 104; 105; 106; 107; 108; 109; 110; 111; 112])
1964N/A+
1964N/A+let destroyed_at_oper = function
1964N/A+ Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs
1964N/A+ | Iop(Iextcall(_, false)) -> destroyed_at_c_call
1964N/A+ | _ -> [||]
1964N/A+
1964N/A+let destroyed_at_raise = all_phys_regs
1964N/A+
1964N/A+(* Maximal register pressure *)
1964N/A+
1964N/A+let safe_register_pressure = function
1964N/A+ Iextcall(_, _) -> 15
1964N/A+ | _ -> 23
1964N/A+
1964N/A+let max_register_pressure = function
1964N/A+ Iextcall(_, _) -> [| 15; 18 |]
1964N/A+ | _ -> [| 23; 30 |]
1964N/A+
1964N/A+(* Layout of the stack *)
1964N/A+
1964N/A+let num_stack_slots = [| 0; 0 |]
1964N/A+let contains_calls = ref false
1964N/A+
1964N/A+(* Calling the assembler *)
1964N/A+
1964N/A+let assemble_file infile outfile =
1964N/A+ let infile = Filename.quote infile
1964N/A+ and outfile = Filename.quote outfile in
1964N/A+ match Config.system with
1964N/A+ | "elf" ->
1964N/A+ Ccomp.command ("as -u -m ppc64 -o " ^ outfile ^ " " ^ infile)
1964N/A+ | _ -> assert false
1964N/A+
1964N/A+open Clflags;;
1964N/A+open Config;;
1964N/Adiff -uNr ocaml-3.10.1/asmcomp/power64/reload.ml ocaml-3.10.1.ppc64/asmcomp/power64/reload.ml
1964N/A--- ocaml-3.10.1/asmcomp/power64/reload.ml 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmcomp/power64/reload.ml 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,18 @@
1964N/A+(***********************************************************************)
1964N/A+(* *)
1964N/A+(* Objective Caml *)
1964N/A+(* *)
1964N/A+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
1964N/A+(* *)
1964N/A+(* Copyright 1996 Institut National de Recherche en Informatique et *)
1964N/A+(* en Automatique. All rights reserved. This file is distributed *)
1964N/A+(* under the terms of the Q Public License version 1.0. *)
1964N/A+(* *)
1964N/A+(***********************************************************************)
1964N/A+
1964N/A+(* $Id: reload.ml,v 1.3 1999/11/17 18:56:46 xleroy Exp $ *)
1964N/A+
1964N/A+(* Reloading for the PowerPC *)
1964N/A+
1964N/A+let fundecl f =
1964N/A+ (new Reloadgen.reload_generic)#fundecl f
1964N/Adiff -uNr ocaml-3.10.1/asmcomp/power64/scheduling.ml ocaml-3.10.1.ppc64/asmcomp/power64/scheduling.ml
1964N/A--- ocaml-3.10.1/asmcomp/power64/scheduling.ml 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmcomp/power64/scheduling.ml 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,66 @@
1964N/A+(***********************************************************************)
1964N/A+(* *)
1964N/A+(* Objective Caml *)
1964N/A+(* *)
1964N/A+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
1964N/A+(* *)
1964N/A+(* Copyright 1996 Institut National de Recherche en Informatique et *)
1964N/A+(* en Automatique. All rights reserved. This file is distributed *)
1964N/A+(* under the terms of the Q Public License version 1.0. *)
1964N/A+(* *)
1964N/A+(***********************************************************************)
1964N/A+
1964N/A+(* $Id: scheduling.ml,v 1.6 2004/06/19 16:13:33 xleroy Exp $ *)
1964N/A+
1964N/A+(* Instruction scheduling for the Power PC *)
1964N/A+
1964N/A+open Arch
1964N/A+open Mach
1964N/A+
1964N/A+class scheduler = object
1964N/A+
1964N/A+inherit Schedgen.scheduler_generic
1964N/A+
1964N/A+(* Latencies (in cycles). Based roughly on the "common model". *)
1964N/A+
1964N/A+method oper_latency = function
1964N/A+ Ireload -> 2
1964N/A+ | Iload(_, _) -> 2
1964N/A+ | Iconst_float _ -> 2 (* turned into a load *)
1964N/A+ | Iconst_symbol _ -> 1
1964N/A+ | Iintop Imul -> 9
1964N/A+ | Iintop_imm(Imul, _) -> 5
1964N/A+ | Iintop(Idiv | Imod) -> 36
1964N/A+ | Iaddf | Isubf -> 4
1964N/A+ | Imulf -> 5
1964N/A+ | Idivf -> 33
1964N/A+ | Ispecific(Imultaddf | Imultsubf) -> 5
1964N/A+ | _ -> 1
1964N/A+
1964N/A+method reload_retaddr_latency = 12
1964N/A+ (* If we can have that many cycles between the reloadretaddr and the
1964N/A+ return, we can expect that the blr branch will be completely folded. *)
1964N/A+
1964N/A+(* Issue cycles. Rough approximations. *)
1964N/A+
1964N/A+method oper_issue_cycles = function
1964N/A+ Iconst_float _ | Iconst_symbol _ -> 2
1964N/A+ | Iload(_, Ibased(_, _)) -> 2
1964N/A+ | Istore(_, Ibased(_, _)) -> 2
1964N/A+ | Ialloc _ -> 4
1964N/A+ | Iintop(Imod) -> 40 (* assuming full stall *)
1964N/A+ | Iintop(Icomp _) -> 4
1964N/A+ | Iintop_imm(Idiv, _) -> 2
1964N/A+ | Iintop_imm(Imod, _) -> 4
1964N/A+ | Iintop_imm(Icomp _, _) -> 4
1964N/A+ | Ifloatofint -> 9
1964N/A+ | Iintoffloat -> 4
1964N/A+ | _ -> 1
1964N/A+
1964N/A+method reload_retaddr_issue_cycles = 3
1964N/A+ (* load then stalling mtlr *)
1964N/A+
1964N/A+end
1964N/A+
1964N/A+let fundecl f = (new scheduler)#schedule_fundecl f
1964N/A+
1964N/Adiff -uNr ocaml-3.10.1/asmcomp/power64/selection.ml ocaml-3.10.1.ppc64/asmcomp/power64/selection.ml
1964N/A--- ocaml-3.10.1/asmcomp/power64/selection.ml 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmcomp/power64/selection.ml 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,103 @@
1964N/A+(***********************************************************************)
1964N/A+(* *)
1964N/A+(* Objective Caml *)
1964N/A+(* *)
1964N/A+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
1964N/A+(* *)
1964N/A+(* Copyright 1997 Institut National de Recherche en Informatique et *)
1964N/A+(* en Automatique. All rights reserved. This file is distributed *)
1964N/A+(* under the terms of the Q Public License version 1.0. *)
1964N/A+(* *)
1964N/A+(***********************************************************************)
1964N/A+
1964N/A+(* $Id: selection.ml,v 1.6 2004/06/19 16:13:33 xleroy Exp $ *)
1964N/A+
1964N/A+(* Instruction selection for the Power PC processor *)
1964N/A+
1964N/A+open Misc
1964N/A+open Cmm
1964N/A+open Reg
1964N/A+open Arch
1964N/A+open Mach
1964N/A+
1964N/A+(* Recognition of addressing modes *)
1964N/A+
1964N/A+type addressing_expr =
1964N/A+ Asymbol of string
1964N/A+ | Alinear of expression
1964N/A+ | Aadd of expression * expression
1964N/A+
1964N/A+let rec select_addr = function
1964N/A+ Cconst_symbol s ->
1964N/A+ (Asymbol s, 0)
1964N/A+ | Cop((Caddi | Cadda), [arg; Cconst_int m]) ->
1964N/A+ let (a, n) = select_addr arg in (a, n + m)
1964N/A+ | Cop((Caddi | Cadda), [Cconst_int m; arg]) ->
1964N/A+ let (a, n) = select_addr arg in (a, n + m)
1964N/A+ | Cop((Caddi | Cadda), [arg1; arg2]) ->
1964N/A+ begin match (select_addr arg1, select_addr arg2) with
1964N/A+ ((Alinear e1, n1), (Alinear e2, n2)) ->
1964N/A+ (Aadd(e1, e2), n1 + n2)
1964N/A+ | _ ->
1964N/A+ (Aadd(arg1, arg2), 0)
1964N/A+ end
1964N/A+ | exp ->
1964N/A+ (Alinear exp, 0)
1964N/A+
1964N/A+(* Instruction selection *)
1964N/A+
1964N/A+class selector = object (self)
1964N/A+
1964N/A+inherit Selectgen.selector_generic as super
1964N/A+
1964N/A+method is_immediate n = (n <= 32767) && (n >= -32768)
1964N/A+
1964N/A+method select_addressing exp =
1964N/A+ match select_addr exp with
1964N/A+ (Asymbol s, d) ->
1964N/A+ (Ibased(s, d), Ctuple [])
1964N/A+ | (Alinear e, d) ->
1964N/A+ (Iindexed d, e)
1964N/A+ | (Aadd(e1, e2), d) ->
1964N/A+ if d = 0
1964N/A+ then (Iindexed2, Ctuple[e1; e2])
1964N/A+ else (Iindexed d, Cop(Cadda, [e1; e2]))
1964N/A+
1964N/A+method select_operation op args =
1964N/A+ match (op, args) with
1964N/A+ (* Prevent the recognition of (x / cst) and (x % cst) when cst is not
1964N/A+ a power of 2, which do not correspond to an instruction. *)
1964N/A+ (Cdivi, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) ->
1964N/A+ (Iintop_imm(Idiv, n), [arg])
1964N/A+ | (Cdivi, _) ->
1964N/A+ (Iintop Idiv, args)
1964N/A+ | (Cmodi, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) ->
1964N/A+ (Iintop_imm(Imod, n), [arg])
1964N/A+ | (Cmodi, _) ->
1964N/A+ (Iintop Imod, args)
1964N/A+ (* The and, or and xor instructions have a different range of immediate
1964N/A+ operands than the other instructions *)
1964N/A+ | (Cand, _) -> self#select_logical Iand args
1964N/A+ | (Cor, _) -> self#select_logical Ior args
1964N/A+ | (Cxor, _) -> self#select_logical Ixor args
1964N/A+ (* Recognize mult-add and mult-sub instructions *)
1964N/A+ | (Caddf, [Cop(Cmulf, [arg1; arg2]); arg3]) ->
1964N/A+ (Ispecific Imultaddf, [arg1; arg2; arg3])
1964N/A+ | (Caddf, [arg3; Cop(Cmulf, [arg1; arg2])]) ->
1964N/A+ (Ispecific Imultaddf, [arg1; arg2; arg3])
1964N/A+ | (Csubf, [Cop(Cmulf, [arg1; arg2]); arg3]) ->
1964N/A+ (Ispecific Imultsubf, [arg1; arg2; arg3])
1964N/A+ | _ ->
1964N/A+ super#select_operation op args
1964N/A+
1964N/A+method select_logical op = function
1964N/A+ [arg; Cconst_int n] when n >= 0 && n <= 0xFFFF ->
1964N/A+ (Iintop_imm(op, n), [arg])
1964N/A+ | [Cconst_int n; arg] when n >= 0 && n <= 0xFFFF ->
1964N/A+ (Iintop_imm(op, n), [arg])
1964N/A+ | args ->
1964N/A+ (Iintop op, args)
1964N/A+
1964N/A+end
1964N/A+
1964N/A+let fundecl f = (new selector)#emit_fundecl f
1964N/Adiff -uNr ocaml-3.10.1/asmrun/Makefile ocaml-3.10.1.ppc64/asmrun/Makefile
1964N/A--- ocaml-3.10.1/asmrun/Makefile 2007-02-23 04:29:45.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmrun/Makefile 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -74,6 +74,12 @@
1964N/A power.p.o: power-$(SYSTEM).o
1964N/A cp power-$(SYSTEM).o power.p.o
1964N/A
1964N/A+power64.o: power64-$(SYSTEM).o
1964N/A+ cp power64-$(SYSTEM).o power64.o
1964N/A+
1964N/A+power64.p.o: power64-$(SYSTEM).o
1964N/A+ cp power64-$(SYSTEM).o power64.p.o
1964N/A+
1964N/A main.c: ../byterun/main.c
1964N/A ln -s ../byterun/main.c main.c
1964N/A misc.c: ../byterun/misc.c
1964N/Adiff -uNr ocaml-3.10.1/asmrun/power64-elf.S ocaml-3.10.1.ppc64/asmrun/power64-elf.S
1964N/A--- ocaml-3.10.1/asmrun/power64-elf.S 1969-12-31 19:00:00.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmrun/power64-elf.S 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -0,0 +1,486 @@
1964N/A+/*********************************************************************/
1964N/A+/* */
1964N/A+/* Objective Caml */
1964N/A+/* */
1964N/A+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
1964N/A+/* */
1964N/A+/* Copyright 1996 Institut National de Recherche en Informatique et */
1964N/A+/* en Automatique. All rights reserved. This file is distributed */
1964N/A+/* under the terms of the GNU Library General Public License, with */
1964N/A+/* the special exception on linking described in file ../LICENSE. */
1964N/A+/* */
1964N/A+/*********************************************************************/
1964N/A+
1964N/A+/* $Id: power-elf.S,v 1.18 2004/01/03 12:51:19 doligez Exp $ */
1964N/A+
1964N/A+#define Addrglobal(reg,glob) \
1964N/A+ addis reg, 0, glob@ha; \
1964N/A+ addi reg, reg, glob@l
1964N/A+#define Loadglobal(reg,glob,tmp) \
1964N/A+ addis tmp, 0, glob@ha; \
1964N/A+ ld reg, glob@l(tmp)
1964N/A+#define Storeglobal(reg,glob,tmp) \
1964N/A+ addis tmp, 0, glob@ha; \
1964N/A+ std reg, glob@l(tmp)
1964N/A+
1964N/A+ .section ".text"
1964N/A+
1964N/A+/* Invoke the garbage collector. */
1964N/A+
1964N/A+ .globl caml_call_gc
1964N/A+ .type caml_call_gc, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_call_gc:
1964N/A+ .quad .L.caml_call_gc,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_call_gc:
1964N/A+ /* Set up stack frame */
1964N/A+ mflr 0
1964N/A+ std 0, 16(1)
1964N/A+ /* Record return address into Caml code */
1964N/A+ Storeglobal(0, caml_last_return_address, 11)
1964N/A+ /* Record lowest stack address */
1964N/A+ Storeglobal(1, caml_bottom_of_stack, 11)
1964N/A+ /* 0x220 = 8*32 (int regs) + 8*32 (float regs) + 48 (stack frame) */
1964N/A+ stdu 1, -0x230(1)
1964N/A+ /* Record pointer to register array */
1964N/A+ addi 0, 1, 8*32 + 48
1964N/A+ Storeglobal(0, caml_gc_regs, 11)
1964N/A+ /* Save current allocation pointer for debugging purposes */
1964N/A+ Storeglobal(31, caml_young_ptr, 11)
1964N/A+ /* Save exception pointer (if e.g. a sighandler raises) */
1964N/A+ Storeglobal(29, caml_exception_pointer, 11)
1964N/A+ /* Save all registers used by the code generator */
1964N/A+ addi 11, 1, 8*32 + 48 - 8
1964N/A+ stdu 3, 8(11)
1964N/A+ stdu 4, 8(11)
1964N/A+ stdu 5, 8(11)
1964N/A+ stdu 6, 8(11)
1964N/A+ stdu 7, 8(11)
1964N/A+ stdu 8, 8(11)
1964N/A+ stdu 9, 8(11)
1964N/A+ stdu 10, 8(11)
1964N/A+ stdu 14, 8(11)
1964N/A+ stdu 15, 8(11)
1964N/A+ stdu 16, 8(11)
1964N/A+ stdu 17, 8(11)
1964N/A+ stdu 18, 8(11)
1964N/A+ stdu 19, 8(11)
1964N/A+ stdu 20, 8(11)
1964N/A+ stdu 21, 8(11)
1964N/A+ stdu 22, 8(11)
1964N/A+ stdu 23, 8(11)
1964N/A+ stdu 24, 8(11)
1964N/A+ stdu 25, 8(11)
1964N/A+ stdu 26, 8(11)
1964N/A+ stdu 27, 8(11)
1964N/A+ stdu 28, 8(11)
1964N/A+ addi 11, 1, 48 - 8
1964N/A+ stfdu 1, 8(11)
1964N/A+ stfdu 2, 8(11)
1964N/A+ stfdu 3, 8(11)
1964N/A+ stfdu 4, 8(11)
1964N/A+ stfdu 5, 8(11)
1964N/A+ stfdu 6, 8(11)
1964N/A+ stfdu 7, 8(11)
1964N/A+ stfdu 8, 8(11)
1964N/A+ stfdu 9, 8(11)
1964N/A+ stfdu 10, 8(11)
1964N/A+ stfdu 11, 8(11)
1964N/A+ stfdu 12, 8(11)
1964N/A+ stfdu 13, 8(11)
1964N/A+ stfdu 14, 8(11)
1964N/A+ stfdu 15, 8(11)
1964N/A+ stfdu 16, 8(11)
1964N/A+ stfdu 17, 8(11)
1964N/A+ stfdu 18, 8(11)
1964N/A+ stfdu 19, 8(11)
1964N/A+ stfdu 20, 8(11)
1964N/A+ stfdu 21, 8(11)
1964N/A+ stfdu 22, 8(11)
1964N/A+ stfdu 23, 8(11)
1964N/A+ stfdu 24, 8(11)
1964N/A+ stfdu 25, 8(11)
1964N/A+ stfdu 26, 8(11)
1964N/A+ stfdu 27, 8(11)
1964N/A+ stfdu 28, 8(11)
1964N/A+ stfdu 29, 8(11)
1964N/A+ stfdu 30, 8(11)
1964N/A+ stfdu 31, 8(11)
1964N/A+ /* Call the GC */
1964N/A+ std 2,40(1)
1964N/A+ Addrglobal(11, caml_garbage_collection)
1964N/A+ ld 2,8(11)
1964N/A+ ld 11,0(11)
1964N/A+ mtlr 11
1964N/A+ blrl
1964N/A+ ld 2,40(1)
1964N/A+ /* Reload new allocation pointer and allocation limit */
1964N/A+ Loadglobal(31, caml_young_ptr, 11)
1964N/A+ Loadglobal(30, caml_young_limit, 11)
1964N/A+ /* Restore all regs used by the code generator */
1964N/A+ addi 11, 1, 8*32 + 48 - 8
1964N/A+ ldu 3, 8(11)
1964N/A+ ldu 4, 8(11)
1964N/A+ ldu 5, 8(11)
1964N/A+ ldu 6, 8(11)
1964N/A+ ldu 7, 8(11)
1964N/A+ ldu 8, 8(11)
1964N/A+ ldu 9, 8(11)
1964N/A+ ldu 10, 8(11)
1964N/A+ ldu 14, 8(11)
1964N/A+ ldu 15, 8(11)
1964N/A+ ldu 16, 8(11)
1964N/A+ ldu 17, 8(11)
1964N/A+ ldu 18, 8(11)
1964N/A+ ldu 19, 8(11)
1964N/A+ ldu 20, 8(11)
1964N/A+ ldu 21, 8(11)
1964N/A+ ldu 22, 8(11)
1964N/A+ ldu 23, 8(11)
1964N/A+ ldu 24, 8(11)
1964N/A+ ldu 25, 8(11)
1964N/A+ ldu 26, 8(11)
1964N/A+ ldu 27, 8(11)
1964N/A+ ldu 28, 8(11)
1964N/A+ addi 11, 1, 48 - 8
1964N/A+ lfdu 1, 8(11)
1964N/A+ lfdu 2, 8(11)
1964N/A+ lfdu 3, 8(11)
1964N/A+ lfdu 4, 8(11)
1964N/A+ lfdu 5, 8(11)
1964N/A+ lfdu 6, 8(11)
1964N/A+ lfdu 7, 8(11)
1964N/A+ lfdu 8, 8(11)
1964N/A+ lfdu 9, 8(11)
1964N/A+ lfdu 10, 8(11)
1964N/A+ lfdu 11, 8(11)
1964N/A+ lfdu 12, 8(11)
1964N/A+ lfdu 13, 8(11)
1964N/A+ lfdu 14, 8(11)
1964N/A+ lfdu 15, 8(11)
1964N/A+ lfdu 16, 8(11)
1964N/A+ lfdu 17, 8(11)
1964N/A+ lfdu 18, 8(11)
1964N/A+ lfdu 19, 8(11)
1964N/A+ lfdu 20, 8(11)
1964N/A+ lfdu 21, 8(11)
1964N/A+ lfdu 22, 8(11)
1964N/A+ lfdu 23, 8(11)
1964N/A+ lfdu 24, 8(11)
1964N/A+ lfdu 25, 8(11)
1964N/A+ lfdu 26, 8(11)
1964N/A+ lfdu 27, 8(11)
1964N/A+ lfdu 28, 8(11)
1964N/A+ lfdu 29, 8(11)
1964N/A+ lfdu 30, 8(11)
1964N/A+ lfdu 31, 8(11)
1964N/A+ /* Return to caller, restarting the allocation */
1964N/A+ Loadglobal(0, caml_last_return_address, 11)
1964N/A+ addic 0, 0, -16 /* Restart the allocation (4 instructions) */
1964N/A+ mtlr 0
1964N/A+ /* Say we are back into Caml code */
1964N/A+ li 12, 0
1964N/A+ Storeglobal(12, caml_last_return_address, 11)
1964N/A+ /* Deallocate stack frame */
1964N/A+ ld 1, 0(1)
1964N/A+ /* Return */
1964N/A+ blr
1964N/A+ .size .L.caml_call_gc,.-.L.caml_call_gc
1964N/A+
1964N/A+/* Call a C function from Caml */
1964N/A+
1964N/A+ .globl caml_c_call
1964N/A+ .type caml_c_call, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_c_call:
1964N/A+ .quad .L.caml_c_call,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_c_call:
1964N/A+ .cfi_startproc
1964N/A+ /* Save return address */
1964N/A+ mflr 25
1964N/A+ .cfi_register lr,25
1964N/A+ /* Get ready to call C function (address in 11) */
1964N/A+ ld 2, 8(11)
1964N/A+ ld 11,0(11)
1964N/A+ mtlr 11
1964N/A+ /* Record lowest stack address and return address */
1964N/A+ Storeglobal(1, caml_bottom_of_stack, 12)
1964N/A+ Storeglobal(25, caml_last_return_address, 12)
1964N/A+ /* Make the exception handler and alloc ptr available to the C code */
1964N/A+ Storeglobal(31, caml_young_ptr, 11)
1964N/A+ Storeglobal(29, caml_exception_pointer, 11)
1964N/A+ /* Call the function (address in link register) */
1964N/A+ blrl
1964N/A+ /* Restore return address (in 25, preserved by the C function) */
1964N/A+ mtlr 25
1964N/A+ /* Reload allocation pointer and allocation limit*/
1964N/A+ Loadglobal(31, caml_young_ptr, 11)
1964N/A+ Loadglobal(30, caml_young_limit, 11)
1964N/A+ /* Say we are back into Caml code */
1964N/A+ li 12, 0
1964N/A+ Storeglobal(12, caml_last_return_address, 11)
1964N/A+ /* Return to caller */
1964N/A+ blr
1964N/A+ .cfi_endproc
1964N/A+ .size .L.caml_c_call,.-.L.caml_c_call
1964N/A+
1964N/A+/* Raise an exception from C */
1964N/A+
1964N/A+ .globl caml_raise_exception
1964N/A+ .type caml_raise_exception, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_raise_exception:
1964N/A+ .quad .L.caml_raise_exception,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_raise_exception:
1964N/A+ /* Reload Caml global registers */
1964N/A+ Loadglobal(29, caml_exception_pointer, 11)
1964N/A+ Loadglobal(31, caml_young_ptr, 11)
1964N/A+ Loadglobal(30, caml_young_limit, 11)
1964N/A+ /* Say we are back into Caml code */
1964N/A+ li 0, 0
1964N/A+ Storeglobal(0, caml_last_return_address, 11)
1964N/A+ /* Pop trap frame */
1964N/A+ ld 0, 8(29)
1964N/A+ ld 1, 16(29)
1964N/A+ mtlr 0
1964N/A+ ld 2, 24(29)
1964N/A+ ld 29, 0(29)
1964N/A+ /* Branch to handler */
1964N/A+ blr
1964N/A+ .size .L.caml_raise_exception,.-.L.caml_raise_exception
1964N/A+
1964N/A+/* Start the Caml program */
1964N/A+
1964N/A+ .globl caml_start_program
1964N/A+ .type caml_start_program, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_start_program:
1964N/A+ .quad .L.caml_start_program,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_start_program:
1964N/A+ Addrglobal(12, caml_program)
1964N/A+
1964N/A+/* Code shared between caml_start_program and caml_callback */
1964N/A+.L102:
1964N/A+ /* Allocate and link stack frame */
1964N/A+ mflr 0
1964N/A+ std 0, 16(1)
1964N/A+ stdu 1, -0x190(1) /* 48 + 8*36(regs) + 32(callback) + 32(exc) */
1964N/A+ /* Save return address */
1964N/A+ /* Save all callee-save registers */
1964N/A+ /* GPR 14 ... GPR 31 then FPR 14 ... FPR 31 starting at sp+16 */
1964N/A+ addi 11, 1, 48-8
1964N/A+ stdu 14, 8(11)
1964N/A+ stdu 15, 8(11)
1964N/A+ stdu 16, 8(11)
1964N/A+ stdu 17, 8(11)
1964N/A+ stdu 18, 8(11)
1964N/A+ stdu 19, 8(11)
1964N/A+ stdu 20, 8(11)
1964N/A+ stdu 21, 8(11)
1964N/A+ stdu 22, 8(11)
1964N/A+ stdu 23, 8(11)
1964N/A+ stdu 24, 8(11)
1964N/A+ stdu 25, 8(11)
1964N/A+ stdu 26, 8(11)
1964N/A+ stdu 27, 8(11)
1964N/A+ stdu 28, 8(11)
1964N/A+ stdu 29, 8(11)
1964N/A+ stdu 30, 8(11)
1964N/A+ stdu 31, 8(11)
1964N/A+ stfdu 14, 8(11)
1964N/A+ stfdu 15, 8(11)
1964N/A+ stfdu 16, 8(11)
1964N/A+ stfdu 17, 8(11)
1964N/A+ stfdu 18, 8(11)
1964N/A+ stfdu 19, 8(11)
1964N/A+ stfdu 20, 8(11)
1964N/A+ stfdu 21, 8(11)
1964N/A+ stfdu 22, 8(11)
1964N/A+ stfdu 23, 8(11)
1964N/A+ stfdu 24, 8(11)
1964N/A+ stfdu 25, 8(11)
1964N/A+ stfdu 26, 8(11)
1964N/A+ stfdu 27, 8(11)
1964N/A+ stfdu 28, 8(11)
1964N/A+ stfdu 29, 8(11)
1964N/A+ stfdu 30, 8(11)
1964N/A+ stfdu 31, 8(11)
1964N/A+ /* Set up a callback link */
1964N/A+ Loadglobal(9, caml_bottom_of_stack, 11)
1964N/A+ Loadglobal(10, caml_last_return_address, 11)
1964N/A+ Loadglobal(11, caml_gc_regs, 11)
1964N/A+ std 9, 0x150(1)
1964N/A+ std 10, 0x158(1)
1964N/A+ std 11, 0x160(1)
1964N/A+ /* Build an exception handler to catch exceptions escaping out of Caml */
1964N/A+ bl .L103
1964N/A+ b .L104
1964N/A+.L103:
1964N/A+ mflr 0
1964N/A+ addi 29, 1, 0x170 /* Alignment */
1964N/A+ std 0, 8(29)
1964N/A+ std 1, 16(29)
1964N/A+ std 2, 24(29)
1964N/A+ Loadglobal(11, caml_exception_pointer, 11)
1964N/A+ std 11, 0(29)
1964N/A+ /* Reload allocation pointers */
1964N/A+ Loadglobal(31, caml_young_ptr, 11)
1964N/A+ Loadglobal(30, caml_young_limit, 11)
1964N/A+ /* Say we are back into Caml code */
1964N/A+ li 0, 0
1964N/A+ Storeglobal(0, caml_last_return_address, 11)
1964N/A+ /* Call the Caml code */
1964N/A+ std 2,40(1)
1964N/A+ ld 2,8(12)
1964N/A+ ld 12,0(12)
1964N/A+ mtlr 12
1964N/A+.L105:
1964N/A+ blrl
1964N/A+ ld 2,40(1)
1964N/A+ /* Pop the trap frame, restoring caml_exception_pointer */
1964N/A+ ld 9, 0x170(1)
1964N/A+ Storeglobal(9, caml_exception_pointer, 11)
1964N/A+ /* Pop the callback link, restoring the global variables */
1964N/A+.L106:
1964N/A+ ld 9, 0x150(1)
1964N/A+ ld 10, 0x158(1)
1964N/A+ ld 11, 0x160(1)
1964N/A+ Storeglobal(9, caml_bottom_of_stack, 12)
1964N/A+ Storeglobal(10, caml_last_return_address, 12)
1964N/A+ Storeglobal(11, caml_gc_regs, 12)
1964N/A+ /* Update allocation pointer */
1964N/A+ Storeglobal(31, caml_young_ptr, 11)
1964N/A+ /* Restore callee-save registers */
1964N/A+ addi 11, 1, 48-8
1964N/A+ ldu 14, 8(11)
1964N/A+ ldu 15, 8(11)
1964N/A+ ldu 16, 8(11)
1964N/A+ ldu 17, 8(11)
1964N/A+ ldu 18, 8(11)
1964N/A+ ldu 19, 8(11)
1964N/A+ ldu 20, 8(11)
1964N/A+ ldu 21, 8(11)
1964N/A+ ldu 22, 8(11)
1964N/A+ ldu 23, 8(11)
1964N/A+ ldu 24, 8(11)
1964N/A+ ldu 25, 8(11)
1964N/A+ ldu 26, 8(11)
1964N/A+ ldu 27, 8(11)
1964N/A+ ldu 28, 8(11)
1964N/A+ ldu 29, 8(11)
1964N/A+ ldu 30, 8(11)
1964N/A+ ldu 31, 8(11)
1964N/A+ lfdu 14, 8(11)
1964N/A+ lfdu 15, 8(11)
1964N/A+ lfdu 16, 8(11)
1964N/A+ lfdu 17, 8(11)
1964N/A+ lfdu 18, 8(11)
1964N/A+ lfdu 19, 8(11)
1964N/A+ lfdu 20, 8(11)
1964N/A+ lfdu 21, 8(11)
1964N/A+ lfdu 22, 8(11)
1964N/A+ lfdu 23, 8(11)
1964N/A+ lfdu 24, 8(11)
1964N/A+ lfdu 25, 8(11)
1964N/A+ lfdu 26, 8(11)
1964N/A+ lfdu 27, 8(11)
1964N/A+ lfdu 28, 8(11)
1964N/A+ lfdu 29, 8(11)
1964N/A+ lfdu 30, 8(11)
1964N/A+ lfdu 31, 8(11)
1964N/A+ /* Return */
1964N/A+ ld 1,0(1)
1964N/A+ /* Reload return address */
1964N/A+ ld 0, 16(1)
1964N/A+ mtlr 0
1964N/A+ blr
1964N/A+
1964N/A+ /* The trap handler: */
1964N/A+.L104:
1964N/A+ /* Update caml_exception_pointer */
1964N/A+ Storeglobal(29, caml_exception_pointer, 11)
1964N/A+ /* Encode exception bucket as an exception result and return it */
1964N/A+ ori 3, 3, 2
1964N/A+ b .L106
1964N/A+ .size .L.caml_start_program,.-.L.caml_start_program
1964N/A+
1964N/A+/* Callback from C to Caml */
1964N/A+
1964N/A+ .globl caml_callback_exn
1964N/A+ .type caml_callback_exn, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_callback_exn:
1964N/A+ .quad .L.caml_callback_exn,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_callback_exn:
1964N/A+ /* Initial shuffling of arguments */
1964N/A+ mr 0, 3 /* Closure */
1964N/A+ mr 3, 4 /* Argument */
1964N/A+ mr 4, 0
1964N/A+ ld 12, 0(4) /* Code pointer */
1964N/A+ b .L102
1964N/A+ .size .L.caml_callback_exn,.-.L.caml_callback_exn
1964N/A+
1964N/A+
1964N/A+ .globl caml_callback2_exn
1964N/A+ .type caml_callback2_exn, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_callback2_exn:
1964N/A+ .quad .L.caml_callback2_exn,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_callback2_exn:
1964N/A+ mr 0, 3 /* Closure */
1964N/A+ mr 3, 4 /* First argument */
1964N/A+ mr 4, 5 /* Second argument */
1964N/A+ mr 5, 0
1964N/A+ Addrglobal(12, caml_apply2)
1964N/A+ b .L102
1964N/A+ .size .L.caml_callback2_exn,.-.L.caml_callback2_exn
1964N/A+
1964N/A+
1964N/A+ .globl caml_callback3_exn
1964N/A+ .type caml_callback3_exn, @function
1964N/A+ .section ".opd","aw"
1964N/A+ .align 3
1964N/A+caml_callback3_exn:
1964N/A+ .quad .L.caml_callback3_exn,.TOC.@tocbase
1964N/A+ .previous
1964N/A+ .align 2
1964N/A+.L.caml_callback3_exn:
1964N/A+ mr 0, 3 /* Closure */
1964N/A+ mr 3, 4 /* First argument */
1964N/A+ mr 4, 5 /* Second argument */
1964N/A+ mr 5, 6 /* Third argument */
1964N/A+ mr 6, 0
1964N/A+ Addrglobal(12, caml_apply3)
1964N/A+ b .L102
1964N/A+ .size .L.caml_callback3_exn,.-.L.caml_callback3_exn
1964N/A+
1964N/A+/* Frame table */
1964N/A+
1964N/A+ .section ".data"
1964N/A+ .globl caml_system__frametable
1964N/A+ .type caml_system__frametable, @object
1964N/A+caml_system__frametable:
1964N/A+ .quad 1 /* one descriptor */
1964N/A+ .quad .L105 + 4 /* return address into callback */
1964N/A+ .short -1 /* negative size count => use callback link */
1964N/A+ .short 0 /* no roots here */
1964N/A+ .align 3
1964N/A+
1964N/Adiff -uNr ocaml-3.10.1/asmrun/stack.h ocaml-3.10.1.ppc64/asmrun/stack.h
1964N/A--- ocaml-3.10.1/asmrun/stack.h 2007-02-15 13:35:20.000000000 -0500
1964N/A+++ ocaml-3.10.1.ppc64/asmrun/stack.h 2008-02-29 08:37:45.000000000 -0500
1964N/A@@ -65,6 +65,15 @@
1964N/A #define Callback_link(sp) ((struct caml_context *)((sp) + Trap_frame_size))
1964N/A #endif
1964N/A
1964N/A+#ifdef TARGET_power64
1964N/A+#define Saved_return_address(sp) *((intnat *)((sp) +16))
1964N/A+#define Already_scanned(sp, retaddr) ((retaddr) & 1)
1964N/A+#define Mark_scanned(sp, retaddr) (Saved_return_address(sp) = (retaddr) | 1)
1964N/A+#define Mask_already_scanned(retaddr) ((retaddr) & ~1)
1964N/A+#define Trap_frame_size 0x150
1964N/A+#define Callback_link(sp) ((struct caml_context *)((sp) + Trap_frame_size))
1964N/A+#endif
1964N/A+
1964N/A #ifdef TARGET_m68k
1964N/A #define Saved_return_address(sp) *((intnat *)((sp) - 4))
1964N/A #define Callback_link(sp) ((struct caml_context *)((sp) + 8))
1964N/Adiff -uNr ocaml-3.11.0+beta1/configure ocaml-3.11.0+beta1.ppc64/configure
1964N/A--- ocaml-3.11.0+beta1/configure.ppc64 2008-11-18 15:46:57.000000000 +0000
1964N/A+++ ocaml-3.11.0+beta1/configure 2008-11-18 15:49:19.000000000 +0000
1964N/A@@ -632,6 +632,7 @@
1964N/A hppa2.0*-*-hpux*) arch=hppa; system=hpux;;
1964N/A hppa*-*-linux*) arch=hppa; system=linux;;
1964N/A hppa*-*-gnu*) arch=hppa; system=gnu;;
1964N/A+ powerpc64-*-linux*) arch=power64; model=ppc64; system=elf;;
1964N/A powerpc*-*-linux*) arch=power; model=ppc; system=elf;;
1964N/A powerpc-*-netbsd*) arch=power; model=ppc; system=elf;;
1964N/A powerpc-*-rhapsody*) arch=power; model=ppc; system=rhapsody;;
1964N/A@@ -655,7 +656,7 @@
1964N/A
1964N/A if $arch64; then
1964N/A case "$arch,$model" in
1964N/A- sparc,default|mips,default|hppa,default|power,ppc)
1964N/A+ sparc,default|mips,default|hppa,default)
1964N/A arch=none; model=default; system=unknown;;
1964N/A esac
1964N/A fi
1964N/A@@ -712,6 +713,8 @@
1964N/A aspp='as -n32 -O2';;
1964N/A power,*,elf) as='as -u -m ppc'
1964N/A aspp='gcc -c';;
1964N/A+ power64,*,elf) as='as -u -m ppc64'
1964N/A+ aspp='gcc -c';;
1964N/A power,*,bsd) as='as'
1964N/A aspp='gcc -c';;
1964N/A power,*,rhapsody) as="as -arch $model"