Merge remote-tracking branch 'origin/GP-1208_Dan_emuSyscalls-4--SQUASHED'

This commit is contained in:
Ryan Kurtz 2022-05-20 13:53:48 -04:00
commit d428ecd97a
144 changed files with 12712 additions and 804 deletions

View file

@ -80,6 +80,7 @@ public abstract class PcodeCompile {
/**
* Handle a sleigh 'macro' invocation, returning the resulting p-code op templates (OpTpl)
*
* @param location is the file/line where the macro is invoked
* @param sym MacroSymbol is the macro symbol
* @param param is the parsed list of operand expressions
@ -143,7 +144,8 @@ public abstract class PcodeCompile {
if (vn.getOffset().equals(vt.getOffset())) {
if ((size.getType() == ConstTpl.const_type.real) &&
(vn.getSize().getType() == ConstTpl.const_type.real) &&
(vn.getSize().getReal() != 0) && (vn.getSize().getReal() != size.getReal())) {
(vn.getSize().getReal() != 0) &&
(vn.getSize().getReal() != size.getReal())) {
throw new SleighError(String.format("Localtemp size mismatch: %d vs %d",
vn.getSize().getReal(), size.getReal()), op.location);
}
@ -155,7 +157,8 @@ public abstract class PcodeCompile {
if (vn.isLocalTemp() && (vn.getOffset().equals(vt.getOffset()))) {
if ((size.getType() == ConstTpl.const_type.real) &&
(vn.getSize().getType() == ConstTpl.const_type.real) &&
(vn.getSize().getReal() != 0) && (vn.getSize().getReal() != size.getReal())) {
(vn.getSize().getReal() != 0) &&
(vn.getSize().getReal() != size.getReal())) {
throw new SleighError(String.format("Input size mismatch: %d vs %d",
vn.getSize().getReal(), size.getReal()), op.location);
}
@ -194,10 +197,10 @@ public abstract class PcodeCompile {
labsym.setPlaced();
VectorSTL<OpTpl> res = new VectorSTL<OpTpl>();
OpTpl op = new OpTpl(location, OpCode.CPUI_PTRADD);
VarnodeTpl idvn =
new VarnodeTpl(location, new ConstTpl(getConstantSpace()), new ConstTpl(
ConstTpl.const_type.real, labsym.getIndex()), new ConstTpl(
ConstTpl.const_type.real, 4));
VarnodeTpl idvn = new VarnodeTpl(location,
new ConstTpl(getConstantSpace()),
new ConstTpl(ConstTpl.const_type.real, labsym.getIndex()),
new ConstTpl(ConstTpl.const_type.real, 4));
op.addInput(idvn);
res.push_back(op);
return res;
@ -346,7 +349,8 @@ public abstract class PcodeCompile {
return res;
}
public VectorSTL<OpTpl> createOpNoOut(Location location, OpCode opc, ExprTree vn1, ExprTree vn2) {
public VectorSTL<OpTpl> createOpNoOut(Location location, OpCode opc, ExprTree vn1,
ExprTree vn2) {
// Create new expression by creating op with given -opc-
// and inputs vn1 and vn2. Free the input expressions
entry("createOpNoOut", opc, vn1, vn2);
@ -438,14 +442,14 @@ public abstract class PcodeCompile {
return ExprTree.appendParams(op, param);
}
public ExprTree createVariadic(Location location,OpCode opc,VectorSTL<ExprTree> param) {
public ExprTree createVariadic(Location location, OpCode opc, VectorSTL<ExprTree> param) {
entry("createVariadic", location, opc, param);
VarnodeTpl outvn = buildTemporary(location);
ExprTree res = new ExprTree(location);
OpTpl op = new OpTpl(location, opc);
res.ops = ExprTree.appendParams(op, param);
res.ops.back().setOutput(outvn);
res.outvn = new VarnodeTpl(location,outvn);
res.outvn = new VarnodeTpl(location, outvn);
return res;
}
@ -602,7 +606,8 @@ public abstract class PcodeCompile {
// The result is truncated to the smallest byte size that can
// contain the indicated number of bits. The result has the
// desired bits shifted all the way to the right
public ExprTree createBitRange(Location location, SpecificSymbol sym, int bitoffset, int numbits) {
public ExprTree createBitRange(Location location, SpecificSymbol sym, int bitoffset,
int numbits) {
entry("createBitRange", location, sym, bitoffset, numbits);
String errmsg = "";
if (numbits == 0) {
@ -841,12 +846,12 @@ public abstract class PcodeCompile {
break;
case CPUI_CPOOLREF:
if (op.getOut().isZeroSize() && (!op.getIn(0).isZeroSize())) {
force_size(op.getOut(),op.getIn(0).getSize(),ops);
force_size(op.getOut(), op.getIn(0).getSize(), ops);
}
if (op.getIn(0).isZeroSize() && (!op.getOut().isZeroSize())) {
force_size(op.getIn(0),op.getOut().getSize(),ops);
force_size(op.getIn(0), op.getOut().getSize(), ops);
}
for(i=1;i<op.numInput();++i) {
for (i = 1; i < op.numInput(); ++i) {
force_size(op.getIn(i), new ConstTpl(ConstTpl.const_type.real, 8), ops);
}
default:
@ -923,15 +928,17 @@ public abstract class PcodeCompile {
}
/**
* EXTREMELY IMPORTANT: keep this up to date with isInternalFunction below!!!
* Lookup the given identifier as part of parsing p-code with functional syntax.
* Build the resulting p-code expression object from the parsed operand expressions.
* EXTREMELY IMPORTANT: keep this up to date with isInternalFunction below!!! Lookup the given
* identifier as part of parsing p-code with functional syntax. Build the resulting p-code
* expression object from the parsed operand expressions.
*
* @param location identifies the file/line where the p-code is parsed from
* @param name is the given functional identifier
* @param operands is the ordered list of operand expressions
* @return the new expression (ExprTree) object
*/
public Object findInternalFunction(Location location, String name, VectorSTL<ExprTree> operands) {
public Object findInternalFunction(Location location, String name,
VectorSTL<ExprTree> operands) {
ExprTree r = null;
ExprTree s = null;
if (operands.size() > 0) {
@ -990,13 +997,13 @@ public abstract class PcodeCompile {
if (operands.size() >= 2) {
return createVariadic(location, OpCode.CPUI_CPOOLREF, operands);
}
reportError(location,name+"() expects at least two arguments");
reportError(location, name + "() expects at least two arguments");
}
if ("newobject".equals(name)) {
if (operands.size() >= 1) {
return createVariadic(location, OpCode.CPUI_NEW, operands);
}
reportError(location,name+"() expects at least one argument");
reportError(location, name + "() expects at least one argument");
}
if ("popcount".equals(name) && hasOperands(1, operands, location, name)) {
return createOp(location, OpCode.CPUI_POPCOUNT, r);
@ -1016,9 +1023,10 @@ public abstract class PcodeCompile {
}
/**
* EXTREMELY IMPORTANT: keep this up to date with findInternalFunction above!!!
* Determine if the given identifier is a sleigh internal function. Used to
* prevent user-defined p-code names from colliding with internal names
* EXTREMELY IMPORTANT: keep this up to date with findInternalFunction above!!! Determine if the
* given identifier is a sleigh internal function. Used to prevent user-defined p-code names
* from colliding with internal names
*
* @param name is the given identifier to check
* @return true if the identifier is a reserved internal function
*/

View file

@ -46,9 +46,9 @@ import ghidra.sleigh.grammar.SleighParser_SemanticParser.semantic_return;
import ghidra.util.exception.AssertException;
/**
* This class is intended to parse p-code snippets, typically from compiler specification files
* or extensions. This is outside the normal SLEIGH compilation process, and the parser is built
* on top of an existing SleighLanguage.
* This class is intended to parse p-code snippets, typically from compiler specification files or
* extensions. This is outside the normal SLEIGH compilation process, and the parser is built on top
* of an existing SleighLanguage.
*/
public class PcodeParser extends PcodeCompile {
@ -68,6 +68,7 @@ public class PcodeParser extends PcodeCompile {
/**
* Build parser from an existing SleighLanguage.
*
* @param language is the existing language
* @param ubase is the starting offset for allocating temporary registers
*/
@ -90,9 +91,12 @@ public class PcodeParser extends PcodeCompile {
}
/**
* Inject a symbol representing an "operand" to the pcode snippet. This puts a placeholder in the
* resulting template, which gets filled in with the context specific storage locations when final
* p-code is generated
* Inject a symbol representing an "operand" to the pcode snippet.
*
* <p>
* This puts a placeholder in the resulting template, which gets filled in with the context
* specific storage locations when final p-code is generated
*
* @param loc is location information for the operand
* @param name of operand symbol
* @param index to use for the placeholder
@ -153,6 +157,10 @@ public class PcodeParser extends PcodeCompile {
return PcodeParser.this.sleigh.findSymbol(nm);
}
public SleighBase getSleigh() {
return sleigh;
}
@Override
public AddrSpace getConstantSpace() {
return sleigh.getConstantSpace();
@ -217,10 +225,10 @@ public class PcodeParser extends PcodeCompile {
/**
* This class wraps on existing SleighLanguage with the SleighBase interface expected by
* PcodeCompile. It populates the symbol table with user-defined operations and the global
* PcodeCompile. It populates the symbol table with user-defined operations and the global
* VarnodeSymbol objects, which typically includes all the general purpose registers.
*/
private static class PcodeTranslate extends SleighBase {
public static class PcodeTranslate extends SleighBase {
private void copySpaces(SleighLanguage language) {
insertSpace(new ConstantSpace(this));
@ -270,8 +278,9 @@ public class PcodeParser extends PcodeCompile {
}
/**
* Populate the predefined symbol table for the parser from the given SLEIGH language.
* We only use user-defined op symbols and varnode symbols.
* Populate the predefined symbol table for the parser from the given SLEIGH language. We
* only use user-defined op symbols and varnode symbols.
*
* @param language is the SLEIGH language
*/
private void copySymbols(SleighLanguage language) {
@ -383,11 +392,12 @@ public class PcodeParser extends PcodeCompile {
/**
* Compile pcode semantic statements.
*
* @param pcodeStatements is the raw source to parse
* @param srcFile source filename from which pcodeStatements came (
* @param srcLine line number in srcFile corresponding to pcodeStatements
* @return ConstructTpl. A null may be returned or
* an exception thrown if parsing/compiling fails (see application log for errors).
* @return ConstructTpl. A null may be returned or an exception thrown if parsing/compiling
* fails (see application log for errors).
* @throws SleighException pcode compile error
*/
public ConstructTpl compilePcode(String pcodeStatements, String srcFile, int srcLine)