10b57cec5SDimitry Andric //===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file provides MSP430 specific target streamer methods. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #include "MSP430MCTargetDesc.h" 140b57cec5SDimitry Andric #include "llvm/BinaryFormat/ELF.h" 15*81ad6265SDimitry Andric #include "llvm/MC/MCAssembler.h" 160b57cec5SDimitry Andric #include "llvm/MC/MCContext.h" 170b57cec5SDimitry Andric #include "llvm/MC/MCELFStreamer.h" 180b57cec5SDimitry Andric #include "llvm/MC/MCSectionELF.h" 190b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h" 200b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h" 21349cc55cSDimitry Andric #include "llvm/Support/MSP430Attributes.h" 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric using namespace llvm; 24349cc55cSDimitry Andric using namespace llvm::MSP430Attrs; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric namespace llvm { 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric class MSP430TargetELFStreamer : public MCTargetStreamer { 290b57cec5SDimitry Andric public: 300b57cec5SDimitry Andric MCELFStreamer &getStreamer(); 310b57cec5SDimitry Andric MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); 320b57cec5SDimitry Andric }; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric // This part is for ELF object output. 350b57cec5SDimitry Andric MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer &S, 360b57cec5SDimitry Andric const MCSubtargetInfo &STI) 370b57cec5SDimitry Andric : MCTargetStreamer(S) { 380b57cec5SDimitry Andric // Emit build attributes section according to 390b57cec5SDimitry Andric // MSP430 EABI (slaa534.pdf, part 13). 400b57cec5SDimitry Andric MCSection *AttributeSection = getStreamer().getContext().getELFSection( 410b57cec5SDimitry Andric ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0); 42*81ad6265SDimitry Andric Streamer.switchSection(AttributeSection); 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric // Format version. 455ffd83dbSDimitry Andric Streamer.emitInt8(0x41); 460b57cec5SDimitry Andric // Subsection length. 475ffd83dbSDimitry Andric Streamer.emitInt32(22); 480b57cec5SDimitry Andric // Vendor name string, zero-terminated. 495ffd83dbSDimitry Andric Streamer.emitBytes("mspabi"); 505ffd83dbSDimitry Andric Streamer.emitInt8(0); 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric // Attribute vector scope tag. 1 stands for the entire file. 535ffd83dbSDimitry Andric Streamer.emitInt8(1); 540b57cec5SDimitry Andric // Attribute vector length. 555ffd83dbSDimitry Andric Streamer.emitInt32(11); 56349cc55cSDimitry Andric 57349cc55cSDimitry Andric Streamer.emitInt8(TagISA); 58349cc55cSDimitry Andric Streamer.emitInt8(STI.hasFeature(MSP430::FeatureX) ? ISAMSP430X : ISAMSP430); 59349cc55cSDimitry Andric Streamer.emitInt8(TagCodeModel); 60349cc55cSDimitry Andric Streamer.emitInt8(CMSmall); 61349cc55cSDimitry Andric Streamer.emitInt8(TagDataModel); 62349cc55cSDimitry Andric Streamer.emitInt8(DMSmall); 63349cc55cSDimitry Andric // Don't emit TagEnumSize, for full GCC compatibility. 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric MCELFStreamer &MSP430TargetELFStreamer::getStreamer() { 670b57cec5SDimitry Andric return static_cast<MCELFStreamer &>(Streamer); 680b57cec5SDimitry Andric } 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric MCTargetStreamer * 710b57cec5SDimitry Andric createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) { 720b57cec5SDimitry Andric const Triple &TT = STI.getTargetTriple(); 730b57cec5SDimitry Andric if (TT.isOSBinFormatELF()) 740b57cec5SDimitry Andric return new MSP430TargetELFStreamer(S, STI); 750b57cec5SDimitry Andric return nullptr; 760b57cec5SDimitry Andric } 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric } // namespace llvm 79