| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 | 97 |
| 98 void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, | 98 void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 99 Condition cond) { | 99 Condition cond) { |
| 100 ASSERT(RelocInfo::IsCodeTarget(rmode)); | 100 ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 101 // 'code' is always generated ARM code, never THUMB code | 101 // 'code' is always generated ARM code, never THUMB code |
| 102 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); | 102 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| 106 int MacroAssembler::CallSize(Register target, Condition cond) { |
| 107 #if USE_BLX |
| 108 return kInstrSize; |
| 109 #else |
| 110 return 2 * kInstrSize; |
| 111 #endif |
| 112 } |
| 113 |
| 114 |
| 106 void MacroAssembler::Call(Register target, Condition cond) { | 115 void MacroAssembler::Call(Register target, Condition cond) { |
| 116 #ifdef DEBUG |
| 117 int pre_position = pc_offset(); |
| 118 #endif |
| 119 |
| 107 #if USE_BLX | 120 #if USE_BLX |
| 108 blx(target, cond); | 121 blx(target, cond); |
| 109 #else | 122 #else |
| 110 // set lr for return at current pc + 8 | 123 // set lr for return at current pc + 8 |
| 111 mov(lr, Operand(pc), LeaveCC, cond); | 124 { BlockConstPoolScope block_const_pool(this); |
| 112 mov(pc, Operand(target), LeaveCC, cond); | 125 mov(lr, Operand(pc), LeaveCC, cond); |
| 126 mov(pc, Operand(target), LeaveCC, cond); |
| 127 } |
| 128 #endif |
| 129 |
| 130 #ifdef DEBUG |
| 131 int post_position = pc_offset(); |
| 132 CHECK_EQ(pre_position + CallSize(target, cond), post_position); |
| 113 #endif | 133 #endif |
| 114 } | 134 } |
| 115 | 135 |
| 116 | 136 |
| 117 void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode, | 137 int MacroAssembler::CallSize( |
| 118 Condition cond) { | 138 intptr_t target, RelocInfo::Mode rmode, Condition cond) { |
| 139 int size = 2 * kInstrSize; |
| 140 Instr mov_instr = cond | MOV | LeaveCC; |
| 141 if (!Operand(target, rmode).is_single_instruction(mov_instr)) { |
| 142 size += kInstrSize; |
| 143 } |
| 144 return size; |
| 145 } |
| 146 |
| 147 |
| 148 void MacroAssembler::Call( |
| 149 intptr_t target, RelocInfo::Mode rmode, Condition cond) { |
| 150 #ifdef DEBUG |
| 151 int pre_position = pc_offset(); |
| 152 #endif |
| 153 |
| 119 #if USE_BLX | 154 #if USE_BLX |
| 120 // On ARMv5 and after the recommended call sequence is: | 155 // On ARMv5 and after the recommended call sequence is: |
| 121 // ldr ip, [pc, #...] | 156 // ldr ip, [pc, #...] |
| 122 // blx ip | 157 // blx ip |
| 123 | 158 |
| 124 // The two instructions (ldr and blx) could be separated by a constant | 159 // The two instructions (ldr and blx) could be separated by a constant |
| 125 // pool and the code would still work. The issue comes from the | 160 // pool and the code would still work. The issue comes from the |
| 126 // patching code which expect the ldr to be just above the blx. | 161 // patching code which expect the ldr to be just above the blx. |
| 127 { BlockConstPoolScope block_const_pool(this); | 162 { BlockConstPoolScope block_const_pool(this); |
| 128 // Statement positions are expected to be recorded when the target | 163 // Statement positions are expected to be recorded when the target |
| 129 // address is loaded. The mov method will automatically record | 164 // address is loaded. The mov method will automatically record |
| 130 // positions when pc is the target, since this is not the case here | 165 // positions when pc is the target, since this is not the case here |
| 131 // we have to do it explicitly. | 166 // we have to do it explicitly. |
| 132 positions_recorder()->WriteRecordedPositions(); | 167 positions_recorder()->WriteRecordedPositions(); |
| 133 | 168 |
| 134 mov(ip, Operand(target, rmode), LeaveCC, cond); | 169 mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 135 blx(ip, cond); | 170 blx(ip, cond); |
| 136 } | 171 } |
| 137 | 172 |
| 138 ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); | 173 ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 139 #else | 174 #else |
| 140 // Set lr for return at current pc + 8. | 175 { BlockConstPoolScope block_const_pool(this); |
| 141 mov(lr, Operand(pc), LeaveCC, cond); | 176 // Set lr for return at current pc + 8. |
| 142 // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. | 177 mov(lr, Operand(pc), LeaveCC, cond); |
| 143 mov(pc, Operand(target, rmode), LeaveCC, cond); | 178 // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 179 mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 180 } |
| 181 ASSERT(kCallTargetAddressOffset == kInstrSize); |
| 182 #endif |
| 144 | 183 |
| 145 ASSERT(kCallTargetAddressOffset == kInstrSize); | 184 #ifdef DEBUG |
| 185 int post_position = pc_offset(); |
| 186 CHECK_EQ(pre_position + CallSize(target, rmode, cond), post_position); |
| 146 #endif | 187 #endif |
| 147 } | 188 } |
| 148 | 189 |
| 149 | 190 |
| 150 void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode, | 191 int MacroAssembler::CallSize( |
| 151 Condition cond) { | 192 byte* target, RelocInfo::Mode rmode, Condition cond) { |
| 152 ASSERT(!RelocInfo::IsCodeTarget(rmode)); | 193 return CallSize(reinterpret_cast<intptr_t>(target), rmode); |
| 153 Call(reinterpret_cast<intptr_t>(target), rmode, cond); | |
| 154 } | 194 } |
| 155 | 195 |
| 156 | 196 |
| 157 void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, | 197 void MacroAssembler::Call( |
| 158 Condition cond) { | 198 byte* target, RelocInfo::Mode rmode, Condition cond) { |
| 199 #ifdef DEBUG |
| 200 int pre_position = pc_offset(); |
| 201 #endif |
| 202 |
| 203 ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 204 Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 205 |
| 206 #ifdef DEBUG |
| 207 int post_position = pc_offset(); |
| 208 CHECK_EQ(pre_position + CallSize(target, rmode, cond), post_position); |
| 209 #endif |
| 210 } |
| 211 |
| 212 |
| 213 int MacroAssembler::CallSize( |
| 214 Handle<Code> code, RelocInfo::Mode rmode, Condition cond) { |
| 215 return CallSize(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 216 } |
| 217 |
| 218 |
| 219 void MacroAssembler::Call( |
| 220 Handle<Code> code, RelocInfo::Mode rmode, Condition cond) { |
| 221 #ifdef DEBUG |
| 222 int pre_position = pc_offset(); |
| 223 #endif |
| 224 |
| 159 ASSERT(RelocInfo::IsCodeTarget(rmode)); | 225 ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 160 // 'code' is always generated ARM code, never THUMB code | 226 // 'code' is always generated ARM code, never THUMB code |
| 161 Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); | 227 Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 228 |
| 229 #ifdef DEBUG |
| 230 int post_position = pc_offset(); |
| 231 CHECK_EQ(pre_position + CallSize(code, rmode, cond), post_position); |
| 232 #endif |
| 162 } | 233 } |
| 163 | 234 |
| 164 | 235 |
| 165 void MacroAssembler::Ret(Condition cond) { | 236 void MacroAssembler::Ret(Condition cond) { |
| 166 #if USE_BX | 237 #if USE_BX |
| 167 bx(lr, cond); | 238 bx(lr, cond); |
| 168 #else | 239 #else |
| 169 mov(pc, Operand(lr), LeaveCC, cond); | 240 mov(pc, Operand(lr), LeaveCC, cond); |
| 170 #endif | 241 #endif |
| 171 } | 242 } |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 #endif | 848 #endif |
| 778 } | 849 } |
| 779 | 850 |
| 780 | 851 |
| 781 void MacroAssembler::InvokePrologue(const ParameterCount& expected, | 852 void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 782 const ParameterCount& actual, | 853 const ParameterCount& actual, |
| 783 Handle<Code> code_constant, | 854 Handle<Code> code_constant, |
| 784 Register code_reg, | 855 Register code_reg, |
| 785 Label* done, | 856 Label* done, |
| 786 InvokeFlag flag, | 857 InvokeFlag flag, |
| 787 PostCallGenerator* post_call_generator) { | 858 CallWrapper* call_wrapper) { |
| 788 bool definitely_matches = false; | 859 bool definitely_matches = false; |
| 789 Label regular_invoke; | 860 Label regular_invoke; |
| 790 | 861 |
| 791 // Check whether the expected and actual arguments count match. If not, | 862 // Check whether the expected and actual arguments count match. If not, |
| 792 // setup registers according to contract with ArgumentsAdaptorTrampoline: | 863 // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 793 // r0: actual arguments count | 864 // r0: actual arguments count |
| 794 // r1: function (passed through to callee) | 865 // r1: function (passed through to callee) |
| 795 // r2: expected arguments count | 866 // r2: expected arguments count |
| 796 // r3: callee code entry | 867 // r3: callee code entry |
| 797 | 868 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 if (!definitely_matches) { | 904 if (!definitely_matches) { |
| 834 if (!code_constant.is_null()) { | 905 if (!code_constant.is_null()) { |
| 835 mov(r3, Operand(code_constant)); | 906 mov(r3, Operand(code_constant)); |
| 836 add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); | 907 add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 837 } | 908 } |
| 838 | 909 |
| 839 Handle<Code> adaptor = | 910 Handle<Code> adaptor = |
| 840 Handle<Code>(Isolate::Current()->builtins()->builtin( | 911 Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 841 Builtins::ArgumentsAdaptorTrampoline)); | 912 Builtins::ArgumentsAdaptorTrampoline)); |
| 842 if (flag == CALL_FUNCTION) { | 913 if (flag == CALL_FUNCTION) { |
| 914 if (call_wrapper != NULL) { |
| 915 call_wrapper->BeforeCall(CallSize(adaptor, RelocInfo::CODE_TARGET)); |
| 916 } |
| 843 Call(adaptor, RelocInfo::CODE_TARGET); | 917 Call(adaptor, RelocInfo::CODE_TARGET); |
| 844 if (post_call_generator != NULL) post_call_generator->Generate(); | 918 if (call_wrapper != NULL) call_wrapper->AfterCall(); |
| 845 b(done); | 919 b(done); |
| 846 } else { | 920 } else { |
| 847 Jump(adaptor, RelocInfo::CODE_TARGET); | 921 Jump(adaptor, RelocInfo::CODE_TARGET); |
| 848 } | 922 } |
| 849 bind(®ular_invoke); | 923 bind(®ular_invoke); |
| 850 } | 924 } |
| 851 } | 925 } |
| 852 | 926 |
| 853 | 927 |
| 854 void MacroAssembler::InvokeCode(Register code, | 928 void MacroAssembler::InvokeCode(Register code, |
| 855 const ParameterCount& expected, | 929 const ParameterCount& expected, |
| 856 const ParameterCount& actual, | 930 const ParameterCount& actual, |
| 857 InvokeFlag flag, | 931 InvokeFlag flag, |
| 858 PostCallGenerator* post_call_generator) { | 932 CallWrapper* call_wrapper) { |
| 859 Label done; | 933 Label done; |
| 860 | 934 |
| 861 InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag, | 935 InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag, |
| 862 post_call_generator); | 936 call_wrapper); |
| 863 if (flag == CALL_FUNCTION) { | 937 if (flag == CALL_FUNCTION) { |
| 938 if (call_wrapper != NULL) call_wrapper->BeforeCall(CallSize(code)); |
| 864 Call(code); | 939 Call(code); |
| 865 if (post_call_generator != NULL) post_call_generator->Generate(); | 940 if (call_wrapper != NULL) call_wrapper->AfterCall(); |
| 866 } else { | 941 } else { |
| 867 ASSERT(flag == JUMP_FUNCTION); | 942 ASSERT(flag == JUMP_FUNCTION); |
| 868 Jump(code); | 943 Jump(code); |
| 869 } | 944 } |
| 870 | 945 |
| 871 // Continue here if InvokePrologue does handle the invocation due to | 946 // Continue here if InvokePrologue does handle the invocation due to |
| 872 // mismatched parameter counts. | 947 // mismatched parameter counts. |
| 873 bind(&done); | 948 bind(&done); |
| 874 } | 949 } |
| 875 | 950 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 890 | 965 |
| 891 // Continue here if InvokePrologue does handle the invocation due to | 966 // Continue here if InvokePrologue does handle the invocation due to |
| 892 // mismatched parameter counts. | 967 // mismatched parameter counts. |
| 893 bind(&done); | 968 bind(&done); |
| 894 } | 969 } |
| 895 | 970 |
| 896 | 971 |
| 897 void MacroAssembler::InvokeFunction(Register fun, | 972 void MacroAssembler::InvokeFunction(Register fun, |
| 898 const ParameterCount& actual, | 973 const ParameterCount& actual, |
| 899 InvokeFlag flag, | 974 InvokeFlag flag, |
| 900 PostCallGenerator* post_call_generator) { | 975 CallWrapper* call_wrapper) { |
| 901 // Contract with called JS functions requires that function is passed in r1. | 976 // Contract with called JS functions requires that function is passed in r1. |
| 902 ASSERT(fun.is(r1)); | 977 ASSERT(fun.is(r1)); |
| 903 | 978 |
| 904 Register expected_reg = r2; | 979 Register expected_reg = r2; |
| 905 Register code_reg = r3; | 980 Register code_reg = r3; |
| 906 | 981 |
| 907 ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); | 982 ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 908 ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); | 983 ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 909 ldr(expected_reg, | 984 ldr(expected_reg, |
| 910 FieldMemOperand(code_reg, | 985 FieldMemOperand(code_reg, |
| 911 SharedFunctionInfo::kFormalParameterCountOffset)); | 986 SharedFunctionInfo::kFormalParameterCountOffset)); |
| 912 mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); | 987 mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
| 913 ldr(code_reg, | 988 ldr(code_reg, |
| 914 FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); | 989 FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 915 | 990 |
| 916 ParameterCount expected(expected_reg); | 991 ParameterCount expected(expected_reg); |
| 917 InvokeCode(code_reg, expected, actual, flag, post_call_generator); | 992 InvokeCode(code_reg, expected, actual, flag, call_wrapper); |
| 918 } | 993 } |
| 919 | 994 |
| 920 | 995 |
| 921 void MacroAssembler::InvokeFunction(JSFunction* function, | 996 void MacroAssembler::InvokeFunction(JSFunction* function, |
| 922 const ParameterCount& actual, | 997 const ParameterCount& actual, |
| 923 InvokeFlag flag) { | 998 InvokeFlag flag) { |
| 924 ASSERT(function->is_compiled()); | 999 ASSERT(function->is_compiled()); |
| 925 | 1000 |
| 926 // Get the function and setup the context. | 1001 // Get the function and setup the context. |
| 927 mov(r1, Operand(Handle<JSFunction>(function))); | 1002 mov(r1, Operand(Handle<JSFunction>(function))); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2079 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); | 2154 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2080 #endif | 2155 #endif |
| 2081 mov(r1, Operand(builtin)); | 2156 mov(r1, Operand(builtin)); |
| 2082 CEntryStub stub(1); | 2157 CEntryStub stub(1); |
| 2083 return TryTailCallStub(&stub); | 2158 return TryTailCallStub(&stub); |
| 2084 } | 2159 } |
| 2085 | 2160 |
| 2086 | 2161 |
| 2087 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, | 2162 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 2088 InvokeJSFlags flags, | 2163 InvokeJSFlags flags, |
| 2089 PostCallGenerator* post_call_generator) { | 2164 CallWrapper* call_wrapper) { |
| 2090 GetBuiltinEntry(r2, id); | 2165 GetBuiltinEntry(r2, id); |
| 2091 if (flags == CALL_JS) { | 2166 if (flags == CALL_JS) { |
| 2167 if (call_wrapper != NULL) call_wrapper->BeforeCall(CallSize(r2)); |
| 2092 Call(r2); | 2168 Call(r2); |
| 2093 if (post_call_generator != NULL) post_call_generator->Generate(); | 2169 if (call_wrapper != NULL) call_wrapper->AfterCall(); |
| 2094 } else { | 2170 } else { |
| 2095 ASSERT(flags == JUMP_JS); | 2171 ASSERT(flags == JUMP_JS); |
| 2096 Jump(r2); | 2172 Jump(r2); |
| 2097 } | 2173 } |
| 2098 } | 2174 } |
| 2099 | 2175 |
| 2100 | 2176 |
| 2101 void MacroAssembler::GetBuiltinFunction(Register target, | 2177 void MacroAssembler::GetBuiltinFunction(Register target, |
| 2102 Builtins::JavaScript id) { | 2178 Builtins::JavaScript id) { |
| 2103 // Load the builtins object into target register. | 2179 // Load the builtins object into target register. |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2738 void CodePatcher::EmitCondition(Condition cond) { | 2814 void CodePatcher::EmitCondition(Condition cond) { |
| 2739 Instr instr = Assembler::instr_at(masm_.pc_); | 2815 Instr instr = Assembler::instr_at(masm_.pc_); |
| 2740 instr = (instr & ~kCondMask) | cond; | 2816 instr = (instr & ~kCondMask) | cond; |
| 2741 masm_.emit(instr); | 2817 masm_.emit(instr); |
| 2742 } | 2818 } |
| 2743 | 2819 |
| 2744 | 2820 |
| 2745 } } // namespace v8::internal | 2821 } } // namespace v8::internal |
| 2746 | 2822 |
| 2747 #endif // V8_TARGET_ARCH_ARM | 2823 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |