Index: src/arm/simulator-arm.cc |
=================================================================== |
--- src/arm/simulator-arm.cc (revision 4519) |
+++ src/arm/simulator-arm.cc (working copy) |
@@ -866,16 +866,26 @@ |
registers_[12] = 0x50Bad4U; |
} |
- |
-// The ARM cannot do unaligned reads and writes. On some ARM platforms an |
-// interrupt is caused. On others it does a funky rotation thing. For now we |
+// Some Operating Systems allow unaligned access on ARMv7 targets. We |
+// assume that unaligned accesses are not allowed unless the v8 build system |
+// defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero. |
+// The following statements below describes the behavior of the ARM CPUs |
+// that don't support unaligned access. |
+// Some ARM platforms raises an interrupt on detecting unaligned access. |
+// On others it does a funky rotation thing. For now we |
// simply disallow unaligned reads, but at some point we may want to move to |
// emulating the rotate behaviour. Note that simulator runs have the runtime |
// system running directly on the host system and only generated code is |
// executed in the simulator. Since the host is typically IA32 we will not |
-// get the correct ARM-like behaviour on unaligned accesses. |
+// get the correct ARM-like behaviour on unaligned accesses for those ARM |
+// targets that don't support unaligned loads and stores. |
+ |
int Simulator::ReadW(int32_t addr, Instr* instr) { |
+#if V8_TARGET_CAN_READ_UNALIGNED |
+ intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
+ return *ptr; |
+#else |
if ((addr & 3) == 0) { |
intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
return *ptr; |
@@ -883,10 +893,16 @@ |
PrintF("Unaligned read at 0x%08x\n", addr); |
UNIMPLEMENTED(); |
return 0; |
+#endif |
} |
void Simulator::WriteW(int32_t addr, int value, Instr* instr) { |
+#if V8_TARGET_CAN_READ_UNALIGNED |
+ intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
+ *ptr = value; |
+ return; |
+#else |
if ((addr & 3) == 0) { |
intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
*ptr = value; |
@@ -894,10 +910,15 @@ |
} |
PrintF("Unaligned write at 0x%08x, pc=%p\n", addr, instr); |
UNIMPLEMENTED(); |
+#endif |
} |
uint16_t Simulator::ReadHU(int32_t addr, Instr* instr) { |
+#if V8_TARGET_CAN_READ_UNALIGNED |
+ uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
+ return *ptr; |
+#else |
if ((addr & 1) == 0) { |
uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
return *ptr; |
@@ -905,10 +926,15 @@ |
PrintF("Unaligned unsigned halfword read at 0x%08x, pc=%p\n", addr, instr); |
UNIMPLEMENTED(); |
return 0; |
+#endif |
} |
int16_t Simulator::ReadH(int32_t addr, Instr* instr) { |
+#if V8_TARGET_CAN_READ_UNALIGNED |
+ int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
+ return *ptr; |
+#else |
if ((addr & 1) == 0) { |
int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
return *ptr; |
@@ -916,10 +942,16 @@ |
PrintF("Unaligned signed halfword read at 0x%08x\n", addr); |
UNIMPLEMENTED(); |
return 0; |
+#endif |
} |
void Simulator::WriteH(int32_t addr, uint16_t value, Instr* instr) { |
+#if V8_TARGET_CAN_READ_UNALIGNED |
+ uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
+ *ptr = value; |
+ return; |
+#else |
if ((addr & 1) == 0) { |
uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
*ptr = value; |
@@ -927,10 +959,16 @@ |
} |
PrintF("Unaligned unsigned halfword write at 0x%08x, pc=%p\n", addr, instr); |
UNIMPLEMENTED(); |
+#endif |
} |
void Simulator::WriteH(int32_t addr, int16_t value, Instr* instr) { |
+#if V8_TARGET_CAN_READ_UNALIGNED |
+ int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
+ *ptr = value; |
+ return; |
+#else |
if ((addr & 1) == 0) { |
int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
*ptr = value; |
@@ -938,6 +976,7 @@ |
} |
PrintF("Unaligned halfword write at 0x%08x, pc=%p\n", addr, instr); |
UNIMPLEMENTED(); |
+#endif |
} |