2017-06-17 01:32:43 +08:00
|
|
|
//===- AVR.cpp ------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2017-06-17 01:32:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-06-17 01:53:26 +08:00
|
|
|
//
|
|
|
|
// AVR is a Harvard-architecture 8-bit micrcontroller designed for small
|
|
|
|
// baremetal programs. All AVR-family processors have 32 8-bit registers.
|
|
|
|
// The tiniest AVR has 32 byte RAM and 1 KiB program memory, and the largest
|
|
|
|
// one supports up to 2^24 data address space and 2^22 code address space.
|
|
|
|
//
|
|
|
|
// Since it is a baremetal programming, there's usually no loader to load
|
|
|
|
// ELF files on AVRs. You are expected to link your program against address
|
|
|
|
// 0 and pull out a .text section from the result using objcopy, so that you
|
|
|
|
// can write the linked code to on-chip flush memory. You can do that with
|
|
|
|
// the following commands:
|
|
|
|
//
|
|
|
|
// ld.lld -Ttext=0 -o foo foo.o
|
|
|
|
// objcopy -O binary --only-section=.text foo output.bin
|
|
|
|
//
|
|
|
|
// Note that the current AVR support is very preliminary so you can't
|
|
|
|
// link any useful program yet, though.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-06-17 01:32:43 +08:00
|
|
|
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#include "Symbols.h"
|
|
|
|
#include "Target.h"
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
#include "lld/Common/ErrorHandler.h"
|
2017-06-17 01:32:43 +08:00
|
|
|
#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;
|
2019-10-07 16:31:18 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2017-06-17 01:32:43 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
class AVR final : public TargetInfo {
|
|
|
|
public:
|
2018-09-26 16:11:34 +08:00
|
|
|
AVR();
|
2017-11-04 05:21:47 +08:00
|
|
|
RelExpr getRelExpr(RelType type, const Symbol &s,
|
2017-06-17 01:32:43 +08:00
|
|
|
const uint8_t *loc) const override;
|
2020-01-23 13:39:16 +08:00
|
|
|
void relocate(uint8_t *loc, const Relocation &rel,
|
|
|
|
uint64_t val) const override;
|
2017-06-17 01:32:43 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2018-09-26 16:11:34 +08:00
|
|
|
AVR::AVR() { noneRel = R_AVR_NONE; }
|
|
|
|
|
2017-11-04 05:21:47 +08:00
|
|
|
RelExpr AVR::getRelExpr(RelType type, const Symbol &s,
|
2017-10-12 11:14:06 +08:00
|
|
|
const uint8_t *loc) const {
|
|
|
|
return R_ABS;
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
2020-01-23 13:39:16 +08:00
|
|
|
void AVR::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
|
|
|
|
switch (rel.type) {
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_AVR_CALL: {
|
|
|
|
uint16_t hi = val >> 17;
|
|
|
|
uint16_t lo = val >> 1;
|
|
|
|
write16le(loc, read16le(loc) | ((hi >> 1) << 4) | (hi & 1));
|
|
|
|
write16le(loc + 2, lo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2020-01-23 13:39:16 +08:00
|
|
|
error(getErrorLocation(loc) + "unrecognized relocation " +
|
|
|
|
toString(rel.type));
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 16:31:18 +08:00
|
|
|
TargetInfo *getAVRTargetInfo() {
|
2017-06-17 04:15:03 +08:00
|
|
|
static AVR target;
|
|
|
|
return ⌖
|
|
|
|
}
|
2019-10-07 16:31:18 +08:00
|
|
|
|
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|