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/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 __ EnterExitFrame(save_doubles()); | 1085 __ EnterExitFrame(save_doubles()); |
1086 | 1086 |
1087 // s0: number of arguments including receiver (C callee-saved) | 1087 // s0: number of arguments including receiver (C callee-saved) |
1088 // s1: pointer to first argument (C callee-saved) | 1088 // s1: pointer to first argument (C callee-saved) |
1089 // s2: pointer to builtin function (C callee-saved) | 1089 // s2: pointer to builtin function (C callee-saved) |
1090 | 1090 |
1091 // Prepare arguments for C routine. | 1091 // Prepare arguments for C routine. |
1092 // a0 = argc | 1092 // a0 = argc |
1093 __ mov(s0, a0); | 1093 __ mov(s0, a0); |
1094 __ mov(s2, a1); | 1094 __ mov(s2, a1); |
1095 // a1 = argv (set in the delay slot after find_ra below). | |
1096 | 1095 |
1097 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We | 1096 // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We |
1098 // also need to reserve the 4 argument slots on the stack. | 1097 // also need to reserve the 4 argument slots on the stack. |
1099 | 1098 |
1100 __ AssertStackIsAligned(); | 1099 __ AssertStackIsAligned(); |
1101 | 1100 |
1102 __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); | 1101 int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 1102 int frame_alignment_mask = frame_alignment - 1; |
| 1103 int result_stack_size; |
| 1104 if (result_size() <= 2) { |
| 1105 // a0 = argc, a1 = argv, a2 = isolate |
| 1106 __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1107 __ mov(a1, s1); |
| 1108 result_stack_size = 0; |
| 1109 } else { |
| 1110 DCHECK_EQ(3, result_size()); |
| 1111 // Allocate additional space for the result. |
| 1112 result_stack_size = |
| 1113 ((result_size() * kPointerSize) + frame_alignment_mask) & |
| 1114 ~frame_alignment_mask; |
| 1115 __ Subu(sp, sp, Operand(result_stack_size)); |
| 1116 |
| 1117 // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate. |
| 1118 __ li(a3, Operand(ExternalReference::isolate_address(isolate()))); |
| 1119 __ mov(a2, s1); |
| 1120 __ mov(a1, a0); |
| 1121 __ mov(a0, sp); |
| 1122 } |
1103 | 1123 |
1104 // To let the GC traverse the return address of the exit frames, we need to | 1124 // To let the GC traverse the return address of the exit frames, we need to |
1105 // know where the return address is. The CEntryStub is unmovable, so | 1125 // know where the return address is. The CEntryStub is unmovable, so |
1106 // we can store the address on the stack to be able to find it again and | 1126 // we can store the address on the stack to be able to find it again and |
1107 // we never have to restore it, because it will not change. | 1127 // we never have to restore it, because it will not change. |
1108 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); | 1128 { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
1109 // This branch-and-link sequence is needed to find the current PC on mips, | 1129 // This branch-and-link sequence is needed to find the current PC on mips, |
1110 // saved to the ra register. | 1130 // saved to the ra register. |
1111 // Use masm-> here instead of the double-underscore macro since extra | 1131 // Use masm-> here instead of the double-underscore macro since extra |
1112 // coverage code can interfere with the proper calculation of ra. | 1132 // coverage code can interfere with the proper calculation of ra. |
1113 Label find_ra; | 1133 Label find_ra; |
1114 masm->bal(&find_ra); // bal exposes branch delay slot. | 1134 __ bal(&find_ra); // bal exposes branch delay slot. |
1115 masm->mov(a1, s1); | 1135 __ nop(); |
1116 masm->bind(&find_ra); | 1136 __ bind(&find_ra); |
1117 | 1137 |
1118 // Adjust the value in ra to point to the correct return location, 2nd | 1138 // Adjust the value in ra to point to the correct return location, 2nd |
1119 // instruction past the real call into C code (the jalr(t9)), and push it. | 1139 // instruction past the real call into C code (the jalr(t9)), and push it. |
1120 // This is the return address of the exit frame. | 1140 // This is the return address of the exit frame. |
1121 const int kNumInstructionsToJump = 5; | 1141 const int kNumInstructionsToJump = 5; |
1122 masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize); | 1142 __ Addu(ra, ra, kNumInstructionsToJump * kPointerSize); |
1123 masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame. | 1143 // This spot was reserved in EnterExitFrame. |
| 1144 __ sw(ra, MemOperand(sp, result_stack_size)); |
1124 // Stack space reservation moved to the branch delay slot below. | 1145 // Stack space reservation moved to the branch delay slot below. |
1125 // Stack is still aligned. | 1146 // Stack is still aligned. |
1126 | 1147 |
1127 // Call the C routine. | 1148 // Call the C routine. |
1128 masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. | 1149 __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. |
1129 masm->jalr(t9); | 1150 __ jalr(t9); |
1130 // Set up sp in the delay slot. | 1151 // Set up sp in the delay slot. |
1131 masm->addiu(sp, sp, -kCArgsSlotsSize); | 1152 __ addiu(sp, sp, -kCArgsSlotsSize); |
1132 // Make sure the stored 'ra' points to this position. | 1153 // Make sure the stored 'ra' points to this position. |
1133 DCHECK_EQ(kNumInstructionsToJump, | 1154 DCHECK_EQ(kNumInstructionsToJump, |
1134 masm->InstructionsGeneratedSince(&find_ra)); | 1155 masm->InstructionsGeneratedSince(&find_ra)); |
1135 } | 1156 } |
1136 | 1157 if (result_size() > 2) { |
| 1158 DCHECK_EQ(3, result_size()); |
| 1159 // Read result values stored on stack. |
| 1160 __ lw(a0, MemOperand(v0, 2 * kPointerSize)); |
| 1161 __ lw(v1, MemOperand(v0, 1 * kPointerSize)); |
| 1162 __ lw(v0, MemOperand(v0, 0 * kPointerSize)); |
| 1163 } |
| 1164 // Result returned in v0, v1:v0 or a0:v1:v0 - do not destroy these registers! |
1137 | 1165 |
1138 // Check result for exception sentinel. | 1166 // Check result for exception sentinel. |
1139 Label exception_returned; | 1167 Label exception_returned; |
1140 __ LoadRoot(t0, Heap::kExceptionRootIndex); | 1168 __ LoadRoot(t0, Heap::kExceptionRootIndex); |
1141 __ Branch(&exception_returned, eq, t0, Operand(v0)); | 1169 __ Branch(&exception_returned, eq, t0, Operand(v0)); |
1142 | 1170 |
1143 // Check that there is no pending exception, otherwise we | 1171 // Check that there is no pending exception, otherwise we |
1144 // should have returned the exception sentinel. | 1172 // should have returned the exception sentinel. |
1145 if (FLAG_debug_code) { | 1173 if (FLAG_debug_code) { |
1146 Label okay; | 1174 Label okay; |
(...skipping 4444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5591 MemOperand(fp, 6 * kPointerSize), NULL); | 5619 MemOperand(fp, 6 * kPointerSize), NULL); |
5592 } | 5620 } |
5593 | 5621 |
5594 | 5622 |
5595 #undef __ | 5623 #undef __ |
5596 | 5624 |
5597 } // namespace internal | 5625 } // namespace internal |
5598 } // namespace v8 | 5626 } // namespace v8 |
5599 | 5627 |
5600 #endif // V8_TARGET_ARCH_MIPS | 5628 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |