blob: f3a3fce2ee7dfc18efe36032d8c2c1dc38b2e378 [file] [log] [blame]
Jack Carter86ac5c12013-11-18 23:55:27 +00001//===-- MipsTargetStreamer.cpp - Mips Target Streamer Methods -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides Mips specific target streamer methods.
11//
12//===----------------------------------------------------------------------===//
13
Rafael Espindola054234f2014-01-27 03:53:56 +000014#include "InstPrinter/MipsInstPrinter.h"
Daniel Sanders68c37472014-07-21 13:30:55 +000015#include "MipsELFStreamer.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000016#include "MipsMCTargetDesc.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000017#include "MipsTargetObjectFile.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000018#include "MipsTargetStreamer.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000019#include "llvm/MC/MCContext.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000020#include "llvm/MC/MCELF.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000021#include "llvm/MC/MCSectionELF.h"
Rafael Espindolacb1953f2014-01-26 06:57:13 +000022#include "llvm/MC/MCSubtargetInfo.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000023#include "llvm/MC/MCSymbol.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000024#include "llvm/Support/CommandLine.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000025#include "llvm/Support/ELF.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000026#include "llvm/Support/ErrorHandling.h"
27#include "llvm/Support/FormattedStream.h"
28
29using namespace llvm;
30
Vladimir Medicfb8a2a92014-07-08 08:59:22 +000031MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S)
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000032 : MCTargetStreamer(S), ModuleDirectiveAllowed(true) {
Daniel Sandersd97a6342014-08-13 10:07:34 +000033 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
34}
Rafael Espindola60890b82014-06-23 19:43:40 +000035void MipsTargetStreamer::emitDirectiveSetMicroMips() {}
36void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {}
37void MipsTargetStreamer::emitDirectiveSetMips16() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000038void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); }
39void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000040void MipsTargetStreamer::emitDirectiveSetNoReorder() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000041void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); }
42void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); }
43void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); }
44void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); }
45void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); }
46void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000047void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {}
48void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {}
49void MipsTargetStreamer::emitDirectiveAbiCalls() {}
50void MipsTargetStreamer::emitDirectiveNaN2008() {}
51void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
52void MipsTargetStreamer::emitDirectiveOptionPic0() {}
53void MipsTargetStreamer::emitDirectiveOptionPic2() {}
54void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
55 unsigned ReturnReg) {}
56void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
57void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
58}
Toma Tabacu85618b32014-08-19 14:22:52 +000059void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
60 forbidModuleDirective();
61}
Toma Tabacu26647792014-09-09 12:52:14 +000062void MipsTargetStreamer::emitDirectiveSetMips0() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000063void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
64void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
65void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
66void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); }
67void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); }
68void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); }
69void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); }
70void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); }
71void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); }
72void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
73void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
Toma Tabacu9db22db2014-09-09 10:15:38 +000074void MipsTargetStreamer::emitDirectiveSetPop() {}
75void MipsTargetStreamer::emitDirectiveSetPush() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000076void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
Toma Tabacu351b2fe2014-09-17 09:01:54 +000077void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
Toma Tabacuc4c202a2014-10-01 14:53:19 +000078void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
Rafael Espindola60890b82014-06-23 19:43:40 +000079void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
80 const MCSymbol &Sym, bool IsReg) {
81}
Daniel Sanders7e527422014-07-10 13:38:23 +000082void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
83 bool IsO32ABI) {
84 if (!Enabled && !IsO32ABI)
85 report_fatal_error("+nooddspreg is only valid for O32");
86}
Rafael Espindola24ea09e2014-01-26 06:06:37 +000087
88MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
89 formatted_raw_ostream &OS)
90 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +000091
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +000092void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
93 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000094 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +000095}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +000096
97void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
98 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000099 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000100}
101
Rafael Espindola6633d572014-01-14 18:57:12 +0000102void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
103 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000104 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000105}
106
107void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
108 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000109 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000110}
111
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000112void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
113 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000114 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000115}
116
117void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
118 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000119 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000120}
121
122void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
123 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000124 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000125}
126
127void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
128 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000129 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000130}
131
Daniel Sanders44934432014-08-07 12:03:36 +0000132void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
133 OS << "\t.set\tmsa\n";
134 MipsTargetStreamer::emitDirectiveSetMsa();
135}
136
137void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
138 OS << "\t.set\tnomsa\n";
139 MipsTargetStreamer::emitDirectiveSetNoMsa();
140}
141
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000142void MipsTargetAsmStreamer::emitDirectiveSetAt() {
143 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000144 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000145}
146
147void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
148 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000149 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000150}
151
152void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
153 OS << "\t.end\t" << Name << '\n';
154}
155
Rafael Espindola6633d572014-01-14 18:57:12 +0000156void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
157 OS << "\t.ent\t" << Symbol.getName() << '\n';
158}
159
Jack Carter0cd3c192014-01-06 23:27:31 +0000160void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000161
162void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
163
164void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
165 OS << "\t.nan\tlegacy\n";
166}
167
Jack Carter0cd3c192014-01-06 23:27:31 +0000168void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
169 OS << "\t.option\tpic0\n";
170}
171
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000172void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
173 OS << "\t.option\tpic2\n";
174}
175
Rafael Espindola054234f2014-01-27 03:53:56 +0000176void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
177 unsigned ReturnReg) {
178 OS << "\t.frame\t$"
179 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
180 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000181 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
182}
183
Toma Tabacu85618b32014-08-19 14:22:52 +0000184void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
185 OS << "\t.set arch=" << Arch << "\n";
186 MipsTargetStreamer::emitDirectiveSetArch(Arch);
187}
188
Toma Tabacu26647792014-09-09 12:52:14 +0000189void MipsTargetAsmStreamer::emitDirectiveSetMips0() { OS << "\t.set\tmips0\n"; }
190
Daniel Sandersf0df2212014-08-04 12:20:00 +0000191void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
192 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000193 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000194}
195
196void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
197 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000198 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000199}
200
201void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
202 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000203 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000204}
205
206void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
207 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000208 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000209}
210
211void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
212 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000213 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000214}
215
216void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
217 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000218 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000219}
220
Vladimir Medic615b26e2014-03-04 09:54:09 +0000221void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
222 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000223 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000224}
225
Daniel Sandersf0df2212014-08-04 12:20:00 +0000226void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
227 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000228 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000229}
230
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000231void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
232 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000233 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000234}
235
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000236void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
237 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000238 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000239}
240
Daniel Sandersf0df2212014-08-04 12:20:00 +0000241void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
242 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000243 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000244}
245
Vladimir Medic27c398e2014-03-05 11:05:09 +0000246void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
247 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000248 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000249}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000250
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000251void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
252 OS << "\t.set\tnodsp\n";
253 MipsTargetStreamer::emitDirectiveSetNoDsp();
254}
255
Toma Tabacu9db22db2014-09-09 10:15:38 +0000256void MipsTargetAsmStreamer::emitDirectiveSetPop() { OS << "\t.set\tpop\n"; }
257
258void MipsTargetAsmStreamer::emitDirectiveSetPush() { OS << "\t.set\tpush\n"; }
259
Rafael Espindola25fa2912014-01-27 04:33:11 +0000260// Print a 32 bit hex number with all numbers.
261static void printHex32(unsigned Value, raw_ostream &OS) {
262 OS << "0x";
263 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000264 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000265}
266
267void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
268 int CPUTopSavedRegOff) {
269 OS << "\t.mask \t";
270 printHex32(CPUBitmask, OS);
271 OS << ',' << CPUTopSavedRegOff << '\n';
272}
273
274void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
275 int FPUTopSavedRegOff) {
276 OS << "\t.fmask\t";
277 printHex32(FPUBitmask, OS);
278 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000279}
280
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000281void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000282 OS << "\t.cpload\t$"
283 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000284 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000285}
286
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000287void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
288 int RegOrOffset,
289 const MCSymbol &Sym,
290 bool IsReg) {
291 OS << "\t.cpsetup\t$"
292 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
293
294 if (IsReg)
295 OS << "$"
296 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
297 else
298 OS << RegOrOffset;
299
300 OS << ", ";
301
302 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000303 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000304}
305
Daniel Sanders7e527422014-07-10 13:38:23 +0000306void MipsTargetAsmStreamer::emitDirectiveModuleFP(
307 MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
308 MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000309
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000310 StringRef ModuleValue;
311 OS << "\t.module\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000312 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000313}
314
Daniel Sanders7e527422014-07-10 13:38:23 +0000315void MipsTargetAsmStreamer::emitDirectiveSetFp(
316 MipsABIFlagsSection::FpABIKind Value) {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000317 StringRef ModuleValue;
318 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000319 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000320}
321
322void MipsTargetAsmStreamer::emitMipsAbiFlags() {
323 // No action required for text output.
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000324}
325
Daniel Sanders7e527422014-07-10 13:38:23 +0000326void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
327 bool IsO32ABI) {
328 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
329
330 OS << "\t.module\t" << (Enabled ? "" : "no") << "oddspreg\n";
331}
332
Jack Carter0cd3c192014-01-06 23:27:31 +0000333// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000334MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
335 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000336 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000337 MCAssembler &MCA = getStreamer().getAssembler();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000338 Triple T(STI.getTargetTriple());
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000339 Pic = (MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_)
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000340 ? true
341 : false;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000342
Eric Christophera5762812015-01-26 17:33:46 +0000343 uint64_t Features = STI.getFeatureBits();
344
345 // Set the header flags that we can in the constructor.
346 // FIXME: This is a fairly terrible hack. We set the rest
347 // of these in the destructor. The problem here is two-fold:
348 //
349 // a: Some of the eflags can be set/reset by directives.
350 // b: There aren't any usage paths that initialize the ABI
351 // pointer until after we initialize either an assembler
352 // or the target machine.
353 // We can fix this by making the target streamer construct
354 // the ABI, but this is fraught with wide ranging dependency
355 // issues as well.
356 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000357
358 // Architecture
Daniel Sanders950f48d2014-07-04 15:21:53 +0000359 if (Features & Mips::FeatureMips64r6)
360 EFlags |= ELF::EF_MIPS_ARCH_64R6;
361 else if (Features & Mips::FeatureMips64r2)
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000362 EFlags |= ELF::EF_MIPS_ARCH_64R2;
363 else if (Features & Mips::FeatureMips64)
364 EFlags |= ELF::EF_MIPS_ARCH_64;
Daniel Sanders950f48d2014-07-04 15:21:53 +0000365 else if (Features & Mips::FeatureMips5)
366 EFlags |= ELF::EF_MIPS_ARCH_5;
Daniel Sandersf7b32292014-04-03 12:13:36 +0000367 else if (Features & Mips::FeatureMips4)
368 EFlags |= ELF::EF_MIPS_ARCH_4;
Daniel Sanders950f48d2014-07-04 15:21:53 +0000369 else if (Features & Mips::FeatureMips3)
370 EFlags |= ELF::EF_MIPS_ARCH_3;
371 else if (Features & Mips::FeatureMips32r6)
372 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000373 else if (Features & Mips::FeatureMips32r2)
374 EFlags |= ELF::EF_MIPS_ARCH_32R2;
375 else if (Features & Mips::FeatureMips32)
376 EFlags |= ELF::EF_MIPS_ARCH_32;
Daniel Sanders950f48d2014-07-04 15:21:53 +0000377 else if (Features & Mips::FeatureMips2)
378 EFlags |= ELF::EF_MIPS_ARCH_2;
379 else
380 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000381
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000382 // Other options.
383 if (Features & Mips::FeatureNaN2008)
384 EFlags |= ELF::EF_MIPS_NAN2008;
385
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000386 // -mabicalls and -mplt are not implemented but we should act as if they were
387 // given.
388 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000389
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000390 MCA.setELFHeaderEFlags(EFlags);
391}
Jack Carter86ac5c12013-11-18 23:55:27 +0000392
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000393void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
Rafael Espindola26e917c2014-01-15 03:07:12 +0000394 if (!isMicroMipsEnabled())
395 return;
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000396 MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Symbol);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000397 uint8_t Type = MCELF::GetType(Data);
398 if (Type != ELF::STT_FUNC)
399 return;
400
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000401 // The "other" values are stored in the last 6 bits of the second byte
402 // The traditional defines for STO values assume the full byte and thus
403 // the shift to pack it.
Rafael Espindola26e917c2014-01-15 03:07:12 +0000404 MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000405}
406
Rafael Espindola972e71a2014-01-31 23:10:26 +0000407void MipsTargetELFStreamer::finish() {
408 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000409 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000410
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000411 // .bss, .text and .data are always at least 16-byte aligned.
412 MCSectionData &TextSectionData =
413 MCA.getOrCreateSectionData(*OFI.getTextSection());
414 MCSectionData &DataSectionData =
415 MCA.getOrCreateSectionData(*OFI.getDataSection());
416 MCSectionData &BSSSectionData =
417 MCA.getOrCreateSectionData(*OFI.getBSSSection());
418
419 TextSectionData.setAlignment(std::max(16u, TextSectionData.getAlignment()));
420 DataSectionData.setAlignment(std::max(16u, DataSectionData.getAlignment()));
421 BSSSectionData.setAlignment(std::max(16u, BSSSectionData.getAlignment()));
422
Eric Christophera5762812015-01-26 17:33:46 +0000423 uint64_t Features = STI.getFeatureBits();
424
425 // Update e_header flags. See the FIXME and comment above in
426 // the constructor for a full rundown on this.
427 unsigned EFlags = MCA.getELFHeaderEFlags();
428
429 // ABI
430 // N64 does not require any ABI bits.
431 if (getABI().IsO32())
432 EFlags |= ELF::EF_MIPS_ABI_O32;
433 else if (getABI().IsN32())
434 EFlags |= ELF::EF_MIPS_ABI2;
435
436 if (Features & Mips::FeatureGP64Bit) {
437 if (getABI().IsO32())
438 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
439 } else if (Features & Mips::FeatureMips64r2 || Features & Mips::FeatureMips64)
440 EFlags |= ELF::EF_MIPS_32BITMODE;
441
442 // If we've set the cpic eflag and we're n64, go ahead and set the pic
443 // one as well.
444 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
445 EFlags |= ELF::EF_MIPS_PIC;
446
447 MCA.setELFHeaderEFlags(EFlags);
448
Daniel Sanders68c37472014-07-21 13:30:55 +0000449 // Emit all the option records.
450 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
451 // .reginfo.
452 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
453 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000454
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000455 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000456}
457
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000458void MipsTargetELFStreamer::emitAssignment(MCSymbol *Symbol,
459 const MCExpr *Value) {
460 // If on rhs is micromips symbol then mark Symbol as microMips.
461 if (Value->getKind() != MCExpr::SymbolRef)
462 return;
463 const MCSymbol &RhsSym =
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000464 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol();
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000465 MCSymbolData &Data = getStreamer().getOrCreateSymbolData(&RhsSym);
466 uint8_t Type = MCELF::GetType(Data);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000467 if ((Type != ELF::STT_FUNC) ||
468 !(MCELF::getOther(Data) & (ELF::STO_MIPS_MICROMIPS >> 2)))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000469 return;
470
471 MCSymbolData &SymbolData = getStreamer().getOrCreateSymbolData(Symbol);
472 // The "other" values are stored in the last 6 bits of the second byte.
473 // The traditional defines for STO values assume the full byte and thus
474 // the shift to pack it.
475 MCELF::setOther(SymbolData, ELF::STO_MIPS_MICROMIPS >> 2);
476}
477
Jack Carter86ac5c12013-11-18 23:55:27 +0000478MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000479 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000480}
481
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000482void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
483 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000484
485 MCAssembler &MCA = getStreamer().getAssembler();
486 unsigned Flags = MCA.getELFHeaderEFlags();
487 Flags |= ELF::EF_MIPS_MICROMIPS;
488 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000489 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000490}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000491
492void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
493 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000494 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000495}
496
Rafael Espindola6633d572014-01-14 18:57:12 +0000497void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000498 MCAssembler &MCA = getStreamer().getAssembler();
499 unsigned Flags = MCA.getELFHeaderEFlags();
500 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
501 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000502 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000503}
504
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000505void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000506 MCAssembler &MCA = getStreamer().getAssembler();
507 unsigned Flags = MCA.getELFHeaderEFlags();
508 Flags |= ELF::EF_MIPS_NOREORDER;
509 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000510 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000511}
512
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000513void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000514 MCAssembler &MCA = getStreamer().getAssembler();
515 MCContext &Context = MCA.getContext();
516 MCStreamer &OS = getStreamer();
517
Rafael Espindolaba31e272015-01-29 17:33:21 +0000518 const MCSectionELF *Sec = Context.getELFSection(
519 ".pdr", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000520
521 const MCSymbolRefExpr *ExprRef =
522 MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context);
523
524 MCSectionData &SecData = MCA.getOrCreateSectionData(*Sec);
525 SecData.setAlignment(4);
526
527 OS.PushSection();
528
529 OS.SwitchSection(Sec);
530
531 OS.EmitValueImpl(ExprRef, 4);
532
533 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
534 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
535
536 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
537 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
538
539 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
540 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
541 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
542
543 // The .end directive marks the end of a procedure. Invalidate
544 // the information gathered up until this point.
545 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
546
547 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000548}
549
Rafael Espindola6633d572014-01-14 18:57:12 +0000550void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000551 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000552}
553
Jack Carter0cd3c192014-01-06 23:27:31 +0000554void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
555 MCAssembler &MCA = getStreamer().getAssembler();
556 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000557 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000558 MCA.setELFHeaderEFlags(Flags);
559}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000560
561void MipsTargetELFStreamer::emitDirectiveNaN2008() {
562 MCAssembler &MCA = getStreamer().getAssembler();
563 unsigned Flags = MCA.getELFHeaderEFlags();
564 Flags |= ELF::EF_MIPS_NAN2008;
565 MCA.setELFHeaderEFlags(Flags);
566}
567
568void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
569 MCAssembler &MCA = getStreamer().getAssembler();
570 unsigned Flags = MCA.getELFHeaderEFlags();
571 Flags &= ~ELF::EF_MIPS_NAN2008;
572 MCA.setELFHeaderEFlags(Flags);
573}
574
Jack Carter0cd3c192014-01-06 23:27:31 +0000575void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
576 MCAssembler &MCA = getStreamer().getAssembler();
577 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000578 // This option overrides other PIC options like -KPIC.
579 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000580 Flags &= ~ELF::EF_MIPS_PIC;
581 MCA.setELFHeaderEFlags(Flags);
582}
Rafael Espindola054234f2014-01-27 03:53:56 +0000583
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000584void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
585 MCAssembler &MCA = getStreamer().getAssembler();
586 unsigned Flags = MCA.getELFHeaderEFlags();
587 Pic = true;
588 // NOTE: We are following the GAS behaviour here which means the directive
589 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
590 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
591 // EF_MIPS_CPIC to be mutually exclusive.
592 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
593 MCA.setELFHeaderEFlags(Flags);
594}
595
Rafael Espindola054234f2014-01-27 03:53:56 +0000596void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000597 unsigned ReturnReg_) {
598 MCContext &Context = getStreamer().getAssembler().getContext();
599 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
600
601 FrameInfoSet = true;
602 FrameReg = RegInfo->getEncodingValue(StackReg);
603 FrameOffset = StackSize;
604 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000605}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000606
607void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
608 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000609 GPRInfoSet = true;
610 GPRBitMask = CPUBitmask;
611 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000612}
613
614void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
615 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000616 FPRInfoSet = true;
617 FPRBitMask = FPUBitmask;
618 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000619}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000620
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000621void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000622 // .cpload $reg
623 // This directive expands to:
624 // lui $gp, %hi(_gp_disp)
625 // addui $gp, $gp, %lo(_gp_disp)
626 // addu $gp, $gp, $reg
627 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000628 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000629 return;
630
631 // There's a GNU extension controlled by -mno-shared that allows
632 // locally-binding symbols to be accessed using absolute addresses.
633 // This is currently not supported. When supported -mno-shared makes
634 // .cpload expand to:
635 // lui $gp, %hi(__gnu_local_gp)
636 // addiu $gp, $gp, %lo(__gnu_local_gp)
637
638 StringRef SymName("_gp_disp");
639 MCAssembler &MCA = getStreamer().getAssembler();
640 MCSymbol *GP_Disp = MCA.getContext().GetOrCreateSymbol(SymName);
641 MCA.getOrCreateSymbolData(*GP_Disp);
642
643 MCInst TmpInst;
644 TmpInst.setOpcode(Mips::LUi);
645 TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
646 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::Create(
647 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
648 TmpInst.addOperand(MCOperand::CreateExpr(HiSym));
649 getStreamer().EmitInstruction(TmpInst, STI);
650
651 TmpInst.clear();
652
653 TmpInst.setOpcode(Mips::ADDiu);
654 TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
655 TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
656 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::Create(
657 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
658 TmpInst.addOperand(MCOperand::CreateExpr(LoSym));
659 getStreamer().EmitInstruction(TmpInst, STI);
660
661 TmpInst.clear();
662
663 TmpInst.setOpcode(Mips::ADDu);
664 TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
665 TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
666 TmpInst.addOperand(MCOperand::CreateReg(RegNo));
667 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000668
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000669 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000670}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000671
672void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
673 int RegOrOffset,
674 const MCSymbol &Sym,
675 bool IsReg) {
676 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000677 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000678 return;
679
680 MCAssembler &MCA = getStreamer().getAssembler();
681 MCInst Inst;
682
683 // Either store the old $gp in a register or on the stack
684 if (IsReg) {
685 // move $save, $gpreg
686 Inst.setOpcode(Mips::DADDu);
687 Inst.addOperand(MCOperand::CreateReg(RegOrOffset));
688 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
689 Inst.addOperand(MCOperand::CreateReg(Mips::ZERO));
690 } else {
691 // sd $gpreg, offset($sp)
692 Inst.setOpcode(Mips::SD);
693 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
694 Inst.addOperand(MCOperand::CreateReg(Mips::SP));
695 Inst.addOperand(MCOperand::CreateImm(RegOrOffset));
696 }
697 getStreamer().EmitInstruction(Inst, STI);
698 Inst.clear();
699
700 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
701 Sym.getName(), MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
702 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
703 Sym.getName(), MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
704 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
705 Inst.setOpcode(Mips::LUi);
706 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
707 Inst.addOperand(MCOperand::CreateExpr(HiExpr));
708 getStreamer().EmitInstruction(Inst, STI);
709 Inst.clear();
710
711 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
712 Inst.setOpcode(Mips::ADDiu);
713 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
714 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
715 Inst.addOperand(MCOperand::CreateExpr(LoExpr));
716 getStreamer().EmitInstruction(Inst, STI);
717 Inst.clear();
718
719 // daddu $gp, $gp, $funcreg
720 Inst.setOpcode(Mips::DADDu);
721 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
722 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
723 Inst.addOperand(MCOperand::CreateReg(RegNo));
724 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000725
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000726 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000727}
728
729void MipsTargetELFStreamer::emitMipsAbiFlags() {
730 MCAssembler &MCA = getStreamer().getAssembler();
731 MCContext &Context = MCA.getContext();
732 MCStreamer &OS = getStreamer();
Rafael Espindolaba31e272015-01-29 17:33:21 +0000733 const MCSectionELF *Sec = Context.getELFSection(
734 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000735 MCSectionData &ABIShndxSD = MCA.getOrCreateSectionData(*Sec);
736 ABIShndxSD.setAlignment(8);
737 OS.SwitchSection(Sec);
738
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000739 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000740}
Daniel Sanders7e527422014-07-10 13:38:23 +0000741
742void MipsTargetELFStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
743 bool IsO32ABI) {
744 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
745
746 ABIFlagsSection.OddSPReg = Enabled;
747}