blob: 8d9f80a7e6faa9d4f83300dfbafa1e55526ad29e [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 Espindolae3b2acf2015-05-29 18:47:23 +0000460 getStreamer().getOrCreateSymbolData(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 Espindola6d5f7ce2014-01-14 04:25:13 +0000465 // The "other" values are stored in the last 6 bits of the second byte
466 // The traditional defines for STO values assume the full byte and thus
467 // the shift to pack it.
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000468 Symbol->setOther(ELF::STO_MIPS_MICROMIPS >> 2);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000469}
470
Rafael Espindola972e71a2014-01-31 23:10:26 +0000471void MipsTargetELFStreamer::finish() {
472 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000473 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000474
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000475 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000476 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000477 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000478 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000479 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000480 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000481 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000482
Rafael Espindola967d6a62015-05-21 21:02:35 +0000483 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
484 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
485 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000486
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000487 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000488
489 // Update e_header flags. See the FIXME and comment above in
490 // the constructor for a full rundown on this.
491 unsigned EFlags = MCA.getELFHeaderEFlags();
492
493 // ABI
494 // N64 does not require any ABI bits.
495 if (getABI().IsO32())
496 EFlags |= ELF::EF_MIPS_ABI_O32;
497 else if (getABI().IsN32())
498 EFlags |= ELF::EF_MIPS_ABI2;
499
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000500 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000501 if (getABI().IsO32())
502 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000503 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000504 EFlags |= ELF::EF_MIPS_32BITMODE;
505
506 // If we've set the cpic eflag and we're n64, go ahead and set the pic
507 // one as well.
508 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
509 EFlags |= ELF::EF_MIPS_PIC;
510
511 MCA.setELFHeaderEFlags(EFlags);
512
Daniel Sanders68c37472014-07-21 13:30:55 +0000513 // Emit all the option records.
514 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
515 // .reginfo.
516 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
517 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000518
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000519 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000520}
521
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000522void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
523 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000524 // If on rhs is micromips symbol then mark Symbol as microMips.
525 if (Value->getKind() != MCExpr::SymbolRef)
526 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000527 const auto &RhsSym = cast<MCSymbolELF>(
528 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000529
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000530 if (!(RhsSym.getOther() & (ELF::STO_MIPS_MICROMIPS >> 2)))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000531 return;
532
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000533 // The "other" values are stored in the last 6 bits of the second byte.
534 // The traditional defines for STO values assume the full byte and thus
535 // the shift to pack it.
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000536 Symbol->setOther(ELF::STO_MIPS_MICROMIPS >> 2);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000537}
538
Jack Carter86ac5c12013-11-18 23:55:27 +0000539MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000540 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000541}
542
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000543void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
544 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000545
546 MCAssembler &MCA = getStreamer().getAssembler();
547 unsigned Flags = MCA.getELFHeaderEFlags();
548 Flags |= ELF::EF_MIPS_MICROMIPS;
549 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000550 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000551}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000552
553void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
554 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000555 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000556}
557
Rafael Espindola6633d572014-01-14 18:57:12 +0000558void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000559 MCAssembler &MCA = getStreamer().getAssembler();
560 unsigned Flags = MCA.getELFHeaderEFlags();
561 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
562 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000563 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000564}
565
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000566void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000567 MCAssembler &MCA = getStreamer().getAssembler();
568 unsigned Flags = MCA.getELFHeaderEFlags();
569 Flags |= ELF::EF_MIPS_NOREORDER;
570 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000571 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000572}
573
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000574void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000575 MCAssembler &MCA = getStreamer().getAssembler();
576 MCContext &Context = MCA.getContext();
577 MCStreamer &OS = getStreamer();
578
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000579 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
580 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000581
582 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000583 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000584
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000585 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000586 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000587
588 OS.PushSection();
589
590 OS.SwitchSection(Sec);
591
592 OS.EmitValueImpl(ExprRef, 4);
593
594 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
595 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
596
597 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
598 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
599
600 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
601 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
602 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
603
604 // The .end directive marks the end of a procedure. Invalidate
605 // the information gathered up until this point.
606 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
607
608 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000609}
610
Rafael Espindola6633d572014-01-14 18:57:12 +0000611void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000612 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000613}
614
Jack Carter0cd3c192014-01-06 23:27:31 +0000615void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
616 MCAssembler &MCA = getStreamer().getAssembler();
617 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000618 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000619 MCA.setELFHeaderEFlags(Flags);
620}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000621
622void MipsTargetELFStreamer::emitDirectiveNaN2008() {
623 MCAssembler &MCA = getStreamer().getAssembler();
624 unsigned Flags = MCA.getELFHeaderEFlags();
625 Flags |= ELF::EF_MIPS_NAN2008;
626 MCA.setELFHeaderEFlags(Flags);
627}
628
629void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
630 MCAssembler &MCA = getStreamer().getAssembler();
631 unsigned Flags = MCA.getELFHeaderEFlags();
632 Flags &= ~ELF::EF_MIPS_NAN2008;
633 MCA.setELFHeaderEFlags(Flags);
634}
635
Jack Carter0cd3c192014-01-06 23:27:31 +0000636void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
637 MCAssembler &MCA = getStreamer().getAssembler();
638 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000639 // This option overrides other PIC options like -KPIC.
640 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000641 Flags &= ~ELF::EF_MIPS_PIC;
642 MCA.setELFHeaderEFlags(Flags);
643}
Rafael Espindola054234f2014-01-27 03:53:56 +0000644
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000645void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
646 MCAssembler &MCA = getStreamer().getAssembler();
647 unsigned Flags = MCA.getELFHeaderEFlags();
648 Pic = true;
649 // NOTE: We are following the GAS behaviour here which means the directive
650 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
651 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
652 // EF_MIPS_CPIC to be mutually exclusive.
653 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
654 MCA.setELFHeaderEFlags(Flags);
655}
656
Toma Tabacu9ca50962015-04-16 09:53:47 +0000657void MipsTargetELFStreamer::emitDirectiveInsn() {
658 MipsTargetStreamer::emitDirectiveInsn();
659 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
660 MEF.createPendingLabelRelocs();
661}
662
Rafael Espindola054234f2014-01-27 03:53:56 +0000663void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000664 unsigned ReturnReg_) {
665 MCContext &Context = getStreamer().getAssembler().getContext();
666 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
667
668 FrameInfoSet = true;
669 FrameReg = RegInfo->getEncodingValue(StackReg);
670 FrameOffset = StackSize;
671 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000672}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000673
674void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
675 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000676 GPRInfoSet = true;
677 GPRBitMask = CPUBitmask;
678 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000679}
680
681void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
682 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000683 FPRInfoSet = true;
684 FPRBitMask = FPUBitmask;
685 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000686}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000687
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000688void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000689 // .cpload $reg
690 // This directive expands to:
691 // lui $gp, %hi(_gp_disp)
692 // addui $gp, $gp, %lo(_gp_disp)
693 // addu $gp, $gp, $reg
694 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000695 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000696 return;
697
698 // There's a GNU extension controlled by -mno-shared that allows
699 // locally-binding symbols to be accessed using absolute addresses.
700 // This is currently not supported. When supported -mno-shared makes
701 // .cpload expand to:
702 // lui $gp, %hi(__gnu_local_gp)
703 // addiu $gp, $gp, %lo(__gnu_local_gp)
704
705 StringRef SymName("_gp_disp");
706 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000707 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000708 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000709
710 MCInst TmpInst;
711 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000712 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000713 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000714 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000715 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000716 getStreamer().EmitInstruction(TmpInst, STI);
717
718 TmpInst.clear();
719
720 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000721 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
722 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000723 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000724 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000725 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000726 getStreamer().EmitInstruction(TmpInst, STI);
727
728 TmpInst.clear();
729
730 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000731 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
732 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
733 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000734 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000735
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000736 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000737}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000738
739void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
740 int RegOrOffset,
741 const MCSymbol &Sym,
742 bool IsReg) {
743 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000744 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000745 return;
746
747 MCAssembler &MCA = getStreamer().getAssembler();
748 MCInst Inst;
749
750 // Either store the old $gp in a register or on the stack
751 if (IsReg) {
752 // move $save, $gpreg
753 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000754 Inst.addOperand(MCOperand::createReg(RegOrOffset));
755 Inst.addOperand(MCOperand::createReg(Mips::GP));
756 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000757 } else {
758 // sd $gpreg, offset($sp)
759 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000760 Inst.addOperand(MCOperand::createReg(Mips::GP));
761 Inst.addOperand(MCOperand::createReg(Mips::SP));
762 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000763 }
764 getStreamer().EmitInstruction(Inst, STI);
765 Inst.clear();
766
Jim Grosbach13760bd2015-05-30 01:25:56 +0000767 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000768 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000769 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000770 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
771
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000772 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
773 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000774 Inst.addOperand(MCOperand::createReg(Mips::GP));
775 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000776 getStreamer().EmitInstruction(Inst, STI);
777 Inst.clear();
778
779 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
780 Inst.setOpcode(Mips::ADDiu);
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::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000784 getStreamer().EmitInstruction(Inst, STI);
785 Inst.clear();
786
787 // daddu $gp, $gp, $funcreg
788 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000789 Inst.addOperand(MCOperand::createReg(Mips::GP));
790 Inst.addOperand(MCOperand::createReg(Mips::GP));
791 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000792 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000793
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000794 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000795}
796
797void MipsTargetELFStreamer::emitMipsAbiFlags() {
798 MCAssembler &MCA = getStreamer().getAssembler();
799 MCContext &Context = MCA.getContext();
800 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000801 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000802 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000803 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000804 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000805 OS.SwitchSection(Sec);
806
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000807 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000808}
Daniel Sanders7e527422014-07-10 13:38:23 +0000809
810void MipsTargetELFStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
811 bool IsO32ABI) {
812 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
813
814 ABIFlagsSection.OddSPReg = Enabled;
815}