1 //===- MSP430.cpp ---------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // The MSP430 is a 16-bit microcontroller RISC architecture. The instruction set
10 // has only 27 core instructions orthogonally augmented with a variety
11 // of addressing modes for source and destination operands. Entire address space
12 // of MSP430 is 64KB (the extended MSP430X architecture is not considered here).
13 // A typical MSP430 MCU has several kilobytes of RAM and ROM, plenty
14 // of peripherals and is generally optimized for a low power consumption.
16 //===----------------------------------------------------------------------===//
18 #include "InputFiles.h"
21 #include "lld/Common/ErrorHandler.h"
22 #include "llvm/Object/ELF.h"
23 #include "llvm/Support/Endian.h"
26 using namespace llvm::object;
27 using namespace llvm::support::endian;
28 using namespace llvm::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 relocation " + toString(type));
91 TargetInfo *getMSP430TargetInfo() {