Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Arch/MSP430.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MSP430.cpp ---------------------------------------------------------===//
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
// 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.
15
//
16
//===----------------------------------------------------------------------===//
17
18
#include "InputFiles.h"
19
#include "Symbols.h"
20
#include "Target.h"
21
#include "lld/Common/ErrorHandler.h"
22
#include "llvm/Object/ELF.h"
23
#include "llvm/Support/Endian.h"
24
25
using namespace llvm;
26
using namespace llvm::object;
27
using namespace llvm::support::endian;
28
using namespace llvm::ELF;
29
using namespace lld;
30
using namespace lld::elf;
31
32
namespace {
33
class MSP430 final : public TargetInfo {
34
public:
35
  MSP430();
36
  RelExpr getRelExpr(RelType type, const Symbol &s,
37
                     const uint8_t *loc) const override;
38
  void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;
39
};
40
} // namespace
41
42
1
MSP430::MSP430() {
43
1
  // mov.b #0, r3
44
1
  trapInstr = {0x43, 0x43, 0x43, 0x43};
45
1
}
46
47
RelExpr MSP430::getRelExpr(RelType type, const Symbol &s,
48
6
                           const uint8_t *loc) const {
49
6
  switch (type) {
50
6
  case R_MSP430_10_PCREL:
51
2
  case R_MSP430_16_PCREL:
52
2
  case R_MSP430_16_PCREL_BYTE:
53
2
  case R_MSP430_2X_PCREL:
54
2
  case R_MSP430_RL_PCREL:
55
2
  case R_MSP430_SYM_DIFF:
56
2
    return R_PC;
57
4
  default:
58
4
    return R_ABS;
59
6
  }
60
6
}
61
62
6
void MSP430::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
63
6
  switch (type) {
64
6
  case R_MSP430_8:
65
1
    checkIntUInt(loc, val, 8, type);
66
1
    *loc = val;
67
1
    break;
68
6
  case R_MSP430_16:
69
3
  case R_MSP430_16_PCREL:
70
3
  case R_MSP430_16_BYTE:
71
3
  case R_MSP430_16_PCREL_BYTE:
72
3
    checkIntUInt(loc, val, 16, type);
73
3
    write16le(loc, val);
74
3
    break;
75
3
  case R_MSP430_32:
76
1
    checkIntUInt(loc, val, 32, type);
77
1
    write32le(loc, val);
78
1
    break;
79
3
  case R_MSP430_10_PCREL: {
80
1
    int16_t offset = ((int16_t)val >> 1) - 1;
81
1
    checkInt(loc, offset, 10, type);
82
1
    write16le(loc, (read16le(loc) & 0xFC00) | (offset & 0x3FF));
83
1
    break;
84
3
  }
85
3
  default:
86
0
    error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));
87
6
  }
88
6
}
89
90
2
TargetInfo *elf::getMSP430TargetInfo() {
91
2
  static MSP430 target;
92
2
  return ⌖
93
2
}