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

Side by Side Diff: runtime/vm/assembler_mips.cc

Issue 12634030: Adds branch instructions and labels to the MIPS simulator, assembler, disassembler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
OLDNEW
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, true, "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
26 void Assembler::Bind(Label* label) {
27 ASSERT(!label->IsBound());
28 int bound_pc = buffer_.Size();
29 while (label->IsLinked()) {
30 int32_t position = label->Position();
31 int32_t next = buffer_.Load<int32_t>(position);
32 int32_t encoded = Assembler::EncodeBranchOffset(bound_pc - position, next);
33 buffer_.Store<int32_t>(position, encoded);
34 label->position_ = Assembler::DecodeBranchOffset(next);
35 }
36 label->BindTo(bound_pc);
37 }
38
39
40 int32_t Assembler::EncodeBranchOffset(int32_t offset, int32_t inst) {
regis 2013/03/22 19:51:16 inst -> instr
zra 2013/03/22 20:16:01 Done.
41 ASSERT(Utils::IsAligned(offset, 4));
42 ASSERT(Utils::IsInt(16, offset));
regis 2013/03/22 19:51:16 Not 16, but 18.
zra 2013/03/22 20:16:01 Done.
43
44 // Properly preserve only the bits supported in the instruction.
45 offset >>= 2;
46 offset &= kBranchOffsetMask;
47 return (inst & ~kBranchOffsetMask) | offset;
48 }
49
50
51 int Assembler::DecodeBranchOffset(int32_t inst) {
regis 2013/03/22 19:51:16 Do you use this call while assembling instructions
zra 2013/03/22 20:16:01 It's used in Bind above. This also mirrors the ARM
52 // Sign-extend, left-shift by 2.
53 return (((inst & kBranchOffsetMask) << 16) >> 14);
54 }
55
25 } // namespace dart 56 } // namespace dart
26 57
27 #endif // defined TARGET_ARCH_MIPS 58 #endif // defined TARGET_ARCH_MIPS
28 59
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698