blob: 9a0ffb27f598edfafe3cd40bae048a27107b8636 [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(); }
Toma Tabacu29696502015-06-02 09:48:04 +000084void MipsTargetStreamer::emitDirectiveSetSoftFloat() {
85 forbidModuleDirective();
86}
87void MipsTargetStreamer::emitDirectiveSetHardFloat() {
88 forbidModuleDirective();
89}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000090void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
Toma Tabacu351b2fe2014-09-17 09:01:54 +000091void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
Toma Tabacuc4c202a2014-10-01 14:53:19 +000092void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
Rafael Espindola60890b82014-06-23 19:43:40 +000093void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
94 const MCSymbol &Sym, bool IsReg) {
95}
Daniel Sanders7e527422014-07-10 13:38:23 +000096void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
97 bool IsO32ABI) {
98 if (!Enabled && !IsO32ABI)
99 report_fatal_error("+nooddspreg is only valid for O32");
100}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000101void MipsTargetStreamer::emitDirectiveSetFp(
102 MipsABIFlagsSection::FpABIKind Value) {
103 forbidModuleDirective();
104}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000105
106MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
107 formatted_raw_ostream &OS)
108 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000109
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000110void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
111 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000112 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000113}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000114
115void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
116 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000117 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000118}
119
Rafael Espindola6633d572014-01-14 18:57:12 +0000120void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
121 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000122 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000123}
124
125void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
126 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000127 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000128}
129
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000130void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
131 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000132 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000133}
134
135void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
136 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000137 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000138}
139
140void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
141 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000142 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000143}
144
145void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
146 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000147 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000148}
149
Daniel Sanders44934432014-08-07 12:03:36 +0000150void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
151 OS << "\t.set\tmsa\n";
152 MipsTargetStreamer::emitDirectiveSetMsa();
153}
154
155void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
156 OS << "\t.set\tnomsa\n";
157 MipsTargetStreamer::emitDirectiveSetNoMsa();
158}
159
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000160void MipsTargetAsmStreamer::emitDirectiveSetAt() {
161 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000162 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000163}
164
Toma Tabacu16a74492015-02-13 10:30:57 +0000165void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
166 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
167 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
168}
169
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000170void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
171 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000172 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000173}
174
175void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
176 OS << "\t.end\t" << Name << '\n';
177}
178
Rafael Espindola6633d572014-01-14 18:57:12 +0000179void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
180 OS << "\t.ent\t" << Symbol.getName() << '\n';
181}
182
Jack Carter0cd3c192014-01-06 23:27:31 +0000183void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000184
185void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
186
187void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
188 OS << "\t.nan\tlegacy\n";
189}
190
Jack Carter0cd3c192014-01-06 23:27:31 +0000191void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
192 OS << "\t.option\tpic0\n";
193}
194
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000195void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
196 OS << "\t.option\tpic2\n";
197}
198
Toma Tabacu9ca50962015-04-16 09:53:47 +0000199void MipsTargetAsmStreamer::emitDirectiveInsn() {
200 MipsTargetStreamer::emitDirectiveInsn();
201 OS << "\t.insn\n";
202}
203
Rafael Espindola054234f2014-01-27 03:53:56 +0000204void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
205 unsigned ReturnReg) {
206 OS << "\t.frame\t$"
207 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
208 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000209 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
210}
211
Toma Tabacu85618b32014-08-19 14:22:52 +0000212void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
213 OS << "\t.set arch=" << Arch << "\n";
214 MipsTargetStreamer::emitDirectiveSetArch(Arch);
215}
216
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000217void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
218 OS << "\t.set\tmips0\n";
219 MipsTargetStreamer::emitDirectiveSetMips0();
220}
Toma Tabacu26647792014-09-09 12:52:14 +0000221
Daniel Sandersf0df2212014-08-04 12:20:00 +0000222void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
223 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000224 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000225}
226
227void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
228 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000229 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000230}
231
232void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
233 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000234 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000235}
236
237void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
238 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000239 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000240}
241
242void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
243 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000244 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000245}
246
247void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
248 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000249 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000250}
251
Vladimir Medic615b26e2014-03-04 09:54:09 +0000252void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
253 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000254 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000255}
256
Daniel Sanders17793142015-02-18 16:24:50 +0000257void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
258 OS << "\t.set\tmips32r3\n";
259 MipsTargetStreamer::emitDirectiveSetMips32R3();
260}
261
262void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
263 OS << "\t.set\tmips32r5\n";
264 MipsTargetStreamer::emitDirectiveSetMips32R5();
265}
266
Daniel Sandersf0df2212014-08-04 12:20:00 +0000267void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
268 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000269 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000270}
271
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000272void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
273 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000274 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000275}
276
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000277void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
278 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000279 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000280}
281
Daniel Sanders17793142015-02-18 16:24:50 +0000282void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
283 OS << "\t.set\tmips64r3\n";
284 MipsTargetStreamer::emitDirectiveSetMips64R3();
285}
286
287void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
288 OS << "\t.set\tmips64r5\n";
289 MipsTargetStreamer::emitDirectiveSetMips64R5();
290}
291
Daniel Sandersf0df2212014-08-04 12:20:00 +0000292void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
293 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000294 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000295}
296
Vladimir Medic27c398e2014-03-05 11:05:09 +0000297void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
298 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000299 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000300}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000301
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000302void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
303 OS << "\t.set\tnodsp\n";
304 MipsTargetStreamer::emitDirectiveSetNoDsp();
305}
306
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000307void MipsTargetAsmStreamer::emitDirectiveSetPop() {
308 OS << "\t.set\tpop\n";
309 MipsTargetStreamer::emitDirectiveSetPop();
310}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000311
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000312void MipsTargetAsmStreamer::emitDirectiveSetPush() {
313 OS << "\t.set\tpush\n";
314 MipsTargetStreamer::emitDirectiveSetPush();
315}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000316
Toma Tabacu29696502015-06-02 09:48:04 +0000317void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
318 OS << "\t.set\tsoftfloat\n";
319 MipsTargetStreamer::emitDirectiveSetSoftFloat();
320}
321
322void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
323 OS << "\t.set\thardfloat\n";
324 MipsTargetStreamer::emitDirectiveSetHardFloat();
325}
326
Rafael Espindola25fa2912014-01-27 04:33:11 +0000327// Print a 32 bit hex number with all numbers.
328static void printHex32(unsigned Value, raw_ostream &OS) {
329 OS << "0x";
330 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000331 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000332}
333
334void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
335 int CPUTopSavedRegOff) {
336 OS << "\t.mask \t";
337 printHex32(CPUBitmask, OS);
338 OS << ',' << CPUTopSavedRegOff << '\n';
339}
340
341void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
342 int FPUTopSavedRegOff) {
343 OS << "\t.fmask\t";
344 printHex32(FPUBitmask, OS);
345 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000346}
347
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000348void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000349 OS << "\t.cpload\t$"
350 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000351 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000352}
353
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000354void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
355 int RegOrOffset,
356 const MCSymbol &Sym,
357 bool IsReg) {
358 OS << "\t.cpsetup\t$"
359 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
360
361 if (IsReg)
362 OS << "$"
363 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
364 else
365 OS << RegOrOffset;
366
367 OS << ", ";
368
369 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000370 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000371}
372
Daniel Sanders7e527422014-07-10 13:38:23 +0000373void MipsTargetAsmStreamer::emitDirectiveModuleFP(
374 MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
375 MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000376
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000377 OS << "\t.module\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000378 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000379}
380
Daniel Sanders7e527422014-07-10 13:38:23 +0000381void MipsTargetAsmStreamer::emitDirectiveSetFp(
382 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000383 MipsTargetStreamer::emitDirectiveSetFp(Value);
384
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000385 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000386 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000387}
388
Daniel Sanders7e527422014-07-10 13:38:23 +0000389void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
390 bool IsO32ABI) {
391 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
392
393 OS << "\t.module\t" << (Enabled ? "" : "no") << "oddspreg\n";
394}
395
Jack Carter0cd3c192014-01-06 23:27:31 +0000396// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000397MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
398 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000399 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000400 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000401 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000402
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000403 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000404
405 // Set the header flags that we can in the constructor.
406 // FIXME: This is a fairly terrible hack. We set the rest
407 // of these in the destructor. The problem here is two-fold:
408 //
409 // a: Some of the eflags can be set/reset by directives.
410 // b: There aren't any usage paths that initialize the ABI
411 // pointer until after we initialize either an assembler
412 // or the target machine.
413 // We can fix this by making the target streamer construct
414 // the ABI, but this is fraught with wide ranging dependency
415 // issues as well.
416 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000417
418 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000419 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000420 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000421 else if (Features[Mips::FeatureMips64r2] ||
422 Features[Mips::FeatureMips64r3] ||
423 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000424 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000425 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000426 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000427 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000428 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000429 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000430 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000431 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000432 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000433 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000434 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000435 else if (Features[Mips::FeatureMips32r2] ||
436 Features[Mips::FeatureMips32r3] ||
437 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000438 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000439 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000440 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000441 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000442 EFlags |= ELF::EF_MIPS_ARCH_2;
443 else
444 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000445
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000446 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000447 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000448 EFlags |= ELF::EF_MIPS_NAN2008;
449
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000450 // -mabicalls and -mplt are not implemented but we should act as if they were
451 // given.
452 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000453
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000454 MCA.setELFHeaderEFlags(EFlags);
455}
Jack Carter86ac5c12013-11-18 23:55:27 +0000456
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000457void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
Rafael Espindola26e917c2014-01-15 03:07:12 +0000458 if (!isMicroMipsEnabled())
459 return;
Rafael Espindolae3b2acf2015-05-29 18:47:23 +0000460 getStreamer().getOrCreateSymbolData(Symbol);
461 uint8_t Type = MCELF::GetType(*Symbol);
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 Espindolae3b2acf2015-05-29 18:47:23 +0000468 MCELF::setOther(*Symbol, 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
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000522void MipsTargetELFStreamer::emitAssignment(MCSymbol *Symbol,
523 const MCExpr *Value) {
524 // If on rhs is micromips symbol then mark Symbol as microMips.
525 if (Value->getKind() != MCExpr::SymbolRef)
526 return;
527 const MCSymbol &RhsSym =
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000528 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol();
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000529
Rafael Espindolae3b2acf2015-05-29 18:47:23 +0000530 if (!(MCELF::getOther(RhsSym) & (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 Espindolae3b2acf2015-05-29 18:47:23 +0000536 MCELF::setOther(*Symbol, 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}