diff --git a/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml b/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml index 33aa1d5061..00c452a1c5 100644 --- a/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml +++ b/Ghidra/Features/Decompiler/src/main/doc/pcoderef.xml @@ -2,7 +2,7 @@
P-Code Reference Manual - Last updated September 21, 2017 + Last updated September 5, 2019 @@ -84,55 +84,55 @@ - + - + - + - + - + - + - + - + - + @@ -932,6 +932,51 @@ truncated. +POPCOUNT + +
INT_EQUALPOPCOUNT INT_SRIGHT FLOAT_CEIL
INT_NOTEQUALINT_EQUAL INT_MULT FLOAT_FLOOR
INT_LESSINT_NOTEQUAL INT_DIV FLOAT_ROUND
INT_SLESSINT_LESS INT_REM FLOAT_NAN
INT_LESSEQUALINT_SLESS INT_SDIV INT2FLOAT
INT_SLESSEQUALINT_LESSEQUAL INT_SREM FLOAT2FLOAT
INT_ZEXTINT_SLESSEQUAL BOOL_NEGATE TRUNC
INT_SEXTINT_ZEXT BOOL_XOR CPOOLREF
INT_SEXT BOOL_AND NEW
++++ + + + + + + + + + + + + + + + + + + + + + + + +
ParametersDescription
input0 + Input varnode to count.
output + Resulting integer varnode containing count.
Semantic statement +
+ output = popcount(input0);
+ + +This is a bit count (population count) operator. Within the binary representation of the value +contained in the input varnode, the number of 1 bits are counted and then returned in the +output varnode. A value of 0 returns 0, a 4-byte varnode containing the value 232-1 +(all bits set) returns 32, for instance. The input and output varnodes can have any size. The resulting +count is zero extended into the output varnode. + + + INT_EQUAL @@ -3761,6 +3806,137 @@ interpretation as a data-type changes at this point. +INSERT + +
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParametersDescription
input0 + Varnode where the value will be inserted.
input1 + Integer varnode containing the value to insert.
position(constant)Constant indicating the bit position to insert at.
size(constant)Constant indicating the number of bits to insert.
output + Varnode result containing input0 with input1 inserted.
Semantic statement +
+ Cannot be explicitly coded.
+
+ +The values position and size must be constants. +The least significant size bits from input1 are +inserted into input0, overwriting a range of bits of the same size, +but leaving any other bits in input0 unchanged. The least significant bit of the overwritten +range is given by position, where bits in index0 are labeled from least significant +to most significant, starting at 0. The value obtained after this overwriting is returned +as output. +Varnodes input0 and output must be the same size and are intended to be the same varnode. +The value size must be not be bigger than the varnode input1, and +size + position must not be bigger than the varnode input0. + + +This operation is never generated as raw p-code, even though it is equivalent +to SLEIGH bitrange syntax such as input0[10,1] = input1. + +
+ +EXTRACT + + ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParametersDescription
input0 + Varnode to extract a value from.
position(constant)Constant indicating the bit position to extract from.
size(constant)Constant indicating the number of bits to extract.
output + Varnode result containing the extracted value.
Semantic statement +
+ Cannot be explicitly coded.
+
+ +The values position and size must be constants. +The operation extracts size bits from input0 and returns it in output. +The position indicates the least significant bit in the range being extracted, with +the bits in input0 labeled from least to most significant, starting at 0. The varnodes input0 and output +can be different sizes, and the extracted value is zero extended into output. +The value size must not be bigger than the varnode output, and +size + position must not be bigger +than the varnode input0. + + +This operation is never generated as raw p-code, even though it is equivalent +to SLEIGH bitrange syntax such as output = input0[10,1]. + +
+ @@ -3862,6 +4038,26 @@ interpretation as a data-type changes at this point. Branch execution to value in v0 viewed as an offset into the current space. Hint that the branch is a subroutine return. + + PIECE + <na> + Concatenate two varnodes into a single varnode. + + + SUBPIECE + v0:2 + The least signficant n bytes of v0. + + + SUBPIECE + v0(2) + All but the least significant n bytes of v0. + + + POPCOUNT + popcount(v0) + Count 1 bits in v0. + INT_EQUAL v0 == v1 @@ -3872,38 +4068,6 @@ interpretation as a data-type changes at this point. v0 != v1 True if v0 does not equal v1. - - INT_SLESS - - - - - - - - - - -
v0 s< v1
v1 s> v0
- - True if v0 is less than v1 as a signed integer. - - - INT_SLESSEQUAL - - - - - - - - - - -
v0 s<= v1
v1 s>= v0
- - True if v0 is less than or equal to v1 as a signed integer. - INT_LESS @@ -3920,6 +4084,22 @@ interpretation as a data-type changes at this point. True if v0 is less than v1 as an unsigned integer. + + INT_SLESS + + + + + + + + + + +
v0 s< v1
v1 s> v0
+ + True if v0 is less than v1 as a signed integer. + INT_LESSEQUAL @@ -3936,6 +4116,22 @@ interpretation as a data-type changes at this point. True if v0 is less than or equal to v1 as an unsigned integer. + + INT_SLESSEQUAL + + + + + + + + + + +
v0 s<= v1
v1 s>= v0
+ + True if v0 is less than or equal to v1 as a signed integer. + INT_ZEXT zext(v0) @@ -4021,16 +4217,16 @@ interpretation as a data-type changes at this point. v0 / v1 Unsigned division of v0 by v1. - - INT_SDIV - v0 s/ v1 - Signed division of v0 by v1. - INT_REM v0 % v1 Unsigned remainder of v0 modulo v1. + + INT_SDIV + v0 s/ v1 + Signed division of v0 by v1. + INT_SREM v0 s% v1 @@ -4098,20 +4294,15 @@ interpretation as a data-type changes at this point. True if v0 is less than or equal to v1 viewed as floating-point numbers. - - FLOAT_NAN - nan(v0) - True if v0 is not a valid floating-point number (NaN). - FLOAT_ADD v0 f+ v1 Addition of v0 and v1 as floating-point numbers. - FLOAT_DIV - v0 f/ v1 - Division of v0 by v1 as floating-point numbers. + FLOAT_SUB + v0 f- v1 + Subtraction of v1 from v0 as floating-point numbers. FLOAT_MULT @@ -4119,9 +4310,9 @@ interpretation as a data-type changes at this point. Multiplication of v0 and v1 as floating-point numbers. - FLOAT_SUB - v0 f- v1 - Subtraction of v1 from v0 as floating-point numbers. + FLOAT_DIV + v0 f/ v1 + Division of v0 by v1 as floating-point numbers. FLOAT_NEG @@ -4138,21 +4329,6 @@ interpretation as a data-type changes at this point. sqrt(v0) Square root of v0 as a floating-point number. - - INT2FLOAT - int2float(v0) - Floating-point representation of v0 viewed as an integer. - - - FLOAT2FLOAT - float2float(v0) - Copy of floating-point number v0 with more or less precision. - - - TRUNC - trunc(v0) - Signed integer obtained by truncating v0 viewed as a floating-point number. - FLOAT_CEIL ceil(v0) @@ -4169,19 +4345,24 @@ interpretation as a data-type changes at this point. Nearest integral floating-point to v0, viewed as a floating-point number. - SUBPIECE - v0:2 - The least signficant n bytes of v0. + FLOAT_NAN + nan(v0) + True if v0 is not a valid floating-point number (NaN). - SUBPIECE - v0(2) - All but the least significant n bytes of v0. + INT2FLOAT + int2float(v0) + Floating-point representation of v0 viewed as an integer. - PIECE - <na> - Concatenate two varnodes into a single varnode. + FLOAT2FLOAT + float2float(v0) + Copy of floating-point number v0 with more or less precision. + + + TRUNC + trunc(v0) + Signed integer obtained by truncating v0 viewed as a floating-point number. CPOOLREF @@ -4229,6 +4410,16 @@ interpretation as a data-type changes at this point. <na> Construct a pointer to a field from a pointer to a structure and an offset. + + INSERT + <na> + Insert a value as a bit-range into a varnode + + + EXTRACT + <na> + Extract a bit-range from a varnode + diff --git a/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml b/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml index f6cdbd2be2..c6b1b624c2 100644 --- a/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml +++ b/Ghidra/Features/Decompiler/src/main/doc/sleigh.xml @@ -4,7 +4,7 @@ SLEIGH A Language for Rapid Processor Specification Originally published December 16, 2005 - Last updated September 1, 2017 + Last updated September 5, 2019 @@ -279,7 +279,7 @@ general purpose processor instruction sets. They break up into groups. Logical - INT_NEGATE, INT_XOR, INT_AND, INT_OR, INT_LEFT, INT_RIGHT, INT_SRIGHT + INT_NEGATE, INT_XOR, INT_AND, INT_OR, INT_LEFT, INT_RIGHT, INT_SRIGHT, POPCOUNT Integer Comparison @@ -3803,6 +3803,12 @@ to lowest. truncated depending on result size. + + POPCOUNT + popcount(v0) + Count the number of 1 bits in v0. + + (simulated) v0[6,1] diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java index 8b0986b966..ae14df5cfd 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java @@ -79,11 +79,11 @@ public abstract class PcodeCompile { public abstract SectionVector finalNamedSection(SectionVector vec, ConstructTpl section); /** - * - * @param location - * @param sym MacroSymbol - * @param param - * @return + * 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 + * @return a list of p-code op templates */ public abstract VectorSTL createMacroUse(Location location, MacroSymbol sym, VectorSTL param); @@ -904,7 +904,7 @@ public abstract class PcodeCompile { return true; } if (o instanceof List) { - List l = (List) o; + List l = (List) o; for (Object t : l) { if (isLocationIsh(t)) { return true; @@ -912,7 +912,7 @@ public abstract class PcodeCompile { } } if (o instanceof VectorSTL) { - VectorSTL v = (VectorSTL) o; + VectorSTL v = (VectorSTL) o; for (Object t : v) { if (isLocationIsh(t)) { return true; @@ -924,8 +924,12 @@ public abstract class PcodeCompile { /** * EXTREMELY IMPORTANT: keep this up to date with isInternalFunction below!!! - * @param name - * @return + * 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 operands) { ExprTree r = null; @@ -1013,8 +1017,10 @@ public abstract class PcodeCompile { /** * EXTREMELY IMPORTANT: keep this up to date with findInternalFunction above!!! - * @param name - * @return + * 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 */ public boolean isInternalFunction(String name) { if ("zext".equals(name)) { @@ -1068,6 +1074,9 @@ public abstract class PcodeCompile { if ("newobject".equals(name)) { return true; } + if ("popcount".equals(name)) { + return true; + } return false; } diff --git a/GhidraDocs/languages/html/additionalpcode.html b/GhidraDocs/languages/html/additionalpcode.html index 611cfc911f..a822ce92c4 100644 --- a/GhidraDocs/languages/html/additionalpcode.html +++ b/GhidraDocs/languages/html/additionalpcode.html @@ -301,6 +301,135 @@ This operator is intended specifically for when the value doesn't change but its interpretation as a data-type changes at this point.

+
+

+INSERT

+
+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParametersDescription
input0Varnode where the value will be inserted.
input1Integer varnode containing the value to insert.
position(constant)Constant indicating the bit position to insert at.
size(constant)Constant indicating the number of bits to insert.
outputVarnode result containing input0 with input1 inserted.
Semantic statement
Cannot be explicitly coded.
+
+

+The values position and size must be constants. +The least significant size bits from input1 are +inserted into input0, overwriting a range of bits of the same size, +but leaving any other bits in input0 unchanged. The least significant bit of the overwritten +range is given by position, where bits in index0 are labeled from least significant +to most significant, starting at 0. The value obtained after this overwriting is returned +as output. +Varnodes input0 and output must be the same size and are intended to be the same varnode. +The value size must be not be bigger than the varnode input1, and +size + position must not be bigger than the varnode input0. +

+

+This operation is never generated as raw p-code, even though it is equivalent +to SLEIGH bitrange syntax such as input0[10,1] = input1. +

+
+
+

+EXTRACT

+
+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParametersDescription
input0Varnode to extract a value from.
position(constant)Constant indicating the bit position to extract from.
size(constant)Constant indicating the number of bits to extract.
outputVarnode result containing the extracted value.
Semantic statement
Cannot be explicitly coded.
+
+

+The values position and size must be constants. +The operation extracts size bits from input0 and returns it in output. +The position indicates the least significant bit in the range being extracted, with +the bits in input0 labeled from least to most significant, starting at 0. The varnodes input0 and output +can be different sizes, and the extracted value is zero extended into output. +The value size must not be bigger than the varnode output, and +size + position must not be bigger +than the varnode input0. +

+

+This operation is never generated as raw p-code, even though it is equivalent +to SLEIGH bitrange syntax such as output = input0[10,1]. +

+

+POPCOUNT

+
+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + +
ParametersDescription
input0Input varnode to count.
outputResulting integer varnode containing count.
Semantic statement
output = popcount(input0);
+
+

+This is a bit count (population count) operator. Within the binary representation of the value +contained in the input varnode, the number of 1 bits are counted and then returned in the +output varnode. A value of 0 returns 0, a 4-byte varnode containing the value 232-1 +(all bits set) returns 32, for instance. The input and output varnodes can have any size. The resulting +count is zero extended into the output varnode. +

+
+
+

INT_EQUAL

diff --git a/GhidraDocs/languages/html/pcoderef.html b/GhidraDocs/languages/html/pcoderef.html index 93b4afb949..6942d50778 100644 --- a/GhidraDocs/languages/html/pcoderef.html +++ b/GhidraDocs/languages/html/pcoderef.html @@ -25,8 +25,8 @@

-P-Code Reference Manual

-

Last updated September 21, 2017

+P-Code Reference Manual
+

Last updated September 5, 2019


@@ -111,55 +111,55 @@ - + - + - + - + - + - + - + - + - + @@ -215,7 +215,7 @@ The core concepts of p-code are:

-Address Space

+Address Space

The address space for p-code is a generalization of RAM. It is defined simply as an indexed sequence of bytes that can @@ -256,7 +256,7 @@ any of the other p-code operations.

-Varnode

+Varnode

A varnode is a generalization of either a register or a memory location. It is represented by the formal triple: @@ -303,7 +303,7 @@ on them by the p-code operations that use them.

-P-code Operation

+P-code Operation

A p-code operation is the analog of a machine instruction. All p-code operations have the same basic format diff --git a/GhidraDocs/languages/html/reference.html b/GhidraDocs/languages/html/reference.html index 25296b33ea..4711150020 100644 --- a/GhidraDocs/languages/html/reference.html +++ b/GhidraDocs/languages/html/reference.html @@ -119,6 +119,26 @@

+ + + + + + + + + + + + + + + + + + + + @@ -129,38 +149,6 @@ - - - - - - - - - - + + + + + + + + + + @@ -278,16 +298,16 @@ - - - - - + + + + + @@ -355,20 +375,15 @@ - - - - - - - - + + + @@ -376,9 +391,9 @@ - - - + + + @@ -395,21 +410,6 @@ - - - - - - - - - - - - - - - @@ -426,19 +426,24 @@ - - - + + + - - - + + + - - - + + + + + + + + @@ -486,6 +491,16 @@ + + + + + + + + + +
INT_EQUALPOPCOUNT INT_SRIGHT FLOAT_CEIL
INT_NOTEQUALINT_EQUAL INT_MULT FLOAT_FLOOR
INT_LESSINT_NOTEQUAL INT_DIV FLOAT_ROUND
INT_SLESSINT_LESS INT_REM FLOAT_NAN
INT_LESSEQUALINT_SLESS INT_SDIV INT2FLOAT
INT_SLESSEQUALINT_LESSEQUAL INT_SREM FLOAT2FLOAT
INT_ZEXTINT_SLESSEQUAL BOOL_NEGATE TRUNC
INT_SEXTINT_ZEXT BOOL_XOR CPOOLREF
INT_SEXT BOOL_AND NEW
Branch execution to value in v0 viewed as an offset into the current space. Hint that the branch is a subroutine return.
PIECE<na>Concatenate two varnodes into a single varnode.
SUBPIECEv0:2The least signficant n bytes of v0.
SUBPIECEv0(2)All but the least significant n bytes of v0.
POPCOUNTpopcount(v0)Count 1 bits in v0.
INT_EQUAL v0 == v1v0 != v1 True if v0 does not equal v1.
INT_SLESS -
- - - - - - - -
v0 s< v1
v1 s> v0
-
-
True if v0 is less than v1 as a signed integer.
INT_SLESSEQUAL -
- - - - - - - -
v0 s<= v1
v1 s>= v0
-
-
True if v0 is less than or equal to v1 as a signed integer.
INT_LESS @@ -177,6 +165,22 @@ True if v0 is less than v1 as an unsigned integer.
INT_SLESS +
+ + + + + + + +
v0 s< v1
v1 s> v0
+
+
True if v0 is less than v1 as a signed integer.
INT_LESSEQUAL @@ -193,6 +197,22 @@ True if v0 is less than or equal to v1 as an unsigned integer.
INT_SLESSEQUAL +
+ + + + + + + +
v0 s<= v1
v1 s>= v0
+
+
True if v0 is less than or equal to v1 as a signed integer.
INT_ZEXT zext(v0)v0 / v1 Unsigned division of v0 by v1.
INT_SDIVv0 s/ v1Signed division of v0 by v1.
INT_REM v0 % v1 Unsigned remainder of v0 modulo v1.
INT_SDIVv0 s/ v1Signed division of v0 by v1.
INT_SREM v0 s% v1 True if v0 is less than or equal to v1 viewed as floating-point numbers.
FLOAT_NANnan(v0)True if v0 is not a valid floating-point number (NaN).
FLOAT_ADD v0 f+ v1 Addition of v0 and v1 as floating-point numbers.
FLOAT_DIVv0 f/ v1Division of v0 by v1 as floating-point numbers.FLOAT_SUBv0 f- v1Subtraction of v1 from v0 as floating-point numbers.
FLOAT_MULTMultiplication of v0 and v1 as floating-point numbers.
FLOAT_SUBv0 f- v1Subtraction of v1 from v0 as floating-point numbers.FLOAT_DIVv0 f/ v1Division of v0 by v1 as floating-point numbers.
FLOAT_NEGsqrt(v0) Square root of v0 as a floating-point number.
INT2FLOATint2float(v0)Floating-point representation of v0 viewed as an integer.
FLOAT2FLOATfloat2float(v0)Copy of floating-point number v0 with more or less precision.
TRUNCtrunc(v0)Signed integer obtained by truncating v0 viewed as a floating-point number.
FLOAT_CEIL ceil(v0)Nearest integral floating-point to v0, viewed as a floating-point number.
SUBPIECEv0:2The least signficant n bytes of v0.FLOAT_NANnan(v0)True if v0 is not a valid floating-point number (NaN).
SUBPIECEv0(2)All but the least significant n bytes of v0.INT2FLOATint2float(v0)Floating-point representation of v0 viewed as an integer.
PIECE<na>Concatenate two varnodes into a single varnode.FLOAT2FLOATfloat2float(v0)Copy of floating-point number v0 with more or less precision.
TRUNCtrunc(v0)Signed integer obtained by truncating v0 viewed as a floating-point number.
CPOOLREF<na> Construct a pointer to a field from a pointer to a structure and an offset.
INSERT<na>Insert a value as a bit-range into a varnode
EXTRACT<na>Extract a bit-range from a varnode
diff --git a/GhidraDocs/languages/html/sleigh.html b/GhidraDocs/languages/html/sleigh.html index fa290750c7..cc532db93e 100644 --- a/GhidraDocs/languages/html/sleigh.html +++ b/GhidraDocs/languages/html/sleigh.html @@ -25,9 +25,9 @@

-SLEIGH

+SLEIGH

A Language for Rapid Processor Specification

-

Last updated September 1, 2017

+

Last updated September 5, 2019

Originally published December 16, 2005


@@ -35,51 +35,51 @@

Table of Contents

-
1. Introduction to P-Code
+
1. Introduction to P-Code
-
1.1. Address Spaces
+
1.1. Address Spaces
1.2. Varnodes
-
1.3. Operations
+
1.3. Operations
2. Basic Specification Layout
-
2.1. Comments
-
2.2. Identifiers
-
2.3. Strings
-
2.4. Integers
-
2.5. White Space
+
2.1. Comments
+
2.2. Identifiers
+
2.3. Strings
+
2.4. Integers
+
2.5. White Space
3. Preprocessing
3.1. Including Files
-
3.2. Preprocessor Macros
-
3.3. Conditional Compilation
+
3.2. Preprocessor Macros
+
3.3. Conditional Compilation
4. Basic Definitions
4.1. Endianess Definition
-
4.2. Alignment Definition
-
4.3. Space Definitions
+
4.2. Alignment Definition
+
4.3. Space Definitions
4.4. Naming Registers
-
4.5. Bit Range Registers
-
4.6. User-Defined Operations
+
4.5. Bit Range Registers
+
4.6. User-Defined Operations
5. Introduction to Symbols
-
5.1. Notes on Namespaces
+
5.1. Notes on Namespaces
5.2. Predefined Symbols
6. Tokens and Fields
6.1. Defining Tokens and Fields
-
6.2. Fields as Family Symbols
-
6.3. Attaching Alternate Meanings to Fields
+
6.2. Fields as Family Symbols
+
6.3. Attaching Alternate Meanings to Fields
6.4. Context Variables
7. Constructors
-
7.1. The Five Sections of a Constructor
-
7.2. The Table Header
+
7.1. The Five Sections of a Constructor
+
7.2. The Table Header
7.3. The Display Section
7.4. The Bit Pattern Section
7.5. Disassembly Actions Section
@@ -87,12 +87,12 @@
7.7. The Semantic Section
7.8. Tables
7.9. P-code Macros
-
7.10. Build Directives
-
7.11. Delay Slot Directives
+
7.10. Build Directives
+
7.11. Delay Slot Directives
8. Using Context
-
8.1. Basic Use of Context Variables
+
8.1. Basic Use of Context Variables
8.2. Local Context Change
8.3. Global Context Change
@@ -101,7 +101,7 @@

-History

+History

This document describes the syntax for the SLEIGH processor specification language, which was developed for the GHIDRA @@ -129,7 +129,7 @@

-Overview

+Overview

SLEIGH is a language for describing the instruction sets of general purpose microprocessors, in order to facilitate the reverse @@ -162,7 +162,7 @@ Italics are used when defining terms and for named entities. Bold is used for SL

-1. Introduction to P-Code

+1. Introduction to P-Code

Although p-code is a distinct language from SLEIGH, because a major purpose of SLEIGH is to specify the translation from machine code to @@ -221,7 +221,7 @@ respectively.

-1.1. Address Spaces

+1.1. Address Spaces

An address space for p-code is a generalization of the indexed memory (RAM) that a typical processor has access to, and @@ -322,7 +322,7 @@ must be provided and enforced by the specification designer.

-1.3. Operations

+1.3. Operations

P-code is intended to emulate a target processor by substituting a sequence of p-code operations for each machine instruction. Thus every @@ -372,7 +372,7 @@ general purpose processor instruction sets. They break up into groups. Logical - INT_NEGATE, INT_XOR, INT_AND, INT_OR, INT_LEFT, INT_RIGHT, INT_SRIGHT + INT_NEGATE, INT_XOR, INT_AND, INT_OR, INT_LEFT, INT_RIGHT, INT_SRIGHT, POPCOUNT Integer Comparison diff --git a/GhidraDocs/languages/html/sleigh_constructors.html b/GhidraDocs/languages/html/sleigh_constructors.html index 39b7a8521c..0a0b7f8e7d 100644 --- a/GhidraDocs/languages/html/sleigh_constructors.html +++ b/GhidraDocs/languages/html/sleigh_constructors.html @@ -60,7 +60,7 @@ multiple constructors into a single table are addressed in

-7.1. The Five Sections of a Constructor

+7.1. The Five Sections of a Constructor

A single complex statement in the specification file describes a constructor. This statement is always made up of five distinct @@ -92,7 +92,7 @@ in turn.

-7.2. The Table Header

+7.2. The Table Header

Every constructor must be part of a table, which is the element with an actual family symbol identifier associated with it. So each @@ -230,7 +230,7 @@ no such requirement.

-7.3.2. The '^' character

+7.3.2. The '^' character

The ‘^’ character in the display section is used to separate identifiers from other characters where there shouldn’t be white space @@ -278,7 +278,7 @@ to match the constructor being defined.

-7.4.1. Constraints

+7.4.1. Constraints

The patterns required for processor specifications can almost always be described as a mask and value pair. Given a specific instruction @@ -337,7 +337,7 @@ requires two or more mask/value style checks to correctly implement.

-7.4.3. Defining Operands and Invoking Subtables

+7.4.3. Defining Operands and Invoking Subtables

The principle way of defining a constructor operand, left undefined from the display section, is done in the bit pattern section. If an @@ -396,7 +396,7 @@ statement of the grouping of old symbols into the new constructor.

-7.4.4. Variable Length Instructions

+7.4.4. Variable Length Instructions

There are some additional complexities to designing a specification for a processor with variable length instructions. Some initial @@ -419,7 +419,7 @@ designer control over how tokens fit together.

-7.4.4.1. The ';' Operator
+7.4.4.1. The ';' Operator

The most important operator for patterns defining variable length instructions is the concatenation operator ‘;’. When building a @@ -481,7 +481,7 @@ operator, so parentheses may be necessary to get the intended meaning.

-7.4.4.2. The '...' Operator
+7.4.4.2. The '...' Operator

The ellipsis operator ‘...’ is used to satisfy the token matching requirements of the ‘&’ and ‘|’ operators (described in the previous @@ -557,7 +557,7 @@ don’t quite match the assembly.

-7.4.6. Empty Patterns

+7.4.6. Empty Patterns

Occasionally there is a need for an empty pattern when building tables. An empty pattern matches everything. There is a predefined @@ -567,7 +567,7 @@ to indicate an empty pattern.

-7.4.7. Advanced Constraints

+7.4.7. Advanced Constraints

A constraint does not have to be of the form “field = constant”, although this is almost always what is needed. In certain situations, @@ -939,7 +939,7 @@ varnode is r1.

-7.7.1. Expressions

+7.7.1. Expressions

Expressions are built out of symbols and the binary and unary operators listed in Table 5, “Semantic Expression Operators and Syntax” in the @@ -954,7 +954,7 @@ within expressions to affect this order.

-7.7.1.1. Arithmetic, Logical and Boolean Operators
+7.7.1.1. Arithmetic, Logical and Boolean Operators

For the most part these operators should be familiar to software developers. The only real differences arise from the fact that @@ -1017,7 +1017,7 @@ set to something other than one.

-7.7.1.3. Extension
+7.7.1.3. Extension

Most processors have instructions that extend small values into big values, and many instructions do these minor data manipulations @@ -1039,7 +1039,7 @@ the sext operator.

-7.7.1.4. Truncation
+7.7.1.4. Truncation

There are two forms of syntax indicating a truncation of the input varnode. In one the varnode is followed by a colon ‘:’ and an integer @@ -1169,7 +1169,7 @@ the offset portion of the address, and to copy the desired value, the

-7.7.1.7. Managed Code Operations
+7.7.1.7. Managed Code Operations

SLEIGH provides basic support for instructions where encoding and context don't provide a complete description of the semantics. This is the case @@ -1231,7 +1231,7 @@ define pcodeop arctan;

-7.7.2. Statements

+7.7.2. Statements

We describe the types of semantic statements that are allowed in SLEIGH.

@@ -1305,7 +1305,7 @@ and may be enforced in future compiler versions.
-7.7.2.2. Storage Statements
+7.7.2.2. Storage Statements

SLEIGH supports fairly standard storage statement syntax to complement the load operator. The left-hand side of an @@ -1336,7 +1336,7 @@ attribute is set to something other than one.

-7.7.2.3. Exports
+7.7.2.3. Exports

The semantic section doesn’t just specify how to generate p-code for a constructor. Except for those constructors in the root table, this @@ -1388,7 +1388,7 @@ varnode being modified to be exported as an integer constant.

-7.7.2.4. Dynamic References
+7.7.2.4. Dynamic References

The only other operator allowed as part of an export statement, is the ‘*’ @@ -1447,7 +1447,7 @@ levels.

-7.7.2.5. Branching Statements
+7.7.2.5. Branching Statements

This section discusses statements that generate p-code branching operations. These are listed in Table 7, “Branching Statements”, in the Appendix. @@ -1802,7 +1802,7 @@ each followed by a variation which corrects the error.

-7.7.4. Unimplemented Semantics

+7.7.4. Unimplemented Semantics

The semantic section must be present for every constructor in the specification. But the designer can leave the semantics explicitly @@ -1962,7 +1962,7 @@ should generally be avoided.

-7.8.2. Specific Symbol Trees

+7.8.2. Specific Symbol Trees

When the SLEIGH parser analyzes an instruction, it starts with the root symbol instruction, and decides which of the @@ -2045,7 +2045,7 @@ and p-code for these encodings by walking the trees.

-7.8.2.1. Disassembly Trees
+7.8.2.1. Disassembly Trees

If the nodes of each tree are replaced with the display information of the corresponding specific symbol, we see how the disassembly @@ -2068,7 +2068,7 @@ statements corresponding to the original instruction encodings.

-7.8.2.2. P-code Trees
+7.8.2.2. P-code Trees

A similar procedure produces the resulting p-code translation of the instruction. If each node in the specific symbol tree is replaced with @@ -2147,7 +2147,7 @@ directive however should not be used in a macro.

-7.10. Build Directives

+7.10. Build Directives

Because the nodes of a specific symbol tree are traversed in a depth-first order, the p-code for a child node in general comes before @@ -2202,7 +2202,7 @@ normal action of the instruction.

-7.11. Delay Slot Directives

+7.11. Delay Slot Directives

For processors with a pipe-lined architecture, multiple instructions are typically executing simultaneously. This can lead to processor diff --git a/GhidraDocs/languages/html/sleigh_context.html b/GhidraDocs/languages/html/sleigh_context.html index b3e79c51b9..fa762bb070 100644 --- a/GhidraDocs/languages/html/sleigh_context.html +++ b/GhidraDocs/languages/html/sleigh_context.html @@ -85,7 +85,7 @@ whose encodings are otherwise the same.

-8.1. Basic Use of Context Variables

+8.1. Basic Use of Context Variables

Suppose a processor supports the use of two different sets of registers in its main addressing mode, based on the setting of a diff --git a/GhidraDocs/languages/html/sleigh_definitions.html b/GhidraDocs/languages/html/sleigh_definitions.html index 705532698a..49f23dd0a8 100644 --- a/GhidraDocs/languages/html/sleigh_definitions.html +++ b/GhidraDocs/languages/html/sleigh_definitions.html @@ -55,7 +55,7 @@ specification language will hide endianess issues.

-4.2. Alignment Definition

+4.2. Alignment Definition

An alignment definition looks like

@@ -72,7 +72,7 @@ instruction as an error.

-4.3. Space Definitions

+4.3. Space Definitions

The definition of an address space looks like

@@ -227,7 +227,7 @@ define register offset=0 size=1

-4.5. Bit Range Registers

+4.5. Bit Range Registers

Many processors define registers that either consist of a single bit or otherwise don't use an integral number of bytes. A recurring @@ -298,7 +298,7 @@ used as an alternate syntax for defining overlapping registers.

-4.6. User-Defined Operations

+4.6. User-Defined Operations

The specification designer can define new p-code operations using a define pcodeop statement. This diff --git a/GhidraDocs/languages/html/sleigh_layout.html b/GhidraDocs/languages/html/sleigh_layout.html index d15e0eb97e..1f312277df 100644 --- a/GhidraDocs/languages/html/sleigh_layout.html +++ b/GhidraDocs/languages/html/sleigh_layout.html @@ -36,7 +36,7 @@ by the compiler.

-2.1. Comments

+2.1. Comments

Comments start with the ‘#’ character and continue to the end of the line. Comments can appear anywhere except the display section of a @@ -46,7 +46,7 @@ interpreted as something that should be printed in disassembly.

-2.2. Identifiers

+2.2. Identifiers

Identifiers are made up of letters a-z, capitals A-Z, digits 0-9 and the characters ‘.’ and ‘_’. An identifier can use these characters in @@ -55,7 +55,7 @@ any order and for any length, but it must not start with a digit.

-2.3. Strings

+2.3. Strings

String literals can be used, when specifying names and when specifying how disassembly should be printed, so that special characters are @@ -66,7 +66,7 @@ meaning.

-2.4. Integers

+2.4. Integers

Integers are specified either in a decimal format or in a standard C-style hexadecimal format by prepending the @@ -92,7 +92,7 @@ integers internally with 64 bits of precision.

-2.5. White Space

+2.5. White Space

White space characters include space, tab, line-feed, vertical line-feed, and carriage-return (‘ ‘, ‘\t’, ‘\r’, ‘\v’, diff --git a/GhidraDocs/languages/html/sleigh_preprocessing.html b/GhidraDocs/languages/html/sleigh_preprocessing.html index a3f82b0380..1eb1e45f3a 100644 --- a/GhidraDocs/languages/html/sleigh_preprocessing.html +++ b/GhidraDocs/languages/html/sleigh_preprocessing.html @@ -54,7 +54,7 @@ own @include directives.

-3.2. Preprocessor Macros

+3.2. Preprocessor Macros

SLEIGH allows simple (unparameterized) macro definitions and expansions. A macro definition occurs on one line and starts with @@ -85,7 +85,7 @@ definition of a macro from that point on in the file.

-3.3. Conditional Compilation

+3.3. Conditional Compilation

SLEIGH supports several directives that allow conditional inclusion of parts of a specification, based on the existence of a macro, or its @@ -103,7 +103,7 @@ and @endif.

-3.3.1. @ifdef and @ifndef

+3.3.1. @ifdef and @ifndef

The @ifdef directive is followed by a macro identifier and evaluates to true if the macro is defined. @@ -129,7 +129,7 @@ or @elif directive (See below).

-3.3.2. @if

+3.3.2. @if

The @if directive is followed by a boolean expression with macros as the variables and strings as the @@ -158,7 +158,7 @@ is defined.

-3.3.3. @else and @elif

+3.3.3. @else and @elif

An @else directive splits the lines bounded by an @if directive and diff --git a/GhidraDocs/languages/html/sleigh_ref.html b/GhidraDocs/languages/html/sleigh_ref.html index 8199f08fc4..d2a54cd534 100644 --- a/GhidraDocs/languages/html/sleigh_ref.html +++ b/GhidraDocs/languages/html/sleigh_ref.html @@ -77,6 +77,12 @@ to lowest. truncated depending on result size. + + POPCOUNT + popcount(v0) + Count the number of 1 bits in v0. + + (simulated) v0[6,1] diff --git a/GhidraDocs/languages/html/sleigh_symbols.html b/GhidraDocs/languages/html/sleigh_symbols.html index 847328da56..6eb2b83374 100644 --- a/GhidraDocs/languages/html/sleigh_symbols.html +++ b/GhidraDocs/languages/html/sleigh_symbols.html @@ -105,7 +105,7 @@ the predefined identifier instruction.

-5.1. Notes on Namespaces

+5.1. Notes on Namespaces

Almost all identifiers live in the same global "scope". The global scope includes

diff --git a/GhidraDocs/languages/html/sleigh_tokens.html b/GhidraDocs/languages/html/sleigh_tokens.html index 5d069a831f..79521cfd7b 100644 --- a/GhidraDocs/languages/html/sleigh_tokens.html +++ b/GhidraDocs/languages/html/sleigh_tokens.html @@ -74,7 +74,7 @@ different names.

-6.2. Fields as Family Symbols

+6.2. Fields as Family Symbols

Fields are the most basic form of family symbol; they define a natural map from instruction bits to a specific symbol as follows. We take the @@ -99,7 +99,7 @@ the dec attribute is not supported]

-6.3. Attaching Alternate Meanings to Fields

+6.3. Attaching Alternate Meanings to Fields

The default interpretation of a field is probably the most natural but of course processors interpret fields within an instruction in a wide @@ -110,7 +110,7 @@ interpretations must be built up out of tables.

-6.3.1. Attaching Registers

+6.3.1. Attaching Registers

Probably the most common processor interpretation of a field is as an encoding of a particular register. In SLEIGH this @@ -149,7 +149,7 @@ of the instruction.

-6.3.2. Attaching Other Integers

+6.3.2. Attaching Other Integers

Sometimes a processor interprets a field as an integer but not the integer given by the default interpretation. A different integer @@ -171,7 +171,7 @@ unspecified positions in the list using a ‘_’]

-6.3.3. Attaching Names

+6.3.3. Attaching Names

It is possible to just modify the display characteristics of a field without changing the semantic meaning. The need for this is rare, but diff --git a/GhidraDocs/languages/index.html b/GhidraDocs/languages/index.html index 44fcfd96ff..8eb4e522b4 100644 --- a/GhidraDocs/languages/index.html +++ b/GhidraDocs/languages/index.html @@ -9,7 +9,7 @@

-Ghidra Language Specification

+Ghidra Language Specification