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