| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 (entry(p0, p1, p2, p3, p4)) | 49 (entry(p0, p1, p2, p3, p4)) |
| 50 | 50 |
| 51 typedef int (*arm_regexp_matcher)(String*, int, const byte*, const byte*, | 51 typedef int (*arm_regexp_matcher)(String*, int, const byte*, const byte*, |
| 52 void*, int*, Address, int); | 52 void*, int*, Address, int); |
| 53 | 53 |
| 54 | 54 |
| 55 // Call the generated regexp code directly. The code at the entry address | 55 // Call the generated regexp code directly. The code at the entry address |
| 56 // should act as a function matching the type arm_regexp_matcher. | 56 // should act as a function matching the type arm_regexp_matcher. |
| 57 // The fifth argument is a dummy that reserves the space used for | 57 // The fifth argument is a dummy that reserves the space used for |
| 58 // the return address added by the ExitFrame in native calls. | 58 // the return address added by the ExitFrame in native calls. |
| 59 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ | 59 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7) \ |
| 60 (FUNCTION_CAST<arm_regexp_matcher>(entry)(p0, p1, p2, p3, NULL, p4, p5, p6)) | 60 (FUNCTION_CAST<arm_regexp_matcher>(entry)( \ |
| 61 p0, p1, p2, p3, NULL, p4, p5, p6, p7)) |
| 61 | 62 |
| 62 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ | 63 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ |
| 63 (reinterpret_cast<TryCatch*>(try_catch_address)) | 64 reinterpret_cast<TryCatch*>(try_catch_address) |
| 64 | 65 |
| 65 // The stack limit beyond which we will throw stack overflow errors in | 66 // The stack limit beyond which we will throw stack overflow errors in |
| 66 // generated code. Because generated code on arm uses the C stack, we | 67 // generated code. Because generated code on arm uses the C stack, we |
| 67 // just use the C stack limit. | 68 // just use the C stack limit. |
| 68 class SimulatorStack : public v8::internal::AllStatic { | 69 class SimulatorStack : public v8::internal::AllStatic { |
| 69 public: | 70 public: |
| 70 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { | 71 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { |
| 71 return c_limit; | 72 return c_limit; |
| 72 } | 73 } |
| 73 | 74 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 char data_[kPageSize]; // The cached data. | 119 char data_[kPageSize]; // The cached data. |
| 119 static const int kValidityMapSize = kPageSize >> kLineShift; | 120 static const int kValidityMapSize = kPageSize >> kLineShift; |
| 120 char validity_map_[kValidityMapSize]; // One byte per line. | 121 char validity_map_[kValidityMapSize]; // One byte per line. |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 | 124 |
| 124 class Simulator { | 125 class Simulator { |
| 125 public: | 126 public: |
| 126 friend class Debugger; | 127 friend class ArmDebugger; |
| 127 enum Register { | 128 enum Register { |
| 128 no_reg = -1, | 129 no_reg = -1, |
| 129 r0 = 0, r1, r2, r3, r4, r5, r6, r7, | 130 r0 = 0, r1, r2, r3, r4, r5, r6, r7, |
| 130 r8, r9, r10, r11, r12, r13, r14, r15, | 131 r8, r9, r10, r11, r12, r13, r14, r15, |
| 131 num_registers, | 132 num_registers, |
| 132 sp = 13, | 133 sp = 13, |
| 133 lr = 14, | 134 lr = 14, |
| 134 pc = 15, | 135 pc = 15, |
| 135 s0 = 0, s1, s2, s3, s4, s5, s6, s7, | 136 s0 = 0, s1, s2, s3, s4, s5, s6, s7, |
| 136 s8, s9, s10, s11, s12, s13, s14, s15, | 137 s8, s9, s10, s11, s12, s13, s14, s15, |
| 137 s16, s17, s18, s19, s20, s21, s22, s23, | 138 s16, s17, s18, s19, s20, s21, s22, s23, |
| 138 s24, s25, s26, s27, s28, s29, s30, s31, | 139 s24, s25, s26, s27, s28, s29, s30, s31, |
| 139 num_s_registers = 32, | 140 num_s_registers = 32, |
| 140 d0 = 0, d1, d2, d3, d4, d5, d6, d7, | 141 d0 = 0, d1, d2, d3, d4, d5, d6, d7, |
| 141 d8, d9, d10, d11, d12, d13, d14, d15, | 142 d8, d9, d10, d11, d12, d13, d14, d15, |
| 142 num_d_registers = 16 | 143 num_d_registers = 16 |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 Simulator(); | 146 Simulator(); |
| 146 ~Simulator(); | 147 ~Simulator(); |
| 147 | 148 |
| 148 // The currently executing Simulator instance. Potentially there can be one | 149 // The currently executing Simulator instance. Potentially there can be one |
| 149 // for each native thread. | 150 // for each native thread. |
| 150 static Simulator* current(); | 151 static Simulator* current(v8::internal::Isolate* isolate); |
| 151 | 152 |
| 152 // Accessors for register state. Reading the pc value adheres to the ARM | 153 // Accessors for register state. Reading the pc value adheres to the ARM |
| 153 // architecture specification and is off by a 8 from the currently executing | 154 // architecture specification and is off by a 8 from the currently executing |
| 154 // instruction. | 155 // instruction. |
| 155 void set_register(int reg, int32_t value); | 156 void set_register(int reg, int32_t value); |
| 156 int32_t get_register(int reg) const; | 157 int32_t get_register(int reg) const; |
| 157 void set_dw_register(int dreg, const int* dbl); | 158 void set_dw_register(int dreg, const int* dbl); |
| 158 | 159 |
| 159 // Support for VFP. | 160 // Support for VFP. |
| 160 void set_s_register(int reg, unsigned int value); | 161 void set_s_register(int reg, unsigned int value); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 184 // which sets up the simulator state and grabs the result on return. | 185 // which sets up the simulator state and grabs the result on return. |
| 185 int32_t Call(byte* entry, int argument_count, ...); | 186 int32_t Call(byte* entry, int argument_count, ...); |
| 186 | 187 |
| 187 // Push an address onto the JS stack. | 188 // Push an address onto the JS stack. |
| 188 uintptr_t PushAddress(uintptr_t address); | 189 uintptr_t PushAddress(uintptr_t address); |
| 189 | 190 |
| 190 // Pop an address from the JS stack. | 191 // Pop an address from the JS stack. |
| 191 uintptr_t PopAddress(); | 192 uintptr_t PopAddress(); |
| 192 | 193 |
| 193 // ICache checking. | 194 // ICache checking. |
| 194 static void FlushICache(void* start, size_t size); | 195 static void FlushICache(v8::internal::HashMap* i_cache, void* start, |
| 196 size_t size); |
| 195 | 197 |
| 196 // Returns true if pc register contains one of the 'special_values' defined | 198 // Returns true if pc register contains one of the 'special_values' defined |
| 197 // below (bad_lr, end_sim_pc). | 199 // below (bad_lr, end_sim_pc). |
| 198 bool has_bad_pc() const; | 200 bool has_bad_pc() const; |
| 199 | 201 |
| 200 private: | 202 private: |
| 201 enum special_values { | 203 enum special_values { |
| 202 // Known bad pc value to ensure that the simulator does not execute | 204 // Known bad pc value to ensure that the simulator does not execute |
| 203 // without being properly setup. | 205 // without being properly setup. |
| 204 bad_lr = -1, | 206 bad_lr = -1, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 282 |
| 281 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr); | 283 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr); |
| 282 void DecodeVCMP(Instruction* instr); | 284 void DecodeVCMP(Instruction* instr); |
| 283 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr); | 285 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr); |
| 284 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr); | 286 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr); |
| 285 | 287 |
| 286 // Executes one instruction. | 288 // Executes one instruction. |
| 287 void InstructionDecode(Instruction* instr); | 289 void InstructionDecode(Instruction* instr); |
| 288 | 290 |
| 289 // ICache. | 291 // ICache. |
| 290 static void CheckICache(Instruction* instr); | 292 static void CheckICache(v8::internal::HashMap* i_cache, Instruction* instr); |
| 291 static void FlushOnePage(intptr_t start, int size); | 293 static void FlushOnePage(v8::internal::HashMap* i_cache, intptr_t start, |
| 292 static CachePage* GetCachePage(void* page); | 294 int size); |
| 295 static CachePage* GetCachePage(v8::internal::HashMap* i_cache, void* page); |
| 293 | 296 |
| 294 // Runtime call support. | 297 // Runtime call support. |
| 295 static void* RedirectExternalReference( | 298 static void* RedirectExternalReference( |
| 296 void* external_function, | 299 void* external_function, |
| 297 v8::internal::ExternalReference::Type type); | 300 v8::internal::ExternalReference::Type type); |
| 298 | 301 |
| 299 // For use in calls that take two double values, constructed from r0, r1, r2 | 302 // For use in calls that take two double values, constructed from r0, r1, r2 |
| 300 // and r3. | 303 // and r3. |
| 301 void GetFpArgs(double* x, double* y); | 304 void GetFpArgs(double* x, double* y); |
| 302 void SetFpResult(const double& result); | 305 void SetFpResult(const double& result); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 326 bool inv_op_vfp_flag_; | 329 bool inv_op_vfp_flag_; |
| 327 bool div_zero_vfp_flag_; | 330 bool div_zero_vfp_flag_; |
| 328 bool overflow_vfp_flag_; | 331 bool overflow_vfp_flag_; |
| 329 bool underflow_vfp_flag_; | 332 bool underflow_vfp_flag_; |
| 330 bool inexact_vfp_flag_; | 333 bool inexact_vfp_flag_; |
| 331 | 334 |
| 332 // Simulator support. | 335 // Simulator support. |
| 333 char* stack_; | 336 char* stack_; |
| 334 bool pc_modified_; | 337 bool pc_modified_; |
| 335 int icount_; | 338 int icount_; |
| 336 static bool initialized_; | |
| 337 | 339 |
| 338 // Icache simulation | 340 // Icache simulation |
| 339 static v8::internal::HashMap* i_cache_; | 341 v8::internal::HashMap* i_cache_; |
| 340 | 342 |
| 341 // Registered breakpoints. | 343 // Registered breakpoints. |
| 342 Instruction* break_pc_; | 344 Instruction* break_pc_; |
| 343 Instr break_instr_; | 345 Instr break_instr_; |
| 344 | 346 |
| 347 v8::internal::Isolate* isolate_; |
| 348 |
| 345 // A stop is watched if its code is less than kNumOfWatchedStops. | 349 // A stop is watched if its code is less than kNumOfWatchedStops. |
| 346 // Only watched stops support enabling/disabling and the counter feature. | 350 // Only watched stops support enabling/disabling and the counter feature. |
| 347 static const uint32_t kNumOfWatchedStops = 256; | 351 static const uint32_t kNumOfWatchedStops = 256; |
| 348 | 352 |
| 349 // Breakpoint is disabled if bit 31 is set. | 353 // Breakpoint is disabled if bit 31 is set. |
| 350 static const uint32_t kStopDisabledBit = 1 << 31; | 354 static const uint32_t kStopDisabledBit = 1 << 31; |
| 351 | 355 |
| 352 // A stop is enabled, meaning the simulator will stop when meeting the | 356 // A stop is enabled, meaning the simulator will stop when meeting the |
| 353 // instruction, if bit 31 of watched_stops[code].count is unset. | 357 // instruction, if bit 31 of watched_stops[code].count is unset. |
| 354 // The value watched_stops[code].count & ~(1 << 31) indicates how many times | 358 // The value watched_stops[code].count & ~(1 << 31) indicates how many times |
| 355 // the breakpoint was hit or gone through. | 359 // the breakpoint was hit or gone through. |
| 356 struct StopCountAndDesc { | 360 struct StopCountAndDesc { |
| 357 uint32_t count; | 361 uint32_t count; |
| 358 char* desc; | 362 char* desc; |
| 359 }; | 363 }; |
| 360 StopCountAndDesc watched_stops[kNumOfWatchedStops]; | 364 StopCountAndDesc watched_stops[kNumOfWatchedStops]; |
| 361 }; | 365 }; |
| 362 | 366 |
| 363 | 367 |
| 364 // When running with the simulator transition into simulated execution at this | 368 // When running with the simulator transition into simulated execution at this |
| 365 // point. | 369 // point. |
| 366 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ | 370 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ |
| 367 reinterpret_cast<Object*>(Simulator::current()->Call( \ | 371 reinterpret_cast<Object*>(Simulator::current(Isolate::Current())->Call( \ |
| 368 FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4)) | 372 FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4)) |
| 369 | 373 |
| 370 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ | 374 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7) \ |
| 371 Simulator::current()->Call(entry, 8, p0, p1, p2, p3, NULL, p4, p5, p6) | 375 Simulator::current(Isolate::Current())->Call( \ |
| 376 entry, 9, p0, p1, p2, p3, NULL, p4, p5, p6, p7) |
| 372 | 377 |
| 373 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ | 378 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ |
| 374 try_catch_address == \ | 379 try_catch_address == NULL ? \ |
| 375 NULL ? NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) | 380 NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) |
| 376 | 381 |
| 377 | 382 |
| 378 // The simulator has its own stack. Thus it has a different stack limit from | 383 // The simulator has its own stack. Thus it has a different stack limit from |
| 379 // the C-based native code. Setting the c_limit to indicate a very small | 384 // the C-based native code. Setting the c_limit to indicate a very small |
| 380 // stack cause stack overflow errors, since the simulator ignores the input. | 385 // stack cause stack overflow errors, since the simulator ignores the input. |
| 381 // This is unlikely to be an issue in practice, though it might cause testing | 386 // This is unlikely to be an issue in practice, though it might cause testing |
| 382 // trouble down the line. | 387 // trouble down the line. |
| 383 class SimulatorStack : public v8::internal::AllStatic { | 388 class SimulatorStack : public v8::internal::AllStatic { |
| 384 public: | 389 public: |
| 385 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { | 390 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { |
| 386 return Simulator::current()->StackLimit(); | 391 return Simulator::current(Isolate::Current())->StackLimit(); |
| 387 } | 392 } |
| 388 | 393 |
| 389 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { | 394 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { |
| 390 Simulator* sim = Simulator::current(); | 395 Simulator* sim = Simulator::current(Isolate::Current()); |
| 391 return sim->PushAddress(try_catch_address); | 396 return sim->PushAddress(try_catch_address); |
| 392 } | 397 } |
| 393 | 398 |
| 394 static inline void UnregisterCTryCatch() { | 399 static inline void UnregisterCTryCatch() { |
| 395 Simulator::current()->PopAddress(); | 400 Simulator::current(Isolate::Current())->PopAddress(); |
| 396 } | 401 } |
| 397 }; | 402 }; |
| 398 | 403 |
| 399 } } // namespace v8::internal | 404 } } // namespace v8::internal |
| 400 | 405 |
| 401 #endif // !defined(USE_SIMULATOR) | 406 #endif // !defined(USE_SIMULATOR) |
| 402 #endif // V8_ARM_SIMULATOR_ARM_H_ | 407 #endif // V8_ARM_SIMULATOR_ARM_H_ |
| OLD | NEW |