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