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 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 DEFINE_FLAG(bool, print_stop_message, true, "Print stop message."); | 12 DEFINE_FLAG(bool, print_stop_message, false, "Print stop message."); |
13 | 13 |
14 | 14 |
15 void Assembler::InitializeMemoryWithBreakpoints(uword data, int length) { | 15 void Assembler::InitializeMemoryWithBreakpoints(uword data, int length) { |
16 ASSERT(Utils::IsAligned(data, 4)); | 16 ASSERT(Utils::IsAligned(data, 4)); |
17 ASSERT(Utils::IsAligned(length, 4)); | 17 ASSERT(Utils::IsAligned(length, 4)); |
18 const uword end = data + length; | 18 const uword end = data + length; |
19 while (data < end) { | 19 while (data < end) { |
20 *reinterpret_cast<int32_t*>(data) = Instr::kBreakPointInstruction; | 20 *reinterpret_cast<int32_t*>(data) = Instr::kBreakPointInstruction; |
21 data += 4; | 21 data += 4; |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 void Assembler::Bind(Label* label) { | 26 void Assembler::Bind(Label* label) { |
27 ASSERT(!label->IsBound()); | 27 ASSERT(!label->IsBound()); |
28 int bound_pc = buffer_.Size(); | 28 int bound_pc = buffer_.Size(); |
29 while (label->IsLinked()) { | 29 while (label->IsLinked()) { |
30 int32_t position = label->Position(); | 30 const int32_t position = label->Position(); |
31 int32_t next = buffer_.Load<int32_t>(position); | 31 const int32_t next = buffer_.Load<int32_t>(position); |
32 // Reletive destination from an instruction after the branch. | 32 // Reletive destination from an instruction after the branch. |
regis
2013/03/26 17:52:35
Relative
| |
33 int32_t dest = bound_pc - (position + Instr::kInstrSize); | 33 const int32_t dest = bound_pc - (position + Instr::kInstrSize); |
34 int32_t encoded = Assembler::EncodeBranchOffset(dest, next); | 34 const int32_t encoded = Assembler::EncodeBranchOffset(dest, next); |
35 buffer_.Store<int32_t>(position, encoded); | 35 buffer_.Store<int32_t>(position, encoded); |
36 label->position_ = Assembler::DecodeBranchOffset(next); | 36 label->position_ = Assembler::DecodeBranchOffset(next); |
37 } | 37 } |
38 label->BindTo(bound_pc); | 38 label->BindTo(bound_pc); |
39 delay_slot_available_ = false; | 39 delay_slot_available_ = false; |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 int32_t Assembler::EncodeBranchOffset(int32_t offset, int32_t instr) { | 43 int32_t Assembler::EncodeBranchOffset(int32_t offset, int32_t instr) { |
44 ASSERT(Utils::IsAligned(offset, 4)); | 44 ASSERT(Utils::IsAligned(offset, 4)); |
45 ASSERT(Utils::IsInt(18, offset)); | 45 ASSERT(Utils::IsInt(18, offset)); |
46 | 46 |
47 // Properly preserve only the bits supported in the instruction. | 47 // Properly preserve only the bits supported in the instruction. |
48 offset >>= 2; | 48 offset >>= 2; |
49 offset &= kBranchOffsetMask; | 49 offset &= kBranchOffsetMask; |
50 return (instr & ~kBranchOffsetMask) | offset; | 50 return (instr & ~kBranchOffsetMask) | offset; |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 int Assembler::DecodeBranchOffset(int32_t instr) { | 54 int Assembler::DecodeBranchOffset(int32_t instr) { |
55 // Sign-extend, left-shift by 2. | 55 // Sign-extend, left-shift by 2. |
56 return (((instr & kBranchOffsetMask) << 16) >> 14); | 56 return (((instr & kBranchOffsetMask) << 16) >> 14); |
57 } | 57 } |
58 | 58 |
59 | |
60 void Assembler::LoadWordFromPoolOffset(Register rd, int32_t offset) { | |
61 ASSERT(rd != PP); | |
62 if (Address::CanHoldOffset(offset)) { | |
63 lw(rd, Address(PP, offset)); | |
64 } else { | |
65 const uint16_t offset_low = Utils::Low16Bits(offset); | |
66 const uint16_t offset_high = Utils::High16Bits(offset); | |
67 if (offset_high != 0) { | |
68 lui(rd, Immediate(offset_high)); | |
69 if (Address::CanHoldOffset(offset_low)) { | |
regis
2013/03/26 17:52:35
You need this test, because you chopped off 16 bit
| |
70 addu(rd, rd, PP); | |
71 lw(rd, Address(rd, offset_low)); | |
72 } else { | |
73 ori(rd, rd, Immediate(offset_low)); | |
74 addu(rd, rd, PP); | |
75 lw(rd, Address(rd)); | |
76 } | |
77 } else { | |
78 ori(rd, ZR, Immediate(offset_low)); | |
79 addu(rd, rd, PP); | |
80 lw(rd, Address(rd)); | |
81 } | |
82 } | |
83 } | |
84 | |
85 | |
86 int32_t Assembler::AddObject(const Object& obj) { | |
87 ASSERT(obj.IsNotTemporaryScopedHandle()); | |
88 ASSERT(obj.IsOld()); | |
89 if (object_pool_.IsNull()) { | |
90 // The object pool cannot be used in the vm isolate. | |
91 ASSERT(Isolate::Current() != Dart::vm_isolate()); | |
92 object_pool_ = GrowableObjectArray::New(Heap::kOld); | |
93 } | |
94 for (int i = 0; i < object_pool_.Length(); i++) { | |
95 if (object_pool_.At(i) == obj.raw()) { | |
96 return i; | |
97 } | |
98 } | |
99 object_pool_.Add(obj, Heap::kOld); | |
100 return object_pool_.Length() - 1; | |
101 } | |
102 | |
103 | |
104 int32_t Assembler::AddExternalLabel(const ExternalLabel* label) { | |
105 if (object_pool_.IsNull()) { | |
106 // The object pool cannot be used in the vm isolate. | |
107 ASSERT(Isolate::Current() != Dart::vm_isolate()); | |
108 object_pool_ = GrowableObjectArray::New(Heap::kOld); | |
109 } | |
110 const word address = label->address(); | |
111 ASSERT(Utils::IsAligned(address, 4)); | |
112 // The address is stored in the object array as a RawSmi. | |
113 const Smi& smi = Smi::Handle(Smi::New(address >> kSmiTagShift)); | |
114 // Do not reuse an existing entry, since each reference may be patched | |
115 // independently. | |
116 object_pool_.Add(smi, Heap::kOld); | |
117 return object_pool_.Length() - 1; | |
118 } | |
119 | |
120 | |
121 void Assembler::Stop(const char* message) { | |
122 if (FLAG_print_stop_message) { | |
123 UNIMPLEMENTED(); | |
124 } | |
125 Label stop; | |
126 b(&stop); | |
127 Emit(reinterpret_cast<int32_t>(message)); | |
128 Bind(&stop); | |
129 break_(Instr::kStopMessageCode); | |
130 } | |
131 | |
59 } // namespace dart | 132 } // namespace dart |
60 | 133 |
61 #endif // defined TARGET_ARCH_MIPS | 134 #endif // defined TARGET_ARCH_MIPS |
62 | 135 |
OLD | NEW |