OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_MIPS | 5 #if V8_TARGET_ARCH_MIPS |
6 | 6 |
7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 // Push function as argument and compile for baseline. | 1153 // Push function as argument and compile for baseline. |
1154 __ push(a1); | 1154 __ push(a1); |
1155 __ CallRuntime(Runtime::kCompileBaseline); | 1155 __ CallRuntime(Runtime::kCompileBaseline); |
1156 | 1156 |
1157 // Restore return value. | 1157 // Restore return value. |
1158 __ pop(v0); | 1158 __ pop(v0); |
1159 } | 1159 } |
1160 __ Jump(ra); | 1160 __ Jump(ra); |
1161 } | 1161 } |
1162 | 1162 |
| 1163 static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args, |
| 1164 Register scratch1, Register scratch2, |
| 1165 Label* stack_overflow) { |
| 1166 // Check the stack for overflow. We are not trying to catch |
| 1167 // interruptions (e.g. debug break and preemption) here, so the "real stack |
| 1168 // limit" is checked. |
| 1169 __ LoadRoot(scratch1, Heap::kRealStackLimitRootIndex); |
| 1170 // Make scratch1 the space we have left. The stack might already be overflowed |
| 1171 // here which will cause scratch1 to become negative. |
| 1172 __ subu(scratch1, sp, scratch1); |
| 1173 // Check if the arguments will overflow the stack. |
| 1174 __ sll(scratch2, num_args, kPointerSizeLog2); |
| 1175 // Signed comparison. |
| 1176 __ Branch(stack_overflow, le, scratch1, Operand(scratch2)); |
| 1177 } |
| 1178 |
1163 static void Generate_InterpreterPushArgs(MacroAssembler* masm, | 1179 static void Generate_InterpreterPushArgs(MacroAssembler* masm, |
1164 Register num_args, Register index, | 1180 Register num_args, Register index, |
1165 Register scratch, Register last_addr) { | 1181 Register scratch, Register scratch2, |
| 1182 Label* stack_overflow) { |
| 1183 Generate_StackOverflowCheck(masm, num_args, scratch, scratch2, |
| 1184 stack_overflow); |
| 1185 |
1166 // Find the address of the last argument. | 1186 // Find the address of the last argument. |
1167 __ mov(last_addr, num_args); | 1187 __ mov(scratch2, num_args); |
1168 __ sll(last_addr, last_addr, kPointerSizeLog2); | 1188 __ sll(scratch2, scratch2, kPointerSizeLog2); |
1169 __ Subu(last_addr, index, Operand(last_addr)); | 1189 __ Subu(scratch2, index, Operand(scratch2)); |
1170 | 1190 |
1171 // Push the arguments. | 1191 // Push the arguments. |
1172 Label loop_header, loop_check; | 1192 Label loop_header, loop_check; |
1173 __ Branch(&loop_check); | 1193 __ Branch(&loop_check); |
1174 __ bind(&loop_header); | 1194 __ bind(&loop_header); |
1175 __ lw(scratch, MemOperand(index)); | 1195 __ lw(scratch, MemOperand(index)); |
1176 __ Addu(index, index, Operand(-kPointerSize)); | 1196 __ Addu(index, index, Operand(-kPointerSize)); |
1177 __ push(scratch); | 1197 __ push(scratch); |
1178 __ bind(&loop_check); | 1198 __ bind(&loop_check); |
1179 __ Branch(&loop_header, gt, index, Operand(last_addr)); | 1199 __ Branch(&loop_header, gt, index, Operand(scratch2)); |
1180 } | 1200 } |
1181 | 1201 |
1182 // static | 1202 // static |
1183 void Builtins::Generate_InterpreterPushArgsAndCallImpl( | 1203 void Builtins::Generate_InterpreterPushArgsAndCallImpl( |
1184 MacroAssembler* masm, TailCallMode tail_call_mode, | 1204 MacroAssembler* masm, TailCallMode tail_call_mode, |
1185 CallableType function_type) { | 1205 CallableType function_type) { |
1186 // ----------- S t a t e ------------- | 1206 // ----------- S t a t e ------------- |
1187 // -- a0 : the number of arguments (not including the receiver) | 1207 // -- a0 : the number of arguments (not including the receiver) |
1188 // -- a2 : the address of the first argument to be pushed. Subsequent | 1208 // -- a2 : the address of the first argument to be pushed. Subsequent |
1189 // arguments should be consecutive above this, in the same order as | 1209 // arguments should be consecutive above this, in the same order as |
1190 // they are to be pushed onto the stack. | 1210 // they are to be pushed onto the stack. |
1191 // -- a1 : the target to call (can be any Object). | 1211 // -- a1 : the target to call (can be any Object). |
1192 // ----------------------------------- | 1212 // ----------------------------------- |
| 1213 Label stack_overflow; |
1193 | 1214 |
1194 __ Addu(t0, a0, Operand(1)); // Add one for receiver. | 1215 __ Addu(t0, a0, Operand(1)); // Add one for receiver. |
1195 | 1216 |
1196 // This function modifies a2, t4 and t1. | 1217 // This function modifies a2, t4 and t1. |
1197 Generate_InterpreterPushArgs(masm, t0, a2, t4, t1); | 1218 Generate_InterpreterPushArgs(masm, t0, a2, t4, t1, &stack_overflow); |
1198 | 1219 |
1199 // Call the target. | 1220 // Call the target. |
1200 if (function_type == CallableType::kJSFunction) { | 1221 if (function_type == CallableType::kJSFunction) { |
1201 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, | 1222 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, |
1202 tail_call_mode), | 1223 tail_call_mode), |
1203 RelocInfo::CODE_TARGET); | 1224 RelocInfo::CODE_TARGET); |
1204 } else { | 1225 } else { |
1205 DCHECK_EQ(function_type, CallableType::kAny); | 1226 DCHECK_EQ(function_type, CallableType::kAny); |
1206 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, | 1227 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, |
1207 tail_call_mode), | 1228 tail_call_mode), |
1208 RelocInfo::CODE_TARGET); | 1229 RelocInfo::CODE_TARGET); |
1209 } | 1230 } |
| 1231 |
| 1232 __ bind(&stack_overflow); |
| 1233 { |
| 1234 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 1235 // Unreachable code. |
| 1236 __ break_(0xCC); |
| 1237 } |
1210 } | 1238 } |
1211 | 1239 |
1212 // static | 1240 // static |
1213 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( | 1241 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( |
1214 MacroAssembler* masm, CallableType construct_type) { | 1242 MacroAssembler* masm, CallableType construct_type) { |
1215 // ----------- S t a t e ------------- | 1243 // ----------- S t a t e ------------- |
1216 // -- a0 : argument count (not including receiver) | 1244 // -- a0 : argument count (not including receiver) |
1217 // -- a3 : new target | 1245 // -- a3 : new target |
1218 // -- a1 : constructor to call | 1246 // -- a1 : constructor to call |
1219 // -- a2 : allocation site feedback if available, undefined otherwise. | 1247 // -- a2 : allocation site feedback if available, undefined otherwise. |
1220 // -- t4 : address of the first argument | 1248 // -- t4 : address of the first argument |
1221 // ----------------------------------- | 1249 // ----------------------------------- |
| 1250 Label stack_overflow; |
1222 | 1251 |
1223 // Push a slot for the receiver. | 1252 // Push a slot for the receiver. |
1224 __ push(zero_reg); | 1253 __ push(zero_reg); |
1225 | 1254 |
1226 // This function modified t4, t1 and t0. | 1255 // This function modified t4, t1 and t0. |
1227 Generate_InterpreterPushArgs(masm, a0, t4, t1, t0); | 1256 Generate_InterpreterPushArgs(masm, a0, t4, t1, t0, &stack_overflow); |
1228 | 1257 |
1229 __ AssertUndefinedOrAllocationSite(a2, t0); | 1258 __ AssertUndefinedOrAllocationSite(a2, t0); |
1230 if (construct_type == CallableType::kJSFunction) { | 1259 if (construct_type == CallableType::kJSFunction) { |
1231 __ AssertFunction(a1); | 1260 __ AssertFunction(a1); |
1232 | 1261 |
1233 // Tail call to the function-specific construct stub (still in the caller | 1262 // Tail call to the function-specific construct stub (still in the caller |
1234 // context at this point). | 1263 // context at this point). |
1235 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); | 1264 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
1236 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset)); | 1265 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset)); |
1237 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag)); | 1266 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
1238 __ Jump(at); | 1267 __ Jump(at); |
1239 } else { | 1268 } else { |
1240 DCHECK_EQ(construct_type, CallableType::kAny); | 1269 DCHECK_EQ(construct_type, CallableType::kAny); |
1241 // Call the constructor with a0, a1, and a3 unmodified. | 1270 // Call the constructor with a0, a1, and a3 unmodified. |
1242 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); | 1271 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
1243 } | 1272 } |
| 1273 |
| 1274 __ bind(&stack_overflow); |
| 1275 { |
| 1276 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 1277 // Unreachable code. |
| 1278 __ break_(0xCC); |
| 1279 } |
1244 } | 1280 } |
1245 | 1281 |
1246 // static | 1282 // static |
1247 void Builtins::Generate_InterpreterPushArgsAndConstructArray( | 1283 void Builtins::Generate_InterpreterPushArgsAndConstructArray( |
1248 MacroAssembler* masm) { | 1284 MacroAssembler* masm) { |
1249 // ----------- S t a t e ------------- | 1285 // ----------- S t a t e ------------- |
1250 // -- a0 : the number of arguments (not including the receiver) | 1286 // -- a0 : the number of arguments (not including the receiver) |
1251 // -- a1 : the target to call checked to be Array function. | 1287 // -- a1 : the target to call checked to be Array function. |
1252 // -- a2 : allocation site feedback. | 1288 // -- a2 : allocation site feedback. |
1253 // -- a3 : the address of the first argument to be pushed. Subsequent | 1289 // -- a3 : the address of the first argument to be pushed. Subsequent |
1254 // arguments should be consecutive above this, in the same order as | 1290 // arguments should be consecutive above this, in the same order as |
1255 // they are to be pushed onto the stack. | 1291 // they are to be pushed onto the stack. |
1256 // ----------------------------------- | 1292 // ----------------------------------- |
| 1293 Label stack_overflow; |
1257 | 1294 |
1258 __ Addu(t0, a0, Operand(1)); // Add one for receiver. | 1295 __ Addu(t0, a0, Operand(1)); // Add one for receiver. |
1259 | 1296 |
1260 // This function modifies a3, t4, and t1. | 1297 // This function modifies a3, t4, and t1. |
1261 Generate_InterpreterPushArgs(masm, t0, a3, t1, t4); | 1298 Generate_InterpreterPushArgs(masm, t0, a3, t1, t4, &stack_overflow); |
1262 | 1299 |
1263 // ArrayConstructor stub expects constructor in a3. Set it here. | 1300 // ArrayConstructor stub expects constructor in a3. Set it here. |
1264 __ mov(a3, a1); | 1301 __ mov(a3, a1); |
1265 | 1302 |
1266 ArrayConstructorStub stub(masm->isolate()); | 1303 ArrayConstructorStub stub(masm->isolate()); |
1267 __ TailCallStub(&stub); | 1304 __ TailCallStub(&stub); |
| 1305 |
| 1306 __ bind(&stack_overflow); |
| 1307 { |
| 1308 __ TailCallRuntime(Runtime::kThrowStackOverflow); |
| 1309 // Unreachable code. |
| 1310 __ break_(0xCC); |
| 1311 } |
1268 } | 1312 } |
1269 | 1313 |
1270 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { | 1314 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { |
1271 // Set the return address to the correct point in the interpreter entry | 1315 // Set the return address to the correct point in the interpreter entry |
1272 // trampoline. | 1316 // trampoline. |
1273 Smi* interpreter_entry_return_pc_offset( | 1317 Smi* interpreter_entry_return_pc_offset( |
1274 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); | 1318 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); |
1275 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); | 1319 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); |
1276 __ li(t0, Operand(masm->isolate()->builtins()->InterpreterEntryTrampoline())); | 1320 __ li(t0, Operand(masm->isolate()->builtins()->InterpreterEntryTrampoline())); |
1277 __ Addu(ra, t0, Operand(interpreter_entry_return_pc_offset->value() + | 1321 __ Addu(ra, t0, Operand(interpreter_entry_return_pc_offset->value() + |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 } | 2199 } |
2156 | 2200 |
2157 // 4c. The new.target is not a constructor, throw an appropriate TypeError. | 2201 // 4c. The new.target is not a constructor, throw an appropriate TypeError. |
2158 __ bind(&new_target_not_constructor); | 2202 __ bind(&new_target_not_constructor); |
2159 { | 2203 { |
2160 __ sw(a3, MemOperand(sp)); | 2204 __ sw(a3, MemOperand(sp)); |
2161 __ TailCallRuntime(Runtime::kThrowCalledNonCallable); | 2205 __ TailCallRuntime(Runtime::kThrowCalledNonCallable); |
2162 } | 2206 } |
2163 } | 2207 } |
2164 | 2208 |
2165 static void ArgumentAdaptorStackCheck(MacroAssembler* masm, | |
2166 Label* stack_overflow) { | |
2167 // ----------- S t a t e ------------- | |
2168 // -- a0 : actual number of arguments | |
2169 // -- a1 : function (passed through to callee) | |
2170 // -- a2 : expected number of arguments | |
2171 // -- a3 : new target (passed through to callee) | |
2172 // ----------------------------------- | |
2173 // Check the stack for overflow. We are not trying to catch | |
2174 // interruptions (e.g. debug break and preemption) here, so the "real stack | |
2175 // limit" is checked. | |
2176 __ LoadRoot(t1, Heap::kRealStackLimitRootIndex); | |
2177 // Make t1 the space we have left. The stack might already be overflowed | |
2178 // here which will cause t1 to become negative. | |
2179 __ subu(t1, sp, t1); | |
2180 // Check if the arguments will overflow the stack. | |
2181 __ sll(at, a2, kPointerSizeLog2); | |
2182 // Signed comparison. | |
2183 __ Branch(stack_overflow, le, t1, Operand(at)); | |
2184 } | |
2185 | |
2186 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { | 2209 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { |
2187 __ sll(a0, a0, kSmiTagSize); | 2210 __ sll(a0, a0, kSmiTagSize); |
2188 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | 2211 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
2189 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit()); | 2212 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit()); |
2190 __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp + | 2213 __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp + |
2191 kPointerSize)); | 2214 kPointerSize)); |
2192 } | 2215 } |
2193 | 2216 |
2194 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { | 2217 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { |
2195 // ----------- S t a t e ------------- | 2218 // ----------- S t a t e ------------- |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2940 // We use Uless as the number of argument should always be greater than 0. | 2963 // We use Uless as the number of argument should always be greater than 0. |
2941 __ Branch(&too_few, Uless, a0, Operand(a2)); | 2964 __ Branch(&too_few, Uless, a0, Operand(a2)); |
2942 | 2965 |
2943 { // Enough parameters: actual >= expected. | 2966 { // Enough parameters: actual >= expected. |
2944 // a0: actual number of arguments as a smi | 2967 // a0: actual number of arguments as a smi |
2945 // a1: function | 2968 // a1: function |
2946 // a2: expected number of arguments | 2969 // a2: expected number of arguments |
2947 // a3: new target (passed through to callee) | 2970 // a3: new target (passed through to callee) |
2948 __ bind(&enough); | 2971 __ bind(&enough); |
2949 EnterArgumentsAdaptorFrame(masm); | 2972 EnterArgumentsAdaptorFrame(masm); |
2950 ArgumentAdaptorStackCheck(masm, &stack_overflow); | 2973 Generate_StackOverflowCheck(masm, a2, t1, at, &stack_overflow); |
2951 | 2974 |
2952 // Calculate copy start address into a0 and copy end address into t1. | 2975 // Calculate copy start address into a0 and copy end address into t1. |
2953 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize); | 2976 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize); |
2954 // Adjust for return address and receiver. | 2977 // Adjust for return address and receiver. |
2955 __ Addu(a0, a0, Operand(2 * kPointerSize)); | 2978 __ Addu(a0, a0, Operand(2 * kPointerSize)); |
2956 // Compute copy end address. | 2979 // Compute copy end address. |
2957 __ sll(t1, a2, kPointerSizeLog2); | 2980 __ sll(t1, a2, kPointerSizeLog2); |
2958 __ subu(t1, a0, t1); | 2981 __ subu(t1, a0, t1); |
2959 | 2982 |
2960 // Copy the arguments (including the receiver) to the new stack frame. | 2983 // Copy the arguments (including the receiver) to the new stack frame. |
2961 // a0: copy start address | 2984 // a0: copy start address |
2962 // a1: function | 2985 // a1: function |
2963 // a2: expected number of arguments | 2986 // a2: expected number of arguments |
2964 // a3: new target (passed through to callee) | 2987 // a3: new target (passed through to callee) |
2965 // t1: copy end address | 2988 // t1: copy end address |
2966 | 2989 |
2967 Label copy; | 2990 Label copy; |
2968 __ bind(©); | 2991 __ bind(©); |
2969 __ lw(t0, MemOperand(a0)); | 2992 __ lw(t0, MemOperand(a0)); |
2970 __ push(t0); | 2993 __ push(t0); |
2971 __ Branch(USE_DELAY_SLOT, ©, ne, a0, Operand(t1)); | 2994 __ Branch(USE_DELAY_SLOT, ©, ne, a0, Operand(t1)); |
2972 __ addiu(a0, a0, -kPointerSize); // In delay slot. | 2995 __ addiu(a0, a0, -kPointerSize); // In delay slot. |
2973 | 2996 |
2974 __ jmp(&invoke); | 2997 __ jmp(&invoke); |
2975 } | 2998 } |
2976 | 2999 |
2977 { // Too few parameters: Actual < expected. | 3000 { // Too few parameters: Actual < expected. |
2978 __ bind(&too_few); | 3001 __ bind(&too_few); |
2979 EnterArgumentsAdaptorFrame(masm); | 3002 EnterArgumentsAdaptorFrame(masm); |
2980 ArgumentAdaptorStackCheck(masm, &stack_overflow); | 3003 Generate_StackOverflowCheck(masm, a2, t1, at, &stack_overflow); |
2981 | 3004 |
2982 // Calculate copy start address into a0 and copy end address into t3. | 3005 // Calculate copy start address into a0 and copy end address into t3. |
2983 // a0: actual number of arguments as a smi | 3006 // a0: actual number of arguments as a smi |
2984 // a1: function | 3007 // a1: function |
2985 // a2: expected number of arguments | 3008 // a2: expected number of arguments |
2986 // a3: new target (passed through to callee) | 3009 // a3: new target (passed through to callee) |
2987 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize); | 3010 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize); |
2988 // Adjust for return address and receiver. | 3011 // Adjust for return address and receiver. |
2989 __ Addu(a0, a0, Operand(2 * kPointerSize)); | 3012 __ Addu(a0, a0, Operand(2 * kPointerSize)); |
2990 // Compute copy end address. Also adjust for return address. | 3013 // Compute copy end address. Also adjust for return address. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3052 __ break_(0xCC); | 3075 __ break_(0xCC); |
3053 } | 3076 } |
3054 } | 3077 } |
3055 | 3078 |
3056 #undef __ | 3079 #undef __ |
3057 | 3080 |
3058 } // namespace internal | 3081 } // namespace internal |
3059 } // namespace v8 | 3082 } // namespace v8 |
3060 | 3083 |
3061 #endif // V8_TARGET_ARCH_MIPS | 3084 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |