| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| 11 #include "vm/dart_entry.h" |
| 11 #include "vm/instructions.h" | 12 #include "vm/instructions.h" |
| 12 #include "vm/object.h" | 13 #include "vm/object.h" |
| 13 #include "vm/raw_object.h" | 14 #include "vm/raw_object.h" |
| 14 | 15 |
| 15 namespace dart { | 16 namespace dart { |
| 16 | 17 |
| 17 // The pattern of a Dart instance call is: | 18 // The pattern of a Dart instance call is: |
| 18 // 00: 48 bb imm64 mov RBX, immediate 1 | 19 // 00: 48 bb imm64 mov RBX, immediate 1 |
| 19 // 10: 49 ba imm64 mov R10, immediate 2 | 20 // 10: 49 ba imm64 mov R10, immediate 2 |
| 20 // 20: 49 bb imm64 mov R11, target_address | 21 // 20: 49 bb imm64 mov R11, target_address |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 uword target() const { | 44 uword target() const { |
| 44 return *reinterpret_cast<uword*>(start_ + 20 + 2); | 45 return *reinterpret_cast<uword*>(start_ + 20 + 2); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void set_target(uword target) const { | 48 void set_target(uword target) const { |
| 48 uword* target_addr = reinterpret_cast<uword*>(start_ + 20 + 2); | 49 uword* target_addr = reinterpret_cast<uword*>(start_ + 20 + 2); |
| 49 *target_addr = target; | 50 *target_addr = target; |
| 50 CPU::FlushICache(start_ + 20, 2 + 8); | 51 CPU::FlushICache(start_ + 20, 2 + 8); |
| 51 } | 52 } |
| 52 | 53 |
| 53 uint64_t immediate_one() const { | 54 RawObject* immediate_one() const { |
| 54 return *reinterpret_cast<uint64_t*>(start_ + 0 + 2); | 55 return *reinterpret_cast<RawObject**>(start_ + 0 + 2); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void set_immediate_one(uint64_t value) { | 58 void set_immediate_one(uint64_t value) { |
| 58 uint64_t* target_addr = reinterpret_cast<uint64_t*>(start_ + 0 + 2); | 59 uint64_t* target_addr = reinterpret_cast<uint64_t*>(start_ + 0 + 2); |
| 59 *target_addr = value; | 60 *target_addr = value; |
| 60 CPU::FlushICache(start_ + 0, 2 + 8); | 61 CPU::FlushICache(start_ + 0, 2 + 8); |
| 61 } | 62 } |
| 62 | 63 |
| 63 uint64_t immediate_two() const { | 64 RawObject* immediate_two() const { |
| 64 return *reinterpret_cast<uint64_t*>(start_ + 10 + 2); | 65 return *reinterpret_cast<RawObject**>(start_ + 10 + 2); |
| 65 } | 66 } |
| 66 | 67 |
| 67 int argument_count() const { | 68 intptr_t argument_count() const { |
| 68 Array& args_desc = Array::Handle(); | 69 ArgumentsDescriptor args_desc(immediate_two()); |
| 69 args_desc ^= reinterpret_cast<RawObject*>(immediate_two()); | 70 return args_desc.Count(); |
| 70 Smi& num_args = Smi::Handle(); | |
| 71 num_args ^= args_desc.At(0); | |
| 72 return num_args.Value(); | |
| 73 } | 71 } |
| 74 | 72 |
| 75 int named_argument_count() const { | 73 intptr_t named_argument_count() const { |
| 76 Array& args_desc = Array::Handle(); | 74 ArgumentsDescriptor args_desc(immediate_two()); |
| 77 args_desc ^= reinterpret_cast<RawObject*>(immediate_two()); | 75 return args_desc.NamedCount(); |
| 78 Smi& num_args = Smi::Handle(); | |
| 79 num_args ^= args_desc.At(0); | |
| 80 Smi& num_pos_args = Smi::Handle(); | |
| 81 num_pos_args ^= args_desc.At(1); | |
| 82 return num_args.Value() - num_pos_args.Value(); | |
| 83 } | 76 } |
| 84 | 77 |
| 85 uword start_; | 78 uword start_; |
| 86 DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallPattern); | 79 DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallPattern); |
| 87 }; | 80 }; |
| 88 | 81 |
| 89 | 82 |
| 90 // A Dart instance call passes the ic-data in RBX. | 83 // A Dart instance call passes the ic-data in RBX. |
| 91 // The expected pattern of a dart instance call: | 84 // The expected pattern of a dart instance call: |
| 92 // mov RBX, ic-data | 85 // mov RBX, ic-data |
| 93 // mov R10, argument_descriptor_array | 86 // mov R10, arguments_descriptor_array |
| 94 // mov R11, target_address | 87 // mov R11, target_address |
| 95 // call R11 | 88 // call R11 |
| 96 // <- return address | 89 // <- return address |
| 97 class InstanceCall : public DartCallPattern { | 90 class InstanceCall : public DartCallPattern { |
| 98 public: | 91 public: |
| 99 explicit InstanceCall(uword return_address) | 92 explicit InstanceCall(uword return_address) |
| 100 : DartCallPattern(return_address) {} | 93 : DartCallPattern(return_address) {} |
| 101 | 94 |
| 102 RawICData* ic_data() const { | 95 RawICData* ic_data() const { |
| 103 ICData& ic_data = ICData::Handle(); | 96 ICData& ic_data = ICData::Handle(); |
| 104 ic_data ^= reinterpret_cast<RawObject*>(immediate_one()); | 97 ic_data ^= immediate_one(); |
| 105 return ic_data.raw(); | 98 return ic_data.raw(); |
| 106 } | 99 } |
| 107 | 100 |
| 108 private: | 101 private: |
| 109 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); | 102 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); |
| 110 }; | 103 }; |
| 111 | 104 |
| 112 | 105 |
| 113 // The expected pattern of a dart static call: | 106 // The expected pattern of a dart static call: |
| 114 // mov R10, argument_descriptor_array (10 bytes) | 107 // mov R10, arguments_descriptor_array (10 bytes) |
| 115 // mov R11, target_address (10 bytes) | 108 // mov R11, target_address (10 bytes) |
| 116 // call R11 (3 bytes) | 109 // call R11 (3 bytes) |
| 117 // <- return address | 110 // <- return address |
| 118 class StaticCall : public ValueObject { | 111 class StaticCall : public ValueObject { |
| 119 public: | 112 public: |
| 120 explicit StaticCall(uword return_address) | 113 explicit StaticCall(uword return_address) |
| 121 : start_(return_address - kCallPatternSize) { | 114 : start_(return_address - kCallPatternSize) { |
| 122 ASSERT(IsValid(return_address)); | 115 ASSERT(IsValid(return_address)); |
| 123 ASSERT((kCallPatternSize - 10) == Assembler::kCallExternalLabelSize); | 116 ASSERT((kCallPatternSize - 10) == Assembler::kCallExternalLabelSize); |
| 124 } | 117 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 *reinterpret_cast<uint8_t*>(start) = 0xE8; | 264 *reinterpret_cast<uint8_t*>(start) = 0xE8; |
| 272 ShortCallPattern call(start); | 265 ShortCallPattern call(start); |
| 273 call.SetTargetAddress(target); | 266 call.SetTargetAddress(target); |
| 274 CPU::FlushICache(start, ShortCallPattern::InstructionLength()); | 267 CPU::FlushICache(start, ShortCallPattern::InstructionLength()); |
| 275 } | 268 } |
| 276 | 269 |
| 277 | 270 |
| 278 } // namespace dart | 271 } // namespace dart |
| 279 | 272 |
| 280 #endif // defined TARGET_ARCH_X64 | 273 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |