1 //===-- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -----*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef MIPSABIFLAGSSECTION_H
11 #define MIPSABIFLAGSSECTION_H
13 #include "llvm/MC/MCStreamer.h"
19 struct MipsABIFlagsSection {
20 // Values for the xxx_size bytes of an ABI flags structure.
22 AFL_REG_NONE = 0x00, // No registers.
23 AFL_REG_32 = 0x01, // 32-bit registers.
24 AFL_REG_64 = 0x02, // 64-bit registers.
25 AFL_REG_128 = 0x03 // 128-bit registers.
28 // Masks for the ases word of an ABI flags structure.
30 AFL_ASE_DSP = 0x00000001, // DSP ASE.
31 AFL_ASE_DSPR2 = 0x00000002, // DSP R2 ASE.
32 AFL_ASE_EVA = 0x00000004, // Enhanced VA Scheme.
33 AFL_ASE_MCU = 0x00000008, // MCU (MicroController) ASE.
34 AFL_ASE_MDMX = 0x00000010, // MDMX ASE.
35 AFL_ASE_MIPS3D = 0x00000020, // MIPS-3D ASE.
36 AFL_ASE_MT = 0x00000040, // MT ASE.
37 AFL_ASE_SMARTMIPS = 0x00000080, // SmartMIPS ASE.
38 AFL_ASE_VIRT = 0x00000100, // VZ ASE.
39 AFL_ASE_MSA = 0x00000200, // MSA ASE.
40 AFL_ASE_MIPS16 = 0x00000400, // MIPS16 ASE.
41 AFL_ASE_MICROMIPS = 0x00000800, // MICROMIPS ASE.
42 AFL_ASE_XPA = 0x00001000 // XPA ASE.
45 // Values for the isa_ext word of an ABI flags structure.
47 AFL_EXT_XLR = 1, // RMI Xlr instruction.
48 AFL_EXT_OCTEON2 = 2, // Cavium Networks Octeon2.
49 AFL_EXT_OCTEONP = 3, // Cavium Networks OcteonP.
50 AFL_EXT_LOONGSON_3A = 4, // Loongson 3A.
51 AFL_EXT_OCTEON = 5, // Cavium Networks Octeon.
52 AFL_EXT_5900 = 6, // MIPS R5900 instruction.
53 AFL_EXT_4650 = 7, // MIPS R4650 instruction.
54 AFL_EXT_4010 = 8, // LSI R4010 instruction.
55 AFL_EXT_4100 = 9, // NEC VR4100 instruction.
56 AFL_EXT_3900 = 10, // Toshiba R3900 instruction.
57 AFL_EXT_10000 = 11, // MIPS R10000 instruction.
58 AFL_EXT_SB1 = 12, // Broadcom SB-1 instruction.
59 AFL_EXT_4111 = 13, // NEC VR4111/VR4181 instruction.
60 AFL_EXT_4120 = 14, // NEC VR4120 instruction.
61 AFL_EXT_5400 = 15, // NEC VR5400 instruction.
62 AFL_EXT_5500 = 16, // NEC VR5500 instruction.
63 AFL_EXT_LOONGSON_2E = 17, // ST Microelectronics Loongson 2E.
64 AFL_EXT_LOONGSON_2F = 18 // ST Microelectronics Loongson 2F.
67 // Values for the fp_abi word of an ABI flags structure.
68 enum Val_GNU_MIPS_ABI {
69 Val_GNU_MIPS_ABI_FP_ANY = 0,
70 Val_GNU_MIPS_ABI_FP_DOUBLE = 1,
71 Val_GNU_MIPS_ABI_FP_XX = 5,
72 Val_GNU_MIPS_ABI_FP_64 = 6
75 // Version of flags structure.
77 // The level of the ISA: 1-5, 32, 64.
79 // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
81 // The size of general purpose registers.
83 // The size of co-processor 1 registers.
85 // The size of co-processor 2 registers.
87 // The floating-point ABI.
88 Val_GNU_MIPS_ABI FpABI;
89 // Processor-specific extension.
90 uint32_t ISAExtensionSet;
95 : Version(0), ISALevel(0), ISARevision(0), GPRSize(AFL_REG_NONE),
96 CPR1Size(AFL_REG_NONE), CPR2Size(AFL_REG_NONE),
97 FpABI(Val_GNU_MIPS_ABI_FP_ANY), ISAExtensionSet(0), ASESet(0) {}
99 uint16_t getVersion() { return (uint16_t)Version; }
100 uint8_t getISALevel() { return (uint8_t)ISALevel; }
101 uint8_t getISARevision() { return (uint8_t)ISARevision; }
102 uint8_t getGPRSize() { return (uint8_t)GPRSize; }
103 uint8_t getCPR1Size() { return (uint8_t)CPR1Size; }
104 uint8_t getCPR2Size() { return (uint8_t)CPR2Size; }
105 uint8_t getFpABI() { return (uint8_t)FpABI; }
106 uint32_t getISAExtensionSet() { return (uint32_t)ISAExtensionSet; }
107 uint32_t getASESet() { return (uint32_t)ASESet; }
108 uint32_t getFlags1() { return 0; }
109 uint32_t getFlags2() { return 0; }
111 StringRef getFpABIString(Val_GNU_MIPS_ABI Value, bool Is32BitAbi);
113 template <class PredicateLibrary>
114 void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
119 else if (P.hasMips64r2())
123 } else if (P.hasMips32()) {
127 else if (P.hasMips32r2())
135 else if (P.hasMips4())
137 else if (P.hasMips3())
139 else if (P.hasMips2())
141 else if (P.hasMips1())
144 llvm_unreachable("Unknown ISA level!");
148 template <class PredicateLibrary>
149 void setGPRSizeFromPredicates(const PredicateLibrary &P) {
150 GPRSize = P.isGP64bit() ? AFL_REG_64 : AFL_REG_32;
153 template <class PredicateLibrary>
154 void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
155 if (P.mipsSEUsesSoftFloat())
156 CPR1Size = AFL_REG_NONE;
158 CPR1Size = AFL_REG_128;
160 CPR1Size = P.isFP64bit() ? AFL_REG_64 : AFL_REG_32;
163 template <class PredicateLibrary>
164 void setASESetFromPredicates(const PredicateLibrary &P) {
167 ASESet |= AFL_ASE_DSP;
169 ASESet |= AFL_ASE_DSPR2;
171 ASESet |= AFL_ASE_MSA;
172 if (P.inMicroMipsMode())
173 ASESet |= AFL_ASE_MICROMIPS;
174 if (P.inMips16Mode())
175 ASESet |= AFL_ASE_MIPS16;
178 template <class PredicateLibrary>
179 void setFpAbiFromPredicates(const PredicateLibrary &P) {
180 FpABI = Val_GNU_MIPS_ABI_FP_ANY;
181 if (P.isABI_N32() || P.isABI_N64())
182 FpABI = Val_GNU_MIPS_ABI_FP_DOUBLE;
183 else if (P.isABI_O32()) {
185 FpABI = Val_GNU_MIPS_ABI_FP_64;
186 else if (P.isABI_FPXX())
187 FpABI = Val_GNU_MIPS_ABI_FP_XX;
189 FpABI = Val_GNU_MIPS_ABI_FP_DOUBLE;
193 template <class PredicateLibrary>
194 void setAllFromPredicates(const PredicateLibrary &P) {
195 setISALevelAndRevisionFromPredicates(P);
196 setGPRSizeFromPredicates(P);
197 setCPR1SizeFromPredicates(P);
198 setASESetFromPredicates(P);
199 setFpAbiFromPredicates(P);
203 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);