Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include <stdarg.h> |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | #include <stdlib.h> |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include <cmath> |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/v8.h" |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 10 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #if V8_TARGET_ARCH_ARM |
| 12 | |
| 13 | #include "src/arm/constants-arm.h" |
| 14 | #include "src/arm/simulator-arm.h" |
| 15 | #include "src/assembler.h" |
| 16 | #include "src/codegen.h" |
| 17 | #include "src/disasm.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 18 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 19 | #if defined(USE_SIMULATOR) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 20 | |
| 21 | // Only build the simulator if not compiling for real ARM hardware. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 22 | namespace v8 { |
| 23 | namespace internal { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 24 | |
| 25 | // This macro provides a platform independent use of sscanf. The reason for |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 26 | // SScanF not being implemented in a platform independent way through |
| 27 | // ::v8::internal::OS in the same way as SNPrintF is that the |
| 28 | // Windows C Run-Time Library does not provide vsscanf. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | #define SScanF sscanf // NOLINT |
| 30 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 31 | // The ArmDebugger class is used by the simulator while debugging simulated ARM |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | // code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 33 | class ArmDebugger { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | public: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 35 | explicit ArmDebugger(Simulator* sim) : sim_(sim) { } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 36 | ~ArmDebugger(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 38 | void Stop(Instruction* instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | void Debug(); |
| 40 | |
| 41 | private: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 42 | static const Instr kBreakpointInstr = |
| 43 | (al | (7*B25) | (1*B24) | kBreakpoint); |
| 44 | static const Instr kNopInstr = (al | (13*B21)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 45 | |
| 46 | Simulator* sim_; |
| 47 | |
| 48 | int32_t GetRegisterValue(int regnum); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 49 | double GetRegisterPairDoubleValue(int regnum); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 50 | double GetVFPDoubleRegisterValue(int regnum); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 51 | bool GetValue(const char* desc, int32_t* value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 52 | bool GetVFPSingleValue(const char* desc, float* value); |
| 53 | bool GetVFPDoubleValue(const char* desc, double* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | |
| 55 | // Set or delete a breakpoint. Returns true if successful. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 56 | bool SetBreakpoint(Instruction* breakpc); |
| 57 | bool DeleteBreakpoint(Instruction* breakpc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | |
| 59 | // Undo and redo all breakpoints. This is needed to bracket disassembly and |
| 60 | // execution to skip past breakpoints when run from the debugger. |
| 61 | void UndoBreakpoints(); |
| 62 | void RedoBreakpoints(); |
| 63 | }; |
| 64 | |
| 65 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 66 | ArmDebugger::~ArmDebugger() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | |
| 71 | #ifdef GENERATED_CODE_COVERAGE |
| 72 | static FILE* coverage_log = NULL; |
| 73 | |
| 74 | |
| 75 | static void InitializeCoverage() { |
| 76 | char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); |
| 77 | if (file_name != NULL) { |
| 78 | coverage_log = fopen(file_name, "aw+"); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 83 | void ArmDebugger::Stop(Instruction* instr) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 84 | // Get the stop code. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 85 | uint32_t code = instr->SvcValue() & kStopCodeMask; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 86 | // Retrieve the encoded address, which comes just after this stop. |
| 87 | char** msg_address = |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 88 | reinterpret_cast<char**>(sim_->get_pc() + Instruction::kInstrSize); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 89 | char* msg = *msg_address; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | DCHECK(msg != NULL); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 91 | |
| 92 | // Update this stop description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 93 | if (isWatchedStop(code) && !watched_stops_[code].desc) { |
| 94 | watched_stops_[code].desc = msg; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | if (strlen(msg) > 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | if (coverage_log != NULL) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 99 | fprintf(coverage_log, "%s\n", msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 100 | fflush(coverage_log); |
| 101 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 102 | // Overwrite the instruction and address with nops. |
| 103 | instr->SetInstructionBits(kNopInstr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 104 | reinterpret_cast<Instruction*>(msg_address)->SetInstructionBits(kNopInstr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 106 | sim_->set_pc(sim_->get_pc() + 2 * Instruction::kInstrSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | #else // ndef GENERATED_CODE_COVERAGE |
| 110 | |
| 111 | static void InitializeCoverage() { |
| 112 | } |
| 113 | |
| 114 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 115 | void ArmDebugger::Stop(Instruction* instr) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 116 | // Get the stop code. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 117 | uint32_t code = instr->SvcValue() & kStopCodeMask; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 118 | // Retrieve the encoded address, which comes just after this stop. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 119 | char* msg = *reinterpret_cast<char**>(sim_->get_pc() |
| 120 | + Instruction::kInstrSize); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 121 | // Update this stop description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 122 | if (sim_->isWatchedStop(code) && !sim_->watched_stops_[code].desc) { |
| 123 | sim_->watched_stops_[code].desc = msg; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 124 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 125 | // Print the stop message and code if it is not the default code. |
| 126 | if (code != kMaxStopCode) { |
| 127 | PrintF("Simulator hit stop %u: %s\n", code, msg); |
| 128 | } else { |
| 129 | PrintF("Simulator hit %s\n", msg); |
| 130 | } |
| 131 | sim_->set_pc(sim_->get_pc() + 2 * Instruction::kInstrSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 132 | Debug(); |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 137 | int32_t ArmDebugger::GetRegisterValue(int regnum) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | if (regnum == kPCRegister) { |
| 139 | return sim_->get_pc(); |
| 140 | } else { |
| 141 | return sim_->get_register(regnum); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 146 | double ArmDebugger::GetRegisterPairDoubleValue(int regnum) { |
| 147 | return sim_->get_double_from_register_pair(regnum); |
| 148 | } |
| 149 | |
| 150 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 151 | double ArmDebugger::GetVFPDoubleRegisterValue(int regnum) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 152 | return sim_->get_double_from_d_register(regnum); |
| 153 | } |
| 154 | |
| 155 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 156 | bool ArmDebugger::GetValue(const char* desc, int32_t* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 157 | int regnum = Registers::Number(desc); |
| 158 | if (regnum != kNoRegister) { |
| 159 | *value = GetRegisterValue(regnum); |
| 160 | return true; |
| 161 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 162 | if (strncmp(desc, "0x", 2) == 0) { |
| 163 | return SScanF(desc + 2, "%x", reinterpret_cast<uint32_t*>(value)) == 1; |
| 164 | } else { |
| 165 | return SScanF(desc, "%u", reinterpret_cast<uint32_t*>(value)) == 1; |
| 166 | } |
| 167 | } |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 172 | bool ArmDebugger::GetVFPSingleValue(const char* desc, float* value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 173 | bool is_double; |
| 174 | int regnum = VFPRegisters::Number(desc, &is_double); |
| 175 | if (regnum != kNoRegister && !is_double) { |
| 176 | *value = sim_->get_float_from_s_register(regnum); |
| 177 | return true; |
| 178 | } |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 183 | bool ArmDebugger::GetVFPDoubleValue(const char* desc, double* value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 184 | bool is_double; |
| 185 | int regnum = VFPRegisters::Number(desc, &is_double); |
| 186 | if (regnum != kNoRegister && is_double) { |
| 187 | *value = sim_->get_double_from_d_register(regnum); |
| 188 | return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 189 | } |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 194 | bool ArmDebugger::SetBreakpoint(Instruction* breakpc) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 195 | // Check if a breakpoint can be set. If not return without any side-effects. |
| 196 | if (sim_->break_pc_ != NULL) { |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | // Set the breakpoint. |
| 201 | sim_->break_pc_ = breakpc; |
| 202 | sim_->break_instr_ = breakpc->InstructionBits(); |
| 203 | // Not setting the breakpoint instruction in the code itself. It will be set |
| 204 | // when the debugger shell continues. |
| 205 | return true; |
| 206 | } |
| 207 | |
| 208 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 209 | bool ArmDebugger::DeleteBreakpoint(Instruction* breakpc) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 210 | if (sim_->break_pc_ != NULL) { |
| 211 | sim_->break_pc_->SetInstructionBits(sim_->break_instr_); |
| 212 | } |
| 213 | |
| 214 | sim_->break_pc_ = NULL; |
| 215 | sim_->break_instr_ = 0; |
| 216 | return true; |
| 217 | } |
| 218 | |
| 219 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 220 | void ArmDebugger::UndoBreakpoints() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 221 | if (sim_->break_pc_ != NULL) { |
| 222 | sim_->break_pc_->SetInstructionBits(sim_->break_instr_); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 227 | void ArmDebugger::RedoBreakpoints() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 228 | if (sim_->break_pc_ != NULL) { |
| 229 | sim_->break_pc_->SetInstructionBits(kBreakpointInstr); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 234 | void ArmDebugger::Debug() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 235 | intptr_t last_pc = -1; |
| 236 | bool done = false; |
| 237 | |
| 238 | #define COMMAND_SIZE 63 |
| 239 | #define ARG_SIZE 255 |
| 240 | |
| 241 | #define STR(a) #a |
| 242 | #define XSTR(a) STR(a) |
| 243 | |
| 244 | char cmd[COMMAND_SIZE + 1]; |
| 245 | char arg1[ARG_SIZE + 1]; |
| 246 | char arg2[ARG_SIZE + 1]; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 247 | char* argv[3] = { cmd, arg1, arg2 }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | |
| 249 | // make sure to have a proper terminating character if reaching the limit |
| 250 | cmd[COMMAND_SIZE] = 0; |
| 251 | arg1[ARG_SIZE] = 0; |
| 252 | arg2[ARG_SIZE] = 0; |
| 253 | |
| 254 | // Undo all set breakpoints while running in the debugger shell. This will |
| 255 | // make them invisible to all commands. |
| 256 | UndoBreakpoints(); |
| 257 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 258 | while (!done && !sim_->has_bad_pc()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 259 | if (last_pc != sim_->get_pc()) { |
| 260 | disasm::NameConverter converter; |
| 261 | disasm::Disassembler dasm(converter); |
| 262 | // use a reasonably large buffer |
| 263 | v8::internal::EmbeddedVector<char, 256> buffer; |
| 264 | dasm.InstructionDecode(buffer, |
| 265 | reinterpret_cast<byte*>(sim_->get_pc())); |
| 266 | PrintF(" 0x%08x %s\n", sim_->get_pc(), buffer.start()); |
| 267 | last_pc = sim_->get_pc(); |
| 268 | } |
| 269 | char* line = ReadLine("sim> "); |
| 270 | if (line == NULL) { |
| 271 | break; |
| 272 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 273 | char* last_input = sim_->last_debugger_input(); |
| 274 | if (strcmp(line, "\n") == 0 && last_input != NULL) { |
| 275 | line = last_input; |
| 276 | } else { |
| 277 | // Ownership is transferred to sim_; |
| 278 | sim_->set_last_debugger_input(line); |
| 279 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 280 | // Use sscanf to parse the individual parts of the command line. At the |
| 281 | // moment no command expects more than two parameters. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 282 | int argc = SScanF(line, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 283 | "%" XSTR(COMMAND_SIZE) "s " |
| 284 | "%" XSTR(ARG_SIZE) "s " |
| 285 | "%" XSTR(ARG_SIZE) "s", |
| 286 | cmd, arg1, arg2); |
| 287 | if ((strcmp(cmd, "si") == 0) || (strcmp(cmd, "stepi") == 0)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 288 | sim_->InstructionDecode(reinterpret_cast<Instruction*>(sim_->get_pc())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 289 | } else if ((strcmp(cmd, "c") == 0) || (strcmp(cmd, "cont") == 0)) { |
| 290 | // Execute the one instruction we broke at with breakpoints disabled. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 291 | sim_->InstructionDecode(reinterpret_cast<Instruction*>(sim_->get_pc())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 292 | // Leave the debugger shell. |
| 293 | done = true; |
| 294 | } else if ((strcmp(cmd, "p") == 0) || (strcmp(cmd, "print") == 0)) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 295 | if (argc == 2 || (argc == 3 && strcmp(arg2, "fp") == 0)) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 296 | int32_t value; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 297 | float svalue; |
| 298 | double dvalue; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | if (strcmp(arg1, "all") == 0) { |
| 300 | for (int i = 0; i < kNumRegisters; i++) { |
| 301 | value = GetRegisterValue(i); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 302 | PrintF("%3s: 0x%08x %10d", Registers::Name(i), value, value); |
| 303 | if ((argc == 3 && strcmp(arg2, "fp") == 0) && |
| 304 | i < 8 && |
| 305 | (i % 2) == 0) { |
| 306 | dvalue = GetRegisterPairDoubleValue(i); |
| 307 | PrintF(" (%f)\n", dvalue); |
| 308 | } else { |
| 309 | PrintF("\n"); |
| 310 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 312 | for (int i = 0; i < DwVfpRegister::NumRegisters(); i++) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 313 | dvalue = GetVFPDoubleRegisterValue(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 314 | uint64_t as_words = bit_cast<uint64_t>(dvalue); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 315 | PrintF("%3s: %f 0x%08x %08x\n", |
| 316 | VFPRegisters::Name(i, true), |
| 317 | dvalue, |
| 318 | static_cast<uint32_t>(as_words >> 32), |
| 319 | static_cast<uint32_t>(as_words & 0xffffffff)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 320 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 321 | } else { |
| 322 | if (GetValue(arg1, &value)) { |
| 323 | PrintF("%s: 0x%08x %d \n", arg1, value, value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 324 | } else if (GetVFPSingleValue(arg1, &svalue)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 325 | uint32_t as_word = bit_cast<uint32_t>(svalue); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 326 | PrintF("%s: %f 0x%08x\n", arg1, svalue, as_word); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 327 | } else if (GetVFPDoubleValue(arg1, &dvalue)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 328 | uint64_t as_words = bit_cast<uint64_t>(dvalue); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 329 | PrintF("%s: %f 0x%08x %08x\n", |
| 330 | arg1, |
| 331 | dvalue, |
| 332 | static_cast<uint32_t>(as_words >> 32), |
| 333 | static_cast<uint32_t>(as_words & 0xffffffff)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 334 | } else { |
| 335 | PrintF("%s unrecognized\n", arg1); |
| 336 | } |
| 337 | } |
| 338 | } else { |
| 339 | PrintF("print <register>\n"); |
| 340 | } |
| 341 | } else if ((strcmp(cmd, "po") == 0) |
| 342 | || (strcmp(cmd, "printobject") == 0)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 343 | if (argc == 2) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | int32_t value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 345 | OFStream os(stdout); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 346 | if (GetValue(arg1, &value)) { |
| 347 | Object* obj = reinterpret_cast<Object*>(value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 348 | os << arg1 << ": \n"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 349 | #ifdef DEBUG |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 350 | obj->Print(os); |
| 351 | os << "\n"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 352 | #else |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 353 | os << Brief(obj) << "\n"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | #endif |
| 355 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 356 | os << arg1 << " unrecognized\n"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 357 | } |
| 358 | } else { |
| 359 | PrintF("printobject <value>\n"); |
| 360 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 361 | } else if (strcmp(cmd, "stack") == 0 || strcmp(cmd, "mem") == 0) { |
| 362 | int32_t* cur = NULL; |
| 363 | int32_t* end = NULL; |
| 364 | int next_arg = 1; |
| 365 | |
| 366 | if (strcmp(cmd, "stack") == 0) { |
| 367 | cur = reinterpret_cast<int32_t*>(sim_->get_register(Simulator::sp)); |
| 368 | } else { // "mem" |
| 369 | int32_t value; |
| 370 | if (!GetValue(arg1, &value)) { |
| 371 | PrintF("%s unrecognized\n", arg1); |
| 372 | continue; |
| 373 | } |
| 374 | cur = reinterpret_cast<int32_t*>(value); |
| 375 | next_arg++; |
| 376 | } |
| 377 | |
| 378 | int32_t words; |
| 379 | if (argc == next_arg) { |
| 380 | words = 10; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 381 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 382 | if (!GetValue(argv[next_arg], &words)) { |
| 383 | words = 10; |
| 384 | } |
| 385 | } |
| 386 | end = cur + words; |
| 387 | |
| 388 | while (cur < end) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 389 | PrintF(" 0x%08x: 0x%08x %10d", |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 390 | reinterpret_cast<intptr_t>(cur), *cur, *cur); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 391 | HeapObject* obj = reinterpret_cast<HeapObject*>(*cur); |
| 392 | int value = *cur; |
| 393 | Heap* current_heap = v8::internal::Isolate::Current()->heap(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | if (((value & 1) == 0) || current_heap->Contains(obj)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 395 | PrintF(" ("); |
| 396 | if ((value & 1) == 0) { |
| 397 | PrintF("smi %d", value / 2); |
| 398 | } else { |
| 399 | obj->ShortPrint(); |
| 400 | } |
| 401 | PrintF(")"); |
| 402 | } |
| 403 | PrintF("\n"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 404 | cur++; |
| 405 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 406 | } else if (strcmp(cmd, "disasm") == 0 || strcmp(cmd, "di") == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 407 | disasm::NameConverter converter; |
| 408 | disasm::Disassembler dasm(converter); |
| 409 | // use a reasonably large buffer |
| 410 | v8::internal::EmbeddedVector<char, 256> buffer; |
| 411 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 412 | byte* prev = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | byte* cur = NULL; |
| 414 | byte* end = NULL; |
| 415 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 416 | if (argc == 1) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 417 | cur = reinterpret_cast<byte*>(sim_->get_pc()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 418 | end = cur + (10 * Instruction::kInstrSize); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 419 | } else if (argc == 2) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 420 | int regnum = Registers::Number(arg1); |
| 421 | if (regnum != kNoRegister || strncmp(arg1, "0x", 2) == 0) { |
| 422 | // The argument is an address or a register name. |
| 423 | int32_t value; |
| 424 | if (GetValue(arg1, &value)) { |
| 425 | cur = reinterpret_cast<byte*>(value); |
| 426 | // Disassemble 10 instructions at <arg1>. |
| 427 | end = cur + (10 * Instruction::kInstrSize); |
| 428 | } |
| 429 | } else { |
| 430 | // The argument is the number of instructions. |
| 431 | int32_t value; |
| 432 | if (GetValue(arg1, &value)) { |
| 433 | cur = reinterpret_cast<byte*>(sim_->get_pc()); |
| 434 | // Disassemble <arg1> instructions. |
| 435 | end = cur + (value * Instruction::kInstrSize); |
| 436 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | } |
| 438 | } else { |
| 439 | int32_t value1; |
| 440 | int32_t value2; |
| 441 | if (GetValue(arg1, &value1) && GetValue(arg2, &value2)) { |
| 442 | cur = reinterpret_cast<byte*>(value1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 443 | end = cur + (value2 * Instruction::kInstrSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | while (cur < end) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 448 | prev = cur; |
| 449 | cur += dasm.InstructionDecode(buffer, cur); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 450 | PrintF(" 0x%08x %s\n", |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 451 | reinterpret_cast<intptr_t>(prev), buffer.start()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 452 | } |
| 453 | } else if (strcmp(cmd, "gdb") == 0) { |
| 454 | PrintF("relinquishing control to gdb\n"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 455 | v8::base::OS::DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 456 | PrintF("regaining control from gdb\n"); |
| 457 | } else if (strcmp(cmd, "break") == 0) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 458 | if (argc == 2) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | int32_t value; |
| 460 | if (GetValue(arg1, &value)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 461 | if (!SetBreakpoint(reinterpret_cast<Instruction*>(value))) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | PrintF("setting breakpoint failed\n"); |
| 463 | } |
| 464 | } else { |
| 465 | PrintF("%s unrecognized\n", arg1); |
| 466 | } |
| 467 | } else { |
| 468 | PrintF("break <address>\n"); |
| 469 | } |
| 470 | } else if (strcmp(cmd, "del") == 0) { |
| 471 | if (!DeleteBreakpoint(NULL)) { |
| 472 | PrintF("deleting breakpoint failed\n"); |
| 473 | } |
| 474 | } else if (strcmp(cmd, "flags") == 0) { |
| 475 | PrintF("N flag: %d; ", sim_->n_flag_); |
| 476 | PrintF("Z flag: %d; ", sim_->z_flag_); |
| 477 | PrintF("C flag: %d; ", sim_->c_flag_); |
| 478 | PrintF("V flag: %d\n", sim_->v_flag_); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 479 | PrintF("INVALID OP flag: %d; ", sim_->inv_op_vfp_flag_); |
| 480 | PrintF("DIV BY ZERO flag: %d; ", sim_->div_zero_vfp_flag_); |
| 481 | PrintF("OVERFLOW flag: %d; ", sim_->overflow_vfp_flag_); |
| 482 | PrintF("UNDERFLOW flag: %d; ", sim_->underflow_vfp_flag_); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 483 | PrintF("INEXACT flag: %d;\n", sim_->inexact_vfp_flag_); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 484 | } else if (strcmp(cmd, "stop") == 0) { |
| 485 | int32_t value; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 486 | intptr_t stop_pc = sim_->get_pc() - 2 * Instruction::kInstrSize; |
| 487 | Instruction* stop_instr = reinterpret_cast<Instruction*>(stop_pc); |
| 488 | Instruction* msg_address = |
| 489 | reinterpret_cast<Instruction*>(stop_pc + Instruction::kInstrSize); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 490 | if ((argc == 2) && (strcmp(arg1, "unstop") == 0)) { |
| 491 | // Remove the current stop. |
| 492 | if (sim_->isStopInstruction(stop_instr)) { |
| 493 | stop_instr->SetInstructionBits(kNopInstr); |
| 494 | msg_address->SetInstructionBits(kNopInstr); |
| 495 | } else { |
| 496 | PrintF("Not at debugger stop.\n"); |
| 497 | } |
| 498 | } else if (argc == 3) { |
| 499 | // Print information about all/the specified breakpoint(s). |
| 500 | if (strcmp(arg1, "info") == 0) { |
| 501 | if (strcmp(arg2, "all") == 0) { |
| 502 | PrintF("Stop information:\n"); |
| 503 | for (uint32_t i = 0; i < sim_->kNumOfWatchedStops; i++) { |
| 504 | sim_->PrintStopInfo(i); |
| 505 | } |
| 506 | } else if (GetValue(arg2, &value)) { |
| 507 | sim_->PrintStopInfo(value); |
| 508 | } else { |
| 509 | PrintF("Unrecognized argument.\n"); |
| 510 | } |
| 511 | } else if (strcmp(arg1, "enable") == 0) { |
| 512 | // Enable all/the specified breakpoint(s). |
| 513 | if (strcmp(arg2, "all") == 0) { |
| 514 | for (uint32_t i = 0; i < sim_->kNumOfWatchedStops; i++) { |
| 515 | sim_->EnableStop(i); |
| 516 | } |
| 517 | } else if (GetValue(arg2, &value)) { |
| 518 | sim_->EnableStop(value); |
| 519 | } else { |
| 520 | PrintF("Unrecognized argument.\n"); |
| 521 | } |
| 522 | } else if (strcmp(arg1, "disable") == 0) { |
| 523 | // Disable all/the specified breakpoint(s). |
| 524 | if (strcmp(arg2, "all") == 0) { |
| 525 | for (uint32_t i = 0; i < sim_->kNumOfWatchedStops; i++) { |
| 526 | sim_->DisableStop(i); |
| 527 | } |
| 528 | } else if (GetValue(arg2, &value)) { |
| 529 | sim_->DisableStop(value); |
| 530 | } else { |
| 531 | PrintF("Unrecognized argument.\n"); |
| 532 | } |
| 533 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 534 | } else { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 535 | PrintF("Wrong usage. Use help command for more information.\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 536 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 537 | } else if ((strcmp(cmd, "t") == 0) || strcmp(cmd, "trace") == 0) { |
| 538 | ::v8::internal::FLAG_trace_sim = !::v8::internal::FLAG_trace_sim; |
| 539 | PrintF("Trace of executed instructions is %s\n", |
| 540 | ::v8::internal::FLAG_trace_sim ? "on" : "off"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 541 | } else if ((strcmp(cmd, "h") == 0) || (strcmp(cmd, "help") == 0)) { |
| 542 | PrintF("cont\n"); |
| 543 | PrintF(" continue execution (alias 'c')\n"); |
| 544 | PrintF("stepi\n"); |
| 545 | PrintF(" step one instruction (alias 'si')\n"); |
| 546 | PrintF("print <register>\n"); |
| 547 | PrintF(" print register content (alias 'p')\n"); |
| 548 | PrintF(" use register name 'all' to print all registers\n"); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 549 | PrintF(" add argument 'fp' to print register pair double values\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | PrintF("printobject <register>\n"); |
| 551 | PrintF(" print an object from a register (alias 'po')\n"); |
| 552 | PrintF("flags\n"); |
| 553 | PrintF(" print flags\n"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 554 | PrintF("stack [<words>]\n"); |
| 555 | PrintF(" dump stack content, default dump 10 words)\n"); |
| 556 | PrintF("mem <address> [<words>]\n"); |
| 557 | PrintF(" dump memory content, default dump 10 words)\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | PrintF("disasm [<instructions>]\n"); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 559 | PrintF("disasm [<address/register>]\n"); |
| 560 | PrintF("disasm [[<address/register>] <instructions>]\n"); |
| 561 | PrintF(" disassemble code, default is 10 instructions\n"); |
| 562 | PrintF(" from pc (alias 'di')\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 563 | PrintF("gdb\n"); |
| 564 | PrintF(" enter gdb\n"); |
| 565 | PrintF("break <address>\n"); |
| 566 | PrintF(" set a break point on the address\n"); |
| 567 | PrintF("del\n"); |
| 568 | PrintF(" delete the breakpoint\n"); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 569 | PrintF("trace (alias 't')\n"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 570 | PrintF(" toogle the tracing of all executed statements\n"); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 571 | PrintF("stop feature:\n"); |
| 572 | PrintF(" Description:\n"); |
| 573 | PrintF(" Stops are debug instructions inserted by\n"); |
| 574 | PrintF(" the Assembler::stop() function.\n"); |
| 575 | PrintF(" When hitting a stop, the Simulator will\n"); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 576 | PrintF(" stop and and give control to the ArmDebugger.\n"); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 577 | PrintF(" The first %d stop codes are watched:\n", |
| 578 | Simulator::kNumOfWatchedStops); |
| 579 | PrintF(" - They can be enabled / disabled: the Simulator\n"); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 580 | PrintF(" will / won't stop when hitting them.\n"); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 581 | PrintF(" - The Simulator keeps track of how many times they \n"); |
| 582 | PrintF(" are met. (See the info command.) Going over a\n"); |
| 583 | PrintF(" disabled stop still increases its counter. \n"); |
| 584 | PrintF(" Commands:\n"); |
| 585 | PrintF(" stop info all/<code> : print infos about number <code>\n"); |
| 586 | PrintF(" or all stop(s).\n"); |
| 587 | PrintF(" stop enable/disable all/<code> : enables / disables\n"); |
| 588 | PrintF(" all or number <code> stop(s)\n"); |
| 589 | PrintF(" stop unstop\n"); |
| 590 | PrintF(" ignore the stop instruction at the current location\n"); |
| 591 | PrintF(" from now on\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 592 | } else { |
| 593 | PrintF("Unknown command: %s\n", cmd); |
| 594 | } |
| 595 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | // Add all the breakpoints back to stop execution and enter the debugger |
| 599 | // shell when hit. |
| 600 | RedoBreakpoints(); |
| 601 | |
| 602 | #undef COMMAND_SIZE |
| 603 | #undef ARG_SIZE |
| 604 | |
| 605 | #undef STR |
| 606 | #undef XSTR |
| 607 | } |
| 608 | |
| 609 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 610 | static bool ICacheMatch(void* one, void* two) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 611 | DCHECK((reinterpret_cast<intptr_t>(one) & CachePage::kPageMask) == 0); |
| 612 | DCHECK((reinterpret_cast<intptr_t>(two) & CachePage::kPageMask) == 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 613 | return one == two; |
| 614 | } |
| 615 | |
| 616 | |
| 617 | static uint32_t ICacheHash(void* key) { |
| 618 | return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key)) >> 2; |
| 619 | } |
| 620 | |
| 621 | |
| 622 | static bool AllOnOnePage(uintptr_t start, int size) { |
| 623 | intptr_t start_page = (start & ~CachePage::kPageMask); |
| 624 | intptr_t end_page = ((start + size) & ~CachePage::kPageMask); |
| 625 | return start_page == end_page; |
| 626 | } |
| 627 | |
| 628 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 629 | void Simulator::set_last_debugger_input(char* input) { |
| 630 | DeleteArray(last_debugger_input_); |
| 631 | last_debugger_input_ = input; |
| 632 | } |
| 633 | |
| 634 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 635 | void Simulator::FlushICache(v8::internal::HashMap* i_cache, |
| 636 | void* start_addr, |
| 637 | size_t size) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 638 | intptr_t start = reinterpret_cast<intptr_t>(start_addr); |
| 639 | int intra_line = (start & CachePage::kLineMask); |
| 640 | start -= intra_line; |
| 641 | size += intra_line; |
| 642 | size = ((size - 1) | CachePage::kLineMask) + 1; |
| 643 | int offset = (start & CachePage::kPageMask); |
| 644 | while (!AllOnOnePage(start, size - 1)) { |
| 645 | int bytes_to_flush = CachePage::kPageSize - offset; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 646 | FlushOnePage(i_cache, start, bytes_to_flush); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 647 | start += bytes_to_flush; |
| 648 | size -= bytes_to_flush; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 649 | DCHECK_EQ(0, start & CachePage::kPageMask); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 650 | offset = 0; |
| 651 | } |
| 652 | if (size != 0) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 653 | FlushOnePage(i_cache, start, size); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
| 657 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 658 | CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) { |
| 659 | v8::internal::HashMap::Entry* entry = i_cache->Lookup(page, |
| 660 | ICacheHash(page), |
| 661 | true); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 662 | if (entry->value == NULL) { |
| 663 | CachePage* new_page = new CachePage(); |
| 664 | entry->value = new_page; |
| 665 | } |
| 666 | return reinterpret_cast<CachePage*>(entry->value); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | // Flush from start up to and not including start + size. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 671 | void Simulator::FlushOnePage(v8::internal::HashMap* i_cache, |
| 672 | intptr_t start, |
| 673 | int size) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 674 | DCHECK(size <= CachePage::kPageSize); |
| 675 | DCHECK(AllOnOnePage(start, size - 1)); |
| 676 | DCHECK((start & CachePage::kLineMask) == 0); |
| 677 | DCHECK((size & CachePage::kLineMask) == 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 678 | void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 679 | int offset = (start & CachePage::kPageMask); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 680 | CachePage* cache_page = GetCachePage(i_cache, page); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 681 | char* valid_bytemap = cache_page->ValidityByte(offset); |
| 682 | memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 683 | } |
| 684 | |
| 685 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 686 | void Simulator::CheckICache(v8::internal::HashMap* i_cache, |
| 687 | Instruction* instr) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 688 | intptr_t address = reinterpret_cast<intptr_t>(instr); |
| 689 | void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 690 | void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 691 | int offset = (address & CachePage::kPageMask); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 692 | CachePage* cache_page = GetCachePage(i_cache, page); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 693 | char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 694 | bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 695 | char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 696 | if (cache_hit) { |
| 697 | // Check that the data in memory matches the contents of the I-cache. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 698 | CHECK_EQ(0, |
| 699 | memcmp(reinterpret_cast<void*>(instr), |
| 700 | cache_page->CachedData(offset), Instruction::kInstrSize)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 701 | } else { |
| 702 | // Cache miss. Load memory into the cache. |
| 703 | memcpy(cached_line, line, CachePage::kLineLength); |
| 704 | *cache_valid_byte = CachePage::LINE_VALID; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 709 | void Simulator::Initialize(Isolate* isolate) { |
| 710 | if (isolate->simulator_initialized()) return; |
| 711 | isolate->set_simulator_initialized(true); |
| 712 | ::v8::internal::ExternalReference::set_redirector(isolate, |
| 713 | &RedirectExternalReference); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 717 | Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 718 | i_cache_ = isolate_->simulator_i_cache(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 719 | if (i_cache_ == NULL) { |
| 720 | i_cache_ = new v8::internal::HashMap(&ICacheMatch); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 721 | isolate_->set_simulator_i_cache(i_cache_); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 722 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 723 | Initialize(isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 724 | // Set up simulator support first. Some of this information is needed to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 725 | // setup the architecture state. |
| 726 | size_t stack_size = 1 * 1024*1024; // allocate 1MB for stack |
| 727 | stack_ = reinterpret_cast<char*>(malloc(stack_size)); |
| 728 | pc_modified_ = false; |
| 729 | icount_ = 0; |
| 730 | break_pc_ = NULL; |
| 731 | break_instr_ = 0; |
| 732 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 733 | // Set up architecture state. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | // All registers are initialized to zero to start with. |
| 735 | for (int i = 0; i < num_registers; i++) { |
| 736 | registers_[i] = 0; |
| 737 | } |
| 738 | n_flag_ = false; |
| 739 | z_flag_ = false; |
| 740 | c_flag_ = false; |
| 741 | v_flag_ = false; |
| 742 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 743 | // Initializing VFP registers. |
| 744 | // All registers are initialized to zero to start with |
| 745 | // even though s_registers_ & d_registers_ share the same |
| 746 | // physical registers in the target. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 747 | for (int i = 0; i < num_d_registers * 2; i++) { |
| 748 | vfp_registers_[i] = 0; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 749 | } |
| 750 | n_flag_FPSCR_ = false; |
| 751 | z_flag_FPSCR_ = false; |
| 752 | c_flag_FPSCR_ = false; |
| 753 | v_flag_FPSCR_ = false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 754 | FPSCR_rounding_mode_ = RN; |
| 755 | FPSCR_default_NaN_mode_ = false; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 756 | |
| 757 | inv_op_vfp_flag_ = false; |
| 758 | div_zero_vfp_flag_ = false; |
| 759 | overflow_vfp_flag_ = false; |
| 760 | underflow_vfp_flag_ = false; |
| 761 | inexact_vfp_flag_ = false; |
| 762 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 763 | // The sp is initialized to point to the bottom (high address) of the |
| 764 | // allocated stack area. To be safe in potential stack underflows we leave |
| 765 | // some buffer below. |
| 766 | registers_[sp] = reinterpret_cast<int32_t>(stack_) + stack_size - 64; |
| 767 | // The lr and pc are initialized to a known bad value that will cause an |
| 768 | // access violation if the simulator ever tries to execute it. |
| 769 | registers_[pc] = bad_lr; |
| 770 | registers_[lr] = bad_lr; |
| 771 | InitializeCoverage(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 772 | |
| 773 | last_debugger_input_ = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | Simulator::~Simulator() { |
| 778 | } |
| 779 | |
| 780 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 781 | // When the generated code calls an external reference we need to catch that in |
| 782 | // the simulator. The external reference will be a function compiled for the |
| 783 | // host architecture. We need to call that function instead of trying to |
| 784 | // execute it with the simulator. We do that by redirecting the external |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 785 | // reference to a svc (Supervisor Call) instruction that is handled by |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 786 | // the simulator. We write the original destination of the jump just at a known |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 787 | // offset from the svc instruction so the simulator knows what to call. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 788 | class Redirection { |
| 789 | public: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 790 | Redirection(void* external_function, ExternalReference::Type type) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 791 | : external_function_(external_function), |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 792 | swi_instruction_(al | (0xf*B24) | kCallRtRedirected), |
| 793 | type_(type), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 794 | next_(NULL) { |
| 795 | Isolate* isolate = Isolate::Current(); |
| 796 | next_ = isolate->simulator_redirection(); |
| 797 | Simulator::current(isolate)-> |
| 798 | FlushICache(isolate->simulator_i_cache(), |
| 799 | reinterpret_cast<void*>(&swi_instruction_), |
| 800 | Instruction::kInstrSize); |
| 801 | isolate->set_simulator_redirection(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void* address_of_swi_instruction() { |
| 805 | return reinterpret_cast<void*>(&swi_instruction_); |
| 806 | } |
| 807 | |
| 808 | void* external_function() { return external_function_; } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 809 | ExternalReference::Type type() { return type_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 810 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 811 | static Redirection* Get(void* external_function, |
| 812 | ExternalReference::Type type) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 813 | Isolate* isolate = Isolate::Current(); |
| 814 | Redirection* current = isolate->simulator_redirection(); |
| 815 | for (; current != NULL; current = current->next_) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 816 | if (current->external_function_ == external_function) { |
| 817 | DCHECK_EQ(current->type(), type); |
| 818 | return current; |
| 819 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 821 | return new Redirection(external_function, type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 824 | static Redirection* FromSwiInstruction(Instruction* swi_instruction) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 825 | char* addr_of_swi = reinterpret_cast<char*>(swi_instruction); |
| 826 | char* addr_of_redirection = |
| 827 | addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); |
| 828 | return reinterpret_cast<Redirection*>(addr_of_redirection); |
| 829 | } |
| 830 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 831 | static void* ReverseRedirection(int32_t reg) { |
| 832 | Redirection* redirection = FromSwiInstruction( |
| 833 | reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); |
| 834 | return redirection->external_function(); |
| 835 | } |
| 836 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 837 | private: |
| 838 | void* external_function_; |
| 839 | uint32_t swi_instruction_; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 840 | ExternalReference::Type type_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 841 | Redirection* next_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 842 | }; |
| 843 | |
| 844 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 845 | void* Simulator::RedirectExternalReference(void* external_function, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 846 | ExternalReference::Type type) { |
| 847 | Redirection* redirection = Redirection::Get(external_function, type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 848 | return redirection->address_of_swi_instruction(); |
| 849 | } |
| 850 | |
| 851 | |
| 852 | // Get the active Simulator for the current thread. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 853 | Simulator* Simulator::current(Isolate* isolate) { |
| 854 | v8::internal::Isolate::PerIsolateThreadData* isolate_data = |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 855 | isolate->FindOrAllocatePerThreadDataForThisThread(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | DCHECK(isolate_data != NULL); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 857 | |
| 858 | Simulator* sim = isolate_data->simulator(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 859 | if (sim == NULL) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 860 | // TODO(146): delete the simulator object when a thread/isolate goes away. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 861 | sim = new Simulator(isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 862 | isolate_data->set_simulator(sim); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 863 | } |
| 864 | return sim; |
| 865 | } |
| 866 | |
| 867 | |
| 868 | // Sets the register in the architecture state. It will also deal with updating |
| 869 | // Simulator internal state for special registers such as PC. |
| 870 | void Simulator::set_register(int reg, int32_t value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 871 | DCHECK((reg >= 0) && (reg < num_registers)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 872 | if (reg == pc) { |
| 873 | pc_modified_ = true; |
| 874 | } |
| 875 | registers_[reg] = value; |
| 876 | } |
| 877 | |
| 878 | |
| 879 | // Get the register from the architecture state. This function does handle |
| 880 | // the special case of accessing the PC register. |
| 881 | int32_t Simulator::get_register(int reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 882 | DCHECK((reg >= 0) && (reg < num_registers)); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 883 | // Stupid code added to avoid bug in GCC. |
| 884 | // See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949 |
| 885 | if (reg >= num_registers) return 0; |
| 886 | // End stupid code. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 887 | return registers_[reg] + ((reg == pc) ? Instruction::kPCReadOffset : 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 891 | double Simulator::get_double_from_register_pair(int reg) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 892 | DCHECK((reg >= 0) && (reg < num_registers) && ((reg % 2) == 0)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 893 | |
| 894 | double dm_val = 0.0; |
| 895 | // Read the bits from the unsigned integer register_[] array |
| 896 | // into the double precision floating point value and return it. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 897 | char buffer[2 * sizeof(vfp_registers_[0])]; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 898 | memcpy(buffer, ®isters_[reg], 2 * sizeof(registers_[0])); |
| 899 | memcpy(&dm_val, buffer, 2 * sizeof(registers_[0])); |
| 900 | return(dm_val); |
| 901 | } |
| 902 | |
| 903 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 904 | void Simulator::set_register_pair_from_double(int reg, double* value) { |
| 905 | DCHECK((reg >= 0) && (reg < num_registers) && ((reg % 2) == 0)); |
| 906 | memcpy(registers_ + reg, value, sizeof(*value)); |
| 907 | } |
| 908 | |
| 909 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 910 | void Simulator::set_dw_register(int dreg, const int* dbl) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 911 | DCHECK((dreg >= 0) && (dreg < num_d_registers)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 912 | registers_[dreg] = dbl[0]; |
| 913 | registers_[dreg + 1] = dbl[1]; |
| 914 | } |
| 915 | |
| 916 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 917 | void Simulator::get_d_register(int dreg, uint64_t* value) { |
| 918 | DCHECK((dreg >= 0) && (dreg < DwVfpRegister::NumRegisters())); |
| 919 | memcpy(value, vfp_registers_ + dreg * 2, sizeof(*value)); |
| 920 | } |
| 921 | |
| 922 | |
| 923 | void Simulator::set_d_register(int dreg, const uint64_t* value) { |
| 924 | DCHECK((dreg >= 0) && (dreg < DwVfpRegister::NumRegisters())); |
| 925 | memcpy(vfp_registers_ + dreg * 2, value, sizeof(*value)); |
| 926 | } |
| 927 | |
| 928 | |
| 929 | void Simulator::get_d_register(int dreg, uint32_t* value) { |
| 930 | DCHECK((dreg >= 0) && (dreg < DwVfpRegister::NumRegisters())); |
| 931 | memcpy(value, vfp_registers_ + dreg * 2, sizeof(*value) * 2); |
| 932 | } |
| 933 | |
| 934 | |
| 935 | void Simulator::set_d_register(int dreg, const uint32_t* value) { |
| 936 | DCHECK((dreg >= 0) && (dreg < DwVfpRegister::NumRegisters())); |
| 937 | memcpy(vfp_registers_ + dreg * 2, value, sizeof(*value) * 2); |
| 938 | } |
| 939 | |
| 940 | |
| 941 | void Simulator::get_q_register(int qreg, uint64_t* value) { |
| 942 | DCHECK((qreg >= 0) && (qreg < num_q_registers)); |
| 943 | memcpy(value, vfp_registers_ + qreg * 4, sizeof(*value) * 2); |
| 944 | } |
| 945 | |
| 946 | |
| 947 | void Simulator::set_q_register(int qreg, const uint64_t* value) { |
| 948 | DCHECK((qreg >= 0) && (qreg < num_q_registers)); |
| 949 | memcpy(vfp_registers_ + qreg * 4, value, sizeof(*value) * 2); |
| 950 | } |
| 951 | |
| 952 | |
| 953 | void Simulator::get_q_register(int qreg, uint32_t* value) { |
| 954 | DCHECK((qreg >= 0) && (qreg < num_q_registers)); |
| 955 | memcpy(value, vfp_registers_ + qreg * 4, sizeof(*value) * 4); |
| 956 | } |
| 957 | |
| 958 | |
| 959 | void Simulator::set_q_register(int qreg, const uint32_t* value) { |
| 960 | DCHECK((qreg >= 0) && (qreg < num_q_registers)); |
| 961 | memcpy(vfp_registers_ + qreg * 4, value, sizeof(*value) * 4); |
| 962 | } |
| 963 | |
| 964 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 965 | // Raw access to the PC register. |
| 966 | void Simulator::set_pc(int32_t value) { |
| 967 | pc_modified_ = true; |
| 968 | registers_[pc] = value; |
| 969 | } |
| 970 | |
| 971 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 972 | bool Simulator::has_bad_pc() const { |
| 973 | return ((registers_[pc] == bad_lr) || (registers_[pc] == end_sim_pc)); |
| 974 | } |
| 975 | |
| 976 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 977 | // Raw access to the PC register without the special adjustment when reading. |
| 978 | int32_t Simulator::get_pc() const { |
| 979 | return registers_[pc]; |
| 980 | } |
| 981 | |
| 982 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 983 | // Getting from and setting into VFP registers. |
| 984 | void Simulator::set_s_register(int sreg, unsigned int value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 985 | DCHECK((sreg >= 0) && (sreg < num_s_registers)); |
| 986 | vfp_registers_[sreg] = value; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
| 990 | unsigned int Simulator::get_s_register(int sreg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 991 | DCHECK((sreg >= 0) && (sreg < num_s_registers)); |
| 992 | return vfp_registers_[sreg]; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | template<class InputType, int register_size> |
| 997 | void Simulator::SetVFPRegister(int reg_index, const InputType& value) { |
| 998 | DCHECK(reg_index >= 0); |
| 999 | if (register_size == 1) DCHECK(reg_index < num_s_registers); |
| 1000 | if (register_size == 2) DCHECK(reg_index < DwVfpRegister::NumRegisters()); |
| 1001 | |
| 1002 | char buffer[register_size * sizeof(vfp_registers_[0])]; |
| 1003 | memcpy(buffer, &value, register_size * sizeof(vfp_registers_[0])); |
| 1004 | memcpy(&vfp_registers_[reg_index * register_size], buffer, |
| 1005 | register_size * sizeof(vfp_registers_[0])); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1009 | template<class ReturnType, int register_size> |
| 1010 | ReturnType Simulator::GetFromVFPRegister(int reg_index) { |
| 1011 | DCHECK(reg_index >= 0); |
| 1012 | if (register_size == 1) DCHECK(reg_index < num_s_registers); |
| 1013 | if (register_size == 2) DCHECK(reg_index < DwVfpRegister::NumRegisters()); |
| 1014 | |
| 1015 | ReturnType value = 0; |
| 1016 | char buffer[register_size * sizeof(vfp_registers_[0])]; |
| 1017 | memcpy(buffer, &vfp_registers_[register_size * reg_index], |
| 1018 | register_size * sizeof(vfp_registers_[0])); |
| 1019 | memcpy(&value, buffer, register_size * sizeof(vfp_registers_[0])); |
| 1020 | return value; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1024 | // Runtime FP routines take: |
| 1025 | // - two double arguments |
| 1026 | // - one double argument and zero or one integer arguments. |
| 1027 | // All are consructed here from r0-r3 or d0, d1 and r0. |
| 1028 | void Simulator::GetFpArgs(double* x, double* y, int32_t* z) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1029 | if (use_eabi_hardfloat()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1030 | *x = get_double_from_d_register(0); |
| 1031 | *y = get_double_from_d_register(1); |
| 1032 | *z = get_register(0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1033 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1034 | // Registers 0 and 1 -> x. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1035 | *x = get_double_from_register_pair(0); |
| 1036 | // Register 2 and 3 -> y. |
| 1037 | *y = get_double_from_register_pair(2); |
| 1038 | // Register 2 -> z |
| 1039 | *z = get_register(2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | // The return value is either in r0/r1 or d0. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1045 | void Simulator::SetFpResult(const double& result) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1046 | if (use_eabi_hardfloat()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1047 | char buffer[2 * sizeof(vfp_registers_[0])]; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1048 | memcpy(buffer, &result, sizeof(buffer)); |
| 1049 | // Copy result to d0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1050 | memcpy(vfp_registers_, buffer, sizeof(buffer)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1051 | } else { |
| 1052 | char buffer[2 * sizeof(registers_[0])]; |
| 1053 | memcpy(buffer, &result, sizeof(buffer)); |
| 1054 | // Copy result to r0 and r1. |
| 1055 | memcpy(registers_, buffer, sizeof(buffer)); |
| 1056 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | void Simulator::TrashCallerSaveRegisters() { |
| 1061 | // We don't trash the registers with the return value. |
| 1062 | registers_[2] = 0x50Bad4U; |
| 1063 | registers_[3] = 0x50Bad4U; |
| 1064 | registers_[12] = 0x50Bad4U; |
| 1065 | } |
| 1066 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1067 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1068 | // Some Operating Systems allow unaligned access on ARMv7 targets. We |
| 1069 | // assume that unaligned accesses are not allowed unless the v8 build system |
| 1070 | // defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero. |
| 1071 | // The following statements below describes the behavior of the ARM CPUs |
| 1072 | // that don't support unaligned access. |
| 1073 | // Some ARM platforms raise an interrupt on detecting unaligned access. |
| 1074 | // On others it does a funky rotation thing. For now we |
| 1075 | // simply disallow unaligned reads. Note that simulator runs have the runtime |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1076 | // system running directly on the host system and only generated code is |
| 1077 | // executed in the simulator. Since the host is typically IA32 we will not |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1078 | // get the correct ARM-like behaviour on unaligned accesses for those ARM |
| 1079 | // targets that don't support unaligned loads and stores. |
| 1080 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1081 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1082 | int Simulator::ReadW(int32_t addr, Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1083 | if (FLAG_enable_unaligned_accesses || (addr & 3) == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1084 | intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
| 1085 | return *ptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1086 | } else { |
| 1087 | PrintF("Unaligned read at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1088 | addr, |
| 1089 | reinterpret_cast<intptr_t>(instr)); |
| 1090 | UNIMPLEMENTED(); |
| 1091 | return 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1092 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1096 | void Simulator::WriteW(int32_t addr, int value, Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1097 | if (FLAG_enable_unaligned_accesses || (addr & 3) == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1098 | intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); |
| 1099 | *ptr = value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1100 | } else { |
| 1101 | PrintF("Unaligned write at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1102 | addr, |
| 1103 | reinterpret_cast<intptr_t>(instr)); |
| 1104 | UNIMPLEMENTED(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1105 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1109 | uint16_t Simulator::ReadHU(int32_t addr, Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1110 | if (FLAG_enable_unaligned_accesses || (addr & 1) == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1111 | uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
| 1112 | return *ptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1113 | } else { |
| 1114 | PrintF("Unaligned unsigned halfword read at 0x%08x, pc=0x%08" |
| 1115 | V8PRIxPTR "\n", |
| 1116 | addr, |
| 1117 | reinterpret_cast<intptr_t>(instr)); |
| 1118 | UNIMPLEMENTED(); |
| 1119 | return 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1120 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1124 | int16_t Simulator::ReadH(int32_t addr, Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1125 | if (FLAG_enable_unaligned_accesses || (addr & 1) == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1126 | int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
| 1127 | return *ptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1128 | } else { |
| 1129 | PrintF("Unaligned signed halfword read at 0x%08x\n", addr); |
| 1130 | UNIMPLEMENTED(); |
| 1131 | return 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1132 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1136 | void Simulator::WriteH(int32_t addr, uint16_t value, Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1137 | if (FLAG_enable_unaligned_accesses || (addr & 1) == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1138 | uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); |
| 1139 | *ptr = value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1140 | } else { |
| 1141 | PrintF("Unaligned unsigned halfword write at 0x%08x, pc=0x%08" |
| 1142 | V8PRIxPTR "\n", |
| 1143 | addr, |
| 1144 | reinterpret_cast<intptr_t>(instr)); |
| 1145 | UNIMPLEMENTED(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1146 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1150 | void Simulator::WriteH(int32_t addr, int16_t value, Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1151 | if (FLAG_enable_unaligned_accesses || (addr & 1) == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1152 | int16_t* ptr = reinterpret_cast<int16_t*>(addr); |
| 1153 | *ptr = value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1154 | } else { |
| 1155 | PrintF("Unaligned halfword write at 0x%08x, pc=0x%08" V8PRIxPTR "\n", |
| 1156 | addr, |
| 1157 | reinterpret_cast<intptr_t>(instr)); |
| 1158 | UNIMPLEMENTED(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1159 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | uint8_t Simulator::ReadBU(int32_t addr) { |
| 1164 | uint8_t* ptr = reinterpret_cast<uint8_t*>(addr); |
| 1165 | return *ptr; |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | int8_t Simulator::ReadB(int32_t addr) { |
| 1170 | int8_t* ptr = reinterpret_cast<int8_t*>(addr); |
| 1171 | return *ptr; |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | void Simulator::WriteB(int32_t addr, uint8_t value) { |
| 1176 | uint8_t* ptr = reinterpret_cast<uint8_t*>(addr); |
| 1177 | *ptr = value; |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | void Simulator::WriteB(int32_t addr, int8_t value) { |
| 1182 | int8_t* ptr = reinterpret_cast<int8_t*>(addr); |
| 1183 | *ptr = value; |
| 1184 | } |
| 1185 | |
| 1186 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1187 | int32_t* Simulator::ReadDW(int32_t addr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1188 | if (FLAG_enable_unaligned_accesses || (addr & 3) == 0) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1189 | int32_t* ptr = reinterpret_cast<int32_t*>(addr); |
| 1190 | return ptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1191 | } else { |
| 1192 | PrintF("Unaligned read at 0x%08x\n", addr); |
| 1193 | UNIMPLEMENTED(); |
| 1194 | return 0; |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1195 | } |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | void Simulator::WriteDW(int32_t addr, int32_t value1, int32_t value2) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1200 | if (FLAG_enable_unaligned_accesses || (addr & 3) == 0) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1201 | int32_t* ptr = reinterpret_cast<int32_t*>(addr); |
| 1202 | *ptr++ = value1; |
| 1203 | *ptr = value2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1204 | } else { |
| 1205 | PrintF("Unaligned write at 0x%08x\n", addr); |
| 1206 | UNIMPLEMENTED(); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1207 | } |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1211 | // Returns the limit of the stack area to enable checking for stack overflows. |
| 1212 | uintptr_t Simulator::StackLimit() const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1213 | // Leave a safety margin of 1024 bytes to prevent overrunning the stack when |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1214 | // pushing values. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1215 | return reinterpret_cast<uintptr_t>(stack_) + 1024; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | |
| 1219 | // Unsupported instructions use Format to print an error and stop execution. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1220 | void Simulator::Format(Instruction* instr, const char* format) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1221 | PrintF("Simulator found unsupported instruction:\n 0x%08x: %s\n", |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1222 | reinterpret_cast<intptr_t>(instr), format); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1223 | UNIMPLEMENTED(); |
| 1224 | } |
| 1225 | |
| 1226 | |
| 1227 | // Checks if the current instruction should be executed based on its |
| 1228 | // condition bits. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1229 | bool Simulator::ConditionallyExecute(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1230 | switch (instr->ConditionField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1231 | case eq: return z_flag_; |
| 1232 | case ne: return !z_flag_; |
| 1233 | case cs: return c_flag_; |
| 1234 | case cc: return !c_flag_; |
| 1235 | case mi: return n_flag_; |
| 1236 | case pl: return !n_flag_; |
| 1237 | case vs: return v_flag_; |
| 1238 | case vc: return !v_flag_; |
| 1239 | case hi: return c_flag_ && !z_flag_; |
| 1240 | case ls: return !c_flag_ || z_flag_; |
| 1241 | case ge: return n_flag_ == v_flag_; |
| 1242 | case lt: return n_flag_ != v_flag_; |
| 1243 | case gt: return !z_flag_ && (n_flag_ == v_flag_); |
| 1244 | case le: return z_flag_ || (n_flag_ != v_flag_); |
| 1245 | case al: return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1246 | default: UNREACHABLE(); |
| 1247 | } |
| 1248 | return false; |
| 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | // Calculate and set the Negative and Zero flags. |
| 1253 | void Simulator::SetNZFlags(int32_t val) { |
| 1254 | n_flag_ = (val < 0); |
| 1255 | z_flag_ = (val == 0); |
| 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | // Set the Carry flag. |
| 1260 | void Simulator::SetCFlag(bool val) { |
| 1261 | c_flag_ = val; |
| 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | // Set the oVerflow flag. |
| 1266 | void Simulator::SetVFlag(bool val) { |
| 1267 | v_flag_ = val; |
| 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | // Calculate C flag value for additions. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1272 | bool Simulator::CarryFrom(int32_t left, int32_t right, int32_t carry) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1273 | uint32_t uleft = static_cast<uint32_t>(left); |
| 1274 | uint32_t uright = static_cast<uint32_t>(right); |
| 1275 | uint32_t urest = 0xffffffffU - uleft; |
| 1276 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1277 | return (uright > urest) || |
| 1278 | (carry && (((uright + 1) > urest) || (uright > (urest - 1)))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | // Calculate C flag value for subtractions. |
| 1283 | bool Simulator::BorrowFrom(int32_t left, int32_t right) { |
| 1284 | uint32_t uleft = static_cast<uint32_t>(left); |
| 1285 | uint32_t uright = static_cast<uint32_t>(right); |
| 1286 | |
| 1287 | return (uright > uleft); |
| 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | // Calculate V flag value for additions and subtractions. |
| 1292 | bool Simulator::OverflowFrom(int32_t alu_out, |
| 1293 | int32_t left, int32_t right, bool addition) { |
| 1294 | bool overflow; |
| 1295 | if (addition) { |
| 1296 | // operands have the same sign |
| 1297 | overflow = ((left >= 0 && right >= 0) || (left < 0 && right < 0)) |
| 1298 | // and operands and result have different sign |
| 1299 | && ((left < 0 && alu_out >= 0) || (left >= 0 && alu_out < 0)); |
| 1300 | } else { |
| 1301 | // operands have different signs |
| 1302 | overflow = ((left < 0 && right >= 0) || (left >= 0 && right < 0)) |
| 1303 | // and first operand and result have different signs |
| 1304 | && ((left < 0 && alu_out >= 0) || (left >= 0 && alu_out < 0)); |
| 1305 | } |
| 1306 | return overflow; |
| 1307 | } |
| 1308 | |
| 1309 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1310 | // Support for VFP comparisons. |
| 1311 | void Simulator::Compute_FPSCR_Flags(double val1, double val2) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1312 | if (std::isnan(val1) || std::isnan(val2)) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1313 | n_flag_FPSCR_ = false; |
| 1314 | z_flag_FPSCR_ = false; |
| 1315 | c_flag_FPSCR_ = true; |
| 1316 | v_flag_FPSCR_ = true; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1317 | // All non-NaN cases. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1318 | } else if (val1 == val2) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1319 | n_flag_FPSCR_ = false; |
| 1320 | z_flag_FPSCR_ = true; |
| 1321 | c_flag_FPSCR_ = true; |
| 1322 | v_flag_FPSCR_ = false; |
| 1323 | } else if (val1 < val2) { |
| 1324 | n_flag_FPSCR_ = true; |
| 1325 | z_flag_FPSCR_ = false; |
| 1326 | c_flag_FPSCR_ = false; |
| 1327 | v_flag_FPSCR_ = false; |
| 1328 | } else { |
| 1329 | // Case when (val1 > val2). |
| 1330 | n_flag_FPSCR_ = false; |
| 1331 | z_flag_FPSCR_ = false; |
| 1332 | c_flag_FPSCR_ = true; |
| 1333 | v_flag_FPSCR_ = false; |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | void Simulator::Copy_FPSCR_to_APSR() { |
| 1339 | n_flag_ = n_flag_FPSCR_; |
| 1340 | z_flag_ = z_flag_FPSCR_; |
| 1341 | c_flag_ = c_flag_FPSCR_; |
| 1342 | v_flag_ = v_flag_FPSCR_; |
| 1343 | } |
| 1344 | |
| 1345 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1346 | // Addressing Mode 1 - Data-processing operands: |
| 1347 | // Get the value based on the shifter_operand with register. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1348 | int32_t Simulator::GetShiftRm(Instruction* instr, bool* carry_out) { |
| 1349 | ShiftOp shift = instr->ShiftField(); |
| 1350 | int shift_amount = instr->ShiftAmountValue(); |
| 1351 | int32_t result = get_register(instr->RmValue()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1352 | if (instr->Bit(4) == 0) { |
| 1353 | // by immediate |
| 1354 | if ((shift == ROR) && (shift_amount == 0)) { |
| 1355 | UNIMPLEMENTED(); |
| 1356 | return result; |
| 1357 | } else if (((shift == LSR) || (shift == ASR)) && (shift_amount == 0)) { |
| 1358 | shift_amount = 32; |
| 1359 | } |
| 1360 | switch (shift) { |
| 1361 | case ASR: { |
| 1362 | if (shift_amount == 0) { |
| 1363 | if (result < 0) { |
| 1364 | result = 0xffffffff; |
| 1365 | *carry_out = true; |
| 1366 | } else { |
| 1367 | result = 0; |
| 1368 | *carry_out = false; |
| 1369 | } |
| 1370 | } else { |
| 1371 | result >>= (shift_amount - 1); |
| 1372 | *carry_out = (result & 1) == 1; |
| 1373 | result >>= 1; |
| 1374 | } |
| 1375 | break; |
| 1376 | } |
| 1377 | |
| 1378 | case LSL: { |
| 1379 | if (shift_amount == 0) { |
| 1380 | *carry_out = c_flag_; |
| 1381 | } else { |
| 1382 | result <<= (shift_amount - 1); |
| 1383 | *carry_out = (result < 0); |
| 1384 | result <<= 1; |
| 1385 | } |
| 1386 | break; |
| 1387 | } |
| 1388 | |
| 1389 | case LSR: { |
| 1390 | if (shift_amount == 0) { |
| 1391 | result = 0; |
| 1392 | *carry_out = c_flag_; |
| 1393 | } else { |
| 1394 | uint32_t uresult = static_cast<uint32_t>(result); |
| 1395 | uresult >>= (shift_amount - 1); |
| 1396 | *carry_out = (uresult & 1) == 1; |
| 1397 | uresult >>= 1; |
| 1398 | result = static_cast<int32_t>(uresult); |
| 1399 | } |
| 1400 | break; |
| 1401 | } |
| 1402 | |
| 1403 | case ROR: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1404 | if (shift_amount == 0) { |
| 1405 | *carry_out = c_flag_; |
| 1406 | } else { |
| 1407 | uint32_t left = static_cast<uint32_t>(result) >> shift_amount; |
| 1408 | uint32_t right = static_cast<uint32_t>(result) << (32 - shift_amount); |
| 1409 | result = right | left; |
| 1410 | *carry_out = (static_cast<uint32_t>(result) >> 31) != 0; |
| 1411 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1412 | break; |
| 1413 | } |
| 1414 | |
| 1415 | default: { |
| 1416 | UNREACHABLE(); |
| 1417 | break; |
| 1418 | } |
| 1419 | } |
| 1420 | } else { |
| 1421 | // by register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1422 | int rs = instr->RsValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1423 | shift_amount = get_register(rs) &0xff; |
| 1424 | switch (shift) { |
| 1425 | case ASR: { |
| 1426 | if (shift_amount == 0) { |
| 1427 | *carry_out = c_flag_; |
| 1428 | } else if (shift_amount < 32) { |
| 1429 | result >>= (shift_amount - 1); |
| 1430 | *carry_out = (result & 1) == 1; |
| 1431 | result >>= 1; |
| 1432 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1433 | DCHECK(shift_amount >= 32); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1434 | if (result < 0) { |
| 1435 | *carry_out = true; |
| 1436 | result = 0xffffffff; |
| 1437 | } else { |
| 1438 | *carry_out = false; |
| 1439 | result = 0; |
| 1440 | } |
| 1441 | } |
| 1442 | break; |
| 1443 | } |
| 1444 | |
| 1445 | case LSL: { |
| 1446 | if (shift_amount == 0) { |
| 1447 | *carry_out = c_flag_; |
| 1448 | } else if (shift_amount < 32) { |
| 1449 | result <<= (shift_amount - 1); |
| 1450 | *carry_out = (result < 0); |
| 1451 | result <<= 1; |
| 1452 | } else if (shift_amount == 32) { |
| 1453 | *carry_out = (result & 1) == 1; |
| 1454 | result = 0; |
| 1455 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1456 | DCHECK(shift_amount > 32); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1457 | *carry_out = false; |
| 1458 | result = 0; |
| 1459 | } |
| 1460 | break; |
| 1461 | } |
| 1462 | |
| 1463 | case LSR: { |
| 1464 | if (shift_amount == 0) { |
| 1465 | *carry_out = c_flag_; |
| 1466 | } else if (shift_amount < 32) { |
| 1467 | uint32_t uresult = static_cast<uint32_t>(result); |
| 1468 | uresult >>= (shift_amount - 1); |
| 1469 | *carry_out = (uresult & 1) == 1; |
| 1470 | uresult >>= 1; |
| 1471 | result = static_cast<int32_t>(uresult); |
| 1472 | } else if (shift_amount == 32) { |
| 1473 | *carry_out = (result < 0); |
| 1474 | result = 0; |
| 1475 | } else { |
| 1476 | *carry_out = false; |
| 1477 | result = 0; |
| 1478 | } |
| 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | case ROR: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1483 | if (shift_amount == 0) { |
| 1484 | *carry_out = c_flag_; |
| 1485 | } else { |
| 1486 | uint32_t left = static_cast<uint32_t>(result) >> shift_amount; |
| 1487 | uint32_t right = static_cast<uint32_t>(result) << (32 - shift_amount); |
| 1488 | result = right | left; |
| 1489 | *carry_out = (static_cast<uint32_t>(result) >> 31) != 0; |
| 1490 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | } |
| 1493 | |
| 1494 | default: { |
| 1495 | UNREACHABLE(); |
| 1496 | break; |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | return result; |
| 1501 | } |
| 1502 | |
| 1503 | |
| 1504 | // Addressing Mode 1 - Data-processing operands: |
| 1505 | // Get the value based on the shifter_operand with immediate. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1506 | int32_t Simulator::GetImm(Instruction* instr, bool* carry_out) { |
| 1507 | int rotate = instr->RotateValue() * 2; |
| 1508 | int immed8 = instr->Immed8Value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1509 | int imm = (immed8 >> rotate) | (immed8 << (32 - rotate)); |
| 1510 | *carry_out = (rotate == 0) ? c_flag_ : (imm < 0); |
| 1511 | return imm; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | static int count_bits(int bit_vector) { |
| 1516 | int count = 0; |
| 1517 | while (bit_vector != 0) { |
| 1518 | if ((bit_vector & 1) != 0) { |
| 1519 | count++; |
| 1520 | } |
| 1521 | bit_vector >>= 1; |
| 1522 | } |
| 1523 | return count; |
| 1524 | } |
| 1525 | |
| 1526 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1527 | int32_t Simulator::ProcessPU(Instruction* instr, |
| 1528 | int num_regs, |
| 1529 | int reg_size, |
| 1530 | intptr_t* start_address, |
| 1531 | intptr_t* end_address) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1532 | int rn = instr->RnValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1533 | int32_t rn_val = get_register(rn); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1534 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1535 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1536 | UNIMPLEMENTED(); |
| 1537 | break; |
| 1538 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1539 | case ia_x: { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1540 | *start_address = rn_val; |
| 1541 | *end_address = rn_val + (num_regs * reg_size) - reg_size; |
| 1542 | rn_val = rn_val + (num_regs * reg_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1545 | case db_x: { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1546 | *start_address = rn_val - (num_regs * reg_size); |
| 1547 | *end_address = rn_val - reg_size; |
| 1548 | rn_val = *start_address; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1549 | break; |
| 1550 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1551 | case ib_x: { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1552 | *start_address = rn_val + reg_size; |
| 1553 | *end_address = rn_val + (num_regs * reg_size); |
| 1554 | rn_val = *end_address; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1555 | break; |
| 1556 | } |
| 1557 | default: { |
| 1558 | UNREACHABLE(); |
| 1559 | break; |
| 1560 | } |
| 1561 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1562 | return rn_val; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1565 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1566 | // Addressing Mode 4 - Load and Store Multiple |
| 1567 | void Simulator::HandleRList(Instruction* instr, bool load) { |
| 1568 | int rlist = instr->RlistValue(); |
| 1569 | int num_regs = count_bits(rlist); |
| 1570 | |
| 1571 | intptr_t start_address = 0; |
| 1572 | intptr_t end_address = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1573 | int32_t rn_val = |
| 1574 | ProcessPU(instr, num_regs, kPointerSize, &start_address, &end_address); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1575 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1576 | intptr_t* address = reinterpret_cast<intptr_t*>(start_address); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1577 | // Catch null pointers a little earlier. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1578 | DCHECK(start_address > 8191 || start_address < 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1579 | int reg = 0; |
| 1580 | while (rlist != 0) { |
| 1581 | if ((rlist & 1) != 0) { |
| 1582 | if (load) { |
| 1583 | set_register(reg, *address); |
| 1584 | } else { |
| 1585 | *address = get_register(reg); |
| 1586 | } |
| 1587 | address += 1; |
| 1588 | } |
| 1589 | reg++; |
| 1590 | rlist >>= 1; |
| 1591 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1592 | DCHECK(end_address == ((intptr_t)address) - 4); |
| 1593 | if (instr->HasW()) { |
| 1594 | set_register(instr->RnValue(), rn_val); |
| 1595 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1599 | // Addressing Mode 6 - Load and Store Multiple Coprocessor registers. |
| 1600 | void Simulator::HandleVList(Instruction* instr) { |
| 1601 | VFPRegPrecision precision = |
| 1602 | (instr->SzValue() == 0) ? kSinglePrecision : kDoublePrecision; |
| 1603 | int operand_size = (precision == kSinglePrecision) ? 4 : 8; |
| 1604 | |
| 1605 | bool load = (instr->VLValue() == 0x1); |
| 1606 | |
| 1607 | int vd; |
| 1608 | int num_regs; |
| 1609 | vd = instr->VFPDRegValue(precision); |
| 1610 | if (precision == kSinglePrecision) { |
| 1611 | num_regs = instr->Immed8Value(); |
| 1612 | } else { |
| 1613 | num_regs = instr->Immed8Value() / 2; |
| 1614 | } |
| 1615 | |
| 1616 | intptr_t start_address = 0; |
| 1617 | intptr_t end_address = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1618 | int32_t rn_val = |
| 1619 | ProcessPU(instr, num_regs, operand_size, &start_address, &end_address); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1620 | |
| 1621 | intptr_t* address = reinterpret_cast<intptr_t*>(start_address); |
| 1622 | for (int reg = vd; reg < vd + num_regs; reg++) { |
| 1623 | if (precision == kSinglePrecision) { |
| 1624 | if (load) { |
| 1625 | set_s_register_from_sinteger( |
| 1626 | reg, ReadW(reinterpret_cast<int32_t>(address), instr)); |
| 1627 | } else { |
| 1628 | WriteW(reinterpret_cast<int32_t>(address), |
| 1629 | get_sinteger_from_s_register(reg), instr); |
| 1630 | } |
| 1631 | address += 1; |
| 1632 | } else { |
| 1633 | if (load) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1634 | int32_t data[] = { |
| 1635 | ReadW(reinterpret_cast<int32_t>(address), instr), |
| 1636 | ReadW(reinterpret_cast<int32_t>(address + 1), instr) |
| 1637 | }; |
| 1638 | double d; |
| 1639 | memcpy(&d, data, 8); |
| 1640 | set_d_register_from_double(reg, d); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1641 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1642 | int32_t data[2]; |
| 1643 | double d = get_double_from_d_register(reg); |
| 1644 | memcpy(data, &d, 8); |
| 1645 | WriteW(reinterpret_cast<int32_t>(address), data[0], instr); |
| 1646 | WriteW(reinterpret_cast<int32_t>(address + 1), data[1], instr); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1647 | } |
| 1648 | address += 2; |
| 1649 | } |
| 1650 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1651 | DCHECK(reinterpret_cast<intptr_t>(address) - operand_size == end_address); |
| 1652 | if (instr->HasW()) { |
| 1653 | set_register(instr->RnValue(), rn_val); |
| 1654 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1658 | // Calls into the V8 runtime are based on this very simple interface. |
| 1659 | // Note: To be able to return two values from some calls the code in runtime.cc |
| 1660 | // uses the ObjectPair which is essentially two 32-bit values stuffed into a |
| 1661 | // 64-bit value. With the code below we assume that all runtime calls return |
| 1662 | // 64 bits of result. If they don't, the r1 result register contains a bogus |
| 1663 | // value, which is fine because it is caller-saved. |
| 1664 | typedef int64_t (*SimulatorRuntimeCall)(int32_t arg0, |
| 1665 | int32_t arg1, |
| 1666 | int32_t arg2, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1667 | int32_t arg3, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1668 | int32_t arg4, |
| 1669 | int32_t arg5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1670 | |
| 1671 | // These prototypes handle the four types of FP calls. |
| 1672 | typedef int64_t (*SimulatorRuntimeCompareCall)(double darg0, double darg1); |
| 1673 | typedef double (*SimulatorRuntimeFPFPCall)(double darg0, double darg1); |
| 1674 | typedef double (*SimulatorRuntimeFPCall)(double darg0); |
| 1675 | typedef double (*SimulatorRuntimeFPIntCall)(double darg0, int32_t arg0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1676 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1677 | // This signature supports direct call in to API function native callback |
| 1678 | // (refer to InvocationCallback in v8.h). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1679 | typedef void (*SimulatorRuntimeDirectApiCall)(int32_t arg0); |
| 1680 | typedef void (*SimulatorRuntimeProfilingApiCall)(int32_t arg0, void* arg1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1681 | |
| 1682 | // This signature supports direct call to accessor getter callback. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1683 | typedef void (*SimulatorRuntimeDirectGetterCall)(int32_t arg0, int32_t arg1); |
| 1684 | typedef void (*SimulatorRuntimeProfilingGetterCall)( |
| 1685 | int32_t arg0, int32_t arg1, void* arg2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1686 | |
| 1687 | // Software interrupt instructions are used by the simulator to call into the |
| 1688 | // C-based V8 runtime. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1689 | void Simulator::SoftwareInterrupt(Instruction* instr) { |
| 1690 | int svc = instr->SvcValue(); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1691 | switch (svc) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1692 | case kCallRtRedirected: { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1693 | // Check if stack is aligned. Error if not aligned is reported below to |
| 1694 | // include information on the function called. |
| 1695 | bool stack_aligned = |
| 1696 | (get_register(sp) |
| 1697 | & (::v8::internal::FLAG_sim_stack_alignment - 1)) == 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1698 | Redirection* redirection = Redirection::FromSwiInstruction(instr); |
| 1699 | int32_t arg0 = get_register(r0); |
| 1700 | int32_t arg1 = get_register(r1); |
| 1701 | int32_t arg2 = get_register(r2); |
| 1702 | int32_t arg3 = get_register(r3); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1703 | int32_t* stack_pointer = reinterpret_cast<int32_t*>(get_register(sp)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1704 | int32_t arg4 = stack_pointer[0]; |
| 1705 | int32_t arg5 = stack_pointer[1]; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1706 | bool fp_call = |
| 1707 | (redirection->type() == ExternalReference::BUILTIN_FP_FP_CALL) || |
| 1708 | (redirection->type() == ExternalReference::BUILTIN_COMPARE_CALL) || |
| 1709 | (redirection->type() == ExternalReference::BUILTIN_FP_CALL) || |
| 1710 | (redirection->type() == ExternalReference::BUILTIN_FP_INT_CALL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1711 | // This is dodgy but it works because the C entry stubs are never moved. |
| 1712 | // See comment in codegen-arm.cc and bug 1242173. |
| 1713 | int32_t saved_lr = get_register(lr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1714 | intptr_t external = |
| 1715 | reinterpret_cast<intptr_t>(redirection->external_function()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1716 | if (fp_call) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1717 | double dval0, dval1; // one or two double parameters |
| 1718 | int32_t ival; // zero or one integer parameters |
| 1719 | int64_t iresult = 0; // integer return value |
| 1720 | double dresult = 0; // double return value |
| 1721 | GetFpArgs(&dval0, &dval1, &ival); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1722 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1723 | SimulatorRuntimeCall generic_target = |
| 1724 | reinterpret_cast<SimulatorRuntimeCall>(external); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1725 | switch (redirection->type()) { |
| 1726 | case ExternalReference::BUILTIN_FP_FP_CALL: |
| 1727 | case ExternalReference::BUILTIN_COMPARE_CALL: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1728 | PrintF("Call to host function at %p with args %f, %f", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1729 | FUNCTION_ADDR(generic_target), dval0, dval1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1730 | break; |
| 1731 | case ExternalReference::BUILTIN_FP_CALL: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1732 | PrintF("Call to host function at %p with arg %f", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1733 | FUNCTION_ADDR(generic_target), dval0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1734 | break; |
| 1735 | case ExternalReference::BUILTIN_FP_INT_CALL: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1736 | PrintF("Call to host function at %p with args %f, %d", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1737 | FUNCTION_ADDR(generic_target), dval0, ival); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1738 | break; |
| 1739 | default: |
| 1740 | UNREACHABLE(); |
| 1741 | break; |
| 1742 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1743 | if (!stack_aligned) { |
| 1744 | PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1745 | } |
| 1746 | PrintF("\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1747 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1748 | CHECK(stack_aligned); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1749 | switch (redirection->type()) { |
| 1750 | case ExternalReference::BUILTIN_COMPARE_CALL: { |
| 1751 | SimulatorRuntimeCompareCall target = |
| 1752 | reinterpret_cast<SimulatorRuntimeCompareCall>(external); |
| 1753 | iresult = target(dval0, dval1); |
| 1754 | set_register(r0, static_cast<int32_t>(iresult)); |
| 1755 | set_register(r1, static_cast<int32_t>(iresult >> 32)); |
| 1756 | break; |
| 1757 | } |
| 1758 | case ExternalReference::BUILTIN_FP_FP_CALL: { |
| 1759 | SimulatorRuntimeFPFPCall target = |
| 1760 | reinterpret_cast<SimulatorRuntimeFPFPCall>(external); |
| 1761 | dresult = target(dval0, dval1); |
| 1762 | SetFpResult(dresult); |
| 1763 | break; |
| 1764 | } |
| 1765 | case ExternalReference::BUILTIN_FP_CALL: { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1766 | SimulatorRuntimeFPCall target = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1767 | reinterpret_cast<SimulatorRuntimeFPCall>(external); |
| 1768 | dresult = target(dval0); |
| 1769 | SetFpResult(dresult); |
| 1770 | break; |
| 1771 | } |
| 1772 | case ExternalReference::BUILTIN_FP_INT_CALL: { |
| 1773 | SimulatorRuntimeFPIntCall target = |
| 1774 | reinterpret_cast<SimulatorRuntimeFPIntCall>(external); |
| 1775 | dresult = target(dval0, ival); |
| 1776 | SetFpResult(dresult); |
| 1777 | break; |
| 1778 | } |
| 1779 | default: |
| 1780 | UNREACHABLE(); |
| 1781 | break; |
| 1782 | } |
| 1783 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1784 | switch (redirection->type()) { |
| 1785 | case ExternalReference::BUILTIN_COMPARE_CALL: |
| 1786 | PrintF("Returned %08x\n", static_cast<int32_t>(iresult)); |
| 1787 | break; |
| 1788 | case ExternalReference::BUILTIN_FP_FP_CALL: |
| 1789 | case ExternalReference::BUILTIN_FP_CALL: |
| 1790 | case ExternalReference::BUILTIN_FP_INT_CALL: |
| 1791 | PrintF("Returned %f\n", dresult); |
| 1792 | break; |
| 1793 | default: |
| 1794 | UNREACHABLE(); |
| 1795 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1796 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1797 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1798 | } else if (redirection->type() == ExternalReference::DIRECT_API_CALL) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1799 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1800 | PrintF("Call to host function at %p args %08x", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1801 | reinterpret_cast<void*>(external), arg0); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1802 | if (!stack_aligned) { |
| 1803 | PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1804 | } |
| 1805 | PrintF("\n"); |
| 1806 | } |
| 1807 | CHECK(stack_aligned); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1808 | SimulatorRuntimeDirectApiCall target = |
| 1809 | reinterpret_cast<SimulatorRuntimeDirectApiCall>(external); |
| 1810 | target(arg0); |
| 1811 | } else if ( |
| 1812 | redirection->type() == ExternalReference::PROFILING_API_CALL) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1813 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1814 | PrintF("Call to host function at %p args %08x %08x", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | reinterpret_cast<void*>(external), arg0, arg1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1816 | if (!stack_aligned) { |
| 1817 | PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1818 | } |
| 1819 | PrintF("\n"); |
| 1820 | } |
| 1821 | CHECK(stack_aligned); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1822 | SimulatorRuntimeProfilingApiCall target = |
| 1823 | reinterpret_cast<SimulatorRuntimeProfilingApiCall>(external); |
| 1824 | target(arg0, Redirection::ReverseRedirection(arg1)); |
| 1825 | } else if ( |
| 1826 | redirection->type() == ExternalReference::DIRECT_GETTER_CALL) { |
| 1827 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1828 | PrintF("Call to host function at %p args %08x %08x", |
| 1829 | reinterpret_cast<void*>(external), arg0, arg1); |
| 1830 | if (!stack_aligned) { |
| 1831 | PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1832 | } |
| 1833 | PrintF("\n"); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1834 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1835 | CHECK(stack_aligned); |
| 1836 | SimulatorRuntimeDirectGetterCall target = |
| 1837 | reinterpret_cast<SimulatorRuntimeDirectGetterCall>(external); |
| 1838 | target(arg0, arg1); |
| 1839 | } else if ( |
| 1840 | redirection->type() == ExternalReference::PROFILING_GETTER_CALL) { |
| 1841 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
| 1842 | PrintF("Call to host function at %p args %08x %08x %08x", |
| 1843 | reinterpret_cast<void*>(external), arg0, arg1, arg2); |
| 1844 | if (!stack_aligned) { |
| 1845 | PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1846 | } |
| 1847 | PrintF("\n"); |
| 1848 | } |
| 1849 | CHECK(stack_aligned); |
| 1850 | SimulatorRuntimeProfilingGetterCall target = |
| 1851 | reinterpret_cast<SimulatorRuntimeProfilingGetterCall>( |
| 1852 | external); |
| 1853 | target(arg0, arg1, Redirection::ReverseRedirection(arg2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1854 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1855 | // builtin call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1856 | DCHECK(redirection->type() == ExternalReference::BUILTIN_CALL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1857 | SimulatorRuntimeCall target = |
| 1858 | reinterpret_cast<SimulatorRuntimeCall>(external); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1859 | if (::v8::internal::FLAG_trace_sim || !stack_aligned) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1860 | PrintF( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1861 | "Call to host function at %p " |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1862 | "args %08x, %08x, %08x, %08x, %08x, %08x", |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1863 | FUNCTION_ADDR(target), |
| 1864 | arg0, |
| 1865 | arg1, |
| 1866 | arg2, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1867 | arg3, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1868 | arg4, |
| 1869 | arg5); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1870 | if (!stack_aligned) { |
| 1871 | PrintF(" with unaligned stack %08x\n", get_register(sp)); |
| 1872 | } |
| 1873 | PrintF("\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1874 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1875 | CHECK(stack_aligned); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1876 | int64_t result = target(arg0, arg1, arg2, arg3, arg4, arg5); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1877 | int32_t lo_res = static_cast<int32_t>(result); |
| 1878 | int32_t hi_res = static_cast<int32_t>(result >> 32); |
| 1879 | if (::v8::internal::FLAG_trace_sim) { |
| 1880 | PrintF("Returned %08x\n", lo_res); |
| 1881 | } |
| 1882 | set_register(r0, lo_res); |
| 1883 | set_register(r1, hi_res); |
| 1884 | } |
| 1885 | set_register(lr, saved_lr); |
| 1886 | set_pc(get_register(lr)); |
| 1887 | break; |
| 1888 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1889 | case kBreakpoint: { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1890 | ArmDebugger dbg(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1891 | dbg.Debug(); |
| 1892 | break; |
| 1893 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1894 | // stop uses all codes greater than 1 << 23. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1895 | default: { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1896 | if (svc >= (1 << 23)) { |
| 1897 | uint32_t code = svc & kStopCodeMask; |
| 1898 | if (isWatchedStop(code)) { |
| 1899 | IncreaseStopCounter(code); |
| 1900 | } |
| 1901 | // Stop if it is enabled, otherwise go on jumping over the stop |
| 1902 | // and the message address. |
| 1903 | if (isEnabledStop(code)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1904 | ArmDebugger dbg(this); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1905 | dbg.Stop(instr); |
| 1906 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1907 | set_pc(get_pc() + 2 * Instruction::kInstrSize); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1908 | } |
| 1909 | } else { |
| 1910 | // This is not a valid svc code. |
| 1911 | UNREACHABLE(); |
| 1912 | break; |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1919 | double Simulator::canonicalizeNaN(double value) { |
| 1920 | return (FPSCR_default_NaN_mode_ && std::isnan(value)) ? |
| 1921 | FixedDoubleArray::canonical_not_the_hole_nan_as_double() : value; |
| 1922 | } |
| 1923 | |
| 1924 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1925 | // Stop helper functions. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1926 | bool Simulator::isStopInstruction(Instruction* instr) { |
| 1927 | return (instr->Bits(27, 24) == 0xF) && (instr->SvcValue() >= kStopCode); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | bool Simulator::isWatchedStop(uint32_t code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1932 | DCHECK(code <= kMaxStopCode); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1933 | return code < kNumOfWatchedStops; |
| 1934 | } |
| 1935 | |
| 1936 | |
| 1937 | bool Simulator::isEnabledStop(uint32_t code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1938 | DCHECK(code <= kMaxStopCode); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1939 | // Unwatched stops are always enabled. |
| 1940 | return !isWatchedStop(code) || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1941 | !(watched_stops_[code].count & kStopDisabledBit); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | |
| 1945 | void Simulator::EnableStop(uint32_t code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1946 | DCHECK(isWatchedStop(code)); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1947 | if (!isEnabledStop(code)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1948 | watched_stops_[code].count &= ~kStopDisabledBit; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | void Simulator::DisableStop(uint32_t code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1954 | DCHECK(isWatchedStop(code)); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1955 | if (isEnabledStop(code)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1956 | watched_stops_[code].count |= kStopDisabledBit; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | |
| 1961 | void Simulator::IncreaseStopCounter(uint32_t code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1962 | DCHECK(code <= kMaxStopCode); |
| 1963 | DCHECK(isWatchedStop(code)); |
| 1964 | if ((watched_stops_[code].count & ~(1 << 31)) == 0x7fffffff) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1965 | PrintF("Stop counter for code %i has overflowed.\n" |
| 1966 | "Enabling this code and reseting the counter to 0.\n", code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1967 | watched_stops_[code].count = 0; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1968 | EnableStop(code); |
| 1969 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1970 | watched_stops_[code].count++; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | |
| 1975 | // Print a stop status. |
| 1976 | void Simulator::PrintStopInfo(uint32_t code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1977 | DCHECK(code <= kMaxStopCode); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1978 | if (!isWatchedStop(code)) { |
| 1979 | PrintF("Stop not watched."); |
| 1980 | } else { |
| 1981 | const char* state = isEnabledStop(code) ? "Enabled" : "Disabled"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1982 | int32_t count = watched_stops_[code].count & ~kStopDisabledBit; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1983 | // Don't print the state of unused breakpoints. |
| 1984 | if (count != 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1985 | if (watched_stops_[code].desc) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1986 | PrintF("stop %i - 0x%x: \t%s, \tcounter = %i, \t%s\n", |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1987 | code, code, state, count, watched_stops_[code].desc); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1988 | } else { |
| 1989 | PrintF("stop %i - 0x%x: \t%s, \tcounter = %i\n", |
| 1990 | code, code, state, count); |
| 1991 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | |
| 1997 | // Handle execution based on instruction types. |
| 1998 | |
| 1999 | // Instruction types 0 and 1 are both rolled into one function because they |
| 2000 | // only differ in the handling of the shifter_operand. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2001 | void Simulator::DecodeType01(Instruction* instr) { |
| 2002 | int type = instr->TypeValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2003 | if ((type == 0) && instr->IsSpecialType0()) { |
| 2004 | // multiply instruction or extra loads and stores |
| 2005 | if (instr->Bits(7, 4) == 9) { |
| 2006 | if (instr->Bit(24) == 0) { |
| 2007 | // Raw field decoding here. Multiply instructions have their Rd in |
| 2008 | // funny places. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2009 | int rn = instr->RnValue(); |
| 2010 | int rm = instr->RmValue(); |
| 2011 | int rs = instr->RsValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2012 | int32_t rs_val = get_register(rs); |
| 2013 | int32_t rm_val = get_register(rm); |
| 2014 | if (instr->Bit(23) == 0) { |
| 2015 | if (instr->Bit(21) == 0) { |
| 2016 | // The MUL instruction description (A 4.1.33) refers to Rd as being |
| 2017 | // the destination for the operation, but it confusingly uses the |
| 2018 | // Rn field to encode it. |
| 2019 | // Format(instr, "mul'cond's 'rn, 'rm, 'rs"); |
| 2020 | int rd = rn; // Remap the rn field to the Rd register. |
| 2021 | int32_t alu_out = rm_val * rs_val; |
| 2022 | set_register(rd, alu_out); |
| 2023 | if (instr->HasS()) { |
| 2024 | SetNZFlags(alu_out); |
| 2025 | } |
| 2026 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2027 | int rd = instr->RdValue(); |
| 2028 | int32_t acc_value = get_register(rd); |
| 2029 | if (instr->Bit(22) == 0) { |
| 2030 | // The MLA instruction description (A 4.1.28) refers to the order |
| 2031 | // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the |
| 2032 | // Rn field to encode the Rd register and the Rd field to encode |
| 2033 | // the Rn register. |
| 2034 | // Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd"); |
| 2035 | int32_t mul_out = rm_val * rs_val; |
| 2036 | int32_t result = acc_value + mul_out; |
| 2037 | set_register(rn, result); |
| 2038 | } else { |
| 2039 | // Format(instr, "mls'cond's 'rn, 'rm, 'rs, 'rd"); |
| 2040 | int32_t mul_out = rm_val * rs_val; |
| 2041 | int32_t result = acc_value - mul_out; |
| 2042 | set_register(rn, result); |
| 2043 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2044 | } |
| 2045 | } else { |
| 2046 | // The signed/long multiply instructions use the terms RdHi and RdLo |
| 2047 | // when referring to the target registers. They are mapped to the Rn |
| 2048 | // and Rd fields as follows: |
| 2049 | // RdLo == Rd |
| 2050 | // RdHi == Rn (This is confusingly stored in variable rd here |
| 2051 | // because the mul instruction from above uses the |
| 2052 | // Rn field to encode the Rd register. Good luck figuring |
| 2053 | // this out without reading the ARM instruction manual |
| 2054 | // at a very detailed level.) |
| 2055 | // Format(instr, "'um'al'cond's 'rd, 'rn, 'rs, 'rm"); |
| 2056 | int rd_hi = rn; // Remap the rn field to the RdHi register. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2057 | int rd_lo = instr->RdValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2058 | int32_t hi_res = 0; |
| 2059 | int32_t lo_res = 0; |
| 2060 | if (instr->Bit(22) == 1) { |
| 2061 | int64_t left_op = static_cast<int32_t>(rm_val); |
| 2062 | int64_t right_op = static_cast<int32_t>(rs_val); |
| 2063 | uint64_t result = left_op * right_op; |
| 2064 | hi_res = static_cast<int32_t>(result >> 32); |
| 2065 | lo_res = static_cast<int32_t>(result & 0xffffffff); |
| 2066 | } else { |
| 2067 | // unsigned multiply |
| 2068 | uint64_t left_op = static_cast<uint32_t>(rm_val); |
| 2069 | uint64_t right_op = static_cast<uint32_t>(rs_val); |
| 2070 | uint64_t result = left_op * right_op; |
| 2071 | hi_res = static_cast<int32_t>(result >> 32); |
| 2072 | lo_res = static_cast<int32_t>(result & 0xffffffff); |
| 2073 | } |
| 2074 | set_register(rd_lo, lo_res); |
| 2075 | set_register(rd_hi, hi_res); |
| 2076 | if (instr->HasS()) { |
| 2077 | UNIMPLEMENTED(); |
| 2078 | } |
| 2079 | } |
| 2080 | } else { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2081 | UNIMPLEMENTED(); // Not used by V8. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2082 | } |
| 2083 | } else { |
| 2084 | // extra load/store instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2085 | int rd = instr->RdValue(); |
| 2086 | int rn = instr->RnValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2087 | int32_t rn_val = get_register(rn); |
| 2088 | int32_t addr = 0; |
| 2089 | if (instr->Bit(22) == 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2090 | int rm = instr->RmValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2091 | int32_t rm_val = get_register(rm); |
| 2092 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2093 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2094 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2095 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2096 | addr = rn_val; |
| 2097 | rn_val -= rm_val; |
| 2098 | set_register(rn, rn_val); |
| 2099 | break; |
| 2100 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2101 | case ia_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2102 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2103 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2104 | addr = rn_val; |
| 2105 | rn_val += rm_val; |
| 2106 | set_register(rn, rn_val); |
| 2107 | break; |
| 2108 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2109 | case db_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2110 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w"); |
| 2111 | rn_val -= rm_val; |
| 2112 | addr = rn_val; |
| 2113 | if (instr->HasW()) { |
| 2114 | set_register(rn, rn_val); |
| 2115 | } |
| 2116 | break; |
| 2117 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2118 | case ib_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2119 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w"); |
| 2120 | rn_val += rm_val; |
| 2121 | addr = rn_val; |
| 2122 | if (instr->HasW()) { |
| 2123 | set_register(rn, rn_val); |
| 2124 | } |
| 2125 | break; |
| 2126 | } |
| 2127 | default: { |
| 2128 | // The PU field is a 2-bit field. |
| 2129 | UNREACHABLE(); |
| 2130 | break; |
| 2131 | } |
| 2132 | } |
| 2133 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2134 | int32_t imm_val = (instr->ImmedHValue() << 4) | instr->ImmedLValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2135 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2136 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2137 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2138 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2139 | addr = rn_val; |
| 2140 | rn_val -= imm_val; |
| 2141 | set_register(rn, rn_val); |
| 2142 | break; |
| 2143 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2144 | case ia_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2145 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2146 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2147 | addr = rn_val; |
| 2148 | rn_val += imm_val; |
| 2149 | set_register(rn, rn_val); |
| 2150 | break; |
| 2151 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2152 | case db_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2153 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w"); |
| 2154 | rn_val -= imm_val; |
| 2155 | addr = rn_val; |
| 2156 | if (instr->HasW()) { |
| 2157 | set_register(rn, rn_val); |
| 2158 | } |
| 2159 | break; |
| 2160 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2161 | case ib_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2162 | // Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w"); |
| 2163 | rn_val += imm_val; |
| 2164 | addr = rn_val; |
| 2165 | if (instr->HasW()) { |
| 2166 | set_register(rn, rn_val); |
| 2167 | } |
| 2168 | break; |
| 2169 | } |
| 2170 | default: { |
| 2171 | // The PU field is a 2-bit field. |
| 2172 | UNREACHABLE(); |
| 2173 | break; |
| 2174 | } |
| 2175 | } |
| 2176 | } |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2177 | if (((instr->Bits(7, 4) & 0xd) == 0xd) && (instr->Bit(20) == 0)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2178 | DCHECK((rd % 2) == 0); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2179 | if (instr->HasH()) { |
| 2180 | // The strd instruction. |
| 2181 | int32_t value1 = get_register(rd); |
| 2182 | int32_t value2 = get_register(rd+1); |
| 2183 | WriteDW(addr, value1, value2); |
| 2184 | } else { |
| 2185 | // The ldrd instruction. |
| 2186 | int* rn_data = ReadDW(addr); |
| 2187 | set_dw_register(rd, rn_data); |
| 2188 | } |
| 2189 | } else if (instr->HasH()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2190 | if (instr->HasSign()) { |
| 2191 | if (instr->HasL()) { |
| 2192 | int16_t val = ReadH(addr, instr); |
| 2193 | set_register(rd, val); |
| 2194 | } else { |
| 2195 | int16_t val = get_register(rd); |
| 2196 | WriteH(addr, val, instr); |
| 2197 | } |
| 2198 | } else { |
| 2199 | if (instr->HasL()) { |
| 2200 | uint16_t val = ReadHU(addr, instr); |
| 2201 | set_register(rd, val); |
| 2202 | } else { |
| 2203 | uint16_t val = get_register(rd); |
| 2204 | WriteH(addr, val, instr); |
| 2205 | } |
| 2206 | } |
| 2207 | } else { |
| 2208 | // signed byte loads |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2209 | DCHECK(instr->HasSign()); |
| 2210 | DCHECK(instr->HasL()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2211 | int8_t val = ReadB(addr); |
| 2212 | set_register(rd, val); |
| 2213 | } |
| 2214 | return; |
| 2215 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2216 | } else if ((type == 0) && instr->IsMiscType0()) { |
| 2217 | if (instr->Bits(22, 21) == 1) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2218 | int rm = instr->RmValue(); |
| 2219 | switch (instr->BitField(7, 4)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2220 | case BX: |
| 2221 | set_pc(get_register(rm)); |
| 2222 | break; |
| 2223 | case BLX: { |
| 2224 | uint32_t old_pc = get_pc(); |
| 2225 | set_pc(get_register(rm)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2226 | set_register(lr, old_pc + Instruction::kInstrSize); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2227 | break; |
| 2228 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2229 | case BKPT: { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2230 | ArmDebugger dbg(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2231 | PrintF("Simulator hit BKPT.\n"); |
| 2232 | dbg.Debug(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2233 | break; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2234 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2235 | default: |
| 2236 | UNIMPLEMENTED(); |
| 2237 | } |
| 2238 | } else if (instr->Bits(22, 21) == 3) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2239 | int rm = instr->RmValue(); |
| 2240 | int rd = instr->RdValue(); |
| 2241 | switch (instr->BitField(7, 4)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2242 | case CLZ: { |
| 2243 | uint32_t bits = get_register(rm); |
| 2244 | int leading_zeros = 0; |
| 2245 | if (bits == 0) { |
| 2246 | leading_zeros = 32; |
| 2247 | } else { |
| 2248 | while ((bits & 0x80000000u) == 0) { |
| 2249 | bits <<= 1; |
| 2250 | leading_zeros++; |
| 2251 | } |
| 2252 | } |
| 2253 | set_register(rd, leading_zeros); |
| 2254 | break; |
| 2255 | } |
| 2256 | default: |
| 2257 | UNIMPLEMENTED(); |
| 2258 | } |
| 2259 | } else { |
| 2260 | PrintF("%08x\n", instr->InstructionBits()); |
| 2261 | UNIMPLEMENTED(); |
| 2262 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2263 | } else if ((type == 1) && instr->IsNopType1()) { |
| 2264 | // NOP. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2265 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2266 | int rd = instr->RdValue(); |
| 2267 | int rn = instr->RnValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2268 | int32_t rn_val = get_register(rn); |
| 2269 | int32_t shifter_operand = 0; |
| 2270 | bool shifter_carry_out = 0; |
| 2271 | if (type == 0) { |
| 2272 | shifter_operand = GetShiftRm(instr, &shifter_carry_out); |
| 2273 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2274 | DCHECK(instr->TypeValue() == 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2275 | shifter_operand = GetImm(instr, &shifter_carry_out); |
| 2276 | } |
| 2277 | int32_t alu_out; |
| 2278 | |
| 2279 | switch (instr->OpcodeField()) { |
| 2280 | case AND: { |
| 2281 | // Format(instr, "and'cond's 'rd, 'rn, 'shift_rm"); |
| 2282 | // Format(instr, "and'cond's 'rd, 'rn, 'imm"); |
| 2283 | alu_out = rn_val & shifter_operand; |
| 2284 | set_register(rd, alu_out); |
| 2285 | if (instr->HasS()) { |
| 2286 | SetNZFlags(alu_out); |
| 2287 | SetCFlag(shifter_carry_out); |
| 2288 | } |
| 2289 | break; |
| 2290 | } |
| 2291 | |
| 2292 | case EOR: { |
| 2293 | // Format(instr, "eor'cond's 'rd, 'rn, 'shift_rm"); |
| 2294 | // Format(instr, "eor'cond's 'rd, 'rn, 'imm"); |
| 2295 | alu_out = rn_val ^ shifter_operand; |
| 2296 | set_register(rd, alu_out); |
| 2297 | if (instr->HasS()) { |
| 2298 | SetNZFlags(alu_out); |
| 2299 | SetCFlag(shifter_carry_out); |
| 2300 | } |
| 2301 | break; |
| 2302 | } |
| 2303 | |
| 2304 | case SUB: { |
| 2305 | // Format(instr, "sub'cond's 'rd, 'rn, 'shift_rm"); |
| 2306 | // Format(instr, "sub'cond's 'rd, 'rn, 'imm"); |
| 2307 | alu_out = rn_val - shifter_operand; |
| 2308 | set_register(rd, alu_out); |
| 2309 | if (instr->HasS()) { |
| 2310 | SetNZFlags(alu_out); |
| 2311 | SetCFlag(!BorrowFrom(rn_val, shifter_operand)); |
| 2312 | SetVFlag(OverflowFrom(alu_out, rn_val, shifter_operand, false)); |
| 2313 | } |
| 2314 | break; |
| 2315 | } |
| 2316 | |
| 2317 | case RSB: { |
| 2318 | // Format(instr, "rsb'cond's 'rd, 'rn, 'shift_rm"); |
| 2319 | // Format(instr, "rsb'cond's 'rd, 'rn, 'imm"); |
| 2320 | alu_out = shifter_operand - rn_val; |
| 2321 | set_register(rd, alu_out); |
| 2322 | if (instr->HasS()) { |
| 2323 | SetNZFlags(alu_out); |
| 2324 | SetCFlag(!BorrowFrom(shifter_operand, rn_val)); |
| 2325 | SetVFlag(OverflowFrom(alu_out, shifter_operand, rn_val, false)); |
| 2326 | } |
| 2327 | break; |
| 2328 | } |
| 2329 | |
| 2330 | case ADD: { |
| 2331 | // Format(instr, "add'cond's 'rd, 'rn, 'shift_rm"); |
| 2332 | // Format(instr, "add'cond's 'rd, 'rn, 'imm"); |
| 2333 | alu_out = rn_val + shifter_operand; |
| 2334 | set_register(rd, alu_out); |
| 2335 | if (instr->HasS()) { |
| 2336 | SetNZFlags(alu_out); |
| 2337 | SetCFlag(CarryFrom(rn_val, shifter_operand)); |
| 2338 | SetVFlag(OverflowFrom(alu_out, rn_val, shifter_operand, true)); |
| 2339 | } |
| 2340 | break; |
| 2341 | } |
| 2342 | |
| 2343 | case ADC: { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2344 | // Format(instr, "adc'cond's 'rd, 'rn, 'shift_rm"); |
| 2345 | // Format(instr, "adc'cond's 'rd, 'rn, 'imm"); |
| 2346 | alu_out = rn_val + shifter_operand + GetCarry(); |
| 2347 | set_register(rd, alu_out); |
| 2348 | if (instr->HasS()) { |
| 2349 | SetNZFlags(alu_out); |
| 2350 | SetCFlag(CarryFrom(rn_val, shifter_operand, GetCarry())); |
| 2351 | SetVFlag(OverflowFrom(alu_out, rn_val, shifter_operand, true)); |
| 2352 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | } |
| 2355 | |
| 2356 | case SBC: { |
| 2357 | Format(instr, "sbc'cond's 'rd, 'rn, 'shift_rm"); |
| 2358 | Format(instr, "sbc'cond's 'rd, 'rn, 'imm"); |
| 2359 | break; |
| 2360 | } |
| 2361 | |
| 2362 | case RSC: { |
| 2363 | Format(instr, "rsc'cond's 'rd, 'rn, 'shift_rm"); |
| 2364 | Format(instr, "rsc'cond's 'rd, 'rn, 'imm"); |
| 2365 | break; |
| 2366 | } |
| 2367 | |
| 2368 | case TST: { |
| 2369 | if (instr->HasS()) { |
| 2370 | // Format(instr, "tst'cond 'rn, 'shift_rm"); |
| 2371 | // Format(instr, "tst'cond 'rn, 'imm"); |
| 2372 | alu_out = rn_val & shifter_operand; |
| 2373 | SetNZFlags(alu_out); |
| 2374 | SetCFlag(shifter_carry_out); |
| 2375 | } else { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2376 | // Format(instr, "movw'cond 'rd, 'imm"). |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2377 | alu_out = instr->ImmedMovwMovtValue(); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2378 | set_register(rd, alu_out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2379 | } |
| 2380 | break; |
| 2381 | } |
| 2382 | |
| 2383 | case TEQ: { |
| 2384 | if (instr->HasS()) { |
| 2385 | // Format(instr, "teq'cond 'rn, 'shift_rm"); |
| 2386 | // Format(instr, "teq'cond 'rn, 'imm"); |
| 2387 | alu_out = rn_val ^ shifter_operand; |
| 2388 | SetNZFlags(alu_out); |
| 2389 | SetCFlag(shifter_carry_out); |
| 2390 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2391 | // Other instructions matching this pattern are handled in the |
| 2392 | // miscellaneous instructions part above. |
| 2393 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2394 | } |
| 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | case CMP: { |
| 2399 | if (instr->HasS()) { |
| 2400 | // Format(instr, "cmp'cond 'rn, 'shift_rm"); |
| 2401 | // Format(instr, "cmp'cond 'rn, 'imm"); |
| 2402 | alu_out = rn_val - shifter_operand; |
| 2403 | SetNZFlags(alu_out); |
| 2404 | SetCFlag(!BorrowFrom(rn_val, shifter_operand)); |
| 2405 | SetVFlag(OverflowFrom(alu_out, rn_val, shifter_operand, false)); |
| 2406 | } else { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2407 | // Format(instr, "movt'cond 'rd, 'imm"). |
| 2408 | alu_out = (get_register(rd) & 0xffff) | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2409 | (instr->ImmedMovwMovtValue() << 16); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2410 | set_register(rd, alu_out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2411 | } |
| 2412 | break; |
| 2413 | } |
| 2414 | |
| 2415 | case CMN: { |
| 2416 | if (instr->HasS()) { |
| 2417 | // Format(instr, "cmn'cond 'rn, 'shift_rm"); |
| 2418 | // Format(instr, "cmn'cond 'rn, 'imm"); |
| 2419 | alu_out = rn_val + shifter_operand; |
| 2420 | SetNZFlags(alu_out); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2421 | SetCFlag(CarryFrom(rn_val, shifter_operand)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2422 | SetVFlag(OverflowFrom(alu_out, rn_val, shifter_operand, true)); |
| 2423 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2424 | // Other instructions matching this pattern are handled in the |
| 2425 | // miscellaneous instructions part above. |
| 2426 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2427 | } |
| 2428 | break; |
| 2429 | } |
| 2430 | |
| 2431 | case ORR: { |
| 2432 | // Format(instr, "orr'cond's 'rd, 'rn, 'shift_rm"); |
| 2433 | // Format(instr, "orr'cond's 'rd, 'rn, 'imm"); |
| 2434 | alu_out = rn_val | shifter_operand; |
| 2435 | set_register(rd, alu_out); |
| 2436 | if (instr->HasS()) { |
| 2437 | SetNZFlags(alu_out); |
| 2438 | SetCFlag(shifter_carry_out); |
| 2439 | } |
| 2440 | break; |
| 2441 | } |
| 2442 | |
| 2443 | case MOV: { |
| 2444 | // Format(instr, "mov'cond's 'rd, 'shift_rm"); |
| 2445 | // Format(instr, "mov'cond's 'rd, 'imm"); |
| 2446 | alu_out = shifter_operand; |
| 2447 | set_register(rd, alu_out); |
| 2448 | if (instr->HasS()) { |
| 2449 | SetNZFlags(alu_out); |
| 2450 | SetCFlag(shifter_carry_out); |
| 2451 | } |
| 2452 | break; |
| 2453 | } |
| 2454 | |
| 2455 | case BIC: { |
| 2456 | // Format(instr, "bic'cond's 'rd, 'rn, 'shift_rm"); |
| 2457 | // Format(instr, "bic'cond's 'rd, 'rn, 'imm"); |
| 2458 | alu_out = rn_val & ~shifter_operand; |
| 2459 | set_register(rd, alu_out); |
| 2460 | if (instr->HasS()) { |
| 2461 | SetNZFlags(alu_out); |
| 2462 | SetCFlag(shifter_carry_out); |
| 2463 | } |
| 2464 | break; |
| 2465 | } |
| 2466 | |
| 2467 | case MVN: { |
| 2468 | // Format(instr, "mvn'cond's 'rd, 'shift_rm"); |
| 2469 | // Format(instr, "mvn'cond's 'rd, 'imm"); |
| 2470 | alu_out = ~shifter_operand; |
| 2471 | set_register(rd, alu_out); |
| 2472 | if (instr->HasS()) { |
| 2473 | SetNZFlags(alu_out); |
| 2474 | SetCFlag(shifter_carry_out); |
| 2475 | } |
| 2476 | break; |
| 2477 | } |
| 2478 | |
| 2479 | default: { |
| 2480 | UNREACHABLE(); |
| 2481 | break; |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2488 | void Simulator::DecodeType2(Instruction* instr) { |
| 2489 | int rd = instr->RdValue(); |
| 2490 | int rn = instr->RnValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2491 | int32_t rn_val = get_register(rn); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2492 | int32_t im_val = instr->Offset12Value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2493 | int32_t addr = 0; |
| 2494 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2495 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2496 | // Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2497 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2498 | addr = rn_val; |
| 2499 | rn_val -= im_val; |
| 2500 | set_register(rn, rn_val); |
| 2501 | break; |
| 2502 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2503 | case ia_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2504 | // Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2505 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2506 | addr = rn_val; |
| 2507 | rn_val += im_val; |
| 2508 | set_register(rn, rn_val); |
| 2509 | break; |
| 2510 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2511 | case db_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2512 | // Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w"); |
| 2513 | rn_val -= im_val; |
| 2514 | addr = rn_val; |
| 2515 | if (instr->HasW()) { |
| 2516 | set_register(rn, rn_val); |
| 2517 | } |
| 2518 | break; |
| 2519 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2520 | case ib_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2521 | // Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w"); |
| 2522 | rn_val += im_val; |
| 2523 | addr = rn_val; |
| 2524 | if (instr->HasW()) { |
| 2525 | set_register(rn, rn_val); |
| 2526 | } |
| 2527 | break; |
| 2528 | } |
| 2529 | default: { |
| 2530 | UNREACHABLE(); |
| 2531 | break; |
| 2532 | } |
| 2533 | } |
| 2534 | if (instr->HasB()) { |
| 2535 | if (instr->HasL()) { |
| 2536 | byte val = ReadBU(addr); |
| 2537 | set_register(rd, val); |
| 2538 | } else { |
| 2539 | byte val = get_register(rd); |
| 2540 | WriteB(addr, val); |
| 2541 | } |
| 2542 | } else { |
| 2543 | if (instr->HasL()) { |
| 2544 | set_register(rd, ReadW(addr, instr)); |
| 2545 | } else { |
| 2546 | WriteW(addr, get_register(rd), instr); |
| 2547 | } |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2552 | void Simulator::DecodeType3(Instruction* instr) { |
| 2553 | int rd = instr->RdValue(); |
| 2554 | int rn = instr->RnValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2555 | int32_t rn_val = get_register(rn); |
| 2556 | bool shifter_carry_out = 0; |
| 2557 | int32_t shifter_operand = GetShiftRm(instr, &shifter_carry_out); |
| 2558 | int32_t addr = 0; |
| 2559 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2560 | case da_x: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2561 | DCHECK(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2562 | Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm"); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 2563 | UNIMPLEMENTED(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2566 | case ia_x: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2567 | if (instr->Bit(4) == 0) { |
| 2568 | // Memop. |
| 2569 | } else { |
| 2570 | if (instr->Bit(5) == 0) { |
| 2571 | switch (instr->Bits(22, 21)) { |
| 2572 | case 0: |
| 2573 | if (instr->Bit(20) == 0) { |
| 2574 | if (instr->Bit(6) == 0) { |
| 2575 | // Pkhbt. |
| 2576 | uint32_t rn_val = get_register(rn); |
| 2577 | uint32_t rm_val = get_register(instr->RmValue()); |
| 2578 | int32_t shift = instr->Bits(11, 7); |
| 2579 | rm_val <<= shift; |
| 2580 | set_register(rd, (rn_val & 0xFFFF) | (rm_val & 0xFFFF0000U)); |
| 2581 | } else { |
| 2582 | // Pkhtb. |
| 2583 | uint32_t rn_val = get_register(rn); |
| 2584 | int32_t rm_val = get_register(instr->RmValue()); |
| 2585 | int32_t shift = instr->Bits(11, 7); |
| 2586 | if (shift == 0) { |
| 2587 | shift = 32; |
| 2588 | } |
| 2589 | rm_val >>= shift; |
| 2590 | set_register(rd, (rn_val & 0xFFFF0000U) | (rm_val & 0xFFFF)); |
| 2591 | } |
| 2592 | } else { |
| 2593 | UNIMPLEMENTED(); |
| 2594 | } |
| 2595 | break; |
| 2596 | case 1: |
| 2597 | UNIMPLEMENTED(); |
| 2598 | break; |
| 2599 | case 2: |
| 2600 | UNIMPLEMENTED(); |
| 2601 | break; |
| 2602 | case 3: { |
| 2603 | // Usat. |
| 2604 | int32_t sat_pos = instr->Bits(20, 16); |
| 2605 | int32_t sat_val = (1 << sat_pos) - 1; |
| 2606 | int32_t shift = instr->Bits(11, 7); |
| 2607 | int32_t shift_type = instr->Bit(6); |
| 2608 | int32_t rm_val = get_register(instr->RmValue()); |
| 2609 | if (shift_type == 0) { // LSL |
| 2610 | rm_val <<= shift; |
| 2611 | } else { // ASR |
| 2612 | rm_val >>= shift; |
| 2613 | } |
| 2614 | // If saturation occurs, the Q flag should be set in the CPSR. |
| 2615 | // There is no Q flag yet, and no instruction (MRS) to read the |
| 2616 | // CPSR directly. |
| 2617 | if (rm_val > sat_val) { |
| 2618 | rm_val = sat_val; |
| 2619 | } else if (rm_val < 0) { |
| 2620 | rm_val = 0; |
| 2621 | } |
| 2622 | set_register(rd, rm_val); |
| 2623 | break; |
| 2624 | } |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 2625 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2626 | } else { |
| 2627 | switch (instr->Bits(22, 21)) { |
| 2628 | case 0: |
| 2629 | UNIMPLEMENTED(); |
| 2630 | break; |
| 2631 | case 1: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2632 | if (instr->Bits(9, 6) == 1) { |
| 2633 | if (instr->Bit(20) == 0) { |
| 2634 | if (instr->Bits(19, 16) == 0xF) { |
| 2635 | // Sxtb. |
| 2636 | int32_t rm_val = get_register(instr->RmValue()); |
| 2637 | int32_t rotate = instr->Bits(11, 10); |
| 2638 | switch (rotate) { |
| 2639 | case 0: |
| 2640 | break; |
| 2641 | case 1: |
| 2642 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2643 | break; |
| 2644 | case 2: |
| 2645 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2646 | break; |
| 2647 | case 3: |
| 2648 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2649 | break; |
| 2650 | } |
| 2651 | set_register(rd, static_cast<int8_t>(rm_val)); |
| 2652 | } else { |
| 2653 | // Sxtab. |
| 2654 | int32_t rn_val = get_register(rn); |
| 2655 | int32_t rm_val = get_register(instr->RmValue()); |
| 2656 | int32_t rotate = instr->Bits(11, 10); |
| 2657 | switch (rotate) { |
| 2658 | case 0: |
| 2659 | break; |
| 2660 | case 1: |
| 2661 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2662 | break; |
| 2663 | case 2: |
| 2664 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2665 | break; |
| 2666 | case 3: |
| 2667 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2668 | break; |
| 2669 | } |
| 2670 | set_register(rd, rn_val + static_cast<int8_t>(rm_val)); |
| 2671 | } |
| 2672 | } else { |
| 2673 | if (instr->Bits(19, 16) == 0xF) { |
| 2674 | // Sxth. |
| 2675 | int32_t rm_val = get_register(instr->RmValue()); |
| 2676 | int32_t rotate = instr->Bits(11, 10); |
| 2677 | switch (rotate) { |
| 2678 | case 0: |
| 2679 | break; |
| 2680 | case 1: |
| 2681 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2682 | break; |
| 2683 | case 2: |
| 2684 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2685 | break; |
| 2686 | case 3: |
| 2687 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2688 | break; |
| 2689 | } |
| 2690 | set_register(rd, static_cast<int16_t>(rm_val)); |
| 2691 | } else { |
| 2692 | // Sxtah. |
| 2693 | int32_t rn_val = get_register(rn); |
| 2694 | int32_t rm_val = get_register(instr->RmValue()); |
| 2695 | int32_t rotate = instr->Bits(11, 10); |
| 2696 | switch (rotate) { |
| 2697 | case 0: |
| 2698 | break; |
| 2699 | case 1: |
| 2700 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2701 | break; |
| 2702 | case 2: |
| 2703 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2704 | break; |
| 2705 | case 3: |
| 2706 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2707 | break; |
| 2708 | } |
| 2709 | set_register(rd, rn_val + static_cast<int16_t>(rm_val)); |
| 2710 | } |
| 2711 | } |
| 2712 | } else { |
| 2713 | UNREACHABLE(); |
| 2714 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2715 | break; |
| 2716 | case 2: |
| 2717 | if ((instr->Bit(20) == 0) && (instr->Bits(9, 6) == 1)) { |
| 2718 | if (instr->Bits(19, 16) == 0xF) { |
| 2719 | // Uxtb16. |
| 2720 | uint32_t rm_val = get_register(instr->RmValue()); |
| 2721 | int32_t rotate = instr->Bits(11, 10); |
| 2722 | switch (rotate) { |
| 2723 | case 0: |
| 2724 | break; |
| 2725 | case 1: |
| 2726 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2727 | break; |
| 2728 | case 2: |
| 2729 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2730 | break; |
| 2731 | case 3: |
| 2732 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2733 | break; |
| 2734 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2735 | set_register(rd, (rm_val & 0xFF) | (rm_val & 0xFF0000)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2736 | } else { |
| 2737 | UNIMPLEMENTED(); |
| 2738 | } |
| 2739 | } else { |
| 2740 | UNIMPLEMENTED(); |
| 2741 | } |
| 2742 | break; |
| 2743 | case 3: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2744 | if ((instr->Bits(9, 6) == 1)) { |
| 2745 | if (instr->Bit(20) == 0) { |
| 2746 | if (instr->Bits(19, 16) == 0xF) { |
| 2747 | // Uxtb. |
| 2748 | uint32_t rm_val = get_register(instr->RmValue()); |
| 2749 | int32_t rotate = instr->Bits(11, 10); |
| 2750 | switch (rotate) { |
| 2751 | case 0: |
| 2752 | break; |
| 2753 | case 1: |
| 2754 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2755 | break; |
| 2756 | case 2: |
| 2757 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2758 | break; |
| 2759 | case 3: |
| 2760 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2761 | break; |
| 2762 | } |
| 2763 | set_register(rd, (rm_val & 0xFF)); |
| 2764 | } else { |
| 2765 | // Uxtab. |
| 2766 | uint32_t rn_val = get_register(rn); |
| 2767 | uint32_t rm_val = get_register(instr->RmValue()); |
| 2768 | int32_t rotate = instr->Bits(11, 10); |
| 2769 | switch (rotate) { |
| 2770 | case 0: |
| 2771 | break; |
| 2772 | case 1: |
| 2773 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2774 | break; |
| 2775 | case 2: |
| 2776 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2777 | break; |
| 2778 | case 3: |
| 2779 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2780 | break; |
| 2781 | } |
| 2782 | set_register(rd, rn_val + (rm_val & 0xFF)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2783 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2784 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2785 | if (instr->Bits(19, 16) == 0xF) { |
| 2786 | // Uxth. |
| 2787 | uint32_t rm_val = get_register(instr->RmValue()); |
| 2788 | int32_t rotate = instr->Bits(11, 10); |
| 2789 | switch (rotate) { |
| 2790 | case 0: |
| 2791 | break; |
| 2792 | case 1: |
| 2793 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2794 | break; |
| 2795 | case 2: |
| 2796 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2797 | break; |
| 2798 | case 3: |
| 2799 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2800 | break; |
| 2801 | } |
| 2802 | set_register(rd, (rm_val & 0xFFFF)); |
| 2803 | } else { |
| 2804 | // Uxtah. |
| 2805 | uint32_t rn_val = get_register(rn); |
| 2806 | uint32_t rm_val = get_register(instr->RmValue()); |
| 2807 | int32_t rotate = instr->Bits(11, 10); |
| 2808 | switch (rotate) { |
| 2809 | case 0: |
| 2810 | break; |
| 2811 | case 1: |
| 2812 | rm_val = (rm_val >> 8) | (rm_val << 24); |
| 2813 | break; |
| 2814 | case 2: |
| 2815 | rm_val = (rm_val >> 16) | (rm_val << 16); |
| 2816 | break; |
| 2817 | case 3: |
| 2818 | rm_val = (rm_val >> 24) | (rm_val << 8); |
| 2819 | break; |
| 2820 | } |
| 2821 | set_register(rd, rn_val + (rm_val & 0xFFFF)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2822 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2823 | } |
| 2824 | } else { |
| 2825 | UNIMPLEMENTED(); |
| 2826 | } |
| 2827 | break; |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 2828 | } |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 2829 | } |
| 2830 | return; |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 2831 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2832 | break; |
| 2833 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2834 | case db_x: { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2835 | if (instr->Bits(22, 20) == 0x5) { |
| 2836 | if (instr->Bits(7, 4) == 0x1) { |
| 2837 | int rm = instr->RmValue(); |
| 2838 | int32_t rm_val = get_register(rm); |
| 2839 | int rs = instr->RsValue(); |
| 2840 | int32_t rs_val = get_register(rs); |
| 2841 | if (instr->Bits(15, 12) == 0xF) { |
| 2842 | // SMMUL (in V8 notation matching ARM ISA format) |
| 2843 | // Format(instr, "smmul'cond 'rn, 'rm, 'rs"); |
| 2844 | rn_val = base::bits::SignedMulHigh32(rm_val, rs_val); |
| 2845 | } else { |
| 2846 | // SMMLA (in V8 notation matching ARM ISA format) |
| 2847 | // Format(instr, "smmla'cond 'rn, 'rm, 'rs, 'rd"); |
| 2848 | int rd = instr->RdValue(); |
| 2849 | int32_t rd_val = get_register(rd); |
| 2850 | rn_val = base::bits::SignedMulHighAndAdd32(rm_val, rs_val, rd_val); |
| 2851 | } |
| 2852 | set_register(rn, rn_val); |
| 2853 | return; |
| 2854 | } |
| 2855 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2856 | if (FLAG_enable_sudiv) { |
| 2857 | if (instr->Bits(5, 4) == 0x1) { |
| 2858 | if ((instr->Bit(22) == 0x0) && (instr->Bit(20) == 0x1)) { |
| 2859 | // (s/u)div (in V8 notation matching ARM ISA format) rn = rm/rs |
| 2860 | // Format(instr, "'(s/u)div'cond'b 'rn, 'rm, 'rs); |
| 2861 | int rm = instr->RmValue(); |
| 2862 | int32_t rm_val = get_register(rm); |
| 2863 | int rs = instr->RsValue(); |
| 2864 | int32_t rs_val = get_register(rs); |
| 2865 | int32_t ret_val = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2866 | // udiv |
| 2867 | if (instr->Bit(21) == 0x1) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2868 | ret_val = bit_cast<int32_t>(base::bits::UnsignedDiv32( |
| 2869 | bit_cast<uint32_t>(rm_val), bit_cast<uint32_t>(rs_val))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2870 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2871 | ret_val = base::bits::SignedDiv32(rm_val, rs_val); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2872 | } |
| 2873 | set_register(rn, ret_val); |
| 2874 | return; |
| 2875 | } |
| 2876 | } |
| 2877 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2878 | // Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w"); |
| 2879 | addr = rn_val - shifter_operand; |
| 2880 | if (instr->HasW()) { |
| 2881 | set_register(rn, addr); |
| 2882 | } |
| 2883 | break; |
| 2884 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2885 | case ib_x: { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2886 | if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) { |
| 2887 | uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2888 | uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2889 | uint32_t msbit = widthminus1 + lsbit; |
| 2890 | if (msbit <= 31) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2891 | if (instr->Bit(22)) { |
| 2892 | // ubfx - unsigned bitfield extract. |
| 2893 | uint32_t rm_val = |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2894 | static_cast<uint32_t>(get_register(instr->RmValue())); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2895 | uint32_t extr_val = rm_val << (31 - msbit); |
| 2896 | extr_val = extr_val >> (31 - widthminus1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2897 | set_register(instr->RdValue(), extr_val); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2898 | } else { |
| 2899 | // sbfx - signed bitfield extract. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2900 | int32_t rm_val = get_register(instr->RmValue()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2901 | int32_t extr_val = rm_val << (31 - msbit); |
| 2902 | extr_val = extr_val >> (31 - widthminus1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2903 | set_register(instr->RdValue(), extr_val); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2904 | } |
| 2905 | } else { |
| 2906 | UNREACHABLE(); |
| 2907 | } |
| 2908 | return; |
| 2909 | } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) { |
| 2910 | uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7)); |
| 2911 | uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16)); |
| 2912 | if (msbit >= lsbit) { |
| 2913 | // bfc or bfi - bitfield clear/insert. |
| 2914 | uint32_t rd_val = |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2915 | static_cast<uint32_t>(get_register(instr->RdValue())); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2916 | uint32_t bitcount = msbit - lsbit + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2917 | uint32_t mask = 0xffffffffu >> (32 - bitcount); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2918 | rd_val &= ~(mask << lsbit); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2919 | if (instr->RmValue() != 15) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2920 | // bfi - bitfield insert. |
| 2921 | uint32_t rm_val = |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2922 | static_cast<uint32_t>(get_register(instr->RmValue())); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2923 | rm_val &= mask; |
| 2924 | rd_val |= rm_val << lsbit; |
| 2925 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2926 | set_register(instr->RdValue(), rd_val); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2927 | } else { |
| 2928 | UNREACHABLE(); |
| 2929 | } |
| 2930 | return; |
| 2931 | } else { |
| 2932 | // Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w"); |
| 2933 | addr = rn_val + shifter_operand; |
| 2934 | if (instr->HasW()) { |
| 2935 | set_register(rn, addr); |
| 2936 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2937 | } |
| 2938 | break; |
| 2939 | } |
| 2940 | default: { |
| 2941 | UNREACHABLE(); |
| 2942 | break; |
| 2943 | } |
| 2944 | } |
| 2945 | if (instr->HasB()) { |
| 2946 | if (instr->HasL()) { |
| 2947 | uint8_t byte = ReadB(addr); |
| 2948 | set_register(rd, byte); |
| 2949 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2950 | uint8_t byte = get_register(rd); |
| 2951 | WriteB(addr, byte); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2952 | } |
| 2953 | } else { |
| 2954 | if (instr->HasL()) { |
| 2955 | set_register(rd, ReadW(addr, instr)); |
| 2956 | } else { |
| 2957 | WriteW(addr, get_register(rd), instr); |
| 2958 | } |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2963 | void Simulator::DecodeType4(Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2964 | DCHECK(instr->Bit(22) == 0); // only allowed to be set in privileged mode |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2965 | if (instr->HasL()) { |
| 2966 | // Format(instr, "ldm'cond'pu 'rn'w, 'rlist"); |
| 2967 | HandleRList(instr, true); |
| 2968 | } else { |
| 2969 | // Format(instr, "stm'cond'pu 'rn'w, 'rlist"); |
| 2970 | HandleRList(instr, false); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2975 | void Simulator::DecodeType5(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2976 | // Format(instr, "b'l'cond 'target"); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2977 | int off = (instr->SImmed24Value() << 2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2978 | intptr_t pc_address = get_pc(); |
| 2979 | if (instr->HasLink()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2980 | set_register(lr, pc_address + Instruction::kInstrSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2981 | } |
| 2982 | int pc_reg = get_register(pc); |
| 2983 | set_pc(pc_reg + off); |
| 2984 | } |
| 2985 | |
| 2986 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2987 | void Simulator::DecodeType6(Instruction* instr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2988 | DecodeType6CoprocessorIns(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2992 | void Simulator::DecodeType7(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2993 | if (instr->Bit(24) == 1) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2994 | SoftwareInterrupt(instr); |
| 2995 | } else { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2996 | DecodeTypeVFP(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3001 | // void Simulator::DecodeTypeVFP(Instruction* instr) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3002 | // The Following ARMv7 VFPv instructions are currently supported. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3003 | // vmov :Sn = Rt |
| 3004 | // vmov :Rt = Sn |
| 3005 | // vcvt: Dd = Sm |
| 3006 | // vcvt: Sd = Dm |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3007 | // vcvt.f64.s32 Dd, Dd, #<fbits> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3008 | // Dd = vabs(Dm) |
| 3009 | // Dd = vneg(Dm) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3010 | // Dd = vadd(Dn, Dm) |
| 3011 | // Dd = vsub(Dn, Dm) |
| 3012 | // Dd = vmul(Dn, Dm) |
| 3013 | // Dd = vdiv(Dn, Dm) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3014 | // vcmp(Dd, Dm) |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3015 | // vmrs |
| 3016 | // Dd = vsqrt(Dm) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3017 | void Simulator::DecodeTypeVFP(Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3018 | DCHECK((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0) ); |
| 3019 | DCHECK(instr->Bits(11, 9) == 0x5); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3020 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3021 | // Obtain double precision register codes. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3022 | int vm = instr->VFPMRegValue(kDoublePrecision); |
| 3023 | int vd = instr->VFPDRegValue(kDoublePrecision); |
| 3024 | int vn = instr->VFPNRegValue(kDoublePrecision); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3025 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3026 | if (instr->Bit(4) == 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3027 | if (instr->Opc1Value() == 0x7) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3028 | // Other data processing instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3029 | if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x1)) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3030 | // vmov register to register. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3031 | if (instr->SzValue() == 0x1) { |
| 3032 | int m = instr->VFPMRegValue(kDoublePrecision); |
| 3033 | int d = instr->VFPDRegValue(kDoublePrecision); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3034 | set_d_register_from_double(d, get_double_from_d_register(m)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3035 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3036 | int m = instr->VFPMRegValue(kSinglePrecision); |
| 3037 | int d = instr->VFPDRegValue(kSinglePrecision); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3038 | set_s_register_from_float(d, get_float_from_s_register(m)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3039 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3040 | } else if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x3)) { |
| 3041 | // vabs |
| 3042 | double dm_value = get_double_from_d_register(vm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3043 | double dd_value = std::fabs(dm_value); |
| 3044 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3045 | set_d_register_from_double(vd, dd_value); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3046 | } else if ((instr->Opc2Value() == 0x1) && (instr->Opc3Value() == 0x1)) { |
| 3047 | // vneg |
| 3048 | double dm_value = get_double_from_d_register(vm); |
| 3049 | double dd_value = -dm_value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3050 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3051 | set_d_register_from_double(vd, dd_value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3052 | } else if ((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3053 | DecodeVCVTBetweenDoubleAndSingle(instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3054 | } else if ((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3055 | DecodeVCVTBetweenFloatingPointAndInteger(instr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3056 | } else if ((instr->Opc2Value() == 0xA) && (instr->Opc3Value() == 0x3) && |
| 3057 | (instr->Bit(8) == 1)) { |
| 3058 | // vcvt.f64.s32 Dd, Dd, #<fbits> |
| 3059 | int fraction_bits = 32 - ((instr->Bits(3, 0) << 1) | instr->Bit(5)); |
| 3060 | int fixed_value = get_sinteger_from_s_register(vd * 2); |
| 3061 | double divide = 1 << fraction_bits; |
| 3062 | set_d_register_from_double(vd, fixed_value / divide); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3063 | } else if (((instr->Opc2Value() >> 1) == 0x6) && |
| 3064 | (instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3065 | DecodeVCVTBetweenFloatingPointAndInteger(instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3066 | } else if (((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) && |
| 3067 | (instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3068 | DecodeVCMP(instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3069 | } else if (((instr->Opc2Value() == 0x1)) && (instr->Opc3Value() == 0x3)) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3070 | // vsqrt |
| 3071 | double dm_value = get_double_from_d_register(vm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3072 | double dd_value = std::sqrt(dm_value); |
| 3073 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3074 | set_d_register_from_double(vd, dd_value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3075 | } else if (instr->Opc3Value() == 0x0) { |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3076 | // vmov immediate. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3077 | if (instr->SzValue() == 0x1) { |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3078 | set_d_register_from_double(vd, instr->DoubleImmedVmov()); |
| 3079 | } else { |
| 3080 | UNREACHABLE(); // Not used by v8. |
| 3081 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3082 | } else if (((instr->Opc2Value() == 0x6)) && (instr->Opc3Value() == 0x3)) { |
| 3083 | // vrintz - truncate |
| 3084 | double dm_value = get_double_from_d_register(vm); |
| 3085 | double dd_value = trunc(dm_value); |
| 3086 | dd_value = canonicalizeNaN(dd_value); |
| 3087 | set_d_register_from_double(vd, dd_value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3088 | } else { |
| 3089 | UNREACHABLE(); // Not used by V8. |
| 3090 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3091 | } else if (instr->Opc1Value() == 0x3) { |
| 3092 | if (instr->SzValue() != 0x1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3093 | UNREACHABLE(); // Not used by V8. |
| 3094 | } |
| 3095 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3096 | if (instr->Opc3Value() & 0x1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3097 | // vsub |
| 3098 | double dn_value = get_double_from_d_register(vn); |
| 3099 | double dm_value = get_double_from_d_register(vm); |
| 3100 | double dd_value = dn_value - dm_value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3101 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3102 | set_d_register_from_double(vd, dd_value); |
| 3103 | } else { |
| 3104 | // vadd |
| 3105 | double dn_value = get_double_from_d_register(vn); |
| 3106 | double dm_value = get_double_from_d_register(vm); |
| 3107 | double dd_value = dn_value + dm_value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3108 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3109 | set_d_register_from_double(vd, dd_value); |
| 3110 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3111 | } else if ((instr->Opc1Value() == 0x2) && !(instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3112 | // vmul |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3113 | if (instr->SzValue() != 0x1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3114 | UNREACHABLE(); // Not used by V8. |
| 3115 | } |
| 3116 | |
| 3117 | double dn_value = get_double_from_d_register(vn); |
| 3118 | double dm_value = get_double_from_d_register(vm); |
| 3119 | double dd_value = dn_value * dm_value; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3120 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3121 | set_d_register_from_double(vd, dd_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3122 | } else if ((instr->Opc1Value() == 0x0)) { |
| 3123 | // vmla, vmls |
| 3124 | const bool is_vmls = (instr->Opc3Value() & 0x1); |
| 3125 | |
| 3126 | if (instr->SzValue() != 0x1) { |
| 3127 | UNREACHABLE(); // Not used by V8. |
| 3128 | } |
| 3129 | |
| 3130 | const double dd_val = get_double_from_d_register(vd); |
| 3131 | const double dn_val = get_double_from_d_register(vn); |
| 3132 | const double dm_val = get_double_from_d_register(vm); |
| 3133 | |
| 3134 | // Note: we do the mul and add/sub in separate steps to avoid getting a |
| 3135 | // result with too high precision. |
| 3136 | set_d_register_from_double(vd, dn_val * dm_val); |
| 3137 | if (is_vmls) { |
| 3138 | set_d_register_from_double( |
| 3139 | vd, |
| 3140 | canonicalizeNaN(dd_val - get_double_from_d_register(vd))); |
| 3141 | } else { |
| 3142 | set_d_register_from_double( |
| 3143 | vd, |
| 3144 | canonicalizeNaN(dd_val + get_double_from_d_register(vd))); |
| 3145 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3146 | } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3147 | // vdiv |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3148 | if (instr->SzValue() != 0x1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3149 | UNREACHABLE(); // Not used by V8. |
| 3150 | } |
| 3151 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3152 | double dn_value = get_double_from_d_register(vn); |
| 3153 | double dm_value = get_double_from_d_register(vm); |
| 3154 | double dd_value = dn_value / dm_value; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3155 | div_zero_vfp_flag_ = (dm_value == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3156 | dd_value = canonicalizeNaN(dd_value); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3157 | set_d_register_from_double(vd, dd_value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3158 | } else { |
| 3159 | UNIMPLEMENTED(); // Not used by V8. |
| 3160 | } |
| 3161 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3162 | if ((instr->VCValue() == 0x0) && |
| 3163 | (instr->VAValue() == 0x0)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3164 | DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3165 | } else if ((instr->VLValue() == 0x0) && |
| 3166 | (instr->VCValue() == 0x1) && |
| 3167 | (instr->Bit(23) == 0x0)) { |
| 3168 | // vmov (ARM core register to scalar) |
| 3169 | int vd = instr->Bits(19, 16) | (instr->Bit(7) << 4); |
| 3170 | double dd_value = get_double_from_d_register(vd); |
| 3171 | int32_t data[2]; |
| 3172 | memcpy(data, &dd_value, 8); |
| 3173 | data[instr->Bit(21)] = get_register(instr->RtValue()); |
| 3174 | memcpy(&dd_value, data, 8); |
| 3175 | set_d_register_from_double(vd, dd_value); |
| 3176 | } else if ((instr->VLValue() == 0x1) && |
| 3177 | (instr->VCValue() == 0x1) && |
| 3178 | (instr->Bit(23) == 0x0)) { |
| 3179 | // vmov (scalar to ARM core register) |
| 3180 | int vn = instr->Bits(19, 16) | (instr->Bit(7) << 4); |
| 3181 | double dn_value = get_double_from_d_register(vn); |
| 3182 | int32_t data[2]; |
| 3183 | memcpy(data, &dn_value, 8); |
| 3184 | set_register(instr->RtValue(), data[instr->Bit(21)]); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3185 | } else if ((instr->VLValue() == 0x1) && |
| 3186 | (instr->VCValue() == 0x0) && |
| 3187 | (instr->VAValue() == 0x7) && |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3188 | (instr->Bits(19, 16) == 0x1)) { |
| 3189 | // vmrs |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3190 | uint32_t rt = instr->RtValue(); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3191 | if (rt == 0xF) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3192 | Copy_FPSCR_to_APSR(); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3193 | } else { |
| 3194 | // Emulate FPSCR from the Simulator flags. |
| 3195 | uint32_t fpscr = (n_flag_FPSCR_ << 31) | |
| 3196 | (z_flag_FPSCR_ << 30) | |
| 3197 | (c_flag_FPSCR_ << 29) | |
| 3198 | (v_flag_FPSCR_ << 28) | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3199 | (FPSCR_default_NaN_mode_ << 25) | |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3200 | (inexact_vfp_flag_ << 4) | |
| 3201 | (underflow_vfp_flag_ << 3) | |
| 3202 | (overflow_vfp_flag_ << 2) | |
| 3203 | (div_zero_vfp_flag_ << 1) | |
| 3204 | (inv_op_vfp_flag_ << 0) | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3205 | (FPSCR_rounding_mode_); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3206 | set_register(rt, fpscr); |
| 3207 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3208 | } else if ((instr->VLValue() == 0x0) && |
| 3209 | (instr->VCValue() == 0x0) && |
| 3210 | (instr->VAValue() == 0x7) && |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3211 | (instr->Bits(19, 16) == 0x1)) { |
| 3212 | // vmsr |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3213 | uint32_t rt = instr->RtValue(); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3214 | if (rt == pc) { |
| 3215 | UNREACHABLE(); |
| 3216 | } else { |
| 3217 | uint32_t rt_value = get_register(rt); |
| 3218 | n_flag_FPSCR_ = (rt_value >> 31) & 1; |
| 3219 | z_flag_FPSCR_ = (rt_value >> 30) & 1; |
| 3220 | c_flag_FPSCR_ = (rt_value >> 29) & 1; |
| 3221 | v_flag_FPSCR_ = (rt_value >> 28) & 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3222 | FPSCR_default_NaN_mode_ = (rt_value >> 25) & 1; |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3223 | inexact_vfp_flag_ = (rt_value >> 4) & 1; |
| 3224 | underflow_vfp_flag_ = (rt_value >> 3) & 1; |
| 3225 | overflow_vfp_flag_ = (rt_value >> 2) & 1; |
| 3226 | div_zero_vfp_flag_ = (rt_value >> 1) & 1; |
| 3227 | inv_op_vfp_flag_ = (rt_value >> 0) & 1; |
| 3228 | FPSCR_rounding_mode_ = |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3229 | static_cast<VFPRoundingMode>((rt_value) & kVFPRoundingModeMask); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3230 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3231 | } else { |
| 3232 | UNIMPLEMENTED(); // Not used by V8. |
| 3233 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3238 | void Simulator::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters( |
| 3239 | Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3240 | DCHECK((instr->Bit(4) == 1) && (instr->VCValue() == 0x0) && |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3241 | (instr->VAValue() == 0x0)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3242 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3243 | int t = instr->RtValue(); |
| 3244 | int n = instr->VFPNRegValue(kSinglePrecision); |
| 3245 | bool to_arm_register = (instr->VLValue() == 0x1); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3246 | |
| 3247 | if (to_arm_register) { |
| 3248 | int32_t int_value = get_sinteger_from_s_register(n); |
| 3249 | set_register(t, int_value); |
| 3250 | } else { |
| 3251 | int32_t rs_val = get_register(t); |
| 3252 | set_s_register_from_sinteger(n, rs_val); |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3257 | void Simulator::DecodeVCMP(Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3258 | DCHECK((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7)); |
| 3259 | DCHECK(((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) && |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3260 | (instr->Opc3Value() & 0x1)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3261 | // Comparison. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3262 | |
| 3263 | VFPRegPrecision precision = kSinglePrecision; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3264 | if (instr->SzValue() == 1) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3265 | precision = kDoublePrecision; |
| 3266 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3267 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3268 | int d = instr->VFPDRegValue(precision); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3269 | int m = 0; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3270 | if (instr->Opc2Value() == 0x4) { |
| 3271 | m = instr->VFPMRegValue(precision); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3272 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3273 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3274 | if (precision == kDoublePrecision) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3275 | double dd_value = get_double_from_d_register(d); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3276 | double dm_value = 0.0; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3277 | if (instr->Opc2Value() == 0x4) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3278 | dm_value = get_double_from_d_register(m); |
| 3279 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3280 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3281 | // Raise exceptions for quiet NaNs if necessary. |
| 3282 | if (instr->Bit(7) == 1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3283 | if (std::isnan(dd_value)) { |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3284 | inv_op_vfp_flag_ = true; |
| 3285 | } |
| 3286 | } |
| 3287 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3288 | Compute_FPSCR_Flags(dd_value, dm_value); |
| 3289 | } else { |
| 3290 | UNIMPLEMENTED(); // Not used by V8. |
| 3291 | } |
| 3292 | } |
| 3293 | |
| 3294 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3295 | void Simulator::DecodeVCVTBetweenDoubleAndSingle(Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3296 | DCHECK((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7)); |
| 3297 | DCHECK((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3298 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3299 | VFPRegPrecision dst_precision = kDoublePrecision; |
| 3300 | VFPRegPrecision src_precision = kSinglePrecision; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3301 | if (instr->SzValue() == 1) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3302 | dst_precision = kSinglePrecision; |
| 3303 | src_precision = kDoublePrecision; |
| 3304 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3305 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3306 | int dst = instr->VFPDRegValue(dst_precision); |
| 3307 | int src = instr->VFPMRegValue(src_precision); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3308 | |
| 3309 | if (dst_precision == kSinglePrecision) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3310 | double val = get_double_from_d_register(src); |
| 3311 | set_s_register_from_float(dst, static_cast<float>(val)); |
| 3312 | } else { |
| 3313 | float val = get_float_from_s_register(src); |
| 3314 | set_d_register_from_double(dst, static_cast<double>(val)); |
| 3315 | } |
| 3316 | } |
| 3317 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3318 | bool get_inv_op_vfp_flag(VFPRoundingMode mode, |
| 3319 | double val, |
| 3320 | bool unsigned_) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3321 | DCHECK((mode == RN) || (mode == RM) || (mode == RZ)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3322 | double max_uint = static_cast<double>(0xffffffffu); |
| 3323 | double max_int = static_cast<double>(kMaxInt); |
| 3324 | double min_int = static_cast<double>(kMinInt); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3325 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3326 | // Check for NaN. |
| 3327 | if (val != val) { |
| 3328 | return true; |
| 3329 | } |
| 3330 | |
| 3331 | // Check for overflow. This code works because 32bit integers can be |
| 3332 | // exactly represented by ieee-754 64bit floating-point values. |
| 3333 | switch (mode) { |
| 3334 | case RN: |
| 3335 | return unsigned_ ? (val >= (max_uint + 0.5)) || |
| 3336 | (val < -0.5) |
| 3337 | : (val >= (max_int + 0.5)) || |
| 3338 | (val < (min_int - 0.5)); |
| 3339 | |
| 3340 | case RM: |
| 3341 | return unsigned_ ? (val >= (max_uint + 1.0)) || |
| 3342 | (val < 0) |
| 3343 | : (val >= (max_int + 1.0)) || |
| 3344 | (val < min_int); |
| 3345 | |
| 3346 | case RZ: |
| 3347 | return unsigned_ ? (val >= (max_uint + 1.0)) || |
| 3348 | (val <= -1) |
| 3349 | : (val >= (max_int + 1.0)) || |
| 3350 | (val <= (min_int - 1.0)); |
| 3351 | default: |
| 3352 | UNREACHABLE(); |
| 3353 | return true; |
| 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | |
| 3358 | // We call this function only if we had a vfp invalid exception. |
| 3359 | // It returns the correct saturated value. |
| 3360 | int VFPConversionSaturate(double val, bool unsigned_res) { |
| 3361 | if (val != val) { |
| 3362 | return 0; |
| 3363 | } else { |
| 3364 | if (unsigned_res) { |
| 3365 | return (val < 0) ? 0 : 0xffffffffu; |
| 3366 | } else { |
| 3367 | return (val < 0) ? kMinInt : kMaxInt; |
| 3368 | } |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | |
| 3373 | void Simulator::DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3374 | DCHECK((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7) && |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3375 | (instr->Bits(27, 23) == 0x1D)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3376 | DCHECK(((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) || |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3377 | (((instr->Opc2Value() >> 1) == 0x6) && (instr->Opc3Value() & 0x1))); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3378 | |
| 3379 | // Conversion between floating-point and integer. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3380 | bool to_integer = (instr->Bit(18) == 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3381 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3382 | VFPRegPrecision src_precision = (instr->SzValue() == 1) ? kDoublePrecision |
| 3383 | : kSinglePrecision; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3384 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3385 | if (to_integer) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3386 | // We are playing with code close to the C++ standard's limits below, |
| 3387 | // hence the very simple code and heavy checks. |
| 3388 | // |
| 3389 | // Note: |
| 3390 | // C++ defines default type casting from floating point to integer as |
| 3391 | // (close to) rounding toward zero ("fractional part discarded"). |
| 3392 | |
| 3393 | int dst = instr->VFPDRegValue(kSinglePrecision); |
| 3394 | int src = instr->VFPMRegValue(src_precision); |
| 3395 | |
| 3396 | // Bit 7 in vcvt instructions indicates if we should use the FPSCR rounding |
| 3397 | // mode or the default Round to Zero mode. |
| 3398 | VFPRoundingMode mode = (instr->Bit(7) != 1) ? FPSCR_rounding_mode_ |
| 3399 | : RZ; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3400 | DCHECK((mode == RM) || (mode == RZ) || (mode == RN)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3401 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3402 | bool unsigned_integer = (instr->Bit(16) == 0); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3403 | bool double_precision = (src_precision == kDoublePrecision); |
| 3404 | |
| 3405 | double val = double_precision ? get_double_from_d_register(src) |
| 3406 | : get_float_from_s_register(src); |
| 3407 | |
| 3408 | int temp = unsigned_integer ? static_cast<uint32_t>(val) |
| 3409 | : static_cast<int32_t>(val); |
| 3410 | |
| 3411 | inv_op_vfp_flag_ = get_inv_op_vfp_flag(mode, val, unsigned_integer); |
| 3412 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3413 | double abs_diff = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3414 | unsigned_integer ? std::fabs(val - static_cast<uint32_t>(temp)) |
| 3415 | : std::fabs(val - temp); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3416 | |
| 3417 | inexact_vfp_flag_ = (abs_diff != 0); |
| 3418 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3419 | if (inv_op_vfp_flag_) { |
| 3420 | temp = VFPConversionSaturate(val, unsigned_integer); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3421 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3422 | switch (mode) { |
| 3423 | case RN: { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3424 | int val_sign = (val > 0) ? 1 : -1; |
| 3425 | if (abs_diff > 0.5) { |
| 3426 | temp += val_sign; |
| 3427 | } else if (abs_diff == 0.5) { |
| 3428 | // Round to even if exactly halfway. |
| 3429 | temp = ((temp % 2) == 0) ? temp : temp + val_sign; |
| 3430 | } |
| 3431 | break; |
| 3432 | } |
| 3433 | |
| 3434 | case RM: |
| 3435 | temp = temp > val ? temp - 1 : temp; |
| 3436 | break; |
| 3437 | |
| 3438 | case RZ: |
| 3439 | // Nothing to do. |
| 3440 | break; |
| 3441 | |
| 3442 | default: |
| 3443 | UNREACHABLE(); |
| 3444 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3445 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3446 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3447 | // Update the destination register. |
| 3448 | set_s_register_from_sinteger(dst, temp); |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 3449 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3450 | } else { |
| 3451 | bool unsigned_integer = (instr->Bit(7) == 0); |
| 3452 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3453 | int dst = instr->VFPDRegValue(src_precision); |
| 3454 | int src = instr->VFPMRegValue(kSinglePrecision); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3455 | |
| 3456 | int val = get_sinteger_from_s_register(src); |
| 3457 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3458 | if (src_precision == kDoublePrecision) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3459 | if (unsigned_integer) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3460 | set_d_register_from_double( |
| 3461 | dst, static_cast<double>(static_cast<uint32_t>(val))); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3462 | } else { |
| 3463 | set_d_register_from_double(dst, static_cast<double>(val)); |
| 3464 | } |
| 3465 | } else { |
| 3466 | if (unsigned_integer) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3467 | set_s_register_from_float( |
| 3468 | dst, static_cast<float>(static_cast<uint32_t>(val))); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3469 | } else { |
| 3470 | set_s_register_from_float(dst, static_cast<float>(val)); |
| 3471 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3472 | } |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3477 | // void Simulator::DecodeType6CoprocessorIns(Instruction* instr) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3478 | // Decode Type 6 coprocessor instructions. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3479 | // Dm = vmov(Rt, Rt2) |
| 3480 | // <Rt, Rt2> = vmov(Dm) |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3481 | // Ddst = MEM(Rbase + 4*offset). |
| 3482 | // MEM(Rbase + 4*offset) = Dsrc. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3483 | void Simulator::DecodeType6CoprocessorIns(Instruction* instr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3484 | DCHECK((instr->TypeValue() == 6)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3485 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3486 | if (instr->CoprocessorValue() == 0xA) { |
| 3487 | switch (instr->OpcodeValue()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3488 | case 0x8: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3489 | case 0xA: |
| 3490 | case 0xC: |
| 3491 | case 0xE: { // Load and store single precision float to memory. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3492 | int rn = instr->RnValue(); |
| 3493 | int vd = instr->VFPDRegValue(kSinglePrecision); |
| 3494 | int offset = instr->Immed8Value(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3495 | if (!instr->HasU()) { |
| 3496 | offset = -offset; |
| 3497 | } |
| 3498 | |
| 3499 | int32_t address = get_register(rn) + 4 * offset; |
| 3500 | if (instr->HasL()) { |
| 3501 | // Load double from memory: vldr. |
| 3502 | set_s_register_from_sinteger(vd, ReadW(address, instr)); |
| 3503 | } else { |
| 3504 | // Store double to memory: vstr. |
| 3505 | WriteW(address, get_sinteger_from_s_register(vd), instr); |
| 3506 | } |
| 3507 | break; |
| 3508 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3509 | case 0x4: |
| 3510 | case 0x5: |
| 3511 | case 0x6: |
| 3512 | case 0x7: |
| 3513 | case 0x9: |
| 3514 | case 0xB: |
| 3515 | // Load/store multiple single from memory: vldm/vstm. |
| 3516 | HandleVList(instr); |
| 3517 | break; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3518 | default: |
| 3519 | UNIMPLEMENTED(); // Not used by V8. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3520 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3521 | } else if (instr->CoprocessorValue() == 0xB) { |
| 3522 | switch (instr->OpcodeValue()) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3523 | case 0x2: |
| 3524 | // Load and store double to two GP registers |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3525 | if (instr->Bits(7, 6) != 0 || instr->Bit(4) != 1) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3526 | UNIMPLEMENTED(); // Not used by V8. |
| 3527 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3528 | int rt = instr->RtValue(); |
| 3529 | int rn = instr->RnValue(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3530 | int vm = instr->VFPMRegValue(kDoublePrecision); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3531 | if (instr->HasL()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3532 | int32_t data[2]; |
| 3533 | double d = get_double_from_d_register(vm); |
| 3534 | memcpy(data, &d, 8); |
| 3535 | set_register(rt, data[0]); |
| 3536 | set_register(rn, data[1]); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3537 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3538 | int32_t data[] = { get_register(rt), get_register(rn) }; |
| 3539 | double d; |
| 3540 | memcpy(&d, data, 8); |
| 3541 | set_d_register_from_double(vm, d); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | break; |
| 3545 | case 0x8: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3546 | case 0xA: |
| 3547 | case 0xC: |
| 3548 | case 0xE: { // Load and store double to memory. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3549 | int rn = instr->RnValue(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3550 | int vd = instr->VFPDRegValue(kDoublePrecision); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3551 | int offset = instr->Immed8Value(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3552 | if (!instr->HasU()) { |
| 3553 | offset = -offset; |
| 3554 | } |
| 3555 | int32_t address = get_register(rn) + 4 * offset; |
| 3556 | if (instr->HasL()) { |
| 3557 | // Load double from memory: vldr. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3558 | int32_t data[] = { |
| 3559 | ReadW(address, instr), |
| 3560 | ReadW(address + 4, instr) |
| 3561 | }; |
| 3562 | double val; |
| 3563 | memcpy(&val, data, 8); |
| 3564 | set_d_register_from_double(vd, val); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3565 | } else { |
| 3566 | // Store double to memory: vstr. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3567 | int32_t data[2]; |
| 3568 | double val = get_double_from_d_register(vd); |
| 3569 | memcpy(data, &val, 8); |
| 3570 | WriteW(address, data[0], instr); |
| 3571 | WriteW(address + 4, data[1], instr); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3572 | } |
| 3573 | break; |
| 3574 | } |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3575 | case 0x4: |
| 3576 | case 0x5: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3577 | case 0x6: |
| 3578 | case 0x7: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3579 | case 0x9: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3580 | case 0xB: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3581 | // Load/store multiple double from memory: vldm/vstm. |
| 3582 | HandleVList(instr); |
| 3583 | break; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3584 | default: |
| 3585 | UNIMPLEMENTED(); // Not used by V8. |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3586 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3587 | } else { |
| 3588 | UNIMPLEMENTED(); // Not used by V8. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3593 | void Simulator::DecodeSpecialCondition(Instruction* instr) { |
| 3594 | switch (instr->SpecialValue()) { |
| 3595 | case 5: |
| 3596 | if ((instr->Bits(18, 16) == 0) && (instr->Bits(11, 6) == 0x28) && |
| 3597 | (instr->Bit(4) == 1)) { |
| 3598 | // vmovl signed |
| 3599 | if ((instr->VdValue() & 1) != 0) UNIMPLEMENTED(); |
| 3600 | int Vd = (instr->Bit(22) << 3) | (instr->VdValue() >> 1); |
| 3601 | int Vm = (instr->Bit(5) << 4) | instr->VmValue(); |
| 3602 | int imm3 = instr->Bits(21, 19); |
| 3603 | if ((imm3 != 1) && (imm3 != 2) && (imm3 != 4)) UNIMPLEMENTED(); |
| 3604 | int esize = 8 * imm3; |
| 3605 | int elements = 64 / esize; |
| 3606 | int8_t from[8]; |
| 3607 | get_d_register(Vm, reinterpret_cast<uint64_t*>(from)); |
| 3608 | int16_t to[8]; |
| 3609 | int e = 0; |
| 3610 | while (e < elements) { |
| 3611 | to[e] = from[e]; |
| 3612 | e++; |
| 3613 | } |
| 3614 | set_q_register(Vd, reinterpret_cast<uint64_t*>(to)); |
| 3615 | } else { |
| 3616 | UNIMPLEMENTED(); |
| 3617 | } |
| 3618 | break; |
| 3619 | case 7: |
| 3620 | if ((instr->Bits(18, 16) == 0) && (instr->Bits(11, 6) == 0x28) && |
| 3621 | (instr->Bit(4) == 1)) { |
| 3622 | // vmovl unsigned |
| 3623 | if ((instr->VdValue() & 1) != 0) UNIMPLEMENTED(); |
| 3624 | int Vd = (instr->Bit(22) << 3) | (instr->VdValue() >> 1); |
| 3625 | int Vm = (instr->Bit(5) << 4) | instr->VmValue(); |
| 3626 | int imm3 = instr->Bits(21, 19); |
| 3627 | if ((imm3 != 1) && (imm3 != 2) && (imm3 != 4)) UNIMPLEMENTED(); |
| 3628 | int esize = 8 * imm3; |
| 3629 | int elements = 64 / esize; |
| 3630 | uint8_t from[8]; |
| 3631 | get_d_register(Vm, reinterpret_cast<uint64_t*>(from)); |
| 3632 | uint16_t to[8]; |
| 3633 | int e = 0; |
| 3634 | while (e < elements) { |
| 3635 | to[e] = from[e]; |
| 3636 | e++; |
| 3637 | } |
| 3638 | set_q_register(Vd, reinterpret_cast<uint64_t*>(to)); |
| 3639 | } else { |
| 3640 | UNIMPLEMENTED(); |
| 3641 | } |
| 3642 | break; |
| 3643 | case 8: |
| 3644 | if (instr->Bits(21, 20) == 0) { |
| 3645 | // vst1 |
| 3646 | int Vd = (instr->Bit(22) << 4) | instr->VdValue(); |
| 3647 | int Rn = instr->VnValue(); |
| 3648 | int type = instr->Bits(11, 8); |
| 3649 | int Rm = instr->VmValue(); |
| 3650 | int32_t address = get_register(Rn); |
| 3651 | int regs = 0; |
| 3652 | switch (type) { |
| 3653 | case nlt_1: |
| 3654 | regs = 1; |
| 3655 | break; |
| 3656 | case nlt_2: |
| 3657 | regs = 2; |
| 3658 | break; |
| 3659 | case nlt_3: |
| 3660 | regs = 3; |
| 3661 | break; |
| 3662 | case nlt_4: |
| 3663 | regs = 4; |
| 3664 | break; |
| 3665 | default: |
| 3666 | UNIMPLEMENTED(); |
| 3667 | break; |
| 3668 | } |
| 3669 | int r = 0; |
| 3670 | while (r < regs) { |
| 3671 | uint32_t data[2]; |
| 3672 | get_d_register(Vd + r, data); |
| 3673 | WriteW(address, data[0], instr); |
| 3674 | WriteW(address + 4, data[1], instr); |
| 3675 | address += 8; |
| 3676 | r++; |
| 3677 | } |
| 3678 | if (Rm != 15) { |
| 3679 | if (Rm == 13) { |
| 3680 | set_register(Rn, address); |
| 3681 | } else { |
| 3682 | set_register(Rn, get_register(Rn) + get_register(Rm)); |
| 3683 | } |
| 3684 | } |
| 3685 | } else if (instr->Bits(21, 20) == 2) { |
| 3686 | // vld1 |
| 3687 | int Vd = (instr->Bit(22) << 4) | instr->VdValue(); |
| 3688 | int Rn = instr->VnValue(); |
| 3689 | int type = instr->Bits(11, 8); |
| 3690 | int Rm = instr->VmValue(); |
| 3691 | int32_t address = get_register(Rn); |
| 3692 | int regs = 0; |
| 3693 | switch (type) { |
| 3694 | case nlt_1: |
| 3695 | regs = 1; |
| 3696 | break; |
| 3697 | case nlt_2: |
| 3698 | regs = 2; |
| 3699 | break; |
| 3700 | case nlt_3: |
| 3701 | regs = 3; |
| 3702 | break; |
| 3703 | case nlt_4: |
| 3704 | regs = 4; |
| 3705 | break; |
| 3706 | default: |
| 3707 | UNIMPLEMENTED(); |
| 3708 | break; |
| 3709 | } |
| 3710 | int r = 0; |
| 3711 | while (r < regs) { |
| 3712 | uint32_t data[2]; |
| 3713 | data[0] = ReadW(address, instr); |
| 3714 | data[1] = ReadW(address + 4, instr); |
| 3715 | set_d_register(Vd + r, data); |
| 3716 | address += 8; |
| 3717 | r++; |
| 3718 | } |
| 3719 | if (Rm != 15) { |
| 3720 | if (Rm == 13) { |
| 3721 | set_register(Rn, address); |
| 3722 | } else { |
| 3723 | set_register(Rn, get_register(Rn) + get_register(Rm)); |
| 3724 | } |
| 3725 | } |
| 3726 | } else { |
| 3727 | UNIMPLEMENTED(); |
| 3728 | } |
| 3729 | break; |
| 3730 | case 0xA: |
| 3731 | case 0xB: |
| 3732 | if ((instr->Bits(22, 20) == 5) && (instr->Bits(15, 12) == 0xf)) { |
| 3733 | // pld: ignore instruction. |
| 3734 | } else { |
| 3735 | UNIMPLEMENTED(); |
| 3736 | } |
| 3737 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3738 | case 0x1D: |
| 3739 | if (instr->Opc1Value() == 0x7 && instr->Opc3Value() == 0x1 && |
| 3740 | instr->Bits(11, 9) == 0x5 && instr->Bits(19, 18) == 0x2 && |
| 3741 | instr->Bit(8) == 0x1) { |
| 3742 | int vm = instr->VFPMRegValue(kDoublePrecision); |
| 3743 | int vd = instr->VFPDRegValue(kDoublePrecision); |
| 3744 | double dm_value = get_double_from_d_register(vm); |
| 3745 | double dd_value = 0.0; |
| 3746 | int rounding_mode = instr->Bits(17, 16); |
| 3747 | switch (rounding_mode) { |
| 3748 | case 0x0: // vrinta - round with ties to away from zero |
| 3749 | dd_value = round(dm_value); |
| 3750 | break; |
| 3751 | case 0x1: { // vrintn - round with ties to even |
| 3752 | dd_value = std::floor(dm_value); |
| 3753 | double error = dm_value - dd_value; |
| 3754 | // Take care of correctly handling the range [-0.5, -0.0], which |
| 3755 | // must yield -0.0. |
| 3756 | if ((-0.5 <= dm_value) && (dm_value < 0.0)) { |
| 3757 | dd_value = -0.0; |
| 3758 | // If the error is greater than 0.5, or is equal to 0.5 and the |
| 3759 | // integer result is odd, round up. |
| 3760 | } else if ((error > 0.5) || |
| 3761 | ((error == 0.5) && (fmod(dd_value, 2) != 0))) { |
| 3762 | dd_value++; |
| 3763 | } |
| 3764 | break; |
| 3765 | } |
| 3766 | case 0x2: // vrintp - ceil |
| 3767 | dd_value = std::ceil(dm_value); |
| 3768 | break; |
| 3769 | case 0x3: // vrintm - floor |
| 3770 | dd_value = std::floor(dm_value); |
| 3771 | break; |
| 3772 | default: |
| 3773 | UNREACHABLE(); // Case analysis is exhaustive. |
| 3774 | break; |
| 3775 | } |
| 3776 | dd_value = canonicalizeNaN(dd_value); |
| 3777 | set_d_register_from_double(vd, dd_value); |
| 3778 | } else { |
| 3779 | UNIMPLEMENTED(); |
| 3780 | } |
| 3781 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3782 | default: |
| 3783 | UNIMPLEMENTED(); |
| 3784 | break; |
| 3785 | } |
| 3786 | } |
| 3787 | |
| 3788 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3789 | // Executes the current instruction. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3790 | void Simulator::InstructionDecode(Instruction* instr) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3791 | if (v8::internal::FLAG_check_icache) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3792 | CheckICache(isolate_->simulator_i_cache(), instr); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3793 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3794 | pc_modified_ = false; |
| 3795 | if (::v8::internal::FLAG_trace_sim) { |
| 3796 | disasm::NameConverter converter; |
| 3797 | disasm::Disassembler dasm(converter); |
| 3798 | // use a reasonably large buffer |
| 3799 | v8::internal::EmbeddedVector<char, 256> buffer; |
| 3800 | dasm.InstructionDecode(buffer, |
| 3801 | reinterpret_cast<byte*>(instr)); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 3802 | PrintF(" 0x%08x %s\n", reinterpret_cast<intptr_t>(instr), buffer.start()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3803 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3804 | if (instr->ConditionField() == kSpecialCondition) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3805 | DecodeSpecialCondition(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3806 | } else if (ConditionallyExecute(instr)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3807 | switch (instr->TypeValue()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3808 | case 0: |
| 3809 | case 1: { |
| 3810 | DecodeType01(instr); |
| 3811 | break; |
| 3812 | } |
| 3813 | case 2: { |
| 3814 | DecodeType2(instr); |
| 3815 | break; |
| 3816 | } |
| 3817 | case 3: { |
| 3818 | DecodeType3(instr); |
| 3819 | break; |
| 3820 | } |
| 3821 | case 4: { |
| 3822 | DecodeType4(instr); |
| 3823 | break; |
| 3824 | } |
| 3825 | case 5: { |
| 3826 | DecodeType5(instr); |
| 3827 | break; |
| 3828 | } |
| 3829 | case 6: { |
| 3830 | DecodeType6(instr); |
| 3831 | break; |
| 3832 | } |
| 3833 | case 7: { |
| 3834 | DecodeType7(instr); |
| 3835 | break; |
| 3836 | } |
| 3837 | default: { |
| 3838 | UNIMPLEMENTED(); |
| 3839 | break; |
| 3840 | } |
| 3841 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3842 | // If the instruction is a non taken conditional stop, we need to skip the |
| 3843 | // inlined message address. |
| 3844 | } else if (instr->IsStop()) { |
| 3845 | set_pc(get_pc() + 2 * Instruction::kInstrSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3846 | } |
| 3847 | if (!pc_modified_) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3848 | set_register(pc, reinterpret_cast<int32_t>(instr) |
| 3849 | + Instruction::kInstrSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3854 | void Simulator::Execute() { |
| 3855 | // Get the PC to simulate. Cannot use the accessor here as we need the |
| 3856 | // raw PC value and not the one used as input to arithmetic instructions. |
| 3857 | int program_counter = get_pc(); |
| 3858 | |
| 3859 | if (::v8::internal::FLAG_stop_sim_at == 0) { |
| 3860 | // Fast version of the dispatch loop without checking whether the simulator |
| 3861 | // should be stopping at a particular executed instruction. |
| 3862 | while (program_counter != end_sim_pc) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3863 | Instruction* instr = reinterpret_cast<Instruction*>(program_counter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3864 | icount_++; |
| 3865 | InstructionDecode(instr); |
| 3866 | program_counter = get_pc(); |
| 3867 | } |
| 3868 | } else { |
| 3869 | // FLAG_stop_sim_at is at the non-default value. Stop in the debugger when |
| 3870 | // we reach the particular instuction count. |
| 3871 | while (program_counter != end_sim_pc) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3872 | Instruction* instr = reinterpret_cast<Instruction*>(program_counter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3873 | icount_++; |
| 3874 | if (icount_ == ::v8::internal::FLAG_stop_sim_at) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3875 | ArmDebugger dbg(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3876 | dbg.Debug(); |
| 3877 | } else { |
| 3878 | InstructionDecode(instr); |
| 3879 | } |
| 3880 | program_counter = get_pc(); |
| 3881 | } |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3886 | void Simulator::CallInternal(byte* entry) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3887 | // Prepare to execute the code at entry |
| 3888 | set_register(pc, reinterpret_cast<int32_t>(entry)); |
| 3889 | // Put down marker for end of simulation. The simulator will stop simulation |
| 3890 | // when the PC reaches this value. By saving the "end simulation" value into |
| 3891 | // the LR the simulation stops when returning to this call point. |
| 3892 | set_register(lr, end_sim_pc); |
| 3893 | |
| 3894 | // Remember the values of callee-saved registers. |
| 3895 | // The code below assumes that r9 is not used as sb (static base) in |
| 3896 | // simulator code and therefore is regarded as a callee-saved register. |
| 3897 | int32_t r4_val = get_register(r4); |
| 3898 | int32_t r5_val = get_register(r5); |
| 3899 | int32_t r6_val = get_register(r6); |
| 3900 | int32_t r7_val = get_register(r7); |
| 3901 | int32_t r8_val = get_register(r8); |
| 3902 | int32_t r9_val = get_register(r9); |
| 3903 | int32_t r10_val = get_register(r10); |
| 3904 | int32_t r11_val = get_register(r11); |
| 3905 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3906 | // Set up the callee-saved registers with a known value. To be able to check |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3907 | // that they are preserved properly across JS execution. |
| 3908 | int32_t callee_saved_value = icount_; |
| 3909 | set_register(r4, callee_saved_value); |
| 3910 | set_register(r5, callee_saved_value); |
| 3911 | set_register(r6, callee_saved_value); |
| 3912 | set_register(r7, callee_saved_value); |
| 3913 | set_register(r8, callee_saved_value); |
| 3914 | set_register(r9, callee_saved_value); |
| 3915 | set_register(r10, callee_saved_value); |
| 3916 | set_register(r11, callee_saved_value); |
| 3917 | |
| 3918 | // Start the simulation |
| 3919 | Execute(); |
| 3920 | |
| 3921 | // Check that the callee-saved registers have been preserved. |
| 3922 | CHECK_EQ(callee_saved_value, get_register(r4)); |
| 3923 | CHECK_EQ(callee_saved_value, get_register(r5)); |
| 3924 | CHECK_EQ(callee_saved_value, get_register(r6)); |
| 3925 | CHECK_EQ(callee_saved_value, get_register(r7)); |
| 3926 | CHECK_EQ(callee_saved_value, get_register(r8)); |
| 3927 | CHECK_EQ(callee_saved_value, get_register(r9)); |
| 3928 | CHECK_EQ(callee_saved_value, get_register(r10)); |
| 3929 | CHECK_EQ(callee_saved_value, get_register(r11)); |
| 3930 | |
| 3931 | // Restore callee-saved registers with the original value. |
| 3932 | set_register(r4, r4_val); |
| 3933 | set_register(r5, r5_val); |
| 3934 | set_register(r6, r6_val); |
| 3935 | set_register(r7, r7_val); |
| 3936 | set_register(r8, r8_val); |
| 3937 | set_register(r9, r9_val); |
| 3938 | set_register(r10, r10_val); |
| 3939 | set_register(r11, r11_val); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | |
| 3943 | int32_t Simulator::Call(byte* entry, int argument_count, ...) { |
| 3944 | va_list parameters; |
| 3945 | va_start(parameters, argument_count); |
| 3946 | // Set up arguments |
| 3947 | |
| 3948 | // First four arguments passed in registers. |
| 3949 | DCHECK(argument_count >= 4); |
| 3950 | set_register(r0, va_arg(parameters, int32_t)); |
| 3951 | set_register(r1, va_arg(parameters, int32_t)); |
| 3952 | set_register(r2, va_arg(parameters, int32_t)); |
| 3953 | set_register(r3, va_arg(parameters, int32_t)); |
| 3954 | |
| 3955 | // Remaining arguments passed on stack. |
| 3956 | int original_stack = get_register(sp); |
| 3957 | // Compute position of stack on entry to generated code. |
| 3958 | int entry_stack = (original_stack - (argument_count - 4) * sizeof(int32_t)); |
| 3959 | if (base::OS::ActivationFrameAlignment() != 0) { |
| 3960 | entry_stack &= -base::OS::ActivationFrameAlignment(); |
| 3961 | } |
| 3962 | // Store remaining arguments on stack, from low to high memory. |
| 3963 | intptr_t* stack_argument = reinterpret_cast<intptr_t*>(entry_stack); |
| 3964 | for (int i = 4; i < argument_count; i++) { |
| 3965 | stack_argument[i - 4] = va_arg(parameters, int32_t); |
| 3966 | } |
| 3967 | va_end(parameters); |
| 3968 | set_register(sp, entry_stack); |
| 3969 | |
| 3970 | CallInternal(entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3971 | |
| 3972 | // Pop stack passed arguments. |
| 3973 | CHECK_EQ(entry_stack, get_register(sp)); |
| 3974 | set_register(sp, original_stack); |
| 3975 | |
| 3976 | int32_t result = get_register(r0); |
| 3977 | return result; |
| 3978 | } |
| 3979 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3980 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3981 | void Simulator::CallFP(byte* entry, double d0, double d1) { |
| 3982 | if (use_eabi_hardfloat()) { |
| 3983 | set_d_register_from_double(0, d0); |
| 3984 | set_d_register_from_double(1, d1); |
| 3985 | } else { |
| 3986 | set_register_pair_from_double(0, &d0); |
| 3987 | set_register_pair_from_double(2, &d1); |
| 3988 | } |
| 3989 | CallInternal(entry); |
| 3990 | } |
| 3991 | |
| 3992 | |
| 3993 | int32_t Simulator::CallFPReturnsInt(byte* entry, double d0, double d1) { |
| 3994 | CallFP(entry, d0, d1); |
| 3995 | int32_t result = get_register(r0); |
| 3996 | return result; |
| 3997 | } |
| 3998 | |
| 3999 | |
| 4000 | double Simulator::CallFPReturnsDouble(byte* entry, double d0, double d1) { |
| 4001 | CallFP(entry, d0, d1); |
| 4002 | if (use_eabi_hardfloat()) { |
| 4003 | return get_double_from_d_register(0); |
| 4004 | } else { |
| 4005 | return get_double_from_register_pair(0); |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4010 | uintptr_t Simulator::PushAddress(uintptr_t address) { |
| 4011 | int new_sp = get_register(sp) - sizeof(uintptr_t); |
| 4012 | uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(new_sp); |
| 4013 | *stack_slot = address; |
| 4014 | set_register(sp, new_sp); |
| 4015 | return new_sp; |
| 4016 | } |
| 4017 | |
| 4018 | |
| 4019 | uintptr_t Simulator::PopAddress() { |
| 4020 | int current_sp = get_register(sp); |
| 4021 | uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(current_sp); |
| 4022 | uintptr_t address = *stack_slot; |
| 4023 | set_register(sp, current_sp + sizeof(uintptr_t)); |
| 4024 | return address; |
| 4025 | } |
| 4026 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4027 | } } // namespace v8::internal |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4028 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4029 | #endif // USE_SIMULATOR |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4030 | |
| 4031 | #endif // V8_TARGET_ARCH_ARM |