deleteSet = new ArrayList<>(); // defered delete to avoid iterator resets
+ for (Symbol s : symbolTable.getSymbols(processorDefinedSafeBlockSet, SymbolType.LABEL,
+ true)) {
+ if (s.getSource() == SourceType.IMPORTED && !goodSymbols.contains(s)) {
+ deleteSet.add(s);
+ }
+ }
+ for (Symbol s : deleteSet) {
+ s.delete();
+ }
+
+ }
+ catch (UnsupportedOperationException e) {
+ // skip
+ }
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/generic/MemoryBlockDefinition.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/generic/MemoryBlockDefinition.java
index f7de363fb5..13b5ee917e 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/generic/MemoryBlockDefinition.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/generic/MemoryBlockDefinition.java
@@ -4,9 +4,9 @@
* 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.
@@ -15,11 +15,15 @@
*/
package ghidra.app.plugin.processors.generic;
+import java.util.List;
+
import ghidra.framework.store.LockException;
+import ghidra.program.database.ProgramDB;
import ghidra.program.database.mem.ByteMappingScheme;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.*;
+import ghidra.util.Msg;
import ghidra.util.XmlProgramUtilities;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.CancelledException;
@@ -36,18 +40,22 @@ import ghidra.xml.XmlElement;
*/
public class MemoryBlockDefinition {
- private String blockName;
- private String addressString;
- private int length;
- private boolean initialized;
- private boolean overlay;
- private String bitMappedAddress;
- private String byteMappedAddress;
- private ByteMappingScheme byteMappingScheme;
- private boolean readPermission = true;
- private boolean writePermission = true;
- private boolean executePermission = false;
- private boolean isVolatile = false;
+ private final String blockName;
+ private final String addressString;
+ private final int length;
+ private final boolean initialized;
+ private final boolean overlay;
+ private final String bitMappedAddress;
+ private final String byteMappedAddress;
+ private final ByteMappingScheme byteMappingScheme;
+
+ private final String mode;
+ private final boolean readPermission;
+ private final boolean writePermission;
+ private final boolean executePermission;
+ private final boolean isVolatile;
+
+ private static final String DEFAULT_MODE = "rw";
/**
* Construct MemoryBlockDefinition using a text-based specified.
@@ -62,7 +70,8 @@ public class MemoryBlockDefinition {
* decimations may be specified using a mapping ratio. When specifying a mapping ratio both
* values must be in the range 1..127 where the right (source-byte count) value must be
* greater-than-or-equal to the left value (e.g., 2:4).
- * @param mode block mode as concatenation of the following mode indicator characters:
+ * @param mode block mode as concatenation of the following mode indicator characters. If null
+ * the default mode (rw) will be used.
*
* r - read mode enabled
* w - write mode enabled
@@ -71,18 +80,33 @@ public class MemoryBlockDefinition {
*
* @param lengthString length of memory block in bytes (required)
* @param initializedString boolean (y | n | true | false) indicating if memory block is
- * initialialized or not (must be null for mapped block specification)
+ * initialialized or not (ignored for mapped block specification)
* @param overlayString boolean (y | n | true | false) indicating if memory block is an overlay
* (false assumed if null).
* @throws XmlAttributeException if parse failure occurs (NOTE: address parsing is not performed)
*/
private MemoryBlockDefinition(String blockName, String addressString, String bitMappedAddress,
String byteMappedAddressRatio, String mode, String lengthString,
- String initializedString, String overlayString)
- throws XmlAttributeException {
+ String initializedString, String overlayString) throws XmlAttributeException {
+ this.mode = mode != null ? mode.toLowerCase() : DEFAULT_MODE;
+
+ // Parse specified access mode
+ readPermission = this.mode.indexOf('r') >= 0;
+ writePermission = this.mode.indexOf('w') >= 0;
+ executePermission = this.mode.indexOf('x') >= 0;
+ isVolatile = this.mode.indexOf('v') >= 0;
+
+ if (blockName == null) {
+ throw new XmlAttributeException("Missing default memory block 'name'");
+ }
this.blockName = blockName;
+
+ if (addressString == null) {
+ throw new XmlAttributeException("Missing default memory block 'start_address'");
+ }
this.addressString = addressString;
+
this.bitMappedAddress = bitMappedAddress;
if (byteMappedAddressRatio != null) {
@@ -98,30 +122,35 @@ public class MemoryBlockDefinition {
}
else {
// 1:1 mapping scheme assumed (null byteMappingScheme)
+ byteMappingScheme = null;
byteMappedAddress = byteMappedAddressRatio;
}
}
-
- if (mode != null) {
- mode = mode.toLowerCase();
- readPermission = mode.indexOf('r') >= 0;
- writePermission = mode.indexOf('w') >= 0;
- executePermission = mode.indexOf('x') >= 0;
- isVolatile = mode.indexOf('v') >= 0;
+ else {
+ byteMappedAddress = null;
+ byteMappingScheme = null;
}
+
+ // Parse specified length string
+ int parsedLen = -1;
try {
- length = XmlUtilities.parseInt(lengthString);
+ parsedLen = XmlUtilities.parseInt(lengthString);
}
catch (NumberFormatException e) {
- throw new XmlAttributeException(lengthString + " is not a valid integer");
+ // ignore - length will be checked below
}
+ if (parsedLen <= 0) {
+ throw new XmlAttributeException(lengthString + " is not a valid 'length'");
+ }
+ length = parsedLen;
+
if (initializedString != null) {
if (bitMappedAddress != null || byteMappedAddress != null) {
throw new XmlAttributeException(
"mapped block specifications must not specify initialized attribute");
}
- initialized = XmlUtilities.parseBoolean(initializedString);
}
+ initialized = XmlUtilities.parseBoolean(initializedString);
overlay = XmlUtilities.parseBoolean(overlayString);
}
@@ -142,20 +171,164 @@ public class MemoryBlockDefinition {
return addr;
}
+ /**
+ * {@return memory block name}
+ */
+ public String getBlockName() {
+ return blockName;
+ }
+
+ /**
+ * Create or fixup existing block found within specified program.
+ * @param program target program
+ * @return new or adjusted memory block
+ * @throws LockException if program does not have exclusive access
+ * @throws MemoryBlockException if failed to create or fixup default memory block
+ */
+ public MemoryBlock fixupBlock(ProgramDB program) throws LockException, MemoryBlockException {
+
+ program.checkExclusiveAccess();
+
+ Memory memory = program.getMemory();
+ MemoryBlock block = memory.getBlock(blockName);
+ if (block == null) {
+ try {
+ Msg.info(this, "Adding process-defined memory block: " + blockName);
+ return createBlock(program);
+ }
+ catch (MemoryConflictException | AddressOverflowException | InvalidAddressException e) {
+ throw new MemoryBlockException("Create block failed", e);
+ }
+ }
+
+ MemoryBlockType blockType = getBlockType();
+ List sourceInfos = block.getSourceInfos();
+
+ if (!blockType.equals(block.getType()) || overlay != block.isOverlay() ||
+ sourceInfos.size() != 1) {
+ throw new MemoryBlockException("Incompatible memory block type");
+ }
+
+ MemoryBlockSourceInfo sourceInfo = sourceInfos.get(0);
+
+ Address addr;
+ Address currentStartAddress;
+ try {
+ addr = parseAddress(addressString, program, "block address");
+
+ currentStartAddress = block.getStart();
+ AddressSpace currentAddressSpace = currentStartAddress.getAddressSpace();
+
+ if (currentAddressSpace instanceof OverlayAddressSpace overlaySpace) {
+ if (overlaySpace.getOverlayedSpace().equals(addr.getAddressSpace())) {
+ throw new MemoryBlockException("Incompatible overlay memory block");
+ }
+ // Redefine overlay block start address for comparison use
+ addr = overlaySpace.getAddressInThisSpaceOnly(addr.getOffset());
+ }
+
+ if (bitMappedAddress != null) {
+ Address mappedAddr = parseAddress(bitMappedAddress, program, "bit-mapped address");
+ if (addr.equals(currentStartAddress) &&
+ mappedAddr.equals(sourceInfo.getMappedRange().get().getMinAddress()) &&
+ length == block.getSize()) {
+ return block;
+ }
+ // We do not currently support modifying default bit-mapped block
+ throw new MemoryBlockException("inconsistent bit-mapped block");
+ }
+ else if (byteMappedAddress != null) {
+ Address mappedAddr =
+ parseAddress(byteMappedAddress, program, "byte-mapped address");
+ if (addr.equals(currentStartAddress) &&
+ mappedAddr.equals(sourceInfo.getMappedRange().get().getMinAddress()) &&
+ length == block.getSize()) {
+ return block;
+ }
+ // We do not currently support modifying default byte-mapped block
+ throw new MemoryBlockException("inconsistent byte-mapped block");
+ }
+ }
+ catch (InvalidAddressException e) {
+ throw new MemoryBlockException("failed to process processor block address", e);
+ }
+
+ if (sourceInfo.getFileBytes().isPresent() || sourceInfo.getMappedRange().isPresent()) {
+ throw new MemoryBlockException("unsupported file or memory-mapped block");
+ }
+
+ if (!addr.equals(currentStartAddress)) {
+ throw new MemoryBlockException(
+ "inconsistent block start address: " + addr + " / " + currentStartAddress);
+ }
+
+ try {
+ if (length > block.getSize()) {
+ // Expand processor defined memory block
+ Msg.info(this, "Expanding processor defined memory block from " + block.getSize() +
+ "-bytes to " + length + "-bytes: " + blockName);
+ MemoryBlock newBlock = memory.createBlock(block, block.getName() + ".exp",
+ block.getEnd().next(), length - block.getSize());
+ MemoryBlock b = memory.join(block, newBlock);
+ if (!b.getName().equals(blockName)) {
+ b.setName(blockName); // preserve block name
+ }
+ }
+ else {
+ Msg.warn(this, "Ignored processor block size reduction: " + blockName);
+ }
+
+ boolean accessAdjusted = false;
+ if (readPermission != block.isRead()) {
+ block.setRead(readPermission);
+ accessAdjusted = true;
+ }
+ if (writePermission != block.isWrite()) {
+ block.setWrite(writePermission);
+ accessAdjusted = true;
+ }
+ if (executePermission != block.isExecute()) {
+ block.setExecute(executePermission);
+ accessAdjusted = true;
+ }
+ if (isVolatile != block.isVolatile()) {
+ block.setVolatile(isVolatile);
+ accessAdjusted = true;
+ }
+ if (accessAdjusted) {
+ Msg.warn(this, "Updated processor block access mode (" + mode + "): " + blockName);
+ }
+
+ }
+ catch (IllegalArgumentException | MemoryConflictException | AddressOverflowException e) {
+ throw new MemoryBlockException("block adjustment failed", e);
+ }
+
+ return block;
+ }
+
+ private MemoryBlockType getBlockType() {
+ if (bitMappedAddress != null) {
+ return MemoryBlockType.BIT_MAPPED;
+ }
+ if (byteMappedAddress != null) {
+ return MemoryBlockType.BYTE_MAPPED;
+ }
+ return MemoryBlockType.DEFAULT;
+ }
+
/**
* Create memory block within specified program based upon this block specification.
* @param program target program
+ * @return newly created memory block
* @throws LockException if program does not have exclusive access required when adding memory blocks.
* @throws MemoryConflictException if this specification conflicts with an existing memory block in program
* @throws AddressOverflowException if memory space constraints are violated by block specification
* @throws InvalidAddressException if address defined by this block specification is invalid
* for the specified program. May also indicate an improperly formatted address attribute.
*/
- public void createBlock(Program program) throws LockException, MemoryConflictException,
+ public MemoryBlock createBlock(Program program) throws LockException, MemoryConflictException,
AddressOverflowException, InvalidAddressException {
- if (blockName == null || addressString == null || length <= 0) {
- return;
- }
Memory mem = program.getMemory();
Address addr = parseAddress(addressString, program, "block address");
@@ -172,9 +345,8 @@ public class MemoryBlockDefinition {
}
else if (initialized) {
try {
- block =
- mem.createInitializedBlock(blockName, addr, length, (byte) 0,
- TaskMonitor.DUMMY, overlay);
+ block = mem.createInitializedBlock(blockName, addr, length, (byte) 0,
+ TaskMonitor.DUMMY, overlay);
}
catch (CancelledException e) {
throw new AssertException(e); // unexpected
@@ -187,6 +359,7 @@ public class MemoryBlockDefinition {
block.setWrite(writePermission);
block.setExecute(executePermission);
block.setVolatile(isVolatile);
+ return block;
}
@Override
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
index 330b0a80ef..e98c7f6cea 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
@@ -47,6 +47,7 @@ import ghidra.program.model.util.ProcessorSymbolType;
import ghidra.sleigh.grammar.SleighPreprocessor;
import ghidra.sleigh.grammar.SourceFileIndexer;
import ghidra.util.*;
+import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor;
import ghidra.util.xml.SpecXmlUtils;
import ghidra.xml.*;
@@ -787,10 +788,9 @@ public class SleighLanguage implements Language {
AddressLabelInfo info;
try {
info = new AddressLabelInfo(startAddress, rangeSize, labelName, comment,
- false,
- isEntry, type, isVolatile);
+ false, isEntry, type, isVolatile);
}
- catch (AddressOverflowException e) {
+ catch (AddressOverflowException | InvalidInputException e) {
throw new XmlParseException("invalid symbol definition: " + labelName,
e);
}
@@ -1242,9 +1242,7 @@ public class SleighLanguage implements Language {
ManualEntry manualEntry = null;
int maxInCommon = -1;
- Iterator> ii = subMap.entrySet().iterator();
- while (ii.hasNext()) {
- Entry mapEntry = ii.next();
+ for (Entry mapEntry : subMap.entrySet()) {
String key = mapEntry.getKey();
if (instruction.startsWith(key) && key.length() > maxInCommon) {
manualEntry = mapEntry.getValue();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java
index 31b9a991de..1b641080bb 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/ProgramDB.java
@@ -22,6 +22,7 @@ import java.util.*;
import org.apache.commons.lang3.StringUtils;
import db.DBHandle;
+import ghidra.app.plugin.processors.generic.LanguageFixupUtil;
import ghidra.app.plugin.processors.sleigh.SleighLanguage;
import ghidra.framework.Application;
import ghidra.framework.data.DomainObjectAdapterDB;
@@ -2065,8 +2066,10 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
newCompilerSpecID = translator.getNewCompilerSpecID(compilerSpecID);
}
Msg.info(this, "Setting language for Program " + getName() + ": " + translator);
- Msg.info(this, "Setting compiler spec for Program " + getName() + ": " +
- compilerSpecID + " -> " + newCompilerSpecID);
+ if (!compilerSpecID.equals(newCompilerSpecID)) {
+ Msg.info(this, "Setting compiler spec for Program " + getName() + ": " +
+ compilerSpecID + " -> " + newCompilerSpecID);
+ }
}
else if (!forceRedisassembly && language.getVersion() == languageVersion &&
language.getMinorVersion() == languageMinorVersion) {
@@ -2138,6 +2141,9 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
translator.fixupInstructions(this, translator.getOldLanguage(), monitor);
}
+ // apply pspec default markup as defined by translator and pspec
+ LanguageFixupUtil.applyPSpecFixups(this);
+
dataMap.put(LANGUAGE_ID, languageID.getIdAsString());
dataMap.put(COMPILER_SPEC_ID, compilerSpecID.getIdAsString());
dataMap.put(LANGUAGE_VERSION, languageVersion + "." + languageMinorVersion);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
index 6c262f3512..6d609c8eb1 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/MemoryMapDB.java
@@ -941,7 +941,7 @@ public class MemoryMapDB implements Memory, ManagerDB {
@Override
public void moveBlock(MemoryBlock block, Address newStartAddr, TaskMonitor monitor)
throws MemoryBlockException, MemoryConflictException, AddressOverflowException,
- NotFoundException, LockException {
+ LockException {
lock.acquire();
try {
program.checkExclusiveAccess();
@@ -986,8 +986,7 @@ public class MemoryMapDB implements Memory, ManagerDB {
}
@Override
- public void split(MemoryBlock block, Address addr)
- throws MemoryBlockException, NotFoundException, LockException {
+ public void split(MemoryBlock block, Address addr) throws MemoryBlockException, LockException {
lock.acquire();
try {
program.checkExclusiveAccess();
@@ -1037,7 +1036,7 @@ public class MemoryMapDB implements Memory, ManagerDB {
@Override
public MemoryBlock join(MemoryBlock blockOne, MemoryBlock blockTwo)
- throws MemoryBlockException, NotFoundException, LockException {
+ throws MemoryBlockException, LockException {
lock.acquire();
try {
// swap if second block is before first block
@@ -1111,7 +1110,7 @@ public class MemoryMapDB implements Memory, ManagerDB {
@Override
public MemoryBlock convertToInitialized(MemoryBlock uninitializedBlock, byte initialValue)
- throws MemoryBlockException, NotFoundException, LockException {
+ throws MemoryBlockException, LockException {
lock.acquire();
try {
checkBlock(uninitializedBlock);
@@ -1149,7 +1148,7 @@ public class MemoryMapDB implements Memory, ManagerDB {
@Override
public MemoryBlock convertToUninitialized(MemoryBlock initializedBlock)
- throws MemoryBlockException, NotFoundException, LockException {
+ throws MemoryBlockException, LockException {
lock.acquire();
try {
program.checkExclusiveAccess();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ProgramArchitectureTranslator.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ProgramArchitectureTranslator.java
index 67a42c6043..3bc1159702 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ProgramArchitectureTranslator.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ProgramArchitectureTranslator.java
@@ -4,9 +4,9 @@
* 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.
@@ -15,10 +15,12 @@
*/
package ghidra.program.model.data;
+import ghidra.program.database.ProgramDB;
import ghidra.program.model.lang.*;
import ghidra.program.model.listing.IncompatibleLanguageException;
import ghidra.program.util.DefaultLanguageService;
import ghidra.program.util.LanguageTranslatorAdapter;
+import ghidra.util.task.TaskMonitor;
public class ProgramArchitectureTranslator extends LanguageTranslatorAdapter {
@@ -40,9 +42,8 @@ public class ProgramArchitectureTranslator extends LanguageTranslatorAdapter {
public ProgramArchitectureTranslator(LanguageID oldLanguageId, int oldLanguageVersion,
CompilerSpecID oldCompilerSpecId, Language newLanguage,
- CompilerSpecID newCompilerSpecId)
- throws LanguageNotFoundException, CompilerSpecNotFoundException,
- IncompatibleLanguageException {
+ CompilerSpecID newCompilerSpecId) throws LanguageNotFoundException,
+ CompilerSpecNotFoundException, IncompatibleLanguageException {
this(getLanguage(oldLanguageId, oldLanguageVersion), oldCompilerSpecId, newLanguage,
newCompilerSpecId);
}
@@ -65,5 +66,4 @@ public class ProgramArchitectureTranslator extends LanguageTranslatorAdapter {
return newCompilerSpec;
}
-
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/AddressLabelInfo.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/AddressLabelInfo.java
index ef114b9018..566fddce68 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/AddressLabelInfo.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/AddressLabelInfo.java
@@ -17,7 +17,9 @@ package ghidra.program.model.lang;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressOverflowException;
+import ghidra.program.model.symbol.SymbolUtilities;
import ghidra.program.model.util.ProcessorSymbolType;
+import ghidra.util.exception.InvalidInputException;
/**
* AddressLabelInfo is a utility class for storing
@@ -35,7 +37,7 @@ public class AddressLabelInfo implements Comparable {
private ProcessorSymbolType processorSymbolType;
private int sizeInBytes;
private Boolean isVolatile;
-
+
/**
* Constructor for class AddressLabelInfo
*
@@ -47,17 +49,22 @@ public class AddressLabelInfo implements Comparable {
* @param isEntry boolean describes if this object is an entry label for the Address 'addr'
* @param type ProcessorSymbolType the type of symbol
* @param isVolatile Boolean describes if the memory at this address is volatile
+ * @throws AddressOverflowException if sizeInBytes cause an overflow relative to address
+ * @throws InvalidInputException if an invalid label name is specified
*/
- public AddressLabelInfo(Address addr, Integer sizeInBytes, String label, String description, boolean isPrimary,
- boolean isEntry, ProcessorSymbolType type, Boolean isVolatile) throws AddressOverflowException {
+ public AddressLabelInfo(Address addr, Integer sizeInBytes, String label, String description,
+ boolean isPrimary, boolean isEntry, ProcessorSymbolType type, Boolean isVolatile)
+ throws AddressOverflowException, InvalidInputException {
+ SymbolUtilities.validateName(label);
this.addr = addr;
- if ( sizeInBytes == null || sizeInBytes <= 0 ) {
+ if (sizeInBytes == null || sizeInBytes <= 0) {
// Default size in addressable units
this.sizeInBytes = addr.getAddressSpace().getAddressableUnitSize();
- } else {
+ }
+ else {
this.sizeInBytes = sizeInBytes;
}
- this.endAddr = this.addr.addNoWrap(this.sizeInBytes-1);
+ this.endAddr = this.addr.addNoWrap(this.sizeInBytes - 1);
this.label = label;
this.description = description;
this.isPrimary = isPrimary;
@@ -72,21 +79,21 @@ public class AddressLabelInfo implements Comparable {
public final Address getAddress() {
return addr;
}
-
+
/**
* @return the object's end address.
*/
public final Address getEndAddress() {
return endAddr;
}
-
+
/**
* @return the object's label or alias.
*/
public final String getLabel() {
return label;
}
-
+
/**
* @return the object's description if it has one, null otherwise
*/
@@ -101,14 +108,14 @@ public class AddressLabelInfo implements Comparable {
public final int getByteSize() {
return sizeInBytes;
}
-
+
/**
* @return whether the object is the primary label at the address.
*/
public final boolean isPrimary() {
return isPrimary;
}
-
+
/**
* @return whether the object is volatile.
* Boolean.False when the address is explicitly not volatile.
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/Memory.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/Memory.java
index 3b756fc30a..4fe26964ff 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/Memory.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/Memory.java
@@ -25,7 +25,6 @@ import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.OffsetReference;
import ghidra.util.exception.CancelledException;
-import ghidra.util.exception.NotFoundException;
import ghidra.util.task.TaskMonitor;
/**
@@ -462,16 +461,14 @@ public interface Memory extends AddressSetView {
* @param newStartAddr new start address for block
* @param monitor task monitor so the move block can be canceled
* @throws LockException if exclusive lock not in place (see haveLock())
+ * @throws MemoryBlockException if block movement is not permitted
* @throws MemoryConflictException if move would cause
* blocks to overlap.
- * @throws MemoryBlockException if block movement is not permitted
* @throws AddressOverflowException if block movement would violate bounds of address space
- * @throws NotFoundException if memoryBlock does not exist in
- * this memory.
*/
public void moveBlock(MemoryBlock block, Address newStartAddr, TaskMonitor monitor)
throws LockException, MemoryBlockException, MemoryConflictException,
- AddressOverflowException, NotFoundException;
+ AddressOverflowException;
/**
* Split a block at the given addr and create a new block
@@ -479,14 +476,11 @@ public interface Memory extends AddressSetView {
* @param block block to be split into two
* @param addr address (within block) that will be the
* start of new block
- * @throws LockException if exclusive lock not in place (see haveLock())
- * @throws NotFoundException thrown if block does not exist
- * in memory
* @throws MemoryBlockException memory split not permitted
+ * @throws LockException if exclusive lock not in place (see haveLock())
* @throws AddressOutOfBoundsException thrown if address is not in the block
*/
- public void split(MemoryBlock block, Address addr)
- throws MemoryBlockException, LockException, NotFoundException;
+ public void split(MemoryBlock block, Address addr) throws MemoryBlockException, LockException;
/**
* Join the two blocks to create a single memory block.
@@ -499,7 +493,7 @@ public interface Memory extends AddressSetView {
* not contiguous in the address space,
*/
public MemoryBlock join(MemoryBlock blockOne, MemoryBlock blockTwo)
- throws LockException, MemoryBlockException, NotFoundException;
+ throws LockException, MemoryBlockException;
/**
* Convert an existing uninitialized block with an initialized block.
@@ -512,10 +506,20 @@ public interface Memory extends AddressSetView {
* the same.
*/
public MemoryBlock convertToInitialized(MemoryBlock uninitializedBlock, byte initialValue)
- throws LockException, MemoryBlockException, NotFoundException;
+ throws LockException, MemoryBlockException;
- public MemoryBlock convertToUninitialized(MemoryBlock itializedBlock)
- throws MemoryBlockException, NotFoundException, LockException;
+ /**
+ * Convert an existing initialized block with an uninitialized block.
+ * Block will discard any associated memory bytes and drop source info.
+ * @param initializedBlock uninitialized block to convert
+ * @return the converted block
+ * @throws LockException if exclusive lock not in place (see haveLock())
+ * @throws MemoryBlockException if there is no block in memory
+ * at the same address as block or if the block lengths are not
+ * the same.
+ */
+ public MemoryBlock convertToUninitialized(MemoryBlock initializedBlock)
+ throws MemoryBlockException, LockException;
/**
* Finds a sequence of contiguous bytes that match the
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockException.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockException.java
index a0464dd1c8..92cb2cbfad 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockException.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/MemoryBlockException.java
@@ -1,13 +1,12 @@
/* ###
* 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.
@@ -16,7 +15,6 @@
*/
package ghidra.program.model.mem;
-
/**
* Exception thrown for memory block-related problems.
*/
@@ -29,11 +27,21 @@ public class MemoryBlockException extends MemoryAccessException {
public MemoryBlockException() {
super();
}
+
/**
* Constructs a new MemoryBlockException with a detailed message.
* @param msg detailed message
*/
- public MemoryBlockException(String msg) {
- super(msg);
- }
-}
+ public MemoryBlockException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a new MemoryBlockException with a detailed message.
+ * @param msg detailed message
+ * @param cause original cause of this exception
+ */
+ public MemoryBlockException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/StubMemory.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/StubMemory.java
index ae14cf4aa0..aad0ffc499 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/StubMemory.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/mem/StubMemory.java
@@ -24,7 +24,6 @@ import ghidra.framework.store.LockException;
import ghidra.program.database.mem.*;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Program;
-import ghidra.util.exception.NotFoundException;
import ghidra.util.task.TaskMonitor;
/**
@@ -241,31 +240,31 @@ public class StubMemory extends AddressSet implements Memory {
@Override
public void moveBlock(MemoryBlock block, Address newStartAddr, TaskMonitor monitor)
throws LockException, MemoryBlockException, MemoryConflictException,
- AddressOverflowException, NotFoundException {
+ AddressOverflowException {
throw new UnsupportedOperationException();
}
@Override
public void split(MemoryBlock block, Address addr)
- throws MemoryBlockException, LockException, NotFoundException {
+ throws MemoryBlockException, LockException {
throw new UnsupportedOperationException();
}
@Override
public MemoryBlock join(MemoryBlock blockOne, MemoryBlock blockTwo)
- throws LockException, MemoryBlockException, NotFoundException {
+ throws LockException, MemoryBlockException {
throw new UnsupportedOperationException();
}
@Override
public MemoryBlock convertToInitialized(MemoryBlock uninitializedBlock, byte initialValue)
- throws LockException, MemoryBlockException, NotFoundException {
+ throws LockException, MemoryBlockException {
throw new UnsupportedOperationException();
}
@Override
public MemoryBlock convertToUninitialized(MemoryBlock initializedBlock)
- throws MemoryBlockException, NotFoundException, LockException {
+ throws MemoryBlockException, LockException {
throw new UnsupportedOperationException();
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslator.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslator.java
index 3366310206..2622304812 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslator.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslator.java
@@ -4,9 +4,9 @@
* 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.
@@ -15,6 +15,7 @@
*/
package ghidra.program.util;
+import ghidra.program.database.ProgramDB;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.lang.*;
@@ -34,7 +35,7 @@ import ghidra.util.task.TaskMonitor;
* instantiate Language, AddressSpace, AddressFactory or Register objects until isValid() is invoked.
*/
public interface LanguageTranslator extends ExtensionPoint {
-
+
/**
* Validate translator to complete initialization and ensure language compatibility.
* This method will be invoked by the LanguageTranslatorFactory before handing out this
@@ -42,7 +43,7 @@ public interface LanguageTranslator extends ExtensionPoint {
* @return true if translator successfully validated
*/
public boolean isValid();
-
+
/**
* Returns old language
* @throws IllegalStateException if instance has not been validated
@@ -54,27 +55,27 @@ public interface LanguageTranslator extends ExtensionPoint {
* Returns new language
*/
public Language getNewLanguage();
-
+
/**
* Returns old language name
*/
public LanguageID getOldLanguageID();
-
+
/**
* Returns new language name
*/
public LanguageID getNewLanguageID();
-
+
/**
* Returns old language version
*/
public int getOldVersion();
-
+
/**
* Returns new language version
*/
public int getNewVersion();
-
+
/**
* Translate BASE address spaces (Overlay spaces are not handled)
* @param oldSpaceName old space name
@@ -92,7 +93,7 @@ public interface LanguageTranslator extends ExtensionPoint {
* @see #getOldRegisterContaining(Address)
*/
public Register getOldRegister(Address oldAddr, int size);
-
+
/**
* Get the largest old register which contains the specified oldAddr
* @param oldAddr old register address which may be offcut
@@ -104,14 +105,14 @@ public interface LanguageTranslator extends ExtensionPoint {
* Returns the old processor context register or null if not defined
*/
public Register getOldContextRegister();
-
+
/**
* Find new register which corresponds to the specified old register.
* @param oldReg old register
* @return new register or null if corresponding register not found.
*/
public Register getNewRegister(Register oldReg);
-
+
/**
* Returns the new processor context register or null if not defined
*/
@@ -150,7 +151,8 @@ public interface LanguageTranslator extends ExtensionPoint {
* @throws CompilerSpecNotFoundException if new compiler spec not found based upon
* translator mappings.
*/
- public CompilerSpec getOldCompilerSpec(CompilerSpecID oldCompilerSpecID) throws CompilerSpecNotFoundException;
+ public CompilerSpec getOldCompilerSpec(CompilerSpecID oldCompilerSpecID)
+ throws CompilerSpecNotFoundException;
/**
* Invoked after Program language upgrade has completed.
@@ -172,4 +174,5 @@ public interface LanguageTranslator extends ExtensionPoint {
*/
public void fixupInstructions(Program program, Language oldLanguage, TaskMonitor monitor)
throws Exception, CancelledException;
+
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorAdapter.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorAdapter.java
index 2e03b03a56..4eb2168573 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorAdapter.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorAdapter.java
@@ -4,9 +4,9 @@
* 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.
@@ -225,9 +225,7 @@ public abstract class LanguageTranslatorAdapter implements LanguageTranslator {
protected static AddressSpace findSpaceSameName(AddressSpace oldSpace,
ArrayList newSpaces) throws IncompatibleLanguageException {
- Iterator it = newSpaces.iterator();
- while (it.hasNext()) {
- AddressSpace space = it.next();
+ for (AddressSpace space : newSpaces) {
if (space.getName().equals(oldSpace.getName())) {
if (oldSpace.getSize() > space.getSize()) {
throw new IncompatibleLanguageException("Old language space (" +
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorFactory.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorFactory.java
index e1d1ab97ff..cbc464a876 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorFactory.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LanguageTranslatorFactory.java
@@ -4,9 +4,9 @@
* 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.
@@ -20,6 +20,7 @@ import java.util.*;
import generic.jar.ResourceFile;
import ghidra.framework.Application;
+import ghidra.program.database.ProgramDB;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.lang.*;
@@ -405,10 +406,10 @@ public class LanguageTranslatorFactory {
}
/**
- *
+ * Get language translator
* @param versionTranslatorList sorted list of version translators
- * @param version
- * @return
+ * @param version old/from language version
+ * @return translator from specified version or next greater versionor null if not found
*/
private LanguageTranslator getNextTranslator(List versionTranslatorList,
int version) {
@@ -561,4 +562,5 @@ class FactoryLanguageTranslator implements LanguageTranslator {
public String toString() {
return t1.toString() + "; " + System.getProperty("line.separator") + t2.toString();
}
+
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/OldLanguage.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/OldLanguage.java
index 1d2459058e..21b55e2ab0 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/OldLanguage.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/OldLanguage.java
@@ -289,7 +289,8 @@ class OldLanguage implements Language {
throw new SAXException("Missing required 'spaces' element");
}
if (!registersFound) {
- throw new SAXException("Missing required 'registers' element");
+ // register mapping will not be performed
+ registerMgr = (new RegisterBuilder()).getRegisterManager();
}
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleLanguageTranslator.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleLanguageTranslator.java
index f0f64cad69..e7d462b263 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleLanguageTranslator.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/SimpleLanguageTranslator.java
@@ -4,9 +4,9 @@
* 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.
@@ -471,9 +471,4 @@ class SimpleLanguageTranslator extends LanguageTranslatorAdapter {
contextSettings.put(name, val);
}
- public CompilerSpec getCompilerSpec() {
- // TODO Auto-generated method stub
- return null;
- }
-
}
diff --git a/Ghidra/Processors/RISCV/certification.manifest b/Ghidra/Processors/RISCV/certification.manifest
index e046f53d75..86ac4c8328 100644
--- a/Ghidra/Processors/RISCV/certification.manifest
+++ b/Ghidra/Processors/RISCV/certification.manifest
@@ -6,6 +6,7 @@ data/languages/RV64.pspec||GHIDRA||||END|
data/languages/andestar_v5.instr.sinc||GHIDRA||||END|
data/languages/andestar_v5.ldefs||GHIDRA||||END|
data/languages/andestar_v5.slaspec||GHIDRA||||END|
+data/languages/old/riscv_deprecated.ldefs||GHIDRA||||END|
data/languages/riscv.csr.sinc||GHIDRA||||END|
data/languages/riscv.custom.sinc||GHIDRA||||END|
data/languages/riscv.ilp32d.slaspec||GHIDRA||||END|
diff --git a/Ghidra/Processors/RISCV/data/languages/old/riscv_deprecated.ldefs b/Ghidra/Processors/RISCV/data/languages/old/riscv_deprecated.ldefs
new file mode 100644
index 0000000000..0002af5a63
--- /dev/null
+++ b/Ghidra/Processors/RISCV/data/languages/old/riscv_deprecated.ldefs
@@ -0,0 +1,150 @@
+
+
+
+
+
+ RISC-V 64 little base
+
+
+
+
+
+
+
+ RISC-V 64 little base compressed
+
+
+
+
+
+
+
+ RISC-V 64 little general purpose
+
+
+
+
+
+
+
+ RISC-V 64 little general purpose compressed
+
+
+
+
+
+
+
+ RISC-V 32 little base
+
+
+
+
+
+
+
+ RISC-V 32 little base compressed
+
+
+
+
+
+
+
+ RISC-V 32 little base compressed
+
+
+
+
+
+
+
+ RISC-V 32 little general purpose
+
+
+
+
+
+
+
+ RISC-V 32 little general purpose compressed
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ghidra/Processors/RISCV/data/languages/riscv.ldefs b/Ghidra/Processors/RISCV/data/languages/riscv.ldefs
index 9ed7b30528..346f7d6fa7 100644
--- a/Ghidra/Processors/RISCV/data/languages/riscv.ldefs
+++ b/Ghidra/Processors/RISCV/data/languages/riscv.ldefs
@@ -2,22 +2,6 @@
-
- RISC-V 32 little default
-
-
-
-
-
-
-
-
+
- RISC-V 64 little base
-
-
-
-
-
-
-
- RISC-V 64 little base compressed
-
-
-
-
-
-
-
- RISC-V 64 little general purpose
-
-
-
-
-
-
-
- RISC-V 64 little general purpose compressed
-
-
-
-
-
-
-
- RISC-V 32 little base
-
-
-
-
-
-
-
- RISC-V 32 little base compressed
-
-
-
-
-
-
-
- RISC-V 32 little base compressed
-
-
-
-
-
-
-
- RISC-V 32 little general purpose
+ id="RISCV:LE:32:default">
+ RISC-V 32 little default
-
- RISC-V 32 little general purpose compressed
-
-
-
-
-
-
+
diff --git a/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec b/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec
index c01a51e02f..fd17e478a2 100644
--- a/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec
+++ b/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec
@@ -22,6 +22,7 @@
+