1 //===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===//
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 // This file provides MSP430 specific target streamer methods.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "MSP430MCTargetDesc.h"
14 #include "llvm/BinaryFormat/ELF.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCELFStreamer.h"
17 #include "llvm/MC/MCSectionELF.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCSubtargetInfo.h"
20
21 using namespace llvm;
22
23 namespace llvm {
24
25 class MSP430TargetELFStreamer : public MCTargetStreamer {
26 public:
27 MCELFStreamer &getStreamer();
28 MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
29 };
30
31 // This part is for ELF object output.
MSP430TargetELFStreamer(MCStreamer & S,const MCSubtargetInfo & STI)32 MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer &S,
33 const MCSubtargetInfo &STI)
34 : MCTargetStreamer(S) {
35 MCAssembler &MCA = getStreamer().getAssembler();
36 unsigned EFlags = MCA.getELFHeaderEFlags();
37 MCA.setELFHeaderEFlags(EFlags);
38
39 // Emit build attributes section according to
40 // MSP430 EABI (slaa534.pdf, part 13).
41 MCSection *AttributeSection = getStreamer().getContext().getELFSection(
42 ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0);
43 Streamer.SwitchSection(AttributeSection);
44
45 // Format version.
46 Streamer.emitInt8(0x41);
47 // Subsection length.
48 Streamer.emitInt32(22);
49 // Vendor name string, zero-terminated.
50 Streamer.emitBytes("mspabi");
51 Streamer.emitInt8(0);
52
53 // Attribute vector scope tag. 1 stands for the entire file.
54 Streamer.emitInt8(1);
55 // Attribute vector length.
56 Streamer.emitInt32(11);
57 // OFBA_MSPABI_Tag_ISA(4) = 1, MSP430
58 Streamer.emitInt8(4);
59 Streamer.emitInt8(1);
60 // OFBA_MSPABI_Tag_Code_Model(6) = 1, Small
61 Streamer.emitInt8(6);
62 Streamer.emitInt8(1);
63 // OFBA_MSPABI_Tag_Data_Model(8) = 1, Small
64 Streamer.emitInt8(8);
65 Streamer.emitInt8(1);
66 }
67
getStreamer()68 MCELFStreamer &MSP430TargetELFStreamer::getStreamer() {
69 return static_cast<MCELFStreamer &>(Streamer);
70 }
71
72 MCTargetStreamer *
createMSP430ObjectTargetStreamer(MCStreamer & S,const MCSubtargetInfo & STI)73 createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
74 const Triple &TT = STI.getTargetTriple();
75 if (TT.isOSBinFormatELF())
76 return new MSP430TargetELFStreamer(S, STI);
77 return nullptr;
78 }
79
80 } // namespace llvm
81