blob: 1155d722e17dde3b813a91d3bc862a3c3fba8387 [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
96void
97MipsTargetStreamer::emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value,
98 bool Is32BitABI) {
99 ABIFlagsSection.setFpABI(Value, Is32BitABI);
100}
101
102void MipsTargetStreamer::emitDirectiveModuleFP() {
103 emitDirectiveModuleFP(ABIFlagsSection.getFpABI(), ABIFlagsSection.Is32BitABI);
104}
105
Daniel Sanders7e527422014-07-10 13:38:23 +0000106void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
107 bool IsO32ABI) {
108 if (!Enabled && !IsO32ABI)
109 report_fatal_error("+nooddspreg is only valid for O32");
110}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000111void MipsTargetStreamer::emitDirectiveSetFp(
112 MipsABIFlagsSection::FpABIKind Value) {
113 forbidModuleDirective();
114}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000115
116MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
117 formatted_raw_ostream &OS)
118 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000119
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000120void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
121 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000122 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000123}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000124
125void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
126 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000127 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000128}
129
Rafael Espindola6633d572014-01-14 18:57:12 +0000130void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
131 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000132 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000133}
134
135void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
136 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000137 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000138}
139
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000140void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
141 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000142 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000143}
144
145void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
146 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000147 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000148}
149
150void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
151 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000152 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000153}
154
155void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
156 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000157 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000158}
159
Daniel Sanders44934432014-08-07 12:03:36 +0000160void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
161 OS << "\t.set\tmsa\n";
162 MipsTargetStreamer::emitDirectiveSetMsa();
163}
164
165void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
166 OS << "\t.set\tnomsa\n";
167 MipsTargetStreamer::emitDirectiveSetNoMsa();
168}
169
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000170void MipsTargetAsmStreamer::emitDirectiveSetAt() {
171 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000172 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000173}
174
Toma Tabacu16a74492015-02-13 10:30:57 +0000175void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
176 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
177 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
178}
179
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000180void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
181 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000182 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000183}
184
185void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
186 OS << "\t.end\t" << Name << '\n';
187}
188
Rafael Espindola6633d572014-01-14 18:57:12 +0000189void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
190 OS << "\t.ent\t" << Symbol.getName() << '\n';
191}
192
Jack Carter0cd3c192014-01-06 23:27:31 +0000193void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000194
195void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
196
197void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
198 OS << "\t.nan\tlegacy\n";
199}
200
Jack Carter0cd3c192014-01-06 23:27:31 +0000201void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
202 OS << "\t.option\tpic0\n";
203}
204
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000205void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
206 OS << "\t.option\tpic2\n";
207}
208
Toma Tabacu9ca50962015-04-16 09:53:47 +0000209void MipsTargetAsmStreamer::emitDirectiveInsn() {
210 MipsTargetStreamer::emitDirectiveInsn();
211 OS << "\t.insn\n";
212}
213
Rafael Espindola054234f2014-01-27 03:53:56 +0000214void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
215 unsigned ReturnReg) {
216 OS << "\t.frame\t$"
217 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
218 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000219 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
220}
221
Toma Tabacu85618b32014-08-19 14:22:52 +0000222void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
223 OS << "\t.set arch=" << Arch << "\n";
224 MipsTargetStreamer::emitDirectiveSetArch(Arch);
225}
226
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000227void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
228 OS << "\t.set\tmips0\n";
229 MipsTargetStreamer::emitDirectiveSetMips0();
230}
Toma Tabacu26647792014-09-09 12:52:14 +0000231
Daniel Sandersf0df2212014-08-04 12:20:00 +0000232void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
233 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000234 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000235}
236
237void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
238 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000239 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000240}
241
242void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
243 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000244 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000245}
246
247void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
248 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000249 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000250}
251
252void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
253 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000254 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000255}
256
257void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
258 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000259 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000260}
261
Vladimir Medic615b26e2014-03-04 09:54:09 +0000262void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
263 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000264 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000265}
266
Daniel Sanders17793142015-02-18 16:24:50 +0000267void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
268 OS << "\t.set\tmips32r3\n";
269 MipsTargetStreamer::emitDirectiveSetMips32R3();
270}
271
272void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
273 OS << "\t.set\tmips32r5\n";
274 MipsTargetStreamer::emitDirectiveSetMips32R5();
275}
276
Daniel Sandersf0df2212014-08-04 12:20:00 +0000277void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
278 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000279 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000280}
281
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000282void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
283 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000284 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000285}
286
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000287void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
288 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000289 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000290}
291
Daniel Sanders17793142015-02-18 16:24:50 +0000292void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
293 OS << "\t.set\tmips64r3\n";
294 MipsTargetStreamer::emitDirectiveSetMips64R3();
295}
296
297void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
298 OS << "\t.set\tmips64r5\n";
299 MipsTargetStreamer::emitDirectiveSetMips64R5();
300}
301
Daniel Sandersf0df2212014-08-04 12:20:00 +0000302void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
303 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000304 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000305}
306
Vladimir Medic27c398e2014-03-05 11:05:09 +0000307void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
308 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000309 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000310}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000311
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000312void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
313 OS << "\t.set\tnodsp\n";
314 MipsTargetStreamer::emitDirectiveSetNoDsp();
315}
316
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000317void MipsTargetAsmStreamer::emitDirectiveSetPop() {
318 OS << "\t.set\tpop\n";
319 MipsTargetStreamer::emitDirectiveSetPop();
320}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000321
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000322void MipsTargetAsmStreamer::emitDirectiveSetPush() {
323 OS << "\t.set\tpush\n";
324 MipsTargetStreamer::emitDirectiveSetPush();
325}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000326
Toma Tabacu29696502015-06-02 09:48:04 +0000327void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
328 OS << "\t.set\tsoftfloat\n";
329 MipsTargetStreamer::emitDirectiveSetSoftFloat();
330}
331
332void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
333 OS << "\t.set\thardfloat\n";
334 MipsTargetStreamer::emitDirectiveSetHardFloat();
335}
336
Rafael Espindola25fa2912014-01-27 04:33:11 +0000337// Print a 32 bit hex number with all numbers.
338static void printHex32(unsigned Value, raw_ostream &OS) {
339 OS << "0x";
340 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000341 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000342}
343
344void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
345 int CPUTopSavedRegOff) {
346 OS << "\t.mask \t";
347 printHex32(CPUBitmask, OS);
348 OS << ',' << CPUTopSavedRegOff << '\n';
349}
350
351void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
352 int FPUTopSavedRegOff) {
353 OS << "\t.fmask\t";
354 printHex32(FPUBitmask, OS);
355 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000356}
357
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000358void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000359 OS << "\t.cpload\t$"
360 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000361 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000362}
363
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000364void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
365 int RegOrOffset,
366 const MCSymbol &Sym,
367 bool IsReg) {
368 OS << "\t.cpsetup\t$"
369 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
370
371 if (IsReg)
372 OS << "$"
373 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
374 else
375 OS << RegOrOffset;
376
377 OS << ", ";
378
379 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000380 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000381}
382
Daniel Sanders7e527422014-07-10 13:38:23 +0000383void MipsTargetAsmStreamer::emitDirectiveModuleFP(
384 MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
385 MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000386
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000387 OS << "\t.module\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000388 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000389}
390
Daniel Sanders7e527422014-07-10 13:38:23 +0000391void MipsTargetAsmStreamer::emitDirectiveSetFp(
392 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000393 MipsTargetStreamer::emitDirectiveSetFp(Value);
394
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000395 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000396 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000397}
398
Daniel Sanders7e527422014-07-10 13:38:23 +0000399void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
400 bool IsO32ABI) {
401 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
402
403 OS << "\t.module\t" << (Enabled ? "" : "no") << "oddspreg\n";
404}
405
Jack Carter0cd3c192014-01-06 23:27:31 +0000406// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000407MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
408 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000409 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000410 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000411 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000412
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000413 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000414
415 // Set the header flags that we can in the constructor.
416 // FIXME: This is a fairly terrible hack. We set the rest
417 // of these in the destructor. The problem here is two-fold:
418 //
419 // a: Some of the eflags can be set/reset by directives.
420 // b: There aren't any usage paths that initialize the ABI
421 // pointer until after we initialize either an assembler
422 // or the target machine.
423 // We can fix this by making the target streamer construct
424 // the ABI, but this is fraught with wide ranging dependency
425 // issues as well.
426 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000427
428 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000429 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000430 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000431 else if (Features[Mips::FeatureMips64r2] ||
432 Features[Mips::FeatureMips64r3] ||
433 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000434 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000435 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000436 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000437 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000438 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000439 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000440 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000441 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000442 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000443 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000444 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000445 else if (Features[Mips::FeatureMips32r2] ||
446 Features[Mips::FeatureMips32r3] ||
447 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000448 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000449 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000450 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000451 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000452 EFlags |= ELF::EF_MIPS_ARCH_2;
453 else
454 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000455
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000456 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000457 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000458 EFlags |= ELF::EF_MIPS_NAN2008;
459
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000460 // -mabicalls and -mplt are not implemented but we should act as if they were
461 // given.
462 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000463
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000464 MCA.setELFHeaderEFlags(EFlags);
465}
Jack Carter86ac5c12013-11-18 23:55:27 +0000466
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000467void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
468 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000469 if (!isMicroMipsEnabled())
470 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000471 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000472 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000473 if (Type != ELF::STT_FUNC)
474 return;
475
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000476 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000477}
478
Rafael Espindola972e71a2014-01-31 23:10:26 +0000479void MipsTargetELFStreamer::finish() {
480 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000481 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000482
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000483 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000484 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000485 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000486 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000487 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000488 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000489 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000490
Rafael Espindola967d6a62015-05-21 21:02:35 +0000491 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
492 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
493 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000494
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000495 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000496
497 // Update e_header flags. See the FIXME and comment above in
498 // the constructor for a full rundown on this.
499 unsigned EFlags = MCA.getELFHeaderEFlags();
500
501 // ABI
502 // N64 does not require any ABI bits.
503 if (getABI().IsO32())
504 EFlags |= ELF::EF_MIPS_ABI_O32;
505 else if (getABI().IsN32())
506 EFlags |= ELF::EF_MIPS_ABI2;
507
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000508 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000509 if (getABI().IsO32())
510 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000511 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000512 EFlags |= ELF::EF_MIPS_32BITMODE;
513
514 // If we've set the cpic eflag and we're n64, go ahead and set the pic
515 // one as well.
516 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
517 EFlags |= ELF::EF_MIPS_PIC;
518
519 MCA.setELFHeaderEFlags(EFlags);
520
Daniel Sanders68c37472014-07-21 13:30:55 +0000521 // Emit all the option records.
522 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
523 // .reginfo.
524 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
525 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000526
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000527 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000528}
529
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000530void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
531 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000532 // If on rhs is micromips symbol then mark Symbol as microMips.
533 if (Value->getKind() != MCExpr::SymbolRef)
534 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000535 const auto &RhsSym = cast<MCSymbolELF>(
536 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000537
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000538 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000539 return;
540
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000541 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000542}
543
Jack Carter86ac5c12013-11-18 23:55:27 +0000544MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000545 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000546}
547
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000548void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
549 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000550
551 MCAssembler &MCA = getStreamer().getAssembler();
552 unsigned Flags = MCA.getELFHeaderEFlags();
553 Flags |= ELF::EF_MIPS_MICROMIPS;
554 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000555 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000556}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000557
558void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
559 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000560 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000561}
562
Rafael Espindola6633d572014-01-14 18:57:12 +0000563void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000564 MCAssembler &MCA = getStreamer().getAssembler();
565 unsigned Flags = MCA.getELFHeaderEFlags();
566 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
567 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000568 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000569}
570
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000571void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000572 MCAssembler &MCA = getStreamer().getAssembler();
573 unsigned Flags = MCA.getELFHeaderEFlags();
574 Flags |= ELF::EF_MIPS_NOREORDER;
575 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000576 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000577}
578
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000579void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000580 MCAssembler &MCA = getStreamer().getAssembler();
581 MCContext &Context = MCA.getContext();
582 MCStreamer &OS = getStreamer();
583
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000584 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
585 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000586
587 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000588 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000589
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000590 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000591 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000592
593 OS.PushSection();
594
595 OS.SwitchSection(Sec);
596
597 OS.EmitValueImpl(ExprRef, 4);
598
599 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
600 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
601
602 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
603 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
604
605 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
606 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
607 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
608
609 // The .end directive marks the end of a procedure. Invalidate
610 // the information gathered up until this point.
611 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
612
613 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000614}
615
Rafael Espindola6633d572014-01-14 18:57:12 +0000616void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000617 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000618}
619
Jack Carter0cd3c192014-01-06 23:27:31 +0000620void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
621 MCAssembler &MCA = getStreamer().getAssembler();
622 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000623 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000624 MCA.setELFHeaderEFlags(Flags);
625}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000626
627void MipsTargetELFStreamer::emitDirectiveNaN2008() {
628 MCAssembler &MCA = getStreamer().getAssembler();
629 unsigned Flags = MCA.getELFHeaderEFlags();
630 Flags |= ELF::EF_MIPS_NAN2008;
631 MCA.setELFHeaderEFlags(Flags);
632}
633
634void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
635 MCAssembler &MCA = getStreamer().getAssembler();
636 unsigned Flags = MCA.getELFHeaderEFlags();
637 Flags &= ~ELF::EF_MIPS_NAN2008;
638 MCA.setELFHeaderEFlags(Flags);
639}
640
Jack Carter0cd3c192014-01-06 23:27:31 +0000641void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
642 MCAssembler &MCA = getStreamer().getAssembler();
643 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000644 // This option overrides other PIC options like -KPIC.
645 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000646 Flags &= ~ELF::EF_MIPS_PIC;
647 MCA.setELFHeaderEFlags(Flags);
648}
Rafael Espindola054234f2014-01-27 03:53:56 +0000649
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000650void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
651 MCAssembler &MCA = getStreamer().getAssembler();
652 unsigned Flags = MCA.getELFHeaderEFlags();
653 Pic = true;
654 // NOTE: We are following the GAS behaviour here which means the directive
655 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
656 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
657 // EF_MIPS_CPIC to be mutually exclusive.
658 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
659 MCA.setELFHeaderEFlags(Flags);
660}
661
Toma Tabacu9ca50962015-04-16 09:53:47 +0000662void MipsTargetELFStreamer::emitDirectiveInsn() {
663 MipsTargetStreamer::emitDirectiveInsn();
664 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
665 MEF.createPendingLabelRelocs();
666}
667
Rafael Espindola054234f2014-01-27 03:53:56 +0000668void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000669 unsigned ReturnReg_) {
670 MCContext &Context = getStreamer().getAssembler().getContext();
671 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
672
673 FrameInfoSet = true;
674 FrameReg = RegInfo->getEncodingValue(StackReg);
675 FrameOffset = StackSize;
676 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000677}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000678
679void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
680 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000681 GPRInfoSet = true;
682 GPRBitMask = CPUBitmask;
683 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000684}
685
686void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
687 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000688 FPRInfoSet = true;
689 FPRBitMask = FPUBitmask;
690 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000691}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000692
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000693void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000694 // .cpload $reg
695 // This directive expands to:
696 // lui $gp, %hi(_gp_disp)
697 // addui $gp, $gp, %lo(_gp_disp)
698 // addu $gp, $gp, $reg
699 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000700 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000701 return;
702
703 // There's a GNU extension controlled by -mno-shared that allows
704 // locally-binding symbols to be accessed using absolute addresses.
705 // This is currently not supported. When supported -mno-shared makes
706 // .cpload expand to:
707 // lui $gp, %hi(__gnu_local_gp)
708 // addiu $gp, $gp, %lo(__gnu_local_gp)
709
710 StringRef SymName("_gp_disp");
711 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000712 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000713 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000714
715 MCInst TmpInst;
716 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000717 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000718 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000719 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000720 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000721 getStreamer().EmitInstruction(TmpInst, STI);
722
723 TmpInst.clear();
724
725 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000726 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
727 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000728 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000729 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000730 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000731 getStreamer().EmitInstruction(TmpInst, STI);
732
733 TmpInst.clear();
734
735 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000736 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
737 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
738 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000739 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000740
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000741 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000742}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000743
744void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
745 int RegOrOffset,
746 const MCSymbol &Sym,
747 bool IsReg) {
748 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000749 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000750 return;
751
752 MCAssembler &MCA = getStreamer().getAssembler();
753 MCInst Inst;
754
755 // Either store the old $gp in a register or on the stack
756 if (IsReg) {
757 // move $save, $gpreg
758 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000759 Inst.addOperand(MCOperand::createReg(RegOrOffset));
760 Inst.addOperand(MCOperand::createReg(Mips::GP));
761 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000762 } else {
763 // sd $gpreg, offset($sp)
764 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000765 Inst.addOperand(MCOperand::createReg(Mips::GP));
766 Inst.addOperand(MCOperand::createReg(Mips::SP));
767 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000768 }
769 getStreamer().EmitInstruction(Inst, STI);
770 Inst.clear();
771
Jim Grosbach13760bd2015-05-30 01:25:56 +0000772 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000773 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000774 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000775 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
776
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000777 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
778 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000779 Inst.addOperand(MCOperand::createReg(Mips::GP));
780 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000781 getStreamer().EmitInstruction(Inst, STI);
782 Inst.clear();
783
784 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
785 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000786 Inst.addOperand(MCOperand::createReg(Mips::GP));
787 Inst.addOperand(MCOperand::createReg(Mips::GP));
788 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000789 getStreamer().EmitInstruction(Inst, STI);
790 Inst.clear();
791
792 // daddu $gp, $gp, $funcreg
793 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000794 Inst.addOperand(MCOperand::createReg(Mips::GP));
795 Inst.addOperand(MCOperand::createReg(Mips::GP));
796 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000797 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000798
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000799 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000800}
801
802void MipsTargetELFStreamer::emitMipsAbiFlags() {
803 MCAssembler &MCA = getStreamer().getAssembler();
804 MCContext &Context = MCA.getContext();
805 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000806 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000807 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000808 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000809 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000810 OS.SwitchSection(Sec);
811
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000812 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000813}
Daniel Sanders7e527422014-07-10 13:38:23 +0000814
815void MipsTargetELFStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
816 bool IsO32ABI) {
817 MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
818
819 ABIFlagsSection.OddSPReg = Enabled;
820}