blob: e4da2df75d477f81ba3444ef0137055edb7428fa [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) {}
Rafael Espindola60890b82014-06-23 19:43:40 +000092void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
93 const MCSymbol &Sym, bool IsReg) {
94}
Toma Tabacubfcbfd52015-06-23 12:34:19 +000095
Toma Tabacua64e5402015-06-25 12:44:38 +000096void MipsTargetStreamer::emitDirectiveModuleFP() {}
Toma Tabacubfcbfd52015-06-23 12:34:19 +000097
Toma Tabacu3c499582015-06-25 10:56:57 +000098void MipsTargetStreamer::emitDirectiveModuleOddSPReg() {
99 if (!ABIFlagsSection.OddSPReg && !ABIFlagsSection.Is32BitABI)
Daniel Sanders7e527422014-07-10 13:38:23 +0000100 report_fatal_error("+nooddspreg is only valid for O32");
101}
Toma Tabacu0f093132015-06-30 13:46:03 +0000102void MipsTargetStreamer::emitDirectiveModuleSoftFloat() {}
103void MipsTargetStreamer::emitDirectiveModuleHardFloat() {}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000104void MipsTargetStreamer::emitDirectiveSetFp(
105 MipsABIFlagsSection::FpABIKind Value) {
106 forbidModuleDirective();
107}
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000108void MipsTargetStreamer::emitDirectiveSetOddSPReg() { forbidModuleDirective(); }
109void MipsTargetStreamer::emitDirectiveSetNoOddSPReg() {
110 forbidModuleDirective();
111}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000112
113MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
114 formatted_raw_ostream &OS)
115 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000116
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000117void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
118 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000119 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000120}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000121
122void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
123 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000124 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000125}
126
Rafael Espindola6633d572014-01-14 18:57:12 +0000127void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
128 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000129 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000130}
131
132void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
133 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000134 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000135}
136
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000137void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
138 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000139 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000140}
141
142void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
143 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000144 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000145}
146
147void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
148 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000149 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000150}
151
152void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
153 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000154 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000155}
156
Daniel Sanders44934432014-08-07 12:03:36 +0000157void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
158 OS << "\t.set\tmsa\n";
159 MipsTargetStreamer::emitDirectiveSetMsa();
160}
161
162void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
163 OS << "\t.set\tnomsa\n";
164 MipsTargetStreamer::emitDirectiveSetNoMsa();
165}
166
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000167void MipsTargetAsmStreamer::emitDirectiveSetAt() {
168 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000169 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000170}
171
Toma Tabacu16a74492015-02-13 10:30:57 +0000172void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
173 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
174 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
175}
176
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000177void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
178 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000179 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000180}
181
182void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
183 OS << "\t.end\t" << Name << '\n';
184}
185
Rafael Espindola6633d572014-01-14 18:57:12 +0000186void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
187 OS << "\t.ent\t" << Symbol.getName() << '\n';
188}
189
Jack Carter0cd3c192014-01-06 23:27:31 +0000190void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000191
192void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
193
194void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
195 OS << "\t.nan\tlegacy\n";
196}
197
Jack Carter0cd3c192014-01-06 23:27:31 +0000198void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
199 OS << "\t.option\tpic0\n";
200}
201
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000202void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
203 OS << "\t.option\tpic2\n";
204}
205
Toma Tabacu9ca50962015-04-16 09:53:47 +0000206void MipsTargetAsmStreamer::emitDirectiveInsn() {
207 MipsTargetStreamer::emitDirectiveInsn();
208 OS << "\t.insn\n";
209}
210
Rafael Espindola054234f2014-01-27 03:53:56 +0000211void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
212 unsigned ReturnReg) {
213 OS << "\t.frame\t$"
214 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
215 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000216 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
217}
218
Toma Tabacu85618b32014-08-19 14:22:52 +0000219void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
220 OS << "\t.set arch=" << Arch << "\n";
221 MipsTargetStreamer::emitDirectiveSetArch(Arch);
222}
223
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000224void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
225 OS << "\t.set\tmips0\n";
226 MipsTargetStreamer::emitDirectiveSetMips0();
227}
Toma Tabacu26647792014-09-09 12:52:14 +0000228
Daniel Sandersf0df2212014-08-04 12:20:00 +0000229void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
230 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000231 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000232}
233
234void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
235 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000236 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000237}
238
239void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
240 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000241 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000242}
243
244void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
245 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000246 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000247}
248
249void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
250 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000251 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000252}
253
254void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
255 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000256 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000257}
258
Vladimir Medic615b26e2014-03-04 09:54:09 +0000259void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
260 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000261 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000262}
263
Daniel Sanders17793142015-02-18 16:24:50 +0000264void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
265 OS << "\t.set\tmips32r3\n";
266 MipsTargetStreamer::emitDirectiveSetMips32R3();
267}
268
269void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
270 OS << "\t.set\tmips32r5\n";
271 MipsTargetStreamer::emitDirectiveSetMips32R5();
272}
273
Daniel Sandersf0df2212014-08-04 12:20:00 +0000274void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
275 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000276 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000277}
278
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000279void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
280 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000281 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000282}
283
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000284void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
285 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000286 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000287}
288
Daniel Sanders17793142015-02-18 16:24:50 +0000289void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
290 OS << "\t.set\tmips64r3\n";
291 MipsTargetStreamer::emitDirectiveSetMips64R3();
292}
293
294void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
295 OS << "\t.set\tmips64r5\n";
296 MipsTargetStreamer::emitDirectiveSetMips64R5();
297}
298
Daniel Sandersf0df2212014-08-04 12:20:00 +0000299void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
300 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000301 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000302}
303
Vladimir Medic27c398e2014-03-05 11:05:09 +0000304void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
305 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000306 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000307}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000308
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000309void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
310 OS << "\t.set\tnodsp\n";
311 MipsTargetStreamer::emitDirectiveSetNoDsp();
312}
313
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000314void MipsTargetAsmStreamer::emitDirectiveSetPop() {
315 OS << "\t.set\tpop\n";
316 MipsTargetStreamer::emitDirectiveSetPop();
317}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000318
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000319void MipsTargetAsmStreamer::emitDirectiveSetPush() {
320 OS << "\t.set\tpush\n";
321 MipsTargetStreamer::emitDirectiveSetPush();
322}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000323
Toma Tabacu29696502015-06-02 09:48:04 +0000324void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
325 OS << "\t.set\tsoftfloat\n";
326 MipsTargetStreamer::emitDirectiveSetSoftFloat();
327}
328
329void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
330 OS << "\t.set\thardfloat\n";
331 MipsTargetStreamer::emitDirectiveSetHardFloat();
332}
333
Rafael Espindola25fa2912014-01-27 04:33:11 +0000334// Print a 32 bit hex number with all numbers.
335static void printHex32(unsigned Value, raw_ostream &OS) {
336 OS << "0x";
337 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000338 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000339}
340
341void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
342 int CPUTopSavedRegOff) {
343 OS << "\t.mask \t";
344 printHex32(CPUBitmask, OS);
345 OS << ',' << CPUTopSavedRegOff << '\n';
346}
347
348void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
349 int FPUTopSavedRegOff) {
350 OS << "\t.fmask\t";
351 printHex32(FPUBitmask, OS);
352 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000353}
354
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000355void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000356 OS << "\t.cpload\t$"
357 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000358 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000359}
360
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000361void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
362 int RegOrOffset,
363 const MCSymbol &Sym,
364 bool IsReg) {
365 OS << "\t.cpsetup\t$"
366 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
367
368 if (IsReg)
369 OS << "$"
370 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
371 else
372 OS << RegOrOffset;
373
374 OS << ", ";
375
376 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000377 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000378}
379
Toma Tabacua64e5402015-06-25 12:44:38 +0000380void MipsTargetAsmStreamer::emitDirectiveModuleFP() {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000381 OS << "\t.module\tfp=";
Toma Tabacua64e5402015-06-25 12:44:38 +0000382 OS << ABIFlagsSection.getFpABIString(ABIFlagsSection.getFpABI()) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000383}
384
Daniel Sanders7e527422014-07-10 13:38:23 +0000385void MipsTargetAsmStreamer::emitDirectiveSetFp(
386 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000387 MipsTargetStreamer::emitDirectiveSetFp(Value);
388
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000389 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000390 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000391}
392
Toma Tabacu3c499582015-06-25 10:56:57 +0000393void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() {
394 MipsTargetStreamer::emitDirectiveModuleOddSPReg();
Daniel Sanders7e527422014-07-10 13:38:23 +0000395
Toma Tabacu3c499582015-06-25 10:56:57 +0000396 OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
Daniel Sanders7e527422014-07-10 13:38:23 +0000397}
398
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000399void MipsTargetAsmStreamer::emitDirectiveSetOddSPReg() {
400 MipsTargetStreamer::emitDirectiveSetOddSPReg();
401 OS << "\t.set\toddspreg\n";
402}
403
404void MipsTargetAsmStreamer::emitDirectiveSetNoOddSPReg() {
405 MipsTargetStreamer::emitDirectiveSetNoOddSPReg();
406 OS << "\t.set\tnooddspreg\n";
407}
408
Toma Tabacu0f093132015-06-30 13:46:03 +0000409void MipsTargetAsmStreamer::emitDirectiveModuleSoftFloat() {
410 OS << "\t.module\tsoftfloat\n";
411}
412
413void MipsTargetAsmStreamer::emitDirectiveModuleHardFloat() {
414 OS << "\t.module\thardfloat\n";
415}
416
Jack Carter0cd3c192014-01-06 23:27:31 +0000417// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000418MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
419 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000420 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000421 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000422 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000423
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000424 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000425
426 // Set the header flags that we can in the constructor.
427 // FIXME: This is a fairly terrible hack. We set the rest
428 // of these in the destructor. The problem here is two-fold:
429 //
430 // a: Some of the eflags can be set/reset by directives.
431 // b: There aren't any usage paths that initialize the ABI
432 // pointer until after we initialize either an assembler
433 // or the target machine.
434 // We can fix this by making the target streamer construct
435 // the ABI, but this is fraught with wide ranging dependency
436 // issues as well.
437 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000438
439 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000440 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000441 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000442 else if (Features[Mips::FeatureMips64r2] ||
443 Features[Mips::FeatureMips64r3] ||
444 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000445 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000446 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000447 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000448 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000449 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000450 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000451 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000452 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000453 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000454 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000455 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000456 else if (Features[Mips::FeatureMips32r2] ||
457 Features[Mips::FeatureMips32r3] ||
458 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000459 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000460 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000461 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000462 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000463 EFlags |= ELF::EF_MIPS_ARCH_2;
464 else
465 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000466
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000467 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000468 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000469 EFlags |= ELF::EF_MIPS_NAN2008;
470
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000471 // -mabicalls and -mplt are not implemented but we should act as if they were
472 // given.
473 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000474
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000475 MCA.setELFHeaderEFlags(EFlags);
476}
Jack Carter86ac5c12013-11-18 23:55:27 +0000477
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000478void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
479 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000480 if (!isMicroMipsEnabled())
481 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000482 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000483 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000484 if (Type != ELF::STT_FUNC)
485 return;
486
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000487 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000488}
489
Rafael Espindola972e71a2014-01-31 23:10:26 +0000490void MipsTargetELFStreamer::finish() {
491 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000492 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000493
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000494 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000495 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000496 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000497 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000498 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000499 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000500 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000501
Rafael Espindola967d6a62015-05-21 21:02:35 +0000502 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
503 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
504 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000505
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000506 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000507
508 // Update e_header flags. See the FIXME and comment above in
509 // the constructor for a full rundown on this.
510 unsigned EFlags = MCA.getELFHeaderEFlags();
511
512 // ABI
513 // N64 does not require any ABI bits.
514 if (getABI().IsO32())
515 EFlags |= ELF::EF_MIPS_ABI_O32;
516 else if (getABI().IsN32())
517 EFlags |= ELF::EF_MIPS_ABI2;
518
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000519 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000520 if (getABI().IsO32())
521 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000522 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000523 EFlags |= ELF::EF_MIPS_32BITMODE;
524
525 // If we've set the cpic eflag and we're n64, go ahead and set the pic
526 // one as well.
527 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
528 EFlags |= ELF::EF_MIPS_PIC;
529
530 MCA.setELFHeaderEFlags(EFlags);
531
Daniel Sanders68c37472014-07-21 13:30:55 +0000532 // Emit all the option records.
533 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
534 // .reginfo.
535 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
536 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000537
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000538 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000539}
540
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000541void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
542 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000543 // If on rhs is micromips symbol then mark Symbol as microMips.
544 if (Value->getKind() != MCExpr::SymbolRef)
545 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000546 const auto &RhsSym = cast<MCSymbolELF>(
547 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000548
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000549 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000550 return;
551
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000552 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000553}
554
Jack Carter86ac5c12013-11-18 23:55:27 +0000555MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000556 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000557}
558
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000559void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
560 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000561
562 MCAssembler &MCA = getStreamer().getAssembler();
563 unsigned Flags = MCA.getELFHeaderEFlags();
564 Flags |= ELF::EF_MIPS_MICROMIPS;
565 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000566 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000567}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000568
569void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
570 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000571 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000572}
573
Rafael Espindola6633d572014-01-14 18:57:12 +0000574void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000575 MCAssembler &MCA = getStreamer().getAssembler();
576 unsigned Flags = MCA.getELFHeaderEFlags();
577 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
578 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000579 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000580}
581
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000582void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000583 MCAssembler &MCA = getStreamer().getAssembler();
584 unsigned Flags = MCA.getELFHeaderEFlags();
585 Flags |= ELF::EF_MIPS_NOREORDER;
586 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000587 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000588}
589
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000590void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000591 MCAssembler &MCA = getStreamer().getAssembler();
592 MCContext &Context = MCA.getContext();
593 MCStreamer &OS = getStreamer();
594
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000595 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
596 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000597
598 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000599 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000600
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000601 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000602 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000603
604 OS.PushSection();
605
606 OS.SwitchSection(Sec);
607
608 OS.EmitValueImpl(ExprRef, 4);
609
610 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
611 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
612
613 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
614 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
615
616 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
617 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
618 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
619
620 // The .end directive marks the end of a procedure. Invalidate
621 // the information gathered up until this point.
622 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
623
624 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000625}
626
Rafael Espindola6633d572014-01-14 18:57:12 +0000627void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000628 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000629}
630
Jack Carter0cd3c192014-01-06 23:27:31 +0000631void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
632 MCAssembler &MCA = getStreamer().getAssembler();
633 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000634 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000635 MCA.setELFHeaderEFlags(Flags);
636}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000637
638void MipsTargetELFStreamer::emitDirectiveNaN2008() {
639 MCAssembler &MCA = getStreamer().getAssembler();
640 unsigned Flags = MCA.getELFHeaderEFlags();
641 Flags |= ELF::EF_MIPS_NAN2008;
642 MCA.setELFHeaderEFlags(Flags);
643}
644
645void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
646 MCAssembler &MCA = getStreamer().getAssembler();
647 unsigned Flags = MCA.getELFHeaderEFlags();
648 Flags &= ~ELF::EF_MIPS_NAN2008;
649 MCA.setELFHeaderEFlags(Flags);
650}
651
Jack Carter0cd3c192014-01-06 23:27:31 +0000652void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
653 MCAssembler &MCA = getStreamer().getAssembler();
654 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000655 // This option overrides other PIC options like -KPIC.
656 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000657 Flags &= ~ELF::EF_MIPS_PIC;
658 MCA.setELFHeaderEFlags(Flags);
659}
Rafael Espindola054234f2014-01-27 03:53:56 +0000660
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000661void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
662 MCAssembler &MCA = getStreamer().getAssembler();
663 unsigned Flags = MCA.getELFHeaderEFlags();
664 Pic = true;
665 // NOTE: We are following the GAS behaviour here which means the directive
666 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
667 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
668 // EF_MIPS_CPIC to be mutually exclusive.
669 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
670 MCA.setELFHeaderEFlags(Flags);
671}
672
Toma Tabacu9ca50962015-04-16 09:53:47 +0000673void MipsTargetELFStreamer::emitDirectiveInsn() {
674 MipsTargetStreamer::emitDirectiveInsn();
675 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
676 MEF.createPendingLabelRelocs();
677}
678
Rafael Espindola054234f2014-01-27 03:53:56 +0000679void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000680 unsigned ReturnReg_) {
681 MCContext &Context = getStreamer().getAssembler().getContext();
682 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
683
684 FrameInfoSet = true;
685 FrameReg = RegInfo->getEncodingValue(StackReg);
686 FrameOffset = StackSize;
687 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000688}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000689
690void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
691 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000692 GPRInfoSet = true;
693 GPRBitMask = CPUBitmask;
694 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000695}
696
697void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
698 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000699 FPRInfoSet = true;
700 FPRBitMask = FPUBitmask;
701 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000702}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000703
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000704void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000705 // .cpload $reg
706 // This directive expands to:
707 // lui $gp, %hi(_gp_disp)
708 // addui $gp, $gp, %lo(_gp_disp)
709 // addu $gp, $gp, $reg
710 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000711 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000712 return;
713
714 // There's a GNU extension controlled by -mno-shared that allows
715 // locally-binding symbols to be accessed using absolute addresses.
716 // This is currently not supported. When supported -mno-shared makes
717 // .cpload expand to:
718 // lui $gp, %hi(__gnu_local_gp)
719 // addiu $gp, $gp, %lo(__gnu_local_gp)
720
721 StringRef SymName("_gp_disp");
722 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000723 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000724 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000725
726 MCInst TmpInst;
727 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000728 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000729 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000730 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000731 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000732 getStreamer().EmitInstruction(TmpInst, STI);
733
734 TmpInst.clear();
735
736 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000737 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
738 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000739 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000740 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000741 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000742 getStreamer().EmitInstruction(TmpInst, STI);
743
744 TmpInst.clear();
745
746 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000747 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
748 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
749 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000750 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000751
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000752 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000753}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000754
755void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
756 int RegOrOffset,
757 const MCSymbol &Sym,
758 bool IsReg) {
759 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000760 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000761 return;
762
763 MCAssembler &MCA = getStreamer().getAssembler();
764 MCInst Inst;
765
766 // Either store the old $gp in a register or on the stack
767 if (IsReg) {
768 // move $save, $gpreg
769 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000770 Inst.addOperand(MCOperand::createReg(RegOrOffset));
771 Inst.addOperand(MCOperand::createReg(Mips::GP));
772 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000773 } else {
774 // sd $gpreg, offset($sp)
775 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000776 Inst.addOperand(MCOperand::createReg(Mips::GP));
777 Inst.addOperand(MCOperand::createReg(Mips::SP));
778 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000779 }
780 getStreamer().EmitInstruction(Inst, STI);
781 Inst.clear();
782
Jim Grosbach13760bd2015-05-30 01:25:56 +0000783 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000784 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000785 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000786 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
787
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000788 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
789 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000790 Inst.addOperand(MCOperand::createReg(Mips::GP));
791 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000792 getStreamer().EmitInstruction(Inst, STI);
793 Inst.clear();
794
795 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
796 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000797 Inst.addOperand(MCOperand::createReg(Mips::GP));
798 Inst.addOperand(MCOperand::createReg(Mips::GP));
799 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000800 getStreamer().EmitInstruction(Inst, STI);
801 Inst.clear();
802
803 // daddu $gp, $gp, $funcreg
804 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000805 Inst.addOperand(MCOperand::createReg(Mips::GP));
806 Inst.addOperand(MCOperand::createReg(Mips::GP));
807 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000808 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000809
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000810 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000811}
812
813void MipsTargetELFStreamer::emitMipsAbiFlags() {
814 MCAssembler &MCA = getStreamer().getAssembler();
815 MCContext &Context = MCA.getContext();
816 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000817 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000818 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000819 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000820 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000821 OS.SwitchSection(Sec);
822
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000823 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000824}