decompiler  1.0.0
Classes | Functions
address.hh File Reference

Classes for specifying addresses and other low-level constants. More...

#include "space.hh"

Classes

class  ghidra::Address
 A low-level machine address for labelling bytes and data. More...
 
class  ghidra::SeqNum
 A class for uniquely labelling and comparing PcodeOps. More...
 
class  ghidra::Range
 A contiguous range of bytes in some address space. More...
 
class  ghidra::RangeProperties
 A partially parsed description of a Range. More...
 
class  ghidra::RangeList
 A disjoint set of Ranges, possibly across multiple address spaces. More...
 

Functions

uintb ghidra::calc_mask (int4 size)
 Calculate a mask for a given byte size. More...
 
uintb ghidra::pcode_right (uintb val, int4 sa)
 
uintb ghidra::pcode_left (uintb val, int4 sa)
 
uintb ghidra::minimalmask (uintb val)
 Calculate smallest mask that covers the given value. More...
 
intb ghidra::sign_extend (intb val, int4 bit)
 Sign extend above given bit. More...
 
intb ghidra::zero_extend (intb val, int4 bit)
 Clear all bits above given bit. More...
 
bool ghidra::signbit_negative (uintb val, int4 size)
 Return true if the sign-bit is set. More...
 
uintb ghidra::uintb_negate (uintb in, int4 size)
 Negate the sized value. More...
 
uintb ghidra::sign_extend (uintb in, int4 sizein, int4 sizeout)
 Sign-extend a value between two byte sizes. More...
 
void ghidra::byte_swap (intb &val, int4 size)
 Swap bytes in the given value. More...
 
uintb ghidra::byte_swap (uintb val, int4 size)
 Return the given value with bytes swapped. More...
 
int4 ghidra::leastsigbit_set (uintb val)
 Return index of least significant bit set in given value. More...
 
int4 ghidra::mostsigbit_set (uintb val)
 Return index of most significant bit set in given value. More...
 
int4 ghidra::popcount (uintb val)
 Return the number of one bits in the given value. More...
 
int4 ghidra::count_leading_zeros (uintb val)
 Return the number of leading zero bits in the given value. More...
 
uintb ghidra::coveringmask (uintb val)
 Return a mask that covers the given value. More...
 
int4 ghidra::bit_transitions (uintb val, int4 sz)
 Calculate the number of bit transitions in the sized value. More...
 
void ghidra::mult64to128 (uint8 *res, uint8 x, uint8 y)
 Multiply 2 unsigned 64-bit values, producing a 128-bit value. More...
 
void ghidra::unsignedSubtract128 (uint8 *a, uint8 *b)
 Subtract (in-place) a 128-bit value from a base 128-value. More...
 
int4 ghidra::unsignedCompare128 (uint8 *a, uint8 *b)
 Compare two unsigned 128-bit values. More...
 
int4 ghidra::power2Divide (int4 n, uint8 divisor, uint8 &q, uint8 &r)
 Unsigned division of a power of 2 (upto 2^127) by a 64-bit divisor. More...
 

Detailed Description

Classes for specifying addresses and other low-level constants.

All addresses are absolute and there are are no registers in CPUI. However, all addresses are prefixed with an "immutable" pointer, which can specify a separate RAM space, a register space, an i/o space etc. Thus a translation from a real machine language will typically simulate registers by placing them in their own space, separate from RAM. Indirection (i.e. pointers) must be simulated through the LOAD and STORE ops.

Function Documentation

◆ bit_transitions()

int4 ghidra::bit_transitions ( uintb  val,
int4  sz 
)

Calculate the number of bit transitions in the sized value.

Treat val as a constant of size sz. Scanning across the bits of val return the number of transitions (from 0->1 or 1->0) If there are 2 or less transitions, this is an indication of a bit flag or a mask

Parameters
valis the given value
szis the size to treat the value as
Returns
the number of transitions

◆ byte_swap() [1/2]

void ghidra::byte_swap ( intb &  val,
int4  size 
)

Swap bytes in the given value.

Swap the least significant size bytes in val

Parameters
valis a reference to the value to swap
sizeis the number of bytes to swap

◆ byte_swap() [2/2]

uintb ghidra::byte_swap ( uintb  val,
int4  size 
)

Return the given value with bytes swapped.

Swap the least significant size bytes in val

Parameters
valis the value to swap
sizeis the number of bytes to swap
Returns
the swapped value

◆ calc_mask()

uintb ghidra::calc_mask ( int4  size)
inline

Calculate a mask for a given byte size.

Parameters
sizeis the desired size in bytes
Returns
a value appropriate for masking off the first size bytes

References ghidra::calc_mask().

Referenced by ghidra::AddTreeState::AddTreeState(), ghidra::ActionStackPtrFlow::analyzeExtraPop(), ghidra::RuleCollectTerms::applyOp(), ghidra::RuleOrMask::applyOp(), ghidra::RuleNegateIdentity::applyOp(), ghidra::RuleShiftBitops::applyOp(), ghidra::RuleRightShiftAnd::applyOp(), ghidra::RulePullsubMulti::applyOp(), ghidra::RulePullsubIndirect::applyOp(), ghidra::RuleHighOrderAnd::applyOp(), ghidra::RuleAndDistribute::applyOp(), ghidra::RuleAndCommute::applyOp(), ghidra::RuleAndPiece::applyOp(), ghidra::RuleAndZext::applyOp(), ghidra::RuleAndCompare::applyOp(), ghidra::RuleDoubleShift::applyOp(), ghidra::RuleShiftCompare::applyOp(), ghidra::RuleBoolZext::applyOp(), ghidra::RuleSborrow::applyOp(), ghidra::RuleSignShift::applyOp(), ghidra::RuleTestSign::applyOp(), ghidra::RuleTransformCpool::applyOp(), ghidra::Rule2Comp2Mult::applyOp(), ghidra::RuleCarryElim::applyOp(), ghidra::RuleSub2Add::applyOp(), ghidra::RuleSubCommute::applyOp(), ghidra::RuleConcatCommute::applyOp(), ghidra::RuleShiftAnd::applyOp(), ghidra::RuleSubZext::applyOp(), ghidra::RuleSubCancel::applyOp(), ghidra::RuleHumptyOr::applyOp(), ghidra::RuleLess2Zero::applyOp(), ghidra::RuleLessEqual2Zero::applyOp(), ghidra::RuleSLess2Zero::applyOp(), ghidra::RuleEqual2Zero::applyOp(), ghidra::RuleEqual2Constant::applyOp(), ghidra::RuleMultNegOne::applyOp(), ghidra::RuleAddUnsigned::applyOp(), ghidra::RuleDivTermAdd2::applyOp(), ghidra::RuleSignDiv2::applyOp(), ghidra::RuleDivChain::applyOp(), ghidra::RuleSignForm2::applyOp(), ghidra::RuleSignNearMult::applyOp(), ghidra::RuleModOpt::applyOp(), ghidra::RuleSignMod2nOpt::applyOp(), ghidra::RuleSignMod2Opt::applyOp(), ghidra::RuleSignMod2nOpt2::applyOp(), ghidra::RuleSubvarAnd::applyOp(), ghidra::RuleSubvarSubpiece::applyOp(), ghidra::RuleSubvarCompZero::applyOp(), ghidra::RuleSubvarZext::applyOp(), ghidra::RuleSubvarSext::applyOp(), ghidra::RuleFuncPtrEncoding::applyOp(), ghidra::RuleThreeWayCompare::applyOp(), ghidra::SplitDatatype::buildInConstants(), ghidra::calc_mask(), ghidra::Funcdata::calcNZMask(), ghidra::AddrSpace::calcScaleMask(), ghidra::ActionStackPtrFlow::checkClog(), ghidra::ValueSetSolver::checkRelativeConstant(), ghidra::RuleSignMod2nOpt2::checkSignExtForm(), ghidra::CircleRange::CircleRange(), ghidra::Funcdata::collapseIntMultMult(), ghidra::RangeList::decode(), ghidra::TypeEnum::decode(), ghidra::RuleThreeWayCompare::detectThreeWay(), ghidra::Funcdata::distributeIntMultAdd(), ghidra::TypePointerRel::downChain(), ghidra::OpBehaviorIntAdd::evaluateBinary(), ghidra::OpBehaviorIntSub::evaluateBinary(), ghidra::OpBehaviorIntCarry::evaluateBinary(), ghidra::OpBehaviorIntLeft::evaluateBinary(), ghidra::OpBehaviorIntRight::evaluateBinary(), ghidra::OpBehaviorIntSright::evaluateBinary(), ghidra::OpBehaviorIntMult::evaluateBinary(), ghidra::OpBehaviorSubpiece::evaluateBinary(), ghidra::TypePointerRel::evaluateThruParent(), ghidra::Varnode::findSubpieceShadow(), ghidra::JumpTable::foldInNormalization(), ghidra::ActionDeadCode::gatherConsumedReturn(), ghidra::AliasChecker::gatherOffset(), ghidra::SplitDatatype::generateConstants(), ghidra::SleighBuilder::generateLocation(), ghidra::SleighBuilder::generatePointer(), ghidra::RuleSLess2Zero::getHiBit(), ghidra::EmulatePcodeOp::getLoadImageValue(), ghidra::EmulateSnippet::getLoadImageValue(), ghidra::TypeEnum::getMatches(), ghidra::JumpBasic::getMaxValue(), ghidra::PcodeOp::getNZMaskLocal(), ghidra::ContextDatabase::getTrackedValue(), ghidra::MemoryBank::getValue(), ghidra::EquateSymbol::isValueClose(), ghidra::ActionDeadCode::markConsumedParameters(), ghidra::TransformManager::newConstant(), ghidra::TransformManager::newSplit(), ghidra::PrintC::opPtrsub(), ghidra::FloatFormat::opTrunc(), ghidra::Funcdata::opUndoPtradd(), ghidra::TypeOpIntAdd::propagateAddPointer(), ghidra::ActionDeadCode::propagateConsumed(), ghidra::CircleRange::pullBack(), ghidra::CircleRange::pullBackBinary(), ghidra::CircleRange::pullBackUnary(), ghidra::PrintC::push_integer(), ghidra::ActionDeadCode::pushConsumed(), ghidra::PrintC::pushEquate(), ghidra::CircleRange::pushForwardBinary(), ghidra::CircleRange::pushForwardUnary(), ghidra::OpBehaviorIntAdd::recoverInputBinary(), ghidra::OpBehaviorIntSub::recoverInputBinary(), ghidra::OpBehaviorIntLeft::recoverInputBinary(), ghidra::OpBehaviorIntZext::recoverInputUnary(), ghidra::OpBehaviorIntSext::recoverInputUnary(), ghidra::Funcdata::replaceLessequal(), ghidra::SegmentedResolver::resolve(), ghidra::PcodeCacher::resolveRelatives(), ghidra::TypeFactory::setEnumValues(), ghidra::CircleRange::setFull(), ghidra::CircleRange::setNZMask(), ghidra::CircleRange::setRange(), ghidra::SubvariableFlow::setReplacement(), ghidra::MemoryBank::setValue(), ghidra::SubvariableFlow::traceBackward(), ghidra::SubvariableFlow::traceBackwardSext(), ghidra::SubvariableFlow::traceForward(), ghidra::SubvariableFlow::traceForwardSext(), ghidra::ActionLikelyTrash::traceTrash(), ghidra::Funcdata::transferVarnodeProperties(), and ghidra::zero_extend().

◆ count_leading_zeros()

int4 ghidra::count_leading_zeros ( uintb  val)

Return the number of leading zero bits in the given value.

Count the number of more significant zero bits before the most significant one bit in the representation of the given value;

Parameters
valis the given value
Returns
the number of zero bits

◆ coveringmask()

uintb ghidra::coveringmask ( uintb  val)

Return a mask that covers the given value.

Return smallest number of form 2^n-1, bigger or equal to the given value

Parameters
valis the given value
Returns
the mask

◆ leastsigbit_set()

int4 ghidra::leastsigbit_set ( uintb  val)

Return index of least significant bit set in given value.

The least significant bit is index 0.

Parameters
valis the given value
Returns
the index of the least significant set bit, or -1 if none are set

◆ minimalmask()

uintb ghidra::minimalmask ( uintb  val)
inline

Calculate smallest mask that covers the given value.

Calculcate a mask that covers either the least significant byte, uint2, uint4, or uint8, whatever is smallest.

Parameters
valis the given value
Returns
the minimal mask

References ghidra::minimalmask().

Referenced by ghidra::JumpTable::foldInNormalization(), ghidra::ActionDeadCode::gatherConsumedReturn(), ghidra::ActionDeadCode::markConsumedParameters(), and ghidra::minimalmask().

◆ mostsigbit_set()

int4 ghidra::mostsigbit_set ( uintb  val)

Return index of most significant bit set in given value.

The least significant bit is index 0.

Parameters
valis the given value
Returns
the index of the most significant set bit, or -1 if none are set

◆ mult64to128()

void ghidra::mult64to128 ( uint8 *  res,
uint8  x,
uint8  y 
)

Multiply 2 unsigned 64-bit values, producing a 128-bit value.

TODO: Remove once we import a full multiprecision library.

Parameters
respoints to the result array (2 uint8 pieces)
xis the first 64-bit value
yis the second 64-bit value

◆ pcode_left()

uintb ghidra::pcode_left ( uintb  val,
int4  sa 
)
inline

Perform a CPUI_INT_LEFT on the given val

Parameters
valis the value to shift
sais the number of bits to shift
Returns
the shifted value

References ghidra::pcode_left().

Referenced by ghidra::RuleShiftBitops::applyOp(), ghidra::PcodeOp::getNZMaskLocal(), and ghidra::pcode_left().

◆ pcode_right()

uintb ghidra::pcode_right ( uintb  val,
int4  sa 
)
inline

Perform a CPUI_INT_RIGHT on the given val

Parameters
valis the value to shift
sais the number of bits to shift
Returns
the shifted value

References ghidra::pcode_right().

Referenced by ghidra::RuleShiftBitops::applyOp(), ghidra::PcodeOp::getNZMaskLocal(), and ghidra::pcode_right().

◆ popcount()

int4 ghidra::popcount ( uintb  val)

Return the number of one bits in the given value.

Count the number (population) bits set.

Parameters
valis the given value
Returns
the number of one bits

◆ power2Divide()

int4 ghidra::power2Divide ( int4  n,
uint8  divisor,
uint8 &  q,
uint8 &  r 
)

Unsigned division of a power of 2 (upto 2^127) by a 64-bit divisor.

The result must be less than 2^64. The remainder is calculated.

Parameters
nis the power of 2 for the numerand
divisoris the 64-bit divisor
qis the passed back 64-bit quotient
ris the passed back 64-bit remainder
Returns
0 if successful, 1 if result is too big, 2 if divide by 0

◆ sign_extend() [1/2]

intb ghidra::sign_extend ( intb  val,
int4  bit 
)
inline

Sign extend above given bit.

Sign extend val starting at bit

Parameters
valis the value to be sign-extended
bitis the index of the bit to extend from (0=least significant bit)
Returns
the sign extended value

◆ sign_extend() [2/2]

uintb ghidra::sign_extend ( uintb  in,
int4  sizein,
int4  sizeout 
)

Sign-extend a value between two byte sizes.

Take the first sizein bytes of the given in and sign-extend this to sizeout bytes, keeping any more significant bytes zero

Parameters
inis the given value
sizeinis the size to treat that value as an input
sizeoutis the size to sign-extend the value to
Returns
the sign-extended value

◆ signbit_negative()

bool ghidra::signbit_negative ( uintb  val,
int4  size 
)

Return true if the sign-bit is set.

Treat the given val as a constant of size bytes

Parameters
valis the given value
sizeis the size in bytes
Returns
true if the constant (as sized) has its sign bit set

◆ uintb_negate()

uintb ghidra::uintb_negate ( uintb  in,
int4  size 
)

Negate the sized value.

Treat the given in as a constant of size bytes. Negate this constant keeping the upper bytes zero.

Parameters
inis the given value
sizeis the size in bytes
Returns
the negation of the sized constant

◆ unsignedCompare128()

int4 ghidra::unsignedCompare128 ( uint8 *  a,
uint8 *  b 
)

Compare two unsigned 128-bit values.

TODO: Remove once we import a full multiprecision library. Given a first and second value, return -1, 0, or 1 depending on whether the first value is less, equal, or greater than the second value.

Parameters
ais the first 128-bit value (as an array of 2 uint8 elements)
bis the second 128-bit value
Returns
the comparison code

◆ unsignedSubtract128()

void ghidra::unsignedSubtract128 ( uint8 *  a,
uint8 *  b 
)

Subtract (in-place) a 128-bit value from a base 128-value.

The base value is altered in place. TODO: Remove once we import a full multiprecision library.

Parameters
ais the base 128-bit value being subtracted from in-place
bis the other 128-bit value being subtracted

◆ zero_extend()

intb ghidra::zero_extend ( intb  val,
int4  bit 
)
inline

Clear all bits above given bit.

Zero extend val starting at bit

Parameters
valis the value to be zero extended
bitis the index of the bit to extend from (0=least significant bit)
Returns
the extended value

References ghidra::calc_mask(), and ghidra::zero_extend().

Referenced by ghidra::OpBehaviorIntSdiv::evaluateBinary(), ghidra::OpBehaviorIntSrem::evaluateBinary(), and ghidra::zero_extend().