blob: e947d1c2abc04cc24446bbf6c3a4658fdb8c30c8 [file] [log] [blame]
Jack Carter86ac5c12013-11-18 23:55:27 +00001//===-- MipsTargetStreamer.cpp - Mips Target Streamer Methods -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides Mips specific target streamer methods.
11//
12//===----------------------------------------------------------------------===//
13
Rafael Espindola054234f2014-01-27 03:53:56 +000014#include "InstPrinter/MipsInstPrinter.h"
Daniel Sanders68c37472014-07-21 13:30:55 +000015#include "MipsELFStreamer.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000016#include "MipsMCTargetDesc.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000017#include "MipsTargetObjectFile.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000018#include "MipsTargetStreamer.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000019#include "llvm/MC/MCContext.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000020#include "llvm/MC/MCELF.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000021#include "llvm/MC/MCSectionELF.h"
Rafael Espindolacb1953f2014-01-26 06:57:13 +000022#include "llvm/MC/MCSubtargetInfo.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000023#include "llvm/MC/MCSymbol.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000024#include "llvm/Support/CommandLine.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000025#include "llvm/Support/ELF.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000026#include "llvm/Support/ErrorHandling.h"
27#include "llvm/Support/FormattedStream.h"
28
29using namespace llvm;
30
Vladimir Medicfb8a2a92014-07-08 08:59:22 +000031MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S)
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000032 : MCTargetStreamer(S), ModuleDirectiveAllowed(true) {
Daniel Sandersd97a6342014-08-13 10:07:34 +000033 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
34}
Rafael Espindola60890b82014-06-23 19:43:40 +000035void MipsTargetStreamer::emitDirectiveSetMicroMips() {}
36void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {}
37void MipsTargetStreamer::emitDirectiveSetMips16() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000038void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); }
39void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000040void MipsTargetStreamer::emitDirectiveSetNoReorder() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000041void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); }
42void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); }
43void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); }
44void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); }
45void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); }
Toma Tabacu16a74492015-02-13 10:30:57 +000046void MipsTargetStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
47 forbidModuleDirective();
48}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000049void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000050void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {}
51void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {}
52void MipsTargetStreamer::emitDirectiveAbiCalls() {}
53void MipsTargetStreamer::emitDirectiveNaN2008() {}
54void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
55void MipsTargetStreamer::emitDirectiveOptionPic0() {}
56void MipsTargetStreamer::emitDirectiveOptionPic2() {}
Toma Tabacu9ca50962015-04-16 09:53:47 +000057void MipsTargetStreamer::emitDirectiveInsn() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000058void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
59 unsigned ReturnReg) {}
60void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
61void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
62}
Toma Tabacu85618b32014-08-19 14:22:52 +000063void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
64 forbidModuleDirective();
65}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000066void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000067void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
68void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
69void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
70void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); }
71void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); }
72void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); }
73void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); }
Daniel Sanders17793142015-02-18 16:24:50 +000074void MipsTargetStreamer::emitDirectiveSetMips32R3() { forbidModuleDirective(); }
75void MipsTargetStreamer::emitDirectiveSetMips32R5() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000076void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); }
77void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); }
78void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
Daniel Sanders17793142015-02-18 16:24:50 +000079void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); }
80void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000081void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000082void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); }
83void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000084void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
Toma Tabacu351b2fe2014-09-17 09:01:54 +000085void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
Toma Tabacuc4c202a2014-10-01 14:53:19 +000086void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
Rafael Espindola60890b82014-06-23 19:43:40 +000087void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
88 const MCSymbol &Sym, bool IsReg) {
89}
Daniel Sanders7e527422014-07-10 13:38:23 +000090void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
91 bool IsO32ABI) {
92 if (!Enabled && !IsO32ABI)
93 report_fatal_error("+nooddspreg is only valid for O32");
94}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000095void MipsTargetStreamer::emitDirectiveSetFp(
96 MipsABIFlagsSection::FpABIKind Value) {
97 forbidModuleDirective();
98}
Rafael Espindola24ea09e2014-01-26 06:06:37 +000099
100MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
101 formatted_raw_ostream &OS)
102 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000103
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000104void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
105 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000106 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000107}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000108
109void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
110 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000111 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000112}
113
Rafael Espindola6633d572014-01-14 18:57:12 +0000114void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
115 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000116 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000117}
118
119void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
120 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000121 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000122}
123
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000124void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
125 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000126 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000127}
128
129void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
130 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000131 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000132}
133
134void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
135 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000136 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000137}
138
139void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
140 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000141 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000142}
143
Daniel Sanders44934432014-08-07 12:03:36 +0000144void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
145 OS << "\t.set\tmsa\n";
146 MipsTargetStreamer::emitDirectiveSetMsa();
147}
148
149void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
150 OS << "\t.set\tnomsa\n";
151 MipsTargetStreamer::emitDirectiveSetNoMsa();
152}
153
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000154void MipsTargetAsmStreamer::emitDirectiveSetAt() {
155 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000156 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000157}
158
Toma Tabacu16a74492015-02-13 10:30:57 +0000159void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
160 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
161 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
162}
163
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000164void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
165 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000166 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000167}
168
169void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
170 OS << "\t.end\t" << Name << '\n';
171}
172
Rafael Espindola6633d572014-01-14 18:57:12 +0000173void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
174 OS << "\t.ent\t" << Symbol.getName() << '\n';
175}
176
Jack Carter0cd3c192014-01-06 23:27:31 +0000177void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000178
179void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
180
181void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
182 OS << "\t.nan\tlegacy\n";
183}
184
Jack Carter0cd3c192014-01-06 23:27:31 +0000185void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
186 OS << "\t.option\tpic0\n";
187}
188
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000189void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
190 OS << "\t.option\tpic2\n";
191}
192
Toma Tabacu9ca50962015-04-16 09:53:47 +0000193void MipsTargetAsmStreamer::emitDirectiveInsn() {
194 MipsTargetStreamer::emitDirectiveInsn();
195 OS << "\t.insn\n";
196}
197
Rafael Espindola054234f2014-01-27 03:53:56 +0000198void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
199 unsigned ReturnReg) {
200 OS << "\t.frame\t$"
201 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
202 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000203 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
204}
205
Toma Tabacu85618b32014-08-19 14:22:52 +0000206void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
207 OS << "\t.set arch=" << Arch << "\n";
208 MipsTargetStreamer::emitDirectiveSetArch(Arch);
209}
210
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000211void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
212 OS << "\t.set\tmips0\n";
213 MipsTargetStreamer::emitDirectiveSetMips0();
214}
Toma Tabacu26647792014-09-09 12:52:14 +0000215
Daniel Sandersf0df2212014-08-04 12:20:00 +0000216void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
217 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000218 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000219}
220
221void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
222 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000223 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000224}
225
226void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
227 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000228 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000229}
230
231void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
232 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000233 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000234}
235
236void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
237 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000238 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000239}
240
241void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
242 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000243 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000244}
245
Vladimir Medic615b26e2014-03-04 09:54:09 +0000246void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
247 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000248 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000249}
250
Daniel Sanders17793142015-02-18 16:24:50 +0000251void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
252 OS << "\t.set\tmips32r3\n";
253 MipsTargetStreamer::emitDirectiveSetMips32R3();
254}
255
256void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
257 OS << "\t.set\tmips32r5\n";
258 MipsTargetStreamer::emitDirectiveSetMips32R5();
259}
260
Daniel Sandersf0df2212014-08-04 12:20:00 +0000261void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
262 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000263 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000264}
265
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000266void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
267 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000268 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000269}
270
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000271void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
272 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000273 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000274}
275
Daniel Sanders17793142015-02-18 16:24:50 +0000276void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
277 OS << "\t.set\tmips64r3\n";
278 MipsTargetStreamer::emitDirectiveSetMips64R3();
279}
280
281void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
282 OS << "\t.set\tmips64r5\n";
283 MipsTargetStreamer::emitDirectiveSetMips64R5();
284}
285
Daniel Sandersf0df2212014-08-04 12:20:00 +0000286void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
287 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000288 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000289}
290
Vladimir Medic27c398e2014-03-05 11:05:09 +0000291void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
292 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000293 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000294}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000295
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000296void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
297 OS << "\t.set\tnodsp\n";
298 MipsTargetStreamer::emitDirectiveSetNoDsp();
299}
300
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000301void MipsTargetAsmStreamer::emitDirectiveSetPop() {
302 OS << "\t.set\tpop\n";
303 MipsTargetStreamer::emitDirectiveSetPop();
304}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000305
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000306void MipsTargetAsmStreamer::emitDirectiveSetPush() {
307 OS << "\t.set\tpush\n";
308 MipsTargetStreamer::emitDirectiveSetPush();
309}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000310
Rafael Espindola25fa2912014-01-27 04:33:11 +0000311// Print a 32 bit hex number with all numbers.
312static void printHex32(unsigned Value, raw_ostream &OS) {
313 OS << "0x";
314 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000315 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000316}
317
318void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
319 int CPUTopSavedRegOff) {
320 OS << "\t.mask \t";
321 printHex32(CPUBitmask, OS);
322 OS << ',' << CPUTopSavedRegOff << '\n';
323}
324
325void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
326 int FPUTopSavedRegOff) {
327 OS << "\t.fmask\t";
328 printHex32(FPUBitmask, OS);
329 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000330}
331
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000332void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000333 OS << "\t.cpload\t$"
334 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000335 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000336}
337
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000338void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
339 int RegOrOffset,
340 const MCSymbol &Sym,
341 bool IsReg) {
342 OS << "\t.cpsetup\t$"
343 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
344
345 if (IsReg)
346 OS << "$"
347 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
348 else
349 OS << RegOrOffset;
350
351 OS << ", ";
352
353 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000354 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000355}
356
Daniel Sanders7e527422014-07-10 13:38:23 +0000357void MipsTargetAsmStreamer::emitDirectiveModuleFP(
358 MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
359 MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000360
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000361 OS << "\t.module\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000362 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000363}
364
Daniel Sanders7e527422014-07-10 13:38:23 +0000365void MipsTargetAsmStreamer::emitDirectiveSetFp(
366 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000367 MipsTargetStreamer::emitDirectiveSetFp(Value);
368
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000369 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000370 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000371}
372
Daniel Sanders7e527422014-07-10 13:38:23 +0000373void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
374 bool IsO32ABI) {
375 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
376
377 OS << "\t.module\t" << (Enabled ? "" : "no") << "oddspreg\n";
378}
379
Jack Carter0cd3c192014-01-06 23:27:31 +0000380// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000381MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
382 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000383 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000384 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000385 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000386
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000387 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000388
389 // Set the header flags that we can in the constructor.
390 // FIXME: This is a fairly terrible hack. We set the rest
391 // of these in the destructor. The problem here is two-fold:
392 //
393 // a: Some of the eflags can be set/reset by directives.
394 // b: There aren't any usage paths that initialize the ABI
395 // pointer until after we initialize either an assembler
396 // or the target machine.
397 // We can fix this by making the target streamer construct
398 // the ABI, but this is fraught with wide ranging dependency
399 // issues as well.
400 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000401
402 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000403 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000404 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000405 else if (Features[Mips::FeatureMips64r2] ||
406 Features[Mips::FeatureMips64r3] ||
407 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000408 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000409 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000410 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000411 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000412 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000413 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000414 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000415 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000416 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000417 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000418 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000419 else if (Features[Mips::FeatureMips32r2] ||
420 Features[Mips::FeatureMips32r3] ||
421 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000422 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000423 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000424 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000425 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000426 EFlags |= ELF::EF_MIPS_ARCH_2;
427 else
428 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000429
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000430 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000431 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000432 EFlags |= ELF::EF_MIPS_NAN2008;
433
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000434 // -mabicalls and -mplt are not implemented but we should act as if they were
435 // given.
436 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000437
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000438 MCA.setELFHeaderEFlags(EFlags);
439}
Jack Carter86ac5c12013-11-18 23:55:27 +0000440
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000441void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
Rafael Espindola26e917c2014-01-15 03:07:12 +0000442 if (!isMicroMipsEnabled())
443 return;
Rafael Espindolae3b2acf2015-05-29 18:47:23 +0000444 getStreamer().getOrCreateSymbolData(Symbol);
445 uint8_t Type = MCELF::GetType(*Symbol);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000446 if (Type != ELF::STT_FUNC)
447 return;
448
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000449 // The "other" values are stored in the last 6 bits of the second byte
450 // The traditional defines for STO values assume the full byte and thus
451 // the shift to pack it.
Rafael Espindolae3b2acf2015-05-29 18:47:23 +0000452 MCELF::setOther(*Symbol, ELF::STO_MIPS_MICROMIPS >> 2);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000453}
454
Rafael Espindola972e71a2014-01-31 23:10:26 +0000455void MipsTargetELFStreamer::finish() {
456 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000457 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000458
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000459 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000460 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000461 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000462 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000463 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000464 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000465 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000466
Rafael Espindola967d6a62015-05-21 21:02:35 +0000467 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
468 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
469 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000470
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000471 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000472
473 // Update e_header flags. See the FIXME and comment above in
474 // the constructor for a full rundown on this.
475 unsigned EFlags = MCA.getELFHeaderEFlags();
476
477 // ABI
478 // N64 does not require any ABI bits.
479 if (getABI().IsO32())
480 EFlags |= ELF::EF_MIPS_ABI_O32;
481 else if (getABI().IsN32())
482 EFlags |= ELF::EF_MIPS_ABI2;
483
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000484 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000485 if (getABI().IsO32())
486 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000487 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000488 EFlags |= ELF::EF_MIPS_32BITMODE;
489
490 // If we've set the cpic eflag and we're n64, go ahead and set the pic
491 // one as well.
492 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
493 EFlags |= ELF::EF_MIPS_PIC;
494
495 MCA.setELFHeaderEFlags(EFlags);
496
Daniel Sanders68c37472014-07-21 13:30:55 +0000497 // Emit all the option records.
498 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
499 // .reginfo.
500 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
501 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000502
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000503 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000504}
505
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000506void MipsTargetELFStreamer::emitAssignment(MCSymbol *Symbol,
507 const MCExpr *Value) {
508 // If on rhs is micromips symbol then mark Symbol as microMips.
509 if (Value->getKind() != MCExpr::SymbolRef)
510 return;
511 const MCSymbol &RhsSym =
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000512 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol();
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000513
Rafael Espindolae3b2acf2015-05-29 18:47:23 +0000514 if (!(MCELF::getOther(RhsSym) & (ELF::STO_MIPS_MICROMIPS >> 2)))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000515 return;
516
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000517 // The "other" values are stored in the last 6 bits of the second byte.
518 // The traditional defines for STO values assume the full byte and thus
519 // the shift to pack it.
Rafael Espindolae3b2acf2015-05-29 18:47:23 +0000520 MCELF::setOther(*Symbol, ELF::STO_MIPS_MICROMIPS >> 2);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000521}
522
Jack Carter86ac5c12013-11-18 23:55:27 +0000523MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000524 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000525}
526
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000527void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
528 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000529
530 MCAssembler &MCA = getStreamer().getAssembler();
531 unsigned Flags = MCA.getELFHeaderEFlags();
532 Flags |= ELF::EF_MIPS_MICROMIPS;
533 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000534 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000535}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000536
537void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
538 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000539 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000540}
541
Rafael Espindola6633d572014-01-14 18:57:12 +0000542void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000543 MCAssembler &MCA = getStreamer().getAssembler();
544 unsigned Flags = MCA.getELFHeaderEFlags();
545 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
546 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000547 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000548}
549
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000550void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000551 MCAssembler &MCA = getStreamer().getAssembler();
552 unsigned Flags = MCA.getELFHeaderEFlags();
553 Flags |= ELF::EF_MIPS_NOREORDER;
554 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000555 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000556}
557
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000558void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000559 MCAssembler &MCA = getStreamer().getAssembler();
560 MCContext &Context = MCA.getContext();
561 MCStreamer &OS = getStreamer();
562
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000563 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
564 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000565
566 const MCSymbolRefExpr *ExprRef =
567 MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context);
568
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000569 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000570 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000571
572 OS.PushSection();
573
574 OS.SwitchSection(Sec);
575
576 OS.EmitValueImpl(ExprRef, 4);
577
578 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
579 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
580
581 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
582 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
583
584 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
585 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
586 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
587
588 // The .end directive marks the end of a procedure. Invalidate
589 // the information gathered up until this point.
590 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
591
592 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000593}
594
Rafael Espindola6633d572014-01-14 18:57:12 +0000595void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000596 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000597}
598
Jack Carter0cd3c192014-01-06 23:27:31 +0000599void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
600 MCAssembler &MCA = getStreamer().getAssembler();
601 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000602 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000603 MCA.setELFHeaderEFlags(Flags);
604}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000605
606void MipsTargetELFStreamer::emitDirectiveNaN2008() {
607 MCAssembler &MCA = getStreamer().getAssembler();
608 unsigned Flags = MCA.getELFHeaderEFlags();
609 Flags |= ELF::EF_MIPS_NAN2008;
610 MCA.setELFHeaderEFlags(Flags);
611}
612
613void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
614 MCAssembler &MCA = getStreamer().getAssembler();
615 unsigned Flags = MCA.getELFHeaderEFlags();
616 Flags &= ~ELF::EF_MIPS_NAN2008;
617 MCA.setELFHeaderEFlags(Flags);
618}
619
Jack Carter0cd3c192014-01-06 23:27:31 +0000620void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
621 MCAssembler &MCA = getStreamer().getAssembler();
622 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000623 // This option overrides other PIC options like -KPIC.
624 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000625 Flags &= ~ELF::EF_MIPS_PIC;
626 MCA.setELFHeaderEFlags(Flags);
627}
Rafael Espindola054234f2014-01-27 03:53:56 +0000628
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000629void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
630 MCAssembler &MCA = getStreamer().getAssembler();
631 unsigned Flags = MCA.getELFHeaderEFlags();
632 Pic = true;
633 // NOTE: We are following the GAS behaviour here which means the directive
634 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
635 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
636 // EF_MIPS_CPIC to be mutually exclusive.
637 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
638 MCA.setELFHeaderEFlags(Flags);
639}
640
Toma Tabacu9ca50962015-04-16 09:53:47 +0000641void MipsTargetELFStreamer::emitDirectiveInsn() {
642 MipsTargetStreamer::emitDirectiveInsn();
643 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
644 MEF.createPendingLabelRelocs();
645}
646
Rafael Espindola054234f2014-01-27 03:53:56 +0000647void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000648 unsigned ReturnReg_) {
649 MCContext &Context = getStreamer().getAssembler().getContext();
650 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
651
652 FrameInfoSet = true;
653 FrameReg = RegInfo->getEncodingValue(StackReg);
654 FrameOffset = StackSize;
655 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000656}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000657
658void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
659 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000660 GPRInfoSet = true;
661 GPRBitMask = CPUBitmask;
662 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000663}
664
665void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
666 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000667 FPRInfoSet = true;
668 FPRBitMask = FPUBitmask;
669 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000670}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000671
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000672void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000673 // .cpload $reg
674 // This directive expands to:
675 // lui $gp, %hi(_gp_disp)
676 // addui $gp, $gp, %lo(_gp_disp)
677 // addu $gp, $gp, $reg
678 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000679 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000680 return;
681
682 // There's a GNU extension controlled by -mno-shared that allows
683 // locally-binding symbols to be accessed using absolute addresses.
684 // This is currently not supported. When supported -mno-shared makes
685 // .cpload expand to:
686 // lui $gp, %hi(__gnu_local_gp)
687 // addiu $gp, $gp, %lo(__gnu_local_gp)
688
689 StringRef SymName("_gp_disp");
690 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000691 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000692 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000693
694 MCInst TmpInst;
695 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000696 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000697 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::Create(
698 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000699 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000700 getStreamer().EmitInstruction(TmpInst, STI);
701
702 TmpInst.clear();
703
704 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000705 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
706 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000707 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::Create(
708 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000709 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000710 getStreamer().EmitInstruction(TmpInst, STI);
711
712 TmpInst.clear();
713
714 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000715 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
716 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
717 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000718 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000719
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000720 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000721}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000722
723void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
724 int RegOrOffset,
725 const MCSymbol &Sym,
726 bool IsReg) {
727 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000728 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000729 return;
730
731 MCAssembler &MCA = getStreamer().getAssembler();
732 MCInst Inst;
733
734 // Either store the old $gp in a register or on the stack
735 if (IsReg) {
736 // move $save, $gpreg
737 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000738 Inst.addOperand(MCOperand::createReg(RegOrOffset));
739 Inst.addOperand(MCOperand::createReg(Mips::GP));
740 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000741 } else {
742 // sd $gpreg, offset($sp)
743 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000744 Inst.addOperand(MCOperand::createReg(Mips::GP));
745 Inst.addOperand(MCOperand::createReg(Mips::SP));
746 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000747 }
748 getStreamer().EmitInstruction(Inst, STI);
749 Inst.clear();
750
751 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000752 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000753 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000754 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
755
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000756 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
757 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000758 Inst.addOperand(MCOperand::createReg(Mips::GP));
759 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000760 getStreamer().EmitInstruction(Inst, STI);
761 Inst.clear();
762
763 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
764 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000765 Inst.addOperand(MCOperand::createReg(Mips::GP));
766 Inst.addOperand(MCOperand::createReg(Mips::GP));
767 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000768 getStreamer().EmitInstruction(Inst, STI);
769 Inst.clear();
770
771 // daddu $gp, $gp, $funcreg
772 Inst.setOpcode(Mips::DADDu);
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::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000776 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000777
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000778 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000779}
780
781void MipsTargetELFStreamer::emitMipsAbiFlags() {
782 MCAssembler &MCA = getStreamer().getAssembler();
783 MCContext &Context = MCA.getContext();
784 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000785 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000786 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000787 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000788 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000789 OS.SwitchSection(Sec);
790
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000791 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000792}
Daniel Sanders7e527422014-07-10 13:38:23 +0000793
794void MipsTargetELFStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
795 bool IsO32ABI) {
796 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
797
798 ABIFlagsSection.OddSPReg = Enabled;
799}