blob: bf74ad64757f2c6197f56acc18d9200d075d748c [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
Toma Tabacu3c499582015-06-25 10:56:57 +0000106void MipsTargetStreamer::emitDirectiveModuleOddSPReg() {
107 if (!ABIFlagsSection.OddSPReg && !ABIFlagsSection.Is32BitABI)
Daniel Sanders7e527422014-07-10 13:38:23 +0000108 report_fatal_error("+nooddspreg is only valid for O32");
109}
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000110void MipsTargetStreamer::emitDirectiveSetFp(
111 MipsABIFlagsSection::FpABIKind Value) {
112 forbidModuleDirective();
113}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000114
115MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
116 formatted_raw_ostream &OS)
117 : MipsTargetStreamer(S), OS(OS) {}
Jack Carter6ef6cc52013-11-19 20:53:28 +0000118
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000119void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
120 OS << "\t.set\tmicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000121 forbidModuleDirective();
Jack Carter6ef6cc52013-11-19 20:53:28 +0000122}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000123
124void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
125 OS << "\t.set\tnomicromips\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000126 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000127}
128
Rafael Espindola6633d572014-01-14 18:57:12 +0000129void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
130 OS << "\t.set\tmips16\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000131 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000132}
133
134void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
135 OS << "\t.set\tnomips16\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000136 MipsTargetStreamer::emitDirectiveSetNoMips16();
Rafael Espindola6633d572014-01-14 18:57:12 +0000137}
138
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000139void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
140 OS << "\t.set\treorder\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000141 MipsTargetStreamer::emitDirectiveSetReorder();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000142}
143
144void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
145 OS << "\t.set\tnoreorder\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000146 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000147}
148
149void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
150 OS << "\t.set\tmacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000151 MipsTargetStreamer::emitDirectiveSetMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000152}
153
154void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
155 OS << "\t.set\tnomacro\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000156 MipsTargetStreamer::emitDirectiveSetNoMacro();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000157}
158
Daniel Sanders44934432014-08-07 12:03:36 +0000159void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
160 OS << "\t.set\tmsa\n";
161 MipsTargetStreamer::emitDirectiveSetMsa();
162}
163
164void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
165 OS << "\t.set\tnomsa\n";
166 MipsTargetStreamer::emitDirectiveSetNoMsa();
167}
168
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000169void MipsTargetAsmStreamer::emitDirectiveSetAt() {
170 OS << "\t.set\tat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000171 MipsTargetStreamer::emitDirectiveSetAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000172}
173
Toma Tabacu16a74492015-02-13 10:30:57 +0000174void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
175 OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
176 MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
177}
178
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000179void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
180 OS << "\t.set\tnoat\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000181 MipsTargetStreamer::emitDirectiveSetNoAt();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000182}
183
184void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
185 OS << "\t.end\t" << Name << '\n';
186}
187
Rafael Espindola6633d572014-01-14 18:57:12 +0000188void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
189 OS << "\t.ent\t" << Symbol.getName() << '\n';
190}
191
Jack Carter0cd3c192014-01-06 23:27:31 +0000192void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000193
194void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
195
196void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
197 OS << "\t.nan\tlegacy\n";
198}
199
Jack Carter0cd3c192014-01-06 23:27:31 +0000200void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
201 OS << "\t.option\tpic0\n";
202}
203
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000204void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
205 OS << "\t.option\tpic2\n";
206}
207
Toma Tabacu9ca50962015-04-16 09:53:47 +0000208void MipsTargetAsmStreamer::emitDirectiveInsn() {
209 MipsTargetStreamer::emitDirectiveInsn();
210 OS << "\t.insn\n";
211}
212
Rafael Espindola054234f2014-01-27 03:53:56 +0000213void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
214 unsigned ReturnReg) {
215 OS << "\t.frame\t$"
216 << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
217 << StackSize << ",$"
Rafael Espindola25fa2912014-01-27 04:33:11 +0000218 << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
219}
220
Toma Tabacu85618b32014-08-19 14:22:52 +0000221void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
222 OS << "\t.set arch=" << Arch << "\n";
223 MipsTargetStreamer::emitDirectiveSetArch(Arch);
224}
225
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000226void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
227 OS << "\t.set\tmips0\n";
228 MipsTargetStreamer::emitDirectiveSetMips0();
229}
Toma Tabacu26647792014-09-09 12:52:14 +0000230
Daniel Sandersf0df2212014-08-04 12:20:00 +0000231void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
232 OS << "\t.set\tmips1\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000233 MipsTargetStreamer::emitDirectiveSetMips1();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000234}
235
236void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
237 OS << "\t.set\tmips2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000238 MipsTargetStreamer::emitDirectiveSetMips2();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000239}
240
241void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
242 OS << "\t.set\tmips3\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000243 MipsTargetStreamer::emitDirectiveSetMips3();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000244}
245
246void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
247 OS << "\t.set\tmips4\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000248 MipsTargetStreamer::emitDirectiveSetMips4();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000249}
250
251void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
252 OS << "\t.set\tmips5\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000253 MipsTargetStreamer::emitDirectiveSetMips5();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000254}
255
256void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
257 OS << "\t.set\tmips32\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000258 MipsTargetStreamer::emitDirectiveSetMips32();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000259}
260
Vladimir Medic615b26e2014-03-04 09:54:09 +0000261void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
262 OS << "\t.set\tmips32r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000263 MipsTargetStreamer::emitDirectiveSetMips32R2();
Vladimir Medic615b26e2014-03-04 09:54:09 +0000264}
265
Daniel Sanders17793142015-02-18 16:24:50 +0000266void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
267 OS << "\t.set\tmips32r3\n";
268 MipsTargetStreamer::emitDirectiveSetMips32R3();
269}
270
271void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
272 OS << "\t.set\tmips32r5\n";
273 MipsTargetStreamer::emitDirectiveSetMips32R5();
274}
275
Daniel Sandersf0df2212014-08-04 12:20:00 +0000276void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
277 OS << "\t.set\tmips32r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000278 MipsTargetStreamer::emitDirectiveSetMips32R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000279}
280
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000281void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
282 OS << "\t.set\tmips64\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000283 MipsTargetStreamer::emitDirectiveSetMips64();
Matheus Almeida3b9c63d2014-03-26 15:14:32 +0000284}
285
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000286void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
287 OS << "\t.set\tmips64r2\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000288 MipsTargetStreamer::emitDirectiveSetMips64R2();
Matheus Almeidaa2cd0092014-03-26 14:52:22 +0000289}
290
Daniel Sanders17793142015-02-18 16:24:50 +0000291void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
292 OS << "\t.set\tmips64r3\n";
293 MipsTargetStreamer::emitDirectiveSetMips64R3();
294}
295
296void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
297 OS << "\t.set\tmips64r5\n";
298 MipsTargetStreamer::emitDirectiveSetMips64R5();
299}
300
Daniel Sandersf0df2212014-08-04 12:20:00 +0000301void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
302 OS << "\t.set\tmips64r6\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000303 MipsTargetStreamer::emitDirectiveSetMips64R6();
Daniel Sandersf0df2212014-08-04 12:20:00 +0000304}
305
Vladimir Medic27c398e2014-03-05 11:05:09 +0000306void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
307 OS << "\t.set\tdsp\n";
Toma Tabacu88f05ce2014-08-13 12:48:12 +0000308 MipsTargetStreamer::emitDirectiveSetDsp();
Vladimir Medic27c398e2014-03-05 11:05:09 +0000309}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000310
Toma Tabacu351b2fe2014-09-17 09:01:54 +0000311void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
312 OS << "\t.set\tnodsp\n";
313 MipsTargetStreamer::emitDirectiveSetNoDsp();
314}
315
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000316void MipsTargetAsmStreamer::emitDirectiveSetPop() {
317 OS << "\t.set\tpop\n";
318 MipsTargetStreamer::emitDirectiveSetPop();
319}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000320
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000321void MipsTargetAsmStreamer::emitDirectiveSetPush() {
322 OS << "\t.set\tpush\n";
323 MipsTargetStreamer::emitDirectiveSetPush();
324}
Toma Tabacu9db22db2014-09-09 10:15:38 +0000325
Toma Tabacu29696502015-06-02 09:48:04 +0000326void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() {
327 OS << "\t.set\tsoftfloat\n";
328 MipsTargetStreamer::emitDirectiveSetSoftFloat();
329}
330
331void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() {
332 OS << "\t.set\thardfloat\n";
333 MipsTargetStreamer::emitDirectiveSetHardFloat();
334}
335
Rafael Espindola25fa2912014-01-27 04:33:11 +0000336// Print a 32 bit hex number with all numbers.
337static void printHex32(unsigned Value, raw_ostream &OS) {
338 OS << "0x";
339 for (int i = 7; i >= 0; i--)
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000340 OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
Rafael Espindola25fa2912014-01-27 04:33:11 +0000341}
342
343void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
344 int CPUTopSavedRegOff) {
345 OS << "\t.mask \t";
346 printHex32(CPUBitmask, OS);
347 OS << ',' << CPUTopSavedRegOff << '\n';
348}
349
350void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
351 int FPUTopSavedRegOff) {
352 OS << "\t.fmask\t";
353 printHex32(FPUBitmask, OS);
354 OS << "," << FPUTopSavedRegOff << '\n';
Rafael Espindola054234f2014-01-27 03:53:56 +0000355}
356
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000357void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000358 OS << "\t.cpload\t$"
359 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000360 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000361}
362
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000363void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
364 int RegOrOffset,
365 const MCSymbol &Sym,
366 bool IsReg) {
367 OS << "\t.cpsetup\t$"
368 << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
369
370 if (IsReg)
371 OS << "$"
372 << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
373 else
374 OS << RegOrOffset;
375
376 OS << ", ";
377
378 OS << Sym.getName() << "\n";
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000379 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000380}
381
Daniel Sanders7e527422014-07-10 13:38:23 +0000382void MipsTargetAsmStreamer::emitDirectiveModuleFP(
383 MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
384 MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000385
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000386 OS << "\t.module\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000387 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000388}
389
Daniel Sanders7e527422014-07-10 13:38:23 +0000390void MipsTargetAsmStreamer::emitDirectiveSetFp(
391 MipsABIFlagsSection::FpABIKind Value) {
Toma Tabacu4e0cf8e2015-03-06 12:15:12 +0000392 MipsTargetStreamer::emitDirectiveSetFp(Value);
393
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000394 OS << "\t.set\tfp=";
Daniel Sanders7e527422014-07-10 13:38:23 +0000395 OS << ABIFlagsSection.getFpABIString(Value) << "\n";
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000396}
397
Toma Tabacu3c499582015-06-25 10:56:57 +0000398void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() {
399 MipsTargetStreamer::emitDirectiveModuleOddSPReg();
Daniel Sanders7e527422014-07-10 13:38:23 +0000400
Toma Tabacu3c499582015-06-25 10:56:57 +0000401 OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
Daniel Sanders7e527422014-07-10 13:38:23 +0000402}
403
Jack Carter0cd3c192014-01-06 23:27:31 +0000404// This part is for ELF object output.
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000405MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
406 const MCSubtargetInfo &STI)
Rafael Espindola972e71a2014-01-31 23:10:26 +0000407 : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000408 MCAssembler &MCA = getStreamer().getAssembler();
Simon Atanasyanc99ce682015-03-24 12:24:56 +0000409 Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000410
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000411 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000412
413 // Set the header flags that we can in the constructor.
414 // FIXME: This is a fairly terrible hack. We set the rest
415 // of these in the destructor. The problem here is two-fold:
416 //
417 // a: Some of the eflags can be set/reset by directives.
418 // b: There aren't any usage paths that initialize the ABI
419 // pointer until after we initialize either an assembler
420 // or the target machine.
421 // We can fix this by making the target streamer construct
422 // the ABI, but this is fraught with wide ranging dependency
423 // issues as well.
424 unsigned EFlags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000425
426 // Architecture
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000427 if (Features[Mips::FeatureMips64r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000428 EFlags |= ELF::EF_MIPS_ARCH_64R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000429 else if (Features[Mips::FeatureMips64r2] ||
430 Features[Mips::FeatureMips64r3] ||
431 Features[Mips::FeatureMips64r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000432 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000433 else if (Features[Mips::FeatureMips64])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000434 EFlags |= ELF::EF_MIPS_ARCH_64;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000435 else if (Features[Mips::FeatureMips5])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000436 EFlags |= ELF::EF_MIPS_ARCH_5;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000437 else if (Features[Mips::FeatureMips4])
Daniel Sandersf7b32292014-04-03 12:13:36 +0000438 EFlags |= ELF::EF_MIPS_ARCH_4;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000439 else if (Features[Mips::FeatureMips3])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000440 EFlags |= ELF::EF_MIPS_ARCH_3;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000441 else if (Features[Mips::FeatureMips32r6])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000442 EFlags |= ELF::EF_MIPS_ARCH_32R6;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000443 else if (Features[Mips::FeatureMips32r2] ||
444 Features[Mips::FeatureMips32r3] ||
445 Features[Mips::FeatureMips32r5])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000446 EFlags |= ELF::EF_MIPS_ARCH_32R2;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000447 else if (Features[Mips::FeatureMips32])
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000448 EFlags |= ELF::EF_MIPS_ARCH_32;
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000449 else if (Features[Mips::FeatureMips2])
Daniel Sanders950f48d2014-07-04 15:21:53 +0000450 EFlags |= ELF::EF_MIPS_ARCH_2;
451 else
452 EFlags |= ELF::EF_MIPS_ARCH_1;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000453
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000454 // Other options.
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000455 if (Features[Mips::FeatureNaN2008])
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000456 EFlags |= ELF::EF_MIPS_NAN2008;
457
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000458 // -mabicalls and -mplt are not implemented but we should act as if they were
459 // given.
460 EFlags |= ELF::EF_MIPS_CPIC;
Daniel Sanders16ec6c12014-07-17 09:52:56 +0000461
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000462 MCA.setELFHeaderEFlags(EFlags);
463}
Jack Carter86ac5c12013-11-18 23:55:27 +0000464
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000465void MipsTargetELFStreamer::emitLabel(MCSymbol *S) {
466 auto *Symbol = cast<MCSymbolELF>(S);
Rafael Espindola26e917c2014-01-15 03:07:12 +0000467 if (!isMicroMipsEnabled())
468 return;
Rafael Espindolac73aed12015-06-03 19:03:11 +0000469 getStreamer().getAssembler().registerSymbol(*Symbol);
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000470 uint8_t Type = Symbol->getType();
Rafael Espindola26e917c2014-01-15 03:07:12 +0000471 if (Type != ELF::STT_FUNC)
472 return;
473
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000474 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000475}
476
Rafael Espindola972e71a2014-01-31 23:10:26 +0000477void MipsTargetELFStreamer::finish() {
478 MCAssembler &MCA = getStreamer().getAssembler();
Daniel Sanders68c37472014-07-21 13:30:55 +0000479 const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000480
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000481 // .bss, .text and .data are always at least 16-byte aligned.
Rafael Espindola967d6a62015-05-21 21:02:35 +0000482 MCSection &TextSection = *OFI.getTextSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000483 MCA.registerSection(TextSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000484 MCSection &DataSection = *OFI.getDataSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000485 MCA.registerSection(DataSection);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000486 MCSection &BSSSection = *OFI.getBSSSection();
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000487 MCA.registerSection(BSSSection);
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000488
Rafael Espindola967d6a62015-05-21 21:02:35 +0000489 TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
490 DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
491 BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
Daniel Sanders41ffa5d2014-07-14 15:05:51 +0000492
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000493 const FeatureBitset &Features = STI.getFeatureBits();
Eric Christophera5762812015-01-26 17:33:46 +0000494
495 // Update e_header flags. See the FIXME and comment above in
496 // the constructor for a full rundown on this.
497 unsigned EFlags = MCA.getELFHeaderEFlags();
498
499 // ABI
500 // N64 does not require any ABI bits.
501 if (getABI().IsO32())
502 EFlags |= ELF::EF_MIPS_ABI_O32;
503 else if (getABI().IsN32())
504 EFlags |= ELF::EF_MIPS_ABI2;
505
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000506 if (Features[Mips::FeatureGP64Bit]) {
Eric Christophera5762812015-01-26 17:33:46 +0000507 if (getABI().IsO32())
508 EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000509 } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
Eric Christophera5762812015-01-26 17:33:46 +0000510 EFlags |= ELF::EF_MIPS_32BITMODE;
511
512 // If we've set the cpic eflag and we're n64, go ahead and set the pic
513 // one as well.
514 if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
515 EFlags |= ELF::EF_MIPS_PIC;
516
517 MCA.setELFHeaderEFlags(EFlags);
518
Daniel Sanders68c37472014-07-21 13:30:55 +0000519 // Emit all the option records.
520 // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
521 // .reginfo.
522 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
523 MEF.EmitMipsOptionRecords();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000524
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000525 emitMipsAbiFlags();
Rafael Espindola972e71a2014-01-31 23:10:26 +0000526}
527
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000528void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) {
529 auto *Symbol = cast<MCSymbolELF>(S);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000530 // If on rhs is micromips symbol then mark Symbol as microMips.
531 if (Value->getKind() != MCExpr::SymbolRef)
532 return;
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000533 const auto &RhsSym = cast<MCSymbolELF>(
534 static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
Toma Tabacu2cc44f52015-04-16 13:37:32 +0000535
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000536 if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000537 return;
538
Rafael Espindola8c006ee2015-06-04 05:59:23 +0000539 Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
Zoran Jovanovic28221d82014-03-20 09:44:49 +0000540}
541
Jack Carter86ac5c12013-11-18 23:55:27 +0000542MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000543 return static_cast<MCELFStreamer &>(Streamer);
Jack Carter86ac5c12013-11-18 23:55:27 +0000544}
545
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000546void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
547 MicroMipsEnabled = true;
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000548
549 MCAssembler &MCA = getStreamer().getAssembler();
550 unsigned Flags = MCA.getELFHeaderEFlags();
551 Flags |= ELF::EF_MIPS_MICROMIPS;
552 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000553 forbidModuleDirective();
Jack Carter86ac5c12013-11-18 23:55:27 +0000554}
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000555
556void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
557 MicroMipsEnabled = false;
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000558 forbidModuleDirective();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000559}
560
Rafael Espindola6633d572014-01-14 18:57:12 +0000561void MipsTargetELFStreamer::emitDirectiveSetMips16() {
Rafael Espindolae7583752014-01-24 16:13:20 +0000562 MCAssembler &MCA = getStreamer().getAssembler();
563 unsigned Flags = MCA.getELFHeaderEFlags();
564 Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
565 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000566 forbidModuleDirective();
Rafael Espindola6633d572014-01-14 18:57:12 +0000567}
568
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000569void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000570 MCAssembler &MCA = getStreamer().getAssembler();
571 unsigned Flags = MCA.getELFHeaderEFlags();
572 Flags |= ELF::EF_MIPS_NOREORDER;
573 MCA.setELFHeaderEFlags(Flags);
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000574 forbidModuleDirective();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000575}
576
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000577void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000578 MCAssembler &MCA = getStreamer().getAssembler();
579 MCContext &Context = MCA.getContext();
580 MCStreamer &OS = getStreamer();
581
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000582 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
583 ELF::SHF_ALLOC | ELF::SHT_REL);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000584
585 const MCSymbolRefExpr *ExprRef =
Jim Grosbach13760bd2015-05-30 01:25:56 +0000586 MCSymbolRefExpr::create(Name, MCSymbolRefExpr::VK_None, Context);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000587
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000588 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000589 Sec->setAlignment(4);
Daniel Sandersd97a6342014-08-13 10:07:34 +0000590
591 OS.PushSection();
592
593 OS.SwitchSection(Sec);
594
595 OS.EmitValueImpl(ExprRef, 4);
596
597 OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
598 OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
599
600 OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
601 OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
602
603 OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
604 OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
605 OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
606
607 // The .end directive marks the end of a procedure. Invalidate
608 // the information gathered up until this point.
609 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
610
611 OS.PopSection();
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000612}
613
Rafael Espindola6633d572014-01-14 18:57:12 +0000614void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000615 GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
Rafael Espindola6633d572014-01-14 18:57:12 +0000616}
617
Jack Carter0cd3c192014-01-06 23:27:31 +0000618void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
619 MCAssembler &MCA = getStreamer().getAssembler();
620 unsigned Flags = MCA.getELFHeaderEFlags();
Rafael Espindolacb1953f2014-01-26 06:57:13 +0000621 Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
Jack Carter0cd3c192014-01-06 23:27:31 +0000622 MCA.setELFHeaderEFlags(Flags);
623}
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000624
625void MipsTargetELFStreamer::emitDirectiveNaN2008() {
626 MCAssembler &MCA = getStreamer().getAssembler();
627 unsigned Flags = MCA.getELFHeaderEFlags();
628 Flags |= ELF::EF_MIPS_NAN2008;
629 MCA.setELFHeaderEFlags(Flags);
630}
631
632void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
633 MCAssembler &MCA = getStreamer().getAssembler();
634 unsigned Flags = MCA.getELFHeaderEFlags();
635 Flags &= ~ELF::EF_MIPS_NAN2008;
636 MCA.setELFHeaderEFlags(Flags);
637}
638
Jack Carter0cd3c192014-01-06 23:27:31 +0000639void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
640 MCAssembler &MCA = getStreamer().getAssembler();
641 unsigned Flags = MCA.getELFHeaderEFlags();
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000642 // This option overrides other PIC options like -KPIC.
643 Pic = false;
Jack Carter0cd3c192014-01-06 23:27:31 +0000644 Flags &= ~ELF::EF_MIPS_PIC;
645 MCA.setELFHeaderEFlags(Flags);
646}
Rafael Espindola054234f2014-01-27 03:53:56 +0000647
Matheus Almeidaf79b2812014-03-26 13:40:29 +0000648void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
649 MCAssembler &MCA = getStreamer().getAssembler();
650 unsigned Flags = MCA.getELFHeaderEFlags();
651 Pic = true;
652 // NOTE: We are following the GAS behaviour here which means the directive
653 // 'pic2' also sets the CPIC bit in the ELF header. This is different from
654 // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
655 // EF_MIPS_CPIC to be mutually exclusive.
656 Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
657 MCA.setELFHeaderEFlags(Flags);
658}
659
Toma Tabacu9ca50962015-04-16 09:53:47 +0000660void MipsTargetELFStreamer::emitDirectiveInsn() {
661 MipsTargetStreamer::emitDirectiveInsn();
662 MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
663 MEF.createPendingLabelRelocs();
664}
665
Rafael Espindola054234f2014-01-27 03:53:56 +0000666void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
Daniel Sandersd97a6342014-08-13 10:07:34 +0000667 unsigned ReturnReg_) {
668 MCContext &Context = getStreamer().getAssembler().getContext();
669 const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
670
671 FrameInfoSet = true;
672 FrameReg = RegInfo->getEncodingValue(StackReg);
673 FrameOffset = StackSize;
674 ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
Rafael Espindola054234f2014-01-27 03:53:56 +0000675}
Rafael Espindola25fa2912014-01-27 04:33:11 +0000676
677void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
678 int CPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000679 GPRInfoSet = true;
680 GPRBitMask = CPUBitmask;
681 GPROffset = CPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000682}
683
684void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
685 int FPUTopSavedRegOff) {
Daniel Sandersd97a6342014-08-13 10:07:34 +0000686 FPRInfoSet = true;
687 FPRBitMask = FPUBitmask;
688 FPROffset = FPUTopSavedRegOff;
Rafael Espindola25fa2912014-01-27 04:33:11 +0000689}
Vladimir Medic615b26e2014-03-04 09:54:09 +0000690
Toma Tabacuc4c202a2014-10-01 14:53:19 +0000691void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000692 // .cpload $reg
693 // This directive expands to:
694 // lui $gp, %hi(_gp_disp)
695 // addui $gp, $gp, %lo(_gp_disp)
696 // addu $gp, $gp, $reg
697 // when support for position independent code is enabled.
Eric Christophera5762812015-01-26 17:33:46 +0000698 if (!Pic || (getABI().IsN32() || getABI().IsN64()))
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000699 return;
700
701 // There's a GNU extension controlled by -mno-shared that allows
702 // locally-binding symbols to be accessed using absolute addresses.
703 // This is currently not supported. When supported -mno-shared makes
704 // .cpload expand to:
705 // lui $gp, %hi(__gnu_local_gp)
706 // addiu $gp, $gp, %lo(__gnu_local_gp)
707
708 StringRef SymName("_gp_disp");
709 MCAssembler &MCA = getStreamer().getAssembler();
Jim Grosbach6f482002015-05-18 18:43:14 +0000710 MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
Rafael Espindolab5d316b2015-05-29 20:21:02 +0000711 MCA.registerSymbol(*GP_Disp);
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000712
713 MCInst TmpInst;
714 TmpInst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000715 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000716 const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000717 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000718 TmpInst.addOperand(MCOperand::createExpr(HiSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000719 getStreamer().EmitInstruction(TmpInst, STI);
720
721 TmpInst.clear();
722
723 TmpInst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000724 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
725 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
Jim Grosbach13760bd2015-05-30 01:25:56 +0000726 const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create(
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000727 "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
Jim Grosbache9119e42015-05-13 18:37:00 +0000728 TmpInst.addOperand(MCOperand::createExpr(LoSym));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000729 getStreamer().EmitInstruction(TmpInst, STI);
730
731 TmpInst.clear();
732
733 TmpInst.setOpcode(Mips::ADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000734 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
735 TmpInst.addOperand(MCOperand::createReg(Mips::GP));
736 TmpInst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000737 getStreamer().EmitInstruction(TmpInst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000738
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000739 forbidModuleDirective();
Matheus Almeida525bc4f2014-04-30 11:28:42 +0000740}
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000741
742void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
743 int RegOrOffset,
744 const MCSymbol &Sym,
745 bool IsReg) {
746 // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
Eric Christophera5762812015-01-26 17:33:46 +0000747 if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000748 return;
749
750 MCAssembler &MCA = getStreamer().getAssembler();
751 MCInst Inst;
752
753 // Either store the old $gp in a register or on the stack
754 if (IsReg) {
755 // move $save, $gpreg
756 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000757 Inst.addOperand(MCOperand::createReg(RegOrOffset));
758 Inst.addOperand(MCOperand::createReg(Mips::GP));
759 Inst.addOperand(MCOperand::createReg(Mips::ZERO));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000760 } else {
761 // sd $gpreg, offset($sp)
762 Inst.setOpcode(Mips::SD);
Jim Grosbache9119e42015-05-13 18:37:00 +0000763 Inst.addOperand(MCOperand::createReg(Mips::GP));
764 Inst.addOperand(MCOperand::createReg(Mips::SP));
765 Inst.addOperand(MCOperand::createImm(RegOrOffset));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000766 }
767 getStreamer().EmitInstruction(Inst, STI);
768 Inst.clear();
769
Jim Grosbach13760bd2015-05-30 01:25:56 +0000770 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000771 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
Jim Grosbach13760bd2015-05-30 01:25:56 +0000772 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create(
Toma Tabacu8874eac2015-02-18 13:46:53 +0000773 &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
774
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000775 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
776 Inst.setOpcode(Mips::LUi);
Jim Grosbache9119e42015-05-13 18:37:00 +0000777 Inst.addOperand(MCOperand::createReg(Mips::GP));
778 Inst.addOperand(MCOperand::createExpr(HiExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000779 getStreamer().EmitInstruction(Inst, STI);
780 Inst.clear();
781
782 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
783 Inst.setOpcode(Mips::ADDiu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000784 Inst.addOperand(MCOperand::createReg(Mips::GP));
785 Inst.addOperand(MCOperand::createReg(Mips::GP));
786 Inst.addOperand(MCOperand::createExpr(LoExpr));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000787 getStreamer().EmitInstruction(Inst, STI);
788 Inst.clear();
789
790 // daddu $gp, $gp, $funcreg
791 Inst.setOpcode(Mips::DADDu);
Jim Grosbache9119e42015-05-13 18:37:00 +0000792 Inst.addOperand(MCOperand::createReg(Mips::GP));
793 Inst.addOperand(MCOperand::createReg(Mips::GP));
794 Inst.addOperand(MCOperand::createReg(RegNo));
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000795 getStreamer().EmitInstruction(Inst, STI);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000796
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000797 forbidModuleDirective();
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000798}
799
800void MipsTargetELFStreamer::emitMipsAbiFlags() {
801 MCAssembler &MCA = getStreamer().getAssembler();
802 MCContext &Context = MCA.getContext();
803 MCStreamer &OS = getStreamer();
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000804 MCSectionELF *Sec = Context.getELFSection(
Rafael Espindolaba31e272015-01-29 17:33:21 +0000805 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
Rafael Espindolabb9a71c2015-05-26 15:07:25 +0000806 MCA.registerSection(*Sec);
Rafael Espindola967d6a62015-05-21 21:02:35 +0000807 Sec->setAlignment(8);
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000808 OS.SwitchSection(Sec);
809
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000810 OS << ABIFlagsSection;
Matheus Almeidad92a3fa2014-05-01 10:24:46 +0000811}