Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 1 | //===-- 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 | |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 14 | #include "MipsTargetStreamer.h" |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 15 | #include "InstPrinter/MipsInstPrinter.h" |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 16 | #include "MipsELFStreamer.h" |
Chandler Carruth | 442f784 | 2014-03-04 10:07:28 +0000 | [diff] [blame] | 17 | #include "MipsMCTargetDesc.h" |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 18 | #include "MipsTargetObjectFile.h" |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCContext.h" |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSectionELF.h" |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSubtargetInfo.h" |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbolELF.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ELF.h" |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
| 25 | #include "llvm/Support/FormattedStream.h" |
| 26 | |
| 27 | using namespace llvm; |
| 28 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 29 | MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S) |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 30 | : MCTargetStreamer(S), ModuleDirectiveAllowed(true) { |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 31 | GPRInfoSet = FPRInfoSet = FrameInfoSet = false; |
| 32 | } |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 33 | void MipsTargetStreamer::emitDirectiveSetMicroMips() {} |
| 34 | void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {} |
| 35 | void MipsTargetStreamer::emitDirectiveSetMips16() {} |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 36 | void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); } |
| 37 | void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); } |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 38 | void MipsTargetStreamer::emitDirectiveSetNoReorder() {} |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 39 | void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); } |
| 40 | void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); } |
| 41 | void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); } |
| 42 | void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); } |
| 43 | void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); } |
Toma Tabacu | 16a7449 | 2015-02-13 10:30:57 +0000 | [diff] [blame] | 44 | void MipsTargetStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) { |
| 45 | forbidModuleDirective(); |
| 46 | } |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 47 | void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); } |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 48 | void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {} |
| 49 | void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {} |
| 50 | void MipsTargetStreamer::emitDirectiveAbiCalls() {} |
| 51 | void MipsTargetStreamer::emitDirectiveNaN2008() {} |
| 52 | void MipsTargetStreamer::emitDirectiveNaNLegacy() {} |
| 53 | void MipsTargetStreamer::emitDirectiveOptionPic0() {} |
| 54 | void MipsTargetStreamer::emitDirectiveOptionPic2() {} |
Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 55 | void MipsTargetStreamer::emitDirectiveInsn() { forbidModuleDirective(); } |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 56 | void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize, |
| 57 | unsigned ReturnReg) {} |
| 58 | void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {} |
| 59 | void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) { |
| 60 | } |
Toma Tabacu | 85618b3 | 2014-08-19 14:22:52 +0000 | [diff] [blame] | 61 | void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) { |
| 62 | forbidModuleDirective(); |
| 63 | } |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 64 | void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); } |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 65 | void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); } |
| 66 | void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); } |
| 67 | void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); } |
| 68 | void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); } |
| 69 | void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); } |
| 70 | void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); } |
| 71 | void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); } |
Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 72 | void MipsTargetStreamer::emitDirectiveSetMips32R3() { forbidModuleDirective(); } |
| 73 | void MipsTargetStreamer::emitDirectiveSetMips32R5() { forbidModuleDirective(); } |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 74 | void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); } |
| 75 | void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); } |
| 76 | void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); } |
Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 77 | void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); } |
| 78 | void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); } |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 79 | void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); } |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 80 | void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); } |
| 81 | void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); } |
Toma Tabacu | 2969650 | 2015-06-02 09:48:04 +0000 | [diff] [blame] | 82 | void MipsTargetStreamer::emitDirectiveSetSoftFloat() { |
| 83 | forbidModuleDirective(); |
| 84 | } |
| 85 | void MipsTargetStreamer::emitDirectiveSetHardFloat() { |
| 86 | forbidModuleDirective(); |
| 87 | } |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 88 | void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); } |
Toma Tabacu | 351b2fe | 2014-09-17 09:01:54 +0000 | [diff] [blame] | 89 | void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); } |
Toma Tabacu | c4c202a | 2014-10-01 14:53:19 +0000 | [diff] [blame] | 90 | void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {} |
Daniel Sanders | c6924fa | 2016-04-18 12:06:15 +0000 | [diff] [blame] | 91 | void MipsTargetStreamer::emitDirectiveCpRestore(int Offset) { |
Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 92 | forbidModuleDirective(); |
| 93 | } |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 94 | void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, |
| 95 | const MCSymbol &Sym, bool IsReg) { |
| 96 | } |
Daniel Sanders | f173dda | 2015-09-22 10:50:09 +0000 | [diff] [blame] | 97 | void MipsTargetStreamer::emitDirectiveCpreturn(unsigned SaveLocation, |
| 98 | bool SaveLocationIsRegister) {} |
Toma Tabacu | bfcbfd5 | 2015-06-23 12:34:19 +0000 | [diff] [blame] | 99 | |
Toma Tabacu | a64e540 | 2015-06-25 12:44:38 +0000 | [diff] [blame] | 100 | void MipsTargetStreamer::emitDirectiveModuleFP() {} |
Toma Tabacu | bfcbfd5 | 2015-06-23 12:34:19 +0000 | [diff] [blame] | 101 | |
Toma Tabacu | 3c49958 | 2015-06-25 10:56:57 +0000 | [diff] [blame] | 102 | void MipsTargetStreamer::emitDirectiveModuleOddSPReg() { |
| 103 | if (!ABIFlagsSection.OddSPReg && !ABIFlagsSection.Is32BitABI) |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 104 | report_fatal_error("+nooddspreg is only valid for O32"); |
| 105 | } |
Toma Tabacu | 0f09313 | 2015-06-30 13:46:03 +0000 | [diff] [blame] | 106 | void MipsTargetStreamer::emitDirectiveModuleSoftFloat() {} |
| 107 | void MipsTargetStreamer::emitDirectiveModuleHardFloat() {} |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 108 | void MipsTargetStreamer::emitDirectiveSetFp( |
| 109 | MipsABIFlagsSection::FpABIKind Value) { |
| 110 | forbidModuleDirective(); |
| 111 | } |
Toma Tabacu | 32c72aa | 2015-06-30 09:36:50 +0000 | [diff] [blame] | 112 | void MipsTargetStreamer::emitDirectiveSetOddSPReg() { forbidModuleDirective(); } |
| 113 | void MipsTargetStreamer::emitDirectiveSetNoOddSPReg() { |
| 114 | forbidModuleDirective(); |
| 115 | } |
Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 116 | |
| 117 | MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S, |
| 118 | formatted_raw_ostream &OS) |
| 119 | : MipsTargetStreamer(S), OS(OS) {} |
Jack Carter | 6ef6cc5 | 2013-11-19 20:53:28 +0000 | [diff] [blame] | 120 | |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 121 | void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() { |
| 122 | OS << "\t.set\tmicromips\n"; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 123 | forbidModuleDirective(); |
Jack Carter | 6ef6cc5 | 2013-11-19 20:53:28 +0000 | [diff] [blame] | 124 | } |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 125 | |
| 126 | void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() { |
| 127 | OS << "\t.set\tnomicromips\n"; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 128 | forbidModuleDirective(); |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 131 | void MipsTargetAsmStreamer::emitDirectiveSetMips16() { |
| 132 | OS << "\t.set\tmips16\n"; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 133 | forbidModuleDirective(); |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() { |
| 137 | OS << "\t.set\tnomips16\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 138 | MipsTargetStreamer::emitDirectiveSetNoMips16(); |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 141 | void MipsTargetAsmStreamer::emitDirectiveSetReorder() { |
| 142 | OS << "\t.set\treorder\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 143 | MipsTargetStreamer::emitDirectiveSetReorder(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() { |
| 147 | OS << "\t.set\tnoreorder\n"; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 148 | forbidModuleDirective(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void MipsTargetAsmStreamer::emitDirectiveSetMacro() { |
| 152 | OS << "\t.set\tmacro\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 153 | MipsTargetStreamer::emitDirectiveSetMacro(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() { |
| 157 | OS << "\t.set\tnomacro\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 158 | MipsTargetStreamer::emitDirectiveSetNoMacro(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Daniel Sanders | 4493443 | 2014-08-07 12:03:36 +0000 | [diff] [blame] | 161 | void MipsTargetAsmStreamer::emitDirectiveSetMsa() { |
| 162 | OS << "\t.set\tmsa\n"; |
| 163 | MipsTargetStreamer::emitDirectiveSetMsa(); |
| 164 | } |
| 165 | |
| 166 | void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() { |
| 167 | OS << "\t.set\tnomsa\n"; |
| 168 | MipsTargetStreamer::emitDirectiveSetNoMsa(); |
| 169 | } |
| 170 | |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 171 | void MipsTargetAsmStreamer::emitDirectiveSetAt() { |
| 172 | OS << "\t.set\tat\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 173 | MipsTargetStreamer::emitDirectiveSetAt(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Toma Tabacu | 16a7449 | 2015-02-13 10:30:57 +0000 | [diff] [blame] | 176 | void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) { |
| 177 | OS << "\t.set\tat=$" << Twine(RegNo) << "\n"; |
| 178 | MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo); |
| 179 | } |
| 180 | |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 181 | void MipsTargetAsmStreamer::emitDirectiveSetNoAt() { |
| 182 | OS << "\t.set\tnoat\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 183 | MipsTargetStreamer::emitDirectiveSetNoAt(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) { |
| 187 | OS << "\t.end\t" << Name << '\n'; |
| 188 | } |
| 189 | |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 190 | void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) { |
| 191 | OS << "\t.ent\t" << Symbol.getName() << '\n'; |
| 192 | } |
| 193 | |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 194 | void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; } |
Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 195 | |
| 196 | void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; } |
| 197 | |
| 198 | void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() { |
| 199 | OS << "\t.nan\tlegacy\n"; |
| 200 | } |
| 201 | |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 202 | void MipsTargetAsmStreamer::emitDirectiveOptionPic0() { |
| 203 | OS << "\t.option\tpic0\n"; |
| 204 | } |
| 205 | |
Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 206 | void MipsTargetAsmStreamer::emitDirectiveOptionPic2() { |
| 207 | OS << "\t.option\tpic2\n"; |
| 208 | } |
| 209 | |
Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 210 | void MipsTargetAsmStreamer::emitDirectiveInsn() { |
| 211 | MipsTargetStreamer::emitDirectiveInsn(); |
| 212 | OS << "\t.insn\n"; |
| 213 | } |
| 214 | |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 215 | void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize, |
| 216 | unsigned ReturnReg) { |
| 217 | OS << "\t.frame\t$" |
| 218 | << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << "," |
| 219 | << StackSize << ",$" |
Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 220 | << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n'; |
| 221 | } |
| 222 | |
Toma Tabacu | 85618b3 | 2014-08-19 14:22:52 +0000 | [diff] [blame] | 223 | void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) { |
| 224 | OS << "\t.set arch=" << Arch << "\n"; |
| 225 | MipsTargetStreamer::emitDirectiveSetArch(Arch); |
| 226 | } |
| 227 | |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 228 | void MipsTargetAsmStreamer::emitDirectiveSetMips0() { |
| 229 | OS << "\t.set\tmips0\n"; |
| 230 | MipsTargetStreamer::emitDirectiveSetMips0(); |
| 231 | } |
Toma Tabacu | 2664779 | 2014-09-09 12:52:14 +0000 | [diff] [blame] | 232 | |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 233 | void MipsTargetAsmStreamer::emitDirectiveSetMips1() { |
| 234 | OS << "\t.set\tmips1\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 235 | MipsTargetStreamer::emitDirectiveSetMips1(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void MipsTargetAsmStreamer::emitDirectiveSetMips2() { |
| 239 | OS << "\t.set\tmips2\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 240 | MipsTargetStreamer::emitDirectiveSetMips2(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void MipsTargetAsmStreamer::emitDirectiveSetMips3() { |
| 244 | OS << "\t.set\tmips3\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 245 | MipsTargetStreamer::emitDirectiveSetMips3(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void MipsTargetAsmStreamer::emitDirectiveSetMips4() { |
| 249 | OS << "\t.set\tmips4\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 250 | MipsTargetStreamer::emitDirectiveSetMips4(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void MipsTargetAsmStreamer::emitDirectiveSetMips5() { |
| 254 | OS << "\t.set\tmips5\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 255 | MipsTargetStreamer::emitDirectiveSetMips5(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void MipsTargetAsmStreamer::emitDirectiveSetMips32() { |
| 259 | OS << "\t.set\tmips32\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 260 | MipsTargetStreamer::emitDirectiveSetMips32(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 263 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() { |
| 264 | OS << "\t.set\tmips32r2\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 265 | MipsTargetStreamer::emitDirectiveSetMips32R2(); |
Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 268 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() { |
| 269 | OS << "\t.set\tmips32r3\n"; |
| 270 | MipsTargetStreamer::emitDirectiveSetMips32R3(); |
| 271 | } |
| 272 | |
| 273 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() { |
| 274 | OS << "\t.set\tmips32r5\n"; |
| 275 | MipsTargetStreamer::emitDirectiveSetMips32R5(); |
| 276 | } |
| 277 | |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 278 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() { |
| 279 | OS << "\t.set\tmips32r6\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 280 | MipsTargetStreamer::emitDirectiveSetMips32R6(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Matheus Almeida | 3b9c63d | 2014-03-26 15:14:32 +0000 | [diff] [blame] | 283 | void MipsTargetAsmStreamer::emitDirectiveSetMips64() { |
| 284 | OS << "\t.set\tmips64\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 285 | MipsTargetStreamer::emitDirectiveSetMips64(); |
Matheus Almeida | 3b9c63d | 2014-03-26 15:14:32 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Matheus Almeida | a2cd009 | 2014-03-26 14:52:22 +0000 | [diff] [blame] | 288 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() { |
| 289 | OS << "\t.set\tmips64r2\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 290 | MipsTargetStreamer::emitDirectiveSetMips64R2(); |
Matheus Almeida | a2cd009 | 2014-03-26 14:52:22 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 293 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() { |
| 294 | OS << "\t.set\tmips64r3\n"; |
| 295 | MipsTargetStreamer::emitDirectiveSetMips64R3(); |
| 296 | } |
| 297 | |
| 298 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() { |
| 299 | OS << "\t.set\tmips64r5\n"; |
| 300 | MipsTargetStreamer::emitDirectiveSetMips64R5(); |
| 301 | } |
| 302 | |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 303 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() { |
| 304 | OS << "\t.set\tmips64r6\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 305 | MipsTargetStreamer::emitDirectiveSetMips64R6(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Vladimir Medic | 27c398e | 2014-03-05 11:05:09 +0000 | [diff] [blame] | 308 | void MipsTargetAsmStreamer::emitDirectiveSetDsp() { |
| 309 | OS << "\t.set\tdsp\n"; |
Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 310 | MipsTargetStreamer::emitDirectiveSetDsp(); |
Vladimir Medic | 27c398e | 2014-03-05 11:05:09 +0000 | [diff] [blame] | 311 | } |
Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 312 | |
Toma Tabacu | 351b2fe | 2014-09-17 09:01:54 +0000 | [diff] [blame] | 313 | void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() { |
| 314 | OS << "\t.set\tnodsp\n"; |
| 315 | MipsTargetStreamer::emitDirectiveSetNoDsp(); |
| 316 | } |
| 317 | |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 318 | void MipsTargetAsmStreamer::emitDirectiveSetPop() { |
| 319 | OS << "\t.set\tpop\n"; |
| 320 | MipsTargetStreamer::emitDirectiveSetPop(); |
| 321 | } |
Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 322 | |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 323 | void MipsTargetAsmStreamer::emitDirectiveSetPush() { |
| 324 | OS << "\t.set\tpush\n"; |
| 325 | MipsTargetStreamer::emitDirectiveSetPush(); |
| 326 | } |
Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 327 | |
Toma Tabacu | 2969650 | 2015-06-02 09:48:04 +0000 | [diff] [blame] | 328 | void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() { |
| 329 | OS << "\t.set\tsoftfloat\n"; |
| 330 | MipsTargetStreamer::emitDirectiveSetSoftFloat(); |
| 331 | } |
| 332 | |
| 333 | void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() { |
| 334 | OS << "\t.set\thardfloat\n"; |
| 335 | MipsTargetStreamer::emitDirectiveSetHardFloat(); |
| 336 | } |
| 337 | |
Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 338 | // Print a 32 bit hex number with all numbers. |
| 339 | static void printHex32(unsigned Value, raw_ostream &OS) { |
| 340 | OS << "0x"; |
| 341 | for (int i = 7; i >= 0; i--) |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 342 | OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4)); |
Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask, |
| 346 | int CPUTopSavedRegOff) { |
| 347 | OS << "\t.mask \t"; |
| 348 | printHex32(CPUBitmask, OS); |
| 349 | OS << ',' << CPUTopSavedRegOff << '\n'; |
| 350 | } |
| 351 | |
| 352 | void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask, |
| 353 | int FPUTopSavedRegOff) { |
| 354 | OS << "\t.fmask\t"; |
| 355 | printHex32(FPUBitmask, OS); |
| 356 | OS << "," << FPUTopSavedRegOff << '\n'; |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Toma Tabacu | c4c202a | 2014-10-01 14:53:19 +0000 | [diff] [blame] | 359 | void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) { |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 360 | OS << "\t.cpload\t$" |
| 361 | << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n"; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 362 | forbidModuleDirective(); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Daniel Sanders | c6924fa | 2016-04-18 12:06:15 +0000 | [diff] [blame] | 365 | void MipsTargetAsmStreamer::emitDirectiveCpRestore(int Offset) { |
| 366 | MipsTargetStreamer::emitDirectiveCpRestore(Offset); |
Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 367 | OS << "\t.cprestore\t" << Offset << "\n"; |
| 368 | } |
| 369 | |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 370 | void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo, |
| 371 | int RegOrOffset, |
| 372 | const MCSymbol &Sym, |
| 373 | bool IsReg) { |
| 374 | OS << "\t.cpsetup\t$" |
| 375 | << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", "; |
| 376 | |
| 377 | if (IsReg) |
| 378 | OS << "$" |
| 379 | << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower(); |
| 380 | else |
| 381 | OS << RegOrOffset; |
| 382 | |
| 383 | OS << ", "; |
| 384 | |
Daniel Sanders | 5d79628 | 2015-09-21 09:26:55 +0000 | [diff] [blame] | 385 | OS << Sym.getName(); |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 386 | forbidModuleDirective(); |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Daniel Sanders | f173dda | 2015-09-22 10:50:09 +0000 | [diff] [blame] | 389 | void MipsTargetAsmStreamer::emitDirectiveCpreturn(unsigned SaveLocation, |
| 390 | bool SaveLocationIsRegister) { |
| 391 | OS << "\t.cpreturn"; |
| 392 | forbidModuleDirective(); |
| 393 | } |
| 394 | |
Toma Tabacu | a64e540 | 2015-06-25 12:44:38 +0000 | [diff] [blame] | 395 | void MipsTargetAsmStreamer::emitDirectiveModuleFP() { |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 396 | OS << "\t.module\tfp="; |
Toma Tabacu | a64e540 | 2015-06-25 12:44:38 +0000 | [diff] [blame] | 397 | OS << ABIFlagsSection.getFpABIString(ABIFlagsSection.getFpABI()) << "\n"; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 400 | void MipsTargetAsmStreamer::emitDirectiveSetFp( |
| 401 | MipsABIFlagsSection::FpABIKind Value) { |
Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 402 | MipsTargetStreamer::emitDirectiveSetFp(Value); |
| 403 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 404 | OS << "\t.set\tfp="; |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 405 | OS << ABIFlagsSection.getFpABIString(Value) << "\n"; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Toma Tabacu | 3c49958 | 2015-06-25 10:56:57 +0000 | [diff] [blame] | 408 | void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() { |
| 409 | MipsTargetStreamer::emitDirectiveModuleOddSPReg(); |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 410 | |
Toma Tabacu | 3c49958 | 2015-06-25 10:56:57 +0000 | [diff] [blame] | 411 | OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n"; |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Toma Tabacu | 32c72aa | 2015-06-30 09:36:50 +0000 | [diff] [blame] | 414 | void MipsTargetAsmStreamer::emitDirectiveSetOddSPReg() { |
| 415 | MipsTargetStreamer::emitDirectiveSetOddSPReg(); |
| 416 | OS << "\t.set\toddspreg\n"; |
| 417 | } |
| 418 | |
| 419 | void MipsTargetAsmStreamer::emitDirectiveSetNoOddSPReg() { |
| 420 | MipsTargetStreamer::emitDirectiveSetNoOddSPReg(); |
| 421 | OS << "\t.set\tnooddspreg\n"; |
| 422 | } |
| 423 | |
Toma Tabacu | 0f09313 | 2015-06-30 13:46:03 +0000 | [diff] [blame] | 424 | void MipsTargetAsmStreamer::emitDirectiveModuleSoftFloat() { |
| 425 | OS << "\t.module\tsoftfloat\n"; |
| 426 | } |
| 427 | |
| 428 | void MipsTargetAsmStreamer::emitDirectiveModuleHardFloat() { |
| 429 | OS << "\t.module\thardfloat\n"; |
| 430 | } |
| 431 | |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 432 | // This part is for ELF object output. |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 433 | MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S, |
| 434 | const MCSubtargetInfo &STI) |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 435 | : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) { |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 436 | MCAssembler &MCA = getStreamer().getAssembler(); |
Simon Atanasyan | c99ce68 | 2015-03-24 12:24:56 +0000 | [diff] [blame] | 437 | Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_; |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 438 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 439 | const FeatureBitset &Features = STI.getFeatureBits(); |
Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 440 | |
| 441 | // Set the header flags that we can in the constructor. |
| 442 | // FIXME: This is a fairly terrible hack. We set the rest |
| 443 | // of these in the destructor. The problem here is two-fold: |
| 444 | // |
| 445 | // a: Some of the eflags can be set/reset by directives. |
| 446 | // b: There aren't any usage paths that initialize the ABI |
| 447 | // pointer until after we initialize either an assembler |
| 448 | // or the target machine. |
| 449 | // We can fix this by making the target streamer construct |
| 450 | // the ABI, but this is fraught with wide ranging dependency |
| 451 | // issues as well. |
| 452 | unsigned EFlags = MCA.getELFHeaderEFlags(); |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 453 | |
| 454 | // Architecture |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 455 | if (Features[Mips::FeatureMips64r6]) |
Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 456 | EFlags |= ELF::EF_MIPS_ARCH_64R6; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 457 | else if (Features[Mips::FeatureMips64r2] || |
| 458 | Features[Mips::FeatureMips64r3] || |
| 459 | Features[Mips::FeatureMips64r5]) |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 460 | EFlags |= ELF::EF_MIPS_ARCH_64R2; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 461 | else if (Features[Mips::FeatureMips64]) |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 462 | EFlags |= ELF::EF_MIPS_ARCH_64; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 463 | else if (Features[Mips::FeatureMips5]) |
Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 464 | EFlags |= ELF::EF_MIPS_ARCH_5; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 465 | else if (Features[Mips::FeatureMips4]) |
Daniel Sanders | f7b3229 | 2014-04-03 12:13:36 +0000 | [diff] [blame] | 466 | EFlags |= ELF::EF_MIPS_ARCH_4; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 467 | else if (Features[Mips::FeatureMips3]) |
Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 468 | EFlags |= ELF::EF_MIPS_ARCH_3; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 469 | else if (Features[Mips::FeatureMips32r6]) |
Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 470 | EFlags |= ELF::EF_MIPS_ARCH_32R6; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 471 | else if (Features[Mips::FeatureMips32r2] || |
| 472 | Features[Mips::FeatureMips32r3] || |
| 473 | Features[Mips::FeatureMips32r5]) |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 474 | EFlags |= ELF::EF_MIPS_ARCH_32R2; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 475 | else if (Features[Mips::FeatureMips32]) |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 476 | EFlags |= ELF::EF_MIPS_ARCH_32; |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 477 | else if (Features[Mips::FeatureMips2]) |
Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 478 | EFlags |= ELF::EF_MIPS_ARCH_2; |
| 479 | else |
| 480 | EFlags |= ELF::EF_MIPS_ARCH_1; |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 481 | |
Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 482 | // Other options. |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 483 | if (Features[Mips::FeatureNaN2008]) |
Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 484 | EFlags |= ELF::EF_MIPS_NAN2008; |
| 485 | |
Daniel Sanders | 16ec6c1 | 2014-07-17 09:52:56 +0000 | [diff] [blame] | 486 | // -mabicalls and -mplt are not implemented but we should act as if they were |
| 487 | // given. |
| 488 | EFlags |= ELF::EF_MIPS_CPIC; |
Daniel Sanders | 16ec6c1 | 2014-07-17 09:52:56 +0000 | [diff] [blame] | 489 | |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 490 | MCA.setELFHeaderEFlags(EFlags); |
| 491 | } |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 492 | |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 493 | void MipsTargetELFStreamer::emitLabel(MCSymbol *S) { |
| 494 | auto *Symbol = cast<MCSymbolELF>(S); |
Rafael Espindola | 26e917c | 2014-01-15 03:07:12 +0000 | [diff] [blame] | 495 | if (!isMicroMipsEnabled()) |
| 496 | return; |
Rafael Espindola | c73aed1 | 2015-06-03 19:03:11 +0000 | [diff] [blame] | 497 | getStreamer().getAssembler().registerSymbol(*Symbol); |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 498 | uint8_t Type = Symbol->getType(); |
Rafael Espindola | 26e917c | 2014-01-15 03:07:12 +0000 | [diff] [blame] | 499 | if (Type != ELF::STT_FUNC) |
| 500 | return; |
| 501 | |
Rafael Espindola | 8c006ee | 2015-06-04 05:59:23 +0000 | [diff] [blame] | 502 | Symbol->setOther(ELF::STO_MIPS_MICROMIPS); |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 505 | void MipsTargetELFStreamer::finish() { |
| 506 | MCAssembler &MCA = getStreamer().getAssembler(); |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 507 | const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo(); |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 508 | |
Daniel Sanders | 41ffa5d | 2014-07-14 15:05:51 +0000 | [diff] [blame] | 509 | // .bss, .text and .data are always at least 16-byte aligned. |
Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 510 | MCSection &TextSection = *OFI.getTextSection(); |
Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 511 | MCA.registerSection(TextSection); |
Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 512 | MCSection &DataSection = *OFI.getDataSection(); |
Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 513 | MCA.registerSection(DataSection); |
Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 514 | MCSection &BSSSection = *OFI.getBSSSection(); |
Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 515 | MCA.registerSection(BSSSection); |
Daniel Sanders | 41ffa5d | 2014-07-14 15:05:51 +0000 | [diff] [blame] | 516 | |
Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 517 | TextSection.setAlignment(std::max(16u, TextSection.getAlignment())); |
| 518 | DataSection.setAlignment(std::max(16u, DataSection.getAlignment())); |
| 519 | BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment())); |
Daniel Sanders | 41ffa5d | 2014-07-14 15:05:51 +0000 | [diff] [blame] | 520 | |
Daniel Sanders | 9db710a | 2016-04-29 12:44:07 +0000 | [diff] [blame^] | 521 | // Make sections sizes a multiple of the alignment. |
| 522 | MCStreamer &OS = getStreamer(); |
| 523 | for (MCSection &S : MCA) { |
| 524 | MCSectionELF &Section = static_cast<MCSectionELF &>(S); |
| 525 | |
| 526 | unsigned Alignment = Section.getAlignment(); |
| 527 | if (Alignment) { |
| 528 | OS.SwitchSection(&Section); |
| 529 | if (Section.UseCodeAlign()) |
| 530 | OS.EmitCodeAlignment(Alignment, Alignment); |
| 531 | else |
| 532 | OS.EmitValueToAlignment(Alignment, 0, 1, Alignment); |
| 533 | } |
| 534 | } |
| 535 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 536 | const FeatureBitset &Features = STI.getFeatureBits(); |
Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 537 | |
| 538 | // Update e_header flags. See the FIXME and comment above in |
| 539 | // the constructor for a full rundown on this. |
| 540 | unsigned EFlags = MCA.getELFHeaderEFlags(); |
| 541 | |
| 542 | // ABI |
| 543 | // N64 does not require any ABI bits. |
| 544 | if (getABI().IsO32()) |
| 545 | EFlags |= ELF::EF_MIPS_ABI_O32; |
| 546 | else if (getABI().IsN32()) |
| 547 | EFlags |= ELF::EF_MIPS_ABI2; |
| 548 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 549 | if (Features[Mips::FeatureGP64Bit]) { |
Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 550 | if (getABI().IsO32()) |
| 551 | EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */ |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 552 | } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64]) |
Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 553 | EFlags |= ELF::EF_MIPS_32BITMODE; |
| 554 | |
| 555 | // If we've set the cpic eflag and we're n64, go ahead and set the pic |
| 556 | // one as well. |
| 557 | if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64()) |
| 558 | EFlags |= ELF::EF_MIPS_PIC; |
| 559 | |
| 560 | MCA.setELFHeaderEFlags(EFlags); |
| 561 | |
Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 562 | // Emit all the option records. |
| 563 | // At the moment we are only emitting .Mips.options (ODK_REGINFO) and |
| 564 | // .reginfo. |
| 565 | MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer); |
| 566 | MEF.EmitMipsOptionRecords(); |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 567 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 568 | emitMipsAbiFlags(); |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 571 | void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) { |
| 572 | auto *Symbol = cast<MCSymbolELF>(S); |
Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 573 | // If on rhs is micromips symbol then mark Symbol as microMips. |
| 574 | if (Value->getKind() != MCExpr::SymbolRef) |
| 575 | return; |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 576 | const auto &RhsSym = cast<MCSymbolELF>( |
| 577 | static_cast<const MCSymbolRefExpr *>(Value)->getSymbol()); |
Toma Tabacu | 2cc44f5 | 2015-04-16 13:37:32 +0000 | [diff] [blame] | 578 | |
Rafael Espindola | 8c006ee | 2015-06-04 05:59:23 +0000 | [diff] [blame] | 579 | if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS)) |
Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 580 | return; |
| 581 | |
Rafael Espindola | 8c006ee | 2015-06-04 05:59:23 +0000 | [diff] [blame] | 582 | Symbol->setOther(ELF::STO_MIPS_MICROMIPS); |
Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 585 | MCELFStreamer &MipsTargetELFStreamer::getStreamer() { |
Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 586 | return static_cast<MCELFStreamer &>(Streamer); |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 589 | void MipsTargetELFStreamer::emitDirectiveSetMicroMips() { |
| 590 | MicroMipsEnabled = true; |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 591 | |
| 592 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 593 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 594 | Flags |= ELF::EF_MIPS_MICROMIPS; |
| 595 | MCA.setELFHeaderEFlags(Flags); |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 596 | forbidModuleDirective(); |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 597 | } |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 598 | |
| 599 | void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() { |
| 600 | MicroMipsEnabled = false; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 601 | forbidModuleDirective(); |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 604 | void MipsTargetELFStreamer::emitDirectiveSetMips16() { |
Rafael Espindola | e758375 | 2014-01-24 16:13:20 +0000 | [diff] [blame] | 605 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 606 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 607 | Flags |= ELF::EF_MIPS_ARCH_ASE_M16; |
| 608 | MCA.setELFHeaderEFlags(Flags); |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 609 | forbidModuleDirective(); |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 612 | void MipsTargetELFStreamer::emitDirectiveSetNoReorder() { |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 613 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 614 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 615 | Flags |= ELF::EF_MIPS_NOREORDER; |
| 616 | MCA.setELFHeaderEFlags(Flags); |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 617 | forbidModuleDirective(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 620 | void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) { |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 621 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 622 | MCContext &Context = MCA.getContext(); |
| 623 | MCStreamer &OS = getStreamer(); |
| 624 | |
Scott Egerton | 219fae9 | 2016-02-17 11:15:16 +0000 | [diff] [blame] | 625 | MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS, 0); |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 626 | |
Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 627 | MCSymbol *Sym = Context.getOrCreateSymbol(Name); |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 628 | const MCSymbolRefExpr *ExprRef = |
Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 629 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Context); |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 630 | |
Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 631 | MCA.registerSection(*Sec); |
Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 632 | Sec->setAlignment(4); |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 633 | |
| 634 | OS.PushSection(); |
| 635 | |
| 636 | OS.SwitchSection(Sec); |
| 637 | |
| 638 | OS.EmitValueImpl(ExprRef, 4); |
| 639 | |
| 640 | OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask |
| 641 | OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset |
| 642 | |
| 643 | OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask |
| 644 | OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset |
| 645 | |
| 646 | OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset |
| 647 | OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg |
| 648 | OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg |
| 649 | |
| 650 | // The .end directive marks the end of a procedure. Invalidate |
| 651 | // the information gathered up until this point. |
| 652 | GPRInfoSet = FPRInfoSet = FrameInfoSet = false; |
| 653 | |
| 654 | OS.PopSection(); |
Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 655 | |
| 656 | // .end also implicitly sets the size. |
| 657 | MCSymbol *CurPCSym = Context.createTempSymbol(); |
| 658 | OS.EmitLabel(CurPCSym); |
| 659 | const MCExpr *Size = MCBinaryExpr::createSub( |
| 660 | MCSymbolRefExpr::create(CurPCSym, MCSymbolRefExpr::VK_None, Context), |
| 661 | ExprRef, Context); |
| 662 | int64_t AbsSize; |
| 663 | if (!Size->evaluateAsAbsolute(AbsSize, MCA)) |
| 664 | llvm_unreachable("Function size must be evaluatable as absolute"); |
| 665 | Size = MCConstantExpr::create(AbsSize, Context); |
| 666 | static_cast<MCSymbolELF *>(Sym)->setSize(Size); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 669 | void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) { |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 670 | GPRInfoSet = FPRInfoSet = FrameInfoSet = false; |
Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 671 | |
| 672 | // .ent also acts like an implicit '.type symbol, STT_FUNC' |
| 673 | static_cast<const MCSymbolELF &>(Symbol).setType(ELF::STT_FUNC); |
Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 676 | void MipsTargetELFStreamer::emitDirectiveAbiCalls() { |
| 677 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 678 | unsigned Flags = MCA.getELFHeaderEFlags(); |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 679 | Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC; |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 680 | MCA.setELFHeaderEFlags(Flags); |
| 681 | } |
Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 682 | |
| 683 | void MipsTargetELFStreamer::emitDirectiveNaN2008() { |
| 684 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 685 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 686 | Flags |= ELF::EF_MIPS_NAN2008; |
| 687 | MCA.setELFHeaderEFlags(Flags); |
| 688 | } |
| 689 | |
| 690 | void MipsTargetELFStreamer::emitDirectiveNaNLegacy() { |
| 691 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 692 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 693 | Flags &= ~ELF::EF_MIPS_NAN2008; |
| 694 | MCA.setELFHeaderEFlags(Flags); |
| 695 | } |
| 696 | |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 697 | void MipsTargetELFStreamer::emitDirectiveOptionPic0() { |
| 698 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 699 | unsigned Flags = MCA.getELFHeaderEFlags(); |
Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 700 | // This option overrides other PIC options like -KPIC. |
| 701 | Pic = false; |
Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 702 | Flags &= ~ELF::EF_MIPS_PIC; |
| 703 | MCA.setELFHeaderEFlags(Flags); |
| 704 | } |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 705 | |
Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 706 | void MipsTargetELFStreamer::emitDirectiveOptionPic2() { |
| 707 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 708 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 709 | Pic = true; |
| 710 | // NOTE: We are following the GAS behaviour here which means the directive |
| 711 | // 'pic2' also sets the CPIC bit in the ELF header. This is different from |
| 712 | // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and |
| 713 | // EF_MIPS_CPIC to be mutually exclusive. |
| 714 | Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC; |
| 715 | MCA.setELFHeaderEFlags(Flags); |
| 716 | } |
| 717 | |
Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 718 | void MipsTargetELFStreamer::emitDirectiveInsn() { |
| 719 | MipsTargetStreamer::emitDirectiveInsn(); |
| 720 | MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer); |
| 721 | MEF.createPendingLabelRelocs(); |
| 722 | } |
| 723 | |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 724 | void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize, |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 725 | unsigned ReturnReg_) { |
| 726 | MCContext &Context = getStreamer().getAssembler().getContext(); |
| 727 | const MCRegisterInfo *RegInfo = Context.getRegisterInfo(); |
| 728 | |
| 729 | FrameInfoSet = true; |
| 730 | FrameReg = RegInfo->getEncodingValue(StackReg); |
| 731 | FrameOffset = StackSize; |
| 732 | ReturnReg = RegInfo->getEncodingValue(ReturnReg_); |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 733 | } |
Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 734 | |
| 735 | void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask, |
| 736 | int CPUTopSavedRegOff) { |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 737 | GPRInfoSet = true; |
| 738 | GPRBitMask = CPUBitmask; |
| 739 | GPROffset = CPUTopSavedRegOff; |
Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask, |
| 743 | int FPUTopSavedRegOff) { |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 744 | FPRInfoSet = true; |
| 745 | FPRBitMask = FPUBitmask; |
| 746 | FPROffset = FPUTopSavedRegOff; |
Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 747 | } |
Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 748 | |
Toma Tabacu | c4c202a | 2014-10-01 14:53:19 +0000 | [diff] [blame] | 749 | void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) { |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 750 | // .cpload $reg |
| 751 | // This directive expands to: |
| 752 | // lui $gp, %hi(_gp_disp) |
| 753 | // addui $gp, $gp, %lo(_gp_disp) |
| 754 | // addu $gp, $gp, $reg |
| 755 | // when support for position independent code is enabled. |
Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 756 | if (!Pic || (getABI().IsN32() || getABI().IsN64())) |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 757 | return; |
| 758 | |
| 759 | // There's a GNU extension controlled by -mno-shared that allows |
| 760 | // locally-binding symbols to be accessed using absolute addresses. |
| 761 | // This is currently not supported. When supported -mno-shared makes |
| 762 | // .cpload expand to: |
| 763 | // lui $gp, %hi(__gnu_local_gp) |
| 764 | // addiu $gp, $gp, %lo(__gnu_local_gp) |
| 765 | |
| 766 | StringRef SymName("_gp_disp"); |
| 767 | MCAssembler &MCA = getStreamer().getAssembler(); |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 768 | MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName); |
Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 769 | MCA.registerSymbol(*GP_Disp); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 770 | |
| 771 | MCInst TmpInst; |
| 772 | TmpInst.setOpcode(Mips::LUi); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 773 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 774 | const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::create( |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 775 | "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext()); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 776 | TmpInst.addOperand(MCOperand::createExpr(HiSym)); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 777 | getStreamer().EmitInstruction(TmpInst, STI); |
| 778 | |
| 779 | TmpInst.clear(); |
| 780 | |
| 781 | TmpInst.setOpcode(Mips::ADDiu); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 782 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| 783 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 784 | const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::create( |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 785 | "_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext()); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 786 | TmpInst.addOperand(MCOperand::createExpr(LoSym)); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 787 | getStreamer().EmitInstruction(TmpInst, STI); |
| 788 | |
| 789 | TmpInst.clear(); |
| 790 | |
| 791 | TmpInst.setOpcode(Mips::ADDu); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 792 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| 793 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| 794 | TmpInst.addOperand(MCOperand::createReg(RegNo)); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 795 | getStreamer().EmitInstruction(TmpInst, STI); |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 796 | |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 797 | forbidModuleDirective(); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 798 | } |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 799 | |
Daniel Sanders | c6924fa | 2016-04-18 12:06:15 +0000 | [diff] [blame] | 800 | void MipsTargetELFStreamer::emitDirectiveCpRestore(int Offset) { |
| 801 | MipsTargetStreamer::emitDirectiveCpRestore(Offset); |
Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 802 | // .cprestore offset |
| 803 | // When PIC mode is enabled and the O32 ABI is used, this directive expands |
| 804 | // to: |
| 805 | // sw $gp, offset($sp) |
| 806 | // and adds a corresponding LW after every JAL. |
| 807 | |
| 808 | // Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it |
| 809 | // is used in non-PIC mode. |
| 810 | if (!Pic || (getABI().IsN32() || getABI().IsN64())) |
| 811 | return; |
| 812 | |
Daniel Sanders | c6924fa | 2016-04-18 12:06:15 +0000 | [diff] [blame] | 813 | // FIXME: MipsAsmParser currently emits the instructions that should be |
| 814 | // emitted here. |
Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 817 | void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo, |
| 818 | int RegOrOffset, |
| 819 | const MCSymbol &Sym, |
| 820 | bool IsReg) { |
| 821 | // Only N32 and N64 emit anything for .cpsetup iff PIC is set. |
Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 822 | if (!Pic || !(getABI().IsN32() || getABI().IsN64())) |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 823 | return; |
| 824 | |
| 825 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 826 | MCInst Inst; |
| 827 | |
| 828 | // Either store the old $gp in a register or on the stack |
| 829 | if (IsReg) { |
| 830 | // move $save, $gpreg |
Vasileios Kalintiris | 1c78ca6 | 2015-08-11 08:56:25 +0000 | [diff] [blame] | 831 | Inst.setOpcode(Mips::OR64); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 832 | Inst.addOperand(MCOperand::createReg(RegOrOffset)); |
| 833 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 834 | Inst.addOperand(MCOperand::createReg(Mips::ZERO)); |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 835 | } else { |
| 836 | // sd $gpreg, offset($sp) |
| 837 | Inst.setOpcode(Mips::SD); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 838 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 839 | Inst.addOperand(MCOperand::createReg(Mips::SP)); |
| 840 | Inst.addOperand(MCOperand::createImm(RegOrOffset)); |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 841 | } |
| 842 | getStreamer().EmitInstruction(Inst, STI); |
| 843 | Inst.clear(); |
| 844 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 845 | const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::create( |
Toma Tabacu | 8874eac | 2015-02-18 13:46:53 +0000 | [diff] [blame] | 846 | &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext()); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 847 | const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::create( |
Toma Tabacu | 8874eac | 2015-02-18 13:46:53 +0000 | [diff] [blame] | 848 | &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext()); |
| 849 | |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 850 | // lui $gp, %hi(%neg(%gp_rel(funcSym))) |
| 851 | Inst.setOpcode(Mips::LUi); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 852 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 853 | Inst.addOperand(MCOperand::createExpr(HiExpr)); |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 854 | getStreamer().EmitInstruction(Inst, STI); |
| 855 | Inst.clear(); |
| 856 | |
| 857 | // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym))) |
| 858 | Inst.setOpcode(Mips::ADDiu); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 859 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 860 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 861 | Inst.addOperand(MCOperand::createExpr(LoExpr)); |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 862 | getStreamer().EmitInstruction(Inst, STI); |
| 863 | Inst.clear(); |
| 864 | |
| 865 | // daddu $gp, $gp, $funcreg |
| 866 | Inst.setOpcode(Mips::DADDu); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 867 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 868 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 869 | Inst.addOperand(MCOperand::createReg(RegNo)); |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 870 | getStreamer().EmitInstruction(Inst, STI); |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 871 | |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 872 | forbidModuleDirective(); |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Daniel Sanders | f173dda | 2015-09-22 10:50:09 +0000 | [diff] [blame] | 875 | void MipsTargetELFStreamer::emitDirectiveCpreturn(unsigned SaveLocation, |
| 876 | bool SaveLocationIsRegister) { |
| 877 | // Only N32 and N64 emit anything for .cpreturn iff PIC is set. |
| 878 | if (!Pic || !(getABI().IsN32() || getABI().IsN64())) |
| 879 | return; |
| 880 | |
| 881 | MCInst Inst; |
| 882 | // Either restore the old $gp from a register or on the stack |
| 883 | if (SaveLocationIsRegister) { |
| 884 | Inst.setOpcode(Mips::OR); |
| 885 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 886 | Inst.addOperand(MCOperand::createReg(SaveLocation)); |
| 887 | Inst.addOperand(MCOperand::createReg(Mips::ZERO)); |
| 888 | } else { |
| 889 | Inst.setOpcode(Mips::LD); |
| 890 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 891 | Inst.addOperand(MCOperand::createReg(Mips::SP)); |
| 892 | Inst.addOperand(MCOperand::createImm(SaveLocation)); |
| 893 | } |
| 894 | getStreamer().EmitInstruction(Inst, STI); |
| 895 | |
| 896 | forbidModuleDirective(); |
| 897 | } |
| 898 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 899 | void MipsTargetELFStreamer::emitMipsAbiFlags() { |
| 900 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 901 | MCContext &Context = MCA.getContext(); |
| 902 | MCStreamer &OS = getStreamer(); |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 903 | MCSectionELF *Sec = Context.getELFSection( |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 904 | ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, ""); |
Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 905 | MCA.registerSection(*Sec); |
Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 906 | Sec->setAlignment(8); |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 907 | OS.SwitchSection(Sec); |
| 908 | |
Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 909 | OS << ABIFlagsSection; |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 910 | } |