| 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" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/MipsABIInfo.h" |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 17 | #include "MipsELFStreamer.h" |
| Daniel Sanders | fe98b2f | 2016-05-03 13:35:44 +0000 | [diff] [blame] | 18 | #include "MipsMCExpr.h" |
| Chandler Carruth | 442f784 | 2014-03-04 10:07:28 +0000 | [diff] [blame] | 19 | #include "MipsMCTargetDesc.h" |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 20 | #include "MipsTargetObjectFile.h" |
| Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 21 | #include "llvm/BinaryFormat/ELF.h" |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCContext.h" |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSectionELF.h" |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCSubtargetInfo.h" |
| Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCSymbolELF.h" |
| Daniel Sanders | c07f06a | 2016-05-04 13:21:06 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CommandLine.h" |
| Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
| 28 | #include "llvm/Support/FormattedStream.h" |
| 29 | |
| 30 | using namespace llvm; |
| 31 | |
| Daniel Sanders | c07f06a | 2016-05-04 13:21:06 +0000 | [diff] [blame] | 32 | namespace { |
| 33 | static cl::opt<bool> RoundSectionSizes( |
| 34 | "mips-round-section-sizes", cl::init(false), |
| 35 | cl::desc("Round section sizes up to the section alignment"), cl::Hidden); |
| 36 | } // end anonymous namespace |
| 37 | |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 38 | MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S) |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 39 | : MCTargetStreamer(S), ModuleDirectiveAllowed(true) { |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 40 | GPRInfoSet = FPRInfoSet = FrameInfoSet = false; |
| 41 | } |
| Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 42 | void MipsTargetStreamer::emitDirectiveSetMicroMips() {} |
| 43 | void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {} |
| Daniel Sanders | cda908a | 2016-05-16 09:10:13 +0000 | [diff] [blame] | 44 | void MipsTargetStreamer::setUsesMicroMips() {} |
| Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 45 | void MipsTargetStreamer::emitDirectiveSetMips16() {} |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 46 | void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); } |
| 47 | void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); } |
| Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 48 | void MipsTargetStreamer::emitDirectiveSetNoReorder() {} |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 49 | void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); } |
| 50 | void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); } |
| 51 | void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); } |
| 52 | void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); } |
| Simon Dardis | 805f1e0 | 2017-07-11 21:28:36 +0000 | [diff] [blame] | 53 | void MipsTargetStreamer::emitDirectiveSetMt() {} |
| 54 | void MipsTargetStreamer::emitDirectiveSetNoMt() { forbidModuleDirective(); } |
| Petar Jovanovic | 3408caf | 2018-03-14 14:13:31 +0000 | [diff] [blame] | 55 | void MipsTargetStreamer::emitDirectiveSetCRC() {} |
| 56 | void MipsTargetStreamer::emitDirectiveSetNoCRC() {} |
| Petar Jovanovic | d4349f3 | 2018-04-27 09:12:08 +0000 | [diff] [blame] | 57 | void MipsTargetStreamer::emitDirectiveSetVirt() {} |
| 58 | void MipsTargetStreamer::emitDirectiveSetNoVirt() {} |
| Petar Jovanovic | daf5169 | 2018-05-17 16:30:32 +0000 | [diff] [blame^] | 59 | void MipsTargetStreamer::emitDirectiveSetGINV() {} |
| 60 | void MipsTargetStreamer::emitDirectiveSetNoGINV() {} |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 61 | void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); } |
| Toma Tabacu | 16a7449 | 2015-02-13 10:30:57 +0000 | [diff] [blame] | 62 | void MipsTargetStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) { |
| 63 | forbidModuleDirective(); |
| 64 | } |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 65 | void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); } |
| Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 66 | void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {} |
| 67 | void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {} |
| 68 | void MipsTargetStreamer::emitDirectiveAbiCalls() {} |
| 69 | void MipsTargetStreamer::emitDirectiveNaN2008() {} |
| 70 | void MipsTargetStreamer::emitDirectiveNaNLegacy() {} |
| 71 | void MipsTargetStreamer::emitDirectiveOptionPic0() {} |
| 72 | void MipsTargetStreamer::emitDirectiveOptionPic2() {} |
| Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 73 | void MipsTargetStreamer::emitDirectiveInsn() { forbidModuleDirective(); } |
| Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 74 | void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize, |
| 75 | unsigned ReturnReg) {} |
| 76 | void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {} |
| 77 | void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) { |
| 78 | } |
| Toma Tabacu | 85618b3 | 2014-08-19 14:22:52 +0000 | [diff] [blame] | 79 | void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) { |
| 80 | forbidModuleDirective(); |
| 81 | } |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 82 | void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); } |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 83 | void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); } |
| 84 | void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); } |
| 85 | void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); } |
| 86 | void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); } |
| 87 | void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); } |
| 88 | void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); } |
| 89 | void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); } |
| Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 90 | void MipsTargetStreamer::emitDirectiveSetMips32R3() { forbidModuleDirective(); } |
| 91 | void MipsTargetStreamer::emitDirectiveSetMips32R5() { forbidModuleDirective(); } |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 92 | void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); } |
| 93 | void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); } |
| 94 | void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); } |
| Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 95 | void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); } |
| 96 | void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); } |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 97 | void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); } |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 98 | void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); } |
| 99 | void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); } |
| Toma Tabacu | 2969650 | 2015-06-02 09:48:04 +0000 | [diff] [blame] | 100 | void MipsTargetStreamer::emitDirectiveSetSoftFloat() { |
| 101 | forbidModuleDirective(); |
| 102 | } |
| 103 | void MipsTargetStreamer::emitDirectiveSetHardFloat() { |
| 104 | forbidModuleDirective(); |
| 105 | } |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 106 | void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); } |
| Petar Jovanovic | 65f1024 | 2017-10-05 17:40:32 +0000 | [diff] [blame] | 107 | void MipsTargetStreamer::emitDirectiveSetDspr2() { forbidModuleDirective(); } |
| Toma Tabacu | 351b2fe | 2014-09-17 09:01:54 +0000 | [diff] [blame] | 108 | void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); } |
| Toma Tabacu | c4c202a | 2014-10-01 14:53:19 +0000 | [diff] [blame] | 109 | void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {} |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 110 | bool MipsTargetStreamer::emitDirectiveCpRestore( |
| Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 111 | int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc, |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 112 | const MCSubtargetInfo *STI) { |
| Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 113 | forbidModuleDirective(); |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 114 | return true; |
| Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 115 | } |
| Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 116 | void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, |
| 117 | const MCSymbol &Sym, bool IsReg) { |
| 118 | } |
| Daniel Sanders | f173dda | 2015-09-22 10:50:09 +0000 | [diff] [blame] | 119 | void MipsTargetStreamer::emitDirectiveCpreturn(unsigned SaveLocation, |
| 120 | bool SaveLocationIsRegister) {} |
| Toma Tabacu | bfcbfd5 | 2015-06-23 12:34:19 +0000 | [diff] [blame] | 121 | |
| Toma Tabacu | a64e540 | 2015-06-25 12:44:38 +0000 | [diff] [blame] | 122 | void MipsTargetStreamer::emitDirectiveModuleFP() {} |
| Toma Tabacu | bfcbfd5 | 2015-06-23 12:34:19 +0000 | [diff] [blame] | 123 | |
| Toma Tabacu | 3c49958 | 2015-06-25 10:56:57 +0000 | [diff] [blame] | 124 | void MipsTargetStreamer::emitDirectiveModuleOddSPReg() { |
| 125 | if (!ABIFlagsSection.OddSPReg && !ABIFlagsSection.Is32BitABI) |
| Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 126 | report_fatal_error("+nooddspreg is only valid for O32"); |
| 127 | } |
| Toma Tabacu | 0f09313 | 2015-06-30 13:46:03 +0000 | [diff] [blame] | 128 | void MipsTargetStreamer::emitDirectiveModuleSoftFloat() {} |
| 129 | void MipsTargetStreamer::emitDirectiveModuleHardFloat() {} |
| Simon Dardis | 805f1e0 | 2017-07-11 21:28:36 +0000 | [diff] [blame] | 130 | void MipsTargetStreamer::emitDirectiveModuleMT() {} |
| Petar Jovanovic | 3408caf | 2018-03-14 14:13:31 +0000 | [diff] [blame] | 131 | void MipsTargetStreamer::emitDirectiveModuleCRC() {} |
| 132 | void MipsTargetStreamer::emitDirectiveModuleNoCRC() {} |
| Petar Jovanovic | d4349f3 | 2018-04-27 09:12:08 +0000 | [diff] [blame] | 133 | void MipsTargetStreamer::emitDirectiveModuleVirt() {} |
| 134 | void MipsTargetStreamer::emitDirectiveModuleNoVirt() {} |
| Petar Jovanovic | daf5169 | 2018-05-17 16:30:32 +0000 | [diff] [blame^] | 135 | void MipsTargetStreamer::emitDirectiveModuleGINV() {} |
| 136 | void MipsTargetStreamer::emitDirectiveModuleNoGINV() {} |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 137 | void MipsTargetStreamer::emitDirectiveSetFp( |
| 138 | MipsABIFlagsSection::FpABIKind Value) { |
| 139 | forbidModuleDirective(); |
| 140 | } |
| Toma Tabacu | 32c72aa | 2015-06-30 09:36:50 +0000 | [diff] [blame] | 141 | void MipsTargetStreamer::emitDirectiveSetOddSPReg() { forbidModuleDirective(); } |
| 142 | void MipsTargetStreamer::emitDirectiveSetNoOddSPReg() { |
| 143 | forbidModuleDirective(); |
| 144 | } |
| Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 145 | |
| Daniel Sanders | a736b37 | 2016-04-29 13:33:12 +0000 | [diff] [blame] | 146 | void MipsTargetStreamer::emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc, |
| 147 | const MCSubtargetInfo *STI) { |
| 148 | MCInst TmpInst; |
| 149 | TmpInst.setOpcode(Opcode); |
| 150 | TmpInst.addOperand(MCOperand::createReg(Reg0)); |
| 151 | TmpInst.setLoc(IDLoc); |
| 152 | getStreamer().EmitInstruction(TmpInst, *STI); |
| 153 | } |
| 154 | |
| 155 | void MipsTargetStreamer::emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, |
| 156 | SMLoc IDLoc, const MCSubtargetInfo *STI) { |
| 157 | MCInst TmpInst; |
| 158 | TmpInst.setOpcode(Opcode); |
| 159 | TmpInst.addOperand(MCOperand::createReg(Reg0)); |
| 160 | TmpInst.addOperand(Op1); |
| 161 | TmpInst.setLoc(IDLoc); |
| 162 | getStreamer().EmitInstruction(TmpInst, *STI); |
| 163 | } |
| 164 | |
| 165 | void MipsTargetStreamer::emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, |
| 166 | SMLoc IDLoc, const MCSubtargetInfo *STI) { |
| 167 | emitRX(Opcode, Reg0, MCOperand::createImm(Imm), IDLoc, STI); |
| 168 | } |
| 169 | |
| 170 | void MipsTargetStreamer::emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, |
| 171 | SMLoc IDLoc, const MCSubtargetInfo *STI) { |
| 172 | emitRX(Opcode, Reg0, MCOperand::createReg(Reg1), IDLoc, STI); |
| 173 | } |
| 174 | |
| 175 | void MipsTargetStreamer::emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, |
| 176 | SMLoc IDLoc, const MCSubtargetInfo *STI) { |
| 177 | MCInst TmpInst; |
| 178 | TmpInst.setOpcode(Opcode); |
| 179 | TmpInst.addOperand(MCOperand::createImm(Imm1)); |
| 180 | TmpInst.addOperand(MCOperand::createImm(Imm2)); |
| 181 | TmpInst.setLoc(IDLoc); |
| 182 | getStreamer().EmitInstruction(TmpInst, *STI); |
| 183 | } |
| 184 | |
| 185 | void MipsTargetStreamer::emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, |
| 186 | MCOperand Op2, SMLoc IDLoc, |
| 187 | const MCSubtargetInfo *STI) { |
| 188 | MCInst TmpInst; |
| 189 | TmpInst.setOpcode(Opcode); |
| 190 | TmpInst.addOperand(MCOperand::createReg(Reg0)); |
| 191 | TmpInst.addOperand(MCOperand::createReg(Reg1)); |
| 192 | TmpInst.addOperand(Op2); |
| 193 | TmpInst.setLoc(IDLoc); |
| 194 | getStreamer().EmitInstruction(TmpInst, *STI); |
| 195 | } |
| 196 | |
| 197 | void MipsTargetStreamer::emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, |
| 198 | unsigned Reg2, SMLoc IDLoc, |
| 199 | const MCSubtargetInfo *STI) { |
| 200 | emitRRX(Opcode, Reg0, Reg1, MCOperand::createReg(Reg2), IDLoc, STI); |
| 201 | } |
| 202 | |
| 203 | void MipsTargetStreamer::emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, |
| 204 | int16_t Imm, SMLoc IDLoc, |
| 205 | const MCSubtargetInfo *STI) { |
| 206 | emitRRX(Opcode, Reg0, Reg1, MCOperand::createImm(Imm), IDLoc, STI); |
| 207 | } |
| 208 | |
| Simon Dardis | de5ed0c | 2017-11-14 22:26:42 +0000 | [diff] [blame] | 209 | void MipsTargetStreamer::emitRRIII(unsigned Opcode, unsigned Reg0, |
| 210 | unsigned Reg1, int16_t Imm0, int16_t Imm1, |
| 211 | int16_t Imm2, SMLoc IDLoc, |
| 212 | const MCSubtargetInfo *STI) { |
| 213 | MCInst TmpInst; |
| 214 | TmpInst.setOpcode(Opcode); |
| 215 | TmpInst.addOperand(MCOperand::createReg(Reg0)); |
| 216 | TmpInst.addOperand(MCOperand::createReg(Reg1)); |
| 217 | TmpInst.addOperand(MCOperand::createImm(Imm0)); |
| 218 | TmpInst.addOperand(MCOperand::createImm(Imm1)); |
| 219 | TmpInst.addOperand(MCOperand::createImm(Imm2)); |
| 220 | TmpInst.setLoc(IDLoc); |
| 221 | getStreamer().EmitInstruction(TmpInst, *STI); |
| 222 | } |
| 223 | |
| Daniel Sanders | a736b37 | 2016-04-29 13:33:12 +0000 | [diff] [blame] | 224 | void MipsTargetStreamer::emitAddu(unsigned DstReg, unsigned SrcReg, |
| 225 | unsigned TrgReg, bool Is64Bit, |
| 226 | const MCSubtargetInfo *STI) { |
| 227 | emitRRR(Is64Bit ? Mips::DADDu : Mips::ADDu, DstReg, SrcReg, TrgReg, SMLoc(), |
| 228 | STI); |
| 229 | } |
| 230 | |
| 231 | void MipsTargetStreamer::emitDSLL(unsigned DstReg, unsigned SrcReg, |
| 232 | int16_t ShiftAmount, SMLoc IDLoc, |
| 233 | const MCSubtargetInfo *STI) { |
| 234 | if (ShiftAmount >= 32) { |
| 235 | emitRRI(Mips::DSLL32, DstReg, SrcReg, ShiftAmount - 32, IDLoc, STI); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | emitRRI(Mips::DSLL, DstReg, SrcReg, ShiftAmount, IDLoc, STI); |
| 240 | } |
| 241 | |
| 242 | void MipsTargetStreamer::emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, |
| 243 | const MCSubtargetInfo *STI) { |
| 244 | if (hasShortDelaySlot) |
| 245 | emitRR(Mips::MOVE16_MM, Mips::ZERO, Mips::ZERO, IDLoc, STI); |
| 246 | else |
| 247 | emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI); |
| 248 | } |
| 249 | |
| 250 | void MipsTargetStreamer::emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI) { |
| 251 | emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI); |
| 252 | } |
| 253 | |
| Daniel Sanders | 7225cd5 | 2016-04-29 16:16:49 +0000 | [diff] [blame] | 254 | /// Emit the $gp restore operation for .cprestore. |
| 255 | void MipsTargetStreamer::emitGPRestore(int Offset, SMLoc IDLoc, |
| 256 | const MCSubtargetInfo *STI) { |
| 257 | emitLoadWithImmOffset(Mips::LW, Mips::GP, Mips::SP, Offset, Mips::GP, IDLoc, |
| 258 | STI); |
| 259 | } |
| 260 | |
| 261 | /// Emit a store instruction with an immediate offset. |
| Daniel Sanders | fba875f | 2016-04-29 13:43:45 +0000 | [diff] [blame] | 262 | void MipsTargetStreamer::emitStoreWithImmOffset( |
| 263 | unsigned Opcode, unsigned SrcReg, unsigned BaseReg, int64_t Offset, |
| Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 264 | function_ref<unsigned()> GetATReg, SMLoc IDLoc, |
| Daniel Sanders | 241c679 | 2016-05-12 14:01:50 +0000 | [diff] [blame] | 265 | const MCSubtargetInfo *STI) { |
| Daniel Sanders | 7225cd5 | 2016-04-29 16:16:49 +0000 | [diff] [blame] | 266 | if (isInt<16>(Offset)) { |
| 267 | emitRRI(Opcode, SrcReg, BaseReg, Offset, IDLoc, STI); |
| 268 | return; |
| 269 | } |
| 270 | |
| Daniel Sanders | fba875f | 2016-04-29 13:43:45 +0000 | [diff] [blame] | 271 | // sw $8, offset($8) => lui $at, %hi(offset) |
| 272 | // add $at, $at, $8 |
| 273 | // sw $8, %lo(offset)($at) |
| 274 | |
| Daniel Sanders | 241c679 | 2016-05-12 14:01:50 +0000 | [diff] [blame] | 275 | unsigned ATReg = GetATReg(); |
| 276 | if (!ATReg) |
| 277 | return; |
| 278 | |
| Daniel Sanders | fba875f | 2016-04-29 13:43:45 +0000 | [diff] [blame] | 279 | unsigned LoOffset = Offset & 0x0000ffff; |
| 280 | unsigned HiOffset = (Offset & 0xffff0000) >> 16; |
| 281 | |
| 282 | // If msb of LoOffset is 1(negative number) we must increment HiOffset |
| 283 | // to account for the sign-extension of the low part. |
| 284 | if (LoOffset & 0x8000) |
| 285 | HiOffset++; |
| 286 | |
| 287 | // Generate the base address in ATReg. |
| 288 | emitRI(Mips::LUi, ATReg, HiOffset, IDLoc, STI); |
| 289 | if (BaseReg != Mips::ZERO) |
| 290 | emitRRR(Mips::ADDu, ATReg, ATReg, BaseReg, IDLoc, STI); |
| 291 | // Emit the store with the adjusted base and offset. |
| 292 | emitRRI(Opcode, SrcReg, ATReg, LoOffset, IDLoc, STI); |
| 293 | } |
| 294 | |
| 295 | /// Emit a store instruction with an symbol offset. Symbols are assumed to be |
| 296 | /// out of range for a simm16 will be expanded to appropriate instructions. |
| 297 | void MipsTargetStreamer::emitStoreWithSymOffset( |
| 298 | unsigned Opcode, unsigned SrcReg, unsigned BaseReg, MCOperand &HiOperand, |
| 299 | MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, |
| 300 | const MCSubtargetInfo *STI) { |
| 301 | // sw $8, sym => lui $at, %hi(sym) |
| 302 | // sw $8, %lo(sym)($at) |
| 303 | |
| 304 | // Generate the base address in ATReg. |
| 305 | emitRX(Mips::LUi, ATReg, HiOperand, IDLoc, STI); |
| 306 | if (BaseReg != Mips::ZERO) |
| 307 | emitRRR(Mips::ADDu, ATReg, ATReg, BaseReg, IDLoc, STI); |
| 308 | // Emit the store with the adjusted base and offset. |
| 309 | emitRRX(Opcode, SrcReg, ATReg, LoOperand, IDLoc, STI); |
| 310 | } |
| 311 | |
| Daniel Sanders | 7225cd5 | 2016-04-29 16:16:49 +0000 | [diff] [blame] | 312 | /// Emit a load instruction with an immediate offset. DstReg and TmpReg are |
| 313 | /// permitted to be the same register iff DstReg is distinct from BaseReg and |
| 314 | /// DstReg is a GPR. It is the callers responsibility to identify such cases |
| 315 | /// and pass the appropriate register in TmpReg. |
| Daniel Sanders | fba875f | 2016-04-29 13:43:45 +0000 | [diff] [blame] | 316 | void MipsTargetStreamer::emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, |
| 317 | unsigned BaseReg, int64_t Offset, |
| 318 | unsigned TmpReg, SMLoc IDLoc, |
| 319 | const MCSubtargetInfo *STI) { |
| Daniel Sanders | 7225cd5 | 2016-04-29 16:16:49 +0000 | [diff] [blame] | 320 | if (isInt<16>(Offset)) { |
| 321 | emitRRI(Opcode, DstReg, BaseReg, Offset, IDLoc, STI); |
| 322 | return; |
| 323 | } |
| 324 | |
| Daniel Sanders | fba875f | 2016-04-29 13:43:45 +0000 | [diff] [blame] | 325 | // 1) lw $8, offset($9) => lui $8, %hi(offset) |
| 326 | // add $8, $8, $9 |
| 327 | // lw $8, %lo(offset)($9) |
| 328 | // 2) lw $8, offset($8) => lui $at, %hi(offset) |
| 329 | // add $at, $at, $8 |
| 330 | // lw $8, %lo(offset)($at) |
| 331 | |
| 332 | unsigned LoOffset = Offset & 0x0000ffff; |
| 333 | unsigned HiOffset = (Offset & 0xffff0000) >> 16; |
| 334 | |
| 335 | // If msb of LoOffset is 1(negative number) we must increment HiOffset |
| 336 | // to account for the sign-extension of the low part. |
| 337 | if (LoOffset & 0x8000) |
| 338 | HiOffset++; |
| 339 | |
| 340 | // Generate the base address in TmpReg. |
| 341 | emitRI(Mips::LUi, TmpReg, HiOffset, IDLoc, STI); |
| 342 | if (BaseReg != Mips::ZERO) |
| 343 | emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI); |
| 344 | // Emit the load with the adjusted base and offset. |
| 345 | emitRRI(Opcode, DstReg, TmpReg, LoOffset, IDLoc, STI); |
| 346 | } |
| 347 | |
| 348 | /// Emit a load instruction with an symbol offset. Symbols are assumed to be |
| 349 | /// out of range for a simm16 will be expanded to appropriate instructions. |
| 350 | /// DstReg and TmpReg are permitted to be the same register iff DstReg is a |
| 351 | /// GPR. It is the callers responsibility to identify such cases and pass the |
| 352 | /// appropriate register in TmpReg. |
| 353 | void MipsTargetStreamer::emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, |
| 354 | unsigned BaseReg, |
| 355 | MCOperand &HiOperand, |
| 356 | MCOperand &LoOperand, |
| 357 | unsigned TmpReg, SMLoc IDLoc, |
| 358 | const MCSubtargetInfo *STI) { |
| 359 | // 1) lw $8, sym => lui $8, %hi(sym) |
| 360 | // lw $8, %lo(sym)($8) |
| 361 | // 2) ldc1 $f0, sym => lui $at, %hi(sym) |
| 362 | // ldc1 $f0, %lo(sym)($at) |
| 363 | |
| 364 | // Generate the base address in TmpReg. |
| 365 | emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI); |
| 366 | if (BaseReg != Mips::ZERO) |
| 367 | emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI); |
| 368 | // Emit the load with the adjusted base and offset. |
| 369 | emitRRX(Opcode, DstReg, TmpReg, LoOperand, IDLoc, STI); |
| 370 | } |
| 371 | |
| Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 372 | MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S, |
| 373 | formatted_raw_ostream &OS) |
| 374 | : MipsTargetStreamer(S), OS(OS) {} |
| Jack Carter | 6ef6cc5 | 2013-11-19 20:53:28 +0000 | [diff] [blame] | 375 | |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 376 | void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() { |
| 377 | OS << "\t.set\tmicromips\n"; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 378 | forbidModuleDirective(); |
| Jack Carter | 6ef6cc5 | 2013-11-19 20:53:28 +0000 | [diff] [blame] | 379 | } |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 380 | |
| 381 | void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() { |
| 382 | OS << "\t.set\tnomicromips\n"; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 383 | forbidModuleDirective(); |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 386 | void MipsTargetAsmStreamer::emitDirectiveSetMips16() { |
| 387 | OS << "\t.set\tmips16\n"; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 388 | forbidModuleDirective(); |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() { |
| 392 | OS << "\t.set\tnomips16\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 393 | MipsTargetStreamer::emitDirectiveSetNoMips16(); |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 396 | void MipsTargetAsmStreamer::emitDirectiveSetReorder() { |
| 397 | OS << "\t.set\treorder\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 398 | MipsTargetStreamer::emitDirectiveSetReorder(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() { |
| 402 | OS << "\t.set\tnoreorder\n"; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 403 | forbidModuleDirective(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void MipsTargetAsmStreamer::emitDirectiveSetMacro() { |
| 407 | OS << "\t.set\tmacro\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 408 | MipsTargetStreamer::emitDirectiveSetMacro(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() { |
| 412 | OS << "\t.set\tnomacro\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 413 | MipsTargetStreamer::emitDirectiveSetNoMacro(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| Daniel Sanders | 4493443 | 2014-08-07 12:03:36 +0000 | [diff] [blame] | 416 | void MipsTargetAsmStreamer::emitDirectiveSetMsa() { |
| 417 | OS << "\t.set\tmsa\n"; |
| 418 | MipsTargetStreamer::emitDirectiveSetMsa(); |
| 419 | } |
| 420 | |
| 421 | void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() { |
| 422 | OS << "\t.set\tnomsa\n"; |
| 423 | MipsTargetStreamer::emitDirectiveSetNoMsa(); |
| 424 | } |
| 425 | |
| Simon Dardis | 805f1e0 | 2017-07-11 21:28:36 +0000 | [diff] [blame] | 426 | void MipsTargetAsmStreamer::emitDirectiveSetMt() { |
| 427 | OS << "\t.set\tmt\n"; |
| 428 | MipsTargetStreamer::emitDirectiveSetMt(); |
| 429 | } |
| 430 | |
| 431 | void MipsTargetAsmStreamer::emitDirectiveSetNoMt() { |
| 432 | OS << "\t.set\tnomt\n"; |
| 433 | MipsTargetStreamer::emitDirectiveSetNoMt(); |
| 434 | } |
| 435 | |
| Petar Jovanovic | 3408caf | 2018-03-14 14:13:31 +0000 | [diff] [blame] | 436 | void MipsTargetAsmStreamer::emitDirectiveSetCRC() { |
| 437 | OS << "\t.set\tcrc\n"; |
| 438 | MipsTargetStreamer::emitDirectiveSetCRC(); |
| 439 | } |
| 440 | |
| 441 | void MipsTargetAsmStreamer::emitDirectiveSetNoCRC() { |
| 442 | OS << "\t.set\tnocrc\n"; |
| 443 | MipsTargetStreamer::emitDirectiveSetNoCRC(); |
| 444 | } |
| 445 | |
| Petar Jovanovic | d4349f3 | 2018-04-27 09:12:08 +0000 | [diff] [blame] | 446 | void MipsTargetAsmStreamer::emitDirectiveSetVirt() { |
| 447 | OS << "\t.set\tvirt\n"; |
| 448 | MipsTargetStreamer::emitDirectiveSetVirt(); |
| 449 | } |
| 450 | |
| 451 | void MipsTargetAsmStreamer::emitDirectiveSetNoVirt() { |
| 452 | OS << "\t.set\tnovirt\n"; |
| 453 | MipsTargetStreamer::emitDirectiveSetNoVirt(); |
| 454 | } |
| 455 | |
| Petar Jovanovic | daf5169 | 2018-05-17 16:30:32 +0000 | [diff] [blame^] | 456 | void MipsTargetAsmStreamer::emitDirectiveSetGINV() { |
| 457 | OS << "\t.set\tginv\n"; |
| 458 | MipsTargetStreamer::emitDirectiveSetGINV(); |
| 459 | } |
| 460 | |
| 461 | void MipsTargetAsmStreamer::emitDirectiveSetNoGINV() { |
| 462 | OS << "\t.set\tnoginv\n"; |
| 463 | MipsTargetStreamer::emitDirectiveSetNoGINV(); |
| 464 | } |
| 465 | |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 466 | void MipsTargetAsmStreamer::emitDirectiveSetAt() { |
| 467 | OS << "\t.set\tat\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 468 | MipsTargetStreamer::emitDirectiveSetAt(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| Toma Tabacu | 16a7449 | 2015-02-13 10:30:57 +0000 | [diff] [blame] | 471 | void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) { |
| 472 | OS << "\t.set\tat=$" << Twine(RegNo) << "\n"; |
| 473 | MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo); |
| 474 | } |
| 475 | |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 476 | void MipsTargetAsmStreamer::emitDirectiveSetNoAt() { |
| 477 | OS << "\t.set\tnoat\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 478 | MipsTargetStreamer::emitDirectiveSetNoAt(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) { |
| 482 | OS << "\t.end\t" << Name << '\n'; |
| 483 | } |
| 484 | |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 485 | void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) { |
| 486 | OS << "\t.ent\t" << Symbol.getName() << '\n'; |
| 487 | } |
| 488 | |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 489 | void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; } |
| Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 490 | |
| 491 | void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; } |
| 492 | |
| 493 | void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() { |
| 494 | OS << "\t.nan\tlegacy\n"; |
| 495 | } |
| 496 | |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 497 | void MipsTargetAsmStreamer::emitDirectiveOptionPic0() { |
| 498 | OS << "\t.option\tpic0\n"; |
| 499 | } |
| 500 | |
| Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 501 | void MipsTargetAsmStreamer::emitDirectiveOptionPic2() { |
| 502 | OS << "\t.option\tpic2\n"; |
| 503 | } |
| 504 | |
| Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 505 | void MipsTargetAsmStreamer::emitDirectiveInsn() { |
| 506 | MipsTargetStreamer::emitDirectiveInsn(); |
| 507 | OS << "\t.insn\n"; |
| 508 | } |
| 509 | |
| Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 510 | void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize, |
| 511 | unsigned ReturnReg) { |
| 512 | OS << "\t.frame\t$" |
| 513 | << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << "," |
| 514 | << StackSize << ",$" |
| Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 515 | << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n'; |
| 516 | } |
| 517 | |
| Toma Tabacu | 85618b3 | 2014-08-19 14:22:52 +0000 | [diff] [blame] | 518 | void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) { |
| 519 | OS << "\t.set arch=" << Arch << "\n"; |
| 520 | MipsTargetStreamer::emitDirectiveSetArch(Arch); |
| 521 | } |
| 522 | |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 523 | void MipsTargetAsmStreamer::emitDirectiveSetMips0() { |
| 524 | OS << "\t.set\tmips0\n"; |
| 525 | MipsTargetStreamer::emitDirectiveSetMips0(); |
| 526 | } |
| Toma Tabacu | 2664779 | 2014-09-09 12:52:14 +0000 | [diff] [blame] | 527 | |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 528 | void MipsTargetAsmStreamer::emitDirectiveSetMips1() { |
| 529 | OS << "\t.set\tmips1\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 530 | MipsTargetStreamer::emitDirectiveSetMips1(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void MipsTargetAsmStreamer::emitDirectiveSetMips2() { |
| 534 | OS << "\t.set\tmips2\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 535 | MipsTargetStreamer::emitDirectiveSetMips2(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | void MipsTargetAsmStreamer::emitDirectiveSetMips3() { |
| 539 | OS << "\t.set\tmips3\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 540 | MipsTargetStreamer::emitDirectiveSetMips3(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | void MipsTargetAsmStreamer::emitDirectiveSetMips4() { |
| 544 | OS << "\t.set\tmips4\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 545 | MipsTargetStreamer::emitDirectiveSetMips4(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void MipsTargetAsmStreamer::emitDirectiveSetMips5() { |
| 549 | OS << "\t.set\tmips5\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 550 | MipsTargetStreamer::emitDirectiveSetMips5(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | void MipsTargetAsmStreamer::emitDirectiveSetMips32() { |
| 554 | OS << "\t.set\tmips32\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 555 | MipsTargetStreamer::emitDirectiveSetMips32(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 558 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() { |
| 559 | OS << "\t.set\tmips32r2\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 560 | MipsTargetStreamer::emitDirectiveSetMips32R2(); |
| Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 563 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() { |
| 564 | OS << "\t.set\tmips32r3\n"; |
| 565 | MipsTargetStreamer::emitDirectiveSetMips32R3(); |
| 566 | } |
| 567 | |
| 568 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() { |
| 569 | OS << "\t.set\tmips32r5\n"; |
| 570 | MipsTargetStreamer::emitDirectiveSetMips32R5(); |
| 571 | } |
| 572 | |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 573 | void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() { |
| 574 | OS << "\t.set\tmips32r6\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 575 | MipsTargetStreamer::emitDirectiveSetMips32R6(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| Matheus Almeida | 3b9c63d | 2014-03-26 15:14:32 +0000 | [diff] [blame] | 578 | void MipsTargetAsmStreamer::emitDirectiveSetMips64() { |
| 579 | OS << "\t.set\tmips64\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 580 | MipsTargetStreamer::emitDirectiveSetMips64(); |
| Matheus Almeida | 3b9c63d | 2014-03-26 15:14:32 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| Matheus Almeida | a2cd009 | 2014-03-26 14:52:22 +0000 | [diff] [blame] | 583 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() { |
| 584 | OS << "\t.set\tmips64r2\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 585 | MipsTargetStreamer::emitDirectiveSetMips64R2(); |
| Matheus Almeida | a2cd009 | 2014-03-26 14:52:22 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| Daniel Sanders | 1779314 | 2015-02-18 16:24:50 +0000 | [diff] [blame] | 588 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() { |
| 589 | OS << "\t.set\tmips64r3\n"; |
| 590 | MipsTargetStreamer::emitDirectiveSetMips64R3(); |
| 591 | } |
| 592 | |
| 593 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() { |
| 594 | OS << "\t.set\tmips64r5\n"; |
| 595 | MipsTargetStreamer::emitDirectiveSetMips64R5(); |
| 596 | } |
| 597 | |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 598 | void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() { |
| 599 | OS << "\t.set\tmips64r6\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 600 | MipsTargetStreamer::emitDirectiveSetMips64R6(); |
| Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| Vladimir Medic | 27c398e | 2014-03-05 11:05:09 +0000 | [diff] [blame] | 603 | void MipsTargetAsmStreamer::emitDirectiveSetDsp() { |
| 604 | OS << "\t.set\tdsp\n"; |
| Toma Tabacu | 88f05ce | 2014-08-13 12:48:12 +0000 | [diff] [blame] | 605 | MipsTargetStreamer::emitDirectiveSetDsp(); |
| Vladimir Medic | 27c398e | 2014-03-05 11:05:09 +0000 | [diff] [blame] | 606 | } |
| Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 607 | |
| Petar Jovanovic | 65f1024 | 2017-10-05 17:40:32 +0000 | [diff] [blame] | 608 | void MipsTargetAsmStreamer::emitDirectiveSetDspr2() { |
| 609 | OS << "\t.set\tdspr2\n"; |
| 610 | MipsTargetStreamer::emitDirectiveSetDspr2(); |
| 611 | } |
| 612 | |
| Toma Tabacu | 351b2fe | 2014-09-17 09:01:54 +0000 | [diff] [blame] | 613 | void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() { |
| 614 | OS << "\t.set\tnodsp\n"; |
| 615 | MipsTargetStreamer::emitDirectiveSetNoDsp(); |
| 616 | } |
| 617 | |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 618 | void MipsTargetAsmStreamer::emitDirectiveSetPop() { |
| 619 | OS << "\t.set\tpop\n"; |
| 620 | MipsTargetStreamer::emitDirectiveSetPop(); |
| 621 | } |
| Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 622 | |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 623 | void MipsTargetAsmStreamer::emitDirectiveSetPush() { |
| 624 | OS << "\t.set\tpush\n"; |
| 625 | MipsTargetStreamer::emitDirectiveSetPush(); |
| 626 | } |
| Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 627 | |
| Toma Tabacu | 2969650 | 2015-06-02 09:48:04 +0000 | [diff] [blame] | 628 | void MipsTargetAsmStreamer::emitDirectiveSetSoftFloat() { |
| 629 | OS << "\t.set\tsoftfloat\n"; |
| 630 | MipsTargetStreamer::emitDirectiveSetSoftFloat(); |
| 631 | } |
| 632 | |
| 633 | void MipsTargetAsmStreamer::emitDirectiveSetHardFloat() { |
| 634 | OS << "\t.set\thardfloat\n"; |
| 635 | MipsTargetStreamer::emitDirectiveSetHardFloat(); |
| 636 | } |
| 637 | |
| Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 638 | // Print a 32 bit hex number with all numbers. |
| 639 | static void printHex32(unsigned Value, raw_ostream &OS) { |
| 640 | OS << "0x"; |
| 641 | for (int i = 7; i >= 0; i--) |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 642 | OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4)); |
| Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask, |
| 646 | int CPUTopSavedRegOff) { |
| 647 | OS << "\t.mask \t"; |
| 648 | printHex32(CPUBitmask, OS); |
| 649 | OS << ',' << CPUTopSavedRegOff << '\n'; |
| 650 | } |
| 651 | |
| 652 | void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask, |
| 653 | int FPUTopSavedRegOff) { |
| 654 | OS << "\t.fmask\t"; |
| 655 | printHex32(FPUBitmask, OS); |
| 656 | OS << "," << FPUTopSavedRegOff << '\n'; |
| Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| Toma Tabacu | c4c202a | 2014-10-01 14:53:19 +0000 | [diff] [blame] | 659 | void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) { |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 660 | OS << "\t.cpload\t$" |
| 661 | << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n"; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 662 | forbidModuleDirective(); |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 665 | bool MipsTargetAsmStreamer::emitDirectiveCpRestore( |
| Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 666 | int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc, |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 667 | const MCSubtargetInfo *STI) { |
| 668 | MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI); |
| Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 669 | OS << "\t.cprestore\t" << Offset << "\n"; |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 670 | return true; |
| Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 673 | void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo, |
| 674 | int RegOrOffset, |
| 675 | const MCSymbol &Sym, |
| 676 | bool IsReg) { |
| 677 | OS << "\t.cpsetup\t$" |
| 678 | << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", "; |
| 679 | |
| 680 | if (IsReg) |
| 681 | OS << "$" |
| 682 | << StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower(); |
| 683 | else |
| 684 | OS << RegOrOffset; |
| 685 | |
| 686 | OS << ", "; |
| 687 | |
| Daniel Sanders | 5d79628 | 2015-09-21 09:26:55 +0000 | [diff] [blame] | 688 | OS << Sym.getName(); |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 689 | forbidModuleDirective(); |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| Daniel Sanders | f173dda | 2015-09-22 10:50:09 +0000 | [diff] [blame] | 692 | void MipsTargetAsmStreamer::emitDirectiveCpreturn(unsigned SaveLocation, |
| 693 | bool SaveLocationIsRegister) { |
| 694 | OS << "\t.cpreturn"; |
| 695 | forbidModuleDirective(); |
| 696 | } |
| 697 | |
| Toma Tabacu | a64e540 | 2015-06-25 12:44:38 +0000 | [diff] [blame] | 698 | void MipsTargetAsmStreamer::emitDirectiveModuleFP() { |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 699 | OS << "\t.module\tfp="; |
| Toma Tabacu | a64e540 | 2015-06-25 12:44:38 +0000 | [diff] [blame] | 700 | OS << ABIFlagsSection.getFpABIString(ABIFlagsSection.getFpABI()) << "\n"; |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 703 | void MipsTargetAsmStreamer::emitDirectiveSetFp( |
| 704 | MipsABIFlagsSection::FpABIKind Value) { |
| Toma Tabacu | 4e0cf8e | 2015-03-06 12:15:12 +0000 | [diff] [blame] | 705 | MipsTargetStreamer::emitDirectiveSetFp(Value); |
| 706 | |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 707 | OS << "\t.set\tfp="; |
| Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 708 | OS << ABIFlagsSection.getFpABIString(Value) << "\n"; |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| Toma Tabacu | 3c49958 | 2015-06-25 10:56:57 +0000 | [diff] [blame] | 711 | void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg() { |
| 712 | MipsTargetStreamer::emitDirectiveModuleOddSPReg(); |
| Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 713 | |
| Toma Tabacu | 3c49958 | 2015-06-25 10:56:57 +0000 | [diff] [blame] | 714 | OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n"; |
| Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| Toma Tabacu | 32c72aa | 2015-06-30 09:36:50 +0000 | [diff] [blame] | 717 | void MipsTargetAsmStreamer::emitDirectiveSetOddSPReg() { |
| 718 | MipsTargetStreamer::emitDirectiveSetOddSPReg(); |
| 719 | OS << "\t.set\toddspreg\n"; |
| 720 | } |
| 721 | |
| 722 | void MipsTargetAsmStreamer::emitDirectiveSetNoOddSPReg() { |
| 723 | MipsTargetStreamer::emitDirectiveSetNoOddSPReg(); |
| 724 | OS << "\t.set\tnooddspreg\n"; |
| 725 | } |
| 726 | |
| Toma Tabacu | 0f09313 | 2015-06-30 13:46:03 +0000 | [diff] [blame] | 727 | void MipsTargetAsmStreamer::emitDirectiveModuleSoftFloat() { |
| 728 | OS << "\t.module\tsoftfloat\n"; |
| 729 | } |
| 730 | |
| 731 | void MipsTargetAsmStreamer::emitDirectiveModuleHardFloat() { |
| 732 | OS << "\t.module\thardfloat\n"; |
| 733 | } |
| 734 | |
| Simon Dardis | 805f1e0 | 2017-07-11 21:28:36 +0000 | [diff] [blame] | 735 | void MipsTargetAsmStreamer::emitDirectiveModuleMT() { |
| 736 | OS << "\t.module\tmt\n"; |
| 737 | } |
| 738 | |
| Petar Jovanovic | 3408caf | 2018-03-14 14:13:31 +0000 | [diff] [blame] | 739 | void MipsTargetAsmStreamer::emitDirectiveModuleCRC() { |
| 740 | OS << "\t.module\tcrc\n"; |
| 741 | } |
| 742 | |
| 743 | void MipsTargetAsmStreamer::emitDirectiveModuleNoCRC() { |
| 744 | OS << "\t.module\tnocrc\n"; |
| 745 | } |
| 746 | |
| Petar Jovanovic | d4349f3 | 2018-04-27 09:12:08 +0000 | [diff] [blame] | 747 | void MipsTargetAsmStreamer::emitDirectiveModuleVirt() { |
| 748 | OS << "\t.module\tvirt\n"; |
| 749 | } |
| 750 | |
| 751 | void MipsTargetAsmStreamer::emitDirectiveModuleNoVirt() { |
| 752 | OS << "\t.module\tnovirt\n"; |
| 753 | } |
| 754 | |
| Petar Jovanovic | daf5169 | 2018-05-17 16:30:32 +0000 | [diff] [blame^] | 755 | void MipsTargetAsmStreamer::emitDirectiveModuleGINV() { |
| 756 | OS << "\t.module\tginv\n"; |
| 757 | } |
| 758 | |
| 759 | void MipsTargetAsmStreamer::emitDirectiveModuleNoGINV() { |
| 760 | OS << "\t.module\tnoginv\n"; |
| 761 | } |
| 762 | |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 763 | // This part is for ELF object output. |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 764 | MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S, |
| 765 | const MCSubtargetInfo &STI) |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 766 | : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) { |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 767 | MCAssembler &MCA = getStreamer().getAssembler(); |
| Daniel Sanders | 8de3d3c | 2016-05-06 14:37:24 +0000 | [diff] [blame] | 768 | |
| 769 | // It's possible that MCObjectFileInfo isn't fully initialized at this point |
| Matthias Braun | bb8507e | 2017-10-12 22:57:28 +0000 | [diff] [blame] | 770 | // due to an initialization order problem where LLVMTargetMachine creates the |
| Daniel Sanders | 8de3d3c | 2016-05-06 14:37:24 +0000 | [diff] [blame] | 771 | // target streamer before TargetLoweringObjectFile calls |
| 772 | // InitializeMCObjectFileInfo. There doesn't seem to be a single place that |
| 773 | // covers all cases so this statement covers most cases and direct object |
| 774 | // emission must call setPic() once MCObjectFileInfo has been initialized. The |
| 775 | // cases we don't handle here are covered by MipsAsmPrinter. |
| Rafael Espindola | 699281c | 2016-05-18 11:58:50 +0000 | [diff] [blame] | 776 | Pic = MCA.getContext().getObjectFileInfo()->isPositionIndependent(); |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 777 | |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 778 | const FeatureBitset &Features = STI.getFeatureBits(); |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 779 | |
| 780 | // Set the header flags that we can in the constructor. |
| 781 | // FIXME: This is a fairly terrible hack. We set the rest |
| 782 | // of these in the destructor. The problem here is two-fold: |
| 783 | // |
| 784 | // a: Some of the eflags can be set/reset by directives. |
| 785 | // b: There aren't any usage paths that initialize the ABI |
| 786 | // pointer until after we initialize either an assembler |
| 787 | // or the target machine. |
| 788 | // We can fix this by making the target streamer construct |
| 789 | // the ABI, but this is fraught with wide ranging dependency |
| 790 | // issues as well. |
| 791 | unsigned EFlags = MCA.getELFHeaderEFlags(); |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 792 | |
| Simon Dardis | 6433d5a | 2017-02-01 15:39:23 +0000 | [diff] [blame] | 793 | // FIXME: Fix a dependency issue by instantiating the ABI object to some |
| 794 | // default based off the triple. The triple doesn't describe the target |
| 795 | // fully, but any external user of the API that uses the MCTargetStreamer |
| 796 | // would otherwise crash on assertion failure. |
| 797 | |
| 798 | ABI = MipsABIInfo( |
| 799 | STI.getTargetTriple().getArch() == Triple::ArchType::mipsel || |
| 800 | STI.getTargetTriple().getArch() == Triple::ArchType::mips |
| 801 | ? MipsABIInfo::O32() |
| 802 | : MipsABIInfo::N64()); |
| 803 | |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 804 | // Architecture |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 805 | if (Features[Mips::FeatureMips64r6]) |
| Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 806 | EFlags |= ELF::EF_MIPS_ARCH_64R6; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 807 | else if (Features[Mips::FeatureMips64r2] || |
| 808 | Features[Mips::FeatureMips64r3] || |
| 809 | Features[Mips::FeatureMips64r5]) |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 810 | EFlags |= ELF::EF_MIPS_ARCH_64R2; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 811 | else if (Features[Mips::FeatureMips64]) |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 812 | EFlags |= ELF::EF_MIPS_ARCH_64; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 813 | else if (Features[Mips::FeatureMips5]) |
| Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 814 | EFlags |= ELF::EF_MIPS_ARCH_5; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 815 | else if (Features[Mips::FeatureMips4]) |
| Daniel Sanders | f7b3229 | 2014-04-03 12:13:36 +0000 | [diff] [blame] | 816 | EFlags |= ELF::EF_MIPS_ARCH_4; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 817 | else if (Features[Mips::FeatureMips3]) |
| Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 818 | EFlags |= ELF::EF_MIPS_ARCH_3; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 819 | else if (Features[Mips::FeatureMips32r6]) |
| Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 820 | EFlags |= ELF::EF_MIPS_ARCH_32R6; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 821 | else if (Features[Mips::FeatureMips32r2] || |
| 822 | Features[Mips::FeatureMips32r3] || |
| 823 | Features[Mips::FeatureMips32r5]) |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 824 | EFlags |= ELF::EF_MIPS_ARCH_32R2; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 825 | else if (Features[Mips::FeatureMips32]) |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 826 | EFlags |= ELF::EF_MIPS_ARCH_32; |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 827 | else if (Features[Mips::FeatureMips2]) |
| Daniel Sanders | 950f48d | 2014-07-04 15:21:53 +0000 | [diff] [blame] | 828 | EFlags |= ELF::EF_MIPS_ARCH_2; |
| 829 | else |
| 830 | EFlags |= ELF::EF_MIPS_ARCH_1; |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 831 | |
| Daniel Sanders | 415c159 | 2016-05-12 11:31:19 +0000 | [diff] [blame] | 832 | // Machine |
| 833 | if (Features[Mips::FeatureCnMips]) |
| 834 | EFlags |= ELF::EF_MIPS_MACH_OCTEON; |
| 835 | |
| Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 836 | // Other options. |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 837 | if (Features[Mips::FeatureNaN2008]) |
| Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 838 | EFlags |= ELF::EF_MIPS_NAN2008; |
| 839 | |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 840 | MCA.setELFHeaderEFlags(EFlags); |
| 841 | } |
| Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 842 | |
| Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 843 | void MipsTargetELFStreamer::emitLabel(MCSymbol *S) { |
| 844 | auto *Symbol = cast<MCSymbolELF>(S); |
| Rafael Espindola | c73aed1 | 2015-06-03 19:03:11 +0000 | [diff] [blame] | 845 | getStreamer().getAssembler().registerSymbol(*Symbol); |
| Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 846 | uint8_t Type = Symbol->getType(); |
| Rafael Espindola | 26e917c | 2014-01-15 03:07:12 +0000 | [diff] [blame] | 847 | if (Type != ELF::STT_FUNC) |
| 848 | return; |
| 849 | |
| Simon Dardis | 3c82a64 | 2017-02-08 16:25:05 +0000 | [diff] [blame] | 850 | if (isMicroMipsEnabled()) |
| 851 | Symbol->setOther(ELF::STO_MIPS_MICROMIPS); |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 854 | void MipsTargetELFStreamer::finish() { |
| 855 | MCAssembler &MCA = getStreamer().getAssembler(); |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 856 | const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo(); |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 857 | |
| Daniel Sanders | 41ffa5d | 2014-07-14 15:05:51 +0000 | [diff] [blame] | 858 | // .bss, .text and .data are always at least 16-byte aligned. |
| Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 859 | MCSection &TextSection = *OFI.getTextSection(); |
| Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 860 | MCA.registerSection(TextSection); |
| Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 861 | MCSection &DataSection = *OFI.getDataSection(); |
| Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 862 | MCA.registerSection(DataSection); |
| Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 863 | MCSection &BSSSection = *OFI.getBSSSection(); |
| Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 864 | MCA.registerSection(BSSSection); |
| Daniel Sanders | 41ffa5d | 2014-07-14 15:05:51 +0000 | [diff] [blame] | 865 | |
| Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 866 | TextSection.setAlignment(std::max(16u, TextSection.getAlignment())); |
| 867 | DataSection.setAlignment(std::max(16u, DataSection.getAlignment())); |
| 868 | BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment())); |
| Daniel Sanders | 41ffa5d | 2014-07-14 15:05:51 +0000 | [diff] [blame] | 869 | |
| Daniel Sanders | c07f06a | 2016-05-04 13:21:06 +0000 | [diff] [blame] | 870 | if (RoundSectionSizes) { |
| 871 | // Make sections sizes a multiple of the alignment. This is useful for |
| 872 | // verifying the output of IAS against the output of other assemblers but |
| 873 | // it's not necessary to produce a correct object and increases section |
| 874 | // size. |
| 875 | MCStreamer &OS = getStreamer(); |
| 876 | for (MCSection &S : MCA) { |
| 877 | MCSectionELF &Section = static_cast<MCSectionELF &>(S); |
| Daniel Sanders | 9db710a | 2016-04-29 12:44:07 +0000 | [diff] [blame] | 878 | |
| Daniel Sanders | c07f06a | 2016-05-04 13:21:06 +0000 | [diff] [blame] | 879 | unsigned Alignment = Section.getAlignment(); |
| 880 | if (Alignment) { |
| 881 | OS.SwitchSection(&Section); |
| 882 | if (Section.UseCodeAlign()) |
| 883 | OS.EmitCodeAlignment(Alignment, Alignment); |
| 884 | else |
| 885 | OS.EmitValueToAlignment(Alignment, 0, 1, Alignment); |
| 886 | } |
| Daniel Sanders | 9db710a | 2016-04-29 12:44:07 +0000 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 890 | const FeatureBitset &Features = STI.getFeatureBits(); |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 891 | |
| 892 | // Update e_header flags. See the FIXME and comment above in |
| 893 | // the constructor for a full rundown on this. |
| 894 | unsigned EFlags = MCA.getELFHeaderEFlags(); |
| 895 | |
| 896 | // ABI |
| 897 | // N64 does not require any ABI bits. |
| 898 | if (getABI().IsO32()) |
| 899 | EFlags |= ELF::EF_MIPS_ABI_O32; |
| 900 | else if (getABI().IsN32()) |
| 901 | EFlags |= ELF::EF_MIPS_ABI2; |
| 902 | |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 903 | if (Features[Mips::FeatureGP64Bit]) { |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 904 | if (getABI().IsO32()) |
| 905 | EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */ |
| Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 906 | } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64]) |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 907 | EFlags |= ELF::EF_MIPS_32BITMODE; |
| 908 | |
| Simon Dardis | ca74dd7 | 2017-01-27 11:36:52 +0000 | [diff] [blame] | 909 | // -mplt is not implemented but we should act as if it was |
| 910 | // given. |
| 911 | if (!Features[Mips::FeatureNoABICalls]) |
| 912 | EFlags |= ELF::EF_MIPS_CPIC; |
| 913 | |
| 914 | if (Pic) |
| 915 | EFlags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC; |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 916 | |
| 917 | MCA.setELFHeaderEFlags(EFlags); |
| 918 | |
| Daniel Sanders | 68c3747 | 2014-07-21 13:30:55 +0000 | [diff] [blame] | 919 | // Emit all the option records. |
| 920 | // At the moment we are only emitting .Mips.options (ODK_REGINFO) and |
| 921 | // .reginfo. |
| 922 | MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer); |
| 923 | MEF.EmitMipsOptionRecords(); |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 924 | |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 925 | emitMipsAbiFlags(); |
| Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 928 | void MipsTargetELFStreamer::emitAssignment(MCSymbol *S, const MCExpr *Value) { |
| 929 | auto *Symbol = cast<MCSymbolELF>(S); |
| Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 930 | // If on rhs is micromips symbol then mark Symbol as microMips. |
| 931 | if (Value->getKind() != MCExpr::SymbolRef) |
| 932 | return; |
| Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 933 | const auto &RhsSym = cast<MCSymbolELF>( |
| 934 | static_cast<const MCSymbolRefExpr *>(Value)->getSymbol()); |
| Toma Tabacu | 2cc44f5 | 2015-04-16 13:37:32 +0000 | [diff] [blame] | 935 | |
| Rafael Espindola | 8c006ee | 2015-06-04 05:59:23 +0000 | [diff] [blame] | 936 | if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS)) |
| Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 937 | return; |
| 938 | |
| Rafael Espindola | 8c006ee | 2015-06-04 05:59:23 +0000 | [diff] [blame] | 939 | Symbol->setOther(ELF::STO_MIPS_MICROMIPS); |
| Zoran Jovanovic | 28221d8 | 2014-03-20 09:44:49 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 942 | MCELFStreamer &MipsTargetELFStreamer::getStreamer() { |
| Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 943 | return static_cast<MCELFStreamer &>(Streamer); |
| Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 946 | void MipsTargetELFStreamer::emitDirectiveSetMicroMips() { |
| 947 | MicroMipsEnabled = true; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 948 | forbidModuleDirective(); |
| Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 949 | } |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 950 | |
| 951 | void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() { |
| 952 | MicroMipsEnabled = false; |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 953 | forbidModuleDirective(); |
| Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| Daniel Sanders | cda908a | 2016-05-16 09:10:13 +0000 | [diff] [blame] | 956 | void MipsTargetELFStreamer::setUsesMicroMips() { |
| 957 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 958 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 959 | Flags |= ELF::EF_MIPS_MICROMIPS; |
| 960 | MCA.setELFHeaderEFlags(Flags); |
| 961 | } |
| 962 | |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 963 | void MipsTargetELFStreamer::emitDirectiveSetMips16() { |
| Rafael Espindola | e758375 | 2014-01-24 16:13:20 +0000 | [diff] [blame] | 964 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 965 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 966 | Flags |= ELF::EF_MIPS_ARCH_ASE_M16; |
| 967 | MCA.setELFHeaderEFlags(Flags); |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 968 | forbidModuleDirective(); |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 971 | void MipsTargetELFStreamer::emitDirectiveSetNoReorder() { |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 972 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 973 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 974 | Flags |= ELF::EF_MIPS_NOREORDER; |
| 975 | MCA.setELFHeaderEFlags(Flags); |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 976 | forbidModuleDirective(); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 979 | void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) { |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 980 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 981 | MCContext &Context = MCA.getContext(); |
| 982 | MCStreamer &OS = getStreamer(); |
| 983 | |
| Scott Egerton | 219fae9 | 2016-02-17 11:15:16 +0000 | [diff] [blame] | 984 | MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS, 0); |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 985 | |
| Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 986 | MCSymbol *Sym = Context.getOrCreateSymbol(Name); |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 987 | const MCSymbolRefExpr *ExprRef = |
| Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 988 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Context); |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 989 | |
| Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 990 | MCA.registerSection(*Sec); |
| Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 991 | Sec->setAlignment(4); |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 992 | |
| 993 | OS.PushSection(); |
| 994 | |
| 995 | OS.SwitchSection(Sec); |
| 996 | |
| 997 | OS.EmitValueImpl(ExprRef, 4); |
| 998 | |
| 999 | OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask |
| 1000 | OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset |
| 1001 | |
| 1002 | OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask |
| 1003 | OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset |
| 1004 | |
| 1005 | OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset |
| 1006 | OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg |
| 1007 | OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg |
| 1008 | |
| 1009 | // The .end directive marks the end of a procedure. Invalidate |
| 1010 | // the information gathered up until this point. |
| 1011 | GPRInfoSet = FPRInfoSet = FrameInfoSet = false; |
| 1012 | |
| 1013 | OS.PopSection(); |
| Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 1014 | |
| 1015 | // .end also implicitly sets the size. |
| 1016 | MCSymbol *CurPCSym = Context.createTempSymbol(); |
| 1017 | OS.EmitLabel(CurPCSym); |
| 1018 | const MCExpr *Size = MCBinaryExpr::createSub( |
| 1019 | MCSymbolRefExpr::create(CurPCSym, MCSymbolRefExpr::VK_None, Context), |
| 1020 | ExprRef, Context); |
| Simon Dardis | 68e9d94 | 2017-02-03 15:48:53 +0000 | [diff] [blame] | 1021 | |
| 1022 | // The ELFObjectWriter can determine the absolute size as it has access to |
| 1023 | // the layout information of the assembly file, so a size expression rather |
| 1024 | // than an absolute value is ok here. |
| Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 1025 | static_cast<MCSymbolELF *>(Sym)->setSize(Size); |
| Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 1028 | void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) { |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 1029 | GPRInfoSet = FPRInfoSet = FrameInfoSet = false; |
| Daniel Sanders | 2b56133 | 2015-11-23 16:08:03 +0000 | [diff] [blame] | 1030 | |
| 1031 | // .ent also acts like an implicit '.type symbol, STT_FUNC' |
| 1032 | static_cast<const MCSymbolELF &>(Symbol).setType(ELF::STT_FUNC); |
| Rafael Espindola | 6633d57 | 2014-01-14 18:57:12 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 1035 | void MipsTargetELFStreamer::emitDirectiveAbiCalls() { |
| 1036 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1037 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 1038 | Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC; |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 1039 | MCA.setELFHeaderEFlags(Flags); |
| 1040 | } |
| Matheus Almeida | 0051f2d | 2014-04-16 15:48:55 +0000 | [diff] [blame] | 1041 | |
| 1042 | void MipsTargetELFStreamer::emitDirectiveNaN2008() { |
| 1043 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1044 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 1045 | Flags |= ELF::EF_MIPS_NAN2008; |
| 1046 | MCA.setELFHeaderEFlags(Flags); |
| 1047 | } |
| 1048 | |
| 1049 | void MipsTargetELFStreamer::emitDirectiveNaNLegacy() { |
| 1050 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1051 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 1052 | Flags &= ~ELF::EF_MIPS_NAN2008; |
| 1053 | MCA.setELFHeaderEFlags(Flags); |
| 1054 | } |
| 1055 | |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 1056 | void MipsTargetELFStreamer::emitDirectiveOptionPic0() { |
| 1057 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1058 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 1059 | // This option overrides other PIC options like -KPIC. |
| 1060 | Pic = false; |
| Jack Carter | 0cd3c19 | 2014-01-06 23:27:31 +0000 | [diff] [blame] | 1061 | Flags &= ~ELF::EF_MIPS_PIC; |
| 1062 | MCA.setELFHeaderEFlags(Flags); |
| 1063 | } |
| Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 1064 | |
| Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 1065 | void MipsTargetELFStreamer::emitDirectiveOptionPic2() { |
| 1066 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1067 | unsigned Flags = MCA.getELFHeaderEFlags(); |
| 1068 | Pic = true; |
| 1069 | // NOTE: We are following the GAS behaviour here which means the directive |
| 1070 | // 'pic2' also sets the CPIC bit in the ELF header. This is different from |
| 1071 | // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and |
| 1072 | // EF_MIPS_CPIC to be mutually exclusive. |
| 1073 | Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC; |
| 1074 | MCA.setELFHeaderEFlags(Flags); |
| 1075 | } |
| 1076 | |
| Toma Tabacu | 9ca5096 | 2015-04-16 09:53:47 +0000 | [diff] [blame] | 1077 | void MipsTargetELFStreamer::emitDirectiveInsn() { |
| 1078 | MipsTargetStreamer::emitDirectiveInsn(); |
| 1079 | MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer); |
| 1080 | MEF.createPendingLabelRelocs(); |
| 1081 | } |
| 1082 | |
| Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 1083 | void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize, |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 1084 | unsigned ReturnReg_) { |
| 1085 | MCContext &Context = getStreamer().getAssembler().getContext(); |
| 1086 | const MCRegisterInfo *RegInfo = Context.getRegisterInfo(); |
| 1087 | |
| 1088 | FrameInfoSet = true; |
| 1089 | FrameReg = RegInfo->getEncodingValue(StackReg); |
| 1090 | FrameOffset = StackSize; |
| 1091 | ReturnReg = RegInfo->getEncodingValue(ReturnReg_); |
| Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 1092 | } |
| Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 1093 | |
| 1094 | void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask, |
| 1095 | int CPUTopSavedRegOff) { |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 1096 | GPRInfoSet = true; |
| 1097 | GPRBitMask = CPUBitmask; |
| 1098 | GPROffset = CPUTopSavedRegOff; |
| Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask, |
| 1102 | int FPUTopSavedRegOff) { |
| Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 1103 | FPRInfoSet = true; |
| 1104 | FPRBitMask = FPUBitmask; |
| 1105 | FPROffset = FPUTopSavedRegOff; |
| Rafael Espindola | 25fa291 | 2014-01-27 04:33:11 +0000 | [diff] [blame] | 1106 | } |
| Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 1107 | |
| Toma Tabacu | c4c202a | 2014-10-01 14:53:19 +0000 | [diff] [blame] | 1108 | void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) { |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1109 | // .cpload $reg |
| 1110 | // This directive expands to: |
| 1111 | // lui $gp, %hi(_gp_disp) |
| 1112 | // addui $gp, $gp, %lo(_gp_disp) |
| 1113 | // addu $gp, $gp, $reg |
| 1114 | // when support for position independent code is enabled. |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 1115 | if (!Pic || (getABI().IsN32() || getABI().IsN64())) |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1116 | return; |
| 1117 | |
| 1118 | // There's a GNU extension controlled by -mno-shared that allows |
| 1119 | // locally-binding symbols to be accessed using absolute addresses. |
| 1120 | // This is currently not supported. When supported -mno-shared makes |
| 1121 | // .cpload expand to: |
| 1122 | // lui $gp, %hi(__gnu_local_gp) |
| 1123 | // addiu $gp, $gp, %lo(__gnu_local_gp) |
| 1124 | |
| 1125 | StringRef SymName("_gp_disp"); |
| 1126 | MCAssembler &MCA = getStreamer().getAssembler(); |
| Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 1127 | MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName); |
| Rafael Espindola | b5d316b | 2015-05-29 20:21:02 +0000 | [diff] [blame] | 1128 | MCA.registerSymbol(*GP_Disp); |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1129 | |
| 1130 | MCInst TmpInst; |
| 1131 | TmpInst.setOpcode(Mips::LUi); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1132 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| Daniel Sanders | fe98b2f | 2016-05-03 13:35:44 +0000 | [diff] [blame] | 1133 | const MCExpr *HiSym = MipsMCExpr::create( |
| 1134 | MipsMCExpr::MEK_HI, |
| 1135 | MCSymbolRefExpr::create("_gp_disp", MCSymbolRefExpr::VK_None, |
| 1136 | MCA.getContext()), |
| 1137 | MCA.getContext()); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1138 | TmpInst.addOperand(MCOperand::createExpr(HiSym)); |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1139 | getStreamer().EmitInstruction(TmpInst, STI); |
| 1140 | |
| 1141 | TmpInst.clear(); |
| 1142 | |
| 1143 | TmpInst.setOpcode(Mips::ADDiu); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1144 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| 1145 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| Daniel Sanders | fe98b2f | 2016-05-03 13:35:44 +0000 | [diff] [blame] | 1146 | const MCExpr *LoSym = MipsMCExpr::create( |
| 1147 | MipsMCExpr::MEK_LO, |
| 1148 | MCSymbolRefExpr::create("_gp_disp", MCSymbolRefExpr::VK_None, |
| 1149 | MCA.getContext()), |
| 1150 | MCA.getContext()); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1151 | TmpInst.addOperand(MCOperand::createExpr(LoSym)); |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1152 | getStreamer().EmitInstruction(TmpInst, STI); |
| 1153 | |
| 1154 | TmpInst.clear(); |
| 1155 | |
| 1156 | TmpInst.setOpcode(Mips::ADDu); |
| Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 1157 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| 1158 | TmpInst.addOperand(MCOperand::createReg(Mips::GP)); |
| 1159 | TmpInst.addOperand(MCOperand::createReg(RegNo)); |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1160 | getStreamer().EmitInstruction(TmpInst, STI); |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 1161 | |
| Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 1162 | forbidModuleDirective(); |
| Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 1163 | } |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1164 | |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 1165 | bool MipsTargetELFStreamer::emitDirectiveCpRestore( |
| Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 1166 | int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc, |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 1167 | const MCSubtargetInfo *STI) { |
| 1168 | MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI); |
| Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 1169 | // .cprestore offset |
| 1170 | // When PIC mode is enabled and the O32 ABI is used, this directive expands |
| 1171 | // to: |
| 1172 | // sw $gp, offset($sp) |
| 1173 | // and adds a corresponding LW after every JAL. |
| 1174 | |
| 1175 | // Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it |
| 1176 | // is used in non-PIC mode. |
| 1177 | if (!Pic || (getABI().IsN32() || getABI().IsN64())) |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 1178 | return true; |
| 1179 | |
| Daniel Sanders | 7225cd5 | 2016-04-29 16:16:49 +0000 | [diff] [blame] | 1180 | // Store the $gp on the stack. |
| Daniel Sanders | 241c679 | 2016-05-12 14:01:50 +0000 | [diff] [blame] | 1181 | emitStoreWithImmOffset(Mips::SW, Mips::GP, Mips::SP, Offset, GetATReg, IDLoc, |
| Daniel Sanders | 7225cd5 | 2016-04-29 16:16:49 +0000 | [diff] [blame] | 1182 | STI); |
| Daniel Sanders | df8510d | 2016-05-11 12:48:19 +0000 | [diff] [blame] | 1183 | return true; |
| Daniel Sanders | e2982ad | 2015-09-17 16:08:39 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1186 | void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo, |
| 1187 | int RegOrOffset, |
| 1188 | const MCSymbol &Sym, |
| 1189 | bool IsReg) { |
| 1190 | // Only N32 and N64 emit anything for .cpsetup iff PIC is set. |
| Eric Christopher | a576281 | 2015-01-26 17:33:46 +0000 | [diff] [blame] | 1191 | if (!Pic || !(getABI().IsN32() || getABI().IsN64())) |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1192 | return; |
| 1193 | |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1194 | forbidModuleDirective(); |
| 1195 | |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1196 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1197 | MCInst Inst; |
| 1198 | |
| 1199 | // Either store the old $gp in a register or on the stack |
| 1200 | if (IsReg) { |
| 1201 | // move $save, $gpreg |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1202 | emitRRR(Mips::OR64, RegOrOffset, Mips::GP, Mips::ZERO, SMLoc(), &STI); |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1203 | } else { |
| 1204 | // sd $gpreg, offset($sp) |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1205 | emitRRI(Mips::SD, Mips::GP, Mips::SP, RegOrOffset, SMLoc(), &STI); |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1206 | } |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1207 | |
| 1208 | if (getABI().IsN32()) { |
| 1209 | MCSymbol *GPSym = MCA.getContext().getOrCreateSymbol("__gnu_local_gp"); |
| 1210 | const MipsMCExpr *HiExpr = MipsMCExpr::create( |
| 1211 | MipsMCExpr::MEK_HI, MCSymbolRefExpr::create(GPSym, MCA.getContext()), |
| 1212 | MCA.getContext()); |
| 1213 | const MipsMCExpr *LoExpr = MipsMCExpr::create( |
| 1214 | MipsMCExpr::MEK_LO, MCSymbolRefExpr::create(GPSym, MCA.getContext()), |
| 1215 | MCA.getContext()); |
| 1216 | |
| 1217 | // lui $gp, %hi(__gnu_local_gp) |
| 1218 | emitRX(Mips::LUi, Mips::GP, MCOperand::createExpr(HiExpr), SMLoc(), &STI); |
| 1219 | |
| 1220 | // addiu $gp, $gp, %lo(__gnu_local_gp) |
| 1221 | emitRRX(Mips::ADDiu, Mips::GP, Mips::GP, MCOperand::createExpr(LoExpr), |
| 1222 | SMLoc(), &STI); |
| 1223 | |
| 1224 | return; |
| 1225 | } |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1226 | |
| Daniel Sanders | fe98b2f | 2016-05-03 13:35:44 +0000 | [diff] [blame] | 1227 | const MipsMCExpr *HiExpr = MipsMCExpr::createGpOff( |
| 1228 | MipsMCExpr::MEK_HI, MCSymbolRefExpr::create(&Sym, MCA.getContext()), |
| 1229 | MCA.getContext()); |
| 1230 | const MipsMCExpr *LoExpr = MipsMCExpr::createGpOff( |
| 1231 | MipsMCExpr::MEK_LO, MCSymbolRefExpr::create(&Sym, MCA.getContext()), |
| 1232 | MCA.getContext()); |
| Toma Tabacu | 8874eac | 2015-02-18 13:46:53 +0000 | [diff] [blame] | 1233 | |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1234 | // lui $gp, %hi(%neg(%gp_rel(funcSym))) |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1235 | emitRX(Mips::LUi, Mips::GP, MCOperand::createExpr(HiExpr), SMLoc(), &STI); |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1236 | |
| 1237 | // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym))) |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1238 | emitRRX(Mips::ADDiu, Mips::GP, Mips::GP, MCOperand::createExpr(LoExpr), |
| 1239 | SMLoc(), &STI); |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1240 | |
| 1241 | // daddu $gp, $gp, $funcreg |
| Daniel Sanders | e858136 | 2016-06-14 10:13:47 +0000 | [diff] [blame] | 1242 | emitRRR(Mips::DADDu, Mips::GP, Mips::GP, RegNo, SMLoc(), &STI); |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| Daniel Sanders | f173dda | 2015-09-22 10:50:09 +0000 | [diff] [blame] | 1245 | void MipsTargetELFStreamer::emitDirectiveCpreturn(unsigned SaveLocation, |
| 1246 | bool SaveLocationIsRegister) { |
| 1247 | // Only N32 and N64 emit anything for .cpreturn iff PIC is set. |
| 1248 | if (!Pic || !(getABI().IsN32() || getABI().IsN64())) |
| 1249 | return; |
| 1250 | |
| 1251 | MCInst Inst; |
| 1252 | // Either restore the old $gp from a register or on the stack |
| 1253 | if (SaveLocationIsRegister) { |
| 1254 | Inst.setOpcode(Mips::OR); |
| 1255 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 1256 | Inst.addOperand(MCOperand::createReg(SaveLocation)); |
| 1257 | Inst.addOperand(MCOperand::createReg(Mips::ZERO)); |
| 1258 | } else { |
| 1259 | Inst.setOpcode(Mips::LD); |
| 1260 | Inst.addOperand(MCOperand::createReg(Mips::GP)); |
| 1261 | Inst.addOperand(MCOperand::createReg(Mips::SP)); |
| 1262 | Inst.addOperand(MCOperand::createImm(SaveLocation)); |
| 1263 | } |
| 1264 | getStreamer().EmitInstruction(Inst, STI); |
| 1265 | |
| 1266 | forbidModuleDirective(); |
| 1267 | } |
| 1268 | |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 1269 | void MipsTargetELFStreamer::emitMipsAbiFlags() { |
| 1270 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 1271 | MCContext &Context = MCA.getContext(); |
| 1272 | MCStreamer &OS = getStreamer(); |
| Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 1273 | MCSectionELF *Sec = Context.getELFSection( |
| Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 1274 | ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, ""); |
| Rafael Espindola | bb9a71c | 2015-05-26 15:07:25 +0000 | [diff] [blame] | 1275 | MCA.registerSection(*Sec); |
| Rafael Espindola | 967d6a6 | 2015-05-21 21:02:35 +0000 | [diff] [blame] | 1276 | Sec->setAlignment(8); |
| Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 1277 | OS.SwitchSection(Sec); |
| 1278 | |
| Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 1279 | OS << ABIFlagsSection; |
| Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 1280 | } |