Candidate release of source code.

This commit is contained in:
Dan 2019-03-26 13:45:32 -04:00
parent db81e6b3b0
commit 79d8f164f8
12449 changed files with 2800756 additions and 16 deletions

View file

@ -0,0 +1,206 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.util.bin.format.elf;
public class AVR32_ElfRelocationConstants {
/* Atmel AVR32 relocations. */
// NONE (possibly a placeholder for relocations that are moved)
// <align:0 bitpos:0 bitsize:0 complain:dont>
public static final int R_AVR32_NONE = 0;
/* Data Relocations */
// DATA: ((S + A) & 0xffffffff) (Normal Data)
// <align:0 bitpos:0 bitsize:32 complain:dont>
public static final int R_AVR32_32 = 1;
// DATA: ((S + A) & 0x0000ffff) (Normal Data)
// <align:0 bitpos:0 bitsize:16 complain:bitfield>
public static final int R_AVR32_16 = 2;
// DATA: ((S + A) & 0x000000ff)(Normal Data)
// <align:0 bitpos:0 bitsize:8 complain:bitfield>
public static final int R_AVR32_8 = 3;
// DATA: ((S + A - P) & 0xffffffff) (PC-relative)
// <align:0 bitpos:0 bitsize:32 complain:signed>
public static final int R_AVR32_32_PCREL = 4;
// DATA: ((S + A - P) & 0x0000ffff) (PC-relative)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_16_PCREL = 5;
// DATA: ((S + A - P) & 0x000000ff) (PC-relative)
// <align:0 bitpos:0 bitsize:8 complain:signed>
public static final int R_AVR32_8_PCREL = 6;
// Difference between two labels: L2 - L1. The value of L1 is encoded as S +
// A,
// while the initial difference after assembly is
// inserted into the object file by the assembler.
// DATA: (S & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:dont>
public static final int R_AVR32_DIFF32 = 7;
// DATA: (S & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_DIFF16 = 8;
// DATA: (S & 0x000000ff)
// <align:0 bitpos:0 bitsize:8 complain:signed>
public static final int R_AVR32_DIFF8 = 9;
// Reference to a symbol through the Global Offset Table (GOT). The linker
// will allocate an entry for symbol in the GOT and insert the offset
// of this entry as the relocation value. A = 0
// DATA: (G & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:signed>
public static final int R_AVR32_GOT32 = 10;
// DATA: (G & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_GOT16 = 11;
// DATA: (G & 0x000000ff)
// <align:0 bitpos:0 bitsize:8 complain:signed>
public static final int R_AVR32_GOT8 = 12;
/* Normal Code Relocations */
// Normal (non-pc-relative) code relocations. Alignment and signedness
// is indicated by the suffixes. S means signed, U means unsigned.
// W means word-aligned, H means halfword-aligned, neither means
// byte-aligned (no alignment.)
// NORMAL CODE: ((S + A) & 0x1e10ffff)
// <align:0 bitpos:0 bitsize:21 complain:signed>
public static final int R_AVR32_21S = 13;
// NORMAL CODE: ((S + A) & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:unsigned>
public static final int R_AVR32_16U = 14;
// NORMAL CODE: ((S + A) & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_16S = 15;
// NORMAL CODE: (((S + A)) << 4) & 0x00000ff0)
// <align:0 bitpos:4 bitsize:8 complain:signed>
public static final int R_AVR32_8S = 16;
// NORMAL CODE: ((S + A) & 0x000000ff)
// <align:0 bitpos:0 bitsize:8 complain:signed>
public static final int R_AVR32_8S_EXT = 17;
/* PC-Relative Code Relocations */
// PC-relative relocations are signed if neither 'U' nor 'S' is
// specified. However, we explicitly tack on a 'B' to indicate no
// alignment, to avoid confusion with data relocs. All of these
// resolve to S + A - P, except the one with 'N' (negated) suffix.
// This particular one resolves to P - S - A.
// PC-REL CODE: (((S + A - P) >> 1) & 0x1e10ffff)
// <align:1 bitpos:0 bitsize:21 complain:signed>
public static final int R_AVR32_22H_PCREL = 18;
// PC-REL CODE: (((S + A - P) >> 2) & 0x0000ffff)
// <align:2 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_18W_PCREL = 19;
// PC-REL CODE: ((S + A - P) & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_16B_PCREL = 20;
// PC-REL CODE: ((P - S - A) & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_16N_PCREL = 21;
// PC-REL CODE: (((S + A - P) >>> 2) & 0x0000f0ff)
// <align:2 bitpos:0 bitsize:12 complain:unsigned>
public static final int R_AVR32_14UW_PCREL = 22;
// PC-REL CODE: (((S + A - P) >> 1) << 4)
// Must then: tmp1 = (newValue & 0x00000ff3);
// Must then: tmp2 = ((newValue & 0x00003000) >> 12); (to match opcode disp)
// Must then: tmp3 = ((tmp1 << 16) | (tmp2 << 16))
// Must then: (oldValue | tmp3) & 0xffffffff)
// <align:1 bitpos:4 bitsize:10 complain:signed>
public static final int R_AVR32_11H_PCREL = 23;
// PC-REL CODE: (((S + A - P) >>> 2) & 0x000000ff)
// <align:2 bitpos:0 bitsize:8 complain:unsigned>
public static final int R_AVR32_10UW_PCREL = 24;
// PC-REL CODE: ((((S + A - P) >> 1) << 4) & 0x00000ff0)
// Must then: (oldValue | newValue << 16) & 0xffffffff)
// <align:1 bitpos:4 bitsize:8 complain:signed>
public static final int R_AVR32_9H_PCREL = 25;
// PC-REL CODE: ((((S + A) << 4) - P) >>> 2) & 0x000007f0)
// <align:2 bitpos:4 bitsize:7 complain:unsigned>
public static final int R_AVR32_9UW_PCREL = 26;
/* Special Code Relocations */
// Special CODE: (((S + A) >> 16) & 0x0000ffff)
// <align:16 bitpos:0 bitsize:16 complain:dont>
public static final int R_AVR32_HI16 = 27;
// Special CODE: ((S + A) & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:dont>
public static final int R_AVR32_LO16 = 28;
/* PIC Relocations */
// Subtract the link-time address of the GOT from (S + A) and
// insert the result.
// PIC: (((S + A) - GOT) & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:dont>
public static final int R_AVR32_GOTPC = 29;
// Reference to a symbol through the GOT. The linker will
// allocate an entry for symbol in the GOT and insert
// the offset of this entry as the relocation value.
// Addend(A) must be zero. As usual, 'S' means signed, 'W' means
// word-aligned, etc.
// PIC: ((G >> 2) & 0x1e10ffff)
// <align:2 bitpos:0 bitsize:21 complain:signed> (Call instructions)
public static final int R_AVR32_GOTCALL = 30;
// PIC: ((G >> 2) & 0x1e10ffff)
// <align:2 bitpos:0 bitsize:21 complain:signed> (lda.w instructions)
public static final int R_AVR32_LDA_GOT = 31;
// PIC: (G & 0x1e10ffff)
// <align:0 bitpos:0 bitsize:21 complain:signed>
public static final int R_AVR32_GOT21S = 32;
// PIC: ((G >> 2) & 0x0000ffff)
// <align:2 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_GOT18SW = 33;
// PIC: (G & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_GOT16S = 34;
// PIC: (((G) << 4) >> 2) & 0x000001f0)
// <align:2 bitpos:4 bitsize:5 complain:unsigned>
public static final int R_AVR32_GOT7UW = 35;
/* Constant Pool Relocations */
// 32-bit constant pool entry.
// CONST POOL: ((S + A) & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:dont>
public static final int R_AVR32_32_CPENT = 36;
// Constant pool references. Some of these relocations are signed,
// others are unsigned. Constant pool always comes after
// the code that references it.
// CONST POOL: (((S + A - P) >> 2) & 0x0000ffff)
// Must then: ((oldValue | newValue) & 0xffffffff)
// <align:2 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_CPCALL = 37;
// CONST POOL: ((S + A - P) & 0x0000ffff)
// <align:0 bitpos:0 bitsize:16 complain:signed>
public static final int R_AVR32_16_CP = 38;
// CONST POOL: ((((S + A - P) >>> 2) << 4) & 0x000007f0)
// Must then: ((oldValue | newValue << 16) & 0xffffffff)
// <align:2 bitpos:4 bitsize:7 complain:unsigned>
public static final int R_AVR32_9W_CP = 39;
/* Dynamic Relocations */
// Dynamic: ((B + A) & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:signed>
public static final int R_AVR32_RELATIVE = 40;
// Dynamic: ((S + A) & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:dont>
public static final int R_AVR32_GLOB_DAT = 41;
// Dynamic: ((S + A) & 0xffffffff)
// <align:0 bitpos:0 bitsize:32 complain:dont>
public static final int R_AVR32_JMP_SLOT = 42;
/* Linkrelax Information */
// Symbol(S) must be the absolute symbol. The Addend(A) specifies
// the alignment order, e.g. if A is 2, the linker must add
// padding so that the next address is aligned to a 4-byte
// boundary.
// Linkrelax: (P << A)
// <align:0 bitpos:0 bitsize:0 complain:unsigned>
public static final int R_AVR32_ALIGN = 43;
public static final int R_AVR32_NUM = 44;
/* Total Size in Bytes of the Global Offset Table */
public static final int DT_AVR32_GOTSZ = 0x70000001;
/* CPU-Specific flags for the ELF header e_flags field */
public static final int EF_AVR32_LINKRELAX = 0x01;
public static final int EF_AVR32_PIC = 0x02;
}

View file

@ -0,0 +1,337 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.util.bin.format.elf.relocation;
import ghidra.app.util.bin.StructConverter;
import ghidra.app.util.bin.format.elf.*;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.exception.NotFoundException;
import ghidra.util.task.TaskMonitor;
public class AVR32_ElfRelocationHandler extends ElfRelocationHandler {
@Override
public boolean canRelocate(ElfHeader elf) {
return elf.e_machine() == ElfConstants.EM_AVR32;
}
@Override
public void relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation,
Address relocationAddress) throws MemoryAccessException, NotFoundException {
Program program = elfRelocationContext.getProgram();
Memory memory = program.getMemory();
AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
int type = relocation.getType();
int symbolIndex = relocation.getSymbolIndex();
long addend = relocation.getAddend(); // will be 0 for REL case
ElfHeader elf = elfRelocationContext.getElfHeader();
if ((symbolIndex == 0) && (elf.e_machine() == ElfConstants.EM_AVR32)) {
//System.out.println("ZERO_SYMBOL_TYPE = " + type + ", Offset = " + offset + ", Addend = " + addend);
}
else if (symbolIndex == 0) {//TODO
return;
}
long offset = (int) relocationAddress.getOffset();
ElfSymbol sym = elfRelocationContext.getSymbol(symbolIndex);
long symbolValue = elfRelocationContext.getSymbolValue(sym);
int oldValue = memory.getInt(relocationAddress);
if (elf.e_machine() == ElfConstants.EM_AVR32) {
int newValueShiftToAligntoUpper = 0;
switch (type) {
case AVR32_ElfRelocationConstants.R_AVR32_NONE:
break;
case AVR32_ElfRelocationConstants.R_AVR32_32:
int newValue = (((int) symbolValue + (int) addend) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_DIFF32:
newValue = (((int) symbolValue + (int) addend + oldValue) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_22H_PCREL://(BR{cond4})
newValue = (int) ((symbolValue + (int) addend - offset) >> 1);
int nVpart1 = (newValue & 0x0000ffff);
int nVpart2 = (newValue & 0x00010000);
int nVpart3 = (newValue & 0x001e0000);
int newValueParts =
(((nVpart3 << 8) | (nVpart2 << 4) | (nVpart1)) & 0x1e10ffff);
int newValueSet = (oldValue | newValueParts);
memory.setInt(relocationAddress, newValueSet);
break;
case AVR32_ElfRelocationConstants.R_AVR32_11H_PCREL: //WORKING! (RJMP)
newValue = (int) (((symbolValue + (int) addend - offset) >> 1) << 4);
int tempNewValHold = (newValue & 0x00000ff3);
int tempDispHold = ((newValue & 0x00003000) >> 12);
newValueShiftToAligntoUpper = ((tempNewValHold << 16) | (tempDispHold << 16));
newValue = ((oldValue | newValueShiftToAligntoUpper) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_9H_PCREL://WORKING! (BR{cond3})
newValue =
(int) ((((symbolValue + (int) addend - offset) >> 1) << 4) & 0x00000ff0);
newValueShiftToAligntoUpper = (newValue << 16);
newValue = ((oldValue | newValueShiftToAligntoUpper) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_32_CPENT: //WORKING! (POINTER_SYMBOL_PLACEMENT)
newValue = (((int) symbolValue + (int) addend) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
Address currNewAddress = space.getAddress(newValue);
if (!memory.contains(currNewAddress)) {
int currElfSymbolInfoBind = sym.getBind();
int currElfSymbolInfoType = sym.getType();
if ((currElfSymbolInfoBind == ElfSymbol.STB_GLOBAL) &&
((currElfSymbolInfoType == ElfSymbol.STT_OBJECT) ||
(currElfSymbolInfoType == ElfSymbol.STT_NOTYPE))) {
String currElfSymbolName = sym.getNameAsString();
long currElfSymbolSize = sym.getSize();
if (currElfSymbolSize == 0) {
currElfSymbolSize = 2;
}
StringBuffer newSectionNameBuff = new StringBuffer();
newSectionNameBuff.append("cpool.");
newSectionNameBuff.append(currElfSymbolName);
StringBuffer newSectionTypeBuff = new StringBuffer();
newSectionTypeBuff.append("Constant Pool ");
boolean isReadable = true;
boolean isWritable = true;
boolean isExecutable = true;
if (currElfSymbolInfoType == ElfSymbol.STT_OBJECT) {
isReadable = true;
isWritable = true;
isExecutable = false;
newSectionTypeBuff.append("Global Variable Object");
}
else {
isReadable = true;
isWritable = false;
isExecutable = true;
newSectionTypeBuff.append("Global External Function");
}
ElfLoadHelper loadHelper = elfRelocationContext.getLoadHelper();
try {
loadHelper.getMemoryBlockUtil().createInitializedBlock(
newSectionNameBuff.toString(), currNewAddress, null,
currElfSymbolSize, newSectionTypeBuff.toString(), null,
isReadable, // Readable
isWritable, // Not Writable
isExecutable, // Executable
TaskMonitor.DUMMY);
}
catch (AddressOverflowException e) {
loadHelper.log(e.getMessage());
}
}
}
try {
Listing listing = program.getListing();
listing.createData(relocationAddress, StructConverter.POINTER,
relocationAddress.getPointerSize());
}
catch (CodeUnitInsertionException cuie) {
System.out.println("Attempting to create Pointer Data: " + cuie);
}
break;
case AVR32_ElfRelocationConstants.R_AVR32_CPCALL: //WORKING! (MCALL)
int checkForPC = (oldValue & 0x000f0000);
if (checkForPC == 0xf0000) {
newValue =
(int) (((symbolValue + (int) addend - (offset & 0xfffffffc)) >> 2) &
0x0000ffff);
}
else {
newValue =
(int) (((symbolValue + (int) addend - offset) >> 2) & 0x0000ffff);
}
int newValueSet_CPCALL = ((oldValue | newValue) & 0xffffffff);
memory.setInt(relocationAddress, newValueSet_CPCALL);
break;
case AVR32_ElfRelocationConstants.R_AVR32_9W_CP: //WORKING! (LDDPC)
newValue =
(int) ((((symbolValue + (int) addend - (offset & 0xfffffffc)) >>> 2) << 4) &
0x000007f0);
newValueShiftToAligntoUpper = (newValue << 16);
newValue = ((oldValue | newValueShiftToAligntoUpper) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_ALIGN:
//System.out.print("-> type = " + type + ", symbolValue = " + symbolValue + ", addend = " + addend + ", offset = " + offset + " - ");
/*if((addend == 2) && (oldValueLong == 0)){
try{
Listing listing = prog.getListing();
listing.createData(relocationAddress, StructConverter.WORD, (int)addend);
}catch(CodeUnitInsertionException cuie){
System.out.println("Attempting to create Pointer Data: " + cuie);
}
System.out.println(" HANDLED AVR relocation: R_AVR32_ALIGN at "+relocationAddress + ", New = " + newValue);
}*/
//System.out.println(" HANDLED AVR relocation: R_AVR32_ALIGN at "+relocationAddress + ", OldValue = " + Integer.toHexString(oldValue));
break;
//TODO: THE FOLLOWING:
/*case AVR32_ElfRelocationConstants.R_AVR32_16_CP:
//System.out.print("-> type = " + type + ", symbolValue = " + symbolValue + ", addend = " + addend + ", offset = " + offset + " - ");
//newValue = (int)((symbolValue + (int)addend - offset)) & 0x0000ffff;
//memory.setInt(relocationAddress, newValue);
//System.out.println("? HANDLED AVR relocation: R_AVR32_16_CP at "+relocationAddress + ", New = " + Integer.toHexString(newValue));
break;*/
/*case AVR32_ElfRelocationConstants.R_AVR32_RELATIVE:
newValue = (((int)elf.getImageBase() + (int)addend) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_RELATIVE at "+relocationAddress + ", New = " + newValue);
break;
*/
/*case AVR32_ElfRelocationConstants.R_AVR32_16:
newValue = ((symbolValue + (int)addend) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_16 at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_8:
newValue = ((symbolValue + (int)addend) & 0x000000ff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_8 at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_32_PCREL:
newValue = (int)((symbolValue + (int)addend - offset) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_32_PCREL at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_16_PCREL:
newValue = (int)((symbolValue + (int)addend - offset) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_16_PCREL at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_8_PCREL:
newValue = (int)((symbolValue + (int)addend - offset) & 0x000000ff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_8_PCREL at "+relocationAddress + ", New = " + newValue);
break;*/
/*case AVR32_ElfRelocationConstants.R_AVR32_DIFF16:
newValue = ((symbolValue) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_DIFF8 at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_DIFF8:
newValue = ((symbolValue) & 0x000000ff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_DIFF8 at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_21S:
newValue = ((symbolValue + (int)addend) & 0x1e10ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_21S at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_16U: //Use long to accomodate the Unsignedness...
long newValueLong = ((symbolValue + addend) & 0x0000ffff);
memory.setLong(relocationAddress, newValueLong);
System.out.println(" HANDLED AVR relocation: R_AVR32_16U at "+relocationAddress + ", NewLong = " + newValueLong);
break;
case AVR32_ElfRelocationConstants.R_AVR32_16S:
newValue = ((symbolValue + (int)addend) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_16S at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_8S:
newValue = (((symbolValue + (int)addend) << 4) & 0x00000ff0);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_8S at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_8S_EXT:
newValue = ((symbolValue + (int)addend) & 0x000000ff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_8S_EXT at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_18W_PCREL:
newValue = (int)(((symbolValue + (int)addend - offset) >> 2) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_18W_PCREL at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_16B_PCREL:
newValue = (int)((symbolValue + (int)addend - offset) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_16B_PCREL at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_16N_PCREL:
newValue = (int)((offset - symbolValue - (int)addend) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_16N_PCREL at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_14UW_PCREL:
newValue = (int)(((symbolValue + (int)addend - offset) >>> 2) & 0x0000f0ff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_14UW_PCREL at "+relocationAddress + ", New = " + newValue);
break;*/
/*case AVR32_ElfRelocationConstants.R_AVR32_10UW_PCREL:
newValue = (int)(((symbolValue + (int)addend - offset) >>> 2) & 0x000000ff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_10UW_PCREL at "+relocationAddress + ", New = " + newValue);
break;*/
/*case AVR32_ElfRelocationConstants.R_AVR32_9UW_PCREL:
newValue = (int)((((symbolValue + (int)addend - offset) >>> 2) << 4) & 0x000007f0);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_9UW_PCREL at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_HI16:
newValue = (((symbolValue + (int)addend) >> 16) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_HI16 at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_LO16:
newValue = ((symbolValue + (int)addend) & 0x0000ffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_LO16 at "+relocationAddress + ", New = " + newValue);
break;
case AVR32_ElfRelocationConstants.R_AVR32_GOTPC:
ElfSectionHeader dotgot = elf.getGOT();
MemoryBlock got = memory.getBlock(dotgot.getNameAsString());
newValue = ((symbolValue + (int)addend - (int)got.getStart().getOffset()) & 0xffffffff);
memory.setInt(relocationAddress, newValue);
System.out.println(" HANDLED AVR relocation: R_AVR32_GOTPC at "+relocationAddress + ", New = " + newValue);
break;*/
default:
String symbolName = sym.getNameAsString();
markAsUnhandled(program, relocationAddress, type, symbolIndex, symbolName,
elfRelocationContext.getLog());
break;
}
}
}
}