| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 namespace v8 { | 44 namespace v8 { |
| 45 namespace internal { | 45 namespace internal { |
| 46 | 46 |
| 47 // When running without a simulator we call the entry directly. | 47 // When running without a simulator we call the entry directly. |
| 48 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ | 48 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ |
| 49 (entry(p0, p1, p2, p3, p4)) | 49 (entry(p0, p1, p2, p3, p4)) |
| 50 | 50 |
| 51 // Call the generated regexp code directly. The entry function pointer should | 51 // Call the generated regexp code directly. The entry function pointer should |
| 52 // expect seven int/pointer sized arguments and return an int. | 52 // expect seven int/pointer sized arguments and return an int. |
| 53 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ | 53 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ |
| 54 (entry(p0, p1, p2, p3, p4, p5, p6)) | 54 (entry(p0, p1, p2, p3, NULL, p4, p5, p6)) |
| 55 | 55 |
| 56 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ | 56 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ |
| 57 (reinterpret_cast<TryCatch*>(try_catch_address)) | 57 (reinterpret_cast<TryCatch*>(try_catch_address)) |
| 58 | 58 |
| 59 // The stack limit beyond which we will throw stack overflow errors in | 59 // The stack limit beyond which we will throw stack overflow errors in |
| 60 // generated code. Because generated code on arm uses the C stack, we | 60 // generated code. Because generated code on arm uses the C stack, we |
| 61 // just use the C stack limit. | 61 // just use the C stack limit. |
| 62 class SimulatorStack : public v8::internal::AllStatic { | 62 class SimulatorStack : public v8::internal::AllStatic { |
| 63 public: | 63 public: |
| 64 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { | 64 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { |
| 65 return c_limit; | 65 return c_limit; |
| 66 } | 66 } |
| 67 | 67 |
| 68 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { | 68 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { |
| 69 return try_catch_address; | 69 return try_catch_address; |
| 70 } | 70 } |
| 71 | 71 |
| 72 static inline void UnregisterCTryCatch() { } | 72 static inline void UnregisterCTryCatch() { } |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } } // namespace v8::internal | 75 } } // namespace v8::internal |
| 76 | 76 |
| 77 #else // !defined(USE_SIMULATOR) | 77 #else // !defined(USE_SIMULATOR) |
| 78 // Running with a simulator. | 78 // Running with a simulator. |
| 79 | 79 |
| 80 #include "constants-arm.h" | 80 #include "constants-arm.h" |
| 81 #include "hashmap.h" | 81 #include "hashmap.h" |
| 82 #include "assembler.h" |
| 82 | 83 |
| 83 namespace assembler { | 84 namespace v8 { |
| 84 namespace arm { | 85 namespace internal { |
| 85 | 86 |
| 86 class CachePage { | 87 class CachePage { |
| 87 public: | 88 public: |
| 88 static const int LINE_VALID = 0; | 89 static const int LINE_VALID = 0; |
| 89 static const int LINE_INVALID = 1; | 90 static const int LINE_INVALID = 1; |
| 90 | 91 |
| 91 static const int kPageShift = 12; | 92 static const int kPageShift = 12; |
| 92 static const int kPageSize = 1 << kPageShift; | 93 static const int kPageSize = 1 << kPageShift; |
| 93 static const int kPageMask = kPageSize - 1; | 94 static const int kPageMask = kPageSize - 1; |
| 94 static const int kLineShift = 2; // The cache line is only 4 bytes right now. | 95 static const int kLineShift = 2; // The cache line is only 4 bytes right now. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // without being properly setup. | 197 // without being properly setup. |
| 197 bad_lr = -1, | 198 bad_lr = -1, |
| 198 // A pc value used to signal the simulator to stop execution. Generally | 199 // A pc value used to signal the simulator to stop execution. Generally |
| 199 // the lr is set to this value on transition from native C code to | 200 // the lr is set to this value on transition from native C code to |
| 200 // simulated execution, so that the simulator can "return" to the native | 201 // simulated execution, so that the simulator can "return" to the native |
| 201 // C code. | 202 // C code. |
| 202 end_sim_pc = -2 | 203 end_sim_pc = -2 |
| 203 }; | 204 }; |
| 204 | 205 |
| 205 // Unsupported instructions use Format to print an error and stop execution. | 206 // Unsupported instructions use Format to print an error and stop execution. |
| 206 void Format(Instr* instr, const char* format); | 207 void Format(Instruction* instr, const char* format); |
| 207 | 208 |
| 208 // Checks if the current instruction should be executed based on its | 209 // Checks if the current instruction should be executed based on its |
| 209 // condition bits. | 210 // condition bits. |
| 210 bool ConditionallyExecute(Instr* instr); | 211 bool ConditionallyExecute(Instruction* instr); |
| 211 | 212 |
| 212 // Helper functions to set the conditional flags in the architecture state. | 213 // Helper functions to set the conditional flags in the architecture state. |
| 213 void SetNZFlags(int32_t val); | 214 void SetNZFlags(int32_t val); |
| 214 void SetCFlag(bool val); | 215 void SetCFlag(bool val); |
| 215 void SetVFlag(bool val); | 216 void SetVFlag(bool val); |
| 216 bool CarryFrom(int32_t left, int32_t right); | 217 bool CarryFrom(int32_t left, int32_t right); |
| 217 bool BorrowFrom(int32_t left, int32_t right); | 218 bool BorrowFrom(int32_t left, int32_t right); |
| 218 bool OverflowFrom(int32_t alu_out, | 219 bool OverflowFrom(int32_t alu_out, |
| 219 int32_t left, | 220 int32_t left, |
| 220 int32_t right, | 221 int32_t right, |
| 221 bool addition); | 222 bool addition); |
| 222 | 223 |
| 223 // Support for VFP. | 224 // Support for VFP. |
| 224 void Compute_FPSCR_Flags(double val1, double val2); | 225 void Compute_FPSCR_Flags(double val1, double val2); |
| 225 void Copy_FPSCR_to_APSR(); | 226 void Copy_FPSCR_to_APSR(); |
| 226 | 227 |
| 227 // Helper functions to decode common "addressing" modes | 228 // Helper functions to decode common "addressing" modes |
| 228 int32_t GetShiftRm(Instr* instr, bool* carry_out); | 229 int32_t GetShiftRm(Instruction* instr, bool* carry_out); |
| 229 int32_t GetImm(Instr* instr, bool* carry_out); | 230 int32_t GetImm(Instruction* instr, bool* carry_out); |
| 230 void HandleRList(Instr* instr, bool load); | 231 void HandleRList(Instruction* instr, bool load); |
| 231 void SoftwareInterrupt(Instr* instr); | 232 void SoftwareInterrupt(Instruction* instr); |
| 232 | 233 |
| 233 // Stop helper functions. | 234 // Stop helper functions. |
| 234 inline bool isStopInstruction(Instr* instr); | 235 inline bool isStopInstruction(Instruction* instr); |
| 235 inline bool isWatchedStop(uint32_t bkpt_code); | 236 inline bool isWatchedStop(uint32_t bkpt_code); |
| 236 inline bool isEnabledStop(uint32_t bkpt_code); | 237 inline bool isEnabledStop(uint32_t bkpt_code); |
| 237 inline void EnableStop(uint32_t bkpt_code); | 238 inline void EnableStop(uint32_t bkpt_code); |
| 238 inline void DisableStop(uint32_t bkpt_code); | 239 inline void DisableStop(uint32_t bkpt_code); |
| 239 inline void IncreaseStopCounter(uint32_t bkpt_code); | 240 inline void IncreaseStopCounter(uint32_t bkpt_code); |
| 240 void PrintStopInfo(uint32_t code); | 241 void PrintStopInfo(uint32_t code); |
| 241 | 242 |
| 242 // Read and write memory. | 243 // Read and write memory. |
| 243 inline uint8_t ReadBU(int32_t addr); | 244 inline uint8_t ReadBU(int32_t addr); |
| 244 inline int8_t ReadB(int32_t addr); | 245 inline int8_t ReadB(int32_t addr); |
| 245 inline void WriteB(int32_t addr, uint8_t value); | 246 inline void WriteB(int32_t addr, uint8_t value); |
| 246 inline void WriteB(int32_t addr, int8_t value); | 247 inline void WriteB(int32_t addr, int8_t value); |
| 247 | 248 |
| 248 inline uint16_t ReadHU(int32_t addr, Instr* instr); | 249 inline uint16_t ReadHU(int32_t addr, Instruction* instr); |
| 249 inline int16_t ReadH(int32_t addr, Instr* instr); | 250 inline int16_t ReadH(int32_t addr, Instruction* instr); |
| 250 // Note: Overloaded on the sign of the value. | 251 // Note: Overloaded on the sign of the value. |
| 251 inline void WriteH(int32_t addr, uint16_t value, Instr* instr); | 252 inline void WriteH(int32_t addr, uint16_t value, Instruction* instr); |
| 252 inline void WriteH(int32_t addr, int16_t value, Instr* instr); | 253 inline void WriteH(int32_t addr, int16_t value, Instruction* instr); |
| 253 | 254 |
| 254 inline int ReadW(int32_t addr, Instr* instr); | 255 inline int ReadW(int32_t addr, Instruction* instr); |
| 255 inline void WriteW(int32_t addr, int value, Instr* instr); | 256 inline void WriteW(int32_t addr, int value, Instruction* instr); |
| 256 | 257 |
| 257 int32_t* ReadDW(int32_t addr); | 258 int32_t* ReadDW(int32_t addr); |
| 258 void WriteDW(int32_t addr, int32_t value1, int32_t value2); | 259 void WriteDW(int32_t addr, int32_t value1, int32_t value2); |
| 259 | 260 |
| 260 // Executing is handled based on the instruction type. | 261 // Executing is handled based on the instruction type. |
| 261 void DecodeType01(Instr* instr); // both type 0 and type 1 rolled into one | 262 // Both type 0 and type 1 rolled into one. |
| 262 void DecodeType2(Instr* instr); | 263 void DecodeType01(Instruction* instr); |
| 263 void DecodeType3(Instr* instr); | 264 void DecodeType2(Instruction* instr); |
| 264 void DecodeType4(Instr* instr); | 265 void DecodeType3(Instruction* instr); |
| 265 void DecodeType5(Instr* instr); | 266 void DecodeType4(Instruction* instr); |
| 266 void DecodeType6(Instr* instr); | 267 void DecodeType5(Instruction* instr); |
| 267 void DecodeType7(Instr* instr); | 268 void DecodeType6(Instruction* instr); |
| 269 void DecodeType7(Instruction* instr); |
| 268 | 270 |
| 269 // Support for VFP. | 271 // Support for VFP. |
| 270 void DecodeTypeVFP(Instr* instr); | 272 void DecodeTypeVFP(Instruction* instr); |
| 271 void DecodeType6CoprocessorIns(Instr* instr); | 273 void DecodeType6CoprocessorIns(Instruction* instr); |
| 272 | 274 |
| 273 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instr* instr); | 275 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr); |
| 274 void DecodeVCMP(Instr* instr); | 276 void DecodeVCMP(Instruction* instr); |
| 275 void DecodeVCVTBetweenDoubleAndSingle(Instr* instr); | 277 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr); |
| 276 void DecodeVCVTBetweenFloatingPointAndInteger(Instr* instr); | 278 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr); |
| 277 | 279 |
| 278 // Executes one instruction. | 280 // Executes one instruction. |
| 279 void InstructionDecode(Instr* instr); | 281 void InstructionDecode(Instruction* instr); |
| 280 | 282 |
| 281 // ICache. | 283 // ICache. |
| 282 static void CheckICache(Instr* instr); | 284 static void CheckICache(Instruction* instr); |
| 283 static void FlushOnePage(intptr_t start, int size); | 285 static void FlushOnePage(intptr_t start, int size); |
| 284 static CachePage* GetCachePage(void* page); | 286 static CachePage* GetCachePage(void* page); |
| 285 | 287 |
| 286 // Runtime call support. | 288 // Runtime call support. |
| 287 static void* RedirectExternalReference(void* external_function, | 289 static void* RedirectExternalReference( |
| 288 bool fp_return); | 290 void* external_function, |
| 291 v8::internal::ExternalReference::Type type); |
| 289 | 292 |
| 290 // For use in calls that take two double values, constructed from r0, r1, r2 | 293 // For use in calls that take two double values, constructed from r0, r1, r2 |
| 291 // and r3. | 294 // and r3. |
| 292 void GetFpArgs(double* x, double* y); | 295 void GetFpArgs(double* x, double* y); |
| 293 void SetFpResult(const double& result); | 296 void SetFpResult(const double& result); |
| 294 void TrashCallerSaveRegisters(); | 297 void TrashCallerSaveRegisters(); |
| 295 | 298 |
| 296 // Architecture state. | 299 // Architecture state. |
| 297 // Saturating instructions require a Q flag to indicate saturation. | 300 // Saturating instructions require a Q flag to indicate saturation. |
| 298 // There is currently no way to read the CPSR directly, and thus read the Q | 301 // There is currently no way to read the CPSR directly, and thus read the Q |
| 299 // flag, so this is left unimplemented. | 302 // flag, so this is left unimplemented. |
| 300 int32_t registers_[16]; | 303 int32_t registers_[16]; |
| 301 bool n_flag_; | 304 bool n_flag_; |
| 302 bool z_flag_; | 305 bool z_flag_; |
| 303 bool c_flag_; | 306 bool c_flag_; |
| 304 bool v_flag_; | 307 bool v_flag_; |
| 305 | 308 |
| 306 // VFP architecture state. | 309 // VFP architecture state. |
| 307 unsigned int vfp_register[num_s_registers]; | 310 unsigned int vfp_register[num_s_registers]; |
| 308 bool n_flag_FPSCR_; | 311 bool n_flag_FPSCR_; |
| 309 bool z_flag_FPSCR_; | 312 bool z_flag_FPSCR_; |
| 310 bool c_flag_FPSCR_; | 313 bool c_flag_FPSCR_; |
| 311 bool v_flag_FPSCR_; | 314 bool v_flag_FPSCR_; |
| 312 | 315 |
| 313 // VFP rounding mode. See ARM DDI 0406B Page A2-29. | 316 // VFP rounding mode. See ARM DDI 0406B Page A2-29. |
| 314 FPSCRRoundingModes FPSCR_rounding_mode_; | 317 VFPRoundingMode FPSCR_rounding_mode_; |
| 315 | 318 |
| 316 // VFP FP exception flags architecture state. | 319 // VFP FP exception flags architecture state. |
| 317 bool inv_op_vfp_flag_; | 320 bool inv_op_vfp_flag_; |
| 318 bool div_zero_vfp_flag_; | 321 bool div_zero_vfp_flag_; |
| 319 bool overflow_vfp_flag_; | 322 bool overflow_vfp_flag_; |
| 320 bool underflow_vfp_flag_; | 323 bool underflow_vfp_flag_; |
| 321 bool inexact_vfp_flag_; | 324 bool inexact_vfp_flag_; |
| 322 | 325 |
| 323 // Simulator support. | 326 // Simulator support. |
| 324 char* stack_; | 327 char* stack_; |
| 325 bool pc_modified_; | 328 bool pc_modified_; |
| 326 int icount_; | 329 int icount_; |
| 327 static bool initialized_; | 330 static bool initialized_; |
| 328 | 331 |
| 329 // Icache simulation | 332 // Icache simulation |
| 330 static v8::internal::HashMap* i_cache_; | 333 static v8::internal::HashMap* i_cache_; |
| 331 | 334 |
| 332 // Registered breakpoints. | 335 // Registered breakpoints. |
| 333 Instr* break_pc_; | 336 Instruction* break_pc_; |
| 334 instr_t break_instr_; | 337 Instr break_instr_; |
| 335 | 338 |
| 336 // A stop is watched if its code is less than kNumOfWatchedStops. | 339 // A stop is watched if its code is less than kNumOfWatchedStops. |
| 337 // Only watched stops support enabling/disabling and the counter feature. | 340 // Only watched stops support enabling/disabling and the counter feature. |
| 338 static const uint32_t kNumOfWatchedStops = 256; | 341 static const uint32_t kNumOfWatchedStops = 256; |
| 339 | 342 |
| 340 // Breakpoint is disabled if bit 31 is set. | 343 // Breakpoint is disabled if bit 31 is set. |
| 341 static const uint32_t kStopDisabledBit = 1 << 31; | 344 static const uint32_t kStopDisabledBit = 1 << 31; |
| 342 | 345 |
| 343 // A stop is enabled, meaning the simulator will stop when meeting the | 346 // A stop is enabled, meaning the simulator will stop when meeting the |
| 344 // instruction, if bit 31 of watched_stops[code].count is unset. | 347 // instruction, if bit 31 of watched_stops[code].count is unset. |
| 345 // The value watched_stops[code].count & ~(1 << 31) indicates how many times | 348 // The value watched_stops[code].count & ~(1 << 31) indicates how many times |
| 346 // the breakpoint was hit or gone through. | 349 // the breakpoint was hit or gone through. |
| 347 struct StopCoundAndDesc { | 350 struct StopCountAndDesc { |
| 348 uint32_t count; | 351 uint32_t count; |
| 349 char* desc; | 352 char* desc; |
| 350 }; | 353 }; |
| 351 StopCoundAndDesc watched_stops[kNumOfWatchedStops]; | 354 StopCountAndDesc watched_stops[kNumOfWatchedStops]; |
| 352 }; | 355 }; |
| 353 | 356 |
| 354 } } // namespace assembler::arm | |
| 355 | |
| 356 | |
| 357 namespace v8 { | |
| 358 namespace internal { | |
| 359 | 357 |
| 360 // When running with the simulator transition into simulated execution at this | 358 // When running with the simulator transition into simulated execution at this |
| 361 // point. | 359 // point. |
| 362 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ | 360 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \ |
| 363 reinterpret_cast<Object*>(assembler::arm::Simulator::current()->Call( \ | 361 reinterpret_cast<Object*>(Simulator::current()->Call( \ |
| 364 FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4)) | 362 FUNCTION_ADDR(entry), 5, p0, p1, p2, p3, p4)) |
| 365 | 363 |
| 366 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ | 364 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \ |
| 367 assembler::arm::Simulator::current()->Call( \ | 365 Simulator::current()->Call( \ |
| 368 FUNCTION_ADDR(entry), 7, p0, p1, p2, p3, p4, p5, p6) | 366 FUNCTION_ADDR(entry), 8, p0, p1, p2, p3, NULL, p4, p5, p6) |
| 369 | 367 |
| 370 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ | 368 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \ |
| 371 try_catch_address == \ | 369 try_catch_address == \ |
| 372 NULL ? NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) | 370 NULL ? NULL : *(reinterpret_cast<TryCatch**>(try_catch_address)) |
| 373 | 371 |
| 374 | 372 |
| 375 // The simulator has its own stack. Thus it has a different stack limit from | 373 // The simulator has its own stack. Thus it has a different stack limit from |
| 376 // the C-based native code. Setting the c_limit to indicate a very small | 374 // the C-based native code. Setting the c_limit to indicate a very small |
| 377 // stack cause stack overflow errors, since the simulator ignores the input. | 375 // stack cause stack overflow errors, since the simulator ignores the input. |
| 378 // This is unlikely to be an issue in practice, though it might cause testing | 376 // This is unlikely to be an issue in practice, though it might cause testing |
| 379 // trouble down the line. | 377 // trouble down the line. |
| 380 class SimulatorStack : public v8::internal::AllStatic { | 378 class SimulatorStack : public v8::internal::AllStatic { |
| 381 public: | 379 public: |
| 382 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { | 380 static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) { |
| 383 return assembler::arm::Simulator::current()->StackLimit(); | 381 return Simulator::current()->StackLimit(); |
| 384 } | 382 } |
| 385 | 383 |
| 386 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { | 384 static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) { |
| 387 assembler::arm::Simulator* sim = assembler::arm::Simulator::current(); | 385 Simulator* sim = Simulator::current(); |
| 388 return sim->PushAddress(try_catch_address); | 386 return sim->PushAddress(try_catch_address); |
| 389 } | 387 } |
| 390 | 388 |
| 391 static inline void UnregisterCTryCatch() { | 389 static inline void UnregisterCTryCatch() { |
| 392 assembler::arm::Simulator::current()->PopAddress(); | 390 Simulator::current()->PopAddress(); |
| 393 } | 391 } |
| 394 }; | 392 }; |
| 395 | 393 |
| 396 } } // namespace v8::internal | 394 } } // namespace v8::internal |
| 397 | 395 |
| 398 #endif // !defined(USE_SIMULATOR) | 396 #endif // !defined(USE_SIMULATOR) |
| 399 #endif // V8_ARM_SIMULATOR_ARM_H_ | 397 #endif // V8_ARM_SIMULATOR_ARM_H_ |
| OLD | NEW |