This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
94 lines
2.7 KiB
C++
94 lines
2.7 KiB
C++
//===- MSP430.cpp ---------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The MSP430 is a 16-bit microcontroller RISC architecture. The instruction set
|
|
// has only 27 core instructions orthogonally augmented with a variety
|
|
// of addressing modes for source and destination operands. Entire address space
|
|
// of MSP430 is 64KB (the extended MSP430X architecture is not considered here).
|
|
// A typical MSP430 MCU has several kilobytes of RAM and ROM, plenty
|
|
// of peripherals and is generally optimized for a low power consumption.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "InputFiles.h"
|
|
#include "Symbols.h"
|
|
#include "Target.h"
|
|
#include "lld/Common/ErrorHandler.h"
|
|
#include "llvm/Object/ELF.h"
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::object;
|
|
using namespace llvm::support::endian;
|
|
using namespace llvm::ELF;
|
|
using namespace lld;
|
|
using namespace lld::elf;
|
|
|
|
namespace {
|
|
class MSP430 final : public TargetInfo {
|
|
public:
|
|
MSP430();
|
|
RelExpr getRelExpr(RelType type, const Symbol &s,
|
|
const uint8_t *loc) const override;
|
|
void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;
|
|
};
|
|
} // namespace
|
|
|
|
MSP430::MSP430() {
|
|
// mov.b #0, r3
|
|
trapInstr = {0x43, 0x43, 0x43, 0x43};
|
|
}
|
|
|
|
RelExpr MSP430::getRelExpr(RelType type, const Symbol &s,
|
|
const uint8_t *loc) const {
|
|
switch (type) {
|
|
case R_MSP430_10_PCREL:
|
|
case R_MSP430_16_PCREL:
|
|
case R_MSP430_16_PCREL_BYTE:
|
|
case R_MSP430_2X_PCREL:
|
|
case R_MSP430_RL_PCREL:
|
|
case R_MSP430_SYM_DIFF:
|
|
return R_PC;
|
|
default:
|
|
return R_ABS;
|
|
}
|
|
}
|
|
|
|
void MSP430::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
|
|
switch (type) {
|
|
case R_MSP430_8:
|
|
checkIntUInt(loc, val, 8, type);
|
|
*loc = val;
|
|
break;
|
|
case R_MSP430_16:
|
|
case R_MSP430_16_PCREL:
|
|
case R_MSP430_16_BYTE:
|
|
case R_MSP430_16_PCREL_BYTE:
|
|
checkIntUInt(loc, val, 16, type);
|
|
write16le(loc, val);
|
|
break;
|
|
case R_MSP430_32:
|
|
checkIntUInt(loc, val, 32, type);
|
|
write32le(loc, val);
|
|
break;
|
|
case R_MSP430_10_PCREL: {
|
|
int16_t offset = ((int16_t)val >> 1) - 1;
|
|
checkInt(loc, offset, 10, type);
|
|
write16le(loc, (read16le(loc) & 0xFC00) | (offset & 0x3FF));
|
|
break;
|
|
}
|
|
default:
|
|
error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));
|
|
}
|
|
}
|
|
|
|
TargetInfo *elf::getMSP430TargetInfo() {
|
|
static MSP430 target;
|
|
return ⌖
|
|
}
|