Chromium Code Reviews| Index: src/arm/simulator-arm.cc |
| =================================================================== |
| --- src/arm/simulator-arm.cc (revision 6213) |
| +++ src/arm/simulator-arm.cc (working copy) |
| @@ -48,6 +48,7 @@ |
| using ::v8::internal::OS; |
| using ::v8::internal::ReadLine; |
| using ::v8::internal::DeleteArray; |
| +using ::v8::internal::ExternalReference; |
| // This macro provides a platform independent use of sscanf. The reason for |
| // SScanF not being implemented in a platform independent way through |
| @@ -745,10 +746,12 @@ |
| // offset from the svc instruction so the simulator knows what to call. |
| class Redirection { |
| public: |
| - Redirection(void* external_function, bool fp_return) |
| + Redirection(void* external_function, bool fp_return, |
| + ExternalReference::Type type) |
| : external_function_(external_function), |
| swi_instruction_((AL << 28) | (0xf << 24) | call_rt_redirected), |
| fp_return_(fp_return), |
| + type_(type), |
| next_(list_) { |
| Simulator::current()-> |
| FlushICache(reinterpret_cast<void*>(&swi_instruction_), |
| @@ -762,13 +765,15 @@ |
| void* external_function() { return external_function_; } |
| bool fp_return() { return fp_return_; } |
| + ExternalReference::Type type() { return type_; } |
| - static Redirection* Get(void* external_function, bool fp_return) { |
| + static Redirection* Get(void* external_function, bool fp_return, |
| + ExternalReference::Type type) { |
| Redirection* current; |
| for (current = list_; current != NULL; current = current->next_) { |
| if (current->external_function_ == external_function) return current; |
| } |
| - return new Redirection(external_function, fp_return); |
| + return new Redirection(external_function, fp_return, type); |
| } |
| static Redirection* FromSwiInstruction(Instr* swi_instruction) { |
| @@ -782,6 +787,7 @@ |
| void* external_function_; |
| uint32_t swi_instruction_; |
| bool fp_return_; |
| + ExternalReference::Type type_; |
| Redirection* next_; |
| static Redirection* list_; |
| }; |
| @@ -790,9 +796,10 @@ |
| Redirection* Redirection::list_ = NULL; |
| -void* Simulator::RedirectExternalReference(void* external_function, |
| - bool fp_return) { |
| - Redirection* redirection = Redirection::Get(external_function, fp_return); |
| +void* Simulator::RedirectExternalReference( |
| + void* external_function, bool fp_return, ExternalReference::Type type) { |
| + Redirection* redirection = Redirection::Get( |
| + external_function, fp_return, type); |
| return redirection->address_of_swi_instruction(); |
| } |
| @@ -1533,6 +1540,9 @@ |
| int32_t arg2, |
| int32_t arg3); |
| +// This signature supports direct call in to js function native callback |
| +// (refer to InvocationCallback in v8.h). |
| +typedef v8::Handle<v8::Value> (*SimulatorRuntimeApiCall)(int32_t arg0); |
| // Software interrupt instructions are used by the simulator to call into the |
| // C-based V8 runtime. |
| @@ -1574,33 +1584,56 @@ |
| double result = target(arg0, arg1, arg2, arg3); |
| SetFpResult(result); |
| } else { |
| - intptr_t external = |
| - reinterpret_cast<int32_t>(redirection->external_function()); |
| - SimulatorRuntimeCall target = |
| - reinterpret_cast<SimulatorRuntimeCall>(external); |
| - if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| - PrintF( |
| - "Call to host function at %p args %08x, %08x, %08x, %08x, %0xc", |
| - FUNCTION_ADDR(target), |
| - arg0, |
| - arg1, |
| - arg2, |
| - arg3, |
| - arg4); |
| - if (!stack_aligned) { |
| - PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| + if (redirection->type() == ExternalReference::DIRECT_CALL) { |
| + intptr_t external = |
| + reinterpret_cast<int32_t>(redirection->external_function()); |
| + SimulatorRuntimeApiCall target = |
|
SeRya
2011/01/21 09:52:36
May be to add ASSERT that where is indeed one argu
Zaheer
2011/01/21 11:51:50
simulator also uses stack space for the arguments
|
| + reinterpret_cast<SimulatorRuntimeApiCall>(external); |
| + if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| + PrintF( |
| + "Call to host function at %p args %08x", |
| + FUNCTION_ADDR(target), |
| + arg0); |
| + if (!stack_aligned) { |
| + PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| + } |
| + PrintF("\n"); |
| } |
| - PrintF("\n"); |
| + CHECK(stack_aligned); |
| + v8::Handle<v8::Value> result = target(arg0); |
| + if (::v8::internal::FLAG_trace_sim) { |
| + PrintF("Returned %p\n", reinterpret_cast<void *>(*result)); |
| + } |
| + set_register(r0, (int32_t) *result); |
| + } else { |
| + intptr_t external = |
| + reinterpret_cast<int32_t>(redirection->external_function()); |
| + SimulatorRuntimeCall target = |
| + reinterpret_cast<SimulatorRuntimeCall>(external); |
| + if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| + PrintF( |
| + "Call to host function at %p args %08x, %08x, %08x, %08x, %0xc", |
| + FUNCTION_ADDR(target), |
| + arg0, |
| + arg1, |
| + arg2, |
| + arg3, |
| + arg4); |
| + if (!stack_aligned) { |
| + PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| + } |
| + PrintF("\n"); |
| + } |
| + CHECK(stack_aligned); |
| + int64_t result = target(arg0, arg1, arg2, arg3, arg4); |
| + int32_t lo_res = static_cast<int32_t>(result); |
| + int32_t hi_res = static_cast<int32_t>(result >> 32); |
| + if (::v8::internal::FLAG_trace_sim) { |
| + PrintF("Returned %08x\n", lo_res); |
| + } |
| + set_register(r0, lo_res); |
| + set_register(r1, hi_res); |
| } |
| - CHECK(stack_aligned); |
| - int64_t result = target(arg0, arg1, arg2, arg3, arg4); |
| - int32_t lo_res = static_cast<int32_t>(result); |
| - int32_t hi_res = static_cast<int32_t>(result >> 32); |
| - if (::v8::internal::FLAG_trace_sim) { |
| - PrintF("Returned %08x\n", lo_res); |
| - } |
| - set_register(r0, lo_res); |
| - set_register(r1, hi_res); |
| } |
| set_register(lr, saved_lr); |
| set_pc(get_register(lr)); |