blob: e5fa7556053f96944c8e4eb5a55eac925feac477 [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,
Scott Egerton2c2a2f52016-02-15 10:04:38 +0000614 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000615
Daniel Sanders2b561332015-11-23 16:08:03 +0000616 MCSymbol *Sym = Context.getOrCreateSymbol(Name);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000617 const MCSymbolRefExpr *ExprRef =
Daniel Sanders2b561332015-11-23 16:08:03 +0000618 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000619
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000620 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000621 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000622
623 OS.PushSection();
624
625 OS.SwitchSection(Sec);
626
627 OS.EmitValueImpl(ExprRef, 4);
628
629 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
630 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
631
632 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
633 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
634
635 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
636 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
637 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
638
639 // The .end directive marks the end of a procedure. Invalidate
640 // the information gathered up until this point.
641 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
642
643 OS.PopSection();
Daniel Sanders2b561332015-11-23 16:08:03 +0000644
645 // .end also implicitly sets the size.
646 MCSymbol *CurPCSym = Context.createTempSymbol();
647 OS.EmitLabel(CurPCSym);
648 const MCExpr *Size = MCBinaryExpr::createSub(
649 MCSymbolRefExpr::create(CurPCSym, MCSymbolRefExpr::VK_None, Context),
650 ExprRef, Context);
651 int64_t AbsSize;
652 if (!Size->evaluateAsAbsolute(AbsSize, MCA))
653 llvm_unreachable("Function size must be evaluatable as absolute");
654 Size = MCConstantExpr::create(AbsSize, Context);
655 static_cast<MCSymbolELF *>(Sym)->setSize(Size);
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000656}
657
Rafael Espindola6633d572014-01-14 18:57:12 +0000658void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000659 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Daniel Sanders2b561332015-11-23 16:08:03 +0000660
661 // .ent also acts like an implicit '.type symbol, STT_FUNC'
662 static_cast<const MCSymbolELF &>(Symbol).setType(ELF::STT_FUNC);
Rafael Espindola6633d572014-01-14 18:57:12 +0000663}
664
Jack Carter0cd3c192014-01-06 23:27:31 +0000665void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
666 MCAssembler &MCA = getStreamer().getAssembler();
667 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000668 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000669 MCA.setELFHeaderEFlags(Flags);
670}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000671
672void MipsTargetELFStreamer::emitDirectiveNaN2008() {
673 MCAssembler &MCA = getStreamer().getAssembler();
674 unsigned Flags = MCA.getELFHeaderEFlags();
675 Flags |= ELF::EF_MIPS_NAN2008;
676 MCA.setELFHeaderEFlags(Flags);
677}
678
679void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
680 MCAssembler &MCA = getStreamer().getAssembler();
681 unsigned Flags = MCA.getELFHeaderEFlags();
682 Flags &= ~ELF::EF_MIPS_NAN2008;
683 MCA.setELFHeaderEFlags(Flags);
684}
685
Jack Carter0cd3c192014-01-06 23:27:31 +0000686void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
687 MCAssembler &MCA = getStreamer().getAssembler();
688 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000689 // This option overrides other PIC options like -KPIC.
690 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000691 Flags &= ~ELF::EF_MIPS_PIC;
692 MCA.setELFHeaderEFlags(Flags);
693}
Rafael Espindola054234f2014-01-27 03:53:56 +0000694
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000695void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
696 MCAssembler &MCA = getStreamer().getAssembler();
697 unsigned Flags = MCA.getELFHeaderEFlags();
698 Pic = true;
699 // NOTE: We are following the GAS behaviour here which means the directive
700 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
701 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
702 // EF_MIPS_CPIC to be mutually exclusive.
703 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
704 MCA.setELFHeaderEFlags(Flags);
705}
706
Toma Tabacu9ca50962015-04-16 09:53:47 +0000707void MipsTargetELFStreamer::emitDirectiveInsn() {
708 MipsTargetStreamer::emitDirectiveInsn();
709 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
710 MEF.createPendingLabelRelocs();
711}
712
Rafael Espindola054234f2014-01-27 03:53:56 +0000713void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000714 unsigned ReturnReg_) {
715 MCContext &Context = getStreamer().getAssembler().getContext();
716 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
717
718 FrameInfoSet = true;
719 FrameReg = RegInfo->getEncodingValue(StackReg);
720 FrameOffset = StackSize;
721 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000722}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000723
724void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
725 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000726 GPRInfoSet = true;
727 GPRBitMask = CPUBitmask;
728 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000729}
730
731void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
732 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000733 FPRInfoSet = true;
734 FPRBitMask = FPUBitmask;
735 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000736}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000737
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000738void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000739 // .cpload $reg
740 // This directive expands to:
741 // lui $gp, %hi(_gp_disp)
742 // addui $gp, $gp, %lo(_gp_disp)
743 // addu $gp, $gp, $reg
744 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000745 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000746 return;
747
748 // There's a GNU extension controlled by -mno-shared that allows
749 // locally-binding symbols to be accessed using absolute addresses.
750 // This is currently not supported. When supported -mno-shared makes
751 // .cpload expand to:
752 // lui $gp, %hi(__gnu_local_gp)
753 // addiu $gp, $gp, %lo(__gnu_local_gp)
754
755 StringRef SymName("_gp_disp");
756 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000757 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000758 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000759
760 MCInst TmpInst;
761 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000762 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000763 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000764 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000765 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000766 getStreamer().EmitInstruction(TmpInst, STI);
767
768 TmpInst.clear();
769
770 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000771 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
772 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000773 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000774 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000775 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000776 getStreamer().EmitInstruction(TmpInst, STI);
777
778 TmpInst.clear();
779
780 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000781 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
782 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
783 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000784 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000785
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000786 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000787}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000788
Daniel Sanderse2982ad2015-09-17 16:08:39 +0000789void MipsTargetELFStreamer::emitDirectiveCpRestore(
790 SmallVector<MCInst, 3> &StoreInsts, int Offset) {
791 MipsTargetStreamer::emitDirectiveCpRestore(StoreInsts, Offset);
792 // .cprestore offset
793 // When PIC mode is enabled and the O32 ABI is used, this directive expands
794 // to:
795 // sw $gp, offset($sp)
796 // and adds a corresponding LW after every JAL.
797
798 // Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it
799 // is used in non-PIC mode.
800 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
801 return;
802
803 for (const MCInst &Inst : StoreInsts)
804 getStreamer().EmitInstruction(Inst, STI);
805}
806
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000807void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
808 int RegOrOffset,
809 const MCSymbol &Sym,
810 bool IsReg) {
811 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000812 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000813 return;
814
815 MCAssembler &MCA = getStreamer().getAssembler();
816 MCInst Inst;
817
818 // Either store the old $gp in a register or on the stack
819 if (IsReg) {
820 // move $save, $gpreg
Vasileios Kalintiris1c78ca62015-08-11 08:56:25 +0000821 Inst.setOpcode(Mips::OR64);
Jim Grosbache9119e42015-05-13 18:37:00 +0000822 Inst.addOperand(MCOperand::createReg(RegOrOffset));
823 Inst.addOperand(MCOperand::createReg(Mips::GP));
824 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000825 } else {
826 // sd $gpreg, offset($sp)
827 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000828 Inst.addOperand(MCOperand::createReg(Mips::GP));
829 Inst.addOperand(MCOperand::createReg(Mips::SP));
830 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000831 }
832 getStreamer().EmitInstruction(Inst, STI);
833 Inst.clear();
834
Jim Grosbach13760bd2015-05-30 01:25:56 +0000835 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000836 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000837 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000838 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
839
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000840 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
841 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000842 Inst.addOperand(MCOperand::createReg(Mips::GP));
843 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000844 getStreamer().EmitInstruction(Inst, STI);
845 Inst.clear();
846
847 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
848 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000849 Inst.addOperand(MCOperand::createReg(Mips::GP));
850 Inst.addOperand(MCOperand::createReg(Mips::GP));
851 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000852 getStreamer().EmitInstruction(Inst, STI);
853 Inst.clear();
854
855 // daddu $gp, $gp, $funcreg
856 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000857 Inst.addOperand(MCOperand::createReg(Mips::GP));
858 Inst.addOperand(MCOperand::createReg(Mips::GP));
859 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000860 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000861
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000862 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000863}
864
Daniel Sandersf173dda2015-09-22 10:50:09 +0000865void MipsTargetELFStreamer::emitDirectiveCpreturn(unsigned SaveLocation,
866 bool SaveLocationIsRegister) {
867 // Only N32 and N64 emit anything for .cpreturn iff PIC is set.
868 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
869 return;
870
871 MCInst Inst;
872 // Either restore the old $gp from a register or on the stack
873 if (SaveLocationIsRegister) {
874 Inst.setOpcode(Mips::OR);
875 Inst.addOperand(MCOperand::createReg(Mips::GP));
876 Inst.addOperand(MCOperand::createReg(SaveLocation));
877 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
878 } else {
879 Inst.setOpcode(Mips::LD);
880 Inst.addOperand(MCOperand::createReg(Mips::GP));
881 Inst.addOperand(MCOperand::createReg(Mips::SP));
882 Inst.addOperand(MCOperand::createImm(SaveLocation));
883 }
884 getStreamer().EmitInstruction(Inst, STI);
885
886 forbidModuleDirective();
887}
888
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000889void MipsTargetELFStreamer::emitMipsAbiFlags() {
890 MCAssembler &MCA = getStreamer().getAssembler();
891 MCContext &Context = MCA.getContext();
892 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000893 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000894 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000895 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000896 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000897 OS.SwitchSection(Sec);
898
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000899 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000900}