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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X87 | 7 #if V8_TARGET_ARCH_X87 |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/division-by-constant.h" | 10 #include "src/base/division-by-constant.h" |
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2041 | 2041 |
2042 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, | 2042 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
2043 int num_arguments, | 2043 int num_arguments, |
2044 int result_size) { | 2044 int result_size) { |
2045 TailCallExternalReference(ExternalReference(fid, isolate()), | 2045 TailCallExternalReference(ExternalReference(fid, isolate()), |
2046 num_arguments, | 2046 num_arguments, |
2047 result_size); | 2047 result_size); |
2048 } | 2048 } |
2049 | 2049 |
2050 | 2050 |
2051 Operand ApiParameterOperand(int index) { | |
2052 return Operand(esp, index * kPointerSize); | |
2053 } | |
2054 | |
2055 | |
2056 void MacroAssembler::PrepareCallApiFunction(int argc) { | |
2057 EnterApiExitFrame(argc); | |
2058 if (emit_debug_code()) { | |
2059 mov(esi, Immediate(bit_cast<int32_t>(kZapValue))); | |
2060 } | |
2061 } | |
2062 | |
2063 | |
2064 void MacroAssembler::CallApiFunctionAndReturn( | |
2065 Register function_address, ExternalReference thunk_ref, | |
2066 Operand thunk_last_arg, int stack_space, Operand* stack_space_operand, | |
2067 Operand return_value_operand, Operand* context_restore_operand) { | |
2068 ExternalReference next_address = | |
2069 ExternalReference::handle_scope_next_address(isolate()); | |
2070 ExternalReference limit_address = | |
2071 ExternalReference::handle_scope_limit_address(isolate()); | |
2072 ExternalReference level_address = | |
2073 ExternalReference::handle_scope_level_address(isolate()); | |
2074 | |
2075 DCHECK(edx.is(function_address)); | |
2076 // Allocate HandleScope in callee-save registers. | |
2077 mov(ebx, Operand::StaticVariable(next_address)); | |
2078 mov(edi, Operand::StaticVariable(limit_address)); | |
2079 add(Operand::StaticVariable(level_address), Immediate(1)); | |
2080 | |
2081 if (FLAG_log_timer_events) { | |
2082 FrameScope frame(this, StackFrame::MANUAL); | |
2083 PushSafepointRegisters(); | |
2084 PrepareCallCFunction(1, eax); | |
2085 mov(Operand(esp, 0), | |
2086 Immediate(ExternalReference::isolate_address(isolate()))); | |
2087 CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1); | |
2088 PopSafepointRegisters(); | |
2089 } | |
2090 | |
2091 | |
2092 Label profiler_disabled; | |
2093 Label end_profiler_check; | |
2094 mov(eax, Immediate(ExternalReference::is_profiling_address(isolate()))); | |
2095 cmpb(Operand(eax, 0), 0); | |
2096 j(zero, &profiler_disabled); | |
2097 | |
2098 // Additional parameter is the address of the actual getter function. | |
2099 mov(thunk_last_arg, function_address); | |
2100 // Call the api function. | |
2101 mov(eax, Immediate(thunk_ref)); | |
2102 call(eax); | |
2103 jmp(&end_profiler_check); | |
2104 | |
2105 bind(&profiler_disabled); | |
2106 // Call the api function. | |
2107 call(function_address); | |
2108 bind(&end_profiler_check); | |
2109 | |
2110 if (FLAG_log_timer_events) { | |
2111 FrameScope frame(this, StackFrame::MANUAL); | |
2112 PushSafepointRegisters(); | |
2113 PrepareCallCFunction(1, eax); | |
2114 mov(Operand(esp, 0), | |
2115 Immediate(ExternalReference::isolate_address(isolate()))); | |
2116 CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1); | |
2117 PopSafepointRegisters(); | |
2118 } | |
2119 | |
2120 Label prologue; | |
2121 // Load the value from ReturnValue | |
2122 mov(eax, return_value_operand); | |
2123 | |
2124 Label promote_scheduled_exception; | |
2125 Label exception_handled; | |
2126 Label delete_allocated_handles; | |
2127 Label leave_exit_frame; | |
2128 | |
2129 bind(&prologue); | |
2130 // No more valid handles (the result handle was the last one). Restore | |
2131 // previous handle scope. | |
2132 mov(Operand::StaticVariable(next_address), ebx); | |
2133 sub(Operand::StaticVariable(level_address), Immediate(1)); | |
2134 Assert(above_equal, kInvalidHandleScopeLevel); | |
2135 cmp(edi, Operand::StaticVariable(limit_address)); | |
2136 j(not_equal, &delete_allocated_handles); | |
2137 bind(&leave_exit_frame); | |
2138 | |
2139 // Check if the function scheduled an exception. | |
2140 ExternalReference scheduled_exception_address = | |
2141 ExternalReference::scheduled_exception_address(isolate()); | |
2142 cmp(Operand::StaticVariable(scheduled_exception_address), | |
2143 Immediate(isolate()->factory()->the_hole_value())); | |
2144 j(not_equal, &promote_scheduled_exception); | |
2145 bind(&exception_handled); | |
2146 | |
2147 #if DEBUG | |
2148 // Check if the function returned a valid JavaScript value. | |
2149 Label ok; | |
2150 Register return_value = eax; | |
2151 Register map = ecx; | |
2152 | |
2153 JumpIfSmi(return_value, &ok, Label::kNear); | |
2154 mov(map, FieldOperand(return_value, HeapObject::kMapOffset)); | |
2155 | |
2156 CmpInstanceType(map, LAST_NAME_TYPE); | |
2157 j(below_equal, &ok, Label::kNear); | |
2158 | |
2159 CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); | |
2160 j(above_equal, &ok, Label::kNear); | |
2161 | |
2162 cmp(map, isolate()->factory()->heap_number_map()); | |
2163 j(equal, &ok, Label::kNear); | |
2164 | |
2165 cmp(return_value, isolate()->factory()->undefined_value()); | |
2166 j(equal, &ok, Label::kNear); | |
2167 | |
2168 cmp(return_value, isolate()->factory()->true_value()); | |
2169 j(equal, &ok, Label::kNear); | |
2170 | |
2171 cmp(return_value, isolate()->factory()->false_value()); | |
2172 j(equal, &ok, Label::kNear); | |
2173 | |
2174 cmp(return_value, isolate()->factory()->null_value()); | |
2175 j(equal, &ok, Label::kNear); | |
2176 | |
2177 Abort(kAPICallReturnedInvalidObject); | |
2178 | |
2179 bind(&ok); | |
2180 #endif | |
2181 | |
2182 bool restore_context = context_restore_operand != NULL; | |
2183 if (restore_context) { | |
2184 mov(esi, *context_restore_operand); | |
2185 } | |
2186 if (stack_space_operand != nullptr) { | |
2187 mov(ebx, *stack_space_operand); | |
2188 } | |
2189 LeaveApiExitFrame(!restore_context); | |
2190 if (stack_space_operand != nullptr) { | |
2191 DCHECK_EQ(0, stack_space); | |
2192 pop(ecx); | |
2193 add(esp, ebx); | |
2194 jmp(ecx); | |
2195 } else { | |
2196 ret(stack_space * kPointerSize); | |
2197 } | |
2198 | |
2199 bind(&promote_scheduled_exception); | |
2200 { | |
2201 FrameScope frame(this, StackFrame::INTERNAL); | |
2202 CallRuntime(Runtime::kPromoteScheduledException, 0); | |
2203 } | |
2204 jmp(&exception_handled); | |
2205 | |
2206 // HandleScope limit has changed. Delete allocated extensions. | |
2207 ExternalReference delete_extensions = | |
2208 ExternalReference::delete_handle_scope_extensions(isolate()); | |
2209 bind(&delete_allocated_handles); | |
2210 mov(Operand::StaticVariable(limit_address), edi); | |
2211 mov(edi, eax); | |
2212 mov(Operand(esp, 0), | |
2213 Immediate(ExternalReference::isolate_address(isolate()))); | |
2214 mov(eax, Immediate(delete_extensions)); | |
2215 call(eax); | |
2216 mov(eax, edi); | |
2217 jmp(&leave_exit_frame); | |
2218 } | |
2219 | |
2220 | |
2221 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext) { | 2051 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext) { |
2222 // Set the entry point and jump to the C entry runtime stub. | 2052 // Set the entry point and jump to the C entry runtime stub. |
2223 mov(ebx, Immediate(ext)); | 2053 mov(ebx, Immediate(ext)); |
2224 CEntryStub ces(isolate(), 1); | 2054 CEntryStub ces(isolate(), 1); |
2225 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); | 2055 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
2226 } | 2056 } |
2227 | 2057 |
2228 | 2058 |
2229 void MacroAssembler::InvokePrologue(const ParameterCount& expected, | 2059 void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
2230 const ParameterCount& actual, | 2060 const ParameterCount& actual, |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3372 if (mag.shift > 0) sar(edx, mag.shift); | 3202 if (mag.shift > 0) sar(edx, mag.shift); |
3373 mov(eax, dividend); | 3203 mov(eax, dividend); |
3374 shr(eax, 31); | 3204 shr(eax, 31); |
3375 add(edx, eax); | 3205 add(edx, eax); |
3376 } | 3206 } |
3377 | 3207 |
3378 | 3208 |
3379 } } // namespace v8::internal | 3209 } } // namespace v8::internal |
3380 | 3210 |
3381 #endif // V8_TARGET_ARCH_X87 | 3211 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |