blob: a560ce62030de3fe8db16c03ac0c27f1dfef1440 [file] [log] [blame]
Jack Carter86ac5c12013-11-18 23:55:27 +00001//===-- MipsTargetStreamer.cpp - Mips Target Streamer Methods -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides Mips specific target streamer methods.
11//
12//===----------------------------------------------------------------------===//
13
Rafael Espindola054234f2014-01-27 03:53:56 +000014#include "InstPrinter/MipsInstPrinter.h"
Daniel Sanders68c37472014-07-21 13:30:55 +000015#include "MipsELFStreamer.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000016#include "MipsMCTargetDesc.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000017#include "MipsTargetObjectFile.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000018#include "MipsTargetStreamer.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000019#include "llvm/MC/MCContext.h"
Rafael Espindola972e71a2014-01-31 23:10:26 +000020#include "llvm/MC/MCSectionELF.h"
Rafael Espindolacb1953f2014-01-26 06:57:13 +000021#include "llvm/MC/MCSubtargetInfo.h"
Rafael Espindola95fb9b92015-06-02 20:38:46 +000022#include "llvm/MC/MCSymbolELF.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000023#include "llvm/Support/CommandLine.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000024#include "llvm/Support/ELF.h"
Jack Carter86ac5c12013-11-18 23:55:27 +000025#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/FormattedStream.h"
27
28using namespace llvm;
29
Vladimir Medicfb8a2a92014-07-08 08:59:22 +000030MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S)
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000031 : MCTargetStreamer(S), ModuleDirectiveAllowed(true) {
Daniel Sandersd97a6342014-08-13 10:07:34 +000032 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
33}
Rafael Espindola60890b82014-06-23 19:43:40 +000034void MipsTargetStreamer::emitDirectiveSetMicroMips() {}
35void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {}
36void MipsTargetStreamer::emitDirectiveSetMips16() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000037void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); }
38void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000039void MipsTargetStreamer::emitDirectiveSetNoReorder() {}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000040void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); }
41void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); }
42void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); }
43void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); }
44void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); }
Toma Tabacu16a74492015-02-13 10:30:57 +000045void MipsTargetStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
46 forbidModuleDirective();
47}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000048void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000049void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {}
50void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {}
51void MipsTargetStreamer::emitDirectiveAbiCalls() {}
52void MipsTargetStreamer::emitDirectiveNaN2008() {}
53void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
54void MipsTargetStreamer::emitDirectiveOptionPic0() {}
55void MipsTargetStreamer::emitDirectiveOptionPic2() {}
Toma Tabacu9ca50962015-04-16 09:53:47 +000056void MipsTargetStreamer::emitDirectiveInsn() { forbidModuleDirective(); }
Rafael Espindola60890b82014-06-23 19:43:40 +000057void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
58 unsigned ReturnReg) {}
59void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
60void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
61}
Toma Tabacu85618b32014-08-19 14:22:52 +000062void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
63 forbidModuleDirective();
64}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000065void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000066void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
67void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
68void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
69void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); }
70void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); }
71void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); }
72void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); }
Daniel Sanders17793142015-02-18 16:24:50 +000073void MipsTargetStreamer::emitDirectiveSetMips32R3() { forbidModuleDirective(); }
74void MipsTargetStreamer::emitDirectiveSetMips32R5() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000075void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); }
76void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); }
77void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
Daniel Sanders17793142015-02-18 16:24:50 +000078void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); }
79void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); }
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000080void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +000081void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); }
82void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); }
Toma Tabacu29696502015-06-02 09:48:04 +000083void MipsTargetStreamer::emitDirectiveSetSoftFloat() {
84 forbidModuleDirective();
85}
86void MipsTargetStreamer::emitDirectiveSetHardFloat() {
87 forbidModuleDirective();
88}
Daniel Sanderscdb45fa2014-08-14 09:18:14 +000089void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
Toma Tabacu351b2fe2014-09-17 09:01:54 +000090void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
Toma Tabacuc4c202a2014-10-01 14:53:19 +000091void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
Rafael Espindola60890b82014-06-23 19:43:40 +000092void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
93 const MCSymbol &Sym, bool IsReg) {
94}
Toma Tabacubfcbfd52015-06-23 12:34:19 +000095
Toma Tabacua64e5402015-06-25 12:44:38 +000096void MipsTargetStreamer::emitDirectiveModuleFP() {}
Toma Tabacubfcbfd52015-06-23 12:34:19 +000097
Toma Tabacu3c499582015-06-25 10:56:57 +000098void MipsTargetStreamer::emitDirectiveModuleOddSPReg() {
99 if (!ABIFlagsSection.OddSPReg && !ABIFlagsSection.Is32BitABI)
Daniel Sanders7e527422014-07-10 13:38:23 +0000100 report_fatal_error("+nooddspreg is only valid for O32");
101}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000102void MipsTargetStreamer::emitDirectiveSetFp(
103 MipsABIFlagsSection::FpABIKind Value) {
104 forbidModuleDirective();
105}
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000106void MipsTargetStreamer::emitDirectiveSetOddSPReg() { forbidModuleDirective(); }
107void MipsTargetStreamer::emitDirectiveSetNoOddSPReg() {
108 forbidModuleDirective();
109}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000110
111MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
112 formatted_raw_ostream &OS)
113 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000114
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000115void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
116 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000117 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000118}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000119
120void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
121 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000122 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000123}
124
Rafael Espindola6633d572014-01-14 18:57:12 +0000125void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
126 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000127 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000128}
129
130void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
131 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000132 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000133}
134
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000135void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
136 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000137 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000138}
139
140void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
141 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000142 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000143}
144
145void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
146 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000147 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000148}
149
150void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
151 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000152 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000153}
154
Daniel Sanders44934432014-08-07 12:03:36 +0000155void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
156 OS << "\t.set\tmsa\n";
157 MipsTargetStreamer::emitDirectiveSetMsa();
158}
159
160void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
161 OS << "\t.set\tnomsa\n";
162 MipsTargetStreamer::emitDirectiveSetNoMsa();
163}
164
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000165void MipsTargetAsmStreamer::emitDirectiveSetAt() {
166 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000167 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000168}
169
Toma Tabacu16a74492015-02-13 10:30:57 +0000170void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
171 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
172 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
173}
174
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000175void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
176 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000177 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000178}
179
180void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
181 OS << "\t.end\t" << Name << '\n';
182}
183
Rafael Espindola6633d572014-01-14 18:57:12 +0000184void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
185 OS << "\t.ent\t" << Symbol.getName() << '\n';
186}
187
Jack Carter0cd3c192014-01-06 23:27:31 +0000188void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000189
190void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
191
192void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
193 OS << "\t.nan\tlegacy\n";
194}
195
Jack Carter0cd3c192014-01-06 23:27:31 +0000196void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
197 OS << "\t.option\tpic0\n";
198}
199
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000200void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
201 OS << "\t.option\tpic2\n";
202}
203
Toma Tabacu9ca50962015-04-16 09:53:47 +0000204void MipsTargetAsmStreamer::emitDirectiveInsn() {
205 MipsTargetStreamer::emitDirectiveInsn();
206 OS << "\t.insn\n";
207}
208
Rafael Espindola054234f2014-01-27 03:53:56 +0000209void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
210 unsigned ReturnReg) {
211 OS << "\t.frame\t$"
212 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
213 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000214 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
215}
216
Toma Tabacu85618b32014-08-19 14:22:52 +0000217void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
218 OS << "\t.set arch=" << Arch << "\n";
219 MipsTargetStreamer::emitDirectiveSetArch(Arch);
220}
221
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000222void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
223 OS << "\t.set\tmips0\n";
224 MipsTargetStreamer::emitDirectiveSetMips0();
225}
Toma Tabacu26647792014-09-09 12:52:14 +0000226
Daniel Sandersf0df2212014-08-04 12:20:00 +0000227void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
228 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000229 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000230}
231
232void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
233 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000234 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000235}
236
237void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
238 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000239 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000240}
241
242void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
243 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000244 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000245}
246
247void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
248 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000249 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000250}
251
252void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
253 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000254 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000255}
256
Vladimir Medic615b26e2014-03-04 09:54:09 +0000257void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
258 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000259 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000260}
261
Daniel Sanders17793142015-02-18 16:24:50 +0000262void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
263 OS << "\t.set\tmips32r3\n";
264 MipsTargetStreamer::emitDirectiveSetMips32R3();
265}
266
267void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
268 OS << "\t.set\tmips32r5\n";
269 MipsTargetStreamer::emitDirectiveSetMips32R5();
270}
271
Daniel Sandersf0df2212014-08-04 12:20:00 +0000272void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
273 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000274 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000275}
276
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000277void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
278 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000279 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000280}
281
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000282void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
283 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000284 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000285}
286
Daniel Sanders17793142015-02-18 16:24:50 +0000287void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
288 OS << "\t.set\tmips64r3\n";
289 MipsTargetStreamer::emitDirectiveSetMips64R3();
290}
291
292void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
293 OS << "\t.set\tmips64r5\n";
294 MipsTargetStreamer::emitDirectiveSetMips64R5();
295}
296
Daniel Sandersf0df2212014-08-04 12:20:00 +0000297void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
298 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000299 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000300}
301
Vladimir Medic27c398e2014-03-05 11:05:09 +0000302void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
303 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000304 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000305}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000306
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000307void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
308 OS << "\t.set\tnodsp\n";
309 MipsTargetStreamer::emitDirectiveSetNoDsp();
310}
311
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000312void MipsTargetAsmStreamer::emitDirectiveSetPop() {
313 OS << "\t.set\tpop\n";
314 MipsTargetStreamer::emitDirectiveSetPop();
315}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000316
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000317void MipsTargetAsmStreamer::emitDirectiveSetPush() {
318 OS << "\t.set\tpush\n";
319 MipsTargetStreamer::emitDirectiveSetPush();
320}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000321
Toma Tabacu29696502015-06-02 09:48:04 +0000322void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
323 OS << "\t.set\tsoftfloat\n";
324 MipsTargetStreamer::emitDirectiveSetSoftFloat();
325}
326
327void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
328 OS << "\t.set\thardfloat\n";
329 MipsTargetStreamer::emitDirectiveSetHardFloat();
330}
331
Rafael Espindola25fa2912014-01-27 04:33:11 +0000332// Print a 32 bit hex number with all numbers.
333static void printHex32(unsigned Value, raw_ostream &OS) {
334 OS << "0x";
335 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000336 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000337}
338
339void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
340 int CPUTopSavedRegOff) {
341 OS << "\t.mask \t";
342 printHex32(CPUBitmask, OS);
343 OS << ',' << CPUTopSavedRegOff << '\n';
344}
345
346void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
347 int FPUTopSavedRegOff) {
348 OS << "\t.fmask\t";
349 printHex32(FPUBitmask, OS);
350 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000351}
352
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000353void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000354 OS << "\t.cpload\t$"
355 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000356 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000357}
358
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000359void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
360 int RegOrOffset,
361 const MCSymbol &Sym,
362 bool IsReg) {
363 OS << "\t.cpsetup\t$"
364 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
365
366 if (IsReg)
367 OS << "$"
368 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
369 else
370 OS << RegOrOffset;
371
372 OS << ", ";
373
374 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000375 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000376}
377
Toma Tabacua64e5402015-06-25 12:44:38 +0000378void MipsTargetAsmStreamer::emitDirectiveModuleFP() {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000379 OS << "\t.module\tfp=";
Toma Tabacua64e5402015-06-25 12:44:38 +0000380 OS << ABIFlagsSection.getFpABIString(ABIFlagsSection.getFpABI()) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000381}
382
Daniel Sanders7e527422014-07-10 13:38:23 +0000383void MipsTargetAsmStreamer::emitDirectiveSetFp(
384 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000385 MipsTargetStreamer::emitDirectiveSetFp(Value);
386
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000387 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000388 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000389}
390
Toma Tabacu3c499582015-06-25 10:56:57 +0000391void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() {
392 MipsTargetStreamer::emitDirectiveModuleOddSPReg();
Daniel Sanders7e527422014-07-10 13:38:23 +0000393
Toma Tabacu3c499582015-06-25 10:56:57 +0000394 OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
Daniel Sanders7e527422014-07-10 13:38:23 +0000395}
396
Toma Tabacu32c72aa2015-06-30 09:36:50 +0000397void MipsTargetAsmStreamer::emitDirectiveSetOddSPReg() {
398 MipsTargetStreamer::emitDirectiveSetOddSPReg();
399 OS << "\t.set\toddspreg\n";
400}
401
402void MipsTargetAsmStreamer::emitDirectiveSetNoOddSPReg() {
403 MipsTargetStreamer::emitDirectiveSetNoOddSPReg();
404 OS << "\t.set\tnooddspreg\n";
405}
406
Jack Carter0cd3c192014-01-06 23:27:31 +0000407// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000408MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
409 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000410 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000411 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000412 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000413
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000414 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000415
416 // Set the header flags that we can in the constructor.
417 // FIXME: This is a fairly terrible hack. We set the rest
418 // of these in the destructor. The problem here is two-fold:
419 //
420 // a: Some of the eflags can be set/reset by directives.
421 // b: There aren't any usage paths that initialize the ABI
422 // pointer until after we initialize either an assembler
423 // or the target machine.
424 // We can fix this by making the target streamer construct
425 // the ABI, but this is fraught with wide ranging dependency
426 // issues as well.
427 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000428
429 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000430 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000431 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000432 else if (Features[Mips::FeatureMips64r2] ||
433 Features[Mips::FeatureMips64r3] ||
434 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000435 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000436 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000437 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000438 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000439 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000440 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000441 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000442 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000443 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000444 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000445 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000446 else if (Features[Mips::FeatureMips32r2] ||
447 Features[Mips::FeatureMips32r3] ||
448 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000449 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000450 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000451 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000452 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000453 EFlags |= ELF::EF_MIPS_ARCH_2;
454 else
455 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000456
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000457 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000458 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000459 EFlags |= ELF::EF_MIPS_NAN2008;
460
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000461 // -mabicalls and -mplt are not implemented but we should act as if they were
462 // given.
463 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000464
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000465 MCA.setELFHeaderEFlags(EFlags);
466}
Jack Carter86ac5c12013-11-18 23:55:27 +0000467
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000468void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
469 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000470 if (!isMicroMipsEnabled())
471 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000472 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000473 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000474 if (Type != ELF::STT_FUNC)
475 return;
476
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000477 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000478}
479
Rafael Espindola972e71a2014-01-31 23:10:26 +0000480void MipsTargetELFStreamer::finish() {
481 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000482 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000483
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000484 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000485 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000486 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000487 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000488 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000489 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000490 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000491
Rafael Espindola967d6a62015-05-21 21:02:35 +0000492 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
493 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
494 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000495
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000496 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000497
498 // Update e_header flags. See the FIXME and comment above in
499 // the constructor for a full rundown on this.
500 unsigned EFlags = MCA.getELFHeaderEFlags();
501
502 // ABI
503 // N64 does not require any ABI bits.
504 if (getABI().IsO32())
505 EFlags |= ELF::EF_MIPS_ABI_O32;
506 else if (getABI().IsN32())
507 EFlags |= ELF::EF_MIPS_ABI2;
508
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000509 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000510 if (getABI().IsO32())
511 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000512 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000513 EFlags |= ELF::EF_MIPS_32BITMODE;
514
515 // If we've set the cpic eflag and we're n64, go ahead and set the pic
516 // one as well.
517 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
518 EFlags |= ELF::EF_MIPS_PIC;
519
520 MCA.setELFHeaderEFlags(EFlags);
521
Daniel Sanders68c37472014-07-21 13:30:55 +0000522 // Emit all the option records.
523 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
524 // .reginfo.
525 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
526 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000527
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000528 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000529}
530
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000531void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
532 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000533 // If on rhs is micromips symbol then mark Symbol as microMips.
534 if (Value->getKind() != MCExpr::SymbolRef)
535 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000536 const auto &RhsSym = cast<MCSymbolELF>(
537 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000538
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000539 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000540 return;
541
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000542 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000543}
544
Jack Carter86ac5c12013-11-18 23:55:27 +0000545MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000546 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000547}
548
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000549void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
550 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000551
552 MCAssembler &MCA = getStreamer().getAssembler();
553 unsigned Flags = MCA.getELFHeaderEFlags();
554 Flags |= ELF::EF_MIPS_MICROMIPS;
555 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000556 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000557}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000558
559void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
560 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000561 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000562}
563
Rafael Espindola6633d572014-01-14 18:57:12 +0000564void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000565 MCAssembler &MCA = getStreamer().getAssembler();
566 unsigned Flags = MCA.getELFHeaderEFlags();
567 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
568 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000569 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000570}
571
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000572void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000573 MCAssembler &MCA = getStreamer().getAssembler();
574 unsigned Flags = MCA.getELFHeaderEFlags();
575 Flags |= ELF::EF_MIPS_NOREORDER;
576 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000577 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000578}
579
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000580void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000581 MCAssembler &MCA = getStreamer().getAssembler();
582 MCContext &Context = MCA.getContext();
583 MCStreamer &OS = getStreamer();
584
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000585 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
586 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000587
588 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000589 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000590
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000591 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000592 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000593
594 OS.PushSection();
595
596 OS.SwitchSection(Sec);
597
598 OS.EmitValueImpl(ExprRef, 4);
599
600 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
601 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
602
603 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
604 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
605
606 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
607 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
608 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
609
610 // The .end directive marks the end of a procedure. Invalidate
611 // the information gathered up until this point.
612 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
613
614 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000615}
616
Rafael Espindola6633d572014-01-14 18:57:12 +0000617void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000618 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000619}
620
Jack Carter0cd3c192014-01-06 23:27:31 +0000621void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
622 MCAssembler &MCA = getStreamer().getAssembler();
623 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000624 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000625 MCA.setELFHeaderEFlags(Flags);
626}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000627
628void MipsTargetELFStreamer::emitDirectiveNaN2008() {
629 MCAssembler &MCA = getStreamer().getAssembler();
630 unsigned Flags = MCA.getELFHeaderEFlags();
631 Flags |= ELF::EF_MIPS_NAN2008;
632 MCA.setELFHeaderEFlags(Flags);
633}
634
635void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
636 MCAssembler &MCA = getStreamer().getAssembler();
637 unsigned Flags = MCA.getELFHeaderEFlags();
638 Flags &= ~ELF::EF_MIPS_NAN2008;
639 MCA.setELFHeaderEFlags(Flags);
640}
641
Jack Carter0cd3c192014-01-06 23:27:31 +0000642void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
643 MCAssembler &MCA = getStreamer().getAssembler();
644 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000645 // This option overrides other PIC options like -KPIC.
646 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000647 Flags &= ~ELF::EF_MIPS_PIC;
648 MCA.setELFHeaderEFlags(Flags);
649}
Rafael Espindola054234f2014-01-27 03:53:56 +0000650
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000651void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
652 MCAssembler &MCA = getStreamer().getAssembler();
653 unsigned Flags = MCA.getELFHeaderEFlags();
654 Pic = true;
655 // NOTE: We are following the GAS behaviour here which means the directive
656 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
657 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
658 // EF_MIPS_CPIC to be mutually exclusive.
659 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
660 MCA.setELFHeaderEFlags(Flags);
661}
662
Toma Tabacu9ca50962015-04-16 09:53:47 +0000663void MipsTargetELFStreamer::emitDirectiveInsn() {
664 MipsTargetStreamer::emitDirectiveInsn();
665 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
666 MEF.createPendingLabelRelocs();
667}
668
Rafael Espindola054234f2014-01-27 03:53:56 +0000669void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000670 unsigned ReturnReg_) {
671 MCContext &Context = getStreamer().getAssembler().getContext();
672 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
673
674 FrameInfoSet = true;
675 FrameReg = RegInfo->getEncodingValue(StackReg);
676 FrameOffset = StackSize;
677 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000678}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000679
680void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
681 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000682 GPRInfoSet = true;
683 GPRBitMask = CPUBitmask;
684 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000685}
686
687void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
688 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000689 FPRInfoSet = true;
690 FPRBitMask = FPUBitmask;
691 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000692}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000693
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000694void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000695 // .cpload $reg
696 // This directive expands to:
697 // lui $gp, %hi(_gp_disp)
698 // addui $gp, $gp, %lo(_gp_disp)
699 // addu $gp, $gp, $reg
700 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000701 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000702 return;
703
704 // There's a GNU extension controlled by -mno-shared that allows
705 // locally-binding symbols to be accessed using absolute addresses.
706 // This is currently not supported. When supported -mno-shared makes
707 // .cpload expand to:
708 // lui $gp, %hi(__gnu_local_gp)
709 // addiu $gp, $gp, %lo(__gnu_local_gp)
710
711 StringRef SymName("_gp_disp");
712 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000713 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000714 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000715
716 MCInst TmpInst;
717 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000718 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000719 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000720 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000721 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000722 getStreamer().EmitInstruction(TmpInst, STI);
723
724 TmpInst.clear();
725
726 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000727 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
728 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000729 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000730 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000731 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000732 getStreamer().EmitInstruction(TmpInst, STI);
733
734 TmpInst.clear();
735
736 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000737 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
738 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
739 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000740 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000741
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000742 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000743}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000744
745void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
746 int RegOrOffset,
747 const MCSymbol &Sym,
748 bool IsReg) {
749 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000750 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000751 return;
752
753 MCAssembler &MCA = getStreamer().getAssembler();
754 MCInst Inst;
755
756 // Either store the old $gp in a register or on the stack
757 if (IsReg) {
758 // move $save, $gpreg
759 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000760 Inst.addOperand(MCOperand::createReg(RegOrOffset));
761 Inst.addOperand(MCOperand::createReg(Mips::GP));
762 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000763 } else {
764 // sd $gpreg, offset($sp)
765 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000766 Inst.addOperand(MCOperand::createReg(Mips::GP));
767 Inst.addOperand(MCOperand::createReg(Mips::SP));
768 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000769 }
770 getStreamer().EmitInstruction(Inst, STI);
771 Inst.clear();
772
Jim Grosbach13760bd2015-05-30 01:25:56 +0000773 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000774 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000775 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000776 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
777
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000778 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
779 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000780 Inst.addOperand(MCOperand::createReg(Mips::GP));
781 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000782 getStreamer().EmitInstruction(Inst, STI);
783 Inst.clear();
784
785 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
786 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000787 Inst.addOperand(MCOperand::createReg(Mips::GP));
788 Inst.addOperand(MCOperand::createReg(Mips::GP));
789 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000790 getStreamer().EmitInstruction(Inst, STI);
791 Inst.clear();
792
793 // daddu $gp, $gp, $funcreg
794 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000795 Inst.addOperand(MCOperand::createReg(Mips::GP));
796 Inst.addOperand(MCOperand::createReg(Mips::GP));
797 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000798 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000799
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000800 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000801}
802
803void MipsTargetELFStreamer::emitMipsAbiFlags() {
804 MCAssembler &MCA = getStreamer().getAssembler();
805 MCContext &Context = MCA.getContext();
806 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000807 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000808 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000809 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000810 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000811 OS.SwitchSection(Sec);
812
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000813 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000814}