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

Side by Side Diff: src/assembler_ia32.cpp

Issue 828873002: Subzero: Start writing out some relocation sections (text) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: review fixes Created 5 years, 11 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
« no previous file with comments | « src/assembler_ia32.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===// 1 //===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===//
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 // 5 //
6 // Modified by the Subzero authors. 6 // Modified by the Subzero authors.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // The Subzero Code Generator 10 // The Subzero Code Generator
11 // 11 //
12 // This file is distributed under the University of Illinois Open Source 12 // This file is distributed under the University of Illinois Open Source
13 // License. See LICENSE.TXT for details. 13 // License. See LICENSE.TXT for details.
14 // 14 //
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 // 16 //
17 // This file implements the Assembler class for x86-32. 17 // This file implements the Assembler class for x86-32.
18 // 18 //
19 //===----------------------------------------------------------------------===// 19 //===----------------------------------------------------------------------===//
20 20
21 #include "assembler_ia32.h" 21 #include "assembler_ia32.h"
22 #include "IceCfg.h" 22 #include "IceCfg.h"
23 #include "IceOperand.h" 23 #include "IceOperand.h"
24 24
25 namespace Ice { 25 namespace Ice {
26 namespace x86 { 26 namespace x86 {
27 27
28 class DirectCallRelocation : public AssemblerFixup {
29 DirectCallRelocation(const DirectCallRelocation &) = delete;
30 DirectCallRelocation &operator=(const DirectCallRelocation &) = delete;
31
32 public:
33 static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind,
34 const Constant *Sym) {
35 return new (Asm->Allocate<DirectCallRelocation>())
36 DirectCallRelocation(Kind, Sym);
37 }
38
39 private:
40 DirectCallRelocation(FixupKind Kind, const Constant *Sym)
41 : AssemblerFixup(Kind, Sym) {}
42 };
43
44 Address Address::ofConstPool(Assembler *Asm, const Constant *Imm) { 28 Address Address::ofConstPool(Assembler *Asm, const Constant *Imm) {
45 AssemblerFixup *Fixup = 29 AssemblerFixup *Fixup = Asm->createFixup(llvm::ELF::R_386_32, Imm);
46 x86::DisplacementRelocation::create(Asm, FK_Abs_4, Imm);
47 const RelocOffsetT Offset = 0; 30 const RelocOffsetT Offset = 0;
48 return x86::Address::Absolute(Offset, Fixup); 31 return x86::Address::Absolute(Offset, Fixup);
49 } 32 }
50 33
51 AssemblerX86::~AssemblerX86() { 34 AssemblerX86::~AssemblerX86() {
52 #ifndef NDEBUG 35 #ifndef NDEBUG
53 for (const Label *Label : CfgNodeLabels) { 36 for (const Label *Label : CfgNodeLabels) {
54 Label->FinalCheck(); 37 Label->FinalCheck();
55 } 38 }
56 for (const Label *Label : LocalLabels) { 39 for (const Label *Label : LocalLabels) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 void AssemblerX86::call(const Address &address) { 103 void AssemblerX86::call(const Address &address) {
121 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 104 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
122 EmitUint8(0xFF); 105 EmitUint8(0xFF);
123 EmitOperand(2, address); 106 EmitOperand(2, address);
124 } 107 }
125 108
126 void AssemblerX86::call(const ConstantRelocatable *label) { 109 void AssemblerX86::call(const ConstantRelocatable *label) {
127 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 110 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
128 intptr_t call_start = buffer_.GetPosition(); 111 intptr_t call_start = buffer_.GetPosition();
129 EmitUint8(0xE8); 112 EmitUint8(0xE8);
130 EmitFixup(DirectCallRelocation::create(this, FK_PcRel_4, label)); 113 EmitFixup(this->createFixup(llvm::ELF::R_386_PC32, label));
131 EmitInt32(-4); 114 EmitInt32(-4);
132 assert((buffer_.GetPosition() - call_start) == kCallExternalLabelSize); 115 assert((buffer_.GetPosition() - call_start) == kCallExternalLabelSize);
133 (void)call_start; 116 (void)call_start;
134 } 117 }
135 118
136 void AssemblerX86::pushl(GPRRegister reg) { 119 void AssemblerX86::pushl(GPRRegister reg) {
137 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 120 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
138 EmitUint8(0x50 + reg); 121 EmitUint8(0x50 + reg);
139 } 122 }
140 123
(...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 EmitUint8(0x80 + condition); 2250 EmitUint8(0x80 + condition);
2268 EmitLabelLink(label); 2251 EmitLabelLink(label);
2269 } 2252 }
2270 } 2253 }
2271 2254
2272 void AssemblerX86::j(CondX86::BrCond condition, 2255 void AssemblerX86::j(CondX86::BrCond condition,
2273 const ConstantRelocatable *label) { 2256 const ConstantRelocatable *label) {
2274 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 2257 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2275 EmitUint8(0x0F); 2258 EmitUint8(0x0F);
2276 EmitUint8(0x80 + condition); 2259 EmitUint8(0x80 + condition);
2277 EmitFixup(DirectCallRelocation::create(this, FK_PcRel_4, label)); 2260 EmitFixup(this->createFixup(llvm::ELF::R_386_PC32, label));
2278 EmitInt32(-4); 2261 EmitInt32(-4);
2279 } 2262 }
2280 2263
2281 void AssemblerX86::jmp(GPRRegister reg) { 2264 void AssemblerX86::jmp(GPRRegister reg) {
2282 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 2265 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2283 EmitUint8(0xFF); 2266 EmitUint8(0xFF);
2284 EmitRegisterOperand(4, reg); 2267 EmitRegisterOperand(4, reg);
2285 } 2268 }
2286 2269
2287 void AssemblerX86::jmp(Label *label, bool near) { 2270 void AssemblerX86::jmp(Label *label, bool near) {
(...skipping 15 matching lines...) Expand all
2303 EmitNearLabelLink(label); 2286 EmitNearLabelLink(label);
2304 } else { 2287 } else {
2305 EmitUint8(0xE9); 2288 EmitUint8(0xE9);
2306 EmitLabelLink(label); 2289 EmitLabelLink(label);
2307 } 2290 }
2308 } 2291 }
2309 2292
2310 void AssemblerX86::jmp(const ConstantRelocatable *label) { 2293 void AssemblerX86::jmp(const ConstantRelocatable *label) {
2311 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 2294 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2312 EmitUint8(0xE9); 2295 EmitUint8(0xE9);
2313 EmitFixup(DirectCallRelocation::create(this, FK_PcRel_4, label)); 2296 EmitFixup(this->createFixup(llvm::ELF::R_386_PC32, label));
2314 EmitInt32(-4); 2297 EmitInt32(-4);
2315 } 2298 }
2316 2299
2317 void AssemblerX86::mfence() { 2300 void AssemblerX86::mfence() {
2318 AssemblerBuffer::EnsureCapacity ensured(&buffer_); 2301 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2319 EmitUint8(0x0F); 2302 EmitUint8(0x0F);
2320 EmitUint8(0xAE); 2303 EmitUint8(0xAE);
2321 EmitUint8(0xF0); 2304 EmitUint8(0xF0);
2322 } 2305 }
2323 2306
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 assert(shifter == RegX8632::Encoded_Reg_ecx); 2501 assert(shifter == RegX8632::Encoded_Reg_ecx);
2519 (void)shifter; 2502 (void)shifter;
2520 if (Ty == IceType_i16) 2503 if (Ty == IceType_i16)
2521 EmitOperandSizeOverride(); 2504 EmitOperandSizeOverride();
2522 EmitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3); 2505 EmitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3);
2523 EmitOperand(rm, operand); 2506 EmitOperand(rm, operand);
2524 } 2507 }
2525 2508
2526 } // end of namespace x86 2509 } // end of namespace x86
2527 } // end of namespace Ice 2510 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/assembler_ia32.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698