blob: 994126e83b6e425ff518ea03e5771657189efc54 [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"
Rafael Espindola972e71a2014-01-31 23:10:26 +000020#include "llvm/MC/MCSectionELF.h"
Rafael Espindolacb1953f2014-01-26 06:57:13 +000021#include "llvm/MC/MCSubtargetInfo.h"
Rafael Espindola95fb9b92015-06-02 20:38:46 +000022#include "llvm/MC/MCSymbolELF.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000023#include "llvm/Support/CommandLine.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000024#include "llvm/Support/ELF.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000025#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/FormattedStream.h"
27
28using namespace llvm;
29
Vladimir Medicfb8a2a92014-07-08 08:59:22 +000030MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S)
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000031 : MCTargetStreamer(S), ModuleDirectiveAllowed(true) {
Daniel Sandersd97a6342014-08-13 10:07:34 +000032 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
33}
Rafael Espindola60890b82014-06-23 19:43:40 +000034void MipsTargetStreamer::emitDirectiveSetMicroMips() {}
35void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {}
36void MipsTargetStreamer::emitDirectiveSetMips16() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000037void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); }
38void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000039void MipsTargetStreamer::emitDirectiveSetNoReorder() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000040void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); }
41void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); }
42void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); }
43void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); }
44void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); }
Toma Tabacu16a74492015-02-13 10:30:57 +000045void MipsTargetStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
46 forbidModuleDirective();
47}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000048void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000049void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {}
50void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {}
51void MipsTargetStreamer::emitDirectiveAbiCalls() {}
52void MipsTargetStreamer::emitDirectiveNaN2008() {}
53void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
54void MipsTargetStreamer::emitDirectiveOptionPic0() {}
55void MipsTargetStreamer::emitDirectiveOptionPic2() {}
Toma Tabacu9ca50962015-04-16 09:53:47 +000056void MipsTargetStreamer::emitDirectiveInsn() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000057void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
58 unsigned ReturnReg) {}
59void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
60void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
61}
Toma Tabacu85618b32014-08-19 14:22:52 +000062void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
63 forbidModuleDirective();
64}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000065void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000066void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
67void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
68void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
69void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); }
70void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); }
71void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); }
72void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); }
Daniel Sanders17793142015-02-18 16:24:50 +000073void MipsTargetStreamer::emitDirectiveSetMips32R3() { forbidModuleDirective(); }
74void MipsTargetStreamer::emitDirectiveSetMips32R5() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000075void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); }
76void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); }
77void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
Daniel Sanders17793142015-02-18 16:24:50 +000078void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); }
79void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000080void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000081void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); }
82void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); }
Toma Tabacu29696502015-06-02 09:48:04 +000083void MipsTargetStreamer::emitDirectiveSetSoftFloat() {
84 forbidModuleDirective();
85}
86void MipsTargetStreamer::emitDirectiveSetHardFloat() {
87 forbidModuleDirective();
88}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000089void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
Toma Tabacu351b2fe2014-09-17 09:01:54 +000090void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
Toma Tabacuc4c202a2014-10-01 14:53:19 +000091void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
Daniel Sanderse2982ad2015-09-17 16:08:39 +000092void MipsTargetStreamer::emitDirectiveCpRestore(
93 SmallVector<MCInst, 3> &StoreInsts, int Offset) {
94 forbidModuleDirective();
95}
Rafael Espindola60890b82014-06-23 19:43:40 +000096void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
97 const MCSymbol &Sym, bool IsReg) {
98}
Daniel Sandersf173dda2015-09-22 10:50:09 +000099void MipsTargetStreamer::emitDirectiveCpreturn(unsigned SaveLocation,
100 bool SaveLocationIsRegister) {}
Toma Tabacubfcbfd52015-06-23 12:34:19 +0000101
Toma Tabacua64e5402015-06-25 12:44:38 +0000102void MipsTargetStreamer::emitDirectiveModuleFP() {}
Toma Tabacubfcbfd52015-06-23 12:34:19 +0000103
Toma Tabacu3c499582015-06-25 10:56:57 +0000104void MipsTargetStreamer::emitDirectiveModuleOddSPReg() {
105 if (!ABIFlagsSection.OddSPReg && !ABIFlagsSection.Is32BitABI)
Daniel Sanders7e527422014-07-10 13:38:23 +0000106 report_fatal_error("+nooddspreg is only valid for O32");
107}
Toma Tabacu0f093132015-06-30 13:46:03 +0000108void MipsTargetStreamer::emitDirectiveModuleSoftFloat() {}
109void MipsTargetStreamer::emitDirectiveModuleHardFloat() {}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000110void MipsTargetStreamer::emitDirectiveSetFp(
111 MipsABIFlagsSection::FpABIKind Value) {
112 forbidModuleDirective();
113}
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000114void MipsTargetStreamer::emitDirectiveSetOddSPReg() { forbidModuleDirective(); }
115void MipsTargetStreamer::emitDirectiveSetNoOddSPReg() {
116 forbidModuleDirective();
117}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000118
119MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
120 formatted_raw_ostream &OS)
121 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000122
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000123void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
124 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000125 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000126}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000127
128void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
129 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000130 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000131}
132
Rafael Espindola6633d572014-01-14 18:57:12 +0000133void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
134 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000135 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000136}
137
138void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
139 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000140 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000141}
142
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000143void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
144 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000145 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000146}
147
148void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
149 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000150 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000151}
152
153void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
154 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000155 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000156}
157
158void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
159 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000160 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000161}
162
Daniel Sanders44934432014-08-07 12:03:36 +0000163void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
164 OS << "\t.set\tmsa\n";
165 MipsTargetStreamer::emitDirectiveSetMsa();
166}
167
168void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
169 OS << "\t.set\tnomsa\n";
170 MipsTargetStreamer::emitDirectiveSetNoMsa();
171}
172
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000173void MipsTargetAsmStreamer::emitDirectiveSetAt() {
174 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000175 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000176}
177
Toma Tabacu16a74492015-02-13 10:30:57 +0000178void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
179 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
180 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
181}
182
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000183void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
184 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000185 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000186}
187
188void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
189 OS << "\t.end\t" << Name << '\n';
190}
191
Rafael Espindola6633d572014-01-14 18:57:12 +0000192void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
193 OS << "\t.ent\t" << Symbol.getName() << '\n';
194}
195
Jack Carter0cd3c192014-01-06 23:27:31 +0000196void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000197
198void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
199
200void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
201 OS << "\t.nan\tlegacy\n";
202}
203
Jack Carter0cd3c192014-01-06 23:27:31 +0000204void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
205 OS << "\t.option\tpic0\n";
206}
207
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000208void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
209 OS << "\t.option\tpic2\n";
210}
211
Toma Tabacu9ca50962015-04-16 09:53:47 +0000212void MipsTargetAsmStreamer::emitDirectiveInsn() {
213 MipsTargetStreamer::emitDirectiveInsn();
214 OS << "\t.insn\n";
215}
216
Rafael Espindola054234f2014-01-27 03:53:56 +0000217void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
218 unsigned ReturnReg) {
219 OS << "\t.frame\t$"
220 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
221 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000222 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
223}
224
Toma Tabacu85618b32014-08-19 14:22:52 +0000225void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
226 OS << "\t.set arch=" << Arch << "\n";
227 MipsTargetStreamer::emitDirectiveSetArch(Arch);
228}
229
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000230void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
231 OS << "\t.set\tmips0\n";
232 MipsTargetStreamer::emitDirectiveSetMips0();
233}
Toma Tabacu26647792014-09-09 12:52:14 +0000234
Daniel Sandersf0df2212014-08-04 12:20:00 +0000235void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
236 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000237 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000238}
239
240void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
241 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000242 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000243}
244
245void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
246 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000247 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000248}
249
250void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
251 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000252 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000253}
254
255void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
256 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000257 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000258}
259
260void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
261 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000262 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000263}
264
Vladimir Medic615b26e2014-03-04 09:54:09 +0000265void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
266 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000267 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000268}
269
Daniel Sanders17793142015-02-18 16:24:50 +0000270void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
271 OS << "\t.set\tmips32r3\n";
272 MipsTargetStreamer::emitDirectiveSetMips32R3();
273}
274
275void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
276 OS << "\t.set\tmips32r5\n";
277 MipsTargetStreamer::emitDirectiveSetMips32R5();
278}
279
Daniel Sandersf0df2212014-08-04 12:20:00 +0000280void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
281 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000282 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000283}
284
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000285void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
286 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000287 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000288}
289
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000290void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
291 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000292 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000293}
294
Daniel Sanders17793142015-02-18 16:24:50 +0000295void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
296 OS << "\t.set\tmips64r3\n";
297 MipsTargetStreamer::emitDirectiveSetMips64R3();
298}
299
300void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
301 OS << "\t.set\tmips64r5\n";
302 MipsTargetStreamer::emitDirectiveSetMips64R5();
303}
304
Daniel Sandersf0df2212014-08-04 12:20:00 +0000305void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
306 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000307 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000308}
309
Vladimir Medic27c398e2014-03-05 11:05:09 +0000310void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
311 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000312 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000313}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000314
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000315void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
316 OS << "\t.set\tnodsp\n";
317 MipsTargetStreamer::emitDirectiveSetNoDsp();
318}
319
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000320void MipsTargetAsmStreamer::emitDirectiveSetPop() {
321 OS << "\t.set\tpop\n";
322 MipsTargetStreamer::emitDirectiveSetPop();
323}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000324
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000325void MipsTargetAsmStreamer::emitDirectiveSetPush() {
326 OS << "\t.set\tpush\n";
327 MipsTargetStreamer::emitDirectiveSetPush();
328}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000329
Toma Tabacu29696502015-06-02 09:48:04 +0000330void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
331 OS << "\t.set\tsoftfloat\n";
332 MipsTargetStreamer::emitDirectiveSetSoftFloat();
333}
334
335void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
336 OS << "\t.set\thardfloat\n";
337 MipsTargetStreamer::emitDirectiveSetHardFloat();
338}
339
Rafael Espindola25fa2912014-01-27 04:33:11 +0000340// Print a 32 bit hex number with all numbers.
341static void printHex32(unsigned Value, raw_ostream &OS) {
342 OS << "0x";
343 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000344 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000345}
346
347void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
348 int CPUTopSavedRegOff) {
349 OS << "\t.mask \t";
350 printHex32(CPUBitmask, OS);
351 OS << ',' << CPUTopSavedRegOff << '\n';
352}
353
354void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
355 int FPUTopSavedRegOff) {
356 OS << "\t.fmask\t";
357 printHex32(FPUBitmask, OS);
358 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000359}
360
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000361void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000362 OS << "\t.cpload\t$"
363 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000364 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000365}
366
Daniel Sanderse2982ad2015-09-17 16:08:39 +0000367void MipsTargetAsmStreamer::emitDirectiveCpRestore(
368 SmallVector<MCInst, 3> &StoreInsts, int Offset) {
369 MipsTargetStreamer::emitDirectiveCpRestore(StoreInsts, Offset);
370 OS << "\t.cprestore\t" << Offset << "\n";
371}
372
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000373void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
374 int RegOrOffset,
375 const MCSymbol &Sym,
376 bool IsReg) {
377 OS << "\t.cpsetup\t$"
378 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
379
380 if (IsReg)
381 OS << "$"
382 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
383 else
384 OS << RegOrOffset;
385
386 OS << ", ";
387
Daniel Sanders5d796282015-09-21 09:26:55 +0000388 OS << Sym.getName();
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000389 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000390}
391
Daniel Sandersf173dda2015-09-22 10:50:09 +0000392void MipsTargetAsmStreamer::emitDirectiveCpreturn(unsigned SaveLocation,
393 bool SaveLocationIsRegister) {
394 OS << "\t.cpreturn";
395 forbidModuleDirective();
396}
397
Toma Tabacua64e5402015-06-25 12:44:38 +0000398void MipsTargetAsmStreamer::emitDirectiveModuleFP() {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000399 OS << "\t.module\tfp=";
Toma Tabacua64e5402015-06-25 12:44:38 +0000400 OS << ABIFlagsSection.getFpABIString(ABIFlagsSection.getFpABI()) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000401}
402
Daniel Sanders7e527422014-07-10 13:38:23 +0000403void MipsTargetAsmStreamer::emitDirectiveSetFp(
404 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000405 MipsTargetStreamer::emitDirectiveSetFp(Value);
406
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000407 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000408 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000409}
410
Toma Tabacu3c499582015-06-25 10:56:57 +0000411void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() {
412 MipsTargetStreamer::emitDirectiveModuleOddSPReg();
Daniel Sanders7e527422014-07-10 13:38:23 +0000413
Toma Tabacu3c499582015-06-25 10:56:57 +0000414 OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
Daniel Sanders7e527422014-07-10 13:38:23 +0000415}
416
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000417void MipsTargetAsmStreamer::emitDirectiveSetOddSPReg() {
418 MipsTargetStreamer::emitDirectiveSetOddSPReg();
419 OS << "\t.set\toddspreg\n";
420}
421
422void MipsTargetAsmStreamer::emitDirectiveSetNoOddSPReg() {
423 MipsTargetStreamer::emitDirectiveSetNoOddSPReg();
424 OS << "\t.set\tnooddspreg\n";
425}
426
Toma Tabacu0f093132015-06-30 13:46:03 +0000427void MipsTargetAsmStreamer::emitDirectiveModuleSoftFloat() {
428 OS << "\t.module\tsoftfloat\n";
429}
430
431void MipsTargetAsmStreamer::emitDirectiveModuleHardFloat() {
432 OS << "\t.module\thardfloat\n";
433}
434
Jack Carter0cd3c192014-01-06 23:27:31 +0000435// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000436MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
437 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000438 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000439 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000440 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000441
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000442 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000443
444 // Set the header flags that we can in the constructor.
445 // FIXME: This is a fairly terrible hack. We set the rest
446 // of these in the destructor. The problem here is two-fold:
447 //
448 // a: Some of the eflags can be set/reset by directives.
449 // b: There aren't any usage paths that initialize the ABI
450 // pointer until after we initialize either an assembler
451 // or the target machine.
452 // We can fix this by making the target streamer construct
453 // the ABI, but this is fraught with wide ranging dependency
454 // issues as well.
455 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000456
457 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000458 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000459 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000460 else if (Features[Mips::FeatureMips64r2] ||
461 Features[Mips::FeatureMips64r3] ||
462 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000463 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000464 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000465 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000466 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000467 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000468 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000469 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000470 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000471 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000472 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000473 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000474 else if (Features[Mips::FeatureMips32r2] ||
475 Features[Mips::FeatureMips32r3] ||
476 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000477 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000478 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000479 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000480 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000481 EFlags |= ELF::EF_MIPS_ARCH_2;
482 else
483 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000484
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000485 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000486 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000487 EFlags |= ELF::EF_MIPS_NAN2008;
488
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000489 // -mabicalls and -mplt are not implemented but we should act as if they were
490 // given.
491 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000492
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000493 MCA.setELFHeaderEFlags(EFlags);
494}
Jack Carter86ac5c12013-11-18 23:55:27 +0000495
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000496void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
497 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000498 if (!isMicroMipsEnabled())
499 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000500 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000501 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000502 if (Type != ELF::STT_FUNC)
503 return;
504
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000505 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000506}
507
Rafael Espindola972e71a2014-01-31 23:10:26 +0000508void MipsTargetELFStreamer::finish() {
509 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000510 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000511
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000512 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000513 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000514 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000515 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000516 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000517 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000518 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000519
Rafael Espindola967d6a62015-05-21 21:02:35 +0000520 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
521 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
522 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000523
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000524 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000525
526 // Update e_header flags. See the FIXME and comment above in
527 // the constructor for a full rundown on this.
528 unsigned EFlags = MCA.getELFHeaderEFlags();
529
530 // ABI
531 // N64 does not require any ABI bits.
532 if (getABI().IsO32())
533 EFlags |= ELF::EF_MIPS_ABI_O32;
534 else if (getABI().IsN32())
535 EFlags |= ELF::EF_MIPS_ABI2;
536
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000537 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000538 if (getABI().IsO32())
539 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000540 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000541 EFlags |= ELF::EF_MIPS_32BITMODE;
542
543 // If we've set the cpic eflag and we're n64, go ahead and set the pic
544 // one as well.
545 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
546 EFlags |= ELF::EF_MIPS_PIC;
547
548 MCA.setELFHeaderEFlags(EFlags);
549
Daniel Sanders68c37472014-07-21 13:30:55 +0000550 // Emit all the option records.
551 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
552 // .reginfo.
553 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
554 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000555
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000556 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000557}
558
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000559void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
560 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000561 // If on rhs is micromips symbol then mark Symbol as microMips.
562 if (Value->getKind() != MCExpr::SymbolRef)
563 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000564 const auto &RhsSym = cast<MCSymbolELF>(
565 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000566
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000567 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000568 return;
569
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000570 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000571}
572
Jack Carter86ac5c12013-11-18 23:55:27 +0000573MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000574 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000575}
576
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000577void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
578 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000579
580 MCAssembler &MCA = getStreamer().getAssembler();
581 unsigned Flags = MCA.getELFHeaderEFlags();
582 Flags |= ELF::EF_MIPS_MICROMIPS;
583 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000584 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000585}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000586
587void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
588 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000589 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000590}
591
Rafael Espindola6633d572014-01-14 18:57:12 +0000592void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000593 MCAssembler &MCA = getStreamer().getAssembler();
594 unsigned Flags = MCA.getELFHeaderEFlags();
595 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
596 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000597 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000598}
599
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000600void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000601 MCAssembler &MCA = getStreamer().getAssembler();
602 unsigned Flags = MCA.getELFHeaderEFlags();
603 Flags |= ELF::EF_MIPS_NOREORDER;
604 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000605 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000606}
607
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000608void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000609 MCAssembler &MCA = getStreamer().getAssembler();
610 MCContext &Context = MCA.getContext();
611 MCStreamer &OS = getStreamer();
612
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000613 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
614 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000615
616 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000617 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000618
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000619 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000620 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000621
622 OS.PushSection();
623
624 OS.SwitchSection(Sec);
625
626 OS.EmitValueImpl(ExprRef, 4);
627
628 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
629 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
630
631 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
632 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
633
634 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
635 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
636 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
637
638 // The .end directive marks the end of a procedure. Invalidate
639 // the information gathered up until this point.
640 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
641
642 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000643}
644
Rafael Espindola6633d572014-01-14 18:57:12 +0000645void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000646 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000647}
648
Jack Carter0cd3c192014-01-06 23:27:31 +0000649void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
650 MCAssembler &MCA = getStreamer().getAssembler();
651 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000652 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000653 MCA.setELFHeaderEFlags(Flags);
654}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000655
656void MipsTargetELFStreamer::emitDirectiveNaN2008() {
657 MCAssembler &MCA = getStreamer().getAssembler();
658 unsigned Flags = MCA.getELFHeaderEFlags();
659 Flags |= ELF::EF_MIPS_NAN2008;
660 MCA.setELFHeaderEFlags(Flags);
661}
662
663void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
664 MCAssembler &MCA = getStreamer().getAssembler();
665 unsigned Flags = MCA.getELFHeaderEFlags();
666 Flags &= ~ELF::EF_MIPS_NAN2008;
667 MCA.setELFHeaderEFlags(Flags);
668}
669
Jack Carter0cd3c192014-01-06 23:27:31 +0000670void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
671 MCAssembler &MCA = getStreamer().getAssembler();
672 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000673 // This option overrides other PIC options like -KPIC.
674 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000675 Flags &= ~ELF::EF_MIPS_PIC;
676 MCA.setELFHeaderEFlags(Flags);
677}
Rafael Espindola054234f2014-01-27 03:53:56 +0000678
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000679void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
680 MCAssembler &MCA = getStreamer().getAssembler();
681 unsigned Flags = MCA.getELFHeaderEFlags();
682 Pic = true;
683 // NOTE: We are following the GAS behaviour here which means the directive
684 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
685 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
686 // EF_MIPS_CPIC to be mutually exclusive.
687 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
688 MCA.setELFHeaderEFlags(Flags);
689}
690
Toma Tabacu9ca50962015-04-16 09:53:47 +0000691void MipsTargetELFStreamer::emitDirectiveInsn() {
692 MipsTargetStreamer::emitDirectiveInsn();
693 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
694 MEF.createPendingLabelRelocs();
695}
696
Rafael Espindola054234f2014-01-27 03:53:56 +0000697void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000698 unsigned ReturnReg_) {
699 MCContext &Context = getStreamer().getAssembler().getContext();
700 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
701
702 FrameInfoSet = true;
703 FrameReg = RegInfo->getEncodingValue(StackReg);
704 FrameOffset = StackSize;
705 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000706}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000707
708void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
709 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000710 GPRInfoSet = true;
711 GPRBitMask = CPUBitmask;
712 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000713}
714
715void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
716 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000717 FPRInfoSet = true;
718 FPRBitMask = FPUBitmask;
719 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000720}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000721
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000722void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000723 // .cpload $reg
724 // This directive expands to:
725 // lui $gp, %hi(_gp_disp)
726 // addui $gp, $gp, %lo(_gp_disp)
727 // addu $gp, $gp, $reg
728 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000729 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000730 return;
731
732 // There's a GNU extension controlled by -mno-shared that allows
733 // locally-binding symbols to be accessed using absolute addresses.
734 // This is currently not supported. When supported -mno-shared makes
735 // .cpload expand to:
736 // lui $gp, %hi(__gnu_local_gp)
737 // addiu $gp, $gp, %lo(__gnu_local_gp)
738
739 StringRef SymName("_gp_disp");
740 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000741 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000742 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000743
744 MCInst TmpInst;
745 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000746 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000747 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000748 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000749 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000750 getStreamer().EmitInstruction(TmpInst, STI);
751
752 TmpInst.clear();
753
754 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000755 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
756 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000757 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000758 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000759 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000760 getStreamer().EmitInstruction(TmpInst, STI);
761
762 TmpInst.clear();
763
764 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000765 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
766 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
767 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000768 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000769
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000770 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000771}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000772
Daniel Sanderse2982ad2015-09-17 16:08:39 +0000773void MipsTargetELFStreamer::emitDirectiveCpRestore(
774 SmallVector<MCInst, 3> &StoreInsts, int Offset) {
775 MipsTargetStreamer::emitDirectiveCpRestore(StoreInsts, Offset);
776 // .cprestore offset
777 // When PIC mode is enabled and the O32 ABI is used, this directive expands
778 // to:
779 // sw $gp, offset($sp)
780 // and adds a corresponding LW after every JAL.
781
782 // Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it
783 // is used in non-PIC mode.
784 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
785 return;
786
787 for (const MCInst &Inst : StoreInsts)
788 getStreamer().EmitInstruction(Inst, STI);
789}
790
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000791void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
792 int RegOrOffset,
793 const MCSymbol &Sym,
794 bool IsReg) {
795 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000796 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000797 return;
798
799 MCAssembler &MCA = getStreamer().getAssembler();
800 MCInst Inst;
801
802 // Either store the old $gp in a register or on the stack
803 if (IsReg) {
804 // move $save, $gpreg
Vasileios Kalintiris1c78ca62015-08-11 08:56:25 +0000805 Inst.setOpcode(Mips::OR64);
Jim Grosbache9119e42015-05-13 18:37:00 +0000806 Inst.addOperand(MCOperand::createReg(RegOrOffset));
807 Inst.addOperand(MCOperand::createReg(Mips::GP));
808 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000809 } else {
810 // sd $gpreg, offset($sp)
811 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000812 Inst.addOperand(MCOperand::createReg(Mips::GP));
813 Inst.addOperand(MCOperand::createReg(Mips::SP));
814 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000815 }
816 getStreamer().EmitInstruction(Inst, STI);
817 Inst.clear();
818
Jim Grosbach13760bd2015-05-30 01:25:56 +0000819 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000820 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000821 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000822 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
823
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000824 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
825 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000826 Inst.addOperand(MCOperand::createReg(Mips::GP));
827 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000828 getStreamer().EmitInstruction(Inst, STI);
829 Inst.clear();
830
831 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
832 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000833 Inst.addOperand(MCOperand::createReg(Mips::GP));
834 Inst.addOperand(MCOperand::createReg(Mips::GP));
835 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000836 getStreamer().EmitInstruction(Inst, STI);
837 Inst.clear();
838
839 // daddu $gp, $gp, $funcreg
840 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000841 Inst.addOperand(MCOperand::createReg(Mips::GP));
842 Inst.addOperand(MCOperand::createReg(Mips::GP));
843 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000844 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000845
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000846 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000847}
848
Daniel Sandersf173dda2015-09-22 10:50:09 +0000849void MipsTargetELFStreamer::emitDirectiveCpreturn(unsigned SaveLocation,
850 bool SaveLocationIsRegister) {
851 // Only N32 and N64 emit anything for .cpreturn iff PIC is set.
852 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
853 return;
854
855 MCInst Inst;
856 // Either restore the old $gp from a register or on the stack
857 if (SaveLocationIsRegister) {
858 Inst.setOpcode(Mips::OR);
859 Inst.addOperand(MCOperand::createReg(Mips::GP));
860 Inst.addOperand(MCOperand::createReg(SaveLocation));
861 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
862 } else {
863 Inst.setOpcode(Mips::LD);
864 Inst.addOperand(MCOperand::createReg(Mips::GP));
865 Inst.addOperand(MCOperand::createReg(Mips::SP));
866 Inst.addOperand(MCOperand::createImm(SaveLocation));
867 }
868 getStreamer().EmitInstruction(Inst, STI);
869
870 forbidModuleDirective();
871}
872
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000873void MipsTargetELFStreamer::emitMipsAbiFlags() {
874 MCAssembler &MCA = getStreamer().getAssembler();
875 MCContext &Context = MCA.getContext();
876 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000877 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000878 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000879 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000880 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000881 OS.SwitchSection(Sec);
882
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000883 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000884}