OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 ARM64 instructions if we are not generating a native | 5 // Declares a Simulator for ARM64 instructions if we are not generating a native |
6 // ARM64 binary. This Simulator allows us to run and debug ARM64 code generation | 6 // ARM64 binary. This Simulator allows us to run and debug ARM64 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 ARM64 HW platform. | 10 // on a ARM64 HW platform. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // The currently executing Simulator instance, which is associated to the | 43 // The currently executing Simulator instance, which is associated to the |
44 // current isolate | 44 // current isolate |
45 static Simulator* Current(); | 45 static Simulator* Current(); |
46 | 46 |
47 // Accessors for register state. | 47 // Accessors for register state. |
48 // The default value for R31Type has to be R31IsSP because get_register is | 48 // The default value for R31Type has to be R31IsSP because get_register is |
49 // accessed from architecture independent code through SPREG without | 49 // accessed from architecture independent code through SPREG without |
50 // specifying the type. We also can't translate a dummy value for SPREG into | 50 // specifying the type. We also can't translate a dummy value for SPREG into |
51 // a real value because the architecture independent code expects SPREG to | 51 // a real value because the architecture independent code expects SPREG to |
52 // be a real register value. | 52 // be a real register value. |
53 void set_register( | 53 void set_register(Instr* instr, |
54 Instr* instr, Register reg, int64_t value, R31Type r31t = R31IsSP); | 54 Register reg, |
| 55 int64_t value, |
| 56 R31Type r31t = R31IsSP); |
55 int64_t get_register(Register reg, R31Type r31t = R31IsSP) const; | 57 int64_t get_register(Register reg, R31Type r31t = R31IsSP) const; |
56 void set_wregister(Register reg, int32_t value, R31Type r31t = R31IsSP); | 58 void set_wregister(Register reg, int32_t value, R31Type r31t = R31IsSP); |
57 int32_t get_wregister(Register reg, R31Type r31t = R31IsSP) const; | 59 int32_t get_wregister(Register reg, R31Type r31t = R31IsSP) const; |
58 | 60 |
59 int32_t get_vregisters(VRegister reg, int idx) const; | 61 int32_t get_vregisters(VRegister reg, int idx) const; |
60 void set_vregisters(VRegister reg, int idx, int32_t value); | 62 void set_vregisters(VRegister reg, int idx, int32_t value); |
61 | 63 |
62 int64_t get_vregisterd(VRegister reg, int idx) const; | 64 int64_t get_vregisterd(VRegister reg, int idx) const; |
63 void set_vregisterd(VRegister reg, int idx, int64_t value); | 65 void set_vregisterd(VRegister reg, int idx, int64_t value); |
64 | 66 |
65 void get_vregister(VRegister reg, simd_value_t* value) const; | 67 void get_vregister(VRegister reg, simd_value_t* value) const; |
66 void set_vregister(VRegister reg, const simd_value_t& value); | 68 void set_vregister(VRegister reg, const simd_value_t& value); |
67 | 69 |
68 int64_t get_sp() const { | 70 int64_t get_sp() const { return get_register(SPREG); } |
69 return get_register(SPREG); | |
70 } | |
71 | 71 |
72 int64_t get_pc() const; | 72 int64_t get_pc() const; |
73 int64_t get_last_pc() const; | 73 int64_t get_last_pc() const; |
74 void set_pc(int64_t pc); | 74 void set_pc(int64_t pc); |
75 | 75 |
76 // Accessors to the internal simulator stack base and top. | 76 // Accessors to the internal simulator stack base and top. |
77 uword StackBase() const { return reinterpret_cast<uword>(stack_); } | 77 uword StackBase() const { return reinterpret_cast<uword>(stack_); } |
78 uword StackTop() const; | 78 uword StackTop() const; |
79 | 79 |
80 // Accessor to the instruction counter. | 80 // Accessor to the instruction counter. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 uint64_t icount_; | 158 uint64_t icount_; |
159 static int64_t flag_stop_sim_at_; | 159 static int64_t flag_stop_sim_at_; |
160 SimulatorSetjmpBuffer* last_setjmp_buffer_; | 160 SimulatorSetjmpBuffer* last_setjmp_buffer_; |
161 uword top_exit_frame_info_; | 161 uword top_exit_frame_info_; |
162 | 162 |
163 // Registered breakpoints. | 163 // Registered breakpoints. |
164 Instr* break_pc_; | 164 Instr* break_pc_; |
165 int64_t break_instr_; | 165 int64_t break_instr_; |
166 | 166 |
167 // Illegal memory access support. | 167 // Illegal memory access support. |
168 static bool IsIllegalAddress(uword addr) { | 168 static bool IsIllegalAddress(uword addr) { return addr < 64 * 1024; } |
169 return addr < 64*1024; | |
170 } | |
171 void HandleIllegalAccess(uword addr, Instr* instr); | 169 void HandleIllegalAccess(uword addr, Instr* instr); |
172 | 170 |
173 // Handles an unaligned memory access. | 171 // Handles an unaligned memory access. |
174 void UnalignedAccess(const char* msg, uword addr, Instr* instr); | 172 void UnalignedAccess(const char* msg, uword addr, Instr* instr); |
175 | 173 |
176 // Handles a legal instruction that the simulator does not implement. | 174 // Handles a legal instruction that the simulator does not implement. |
177 void UnimplementedInstruction(Instr* instr); | 175 void UnimplementedInstruction(Instr* instr); |
178 | 176 |
179 // Unsupported instructions use Format to print an error and stop execution. | 177 // Unsupported instructions use Format to print an error and stop execution. |
180 void Format(Instr* instr, const char* format); | 178 void Format(Instr* instr, const char* format); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // thread (CLREX). | 223 // thread (CLREX). |
226 static bool HasExclusiveAccessAndOpen(uword addr); | 224 static bool HasExclusiveAccessAndOpen(uword addr); |
227 | 225 |
228 // Helper functions to set the conditional flags in the architecture state. | 226 // Helper functions to set the conditional flags in the architecture state. |
229 void SetNZFlagsW(int32_t val); | 227 void SetNZFlagsW(int32_t val); |
230 bool CarryFromW(int32_t left, int32_t right, int32_t carry); | 228 bool CarryFromW(int32_t left, int32_t right, int32_t carry); |
231 bool OverflowFromW(int32_t left, int32_t right, int32_t carry); | 229 bool OverflowFromW(int32_t left, int32_t right, int32_t carry); |
232 | 230 |
233 void SetNZFlagsX(int64_t val); | 231 void SetNZFlagsX(int64_t val); |
234 bool CarryFromX(int64_t alu_out, int64_t left, int64_t right, bool addition); | 232 bool CarryFromX(int64_t alu_out, int64_t left, int64_t right, bool addition); |
235 bool OverflowFromX( | 233 bool OverflowFromX(int64_t alu_out, |
236 int64_t alu_out, int64_t left, int64_t right, bool addition); | 234 int64_t left, |
| 235 int64_t right, |
| 236 bool addition); |
237 | 237 |
238 void SetCFlag(bool val); | 238 void SetCFlag(bool val); |
239 void SetVFlag(bool val); | 239 void SetVFlag(bool val); |
240 | 240 |
241 int64_t ShiftOperand(uint8_t reg_size, | 241 int64_t ShiftOperand(uint8_t reg_size, |
242 int64_t value, | 242 int64_t value, |
243 Shift shift_type, | 243 Shift shift_type, |
244 uint8_t amount); | 244 uint8_t amount); |
245 | 245 |
246 int64_t ExtendOperand(uint8_t reg_size, | 246 int64_t ExtendOperand(uint8_t reg_size, |
247 int64_t value, | 247 int64_t value, |
248 Extend extend_type, | 248 Extend extend_type, |
249 uint8_t amount); | 249 uint8_t amount); |
250 | 250 |
251 int64_t DecodeShiftExtendOperand(Instr* instr); | 251 int64_t DecodeShiftExtendOperand(Instr* instr); |
252 | 252 |
253 bool ConditionallyExecute(Instr* instr); | 253 bool ConditionallyExecute(Instr* instr); |
254 | 254 |
255 void DoRedirectedCall(Instr* instr); | 255 void DoRedirectedCall(Instr* instr); |
256 | 256 |
257 // Decode instructions. | 257 // Decode instructions. |
258 void InstructionDecode(Instr* instr); | 258 void InstructionDecode(Instr* instr); |
259 #define DECODE_OP(op) \ | 259 #define DECODE_OP(op) void Decode##op(Instr* instr); |
260 void Decode##op(Instr* instr); | |
261 APPLY_OP_LIST(DECODE_OP) | 260 APPLY_OP_LIST(DECODE_OP) |
262 #undef DECODE_OP | 261 #undef DECODE_OP |
263 | 262 |
264 // Executes ARM64 instructions until the PC reaches kEndSimulatingPC. | 263 // Executes ARM64 instructions until the PC reaches kEndSimulatingPC. |
265 void Execute(); | 264 void Execute(); |
266 | 265 |
267 // Returns true if tracing of executed instructions is enabled. | 266 // Returns true if tracing of executed instructions is enabled. |
268 bool IsTracingExecution() const; | 267 bool IsTracingExecution() const; |
269 | 268 |
270 // Longjmp support for exceptions. | 269 // Longjmp support for exceptions. |
271 SimulatorSetjmpBuffer* last_setjmp_buffer() { | 270 SimulatorSetjmpBuffer* last_setjmp_buffer() { return last_setjmp_buffer_; } |
272 return last_setjmp_buffer_; | |
273 } | |
274 void set_last_setjmp_buffer(SimulatorSetjmpBuffer* buffer) { | 271 void set_last_setjmp_buffer(SimulatorSetjmpBuffer* buffer) { |
275 last_setjmp_buffer_ = buffer; | 272 last_setjmp_buffer_ = buffer; |
276 } | 273 } |
277 | 274 |
278 friend class SimulatorDebugger; | 275 friend class SimulatorDebugger; |
279 friend class SimulatorSetjmpBuffer; | 276 friend class SimulatorSetjmpBuffer; |
280 DISALLOW_COPY_AND_ASSIGN(Simulator); | 277 DISALLOW_COPY_AND_ASSIGN(Simulator); |
281 }; | 278 }; |
282 | 279 |
283 } // namespace dart | 280 } // namespace dart |
284 | 281 |
285 #endif // RUNTIME_VM_SIMULATOR_ARM64_H_ | 282 #endif // RUNTIME_VM_SIMULATOR_ARM64_H_ |
OLD | NEW |