blob: a051f4c123fcc5e7fde1351d650d5591b0d5b753 [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}
Daniel Sanders7e527422014-07-10 13:38:23 +000095void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
96 bool IsO32ABI) {
97 if (!Enabled && !IsO32ABI)
98 report_fatal_error("+nooddspreg is only valid for O32");
99}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000100void MipsTargetStreamer::emitDirectiveSetFp(
101 MipsABIFlagsSection::FpABIKind Value) {
102 forbidModuleDirective();
103}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000104
105MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
106 formatted_raw_ostream &OS)
107 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000108
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000109void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
110 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000111 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000112}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000113
114void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
115 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000116 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000117}
118
Rafael Espindola6633d572014-01-14 18:57:12 +0000119void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
120 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000121 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000122}
123
124void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
125 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000126 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000127}
128
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000129void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
130 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000131 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000132}
133
134void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
135 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000136 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000137}
138
139void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
140 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000141 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000142}
143
144void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
145 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000146 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000147}
148
Daniel Sanders44934432014-08-07 12:03:36 +0000149void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
150 OS << "\t.set\tmsa\n";
151 MipsTargetStreamer::emitDirectiveSetMsa();
152}
153
154void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
155 OS << "\t.set\tnomsa\n";
156 MipsTargetStreamer::emitDirectiveSetNoMsa();
157}
158
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000159void MipsTargetAsmStreamer::emitDirectiveSetAt() {
160 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000161 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000162}
163
Toma Tabacu16a74492015-02-13 10:30:57 +0000164void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
165 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
166 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
167}
168
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000169void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
170 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000171 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000172}
173
174void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
175 OS << "\t.end\t" << Name << '\n';
176}
177
Rafael Espindola6633d572014-01-14 18:57:12 +0000178void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
179 OS << "\t.ent\t" << Symbol.getName() << '\n';
180}
181
Jack Carter0cd3c192014-01-06 23:27:31 +0000182void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000183
184void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
185
186void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
187 OS << "\t.nan\tlegacy\n";
188}
189
Jack Carter0cd3c192014-01-06 23:27:31 +0000190void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
191 OS << "\t.option\tpic0\n";
192}
193
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000194void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
195 OS << "\t.option\tpic2\n";
196}
197
Toma Tabacu9ca50962015-04-16 09:53:47 +0000198void MipsTargetAsmStreamer::emitDirectiveInsn() {
199 MipsTargetStreamer::emitDirectiveInsn();
200 OS << "\t.insn\n";
201}
202
Rafael Espindola054234f2014-01-27 03:53:56 +0000203void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
204 unsigned ReturnReg) {
205 OS << "\t.frame\t$"
206 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
207 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000208 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
209}
210
Toma Tabacu85618b32014-08-19 14:22:52 +0000211void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
212 OS << "\t.set arch=" << Arch << "\n";
213 MipsTargetStreamer::emitDirectiveSetArch(Arch);
214}
215
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000216void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
217 OS << "\t.set\tmips0\n";
218 MipsTargetStreamer::emitDirectiveSetMips0();
219}
Toma Tabacu26647792014-09-09 12:52:14 +0000220
Daniel Sandersf0df2212014-08-04 12:20:00 +0000221void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
222 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000223 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000224}
225
226void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
227 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000228 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000229}
230
231void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
232 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000233 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000234}
235
236void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
237 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000238 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000239}
240
241void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
242 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000243 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000244}
245
246void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
247 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000248 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000249}
250
Vladimir Medic615b26e2014-03-04 09:54:09 +0000251void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
252 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000253 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000254}
255
Daniel Sanders17793142015-02-18 16:24:50 +0000256void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
257 OS << "\t.set\tmips32r3\n";
258 MipsTargetStreamer::emitDirectiveSetMips32R3();
259}
260
261void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
262 OS << "\t.set\tmips32r5\n";
263 MipsTargetStreamer::emitDirectiveSetMips32R5();
264}
265
Daniel Sandersf0df2212014-08-04 12:20:00 +0000266void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
267 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000268 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000269}
270
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000271void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
272 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000273 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000274}
275
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000276void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
277 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000278 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000279}
280
Daniel Sanders17793142015-02-18 16:24:50 +0000281void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
282 OS << "\t.set\tmips64r3\n";
283 MipsTargetStreamer::emitDirectiveSetMips64R3();
284}
285
286void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
287 OS << "\t.set\tmips64r5\n";
288 MipsTargetStreamer::emitDirectiveSetMips64R5();
289}
290
Daniel Sandersf0df2212014-08-04 12:20:00 +0000291void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
292 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000293 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000294}
295
Vladimir Medic27c398e2014-03-05 11:05:09 +0000296void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
297 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000298 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000299}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000300
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000301void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
302 OS << "\t.set\tnodsp\n";
303 MipsTargetStreamer::emitDirectiveSetNoDsp();
304}
305
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000306void MipsTargetAsmStreamer::emitDirectiveSetPop() {
307 OS << "\t.set\tpop\n";
308 MipsTargetStreamer::emitDirectiveSetPop();
309}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000310
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000311void MipsTargetAsmStreamer::emitDirectiveSetPush() {
312 OS << "\t.set\tpush\n";
313 MipsTargetStreamer::emitDirectiveSetPush();
314}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000315
Toma Tabacu29696502015-06-02 09:48:04 +0000316void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
317 OS << "\t.set\tsoftfloat\n";
318 MipsTargetStreamer::emitDirectiveSetSoftFloat();
319}
320
321void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
322 OS << "\t.set\thardfloat\n";
323 MipsTargetStreamer::emitDirectiveSetHardFloat();
324}
325
Rafael Espindola25fa2912014-01-27 04:33:11 +0000326// Print a 32 bit hex number with all numbers.
327static void printHex32(unsigned Value, raw_ostream &OS) {
328 OS << "0x";
329 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000330 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000331}
332
333void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
334 int CPUTopSavedRegOff) {
335 OS << "\t.mask \t";
336 printHex32(CPUBitmask, OS);
337 OS << ',' << CPUTopSavedRegOff << '\n';
338}
339
340void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
341 int FPUTopSavedRegOff) {
342 OS << "\t.fmask\t";
343 printHex32(FPUBitmask, OS);
344 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000345}
346
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000347void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000348 OS << "\t.cpload\t$"
349 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000350 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000351}
352
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000353void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
354 int RegOrOffset,
355 const MCSymbol &Sym,
356 bool IsReg) {
357 OS << "\t.cpsetup\t$"
358 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
359
360 if (IsReg)
361 OS << "$"
362 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
363 else
364 OS << RegOrOffset;
365
366 OS << ", ";
367
368 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000369 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000370}
371
Daniel Sanders7e527422014-07-10 13:38:23 +0000372void MipsTargetAsmStreamer::emitDirectiveModuleFP(
373 MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
374 MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000375
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000376 OS << "\t.module\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000377 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000378}
379
Daniel Sanders7e527422014-07-10 13:38:23 +0000380void MipsTargetAsmStreamer::emitDirectiveSetFp(
381 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000382 MipsTargetStreamer::emitDirectiveSetFp(Value);
383
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000384 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000385 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000386}
387
Daniel Sanders7e527422014-07-10 13:38:23 +0000388void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
389 bool IsO32ABI) {
390 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
391
392 OS << "\t.module\t" << (Enabled ? "" : "no") << "oddspreg\n";
393}
394
Jack Carter0cd3c192014-01-06 23:27:31 +0000395// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000396MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
397 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000398 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000399 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000400 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000401
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000402 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000403
404 // Set the header flags that we can in the constructor.
405 // FIXME: This is a fairly terrible hack. We set the rest
406 // of these in the destructor. The problem here is two-fold:
407 //
408 // a: Some of the eflags can be set/reset by directives.
409 // b: There aren't any usage paths that initialize the ABI
410 // pointer until after we initialize either an assembler
411 // or the target machine.
412 // We can fix this by making the target streamer construct
413 // the ABI, but this is fraught with wide ranging dependency
414 // issues as well.
415 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000416
417 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000418 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000419 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000420 else if (Features[Mips::FeatureMips64r2] ||
421 Features[Mips::FeatureMips64r3] ||
422 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000423 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000424 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000425 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000426 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000427 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000428 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000429 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000430 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000431 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000432 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000433 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000434 else if (Features[Mips::FeatureMips32r2] ||
435 Features[Mips::FeatureMips32r3] ||
436 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000437 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000438 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000439 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000440 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000441 EFlags |= ELF::EF_MIPS_ARCH_2;
442 else
443 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000444
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000445 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000446 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000447 EFlags |= ELF::EF_MIPS_NAN2008;
448
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000449 // -mabicalls and -mplt are not implemented but we should act as if they were
450 // given.
451 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000452
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000453 MCA.setELFHeaderEFlags(EFlags);
454}
Jack Carter86ac5c12013-11-18 23:55:27 +0000455
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000456void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
457 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000458 if (!isMicroMipsEnabled())
459 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000460 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000461 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000462 if (Type != ELF::STT_FUNC)
463 return;
464
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000465 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000466}
467
Rafael Espindola972e71a2014-01-31 23:10:26 +0000468void MipsTargetELFStreamer::finish() {
469 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000470 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000471
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000472 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000473 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000474 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000475 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000476 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000477 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000478 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000479
Rafael Espindola967d6a62015-05-21 21:02:35 +0000480 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
481 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
482 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000483
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000484 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000485
486 // Update e_header flags. See the FIXME and comment above in
487 // the constructor for a full rundown on this.
488 unsigned EFlags = MCA.getELFHeaderEFlags();
489
490 // ABI
491 // N64 does not require any ABI bits.
492 if (getABI().IsO32())
493 EFlags |= ELF::EF_MIPS_ABI_O32;
494 else if (getABI().IsN32())
495 EFlags |= ELF::EF_MIPS_ABI2;
496
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000497 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000498 if (getABI().IsO32())
499 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000500 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000501 EFlags |= ELF::EF_MIPS_32BITMODE;
502
503 // If we've set the cpic eflag and we're n64, go ahead and set the pic
504 // one as well.
505 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
506 EFlags |= ELF::EF_MIPS_PIC;
507
508 MCA.setELFHeaderEFlags(EFlags);
509
Daniel Sanders68c37472014-07-21 13:30:55 +0000510 // Emit all the option records.
511 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
512 // .reginfo.
513 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
514 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000515
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000516 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000517}
518
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000519void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
520 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000521 // If on rhs is micromips symbol then mark Symbol as microMips.
522 if (Value->getKind() != MCExpr::SymbolRef)
523 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000524 const auto &RhsSym = cast<MCSymbolELF>(
525 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000526
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000527 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000528 return;
529
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000530 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000531}
532
Jack Carter86ac5c12013-11-18 23:55:27 +0000533MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000534 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000535}
536
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000537void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
538 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000539
540 MCAssembler &MCA = getStreamer().getAssembler();
541 unsigned Flags = MCA.getELFHeaderEFlags();
542 Flags |= ELF::EF_MIPS_MICROMIPS;
543 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000544 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000545}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000546
547void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
548 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000549 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000550}
551
Rafael Espindola6633d572014-01-14 18:57:12 +0000552void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000553 MCAssembler &MCA = getStreamer().getAssembler();
554 unsigned Flags = MCA.getELFHeaderEFlags();
555 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
556 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000557 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000558}
559
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000560void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000561 MCAssembler &MCA = getStreamer().getAssembler();
562 unsigned Flags = MCA.getELFHeaderEFlags();
563 Flags |= ELF::EF_MIPS_NOREORDER;
564 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000565 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000566}
567
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000568void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000569 MCAssembler &MCA = getStreamer().getAssembler();
570 MCContext &Context = MCA.getContext();
571 MCStreamer &OS = getStreamer();
572
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000573 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
574 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000575
576 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000577 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000578
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000579 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000580 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000581
582 OS.PushSection();
583
584 OS.SwitchSection(Sec);
585
586 OS.EmitValueImpl(ExprRef, 4);
587
588 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
589 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
590
591 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
592 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
593
594 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
595 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
596 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
597
598 // The .end directive marks the end of a procedure. Invalidate
599 // the information gathered up until this point.
600 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
601
602 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000603}
604
Rafael Espindola6633d572014-01-14 18:57:12 +0000605void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000606 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000607}
608
Jack Carter0cd3c192014-01-06 23:27:31 +0000609void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
610 MCAssembler &MCA = getStreamer().getAssembler();
611 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000612 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000613 MCA.setELFHeaderEFlags(Flags);
614}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000615
616void MipsTargetELFStreamer::emitDirectiveNaN2008() {
617 MCAssembler &MCA = getStreamer().getAssembler();
618 unsigned Flags = MCA.getELFHeaderEFlags();
619 Flags |= ELF::EF_MIPS_NAN2008;
620 MCA.setELFHeaderEFlags(Flags);
621}
622
623void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
624 MCAssembler &MCA = getStreamer().getAssembler();
625 unsigned Flags = MCA.getELFHeaderEFlags();
626 Flags &= ~ELF::EF_MIPS_NAN2008;
627 MCA.setELFHeaderEFlags(Flags);
628}
629
Jack Carter0cd3c192014-01-06 23:27:31 +0000630void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
631 MCAssembler &MCA = getStreamer().getAssembler();
632 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000633 // This option overrides other PIC options like -KPIC.
634 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000635 Flags &= ~ELF::EF_MIPS_PIC;
636 MCA.setELFHeaderEFlags(Flags);
637}
Rafael Espindola054234f2014-01-27 03:53:56 +0000638
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000639void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
640 MCAssembler &MCA = getStreamer().getAssembler();
641 unsigned Flags = MCA.getELFHeaderEFlags();
642 Pic = true;
643 // NOTE: We are following the GAS behaviour here which means the directive
644 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
645 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
646 // EF_MIPS_CPIC to be mutually exclusive.
647 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
648 MCA.setELFHeaderEFlags(Flags);
649}
650
Toma Tabacu9ca50962015-04-16 09:53:47 +0000651void MipsTargetELFStreamer::emitDirectiveInsn() {
652 MipsTargetStreamer::emitDirectiveInsn();
653 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
654 MEF.createPendingLabelRelocs();
655}
656
Rafael Espindola054234f2014-01-27 03:53:56 +0000657void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000658 unsigned ReturnReg_) {
659 MCContext &Context = getStreamer().getAssembler().getContext();
660 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
661
662 FrameInfoSet = true;
663 FrameReg = RegInfo->getEncodingValue(StackReg);
664 FrameOffset = StackSize;
665 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000666}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000667
668void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
669 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000670 GPRInfoSet = true;
671 GPRBitMask = CPUBitmask;
672 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000673}
674
675void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
676 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000677 FPRInfoSet = true;
678 FPRBitMask = FPUBitmask;
679 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000680}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000681
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000682void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000683 // .cpload $reg
684 // This directive expands to:
685 // lui $gp, %hi(_gp_disp)
686 // addui $gp, $gp, %lo(_gp_disp)
687 // addu $gp, $gp, $reg
688 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000689 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000690 return;
691
692 // There's a GNU extension controlled by -mno-shared that allows
693 // locally-binding symbols to be accessed using absolute addresses.
694 // This is currently not supported. When supported -mno-shared makes
695 // .cpload expand to:
696 // lui $gp, %hi(__gnu_local_gp)
697 // addiu $gp, $gp, %lo(__gnu_local_gp)
698
699 StringRef SymName("_gp_disp");
700 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000701 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000702 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000703
704 MCInst TmpInst;
705 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000706 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000707 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000708 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000709 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000710 getStreamer().EmitInstruction(TmpInst, STI);
711
712 TmpInst.clear();
713
714 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000715 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
716 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000717 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000718 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000719 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000720 getStreamer().EmitInstruction(TmpInst, STI);
721
722 TmpInst.clear();
723
724 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000725 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
726 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
727 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000728 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000729
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000730 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000731}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000732
733void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
734 int RegOrOffset,
735 const MCSymbol &Sym,
736 bool IsReg) {
737 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000738 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000739 return;
740
741 MCAssembler &MCA = getStreamer().getAssembler();
742 MCInst Inst;
743
744 // Either store the old $gp in a register or on the stack
745 if (IsReg) {
746 // move $save, $gpreg
747 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000748 Inst.addOperand(MCOperand::createReg(RegOrOffset));
749 Inst.addOperand(MCOperand::createReg(Mips::GP));
750 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000751 } else {
752 // sd $gpreg, offset($sp)
753 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000754 Inst.addOperand(MCOperand::createReg(Mips::GP));
755 Inst.addOperand(MCOperand::createReg(Mips::SP));
756 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000757 }
758 getStreamer().EmitInstruction(Inst, STI);
759 Inst.clear();
760
Jim Grosbach13760bd2015-05-30 01:25:56 +0000761 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000762 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000763 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000764 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
765
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000766 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
767 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000768 Inst.addOperand(MCOperand::createReg(Mips::GP));
769 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000770 getStreamer().EmitInstruction(Inst, STI);
771 Inst.clear();
772
773 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
774 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000775 Inst.addOperand(MCOperand::createReg(Mips::GP));
776 Inst.addOperand(MCOperand::createReg(Mips::GP));
777 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000778 getStreamer().EmitInstruction(Inst, STI);
779 Inst.clear();
780
781 // daddu $gp, $gp, $funcreg
782 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000783 Inst.addOperand(MCOperand::createReg(Mips::GP));
784 Inst.addOperand(MCOperand::createReg(Mips::GP));
785 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000786 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000787
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000788 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000789}
790
791void MipsTargetELFStreamer::emitMipsAbiFlags() {
792 MCAssembler &MCA = getStreamer().getAssembler();
793 MCContext &Context = MCA.getContext();
794 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000795 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000796 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000797 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000798 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000799 OS.SwitchSection(Sec);
800
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000801 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000802}
Daniel Sanders7e527422014-07-10 13:38:23 +0000803
804void MipsTargetELFStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
805 bool IsO32ABI) {
806 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
807
808 ABIFlagsSection.OddSPReg = Enabled;
809}