1 //===- MSP430.cpp ---------------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The MSP430 is a 16-bit microcontroller RISC architecture. The instruction set
11 // has only 27 core instructions orthogonally augmented with a variety
12 // of addressing modes for source and destination operands. Entire address space
13 // of MSP430 is 64KB (the extended MSP430X architecture is not considered here).
14 // A typical MSP430 MCU has several kilobytes of RAM and ROM, plenty
15 // of peripherals and is generally optimized for a low power consumption.
17 //===----------------------------------------------------------------------===//
19 #include "InputFiles.h"
22 #include "lld/Common/ErrorHandler.h"
23 #include "llvm/Object/ELF.h"
24 #include "llvm/Support/Endian.h"
27 using namespace llvm::object;
28 using namespace llvm::support::endian;
29 using namespace llvm::ELF;
31 using namespace lld::elf;
34 class MSP430 final : public TargetInfo {
37 RelExpr getRelExpr(RelType Type, const Symbol &S,
38 const uint8_t *Loc) const override;
39 void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
45 TrapInstr = {0x43, 0x43, 0x43, 0x43};
48 RelExpr MSP430::getRelExpr(RelType Type, const Symbol &S,
49 const uint8_t *Loc) const {
51 case R_MSP430_10_PCREL:
52 case R_MSP430_16_PCREL:
53 case R_MSP430_16_PCREL_BYTE:
54 case R_MSP430_2X_PCREL:
55 case R_MSP430_RL_PCREL:
56 case R_MSP430_SYM_DIFF:
63 void MSP430::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
66 checkIntUInt(Loc, Val, 8, Type);
70 case R_MSP430_16_PCREL:
71 case R_MSP430_16_BYTE:
72 case R_MSP430_16_PCREL_BYTE:
73 checkIntUInt(Loc, Val, 16, Type);
77 checkIntUInt(Loc, Val, 32, Type);
80 case R_MSP430_10_PCREL: {
81 int16_t Offset = ((int16_t)Val >> 1) - 1;
82 checkInt(Loc, Offset, 10, Type);
83 write16le(Loc, (read16le(Loc) & 0xFC00) | (Offset & 0x3FF));
87 error(getErrorLocation(Loc) + "unrecognized reloc " + toString(Type));
91 TargetInfo *elf::getMSP430TargetInfo() {