blob: 9ffa969095888b2043edeababb7ad4a2008b41b4 [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 Tabacu4e0cf8e2015-03-06 12:15:12 +0000102void MipsTargetStreamer::emitDirectiveSetFp(
103 MipsABIFlagsSection::FpABIKind Value) {
104 forbidModuleDirective();
105}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000106
107MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
108 formatted_raw_ostream &OS)
109 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000110
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000111void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
112 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000113 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000114}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000115
116void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
117 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000118 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000119}
120
Rafael Espindola6633d572014-01-14 18:57:12 +0000121void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
122 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000123 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000124}
125
126void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
127 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000128 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000129}
130
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000131void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
132 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000133 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000134}
135
136void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
137 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000138 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000139}
140
141void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
142 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000143 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000144}
145
146void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
147 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000148 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000149}
150
Daniel Sanders44934432014-08-07 12:03:36 +0000151void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
152 OS << "\t.set\tmsa\n";
153 MipsTargetStreamer::emitDirectiveSetMsa();
154}
155
156void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
157 OS << "\t.set\tnomsa\n";
158 MipsTargetStreamer::emitDirectiveSetNoMsa();
159}
160
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000161void MipsTargetAsmStreamer::emitDirectiveSetAt() {
162 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000163 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000164}
165
Toma Tabacu16a74492015-02-13 10:30:57 +0000166void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
167 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
168 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
169}
170
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000171void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
172 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000173 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000174}
175
176void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
177 OS << "\t.end\t" << Name << '\n';
178}
179
Rafael Espindola6633d572014-01-14 18:57:12 +0000180void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
181 OS << "\t.ent\t" << Symbol.getName() << '\n';
182}
183
Jack Carter0cd3c192014-01-06 23:27:31 +0000184void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000185
186void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
187
188void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
189 OS << "\t.nan\tlegacy\n";
190}
191
Jack Carter0cd3c192014-01-06 23:27:31 +0000192void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
193 OS << "\t.option\tpic0\n";
194}
195
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000196void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
197 OS << "\t.option\tpic2\n";
198}
199
Toma Tabacu9ca50962015-04-16 09:53:47 +0000200void MipsTargetAsmStreamer::emitDirectiveInsn() {
201 MipsTargetStreamer::emitDirectiveInsn();
202 OS << "\t.insn\n";
203}
204
Rafael Espindola054234f2014-01-27 03:53:56 +0000205void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
206 unsigned ReturnReg) {
207 OS << "\t.frame\t$"
208 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
209 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000210 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
211}
212
Toma Tabacu85618b32014-08-19 14:22:52 +0000213void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
214 OS << "\t.set arch=" << Arch << "\n";
215 MipsTargetStreamer::emitDirectiveSetArch(Arch);
216}
217
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000218void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
219 OS << "\t.set\tmips0\n";
220 MipsTargetStreamer::emitDirectiveSetMips0();
221}
Toma Tabacu26647792014-09-09 12:52:14 +0000222
Daniel Sandersf0df2212014-08-04 12:20:00 +0000223void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
224 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000225 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000226}
227
228void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
229 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000230 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000231}
232
233void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
234 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000235 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000236}
237
238void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
239 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000240 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000241}
242
243void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
244 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000245 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000246}
247
248void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
249 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000250 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000251}
252
Vladimir Medic615b26e2014-03-04 09:54:09 +0000253void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
254 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000255 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000256}
257
Daniel Sanders17793142015-02-18 16:24:50 +0000258void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
259 OS << "\t.set\tmips32r3\n";
260 MipsTargetStreamer::emitDirectiveSetMips32R3();
261}
262
263void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
264 OS << "\t.set\tmips32r5\n";
265 MipsTargetStreamer::emitDirectiveSetMips32R5();
266}
267
Daniel Sandersf0df2212014-08-04 12:20:00 +0000268void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
269 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000270 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000271}
272
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000273void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
274 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000275 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000276}
277
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000278void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
279 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000280 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000281}
282
Daniel Sanders17793142015-02-18 16:24:50 +0000283void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
284 OS << "\t.set\tmips64r3\n";
285 MipsTargetStreamer::emitDirectiveSetMips64R3();
286}
287
288void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
289 OS << "\t.set\tmips64r5\n";
290 MipsTargetStreamer::emitDirectiveSetMips64R5();
291}
292
Daniel Sandersf0df2212014-08-04 12:20:00 +0000293void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
294 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000295 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000296}
297
Vladimir Medic27c398e2014-03-05 11:05:09 +0000298void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
299 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000300 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000301}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000302
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000303void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
304 OS << "\t.set\tnodsp\n";
305 MipsTargetStreamer::emitDirectiveSetNoDsp();
306}
307
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000308void MipsTargetAsmStreamer::emitDirectiveSetPop() {
309 OS << "\t.set\tpop\n";
310 MipsTargetStreamer::emitDirectiveSetPop();
311}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000312
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000313void MipsTargetAsmStreamer::emitDirectiveSetPush() {
314 OS << "\t.set\tpush\n";
315 MipsTargetStreamer::emitDirectiveSetPush();
316}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000317
Toma Tabacu29696502015-06-02 09:48:04 +0000318void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
319 OS << "\t.set\tsoftfloat\n";
320 MipsTargetStreamer::emitDirectiveSetSoftFloat();
321}
322
323void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
324 OS << "\t.set\thardfloat\n";
325 MipsTargetStreamer::emitDirectiveSetHardFloat();
326}
327
Rafael Espindola25fa2912014-01-27 04:33:11 +0000328// Print a 32 bit hex number with all numbers.
329static void printHex32(unsigned Value, raw_ostream &OS) {
330 OS << "0x";
331 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000332 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000333}
334
335void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
336 int CPUTopSavedRegOff) {
337 OS << "\t.mask \t";
338 printHex32(CPUBitmask, OS);
339 OS << ',' << CPUTopSavedRegOff << '\n';
340}
341
342void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
343 int FPUTopSavedRegOff) {
344 OS << "\t.fmask\t";
345 printHex32(FPUBitmask, OS);
346 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000347}
348
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000349void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000350 OS << "\t.cpload\t$"
351 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000352 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000353}
354
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000355void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
356 int RegOrOffset,
357 const MCSymbol &Sym,
358 bool IsReg) {
359 OS << "\t.cpsetup\t$"
360 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
361
362 if (IsReg)
363 OS << "$"
364 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
365 else
366 OS << RegOrOffset;
367
368 OS << ", ";
369
370 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000371 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000372}
373
Toma Tabacua64e5402015-06-25 12:44:38 +0000374void MipsTargetAsmStreamer::emitDirectiveModuleFP() {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000375 OS << "\t.module\tfp=";
Toma Tabacua64e5402015-06-25 12:44:38 +0000376 OS << ABIFlagsSection.getFpABIString(ABIFlagsSection.getFpABI()) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000377}
378
Daniel Sanders7e527422014-07-10 13:38:23 +0000379void MipsTargetAsmStreamer::emitDirectiveSetFp(
380 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000381 MipsTargetStreamer::emitDirectiveSetFp(Value);
382
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000383 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000384 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000385}
386
Toma Tabacu3c499582015-06-25 10:56:57 +0000387void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() {
388 MipsTargetStreamer::emitDirectiveModuleOddSPReg();
Daniel Sanders7e527422014-07-10 13:38:23 +0000389
Toma Tabacu3c499582015-06-25 10:56:57 +0000390 OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
Daniel Sanders7e527422014-07-10 13:38:23 +0000391}
392
Jack Carter0cd3c192014-01-06 23:27:31 +0000393// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000394MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
395 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000396 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000397 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000398 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000399
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000400 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000401
402 // Set the header flags that we can in the constructor.
403 // FIXME: This is a fairly terrible hack. We set the rest
404 // of these in the destructor. The problem here is two-fold:
405 //
406 // a: Some of the eflags can be set/reset by directives.
407 // b: There aren't any usage paths that initialize the ABI
408 // pointer until after we initialize either an assembler
409 // or the target machine.
410 // We can fix this by making the target streamer construct
411 // the ABI, but this is fraught with wide ranging dependency
412 // issues as well.
413 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000414
415 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000416 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000417 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000418 else if (Features[Mips::FeatureMips64r2] ||
419 Features[Mips::FeatureMips64r3] ||
420 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000421 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000422 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000423 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000424 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000425 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000426 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000427 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000428 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000429 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000430 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000431 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000432 else if (Features[Mips::FeatureMips32r2] ||
433 Features[Mips::FeatureMips32r3] ||
434 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000435 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000436 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000437 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000438 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000439 EFlags |= ELF::EF_MIPS_ARCH_2;
440 else
441 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000442
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000443 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000444 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000445 EFlags |= ELF::EF_MIPS_NAN2008;
446
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000447 // -mabicalls and -mplt are not implemented but we should act as if they were
448 // given.
449 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000450
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000451 MCA.setELFHeaderEFlags(EFlags);
452}
Jack Carter86ac5c12013-11-18 23:55:27 +0000453
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000454void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
455 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000456 if (!isMicroMipsEnabled())
457 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000458 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000459 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000460 if (Type != ELF::STT_FUNC)
461 return;
462
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000463 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000464}
465
Rafael Espindola972e71a2014-01-31 23:10:26 +0000466void MipsTargetELFStreamer::finish() {
467 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000468 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000469
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000470 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000471 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000472 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000473 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000474 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000475 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000476 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000477
Rafael Espindola967d6a62015-05-21 21:02:35 +0000478 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
479 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
480 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000481
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000482 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000483
484 // Update e_header flags. See the FIXME and comment above in
485 // the constructor for a full rundown on this.
486 unsigned EFlags = MCA.getELFHeaderEFlags();
487
488 // ABI
489 // N64 does not require any ABI bits.
490 if (getABI().IsO32())
491 EFlags |= ELF::EF_MIPS_ABI_O32;
492 else if (getABI().IsN32())
493 EFlags |= ELF::EF_MIPS_ABI2;
494
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000495 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000496 if (getABI().IsO32())
497 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000498 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000499 EFlags |= ELF::EF_MIPS_32BITMODE;
500
501 // If we've set the cpic eflag and we're n64, go ahead and set the pic
502 // one as well.
503 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
504 EFlags |= ELF::EF_MIPS_PIC;
505
506 MCA.setELFHeaderEFlags(EFlags);
507
Daniel Sanders68c37472014-07-21 13:30:55 +0000508 // Emit all the option records.
509 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
510 // .reginfo.
511 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
512 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000513
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000514 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000515}
516
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000517void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
518 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000519 // If on rhs is micromips symbol then mark Symbol as microMips.
520 if (Value->getKind() != MCExpr::SymbolRef)
521 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000522 const auto &RhsSym = cast<MCSymbolELF>(
523 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000524
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000525 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000526 return;
527
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000528 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000529}
530
Jack Carter86ac5c12013-11-18 23:55:27 +0000531MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000532 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000533}
534
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000535void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
536 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000537
538 MCAssembler &MCA = getStreamer().getAssembler();
539 unsigned Flags = MCA.getELFHeaderEFlags();
540 Flags |= ELF::EF_MIPS_MICROMIPS;
541 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000542 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000543}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000544
545void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
546 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000547 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000548}
549
Rafael Espindola6633d572014-01-14 18:57:12 +0000550void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000551 MCAssembler &MCA = getStreamer().getAssembler();
552 unsigned Flags = MCA.getELFHeaderEFlags();
553 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
554 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000555 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000556}
557
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000558void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000559 MCAssembler &MCA = getStreamer().getAssembler();
560 unsigned Flags = MCA.getELFHeaderEFlags();
561 Flags |= ELF::EF_MIPS_NOREORDER;
562 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000563 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000564}
565
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000566void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000567 MCAssembler &MCA = getStreamer().getAssembler();
568 MCContext &Context = MCA.getContext();
569 MCStreamer &OS = getStreamer();
570
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000571 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
572 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000573
574 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000575 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000576
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000577 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000578 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000579
580 OS.PushSection();
581
582 OS.SwitchSection(Sec);
583
584 OS.EmitValueImpl(ExprRef, 4);
585
586 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
587 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
588
589 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
590 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
591
592 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
593 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
594 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
595
596 // The .end directive marks the end of a procedure. Invalidate
597 // the information gathered up until this point.
598 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
599
600 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000601}
602
Rafael Espindola6633d572014-01-14 18:57:12 +0000603void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000604 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000605}
606
Jack Carter0cd3c192014-01-06 23:27:31 +0000607void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
608 MCAssembler &MCA = getStreamer().getAssembler();
609 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000610 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000611 MCA.setELFHeaderEFlags(Flags);
612}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000613
614void MipsTargetELFStreamer::emitDirectiveNaN2008() {
615 MCAssembler &MCA = getStreamer().getAssembler();
616 unsigned Flags = MCA.getELFHeaderEFlags();
617 Flags |= ELF::EF_MIPS_NAN2008;
618 MCA.setELFHeaderEFlags(Flags);
619}
620
621void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
622 MCAssembler &MCA = getStreamer().getAssembler();
623 unsigned Flags = MCA.getELFHeaderEFlags();
624 Flags &= ~ELF::EF_MIPS_NAN2008;
625 MCA.setELFHeaderEFlags(Flags);
626}
627
Jack Carter0cd3c192014-01-06 23:27:31 +0000628void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
629 MCAssembler &MCA = getStreamer().getAssembler();
630 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000631 // This option overrides other PIC options like -KPIC.
632 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000633 Flags &= ~ELF::EF_MIPS_PIC;
634 MCA.setELFHeaderEFlags(Flags);
635}
Rafael Espindola054234f2014-01-27 03:53:56 +0000636
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000637void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
638 MCAssembler &MCA = getStreamer().getAssembler();
639 unsigned Flags = MCA.getELFHeaderEFlags();
640 Pic = true;
641 // NOTE: We are following the GAS behaviour here which means the directive
642 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
643 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
644 // EF_MIPS_CPIC to be mutually exclusive.
645 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
646 MCA.setELFHeaderEFlags(Flags);
647}
648
Toma Tabacu9ca50962015-04-16 09:53:47 +0000649void MipsTargetELFStreamer::emitDirectiveInsn() {
650 MipsTargetStreamer::emitDirectiveInsn();
651 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
652 MEF.createPendingLabelRelocs();
653}
654
Rafael Espindola054234f2014-01-27 03:53:56 +0000655void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000656 unsigned ReturnReg_) {
657 MCContext &Context = getStreamer().getAssembler().getContext();
658 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
659
660 FrameInfoSet = true;
661 FrameReg = RegInfo->getEncodingValue(StackReg);
662 FrameOffset = StackSize;
663 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000664}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000665
666void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
667 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000668 GPRInfoSet = true;
669 GPRBitMask = CPUBitmask;
670 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000671}
672
673void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
674 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000675 FPRInfoSet = true;
676 FPRBitMask = FPUBitmask;
677 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000678}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000679
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000680void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000681 // .cpload $reg
682 // This directive expands to:
683 // lui $gp, %hi(_gp_disp)
684 // addui $gp, $gp, %lo(_gp_disp)
685 // addu $gp, $gp, $reg
686 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000687 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000688 return;
689
690 // There's a GNU extension controlled by -mno-shared that allows
691 // locally-binding symbols to be accessed using absolute addresses.
692 // This is currently not supported. When supported -mno-shared makes
693 // .cpload expand to:
694 // lui $gp, %hi(__gnu_local_gp)
695 // addiu $gp, $gp, %lo(__gnu_local_gp)
696
697 StringRef SymName("_gp_disp");
698 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000699 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000700 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000701
702 MCInst TmpInst;
703 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000704 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000705 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000706 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000707 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000708 getStreamer().EmitInstruction(TmpInst, STI);
709
710 TmpInst.clear();
711
712 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000713 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
714 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000715 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000716 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000717 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000718 getStreamer().EmitInstruction(TmpInst, STI);
719
720 TmpInst.clear();
721
722 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000723 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
724 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
725 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000726 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000727
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000728 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000729}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000730
731void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
732 int RegOrOffset,
733 const MCSymbol &Sym,
734 bool IsReg) {
735 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000736 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000737 return;
738
739 MCAssembler &MCA = getStreamer().getAssembler();
740 MCInst Inst;
741
742 // Either store the old $gp in a register or on the stack
743 if (IsReg) {
744 // move $save, $gpreg
745 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000746 Inst.addOperand(MCOperand::createReg(RegOrOffset));
747 Inst.addOperand(MCOperand::createReg(Mips::GP));
748 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000749 } else {
750 // sd $gpreg, offset($sp)
751 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000752 Inst.addOperand(MCOperand::createReg(Mips::GP));
753 Inst.addOperand(MCOperand::createReg(Mips::SP));
754 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000755 }
756 getStreamer().EmitInstruction(Inst, STI);
757 Inst.clear();
758
Jim Grosbach13760bd2015-05-30 01:25:56 +0000759 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000760 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000761 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000762 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
763
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000764 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
765 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000766 Inst.addOperand(MCOperand::createReg(Mips::GP));
767 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000768 getStreamer().EmitInstruction(Inst, STI);
769 Inst.clear();
770
771 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
772 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000773 Inst.addOperand(MCOperand::createReg(Mips::GP));
774 Inst.addOperand(MCOperand::createReg(Mips::GP));
775 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000776 getStreamer().EmitInstruction(Inst, STI);
777 Inst.clear();
778
779 // daddu $gp, $gp, $funcreg
780 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000781 Inst.addOperand(MCOperand::createReg(Mips::GP));
782 Inst.addOperand(MCOperand::createReg(Mips::GP));
783 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000784 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000785
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000786 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000787}
788
789void MipsTargetELFStreamer::emitMipsAbiFlags() {
790 MCAssembler &MCA = getStreamer().getAssembler();
791 MCContext &Context = MCA.getContext();
792 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000793 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000794 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000795 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000796 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000797 OS.SwitchSection(Sec);
798
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000799 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000800}