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

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

Issue 8888020: Teach the assembler how to generate multi-byte nops. Teach the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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
« no previous file with comments | « runtime/vm/assembler_ia32.h ('k') | runtime/vm/assembler_ia32_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/heap.h" 9 #include "vm/heap.h"
10 #include "vm/memory_region.h" 10 #include "vm/memory_region.h"
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1089
1090 void Assembler::ret(const Immediate& imm) { 1090 void Assembler::ret(const Immediate& imm) {
1091 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1091 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1092 EmitUint8(0xC2); 1092 EmitUint8(0xC2);
1093 ASSERT(imm.is_uint16()); 1093 ASSERT(imm.is_uint16());
1094 EmitUint8(imm.value() & 0xFF); 1094 EmitUint8(imm.value() & 0xFF);
1095 EmitUint8((imm.value() >> 8) & 0xFF); 1095 EmitUint8((imm.value() >> 8) & 0xFF);
1096 } 1096 }
1097 1097
1098 1098
1099 1099 void Assembler::nop(int size) {
1100 void Assembler::nop() {
1101 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1100 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1102 EmitUint8(0x90); 1101 // There are nops up to size 15, but for now just provide up to size 8.
1102 ASSERT(0 < size && size <= MAX_NOP_SIZE);
srdjan 2011/12/08 22:18:12 I would document this limitation in header file.
turnidge 2011/12/08 23:04:57 Done.
1103 switch (size) {
1104 case 1:
1105 EmitUint8(0x90);
1106 break;
1107 case 2:
1108 EmitUint8(0x66);
1109 EmitUint8(0x90);
1110 break;
1111 case 3:
1112 EmitUint8(0x0F);
1113 EmitUint8(0x1F);
1114 EmitUint8(0x00);
1115 break;
1116 case 4:
1117 EmitUint8(0x0F);
1118 EmitUint8(0x1F);
1119 EmitUint8(0x40);
1120 EmitUint8(0x00);
1121 break;
1122 case 5:
1123 EmitUint8(0x0F);
1124 EmitUint8(0x1F);
1125 EmitUint8(0x44);
1126 EmitUint8(0x00);
1127 EmitUint8(0x00);
1128 break;
1129 case 6:
1130 EmitUint8(0x66);
1131 EmitUint8(0x0F);
1132 EmitUint8(0x1F);
1133 EmitUint8(0x44);
1134 EmitUint8(0x00);
1135 EmitUint8(0x00);
1136 break;
1137 case 7:
1138 EmitUint8(0x0F);
1139 EmitUint8(0x1F);
1140 EmitUint8(0x80);
1141 EmitUint8(0x00);
1142 EmitUint8(0x00);
1143 EmitUint8(0x00);
1144 EmitUint8(0x00);
1145 break;
1146 case 8:
1147 EmitUint8(0x0F);
1148 EmitUint8(0x1F);
1149 EmitUint8(0x84);
1150 EmitUint8(0x00);
1151 EmitUint8(0x00);
1152 EmitUint8(0x00);
1153 EmitUint8(0x00);
1154 EmitUint8(0x00);
1155 break;
1156 default:
1157 UNIMPLEMENTED();
1158 }
1103 } 1159 }
1104 1160
1105 1161
1106 void Assembler::int3() { 1162 void Assembler::int3() {
1107 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1163 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1108 EmitUint8(0xCC); 1164 EmitUint8(0xCC);
1109 } 1165 }
1110 1166
1111 1167
1112 void Assembler::hlt() { 1168 void Assembler::hlt() {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 } 1382 }
1327 1383
1328 1384
1329 void Assembler::CallRuntimeFromStub(const RuntimeEntry& entry) { 1385 void Assembler::CallRuntimeFromStub(const RuntimeEntry& entry) {
1330 entry.CallFromStub(this); 1386 entry.CallFromStub(this);
1331 } 1387 }
1332 1388
1333 1389
1334 void Assembler::Align(int alignment, int offset) { 1390 void Assembler::Align(int alignment, int offset) {
1335 ASSERT(Utils::IsPowerOfTwo(alignment)); 1391 ASSERT(Utils::IsPowerOfTwo(alignment));
1336 // Emit nop instruction until the real position is aligned. 1392 int pos = offset + buffer_.GetPosition();
1337 while (((offset + buffer_.GetPosition()) & (alignment-1)) != 0) { 1393 int mod = pos & (alignment - 1);
1338 nop(); 1394 if (mod == 0) {
1395 return;
1339 } 1396 }
1397 int bytes_needed = alignment - mod;
1398 while (bytes_needed > MAX_NOP_SIZE) {
1399 nop(MAX_NOP_SIZE);
1400 bytes_needed -= MAX_NOP_SIZE;
1401 }
1402 if (bytes_needed) {
1403 nop(bytes_needed);
1404 }
1405 ASSERT(((offset + buffer_.GetPosition()) & (alignment-1)) == 0);
1340 } 1406 }
1341 1407
1342 1408
1343 void Assembler::Bind(Label* label) { 1409 void Assembler::Bind(Label* label) {
1344 int bound = buffer_.Size(); 1410 int bound = buffer_.Size();
1345 ASSERT(!label->IsBound()); // Labels can only be bound once. 1411 ASSERT(!label->IsBound()); // Labels can only be bound once.
1346 while (label->IsLinked()) { 1412 while (label->IsLinked()) {
1347 int position = label->LinkPosition(); 1413 int position = label->LinkPosition();
1348 int next = buffer_.Load<int32_t>(position); 1414 int next = buffer_.Load<int32_t>(position);
1349 buffer_.Store<int32_t>(position, bound - (position + 4)); 1415 buffer_.Store<int32_t>(position, bound - (position + 4));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 Register shifter) { 1522 Register shifter) {
1457 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 1523 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1458 ASSERT(shifter == ECX); 1524 ASSERT(shifter == ECX);
1459 EmitUint8(0xD3); 1525 EmitUint8(0xD3);
1460 EmitOperand(rm, Operand(operand)); 1526 EmitOperand(rm, Operand(operand));
1461 } 1527 }
1462 1528
1463 } // namespace dart 1529 } // namespace dart
1464 1530
1465 #endif // defined TARGET_ARCH_IA32 1531 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/assembler_ia32.h ('k') | runtime/vm/assembler_ia32_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698