2013-11-19 07:55:27 +08:00
|
|
|
//===-- MipsTargetStreamer.cpp - Mips Target Streamer Methods -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides Mips specific target streamer methods.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-01-27 11:53:56 +08:00
|
|
|
#include "InstPrinter/MipsInstPrinter.h"
|
2014-07-21 21:30:55 +08:00
|
|
|
#include "MipsELFStreamer.h"
|
2014-03-04 18:07:28 +08:00
|
|
|
#include "MipsMCTargetDesc.h"
|
2014-02-01 07:10:26 +08:00
|
|
|
#include "MipsTargetObjectFile.h"
|
2013-11-19 07:55:27 +08:00
|
|
|
#include "MipsTargetStreamer.h"
|
2014-02-01 07:10:26 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2013-11-19 07:55:27 +08:00
|
|
|
#include "llvm/MC/MCELF.h"
|
2014-02-01 07:10:26 +08:00
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2014-01-26 14:57:13 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2014-03-04 18:07:28 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2013-11-19 07:55:27 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Support/ELF.h"
|
2013-11-19 07:55:27 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-07-08 16:59:22 +08:00
|
|
|
MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S)
|
2014-08-14 17:18:14 +08:00
|
|
|
: MCTargetStreamer(S), ModuleDirectiveAllowed(true) {
|
2014-08-13 18:07:34 +08:00
|
|
|
GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
|
|
|
|
}
|
2014-06-24 03:43:40 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMicroMips() {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips16() {}
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoMips16() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetReorder() { forbidModuleDirective(); }
|
2014-06-24 03:43:40 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoReorder() {}
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMacro() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoMacro() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMsa() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoMsa() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetAt() { forbidModuleDirective(); }
|
2015-02-13 18:30:57 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
|
|
|
|
forbidModuleDirective();
|
|
|
|
}
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoAt() { forbidModuleDirective(); }
|
2014-06-24 03:43:40 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveEnd(StringRef Name) {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveAbiCalls() {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveNaN2008() {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveOptionPic0() {}
|
|
|
|
void MipsTargetStreamer::emitDirectiveOptionPic2() {}
|
|
|
|
void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
|
|
|
unsigned ReturnReg) {}
|
|
|
|
void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
|
|
|
|
void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
|
|
|
|
}
|
2014-08-19 22:22:52 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetArch(StringRef Arch) {
|
|
|
|
forbidModuleDirective();
|
|
|
|
}
|
2015-03-06 20:15:12 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips0() { forbidModuleDirective(); }
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips1() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips2() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips3() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips4() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips5() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips32() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips32R2() { forbidModuleDirective(); }
|
2015-02-19 00:24:50 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips32R3() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips32R5() { forbidModuleDirective(); }
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips32R6() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips64() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips64R2() { forbidModuleDirective(); }
|
2015-02-19 00:24:50 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips64R3() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips64R5() { forbidModuleDirective(); }
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetMips64R6() { forbidModuleDirective(); }
|
2015-03-06 20:15:12 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetPop() { forbidModuleDirective(); }
|
|
|
|
void MipsTargetStreamer::emitDirectiveSetPush() { forbidModuleDirective(); }
|
2014-08-14 17:18:14 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetDsp() { forbidModuleDirective(); }
|
2014-09-17 17:01:54 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetNoDsp() { forbidModuleDirective(); }
|
2014-10-01 22:53:19 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveCpLoad(unsigned RegNo) {}
|
2014-06-24 03:43:40 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
|
|
|
|
const MCSymbol &Sym, bool IsReg) {
|
|
|
|
}
|
2014-07-10 21:38:23 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
|
|
|
|
bool IsO32ABI) {
|
|
|
|
if (!Enabled && !IsO32ABI)
|
|
|
|
report_fatal_error("+nooddspreg is only valid for O32");
|
|
|
|
}
|
2015-03-06 20:15:12 +08:00
|
|
|
void MipsTargetStreamer::emitDirectiveSetFp(
|
|
|
|
MipsABIFlagsSection::FpABIKind Value) {
|
|
|
|
forbidModuleDirective();
|
|
|
|
}
|
2014-01-26 14:06:37 +08:00
|
|
|
|
|
|
|
MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
|
|
|
|
formatted_raw_ostream &OS)
|
|
|
|
: MipsTargetStreamer(S), OS(OS) {}
|
2013-11-20 04:53:28 +08:00
|
|
|
|
2014-01-14 12:25:13 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
|
|
|
|
OS << "\t.set\tmicromips\n";
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-01-14 12:25:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
|
|
|
|
OS << "\t.set\tnomicromips\n";
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2013-11-20 04:53:28 +08:00
|
|
|
}
|
2014-01-14 12:25:13 +08:00
|
|
|
|
2014-01-15 02:57:12 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
|
|
|
|
OS << "\t.set\tmips16\n";
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-01-15 02:57:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
|
|
|
|
OS << "\t.set\tnomips16\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetNoMips16();
|
2014-01-15 02:57:12 +08:00
|
|
|
}
|
|
|
|
|
2014-01-26 13:06:48 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
|
|
|
|
OS << "\t.set\treorder\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetReorder();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
|
|
|
|
OS << "\t.set\tnoreorder\n";
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
|
|
|
|
OS << "\t.set\tmacro\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMacro();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
|
|
|
|
OS << "\t.set\tnomacro\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetNoMacro();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
2014-08-07 20:03:36 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMsa() {
|
|
|
|
OS << "\t.set\tmsa\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetMsa();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMsa() {
|
|
|
|
OS << "\t.set\tnomsa\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetNoMsa();
|
|
|
|
}
|
|
|
|
|
2014-01-26 13:06:48 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetAt() {
|
|
|
|
OS << "\t.set\tat\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetAt();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
2015-02-13 18:30:57 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetAtWithArg(unsigned RegNo) {
|
|
|
|
OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetAtWithArg(RegNo);
|
|
|
|
}
|
|
|
|
|
2014-01-26 13:06:48 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
|
|
|
|
OS << "\t.set\tnoat\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetNoAt();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
|
|
|
|
OS << "\t.end\t" << Name << '\n';
|
|
|
|
}
|
|
|
|
|
2014-01-15 02:57:12 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
|
|
|
|
OS << "\t.ent\t" << Symbol.getName() << '\n';
|
|
|
|
}
|
|
|
|
|
2014-01-07 07:27:31 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
|
2014-04-16 23:48:55 +08:00
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveNaNLegacy() {
|
|
|
|
OS << "\t.nan\tlegacy\n";
|
|
|
|
}
|
|
|
|
|
2014-01-07 07:27:31 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
|
|
|
|
OS << "\t.option\tpic0\n";
|
|
|
|
}
|
|
|
|
|
2014-03-26 21:40:29 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
|
|
|
|
OS << "\t.option\tpic2\n";
|
|
|
|
}
|
|
|
|
|
2014-01-27 11:53:56 +08:00
|
|
|
void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
|
|
|
unsigned ReturnReg) {
|
|
|
|
OS << "\t.frame\t$"
|
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
|
|
|
|
<< StackSize << ",$"
|
2014-01-27 12:33:11 +08:00
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
|
|
|
|
}
|
|
|
|
|
2014-08-19 22:22:52 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetArch(StringRef Arch) {
|
|
|
|
OS << "\t.set arch=" << Arch << "\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetArch(Arch);
|
|
|
|
}
|
|
|
|
|
2015-03-06 20:15:12 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips0() {
|
|
|
|
OS << "\t.set\tmips0\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetMips0();
|
|
|
|
}
|
2014-09-09 20:52:14 +08:00
|
|
|
|
2014-08-04 20:20:00 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips1() {
|
|
|
|
OS << "\t.set\tmips1\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips1();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips2() {
|
|
|
|
OS << "\t.set\tmips2\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips2();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips3() {
|
|
|
|
OS << "\t.set\tmips3\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips3();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips4() {
|
|
|
|
OS << "\t.set\tmips4\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips4();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips5() {
|
|
|
|
OS << "\t.set\tmips5\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips5();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips32() {
|
|
|
|
OS << "\t.set\tmips32\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips32();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 17:54:09 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips32R2() {
|
|
|
|
OS << "\t.set\tmips32r2\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips32R2();
|
2014-03-04 17:54:09 +08:00
|
|
|
}
|
|
|
|
|
2015-02-19 00:24:50 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips32R3() {
|
|
|
|
OS << "\t.set\tmips32r3\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetMips32R3();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips32R5() {
|
|
|
|
OS << "\t.set\tmips32r5\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetMips32R5();
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:20:00 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips32R6() {
|
|
|
|
OS << "\t.set\tmips32r6\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips32R6();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
2014-03-26 23:14:32 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips64() {
|
|
|
|
OS << "\t.set\tmips64\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips64();
|
2014-03-26 23:14:32 +08:00
|
|
|
}
|
|
|
|
|
2014-03-26 22:52:22 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips64R2() {
|
|
|
|
OS << "\t.set\tmips64r2\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips64R2();
|
2014-03-26 22:52:22 +08:00
|
|
|
}
|
|
|
|
|
2015-02-19 00:24:50 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips64R3() {
|
|
|
|
OS << "\t.set\tmips64r3\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetMips64R3();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips64R5() {
|
|
|
|
OS << "\t.set\tmips64r5\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetMips64R5();
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:20:00 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips64R6() {
|
|
|
|
OS << "\t.set\tmips64r6\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetMips64R6();
|
2014-08-04 20:20:00 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 19:05:09 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetDsp() {
|
|
|
|
OS << "\t.set\tdsp\n";
|
2014-08-13 20:48:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetDsp();
|
2014-03-05 19:05:09 +08:00
|
|
|
}
|
2014-09-09 18:15:38 +08:00
|
|
|
|
2014-09-17 17:01:54 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoDsp() {
|
|
|
|
OS << "\t.set\tnodsp\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetNoDsp();
|
|
|
|
}
|
|
|
|
|
2015-03-06 20:15:12 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetPop() {
|
|
|
|
OS << "\t.set\tpop\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetPop();
|
|
|
|
}
|
2014-09-09 18:15:38 +08:00
|
|
|
|
2015-03-06 20:15:12 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetPush() {
|
|
|
|
OS << "\t.set\tpush\n";
|
|
|
|
MipsTargetStreamer::emitDirectiveSetPush();
|
|
|
|
}
|
2014-09-09 18:15:38 +08:00
|
|
|
|
2014-01-27 12:33:11 +08:00
|
|
|
// Print a 32 bit hex number with all numbers.
|
|
|
|
static void printHex32(unsigned Value, raw_ostream &OS) {
|
|
|
|
OS << "0x";
|
|
|
|
for (int i = 7; i >= 0; i--)
|
2014-07-08 16:59:22 +08:00
|
|
|
OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
|
2014-01-27 12:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
|
|
|
|
int CPUTopSavedRegOff) {
|
|
|
|
OS << "\t.mask \t";
|
|
|
|
printHex32(CPUBitmask, OS);
|
|
|
|
OS << ',' << CPUTopSavedRegOff << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
|
|
|
|
int FPUTopSavedRegOff) {
|
|
|
|
OS << "\t.fmask\t";
|
|
|
|
printHex32(FPUBitmask, OS);
|
|
|
|
OS << "," << FPUTopSavedRegOff << '\n';
|
2014-01-27 11:53:56 +08:00
|
|
|
}
|
|
|
|
|
2014-10-01 22:53:19 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveCpLoad(unsigned RegNo) {
|
2014-04-30 19:28:42 +08:00
|
|
|
OS << "\t.cpload\t$"
|
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-04-30 19:28:42 +08:00
|
|
|
}
|
|
|
|
|
2014-05-01 18:24:46 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveCpsetup(unsigned RegNo,
|
|
|
|
int RegOrOffset,
|
|
|
|
const MCSymbol &Sym,
|
|
|
|
bool IsReg) {
|
|
|
|
OS << "\t.cpsetup\t$"
|
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
|
|
|
|
|
|
|
|
if (IsReg)
|
|
|
|
OS << "$"
|
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(RegOrOffset)).lower();
|
|
|
|
else
|
|
|
|
OS << RegOrOffset;
|
|
|
|
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
OS << Sym.getName() << "\n";
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-07-08 16:59:22 +08:00
|
|
|
}
|
|
|
|
|
2014-07-10 21:38:23 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveModuleFP(
|
|
|
|
MipsABIFlagsSection::FpABIKind Value, bool Is32BitABI) {
|
|
|
|
MipsTargetStreamer::emitDirectiveModuleFP(Value, Is32BitABI);
|
2014-07-08 18:11:38 +08:00
|
|
|
|
2014-07-08 16:59:22 +08:00
|
|
|
StringRef ModuleValue;
|
|
|
|
OS << "\t.module\tfp=";
|
2014-07-10 21:38:23 +08:00
|
|
|
OS << ABIFlagsSection.getFpABIString(Value) << "\n";
|
2014-07-08 16:59:22 +08:00
|
|
|
}
|
|
|
|
|
2014-07-10 21:38:23 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetFp(
|
|
|
|
MipsABIFlagsSection::FpABIKind Value) {
|
2015-03-06 20:15:12 +08:00
|
|
|
MipsTargetStreamer::emitDirectiveSetFp(Value);
|
|
|
|
|
2014-07-08 16:59:22 +08:00
|
|
|
StringRef ModuleValue;
|
|
|
|
OS << "\t.set\tfp=";
|
2014-07-10 21:38:23 +08:00
|
|
|
OS << ABIFlagsSection.getFpABIString(Value) << "\n";
|
2014-07-08 16:59:22 +08:00
|
|
|
}
|
|
|
|
|
2014-07-10 21:38:23 +08:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
|
|
|
|
bool IsO32ABI) {
|
|
|
|
MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
|
|
|
|
|
|
|
|
OS << "\t.module\t" << (Enabled ? "" : "no") << "oddspreg\n";
|
|
|
|
}
|
|
|
|
|
2014-01-07 07:27:31 +08:00
|
|
|
// This part is for ELF object output.
|
2014-01-26 14:57:13 +08:00
|
|
|
MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
|
|
|
|
const MCSubtargetInfo &STI)
|
2014-02-01 07:10:26 +08:00
|
|
|
: MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
|
2014-01-26 14:57:13 +08:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
2014-07-08 16:59:22 +08:00
|
|
|
Pic = (MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_)
|
2014-03-26 21:40:29 +08:00
|
|
|
? true
|
|
|
|
: false;
|
2014-01-26 14:57:13 +08:00
|
|
|
|
2015-03-24 17:17:25 +08:00
|
|
|
const FeatureBitset &Features = STI.getFeatureBits();
|
2015-01-27 01:33:46 +08:00
|
|
|
|
|
|
|
// Set the header flags that we can in the constructor.
|
|
|
|
// FIXME: This is a fairly terrible hack. We set the rest
|
|
|
|
// of these in the destructor. The problem here is two-fold:
|
|
|
|
//
|
|
|
|
// a: Some of the eflags can be set/reset by directives.
|
|
|
|
// b: There aren't any usage paths that initialize the ABI
|
|
|
|
// pointer until after we initialize either an assembler
|
|
|
|
// or the target machine.
|
|
|
|
// We can fix this by making the target streamer construct
|
|
|
|
// the ABI, but this is fraught with wide ranging dependency
|
|
|
|
// issues as well.
|
|
|
|
unsigned EFlags = MCA.getELFHeaderEFlags();
|
2014-01-26 14:57:13 +08:00
|
|
|
|
|
|
|
// Architecture
|
2015-03-24 17:17:25 +08:00
|
|
|
if (Features[Mips::FeatureMips64r6])
|
2014-07-04 23:21:53 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_64R6;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips64r2] ||
|
|
|
|
Features[Mips::FeatureMips64r3] ||
|
|
|
|
Features[Mips::FeatureMips64r5])
|
2014-01-26 14:57:13 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_64R2;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips64])
|
2014-01-26 14:57:13 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_64;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips5])
|
2014-07-04 23:21:53 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_5;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips4])
|
2014-04-03 20:13:36 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_4;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips3])
|
2014-07-04 23:21:53 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_3;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips32r6])
|
2014-07-04 23:21:53 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_32R6;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips32r2] ||
|
|
|
|
Features[Mips::FeatureMips32r3] ||
|
|
|
|
Features[Mips::FeatureMips32r5])
|
2014-01-26 14:57:13 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_32R2;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips32])
|
2014-01-26 14:57:13 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_32;
|
2015-03-24 17:17:25 +08:00
|
|
|
else if (Features[Mips::FeatureMips2])
|
2014-07-04 23:21:53 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_2;
|
|
|
|
else
|
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_1;
|
2014-01-26 14:57:13 +08:00
|
|
|
|
2014-04-16 23:48:55 +08:00
|
|
|
// Other options.
|
2015-03-24 17:17:25 +08:00
|
|
|
if (Features[Mips::FeatureNaN2008])
|
2014-04-16 23:48:55 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_NAN2008;
|
|
|
|
|
2014-07-17 17:52:56 +08:00
|
|
|
// -mabicalls and -mplt are not implemented but we should act as if they were
|
|
|
|
// given.
|
|
|
|
EFlags |= ELF::EF_MIPS_CPIC;
|
|
|
|
|
2014-01-26 14:57:13 +08:00
|
|
|
MCA.setELFHeaderEFlags(EFlags);
|
|
|
|
}
|
2013-11-19 07:55:27 +08:00
|
|
|
|
2014-01-14 12:25:13 +08:00
|
|
|
void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
|
2014-01-15 11:07:12 +08:00
|
|
|
if (!isMicroMipsEnabled())
|
|
|
|
return;
|
2014-01-14 12:25:13 +08:00
|
|
|
MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Symbol);
|
2014-01-15 11:07:12 +08:00
|
|
|
uint8_t Type = MCELF::GetType(Data);
|
|
|
|
if (Type != ELF::STT_FUNC)
|
|
|
|
return;
|
|
|
|
|
2014-01-14 12:25:13 +08:00
|
|
|
// The "other" values are stored in the last 6 bits of the second byte
|
|
|
|
// The traditional defines for STO values assume the full byte and thus
|
|
|
|
// the shift to pack it.
|
2014-01-15 11:07:12 +08:00
|
|
|
MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
|
2014-01-14 12:25:13 +08:00
|
|
|
}
|
|
|
|
|
2014-02-01 07:10:26 +08:00
|
|
|
void MipsTargetELFStreamer::finish() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
2014-07-21 21:30:55 +08:00
|
|
|
const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
|
2014-02-01 07:10:26 +08:00
|
|
|
|
2014-07-14 23:05:51 +08:00
|
|
|
// .bss, .text and .data are always at least 16-byte aligned.
|
|
|
|
MCSectionData &TextSectionData =
|
|
|
|
MCA.getOrCreateSectionData(*OFI.getTextSection());
|
|
|
|
MCSectionData &DataSectionData =
|
|
|
|
MCA.getOrCreateSectionData(*OFI.getDataSection());
|
|
|
|
MCSectionData &BSSSectionData =
|
|
|
|
MCA.getOrCreateSectionData(*OFI.getBSSSection());
|
|
|
|
|
|
|
|
TextSectionData.setAlignment(std::max(16u, TextSectionData.getAlignment()));
|
|
|
|
DataSectionData.setAlignment(std::max(16u, DataSectionData.getAlignment()));
|
|
|
|
BSSSectionData.setAlignment(std::max(16u, BSSSectionData.getAlignment()));
|
|
|
|
|
2015-03-24 17:17:25 +08:00
|
|
|
const FeatureBitset &Features = STI.getFeatureBits();
|
2015-01-27 01:33:46 +08:00
|
|
|
|
|
|
|
// Update e_header flags. See the FIXME and comment above in
|
|
|
|
// the constructor for a full rundown on this.
|
|
|
|
unsigned EFlags = MCA.getELFHeaderEFlags();
|
|
|
|
|
|
|
|
// ABI
|
|
|
|
// N64 does not require any ABI bits.
|
|
|
|
if (getABI().IsO32())
|
|
|
|
EFlags |= ELF::EF_MIPS_ABI_O32;
|
|
|
|
else if (getABI().IsN32())
|
|
|
|
EFlags |= ELF::EF_MIPS_ABI2;
|
|
|
|
|
2015-03-24 17:17:25 +08:00
|
|
|
if (Features[Mips::FeatureGP64Bit]) {
|
2015-01-27 01:33:46 +08:00
|
|
|
if (getABI().IsO32())
|
|
|
|
EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
|
2015-03-24 17:17:25 +08:00
|
|
|
} else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
|
2015-01-27 01:33:46 +08:00
|
|
|
EFlags |= ELF::EF_MIPS_32BITMODE;
|
|
|
|
|
|
|
|
// If we've set the cpic eflag and we're n64, go ahead and set the pic
|
|
|
|
// one as well.
|
|
|
|
if (EFlags & ELF::EF_MIPS_CPIC && getABI().IsN64())
|
|
|
|
EFlags |= ELF::EF_MIPS_PIC;
|
|
|
|
|
|
|
|
MCA.setELFHeaderEFlags(EFlags);
|
|
|
|
|
2014-07-21 21:30:55 +08:00
|
|
|
// Emit all the option records.
|
|
|
|
// At the moment we are only emitting .Mips.options (ODK_REGINFO) and
|
|
|
|
// .reginfo.
|
|
|
|
MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
|
|
|
|
MEF.EmitMipsOptionRecords();
|
|
|
|
|
2014-07-08 16:59:22 +08:00
|
|
|
emitMipsAbiFlags();
|
2014-02-01 07:10:26 +08:00
|
|
|
}
|
|
|
|
|
2014-03-20 17:44:49 +08:00
|
|
|
void MipsTargetELFStreamer::emitAssignment(MCSymbol *Symbol,
|
|
|
|
const MCExpr *Value) {
|
|
|
|
// If on rhs is micromips symbol then mark Symbol as microMips.
|
|
|
|
if (Value->getKind() != MCExpr::SymbolRef)
|
|
|
|
return;
|
|
|
|
const MCSymbol &RhsSym =
|
2014-07-08 16:59:22 +08:00
|
|
|
static_cast<const MCSymbolRefExpr *>(Value)->getSymbol();
|
2014-03-20 17:44:49 +08:00
|
|
|
MCSymbolData &Data = getStreamer().getOrCreateSymbolData(&RhsSym);
|
|
|
|
uint8_t Type = MCELF::GetType(Data);
|
2014-07-08 16:59:22 +08:00
|
|
|
if ((Type != ELF::STT_FUNC) ||
|
|
|
|
!(MCELF::getOther(Data) & (ELF::STO_MIPS_MICROMIPS >> 2)))
|
2014-03-20 17:44:49 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
MCSymbolData &SymbolData = getStreamer().getOrCreateSymbolData(Symbol);
|
|
|
|
// The "other" values are stored in the last 6 bits of the second byte.
|
|
|
|
// The traditional defines for STO values assume the full byte and thus
|
|
|
|
// the shift to pack it.
|
|
|
|
MCELF::setOther(SymbolData, ELF::STO_MIPS_MICROMIPS >> 2);
|
|
|
|
}
|
|
|
|
|
2013-11-19 07:55:27 +08:00
|
|
|
MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
|
2014-01-26 14:06:37 +08:00
|
|
|
return static_cast<MCELFStreamer &>(Streamer);
|
2013-11-19 07:55:27 +08:00
|
|
|
}
|
|
|
|
|
2014-01-14 12:25:13 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
|
|
|
|
MicroMipsEnabled = true;
|
2014-01-26 14:57:13 +08:00
|
|
|
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_MICROMIPS;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-01-14 12:25:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
|
|
|
|
MicroMipsEnabled = false;
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2013-11-19 07:55:27 +08:00
|
|
|
}
|
2014-01-14 12:25:13 +08:00
|
|
|
|
2014-01-15 02:57:12 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMips16() {
|
2014-01-25 00:13:20 +08:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-01-15 02:57:12 +08:00
|
|
|
}
|
|
|
|
|
2014-01-26 13:06:48 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
|
2014-01-26 14:57:13 +08:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_NOREORDER;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
|
2014-08-13 18:07:34 +08:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
MCContext &Context = MCA.getContext();
|
|
|
|
MCStreamer &OS = getStreamer();
|
|
|
|
|
2015-01-30 01:33:21 +08:00
|
|
|
const MCSectionELF *Sec = Context.getELFSection(
|
|
|
|
".pdr", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHT_REL);
|
2014-08-13 18:07:34 +08:00
|
|
|
|
|
|
|
const MCSymbolRefExpr *ExprRef =
|
|
|
|
MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context);
|
|
|
|
|
|
|
|
MCSectionData &SecData = MCA.getOrCreateSectionData(*Sec);
|
|
|
|
SecData.setAlignment(4);
|
|
|
|
|
|
|
|
OS.PushSection();
|
|
|
|
|
|
|
|
OS.SwitchSection(Sec);
|
|
|
|
|
|
|
|
OS.EmitValueImpl(ExprRef, 4);
|
|
|
|
|
|
|
|
OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
|
|
|
|
OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
|
|
|
|
|
|
|
|
OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
|
|
|
|
OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
|
|
|
|
|
|
|
|
OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
|
|
|
|
OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
|
|
|
|
OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
|
|
|
|
|
|
|
|
// The .end directive marks the end of a procedure. Invalidate
|
|
|
|
// the information gathered up until this point.
|
|
|
|
GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
|
|
|
|
|
|
|
|
OS.PopSection();
|
2014-01-26 13:06:48 +08:00
|
|
|
}
|
|
|
|
|
2014-01-15 02:57:12 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
|
2014-08-13 18:07:34 +08:00
|
|
|
GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
|
2014-01-15 02:57:12 +08:00
|
|
|
}
|
|
|
|
|
2014-01-07 07:27:31 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
2014-01-26 14:57:13 +08:00
|
|
|
Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
|
2014-01-07 07:27:31 +08:00
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
2014-04-16 23:48:55 +08:00
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveNaN2008() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_NAN2008;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveNaNLegacy() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags &= ~ELF::EF_MIPS_NAN2008;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
|
|
|
|
2014-01-07 07:27:31 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
2014-03-26 21:40:29 +08:00
|
|
|
// This option overrides other PIC options like -KPIC.
|
|
|
|
Pic = false;
|
2014-01-07 07:27:31 +08:00
|
|
|
Flags &= ~ELF::EF_MIPS_PIC;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
2014-01-27 11:53:56 +08:00
|
|
|
|
2014-03-26 21:40:29 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Pic = true;
|
|
|
|
// NOTE: We are following the GAS behaviour here which means the directive
|
|
|
|
// 'pic2' also sets the CPIC bit in the ELF header. This is different from
|
|
|
|
// what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
|
|
|
|
// EF_MIPS_CPIC to be mutually exclusive.
|
|
|
|
Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
|
|
|
|
2014-01-27 11:53:56 +08:00
|
|
|
void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
2014-08-13 18:07:34 +08:00
|
|
|
unsigned ReturnReg_) {
|
|
|
|
MCContext &Context = getStreamer().getAssembler().getContext();
|
|
|
|
const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
|
|
|
|
|
|
|
|
FrameInfoSet = true;
|
|
|
|
FrameReg = RegInfo->getEncodingValue(StackReg);
|
|
|
|
FrameOffset = StackSize;
|
|
|
|
ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
|
2014-01-27 11:53:56 +08:00
|
|
|
}
|
2014-01-27 12:33:11 +08:00
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
|
|
|
|
int CPUTopSavedRegOff) {
|
2014-08-13 18:07:34 +08:00
|
|
|
GPRInfoSet = true;
|
|
|
|
GPRBitMask = CPUBitmask;
|
|
|
|
GPROffset = CPUTopSavedRegOff;
|
2014-01-27 12:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
|
|
|
|
int FPUTopSavedRegOff) {
|
2014-08-13 18:07:34 +08:00
|
|
|
FPRInfoSet = true;
|
|
|
|
FPRBitMask = FPUBitmask;
|
|
|
|
FPROffset = FPUTopSavedRegOff;
|
2014-01-27 12:33:11 +08:00
|
|
|
}
|
2014-03-04 17:54:09 +08:00
|
|
|
|
2014-10-01 22:53:19 +08:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveCpLoad(unsigned RegNo) {
|
2014-04-30 19:28:42 +08:00
|
|
|
// .cpload $reg
|
|
|
|
// This directive expands to:
|
|
|
|
// lui $gp, %hi(_gp_disp)
|
|
|
|
// addui $gp, $gp, %lo(_gp_disp)
|
|
|
|
// addu $gp, $gp, $reg
|
|
|
|
// when support for position independent code is enabled.
|
2015-01-27 01:33:46 +08:00
|
|
|
if (!Pic || (getABI().IsN32() || getABI().IsN64()))
|
2014-04-30 19:28:42 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// There's a GNU extension controlled by -mno-shared that allows
|
|
|
|
// locally-binding symbols to be accessed using absolute addresses.
|
|
|
|
// This is currently not supported. When supported -mno-shared makes
|
|
|
|
// .cpload expand to:
|
|
|
|
// lui $gp, %hi(__gnu_local_gp)
|
|
|
|
// addiu $gp, $gp, %lo(__gnu_local_gp)
|
|
|
|
|
|
|
|
StringRef SymName("_gp_disp");
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
MCSymbol *GP_Disp = MCA.getContext().GetOrCreateSymbol(SymName);
|
|
|
|
MCA.getOrCreateSymbolData(*GP_Disp);
|
|
|
|
|
|
|
|
MCInst TmpInst;
|
|
|
|
TmpInst.setOpcode(Mips::LUi);
|
|
|
|
TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
const MCSymbolRefExpr *HiSym = MCSymbolRefExpr::Create(
|
|
|
|
"_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_HI, MCA.getContext());
|
|
|
|
TmpInst.addOperand(MCOperand::CreateExpr(HiSym));
|
|
|
|
getStreamer().EmitInstruction(TmpInst, STI);
|
|
|
|
|
|
|
|
TmpInst.clear();
|
|
|
|
|
|
|
|
TmpInst.setOpcode(Mips::ADDiu);
|
|
|
|
TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
const MCSymbolRefExpr *LoSym = MCSymbolRefExpr::Create(
|
|
|
|
"_gp_disp", MCSymbolRefExpr::VK_Mips_ABS_LO, MCA.getContext());
|
|
|
|
TmpInst.addOperand(MCOperand::CreateExpr(LoSym));
|
|
|
|
getStreamer().EmitInstruction(TmpInst, STI);
|
|
|
|
|
|
|
|
TmpInst.clear();
|
|
|
|
|
|
|
|
TmpInst.setOpcode(Mips::ADDu);
|
|
|
|
TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
TmpInst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
TmpInst.addOperand(MCOperand::CreateReg(RegNo));
|
|
|
|
getStreamer().EmitInstruction(TmpInst, STI);
|
2014-07-08 16:59:22 +08:00
|
|
|
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-04-30 19:28:42 +08:00
|
|
|
}
|
2014-05-01 18:24:46 +08:00
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
|
|
|
|
int RegOrOffset,
|
|
|
|
const MCSymbol &Sym,
|
|
|
|
bool IsReg) {
|
|
|
|
// Only N32 and N64 emit anything for .cpsetup iff PIC is set.
|
2015-01-27 01:33:46 +08:00
|
|
|
if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
|
2014-05-01 18:24:46 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
MCInst Inst;
|
|
|
|
|
|
|
|
// Either store the old $gp in a register or on the stack
|
|
|
|
if (IsReg) {
|
|
|
|
// move $save, $gpreg
|
|
|
|
Inst.setOpcode(Mips::DADDu);
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(RegOrOffset));
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::ZERO));
|
|
|
|
} else {
|
|
|
|
// sd $gpreg, offset($sp)
|
|
|
|
Inst.setOpcode(Mips::SD);
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::SP));
|
|
|
|
Inst.addOperand(MCOperand::CreateImm(RegOrOffset));
|
|
|
|
}
|
|
|
|
getStreamer().EmitInstruction(Inst, STI);
|
|
|
|
Inst.clear();
|
|
|
|
|
|
|
|
const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
|
2015-02-18 21:46:53 +08:00
|
|
|
&Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
|
2014-05-01 18:24:46 +08:00
|
|
|
const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
|
2015-02-18 21:46:53 +08:00
|
|
|
&Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
|
|
|
|
|
2014-05-01 18:24:46 +08:00
|
|
|
// lui $gp, %hi(%neg(%gp_rel(funcSym)))
|
|
|
|
Inst.setOpcode(Mips::LUi);
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateExpr(HiExpr));
|
|
|
|
getStreamer().EmitInstruction(Inst, STI);
|
|
|
|
Inst.clear();
|
|
|
|
|
|
|
|
// addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
|
|
|
|
Inst.setOpcode(Mips::ADDiu);
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateExpr(LoExpr));
|
|
|
|
getStreamer().EmitInstruction(Inst, STI);
|
|
|
|
Inst.clear();
|
|
|
|
|
|
|
|
// daddu $gp, $gp, $funcreg
|
|
|
|
Inst.setOpcode(Mips::DADDu);
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
|
|
|
|
Inst.addOperand(MCOperand::CreateReg(RegNo));
|
|
|
|
getStreamer().EmitInstruction(Inst, STI);
|
2014-07-08 16:59:22 +08:00
|
|
|
|
2014-08-14 17:18:14 +08:00
|
|
|
forbidModuleDirective();
|
2014-07-08 16:59:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitMipsAbiFlags() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
MCContext &Context = MCA.getContext();
|
|
|
|
MCStreamer &OS = getStreamer();
|
2015-01-30 01:33:21 +08:00
|
|
|
const MCSectionELF *Sec = Context.getELFSection(
|
|
|
|
".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
|
2014-07-08 16:59:22 +08:00
|
|
|
MCSectionData &ABIShndxSD = MCA.getOrCreateSectionData(*Sec);
|
|
|
|
ABIShndxSD.setAlignment(8);
|
|
|
|
OS.SwitchSection(Sec);
|
|
|
|
|
2014-07-08 18:11:38 +08:00
|
|
|
OS << ABIFlagsSection;
|
2014-05-01 18:24:46 +08:00
|
|
|
}
|
2014-07-10 21:38:23 +08:00
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveModuleOddSPReg(bool Enabled,
|
|
|
|
bool IsO32ABI) {
|
|
|
|
MipsTargetStreamer::emitDirectiveModuleOddSPReg(Enabled, IsO32ABI);
|
|
|
|
|
|
|
|
ABIFlagsSection.OddSPReg = Enabled;
|
|
|
|
}
|