AVRFixupKinds.h
4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//===-- AVRFixupKinds.h - AVR Specific Fixup Entries ------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_AVR_FIXUP_KINDS_H
#define LLVM_AVR_FIXUP_KINDS_H
#include "llvm/MC/MCFixup.h"
namespace llvm {
namespace AVR {
/// The set of supported fixups.
///
/// Although most of the current fixup types reflect a unique relocation
/// one can have multiple fixup types for a given relocation and thus need
/// to be uniquely named.
///
/// \note This table *must* be in the same order of
/// MCFixupKindInfo Infos[AVR::NumTargetFixupKinds]
/// in `AVRAsmBackend.cpp`.
enum Fixups {
/// A 32-bit AVR fixup.
fixup_32 = FirstTargetFixupKind,
/// A 7-bit PC-relative fixup for the family of conditional
/// branches which take 7-bit targets (BRNE,BRGT,etc).
fixup_7_pcrel,
/// A 12-bit PC-relative fixup for the family of branches
/// which take 12-bit targets (RJMP,RCALL,etc).
/// \note Although the fixup is labelled as 13 bits, it
/// is actually only encoded in 12. The reason for
/// The nonmenclature is that AVR branch targets are
/// rightshifted by 1, because instructions are always
/// aligned to 2 bytes, so the 0'th bit is always 0.
/// This way there is 13-bits of precision.
fixup_13_pcrel,
/// A 16-bit address.
fixup_16,
/// A 16-bit program memory address.
fixup_16_pm,
/// Replaces the 8-bit immediate with another value.
fixup_ldi,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the lower 8 bits of a 16-bit value (bits 0-7).
fixup_lo8_ldi,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a 16-bit value (bits 8-15).
fixup_hi8_ldi,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a 24-bit value (bits 16-23).
fixup_hh8_ldi,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a 32-bit value (bits 24-31).
fixup_ms8_ldi,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the lower 8 bits of a negated 16-bit value (bits 0-7).
fixup_lo8_ldi_neg,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a negated 16-bit value (bits 8-15).
fixup_hi8_ldi_neg,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a negated negated 24-bit value (bits 16-23).
fixup_hh8_ldi_neg,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a negated negated 32-bit value (bits 24-31).
fixup_ms8_ldi_neg,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the lower 8 bits of a 16-bit program memory address value (bits 0-7).
fixup_lo8_ldi_pm,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a 16-bit program memory address value (bits
/// 8-15).
fixup_hi8_ldi_pm,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a 24-bit program memory address value (bits
/// 16-23).
fixup_hh8_ldi_pm,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the lower 8 bits of a negated 16-bit program memory address value
/// (bits 0-7).
fixup_lo8_ldi_pm_neg,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a negated 16-bit program memory address value
/// (bits 8-15).
fixup_hi8_ldi_pm_neg,
/// Replaces the immediate operand of a 16-bit `Rd, K` instruction
/// with the upper 8 bits of a negated 24-bit program memory address value
/// (bits 16-23).
fixup_hh8_ldi_pm_neg,
/// A 22-bit fixup for the target of a `CALL k` or `JMP k` instruction.
fixup_call,
fixup_6,
/// A symbol+addr fixup for the `LDD <x>+<n>, <r>" family of instructions.
fixup_6_adiw,
fixup_lo8_ldi_gs,
fixup_hi8_ldi_gs,
fixup_8,
fixup_8_lo8,
fixup_8_hi8,
fixup_8_hlo8,
fixup_diff8,
fixup_diff16,
fixup_diff32,
fixup_lds_sts_16,
/// A 6-bit port address.
fixup_port6,
/// A 5-bit port address.
fixup_port5,
// Marker
LastTargetFixupKind,
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind
};
namespace fixups {
/// Adjusts the value of a branch target.
/// All branch targets in AVR are rightshifted by 1 to take advantage
/// of the fact that all instructions are aligned to addresses of size
/// 2, so bit 0 of an address is always 0. This gives us another bit
/// of precision.
/// \param [in,out] val The target to adjust.
template <typename T> inline void adjustBranchTarget(T &val) { val >>= 1; }
} // end of namespace fixups
}
} // end of namespace llvm::AVR
#endif // LLVM_AVR_FIXUP_KINDS_H