OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Declares a Simulator for MIPS instructions if we are not generating a native | 5 // Declares a Simulator for MIPS instructions if we are not generating a native |
6 // MIPS binary. This Simulator allows us to run and debug MIPS code generation | 6 // MIPS binary. This Simulator allows us to run and debug MIPS code generation |
7 // on regular desktop machines. | 7 // on regular desktop machines. |
8 // Dart calls into generated code by "calling" the InvokeDartCode stub, | 8 // Dart calls into generated code by "calling" the InvokeDartCode stub, |
9 // which will start execution in the Simulator or forwards to the real entry | 9 // which will start execution in the Simulator or forwards to the real entry |
10 // on a MIPS HW platform. | 10 // on a MIPS HW platform. |
11 | 11 |
12 #ifndef VM_SIMULATOR_MIPS_H_ | 12 #ifndef VM_SIMULATOR_MIPS_H_ |
13 #define VM_SIMULATOR_MIPS_H_ | 13 #define VM_SIMULATOR_MIPS_H_ |
14 | 14 |
15 #ifndef VM_SIMULATOR_H_ | 15 #ifndef VM_SIMULATOR_H_ |
16 #error Do not include simulator_mips.h directly; use simulator.h. | 16 #error Do not include simulator_mips.h directly; use simulator.h. |
17 #endif | 17 #endif |
18 | 18 |
19 #include "vm/constants_mips.h" | 19 #include "vm/constants_mips.h" |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
| 23 class Isolate; |
| 24 class SimulatorSetjmpBuffer; |
| 25 |
23 class Simulator { | 26 class Simulator { |
24 public: | 27 public: |
25 static const uword kSimulatorStackUnderflowSize = 64; | 28 static const uword kSimulatorStackUnderflowSize = 64; |
26 | 29 |
27 Simulator(); | 30 Simulator(); |
28 ~Simulator(); | 31 ~Simulator(); |
29 | 32 |
30 // The currently executing Simulator instance, which is associated to the | 33 // The currently executing Simulator instance, which is associated to the |
31 // current isolate | 34 // current isolate |
32 static Simulator* Current(); | 35 static Simulator* Current(); |
(...skipping 24 matching lines...) Expand all Loading... |
57 | 60 |
58 // Dart generally calls into generated code with 5 parameters. This is a | 61 // Dart generally calls into generated code with 5 parameters. This is a |
59 // convenience function, which sets up the simulator state and grabs the | 62 // convenience function, which sets up the simulator state and grabs the |
60 // result on return. | 63 // result on return. |
61 int64_t Call(int32_t entry, | 64 int64_t Call(int32_t entry, |
62 int32_t parameter0, | 65 int32_t parameter0, |
63 int32_t parameter1, | 66 int32_t parameter1, |
64 int32_t parameter2, | 67 int32_t parameter2, |
65 int32_t parameter3); | 68 int32_t parameter3); |
66 | 69 |
| 70 // Runtime and native call support. |
| 71 enum CallKind { |
| 72 kRuntimeCall, |
| 73 kLeafRuntimeCall, |
| 74 kNativeCall |
| 75 }; |
| 76 static uword RedirectExternalReference(uword function, CallKind call_kind); |
| 77 |
67 private: | 78 private: |
68 // A pc value used to signal the simulator to stop execution. Generally | 79 // A pc value used to signal the simulator to stop execution. Generally |
69 // the ra is set to this value on transition from native C code to | 80 // the ra is set to this value on transition from native C code to |
70 // simulated execution, so that the simulator can "return" to the native | 81 // simulated execution, so that the simulator can "return" to the native |
71 // C code. | 82 // C code. |
72 static const uword kEndSimulatingPC = -1; | 83 static const uword kEndSimulatingPC = -1; |
73 | 84 |
74 // Special registers for the results of div, divu. | 85 // Special registers for the results of div, divu. |
75 int32_t hi_reg_; | 86 int32_t hi_reg_; |
76 int32_t lo_reg_; | 87 int32_t lo_reg_; |
77 | 88 |
78 int32_t registers_[kNumberOfCpuRegisters]; | 89 int32_t registers_[kNumberOfCpuRegisters]; |
79 double fregisters_[kNumberOfFRegisters]; | 90 double fregisters_[kNumberOfFRegisters]; |
80 uword pc_; | 91 uword pc_; |
81 | 92 |
82 // Simulator support. | 93 // Simulator support. |
83 char* stack_; | 94 char* stack_; |
84 int icount_; | 95 int icount_; |
85 bool delay_slot_; | 96 bool delay_slot_; |
| 97 SimulatorSetjmpBuffer* last_setjmp_buffer_; |
86 | 98 |
87 // Registered breakpoints. | 99 // Registered breakpoints. |
88 Instr* break_pc_; | 100 Instr* break_pc_; |
89 int32_t break_instr_; | 101 int32_t break_instr_; |
90 | 102 |
91 // Illegal memory access support. | 103 // Illegal memory access support. |
92 static bool IsIllegalAddress(uword addr) { | 104 static bool IsIllegalAddress(uword addr) { |
93 return addr < 64*1024; | 105 return addr < 64*1024; |
94 } | 106 } |
95 void HandleIllegalAccess(uword addr, Instr* instr); | 107 void HandleIllegalAccess(uword addr, Instr* instr); |
(...skipping 17 matching lines...) Expand all Loading... |
113 inline uint8_t ReadBU(uword addr); | 125 inline uint8_t ReadBU(uword addr); |
114 inline int16_t ReadH(uword addr, Instr* instr); | 126 inline int16_t ReadH(uword addr, Instr* instr); |
115 inline uint16_t ReadHU(uword addr, Instr *instr); | 127 inline uint16_t ReadHU(uword addr, Instr *instr); |
116 inline int ReadW(uword addr, Instr* instr); | 128 inline int ReadW(uword addr, Instr* instr); |
117 | 129 |
118 inline void WriteB(uword addr, uint8_t value); | 130 inline void WriteB(uword addr, uint8_t value); |
119 inline void WriteH(uword addr, uint16_t value, Instr* isntr); | 131 inline void WriteH(uword addr, uint16_t value, Instr* isntr); |
120 inline void WriteW(uword addr, int value, Instr* instr); | 132 inline void WriteW(uword addr, int value, Instr* instr); |
121 | 133 |
122 void DoBranch(Instr* instr, bool taken, bool likely); | 134 void DoBranch(Instr* instr, bool taken, bool likely); |
| 135 void DoBreak(Instr *instr); |
| 136 |
123 void DecodeSpecial(Instr* instr); | 137 void DecodeSpecial(Instr* instr); |
124 void DecodeSpecial2(Instr* instr); | 138 void DecodeSpecial2(Instr* instr); |
125 void DecodeRegImm(Instr* instr); | 139 void DecodeRegImm(Instr* instr); |
126 void InstructionDecode(Instr* instr); | 140 void InstructionDecode(Instr* instr); |
127 | 141 |
128 void Execute(); | 142 void Execute(); |
129 void ExecuteDelaySlot(); | 143 void ExecuteDelaySlot(); |
130 | 144 |
| 145 // Longjmp support for exceptions. |
| 146 SimulatorSetjmpBuffer* last_setjmp_buffer() { |
| 147 return last_setjmp_buffer_; |
| 148 } |
| 149 void set_last_setjmp_buffer(SimulatorSetjmpBuffer* buffer) { |
| 150 last_setjmp_buffer_ = buffer; |
| 151 } |
| 152 |
131 friend class SimulatorDebugger; | 153 friend class SimulatorDebugger; |
| 154 friend class SimulatorSetjmpBuffer; |
132 }; | 155 }; |
133 | 156 |
134 } // namespace dart | 157 } // namespace dart |
135 | 158 |
136 #endif // VM_SIMULATOR_MIPS_H_ | 159 #endif // VM_SIMULATOR_MIPS_H_ |
OLD | NEW |