mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 09:59:22 +08:00
GT-2909 AVR8 ELF import and pcode test improvements
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
/* ###
|
||||
* 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;
|
||||
|
||||
public class AVR8_ElfRelocationConstants {
|
||||
|
||||
public static final int R_AVR_NONE = 0;
|
||||
public static final int R_AVR_32 = 1;
|
||||
public static final int R_AVR_7_PCREL = 2;
|
||||
public static final int R_AVR_13_PCREL = 3;
|
||||
public static final int R_AVR_16 = 4;
|
||||
public static final int R_AVR_16_PM = 5;
|
||||
public static final int R_AVR_LO8_LDI = 6;
|
||||
public static final int R_AVR_HI8_LDI = 7;
|
||||
public static final int R_AVR_HH8_LDI = 8;
|
||||
public static final int R_AVR_LO8_LDI_NEG = 9;
|
||||
public static final int R_AVR_HI8_LDI_NEG = 10;
|
||||
public static final int R_AVR_HH8_LDI_NEG = 11;
|
||||
public static final int R_AVR_LO8_LDI_PM = 12;
|
||||
public static final int R_AVR_HI8_LDI_PM = 13;
|
||||
public static final int R_AVR_HH8_LDI_PM = 14;
|
||||
public static final int R_AVR_LO8_LDI_PM_NEG = 15;
|
||||
public static final int R_AVR_HI8_LDI_PM_NEG = 16;
|
||||
public static final int R_AVR_HH8_LDI_PM_NEG = 17;
|
||||
public static final int R_AVR_CALL = 18;
|
||||
public static final int R_AVR_LDI = 19;
|
||||
public static final int R_AVR_6 = 20;
|
||||
public static final int R_AVR_6_ADIW = 21;
|
||||
public static final int R_AVR_MS8_LDI = 22;
|
||||
public static final int R_AVR_MS8_LDI_NEG = 23;
|
||||
public static final int R_AVR_LO8_LDI_GS = 24;
|
||||
public static final int R_AVR_HI8_LDI_GS = 25;
|
||||
public static final int R_AVR_8 = 26;
|
||||
public static final int R_AVR_8_LO8 = 27;
|
||||
public static final int R_AVR_8_HI8 = 28;
|
||||
public static final int R_AVR_8_HLO8 = 29;
|
||||
public static final int R_AVR_DIFF8 = 30;
|
||||
public static final int R_AVR_DIFF16 = 31;
|
||||
public static final int R_AVR_DIFF32 = 32;
|
||||
public static final int R_AVR_LDS_STS_16 = 33;
|
||||
public static final int R_AVR_PORT6 = 34;
|
||||
public static final int R_AVR_PORT5 = 35;
|
||||
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/* ###
|
||||
* 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.extend;
|
||||
|
||||
import ghidra.app.util.bin.format.elf.*;
|
||||
import ghidra.program.model.address.AddressSpace;
|
||||
import ghidra.program.model.lang.Language;
|
||||
|
||||
public class AVR8_ElfExtension extends ElfExtension {
|
||||
|
||||
// Processor specific flag mask
|
||||
public static final int EF_AVR_MACH = 0x7F;
|
||||
|
||||
// bit #7 indicates elf file uses local symbols for relocations
|
||||
public static final int EF_AVR_LINKRELAX_PREPARED = 0x80;
|
||||
|
||||
public static final int E_AVR_MACH_AVR1 = 1;
|
||||
public static final int E_AVR_MACH_AVR2 = 2;
|
||||
public static final int E_AVR_MACH_AVR25 = 25;
|
||||
public static final int E_AVR_MACH_AVR3 = 3;
|
||||
public static final int E_AVR_MACH_AVR31 = 31;
|
||||
public static final int E_AVR_MACH_AVR35 = 35;
|
||||
public static final int E_AVR_MACH_AVR4 = 4;
|
||||
public static final int E_AVR_MACH_AVR5 = 5;
|
||||
public static final int E_AVR_MACH_AVR51 = 51;
|
||||
public static final int E_AVR_MACH_AVR6 = 6;
|
||||
public static final int E_AVR_MACH_XMEGA1 = 101;
|
||||
public static final int E_AVR_MACH_XMEGA2 = 102;
|
||||
public static final int E_AVR_MACH_XMEGA3 = 103;
|
||||
public static final int E_AVR_MACH_XMEGA4 = 104;
|
||||
public static final int E_AVR_MACH_XMEGA5 = 105;
|
||||
public static final int E_AVR_MACH_XMEGA6 = 106;
|
||||
public static final int E_AVR_MACH_XMEGA7 = 107;
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ElfHeader elf) {
|
||||
if (elf.e_machine() != ElfConstants.EM_AVR) {
|
||||
return false;
|
||||
}
|
||||
// TODO: limit to specific architectures?
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ElfLoadHelper elfLoadHelper) {
|
||||
Language language = elfLoadHelper.getProgram().getLanguage();
|
||||
return canHandle(elfLoadHelper.getElfHeader()) &&
|
||||
"AVR8".equals(language.getProcessor().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataTypeSuffix() {
|
||||
return "_AVR";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAdjustedMemoryOffset(long elfOffset, AddressSpace space) {
|
||||
if ("code".equals(space.getName())) {
|
||||
elfOffset >>= 1; // code space modeled with wordsize=2 which differs from ELF model
|
||||
}
|
||||
return elfOffset;
|
||||
}
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/* ###
|
||||
* 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.test.processors;
|
||||
|
||||
import ghidra.framework.options.Options;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.test.processors.support.EmulatorTestRunner;
|
||||
import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;
|
||||
import junit.framework.Test;
|
||||
|
||||
public class AVR8_xmega_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
|
||||
|
||||
private static final String LANGUAGE_ID = "avr8:LE:24:xmega";
|
||||
private static final String COMPILER_SPEC_ID = "gcc";
|
||||
|
||||
private static final String[] REG_DUMP_SET = new String[] {};
|
||||
|
||||
public AVR8_xmega_GCC_O0_EmulatorTest(String name) throws Exception {
|
||||
super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getProcessorDesignator() {
|
||||
return "AVR8_xmega_GCC_O0";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeState(EmulatorTestRunner testRunner, Program program)
|
||||
throws Exception {
|
||||
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
|
||||
testRunner.setRegister("SP", 0x0);
|
||||
testRunner.setRegister("R1", 0x0);
|
||||
testRunner.setRegister("Y", 0x0);
|
||||
testRunner.setRegister("W", 0x0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAnalysisOptions(Options analysisOptions) {
|
||||
super.setAnalysisOptions(analysisOptions);
|
||||
analysisOptions.setBoolean("Reference", false); // too many bad disassemblies
|
||||
analysisOptions.setBoolean("Data Reference", false);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(
|
||||
AVR8_xmega_GCC_O0_EmulatorTest.class);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/* ###
|
||||
* 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.test.processors;
|
||||
|
||||
import ghidra.framework.options.Options;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.test.processors.support.EmulatorTestRunner;
|
||||
import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;
|
||||
import junit.framework.Test;
|
||||
|
||||
public class AVR8_xmega_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
|
||||
|
||||
private static final String LANGUAGE_ID = "avr8:LE:24:xmega";
|
||||
private static final String COMPILER_SPEC_ID = "gcc";
|
||||
|
||||
private static final String[] REG_DUMP_SET = new String[] {};
|
||||
|
||||
public AVR8_xmega_GCC_O3_EmulatorTest(String name) throws Exception {
|
||||
super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getProcessorDesignator() {
|
||||
return "AVR8_xmega_GCC_O3";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeState(EmulatorTestRunner testRunner, Program program)
|
||||
throws Exception {
|
||||
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
|
||||
testRunner.setRegister("SP", 0x0);
|
||||
testRunner.setRegister("R1", 0x0);
|
||||
testRunner.setRegister("Y", 0x0);
|
||||
testRunner.setRegister("W", 0x0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAnalysisOptions(Options analysisOptions) {
|
||||
super.setAnalysisOptions(analysisOptions);
|
||||
analysisOptions.setBoolean("Reference", false); // too many bad disassemblies
|
||||
analysisOptions.setBoolean("Data Reference", false);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(
|
||||
AVR8_xmega_GCC_O3_EmulatorTest.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user