2005 2006 // Get current PC + offset. 2007 // Offset given in bytes, must be even! 2008 // "Current PC" here means the address of the larl instruction plus the given offset. 2009 address MacroAssembler::get_PC(Register result, int64_t offset) { 2010 address here = pc(); 2011 z_larl(result, offset/2); // Save target instruction address in result. 2012 return here + offset; 2013 } 2014 2015 // Resize_frame with SP(new) = SP(old) - [offset]. 2016 void MacroAssembler::resize_frame_sub(Register offset, Register fp, bool load_fp) 2017 { 2018 assert_different_registers(offset, fp, Z_SP); 2019 if (load_fp) { z_lg(fp, _z_abi(callers_sp), Z_SP); } 2020 2021 z_sgr(Z_SP, offset); 2022 z_stg(fp, _z_abi(callers_sp), Z_SP); 2023 } 2024 2025 // Resize_frame with SP(new) = [addr]. 2026 void MacroAssembler::resize_frame_absolute(Register addr, Register fp, bool load_fp) { 2027 assert_different_registers(addr, fp, Z_SP); 2028 if (load_fp) { z_lg(fp, _z_abi(callers_sp), Z_SP); } 2029 2030 if (addr != Z_R0) { 2031 // Minimize stalls by not using Z_SP immediately after update. 2032 z_stg(fp, _z_abi(callers_sp), addr); 2033 z_lgr(Z_SP, addr); 2034 } else { 2035 z_lgr(Z_SP, addr); 2036 z_stg(fp, _z_abi(callers_sp), Z_SP); 2037 } 2038 } 2039 2040 // Resize_frame with SP(new) = SP(old) + offset. 2041 void MacroAssembler::resize_frame(RegisterOrConstant offset, Register fp, bool load_fp) { 2042 assert_different_registers(fp, Z_SP); 2043 if (load_fp) z_lg(fp, _z_abi(callers_sp), Z_SP); 2044 2045 if (Displacement::is_validDisp((int)_z_abi(callers_sp) + offset.constant_or_zero())) { 2046 // Minimize stalls by first using, then updating Z_SP. 2047 // Do that only if we have a small positive offset or if ExtImm are available. 2048 z_stg(fp, Address(Z_SP, offset, _z_abi(callers_sp))); 2049 add64(Z_SP, offset); 2050 } else { 2051 add64(Z_SP, offset); 2052 z_stg(fp, _z_abi(callers_sp), Z_SP); 2053 } 2054 } 2055 2056 void MacroAssembler::push_frame(Register bytes, Register old_sp, bool copy_sp, bool bytes_with_inverted_sign) { 2057 #ifdef ASSERT 2058 assert_different_registers(bytes, old_sp, Z_SP); 2059 if (!copy_sp) { 2060 z_cgr(old_sp, Z_SP); 2061 asm_assert_eq("[old_sp]!=[Z_SP]", 0x211); 2062 } 2063 #endif 2064 if (copy_sp) { z_lgr(old_sp, Z_SP); } 2065 if (bytes_with_inverted_sign) { 2066 z_stg(old_sp, 0, bytes, Z_SP); 2067 add2reg_with_index(Z_SP, 0, bytes, Z_SP); 2068 } else { 2069 z_sgr(Z_SP, bytes); // Z_sgfr sufficient, but probably not faster. 2070 z_stg(old_sp, 0, Z_SP); 2071 } 2072 } 2073 2074 unsigned int MacroAssembler::push_frame(unsigned int bytes, Register scratch) { 2075 long offset = Assembler::align(bytes, frame::alignment_in_bytes); 2076 2077 if (Displacement::is_validDisp(-offset)) { 2078 // Minimize stalls by first using, then updating Z_SP. 2079 // Do that only if we have ExtImm available. 2080 z_stg(Z_SP, -offset, Z_SP); 2081 add2reg(Z_SP, -offset); 2082 } else { 2083 if (scratch != Z_R0 && scratch != Z_R1) { 2084 z_stg(Z_SP, -offset, Z_SP); 2085 add2reg(Z_SP, -offset); 2086 } else { // scratch == Z_R0 || scratch == Z_R1 2087 z_lgr(scratch, Z_SP); 2088 add2reg(Z_SP, -offset); 2089 z_stg(scratch, 0, Z_SP); 2090 } 2091 } 2092 return offset; 2093 } 2094 2095 // Push a frame of size `bytes' plus abi160 on top. 2096 unsigned int MacroAssembler::push_frame_abi160(unsigned int bytes) { 2097 BLOCK_COMMENT("push_frame_abi160 {"); 2098 unsigned int res = push_frame(bytes + frame::z_abi_160_size); 2099 BLOCK_COMMENT("} push_frame_abi160"); 2100 return res; 2101 } 2102 2103 // Pop current C frame. 2104 void MacroAssembler::pop_frame() { 2105 BLOCK_COMMENT("pop_frame:"); 2106 Assembler::z_lg(Z_SP, _z_abi(callers_sp), Z_SP); 2107 } 2108 2109 void MacroAssembler::call_VM_leaf_base(address entry_point, bool allow_relocation) { 2110 if (allow_relocation) { 2111 call_c(entry_point); 2112 } else { 2113 call_c_static(entry_point); 2114 } 2115 } 2116 2117 void MacroAssembler::call_VM_leaf_base(address entry_point) { 2118 bool allow_relocation = true; 2119 call_VM_leaf_base(entry_point, allow_relocation); 2120 } 2121 2122 void MacroAssembler::call_VM_base(Register oop_result, 2123 Register last_java_sp, 2124 address entry_point, 2125 bool allow_relocation, 2126 bool check_exceptions) { // Defaults to true. | 2005 2006 // Get current PC + offset. 2007 // Offset given in bytes, must be even! 2008 // "Current PC" here means the address of the larl instruction plus the given offset. 2009 address MacroAssembler::get_PC(Register result, int64_t offset) { 2010 address here = pc(); 2011 z_larl(result, offset/2); // Save target instruction address in result. 2012 return here + offset; 2013 } 2014 2015 // Resize_frame with SP(new) = SP(old) - [offset]. 2016 void MacroAssembler::resize_frame_sub(Register offset, Register fp, bool load_fp) 2017 { 2018 assert_different_registers(offset, fp, Z_SP); 2019 if (load_fp) { z_lg(fp, _z_abi(callers_sp), Z_SP); } 2020 2021 z_sgr(Z_SP, offset); 2022 z_stg(fp, _z_abi(callers_sp), Z_SP); 2023 } 2024 2025 // Resize_frame with SP(new) = [newSP] + offset. 2026 // This emitter is useful if we already have calculated a pointer 2027 // into the to-be-allocated stack space, e.g. with special alignment properties, 2028 // but need some additional space, e.g. for spilling. 2029 // newSP is the pre-calculated pointer. It must not be modified. 2030 // fp holds, or is filled with, the frame pointer. 2031 // offset is the additional increment which is added to addr to form the new SP. 2032 // Note: specify a negative value to reserve more space! 2033 // load_fp == true only indicates that fp is not pre-filled with the frame pointer. 2034 // It does not guarantee that fp contains the frame pointer at the end. 2035 void MacroAssembler::resize_frame_abs_with_offset(Register newSP, Register fp, int offset, bool load_fp) { 2036 assert_different_registers(newSP, fp, Z_SP); 2037 2038 if (load_fp) { 2039 z_lg(fp, _z_abi(callers_sp), Z_SP); 2040 } 2041 add2reg(Z_SP, offset, newSP); 2042 z_stg(fp, _z_abi(callers_sp), Z_SP); 2043 } 2044 2045 // Resize_frame with SP(new) = [newSP]. 2046 // load_fp == true only indicates that fp is not pre-filled with the frame pointer. 2047 // It does not guarantee that fp contains the frame pointer at the end. 2048 void MacroAssembler::resize_frame_absolute(Register newSP, Register fp, bool load_fp) { 2049 assert_different_registers(newSP, fp, Z_SP); 2050 2051 if (load_fp) { 2052 z_lg(fp, _z_abi(callers_sp), Z_SP); // need to use load/store. 2053 } 2054 2055 z_lgr(Z_SP, newSP); 2056 if (newSP != Z_R0) { // make sure we generate correct code, no matter what register newSP uses. 2057 z_stg(fp, _z_abi(callers_sp), newSP); 2058 } else { 2059 z_stg(fp, _z_abi(callers_sp), Z_SP); 2060 } 2061 } 2062 2063 // Resize_frame with SP(new) = SP(old) + offset. 2064 void MacroAssembler::resize_frame(RegisterOrConstant offset, Register fp, bool load_fp) { 2065 assert_different_registers(fp, Z_SP); 2066 2067 if (load_fp) { 2068 z_lg(fp, _z_abi(callers_sp), Z_SP); 2069 } 2070 add64(Z_SP, offset); 2071 z_stg(fp, _z_abi(callers_sp), Z_SP); 2072 } 2073 2074 void MacroAssembler::push_frame(Register bytes, Register old_sp, bool copy_sp, bool bytes_with_inverted_sign) { 2075 #ifdef ASSERT 2076 assert_different_registers(bytes, old_sp, Z_SP); 2077 if (!copy_sp) { 2078 z_cgr(old_sp, Z_SP); 2079 asm_assert_eq("[old_sp]!=[Z_SP]", 0x211); 2080 } 2081 #endif 2082 if (copy_sp) { z_lgr(old_sp, Z_SP); } 2083 if (bytes_with_inverted_sign) { 2084 z_agr(Z_SP, bytes); 2085 z_stg(old_sp, 0, Z_SP); 2086 } else { 2087 z_sgr(Z_SP, bytes); // Z_sgfr sufficient, but probably not faster. 2088 z_stg(old_sp, 0, Z_SP); 2089 } 2090 } 2091 2092 unsigned int MacroAssembler::push_frame(unsigned int bytes, Register scratch) { 2093 long offset = Assembler::align(bytes, frame::alignment_in_bytes); 2094 2095 z_lgr(scratch, Z_SP); 2096 add2reg(Z_SP, -offset); 2097 z_stg(scratch, 0, Z_SP); 2098 return offset; 2099 } 2100 2101 // Push a frame of size `bytes' plus abi160 on top. 2102 unsigned int MacroAssembler::push_frame_abi160(unsigned int bytes) { 2103 BLOCK_COMMENT("push_frame_abi160 {"); 2104 unsigned int res = push_frame(bytes + frame::z_abi_160_size); 2105 BLOCK_COMMENT("} push_frame_abi160"); 2106 return res; 2107 } 2108 2109 // Pop current C frame. 2110 void MacroAssembler::pop_frame() { 2111 BLOCK_COMMENT("pop_frame:"); 2112 Assembler::z_lg(Z_SP, _z_abi(callers_sp), Z_SP); 2113 } 2114 2115 // Pop current C frame and restore return PC register (Z_R14). 2116 void MacroAssembler::pop_frame_restore_retPC(int frame_size_in_bytes) { 2117 BLOCK_COMMENT("pop_frame:"); 2118 int retPC_offset = _z_abi16(return_pc) + frame_size_in_bytes; 2119 // If possible, pop frame by add instead of load (a penny saved is a penny got :-). 2120 if (Displacement::is_validDisp(retPC_offset)) { 2121 z_lg(Z_R14, retPC_offset, Z_SP); 2122 add2reg(Z_SP, frame_size_in_bytes); 2123 } else { 2124 add2reg(Z_SP, frame_size_in_bytes); 2125 restore_return_pc(); 2126 } 2127 } 2128 2129 void MacroAssembler::call_VM_leaf_base(address entry_point, bool allow_relocation) { 2130 if (allow_relocation) { 2131 call_c(entry_point); 2132 } else { 2133 call_c_static(entry_point); 2134 } 2135 } 2136 2137 void MacroAssembler::call_VM_leaf_base(address entry_point) { 2138 bool allow_relocation = true; 2139 call_VM_leaf_base(entry_point, allow_relocation); 2140 } 2141 2142 void MacroAssembler::call_VM_base(Register oop_result, 2143 Register last_java_sp, 2144 address entry_point, 2145 bool allow_relocation, 2146 bool check_exceptions) { // Defaults to true. |