src/cpu/ppc/vm/macroAssembler_ppc.cpp

changeset 6511
31e80afe3fed
parent 6501
c668f307a4c0
child 6512
fd1b9f02cc91
     1.1 --- a/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Thu Feb 20 11:05:12 2014 +0100
     1.2 +++ b/src/cpu/ppc/vm/macroAssembler_ppc.cpp	Thu Mar 06 10:55:28 2014 -0800
     1.3 @@ -594,7 +594,13 @@
     1.4             "can't identify emitted call");
     1.5    } else {
     1.6      // variant 1:
     1.7 -
     1.8 +#if defined(ABI_ELFv2)
     1.9 +    nop();
    1.10 +    calculate_address_from_global_toc(R12, dest, true, true, false);
    1.11 +    mtctr(R12);
    1.12 +    nop();
    1.13 +    nop();
    1.14 +#else
    1.15      mr(R0, R11);  // spill R11 -> R0.
    1.16  
    1.17      // Load the destination address into CTR,
    1.18 @@ -604,6 +610,7 @@
    1.19      mtctr(R11);
    1.20      mr(R11, R0);  // spill R11 <- R0.
    1.21      nop();
    1.22 +#endif
    1.23  
    1.24      // do the call/jump
    1.25      if (link) {
    1.26 @@ -912,16 +919,16 @@
    1.27    }
    1.28  }
    1.29  
    1.30 -// Push a frame of size `bytes' plus abi112 on top.
    1.31 -void MacroAssembler::push_frame_abi112(unsigned int bytes, Register tmp) {
    1.32 -  push_frame(bytes + frame::abi_112_size, tmp);
    1.33 +// Push a frame of size `bytes' plus abi_reg_args on top.
    1.34 +void MacroAssembler::push_frame_reg_args(unsigned int bytes, Register tmp) {
    1.35 +  push_frame(bytes + frame::abi_reg_args_size, tmp);
    1.36  }
    1.37  
    1.38  // Setup up a new C frame with a spill area for non-volatile GPRs and
    1.39  // additional space for local variables.
    1.40 -void MacroAssembler::push_frame_abi112_nonvolatiles(unsigned int bytes,
    1.41 -                                                    Register tmp) {
    1.42 -  push_frame(bytes + frame::abi_112_size + frame::spill_nonvolatiles_size, tmp);
    1.43 +void MacroAssembler::push_frame_reg_args_nonvolatiles(unsigned int bytes,
    1.44 +                                                      Register tmp) {
    1.45 +  push_frame(bytes + frame::abi_reg_args_size + frame::spill_nonvolatiles_size, tmp);
    1.46  }
    1.47  
    1.48  // Pop current C frame.
    1.49 @@ -929,6 +936,42 @@
    1.50    ld(R1_SP, _abi(callers_sp), R1_SP);
    1.51  }
    1.52  
    1.53 +#if defined(ABI_ELFv2)
    1.54 +address MacroAssembler::branch_to(Register r_function_entry, bool and_link) {
    1.55 +  // TODO(asmundak): make sure the caller uses R12 as function descriptor
    1.56 +  // most of the times.
    1.57 +  if (R12 != r_function_entry) {
    1.58 +    mr(R12, r_function_entry);
    1.59 +  }
    1.60 +  mtctr(R12);
    1.61 +  // Do a call or a branch.
    1.62 +  if (and_link) {
    1.63 +    bctrl();
    1.64 +  } else {
    1.65 +    bctr();
    1.66 +  }
    1.67 +  _last_calls_return_pc = pc();
    1.68 +
    1.69 +  return _last_calls_return_pc;
    1.70 +}
    1.71 +
    1.72 +// Call a C function via a function descriptor and use full C
    1.73 +// calling conventions. Updates and returns _last_calls_return_pc.
    1.74 +address MacroAssembler::call_c(Register r_function_entry) {
    1.75 +  return branch_to(r_function_entry, /*and_link=*/true);
    1.76 +}
    1.77 +
    1.78 +// For tail calls: only branch, don't link, so callee returns to caller of this function.
    1.79 +address MacroAssembler::call_c_and_return_to_caller(Register r_function_entry) {
    1.80 +  return branch_to(r_function_entry, /*and_link=*/false);
    1.81 +}
    1.82 +
    1.83 +address MacroAssembler::call_c(address function_entry, relocInfo::relocType rt) {
    1.84 +  load_const(R12, function_entry, R0);
    1.85 +  return branch_to(R12,  /*and_link=*/true);
    1.86 +}
    1.87 +
    1.88 +#else
    1.89  // Generic version of a call to C function via a function descriptor
    1.90  // with variable support for C calling conventions (TOC, ENV, etc.).
    1.91  // Updates and returns _last_calls_return_pc.
    1.92 @@ -1077,6 +1120,7 @@
    1.93    }
    1.94    return _last_calls_return_pc;
    1.95  }
    1.96 +#endif
    1.97  
    1.98  void MacroAssembler::call_VM_base(Register oop_result,
    1.99                                    Register last_java_sp,
   1.100 @@ -1091,8 +1135,11 @@
   1.101  
   1.102    // ARG1 must hold thread address.
   1.103    mr(R3_ARG1, R16_thread);
   1.104 -
   1.105 +#if defined(ABI_ELFv2)
   1.106 +  address return_pc = call_c(entry_point, relocInfo::none);
   1.107 +#else
   1.108    address return_pc = call_c((FunctionDescriptor*)entry_point, relocInfo::none);
   1.109 +#endif
   1.110  
   1.111    reset_last_Java_frame();
   1.112  
   1.113 @@ -1113,7 +1160,11 @@
   1.114  
   1.115  void MacroAssembler::call_VM_leaf_base(address entry_point) {
   1.116    BLOCK_COMMENT("call_VM_leaf {");
   1.117 +#if defined(ABI_ELFv2)
   1.118 +  call_c(entry_point, relocInfo::none);
   1.119 +#else
   1.120    call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, entry_point), relocInfo::none);
   1.121 +#endif
   1.122    BLOCK_COMMENT("} call_VM_leaf");
   1.123  }
   1.124  
   1.125 @@ -2227,7 +2278,7 @@
   1.126    // VM call need frame to access(write) O register.
   1.127    if (needs_frame) {
   1.128      save_LR_CR(Rtmp1);
   1.129 -    push_frame_abi112(0, Rtmp2);
   1.130 +    push_frame_reg_args(0, Rtmp2);
   1.131    }
   1.132  
   1.133    if (Rpre_val->is_volatile() && Robj == noreg) mr(R31, Rpre_val); // Save pre_val across C call if it was preloaded.
   1.134 @@ -3006,13 +3057,13 @@
   1.135    mr(R0, tmp);
   1.136    // kill tmp
   1.137    save_LR_CR(tmp);
   1.138 -  push_frame_abi112(nbytes_save, tmp);
   1.139 +  push_frame_reg_args(nbytes_save, tmp);
   1.140    // restore tmp
   1.141    mr(tmp, R0);
   1.142    save_volatile_gprs(R1_SP, 112); // except R0
   1.143 -  // load FunctionDescriptor**
   1.144 +  // load FunctionDescriptor** / entry_address *
   1.145    load_const(tmp, fd);
   1.146 -  // load FunctionDescriptor*
   1.147 +  // load FunctionDescriptor* / entry_address
   1.148    ld(tmp, 0, tmp);
   1.149    mr(R4_ARG2, oop);
   1.150    load_const(R3_ARG1, (address)msg);

mercurial