Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: src/a64/simulator-a64.h

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/a64/regexp-macro-assembler-a64.cc ('k') | src/a64/simulator-a64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_A64_SIMULATOR_A64_H_
29 #define V8_A64_SIMULATOR_A64_H_
30
31 #include <stdarg.h>
32 #include <vector>
33
34 #include "v8.h"
35
36 #include "globals.h"
37 #include "utils.h"
38 #include "allocation.h"
39 #include "assembler.h"
40 #include "a64/assembler-a64.h"
41 #include "a64/decoder-a64.h"
42 #include "a64/disasm-a64.h"
43 #include "a64/instrument-a64.h"
44
45 #define REGISTER_CODE_LIST(R) \
46 R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
47 R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
48 R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
49 R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
50
51 namespace v8 {
52 namespace internal {
53
54 #if !defined(USE_SIMULATOR)
55
56 // Running without a simulator on a native A64 platform.
57 // When running without a simulator we call the entry directly.
58 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
59 (entry(p0, p1, p2, p3, p4))
60
61 typedef int (*a64_regexp_matcher)(String* input,
62 int64_t start_offset,
63 const byte* input_start,
64 const byte* input_end,
65 int* output,
66 int64_t output_size,
67 Address stack_base,
68 int64_t direct_call,
69 void* return_address,
70 Isolate* isolate);
71
72 // Call the generated regexp code directly. The code at the entry address
73 // should act as a function matching the type a64_regexp_matcher.
74 // The ninth argument is a dummy that reserves the space used for
75 // the return address added by the ExitFrame in native calls.
76 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7, p8) \
77 (FUNCTION_CAST<a64_regexp_matcher>(entry)( \
78 p0, p1, p2, p3, p4, p5, p6, p7, NULL, p8))
79
80 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
81 reinterpret_cast<TryCatch*>(try_catch_address)
82
83 // Running without a simulator there is nothing to do.
84 class SimulatorStack : public v8::internal::AllStatic {
85 public:
86 static uintptr_t JsLimitFromCLimit(v8::internal::Isolate* isolate,
87 uintptr_t c_limit) {
88 USE(isolate);
89 return c_limit;
90 }
91
92 static uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
93 return try_catch_address;
94 }
95
96 static void UnregisterCTryCatch() { }
97 };
98
99 #else // !defined(USE_SIMULATOR)
100
101 enum ReverseByteMode {
102 Reverse16 = 0,
103 Reverse32 = 1,
104 Reverse64 = 2
105 };
106
107
108 // The proper way to initialize a simulated system register (such as NZCV) is as
109 // follows:
110 // SimSystemRegister nzcv = SimSystemRegister::DefaultValueFor(NZCV);
111 class SimSystemRegister {
112 public:
113 // The default constructor represents a register which has no writable bits.
114 // It is not possible to set its value to anything other than 0.
115 SimSystemRegister() : value_(0), write_ignore_mask_(0xffffffff) { }
116
117 uint32_t RawValue() const {
118 return value_;
119 }
120
121 void SetRawValue(uint32_t new_value) {
122 value_ = (value_ & write_ignore_mask_) | (new_value & ~write_ignore_mask_);
123 }
124
125 uint32_t Bits(int msb, int lsb) const {
126 return unsigned_bitextract_32(msb, lsb, value_);
127 }
128
129 int32_t SignedBits(int msb, int lsb) const {
130 return signed_bitextract_32(msb, lsb, value_);
131 }
132
133 void SetBits(int msb, int lsb, uint32_t bits);
134
135 // Default system register values.
136 static SimSystemRegister DefaultValueFor(SystemRegister id);
137
138 #define DEFINE_GETTER(Name, HighBit, LowBit, Func) \
139 uint32_t Name() const { return Func(HighBit, LowBit); } \
140 void Set##Name(uint32_t bits) { SetBits(HighBit, LowBit, bits); }
141 #define DEFINE_WRITE_IGNORE_MASK(Name, Mask) \
142 static const uint32_t Name##WriteIgnoreMask = ~static_cast<uint32_t>(Mask);
143
144 SYSTEM_REGISTER_FIELDS_LIST(DEFINE_GETTER, DEFINE_WRITE_IGNORE_MASK)
145
146 #undef DEFINE_ZERO_BITS
147 #undef DEFINE_GETTER
148
149 protected:
150 // Most system registers only implement a few of the bits in the word. Other
151 // bits are "read-as-zero, write-ignored". The write_ignore_mask argument
152 // describes the bits which are not modifiable.
153 SimSystemRegister(uint32_t value, uint32_t write_ignore_mask)
154 : value_(value), write_ignore_mask_(write_ignore_mask) { }
155
156 uint32_t value_;
157 uint32_t write_ignore_mask_;
158 };
159
160
161 // Represent a register (r0-r31, v0-v31).
162 template<int kSizeInBytes>
163 class SimRegisterBase {
164 public:
165 template<typename T>
166 void Set(T new_value, unsigned size = sizeof(T)) {
167 ASSERT(size <= kSizeInBytes);
168 ASSERT(size <= sizeof(new_value));
169 // All AArch64 registers are zero-extending; Writing a W register clears the
170 // top bits of the corresponding X register.
171 memset(value_, 0, kSizeInBytes);
172 memcpy(value_, &new_value, size);
173 }
174
175 // Copy 'size' bytes of the register to the result, and zero-extend to fill
176 // the result.
177 template<typename T>
178 T Get(unsigned size = sizeof(T)) const {
179 ASSERT(size <= kSizeInBytes);
180 T result;
181 memset(&result, 0, sizeof(result));
182 memcpy(&result, value_, size);
183 return result;
184 }
185
186 protected:
187 uint8_t value_[kSizeInBytes];
188 };
189 typedef SimRegisterBase<kXRegSizeInBytes> SimRegister; // r0-r31
190 typedef SimRegisterBase<kDRegSizeInBytes> SimFPRegister; // v0-v31
191
192
193 class Simulator : public DecoderVisitor {
194 public:
195 explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
196 Isolate* isolate = NULL,
197 FILE* stream = stderr);
198 Simulator();
199 ~Simulator();
200
201 // System functions.
202
203 static void Initialize(Isolate* isolate);
204
205 static Simulator* current(v8::internal::Isolate* isolate);
206
207 class CallArgument;
208
209 // Call an arbitrary function taking an arbitrary number of arguments. The
210 // varargs list must be a set of arguments with type CallArgument, and
211 // terminated by CallArgument::End().
212 void CallVoid(byte* entry, CallArgument* args);
213
214 // Like CallVoid, but expect a return value.
215 int64_t CallInt64(byte* entry, CallArgument* args);
216 double CallDouble(byte* entry, CallArgument* args);
217
218 // V8 calls into generated JS code with 5 parameters and into
219 // generated RegExp code with 10 parameters. These are convenience functions,
220 // which set up the simulator state and grab the result on return.
221 int64_t CallJS(byte* entry,
222 byte* function_entry,
223 JSFunction* func,
224 Object* revc,
225 int64_t argc,
226 Object*** argv);
227 int64_t CallRegExp(byte* entry,
228 String* input,
229 int64_t start_offset,
230 const byte* input_start,
231 const byte* input_end,
232 int* output,
233 int64_t output_size,
234 Address stack_base,
235 int64_t direct_call,
236 void* return_address,
237 Isolate* isolate);
238
239 // A wrapper class that stores an argument for one of the above Call
240 // functions.
241 //
242 // Only arguments up to 64 bits in size are supported.
243 class CallArgument {
244 public:
245 template<typename T>
246 explicit CallArgument(T argument) {
247 ASSERT(sizeof(argument) <= sizeof(bits_));
248 memcpy(&bits_, &argument, sizeof(argument));
249 type_ = X_ARG;
250 }
251
252 explicit CallArgument(double argument) {
253 ASSERT(sizeof(argument) == sizeof(bits_));
254 memcpy(&bits_, &argument, sizeof(argument));
255 type_ = D_ARG;
256 }
257
258 explicit CallArgument(float argument) {
259 // TODO(all): CallArgument(float) is untested, remove this check once
260 // tested.
261 UNIMPLEMENTED();
262 // Make the D register a NaN to try to trap errors if the callee expects a
263 // double. If it expects a float, the callee should ignore the top word.
264 ASSERT(sizeof(kFP64SignallingNaN) == sizeof(bits_));
265 memcpy(&bits_, &kFP64SignallingNaN, sizeof(kFP64SignallingNaN));
266 // Write the float payload to the S register.
267 ASSERT(sizeof(argument) <= sizeof(bits_));
268 memcpy(&bits_, &argument, sizeof(argument));
269 type_ = D_ARG;
270 }
271
272 // This indicates the end of the arguments list, so that CallArgument
273 // objects can be passed into varargs functions.
274 static CallArgument End() { return CallArgument(); }
275
276 int64_t bits() const { return bits_; }
277 bool IsEnd() const { return type_ == NO_ARG; }
278 bool IsX() const { return type_ == X_ARG; }
279 bool IsD() const { return type_ == D_ARG; }
280
281 private:
282 enum CallArgumentType { X_ARG, D_ARG, NO_ARG };
283
284 // All arguments are aligned to at least 64 bits and we don't support
285 // passing bigger arguments, so the payload size can be fixed at 64 bits.
286 int64_t bits_;
287 CallArgumentType type_;
288
289 CallArgument() { type_ = NO_ARG; }
290 };
291
292
293 // Start the debugging command line.
294 void Debug();
295
296 bool GetValue(const char* desc, int64_t* value);
297
298 bool PrintValue(const char* desc);
299
300 // Push an address onto the JS stack.
301 uintptr_t PushAddress(uintptr_t address);
302
303 // Pop an address from the JS stack.
304 uintptr_t PopAddress();
305
306 // Accessor to the internal simulator stack area.
307 uintptr_t StackLimit() const;
308
309 void ResetState();
310
311 // Runtime call support.
312 static void* RedirectExternalReference(void* external_function,
313 ExternalReference::Type type);
314
315 // Run the simulator.
316 static const Instruction* kEndOfSimAddress;
317 void DecodeInstruction();
318 void Run();
319 void RunFrom(Instruction* start);
320
321 // Simulation helpers.
322 template <typename T>
323 void set_pc(T new_pc) {
324 ASSERT(sizeof(T) == sizeof(pc_));
325 memcpy(&pc_, &new_pc, sizeof(T));
326 pc_modified_ = true;
327 }
328 Instruction* pc() { return pc_; }
329
330 void increment_pc() {
331 if (!pc_modified_) {
332 pc_ = pc_->NextInstruction();
333 }
334
335 pc_modified_ = false;
336 }
337
338 virtual void Decode(Instruction* instr) {
339 decoder_->Decode(instr);
340 }
341
342 void ExecuteInstruction() {
343 ASSERT(IsAligned(reinterpret_cast<uintptr_t>(pc_), kInstructionSize));
344 CheckBreakNext();
345 Decode(pc_);
346 LogProcessorState();
347 increment_pc();
348 CheckBreakpoints();
349 }
350
351 // Declare all Visitor functions.
352 #define DECLARE(A) void Visit##A(Instruction* instr);
353 VISITOR_LIST(DECLARE)
354 #undef DECLARE
355
356 // Register accessors.
357
358 // Return 'size' bits of the value of an integer register, as the specified
359 // type. The value is zero-extended to fill the result.
360 //
361 // The only supported values of 'size' are kXRegSize and kWRegSize.
362 template<typename T>
363 T reg(unsigned size, unsigned code,
364 Reg31Mode r31mode = Reg31IsZeroRegister) const {
365 unsigned size_in_bytes = size / 8;
366 ASSERT(size_in_bytes <= sizeof(T));
367 ASSERT((size == kXRegSize) || (size == kWRegSize));
368 ASSERT(code < kNumberOfRegisters);
369
370 if ((code == 31) && (r31mode == Reg31IsZeroRegister)) {
371 T result;
372 memset(&result, 0, sizeof(result));
373 return result;
374 }
375 return registers_[code].Get<T>(size_in_bytes);
376 }
377
378 // Like reg(), but infer the access size from the template type.
379 template<typename T>
380 T reg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const {
381 return reg<T>(sizeof(T) * 8, code, r31mode);
382 }
383
384 // Common specialized accessors for the reg() template.
385 int32_t wreg(unsigned code,
386 Reg31Mode r31mode = Reg31IsZeroRegister) const {
387 return reg<int32_t>(code, r31mode);
388 }
389
390 int64_t xreg(unsigned code,
391 Reg31Mode r31mode = Reg31IsZeroRegister) const {
392 return reg<int64_t>(code, r31mode);
393 }
394
395 int64_t reg(unsigned size, unsigned code,
396 Reg31Mode r31mode = Reg31IsZeroRegister) const {
397 return reg<int64_t>(size, code, r31mode);
398 }
399
400 // Write 'size' bits of 'value' into an integer register. The value is
401 // zero-extended. This behaviour matches AArch64 register writes.
402 //
403 // The only supported values of 'size' are kXRegSize and kWRegSize.
404 template<typename T>
405 void set_reg(unsigned size, unsigned code, T value,
406 Reg31Mode r31mode = Reg31IsZeroRegister) {
407 unsigned size_in_bytes = size / 8;
408 ASSERT(size_in_bytes <= sizeof(T));
409 ASSERT((size == kXRegSize) || (size == kWRegSize));
410 ASSERT(code < kNumberOfRegisters);
411
412 if ((code == 31) && (r31mode == Reg31IsZeroRegister)) {
413 return;
414 }
415 return registers_[code].Set(value, size_in_bytes);
416 }
417
418 // Like set_reg(), but infer the access size from the template type.
419 template<typename T>
420 void set_reg(unsigned code, T value,
421 Reg31Mode r31mode = Reg31IsZeroRegister) {
422 set_reg(sizeof(value) * 8, code, value, r31mode);
423 }
424
425 // Common specialized accessors for the set_reg() template.
426 void set_wreg(unsigned code, int32_t value,
427 Reg31Mode r31mode = Reg31IsZeroRegister) {
428 set_reg(kWRegSize, code, value, r31mode);
429 }
430
431 void set_xreg(unsigned code, int64_t value,
432 Reg31Mode r31mode = Reg31IsZeroRegister) {
433 set_reg(kXRegSize, code, value, r31mode);
434 }
435
436 // Commonly-used special cases.
437 template<typename T>
438 void set_lr(T value) {
439 ASSERT(sizeof(T) == kPointerSize);
440 set_reg(kLinkRegCode, value);
441 }
442
443 template<typename T>
444 void set_sp(T value) {
445 ASSERT(sizeof(T) == kPointerSize);
446 set_reg(31, value, Reg31IsStackPointer);
447 }
448
449 int64_t sp() { return xreg(31, Reg31IsStackPointer); }
450 int64_t jssp() { return xreg(kJSSPCode, Reg31IsStackPointer); }
451 int64_t fp() {
452 return xreg(kFramePointerRegCode, Reg31IsStackPointer);
453 }
454 Instruction* lr() { return reg<Instruction*>(kLinkRegCode); }
455
456 Address get_sp() { return reg<Address>(31, Reg31IsStackPointer); }
457
458 // Return 'size' bits of the value of a floating-point register, as the
459 // specified type. The value is zero-extended to fill the result.
460 //
461 // The only supported values of 'size' are kDRegSize and kSRegSize.
462 template<typename T>
463 T fpreg(unsigned size, unsigned code) const {
464 unsigned size_in_bytes = size / 8;
465 ASSERT(size_in_bytes <= sizeof(T));
466 ASSERT((size == kDRegSize) || (size == kSRegSize));
467 ASSERT(code < kNumberOfFPRegisters);
468 return fpregisters_[code].Get<T>(size_in_bytes);
469 }
470
471 // Like fpreg(), but infer the access size from the template type.
472 template<typename T>
473 T fpreg(unsigned code) const {
474 return fpreg<T>(sizeof(T) * 8, code);
475 }
476
477 // Common specialized accessors for the fpreg() template.
478 float sreg(unsigned code) const {
479 return fpreg<float>(code);
480 }
481
482 uint32_t sreg_bits(unsigned code) const {
483 return fpreg<uint32_t>(code);
484 }
485
486 double dreg(unsigned code) const {
487 return fpreg<double>(code);
488 }
489
490 uint64_t dreg_bits(unsigned code) const {
491 return fpreg<uint64_t>(code);
492 }
493
494 double fpreg(unsigned size, unsigned code) const {
495 switch (size) {
496 case kSRegSize: return sreg(code);
497 case kDRegSize: return dreg(code);
498 default:
499 UNREACHABLE();
500 return 0.0;
501 }
502 }
503
504 // Write 'value' into a floating-point register. The value is zero-extended.
505 // This behaviour matches AArch64 register writes.
506 template<typename T>
507 void set_fpreg(unsigned code, T value) {
508 ASSERT((sizeof(value) == kDRegSizeInBytes) ||
509 (sizeof(value) == kSRegSizeInBytes));
510 ASSERT(code < kNumberOfFPRegisters);
511 fpregisters_[code].Set(value, sizeof(value));
512 }
513
514 // Common specialized accessors for the set_fpreg() template.
515 void set_sreg(unsigned code, float value) {
516 set_fpreg(code, value);
517 }
518
519 void set_sreg_bits(unsigned code, uint32_t value) {
520 set_fpreg(code, value);
521 }
522
523 void set_dreg(unsigned code, double value) {
524 set_fpreg(code, value);
525 }
526
527 void set_dreg_bits(unsigned code, uint64_t value) {
528 set_fpreg(code, value);
529 }
530
531 bool N() { return nzcv_.N() != 0; }
532 bool Z() { return nzcv_.Z() != 0; }
533 bool C() { return nzcv_.C() != 0; }
534 bool V() { return nzcv_.V() != 0; }
535 SimSystemRegister& nzcv() { return nzcv_; }
536
537 // TODO(jbramley): Find a way to make the fpcr_ members return the proper
538 // types, so this accessor is not necessary.
539 FPRounding RMode() { return static_cast<FPRounding>(fpcr_.RMode()); }
540 SimSystemRegister& fpcr() { return fpcr_; }
541
542 // Debug helpers
543
544 // Simulator breakpoints.
545 struct Breakpoint {
546 Instruction* location;
547 bool enabled;
548 };
549 std::vector<Breakpoint> breakpoints_;
550 void SetBreakpoint(Instruction* breakpoint);
551 void ListBreakpoints();
552 void CheckBreakpoints();
553
554 // Helpers for the 'next' command.
555 // When this is set, the Simulator will insert a breakpoint after the next BL
556 // instruction it meets.
557 bool break_on_next_;
558 // Check if the Simulator should insert a break after the current instruction
559 // for the 'next' command.
560 void CheckBreakNext();
561
562 // Disassemble instruction at the given address.
563 void PrintInstructionsAt(Instruction* pc, uint64_t count);
564
565 void PrintSystemRegisters(bool print_all = false);
566 void PrintRegisters(bool print_all_regs = false);
567 void PrintFPRegisters(bool print_all_regs = false);
568 void PrintProcessorState();
569 void PrintWrite(uint8_t* address, uint64_t value, unsigned num_bytes);
570 void LogSystemRegisters() {
571 if (log_parameters_ & LOG_SYS_REGS) PrintSystemRegisters();
572 }
573 void LogRegisters() {
574 if (log_parameters_ & LOG_REGS) PrintRegisters();
575 }
576 void LogFPRegisters() {
577 if (log_parameters_ & LOG_FP_REGS) PrintFPRegisters();
578 }
579 void LogProcessorState() {
580 LogSystemRegisters();
581 LogRegisters();
582 LogFPRegisters();
583 }
584 void LogWrite(uint8_t* address, uint64_t value, unsigned num_bytes) {
585 if (log_parameters_ & LOG_WRITE) PrintWrite(address, value, num_bytes);
586 }
587
588 int log_parameters() { return log_parameters_; }
589 void set_log_parameters(int new_parameters) {
590 log_parameters_ = new_parameters;
591 if (!decoder_) {
592 if (new_parameters & LOG_DISASM) {
593 PrintF("Run --debug-sim to dynamically turn on disassembler\n");
594 }
595 return;
596 }
597 if (new_parameters & LOG_DISASM) {
598 decoder_->InsertVisitorBefore(print_disasm_, this);
599 } else {
600 decoder_->RemoveVisitor(print_disasm_);
601 }
602 }
603
604 static inline const char* WRegNameForCode(unsigned code,
605 Reg31Mode mode = Reg31IsZeroRegister);
606 static inline const char* XRegNameForCode(unsigned code,
607 Reg31Mode mode = Reg31IsZeroRegister);
608 static inline const char* SRegNameForCode(unsigned code);
609 static inline const char* DRegNameForCode(unsigned code);
610 static inline const char* VRegNameForCode(unsigned code);
611 static inline int CodeFromName(const char* name);
612
613 protected:
614 // Simulation helpers ------------------------------------
615 bool ConditionPassed(Condition cond) {
616 switch (cond) {
617 case eq:
618 return Z();
619 case ne:
620 return !Z();
621 case hs:
622 return C();
623 case lo:
624 return !C();
625 case mi:
626 return N();
627 case pl:
628 return !N();
629 case vs:
630 return V();
631 case vc:
632 return !V();
633 case hi:
634 return C() && !Z();
635 case ls:
636 return !(C() && !Z());
637 case ge:
638 return N() == V();
639 case lt:
640 return N() != V();
641 case gt:
642 return !Z() && (N() == V());
643 case le:
644 return !(!Z() && (N() == V()));
645 case nv: // Fall through.
646 case al:
647 return true;
648 default:
649 UNREACHABLE();
650 return false;
651 }
652 }
653
654 bool ConditionFailed(Condition cond) {
655 return !ConditionPassed(cond);
656 }
657
658 void AddSubHelper(Instruction* instr, int64_t op2);
659 int64_t AddWithCarry(unsigned reg_size,
660 bool set_flags,
661 int64_t src1,
662 int64_t src2,
663 int64_t carry_in = 0);
664 void LogicalHelper(Instruction* instr, int64_t op2);
665 void ConditionalCompareHelper(Instruction* instr, int64_t op2);
666 void LoadStoreHelper(Instruction* instr,
667 int64_t offset,
668 AddrMode addrmode);
669 void LoadStorePairHelper(Instruction* instr, AddrMode addrmode);
670 uint8_t* LoadStoreAddress(unsigned addr_reg,
671 int64_t offset,
672 AddrMode addrmode);
673 void LoadStoreWriteBack(unsigned addr_reg,
674 int64_t offset,
675 AddrMode addrmode);
676 void CheckMemoryAccess(uint8_t* address, uint8_t* stack);
677
678 uint64_t MemoryRead(uint8_t* address, unsigned num_bytes);
679 uint8_t MemoryRead8(uint8_t* address);
680 uint16_t MemoryRead16(uint8_t* address);
681 uint32_t MemoryRead32(uint8_t* address);
682 float MemoryReadFP32(uint8_t* address);
683 uint64_t MemoryRead64(uint8_t* address);
684 double MemoryReadFP64(uint8_t* address);
685
686 void MemoryWrite(uint8_t* address, uint64_t value, unsigned num_bytes);
687 void MemoryWrite32(uint8_t* address, uint32_t value);
688 void MemoryWriteFP32(uint8_t* address, float value);
689 void MemoryWrite64(uint8_t* address, uint64_t value);
690 void MemoryWriteFP64(uint8_t* address, double value);
691
692 int64_t ShiftOperand(unsigned reg_size,
693 int64_t value,
694 Shift shift_type,
695 unsigned amount);
696 int64_t Rotate(unsigned reg_width,
697 int64_t value,
698 Shift shift_type,
699 unsigned amount);
700 int64_t ExtendValue(unsigned reg_width,
701 int64_t value,
702 Extend extend_type,
703 unsigned left_shift = 0);
704
705 uint64_t ReverseBits(uint64_t value, unsigned num_bits);
706 uint64_t ReverseBytes(uint64_t value, ReverseByteMode mode);
707
708 void FPCompare(double val0, double val1);
709 double FPRoundInt(double value, FPRounding round_mode);
710 double FPToDouble(float value);
711 float FPToFloat(double value, FPRounding round_mode);
712 double FixedToDouble(int64_t src, int fbits, FPRounding round_mode);
713 double UFixedToDouble(uint64_t src, int fbits, FPRounding round_mode);
714 float FixedToFloat(int64_t src, int fbits, FPRounding round_mode);
715 float UFixedToFloat(uint64_t src, int fbits, FPRounding round_mode);
716 int32_t FPToInt32(double value, FPRounding rmode);
717 int64_t FPToInt64(double value, FPRounding rmode);
718 uint32_t FPToUInt32(double value, FPRounding rmode);
719 uint64_t FPToUInt64(double value, FPRounding rmode);
720
721 template <typename T>
722 T FPMax(T a, T b);
723
724 template <typename T>
725 T FPMin(T a, T b);
726
727 template <typename T>
728 T FPMaxNM(T a, T b);
729
730 template <typename T>
731 T FPMinNM(T a, T b);
732
733 void CheckStackAlignment();
734
735 inline void CheckPCSComplianceAndRun();
736
737 #ifdef DEBUG
738 // Corruption values should have their least significant byte cleared to
739 // allow the code of the register being corrupted to be inserted.
740 static const uint64_t kCallerSavedRegisterCorruptionValue =
741 0xca11edc0de000000UL;
742 // This value is a NaN in both 32-bit and 64-bit FP.
743 static const uint64_t kCallerSavedFPRegisterCorruptionValue =
744 0x7ff000007f801000UL;
745 // This value is a mix of 32/64-bits NaN and "verbose" immediate.
746 static const uint64_t kDefaultCPURegisterCorruptionValue =
747 0x7ffbad007f8bad00UL;
748
749 void CorruptRegisters(CPURegList* list,
750 uint64_t value = kDefaultCPURegisterCorruptionValue);
751 void CorruptAllCallerSavedCPURegisters();
752 #endif
753
754 // Processor state ---------------------------------------
755
756 // Output stream.
757 FILE* stream_;
758 PrintDisassembler* print_disasm_;
759
760 // Instrumentation.
761 Instrument* instrument_;
762
763 // General purpose registers. Register 31 is the stack pointer.
764 SimRegister registers_[kNumberOfRegisters];
765
766 // Floating point registers
767 SimFPRegister fpregisters_[kNumberOfFPRegisters];
768
769 // Processor state
770 // bits[31, 27]: Condition flags N, Z, C, and V.
771 // (Negative, Zero, Carry, Overflow)
772 SimSystemRegister nzcv_;
773
774 // Floating-Point Control Register
775 SimSystemRegister fpcr_;
776
777 // Only a subset of FPCR features are supported by the simulator. This helper
778 // checks that the FPCR settings are supported.
779 //
780 // This is checked when floating-point instructions are executed, not when
781 // FPCR is set. This allows generated code to modify FPCR for external
782 // functions, or to save and restore it when entering and leaving generated
783 // code.
784 void AssertSupportedFPCR() {
785 ASSERT(fpcr().DN() == 0); // No default-NaN support.
786 ASSERT(fpcr().FZ() == 0); // No flush-to-zero support.
787 ASSERT(fpcr().RMode() == FPTieEven); // Ties-to-even rounding only.
788
789 // The simulator does not support half-precision operations so fpcr().AHP()
790 // is irrelevant, and is not checked here.
791 }
792
793 static int CalcNFlag(uint64_t result, unsigned reg_size) {
794 return (result >> (reg_size - 1)) & 1;
795 }
796
797 static int CalcZFlag(uint64_t result) {
798 return result == 0;
799 }
800
801 static const uint32_t kConditionFlagsMask = 0xf0000000;
802
803 // Stack
804 byte* stack_;
805 static const intptr_t stack_protection_size_ = KB;
806 intptr_t stack_size_;
807 byte* stack_limit_;
808 // TODO(aleram): protect the stack.
809
810 Decoder<DispatchingDecoderVisitor>* decoder_;
811 Decoder<DispatchingDecoderVisitor>* disassembler_decoder_;
812
813 // Indicates if the pc has been modified by the instruction and should not be
814 // automatically incremented.
815 bool pc_modified_;
816 Instruction* pc_;
817
818 static const char* xreg_names[];
819 static const char* wreg_names[];
820 static const char* sreg_names[];
821 static const char* dreg_names[];
822 static const char* vreg_names[];
823
824 // Debugger input.
825 void set_last_debugger_input(char* input) {
826 DeleteArray(last_debugger_input_);
827 last_debugger_input_ = input;
828 }
829 char* last_debugger_input() { return last_debugger_input_; }
830 char* last_debugger_input_;
831
832 private:
833 void Init(FILE* stream);
834
835 int log_parameters_;
836 Isolate* isolate_;
837 };
838
839
840 // When running with the simulator transition into simulated execution at this
841 // point.
842 #define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
843 reinterpret_cast<Object*>(Simulator::current(Isolate::Current())->CallJS( \
844 FUNCTION_ADDR(entry), \
845 p0, p1, p2, p3, p4))
846
847 #define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6, p7, p8) \
848 Simulator::current(Isolate::Current())->CallRegExp( \
849 entry, \
850 p0, p1, p2, p3, p4, p5, p6, p7, NULL, p8)
851
852 #define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
853 try_catch_address == NULL ? \
854 NULL : *(reinterpret_cast<TryCatch**>(try_catch_address))
855
856
857 // The simulator has its own stack. Thus it has a different stack limit from
858 // the C-based native code.
859 // See also 'class SimulatorStack' in arm/simulator-arm.h.
860 class SimulatorStack : public v8::internal::AllStatic {
861 public:
862 static uintptr_t JsLimitFromCLimit(v8::internal::Isolate* isolate,
863 uintptr_t c_limit) {
864 return Simulator::current(isolate)->StackLimit();
865 }
866
867 static uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
868 Simulator* sim = Simulator::current(Isolate::Current());
869 return sim->PushAddress(try_catch_address);
870 }
871
872 static void UnregisterCTryCatch() {
873 Simulator::current(Isolate::Current())->PopAddress();
874 }
875 };
876
877 #endif // !defined(USE_SIMULATOR)
878
879 } } // namespace v8::internal
880
881 #endif // V8_A64_SIMULATOR_A64_H_
OLDNEW
« no previous file with comments | « src/a64/regexp-macro-assembler-a64.cc ('k') | src/a64/simulator-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698