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) { |
Erik Corry
2011/01/21 14:28:40
You shouldn't need both the bool for the fp_return
Zaheer
2011/01/24 09:43:31
Done.
|
+ 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 |
antonm
2011/01/21 17:56:36
I'd use API function instead of js function here
Zaheer
2011/01/24 09:43:31
Done.
|
+// (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 = |
antonm
2011/01/21 17:56:36
please, consider refactoring the common logic of l
Zaheer
2011/01/24 09:43:31
The log is unique to each case, the stack alignmen
antonm
2011/01/26 11:36:37
Ok, let's leave it as you have it now.
|
+ 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)); |