| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 static inline void UnregisterCTryCatch() { } | 72 static inline void UnregisterCTryCatch() { } |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 #else // !defined(USE_SIMULATOR) | 75 #else // !defined(USE_SIMULATOR) |
| 76 // Running with a simulator. | 76 // Running with a simulator. |
| 77 | 77 |
| 78 #include "constants-arm.h" | 78 #include "constants-arm.h" |
| 79 #include "hashmap.h" | 79 #include "hashmap.h" |
| 80 | 80 |
| 81 namespace assembler { | 81 namespace v8 { |
| 82 namespace arm { | 82 namespace internal { |
| 83 | 83 |
| 84 class CachePage { | 84 class CachePage { |
| 85 public: | 85 public: |
| 86 static const int LINE_VALID = 0; | 86 static const int LINE_VALID = 0; |
| 87 static const int LINE_INVALID = 1; | 87 static const int LINE_INVALID = 1; |
| 88 | 88 |
| 89 static const int kPageShift = 12; | 89 static const int kPageShift = 12; |
| 90 static const int kPageSize = 1 << kPageShift; | 90 static const int kPageSize = 1 << kPageShift; |
| 91 static const int kPageMask = kPageSize - 1; | 91 static const int kPageMask = kPageSize - 1; |
| 92 static const int kLineShift = 2; // The cache line is only 4 bytes right now. | 92 static const int kLineShift = 2; // The cache line is only 4 bytes right now. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 char data_[kPageSize]; // The cached data. | 109 char data_[kPageSize]; // The cached data. |
| 110 static const int kValidityMapSize = kPageSize >> kLineShift; | 110 static const int kValidityMapSize = kPageSize >> kLineShift; |
| 111 char validity_map_[kValidityMapSize]; // One byte per line. | 111 char validity_map_[kValidityMapSize]; // One byte per line. |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 | 114 |
| 115 class Simulator { | 115 class Simulator { |
| 116 public: | 116 public: |
| 117 friend class Debugger; | 117 friend class ArmDebugger; |
| 118 enum Register { | 118 enum Register { |
| 119 no_reg = -1, | 119 no_reg = -1, |
| 120 r0 = 0, r1, r2, r3, r4, r5, r6, r7, | 120 r0 = 0, r1, r2, r3, r4, r5, r6, r7, |
| 121 r8, r9, r10, r11, r12, r13, r14, r15, | 121 r8, r9, r10, r11, r12, r13, r14, r15, |
| 122 num_registers, | 122 num_registers, |
| 123 sp = 13, | 123 sp = 13, |
| 124 lr = 14, | 124 lr = 14, |
| 125 pc = 15, | 125 pc = 15, |
| 126 s0 = 0, s1, s2, s3, s4, s5, s6, s7, | 126 s0 = 0, s1, s2, s3, s4, s5, s6, s7, |
| 127 s8, s9, s10, s11, s12, s13, s14, s15, | 127 s8, s9, s10, s11, s12, s13, s14, s15, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // without being properly setup. | 195 // without being properly setup. |
| 196 bad_lr = -1, | 196 bad_lr = -1, |
| 197 // A pc value used to signal the simulator to stop execution. Generally | 197 // A pc value used to signal the simulator to stop execution. Generally |
| 198 // the lr is set to this value on transition from native C code to | 198 // the lr is set to this value on transition from native C code to |
| 199 // simulated execution, so that the simulator can "return" to the native | 199 // simulated execution, so that the simulator can "return" to the native |
| 200 // C code. | 200 // C code. |
| 201 end_sim_pc = -2 | 201 end_sim_pc = -2 |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 // Unsupported instructions use Format to print an error and stop execution. | 204 // Unsupported instructions use Format to print an error and stop execution. |
| 205 void Format(Instr* instr, const char* format); | 205 void Format(Instruction* instr, const char* format); |
| 206 | 206 |
| 207 // Checks if the current instruction should be executed based on its | 207 // Checks if the current instruction should be executed based on its |
| 208 // condition bits. | 208 // condition bits. |
| 209 bool ConditionallyExecute(Instr* instr); | 209 bool ConditionallyExecute(Instruction* instr); |
| 210 | 210 |
| 211 // Helper functions to set the conditional flags in the architecture state. | 211 // Helper functions to set the conditional flags in the architecture state. |
| 212 void SetNZFlags(int32_t val); | 212 void SetNZFlags(int32_t val); |
| 213 void SetCFlag(bool val); | 213 void SetCFlag(bool val); |
| 214 void SetVFlag(bool val); | 214 void SetVFlag(bool val); |
| 215 bool CarryFrom(int32_t left, int32_t right); | 215 bool CarryFrom(int32_t left, int32_t right); |
| 216 bool BorrowFrom(int32_t left, int32_t right); | 216 bool BorrowFrom(int32_t left, int32_t right); |
| 217 bool OverflowFrom(int32_t alu_out, | 217 bool OverflowFrom(int32_t alu_out, |
| 218 int32_t left, | 218 int32_t left, |
| 219 int32_t right, | 219 int32_t right, |
| 220 bool addition); | 220 bool addition); |
| 221 | 221 |
| 222 // Support for VFP. | 222 // Support for VFP. |
| 223 void Compute_FPSCR_Flags(double val1, double val2); | 223 void Compute_FPSCR_Flags(double val1, double val2); |
| 224 void Copy_FPSCR_to_APSR(); | 224 void Copy_FPSCR_to_APSR(); |
| 225 | 225 |
| 226 // Helper functions to decode common "addressing" modes | 226 // Helper functions to decode common "addressing" modes |
| 227 int32_t GetShiftRm(Instr* instr, bool* carry_out); | 227 int32_t GetShiftRm(Instruction* instr, bool* carry_out); |
| 228 int32_t GetImm(Instr* instr, bool* carry_out); | 228 int32_t GetImm(Instruction* instr, bool* carry_out); |
| 229 void HandleRList(Instr* instr, bool load); | 229 void HandleRList(Instruction* instr, bool load); |
| 230 void SoftwareInterrupt(Instr* instr); | 230 void SoftwareInterrupt(Instruction* instr); |
| 231 | 231 |
| 232 // Stop helper functions. | 232 // Stop helper functions. |
| 233 inline bool isStopInstruction(Instr* instr); | 233 inline bool isStopInstruction(Instruction* instr); |
| 234 inline bool isWatchedStop(uint32_t bkpt_code); | 234 inline bool isWatchedStop(uint32_t bkpt_code); |
| 235 inline bool isEnabledStop(uint32_t bkpt_code); | 235 inline bool isEnabledStop(uint32_t bkpt_code); |
| 236 inline void EnableStop(uint32_t bkpt_code); | 236 inline void EnableStop(uint32_t bkpt_code); |
| 237 inline void DisableStop(uint32_t bkpt_code); | 237 inline void DisableStop(uint32_t bkpt_code); |
| 238 inline void IncreaseStopCounter(uint32_t bkpt_code); | 238 inline void IncreaseStopCounter(uint32_t bkpt_code); |
| 239 void PrintStopInfo(uint32_t code); | 239 void PrintStopInfo(uint32_t code); |
| 240 | 240 |
| 241 // Read and write memory. | 241 // Read and write memory. |
| 242 inline uint8_t ReadBU(int32_t addr); | 242 inline uint8_t ReadBU(int32_t addr); |
| 243 inline int8_t ReadB(int32_t addr); | 243 inline int8_t ReadB(int32_t addr); |
| 244 inline void WriteB(int32_t addr, uint8_t value); | 244 inline void WriteB(int32_t addr, uint8_t value); |
| 245 inline void WriteB(int32_t addr, int8_t value); | 245 inline void WriteB(int32_t addr, int8_t value); |
| 246 | 246 |
| 247 inline uint16_t ReadHU(int32_t addr, Instr* instr); | 247 inline uint16_t ReadHU(int32_t addr, Instruction* instr); |
| 248 inline int16_t ReadH(int32_t addr, Instr* instr); | 248 inline int16_t ReadH(int32_t addr, Instruction* instr); |
| 249 // Note: Overloaded on the sign of the value. | 249 // Note: Overloaded on the sign of the value. |
| 250 inline void WriteH(int32_t addr, uint16_t value, Instr* instr); | 250 inline void WriteH(int32_t addr, uint16_t value, Instruction* instr); |
| 251 inline void WriteH(int32_t addr, int16_t value, Instr* instr); | 251 inline void WriteH(int32_t addr, int16_t value, Instruction* instr); |
| 252 | 252 |
| 253 inline int ReadW(int32_t addr, Instr* instr); | 253 inline int ReadW(int32_t addr, Instruction* instr); |
| 254 inline void WriteW(int32_t addr, int value, Instr* instr); | 254 inline void WriteW(int32_t addr, int value, Instruction* instr); |
| 255 | 255 |
| 256 int32_t* ReadDW(int32_t addr); | 256 int32_t* ReadDW(int32_t addr); |
| 257 void WriteDW(int32_t addr, int32_t value1, int32_t value2); | 257 void WriteDW(int32_t addr, int32_t value1, int32_t value2); |
| 258 | 258 |
| 259 // Executing is handled based on the instruction type. | 259 // Executing is handled based on the instruction type. |
| 260 void DecodeType01(Instr* instr); // both type 0 and type 1 rolled into one | 260 // Both type 0 and type 1 rolled into one. |
| 261 void DecodeType2(Instr* instr); | 261 void DecodeType01(Instruction* instr); |
| 262 void DecodeType3(Instr* instr); | 262 void DecodeType2(Instruction* instr); |
| 263 void DecodeType4(Instr* instr); | 263 void DecodeType3(Instruction* instr); |
| 264 void DecodeType5(Instr* instr); | 264 void DecodeType4(Instruction* instr); |
| 265 void DecodeType6(Instr* instr); | 265 void DecodeType5(Instruction* instr); |
| 266 void DecodeType7(Instr* instr); | 266 void DecodeType6(Instruction* instr); |
| 267 void DecodeType7(Instruction* instr); |
| 267 | 268 |
| 268 // Support for VFP. | 269 // Support for VFP. |
| 269 void DecodeTypeVFP(Instr* instr); | 270 void DecodeTypeVFP(Instruction* instr); |
| 270 void DecodeType6CoprocessorIns(Instr* instr); | 271 void DecodeType6CoprocessorIns(Instruction* instr); |
| 271 | 272 |
| 272 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instr* instr); | 273 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr); |
| 273 void DecodeVCMP(Instr* instr); | 274 void DecodeVCMP(Instruction* instr); |
| 274 void DecodeVCVTBetweenDoubleAndSingle(Instr* instr); | 275 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr); |
| 275 void DecodeVCVTBetweenFloatingPointAndInteger(Instr* instr); | 276 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr); |
| 276 | 277 |
| 277 // Executes one instruction. | 278 // Executes one instruction. |
| 278 void InstructionDecode(Instr* instr); | 279 void InstructionDecode(Instruction* instr); |
| 279 | 280 |
| 280 // ICache. | 281 // ICache. |
| 281 static void CheckICache(v8::internal::HashMap* i_cache, Instr* instr); | 282 static void CheckICache(v8::internal::HashMap* i_cache, Instruction* instr); |
| 282 static void FlushOnePage(v8::internal::HashMap* i_cache, intptr_t start, | 283 static void FlushOnePage(v8::internal::HashMap* i_cache, intptr_t start, |
| 283 int size); | 284 int size); |
| 284 static CachePage* GetCachePage(v8::internal::HashMap* i_cache, void* page); | 285 static CachePage* GetCachePage(v8::internal::HashMap* i_cache, void* page); |
| 285 | 286 |
| 286 // Runtime call support. | 287 // Runtime call support. |
| 287 static void* RedirectExternalReference(void* external_function, | 288 static void* RedirectExternalReference(void* external_function, |
| 288 bool fp_return); | 289 bool fp_return); |
| 289 | 290 |
| 290 // For use in calls that take two double values, constructed from r0, r1, r2 | 291 // For use in calls that take two double values, constructed from r0, r1, r2 |
| 291 // and r3. | 292 // and r3. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 322 | 323 |
| 323 // Simulator support. | 324 // Simulator support. |
| 324 char* stack_; | 325 char* stack_; |
| 325 bool pc_modified_; | 326 bool pc_modified_; |
| 326 int icount_; | 327 int icount_; |
| 327 | 328 |
| 328 // Icache simulation | 329 // Icache simulation |
| 329 v8::internal::HashMap* i_cache_; | 330 v8::internal::HashMap* i_cache_; |
| 330 | 331 |
| 331 // Registered breakpoints. | 332 // Registered breakpoints. |
| 332 Instr* break_pc_; | 333 Instruction* break_pc_; |
| 333 instr_t break_instr_; | 334 Instr break_instr_; |
| 334 | 335 |
| 335 v8::internal::Isolate* isolate_; | 336 v8::internal::Isolate* isolate_; |
| 336 | 337 |
| 337 // A stop is watched if its code is less than kNumOfWatchedStops. | 338 // A stop is watched if its code is less than kNumOfWatchedStops. |
| 338 // Only watched stops support enabling/disabling and the counter feature. | 339 // Only watched stops support enabling/disabling and the counter feature. |
| 339 static const uint32_t kNumOfWatchedStops = 256; | 340 static const uint32_t kNumOfWatchedStops = 256; |
| 340 | 341 |
| 341 // Breakpoint is disabled if bit 31 is set. | 342 // Breakpoint is disabled if bit 31 is set. |
| 342 static const uint32_t kStopDisabledBit = 1 << 31; | 343 static const uint32_t kStopDisabledBit = 1 << 31; |
| 343 | 344 |
| 344 // A stop is enabled, meaning the simulator will stop when meeting the | 345 // A stop is enabled, meaning the simulator will stop when meeting the |
| 345 // instruction, if bit 31 of watched_stops[code].count is unset. | 346 // instruction, if bit 31 of watched_stops[code].count is unset. |
| 346 // The value watched_stops[code].count & ~(1 << 31) indicates how many times | 347 // The value watched_stops[code].count & ~(1 << 31) indicates how many times |
| 347 // the breakpoint was hit or gone through. | 348 // the breakpoint was hit or gone through. |
| 348 struct StopCoundAndDesc { | 349 struct StopCountAndDesc { |
| 349 uint32_t count; | 350 uint32_t count; |
| 350 char* desc; | 351 char* desc; |
| 351 }; | 352 }; |
| 352 StopCoundAndDesc watched_stops[kNumOfWatchedStops]; | 353 StopCountAndDesc watched_stops[kNumOfWatchedStops]; |
| 353 }; | 354 }; |
| 354 | 355 |
| 355 } } // namespace assembler::arm | |
| 356 | |
| 357 | |
| 358 namespace v8 { | |
| 359 namespace internal { | |
| 360 | 356 |
| 361 // When running with the simulator transition into simulated execution at this | 357 // When running with the simulator transition into simulated execution at this |
| 362 // point. | 358 // point. |
| 363 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ | 359 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ |
| 364 reinterpret_cast<Object*>( \ | 360 reinterpret_cast<Object*>(Simulator::current(Isolate::Current())->Call( \ |
| 365 assembler::arm::Simulator::current(Isolate::Current())-> \ | 361 FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4)) |
| 366 Call(FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4)) | |
| 367 | 362 |
| 368 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7) \ | 363 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7) \ |
| 369 assembler::arm::Simulator::current(Isolate::Current())->Call( \ | 364 Simulator::current(Isolate::Current())->Call( \ |
| 370 FUNCTION_ADDR(entry), 8, p0, p1, p2, p3, p4, p5, p6, p7) | 365 FUNCTION_ADDR(entry), 8, p0, p1, p2, p3, p4, p5, p6, p7) |
| 371 | 366 |
| 372 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ | 367 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ |
| 373 try_catch_address == NULL ? \ | 368 try_catch_address == NULL ? \ |
| 374 NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) | 369 NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) |
| 375 | 370 |
| 376 | 371 |
| 377 // The simulator has its own stack. Thus it has a different stack limit from | 372 // The simulator has its own stack. Thus it has a different stack limit from |
| 378 // the C-based native code. Setting the c_limit to indicate a very small | 373 // the C-based native code. Setting the c_limit to indicate a very small |
| 379 // stack cause stack overflow errors, since the simulator ignores the input. | 374 // stack cause stack overflow errors, since the simulator ignores the input. |
| 380 // This is unlikely to be an issue in practice, though it might cause testing | 375 // This is unlikely to be an issue in practice, though it might cause testing |
| 381 // trouble down the line. | 376 // trouble down the line. |
| 382 class SimulatorStack : public v8::internal::AllStatic { | 377 class SimulatorStack : public v8::internal::AllStatic { |
| 383 public: | 378 public: |
| 384 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { | 379 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { |
| 385 return assembler::arm::Simulator::current( | 380 return Simulator::current(Isolate::Current())->StackLimit(); |
| 386 v8::internal::Isolate::Current())->StackLimit(); | |
| 387 } | 381 } |
| 388 | 382 |
| 389 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { | 383 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { |
| 390 assembler::arm::Simulator* sim = | 384 Simulator* sim = Simulator::current(Isolate::Current()); |
| 391 assembler::arm::Simulator::current(v8::internal::Isolate::Current()); | |
| 392 return sim->PushAddress(try_catch_address); | 385 return sim->PushAddress(try_catch_address); |
| 393 } | 386 } |
| 394 | 387 |
| 395 static inline void UnregisterCTryCatch() { | 388 static inline void UnregisterCTryCatch() { |
| 396 assembler::arm::Simulator::current(v8::internal::Isolate::Current())-> | 389 Simulator::current(Isolate::Current())->PopAddress(); |
| 397 PopAddress(); | |
| 398 } | 390 } |
| 399 }; | 391 }; |
| 400 | 392 |
| 401 } } // namespace v8::internal | 393 } } // namespace v8::internal |
| 402 | 394 |
| 403 #endif // !defined(USE_SIMULATOR) | 395 #endif // !defined(USE_SIMULATOR) |
| 404 #endif // V8_ARM_SIMULATOR_ARM_H_ | 396 #endif // V8_ARM_SIMULATOR_ARM_H_ |
| OLD | NEW |