1 | //===- MipsABIFlagsSection.cpp - Mips ELF ABI Flags Section ---------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "MCTargetDesc/MipsABIFlagsSection.h" |
10 | #include "llvm/ADT/StringRef.h" |
11 | #include "llvm/MC/MCStreamer.h" |
12 | #include "llvm/Support/ErrorHandling.h" |
13 | #include "llvm/Support/MipsABIFlags.h" |
14 | |
15 | using namespace llvm; |
16 | |
17 | uint8_t MipsABIFlagsSection::getFpABIValue() { |
18 | switch (FpABI) { |
19 | case FpABIKind::ANY: |
20 | return Mips::Val_GNU_MIPS_ABI_FP_ANY; |
21 | case FpABIKind::SOFT: |
22 | return Mips::Val_GNU_MIPS_ABI_FP_SOFT; |
23 | case FpABIKind::XX: |
24 | return Mips::Val_GNU_MIPS_ABI_FP_XX; |
25 | case FpABIKind::S32: |
26 | return Mips::Val_GNU_MIPS_ABI_FP_DOUBLE; |
27 | case FpABIKind::S64: |
28 | if (Is32BitABI) |
29 | return OddSPReg ? Mips::Val_GNU_MIPS_ABI_FP_64 |
30 | : Mips::Val_GNU_MIPS_ABI_FP_64A; |
31 | return Mips::Val_GNU_MIPS_ABI_FP_DOUBLE; |
32 | } |
33 | |
34 | llvm_unreachable("unexpected fp abi value" ); |
35 | } |
36 | |
37 | StringRef MipsABIFlagsSection::getFpABIString(FpABIKind Value) { |
38 | switch (Value) { |
39 | case FpABIKind::XX: |
40 | return "xx" ; |
41 | case FpABIKind::S32: |
42 | return "32" ; |
43 | case FpABIKind::S64: |
44 | return "64" ; |
45 | default: |
46 | llvm_unreachable("unsupported fp abi value" ); |
47 | } |
48 | } |
49 | |
50 | uint8_t MipsABIFlagsSection::getCPR1SizeValue() { |
51 | if (FpABI == FpABIKind::XX) |
52 | return (uint8_t)Mips::AFL_REG_32; |
53 | return (uint8_t)CPR1Size; |
54 | } |
55 | |
56 | namespace llvm { |
57 | |
58 | MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection) { |
59 | // Write out a Elf_Internal_ABIFlags_v0 struct |
60 | OS.emitIntValue(Value: ABIFlagsSection.getVersionValue(), Size: 2); // version |
61 | OS.emitIntValue(Value: ABIFlagsSection.getISALevelValue(), Size: 1); // isa_level |
62 | OS.emitIntValue(Value: ABIFlagsSection.getISARevisionValue(), Size: 1); // isa_rev |
63 | OS.emitIntValue(Value: ABIFlagsSection.getGPRSizeValue(), Size: 1); // gpr_size |
64 | OS.emitIntValue(Value: ABIFlagsSection.getCPR1SizeValue(), Size: 1); // cpr1_size |
65 | OS.emitIntValue(Value: ABIFlagsSection.getCPR2SizeValue(), Size: 1); // cpr2_size |
66 | OS.emitIntValue(Value: ABIFlagsSection.getFpABIValue(), Size: 1); // fp_abi |
67 | OS.emitIntValue(Value: ABIFlagsSection.getISAExtensionValue(), Size: 4); // isa_ext |
68 | OS.emitIntValue(Value: ABIFlagsSection.getASESetValue(), Size: 4); // ases |
69 | OS.emitIntValue(Value: ABIFlagsSection.getFlags1Value(), Size: 4); // flags1 |
70 | OS.emitIntValue(Value: ABIFlagsSection.getFlags2Value(), Size: 4); // flags2 |
71 | return OS; |
72 | } |
73 | |
74 | } // end namespace llvm |
75 | |