41#ifndef __ARCH_ARM_INSTS_STATICINST_HH__
42#define __ARCH_ARM_INSTS_STATICINST_HH__
72 uint32_t
type, uint32_t cfval)
const;
74 uint32_t
type, uint32_t cfval)
const;
77 uint32_t
type, uint32_t cfval)
const;
79 uint32_t
type, uint32_t cfval)
const;
84 uint64_t shiftAmt, uint8_t
width)
const;
88 saturateOp(int32_t &res, int64_t op1, int64_t op2,
bool sub=
false)
90 int64_t midRes = sub ? (op1 - op2) : (op1 + op2);
93 res = (1LL << (
width - 1)) - 1;
95 res = -(1LL << (
width - 1));
108 res = (1LL <<
width) - 1;
110 }
else if (
op < -(1LL <<
width)) {
111 res = -(1LL <<
width);
121 uSaturateOp(uint32_t &res, int64_t op1, int64_t op2,
bool sub=
false)
123 int64_t midRes = sub ? (op1 - op2) : (op1 + op2);
124 if (midRes >= (1LL <<
width)) {
125 res = (1LL <<
width) - 1;
127 }
else if (midRes < 0) {
140 res = (1LL <<
width) - 1;
168 uint8_t opWidth = 0)
const;
171 bool isSveVecReg =
false)
const;
176 const std::string &suffix =
"",
177 bool withPred =
true,
178 bool withCond64 =
false,
183 bool noImplicit=
false)
const;
185 const std::string &prefix,
const Addr addr,
186 const std::string &suffix)
const;
188 bool immShift, uint32_t shiftAmt,
192 int64_t shiftAmt)
const;
217 std::unique_ptr<PCStateBase>
223 return std::unique_ptr<PCStateBase>{ret_pc};
236 static inline uint32_t
240 bool privileged = (cpsr.mode !=
MODE_USER);
244 uint32_t bitMask = 0;
246 if (affectState && byteMask==0xF){
249 if (
bits(byteMask, 3)) {
250 unsigned lowIdx = affectState ? 24 : 27;
251 bitMask = bitMask |
mask(31, lowIdx);
253 if (
bits(byteMask, 2)) {
254 bitMask = bitMask |
mask(19, 16);
256 if (
bits(byteMask, 1)) {
257 unsigned highIdx = affectState ? 15 : 9;
258 unsigned lowIdx = (privileged && (
isSecure || scr.aw || haveVirt))
260 bitMask = bitMask |
mask(highIdx, lowIdx);
262 if (
bits(byteMask, 0)) {
265 if ( (!
nmfi || !((
val >> 6) & 0x1)) &&
266 (
isSecure || scr.fw || haveVirt) ) {
273 bool validModeChange =
true;
279 validModeChange =
false;
281 validModeChange =
false;
284 if (scr.ns == 0 && newMode ==
MODE_HYP)
285 validModeChange =
false;
289 validModeChange =
false;
293 validModeChange =
false;
295 if (!opModeIs64(oldMode) && opModeIs64(newMode))
296 validModeChange =
false;
300 if (validModeChange) {
301 bitMask = bitMask |
mask(5);
303 warn_once(
"Illegal change to CPSR mode attempted\n");
306 warn_once(
"Ignoring write of bad mode to CPSR.\n");
310 bitMask = bitMask | (1 << 5);
313 return ((uint32_t)cpsr & ~bitMask) | (
val & bitMask);
316 static inline uint32_t
318 uint8_t byteMask,
bool affectState)
320 uint32_t bitMask = 0;
322 if (
bits(byteMask, 3))
323 bitMask = bitMask |
mask(31, 24);
324 if (
bits(byteMask, 2))
325 bitMask = bitMask |
mask(19, 16);
326 if (
bits(byteMask, 1))
327 bitMask = bitMask |
mask(15, 8);
328 if (
bits(byteMask, 0))
329 bitMask = bitMask |
mask(7, 0);
331 return ((spsr & ~bitMask) | (
val & bitMask));
359 template<
class T,
class E>
363 const unsigned count =
sizeof(T) /
sizeof(
E);
371 for (
unsigned i = 0;
i <
count;
i++) {
372 conv.eVals[
i] =
letobe(conv.eVals[
i]);
375 for (
unsigned i = 0;
i <
count;
i++) {
376 conv.eVals[
i] = conv.eVals[
i];
379 return letoh(conv.tVal);
444 CPSR cpsr, CPACR cpacr)
const;
453 CPSR cpsr, CPACR cpacr,
454 NSACR nsacr, FPEXC fpexc,
455 bool fpexc_check,
bool advsimd)
const;
633 return std::make_shared<UndefinedInstruction>(
void printMiscReg(std::ostream &os, RegIndex reg_idx) const
int64_t extendReg64(uint64_t base, ArmExtendType type, uint64_t shiftAmt, uint8_t width) const
Fault checkSveSmeEnabled(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check an SVE access against CPACR_EL1, CPTR_EL2, and CPTR_EL3, but choosing the correct set of traps ...
void printExtendOperand(bool firstOperand, std::ostream &os, RegIndex rm, ArmExtendType type, int64_t shiftAmt) const
Fault softwareBreakpoint32(ExecContext *xc, uint16_t imm) const
Trigger a Software Breakpoint.
bool shift_carry_imm(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
void advancePC(ThreadContext *tc) const override
ArmStaticInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
void printCondition(std::ostream &os, unsigned code, bool noImplicit=false) const
void printMnemonic(std::ostream &os, const std::string &suffix="", bool withPred=true, bool withCond64=false, ConditionCode cond64=COND_UC) const
void printCCReg(std::ostream &os, RegIndex reg_idx) const
bool generalExceptionsToAArch64(ThreadContext *tc, ExceptionLevel pstateEL) const
Return true if exceptions normally routed to EL1 are being handled at an Exception level using AArch6...
Fault checkSveEnabled(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check an SVE access against CPACR_EL1, CPTR_EL2, and CPTR_EL3.
static unsigned getCurSveVecLen(ThreadContext *tc)
void printMemSymbol(std::ostream &os, const loader::SymbolTable *symtab, const std::string &prefix, const Addr addr, const std::string &suffix) const
Fault undefinedFault32(ThreadContext *tc, ExceptionLevel el) const
UNDEFINED behaviour in AArch32.
uint8_t getIntWidth() const
ssize_t instSize() const
Returns the byte size of current instruction.
static void setIWNextPC(ExecContext *xc, Addr val)
static unsigned getCurSmeVecLenInBits(ThreadContext *tc)
Fault checkForWFxTrap64(ThreadContext *tc, ExceptionLevel tgtEl, bool isWfe) const
Check if WFE/WFI instruction execution in aarch64 should be trapped.
static void activateBreakpoint(ThreadContext *tc)
Fault undefined(bool disabled=false) const
static unsigned getCurSveVecLenInBits(ThreadContext *tc)
bool isWFxTrapping(ThreadContext *tc, ExceptionLevel targetEL, bool isWfe) const
Fault disabledFault() const
Fault smeAccessTrap(ExceptionLevel el, uint32_t iss=0) const
Trap an access to SME registers due to access control bits.
int64_t shiftReg64(uint64_t base, uint64_t shiftAmt, ArmShiftType type, uint8_t width) const
static bool uSaturateOp(uint32_t &res, int64_t op1, int64_t op2, bool sub=false)
Fault checkAdvSIMDOrFPEnabled32(ThreadContext *tc, CPSR cpsr, CPACR cpacr, NSACR nsacr, FPEXC fpexc, bool fpexc_check, bool advsimd) const
Check if a VFP/SIMD access from aarch32 should be allowed.
int32_t shift_rm_rs(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
void printDataInst(std::ostream &os, bool withImm) const
size_t asBytes(void *buf, size_t max_size) override
Instruction classes can override this function to return a a representation of themselves as a blob o...
static void setNextPC(ExecContext *xc, Addr val)
void advancePC(PCStateBase &pcState) const override
CPSR getPSTATEFromPSR(ThreadContext *tc, CPSR cpsr, CPSR spsr) const
Get the new PSTATE from a SPSR register in preparation for an exception return.
void printPFflags(std::ostream &os, int flag) const
Fault trapWFx(ThreadContext *tc, CPSR cpsr, SCR scr, bool isWfe) const
WFE/WFI trapping helper function.
Fault checkSmeEnabled(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check if SME is enabled by checking the SME and FP bits of CPACR_EL1, CPTR_EL2, and CPTR_EL3.
Fault undefinedFault64(ThreadContext *tc, ExceptionLevel el) const
UNDEFINED behaviour in AArch64.
void printVecReg(std::ostream &os, RegIndex reg_idx, bool isSveVecReg=false) const
void printIntReg(std::ostream &os, RegIndex reg_idx, uint8_t opWidth=0) const
Print a register name for disassembly given the unique dependence tag number (FP or int).
static uint32_t cpsrWriteByInstr(CPSR cpsr, uint32_t val, SCR scr, NSACR nsacr, uint8_t byteMask, bool affectState, bool nmfi, ThreadContext *tc)
void printShiftOperand(std::ostream &os, RegIndex rm, bool immShift, uint32_t shiftAmt, RegIndex rs, ArmShiftType type) const
uint64_t getEMI() const override
Fault advSIMDFPAccessTrap64(ExceptionLevel el) const
Trap an access to Advanced SIMD or FP registers due to access control bits.
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
std::unique_ptr< PCStateBase > buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const override
static void setAIWNextPC(ExecContext *xc, Addr val)
static unsigned getCurSmeVecLenInQWords(ThreadContext *tc)
static Addr readPC(ExecContext *xc)
virtual void annotateFault(ArmFault *fault)
Fault checkSmeAccess(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check an SME access against CPACR_EL1, CPTR_EL2, and CPTR_EL3.
static bool saturateOp(int32_t &res, int64_t op1, int64_t op2, bool sub=false)
static bool uSatInt(int32_t &res, int64_t op, int width)
void printFloatReg(std::ostream &os, RegIndex reg_idx) const
static bool satInt(int32_t &res, int64_t op, int width)
Fault checkFPAdvSIMDTrap64(ThreadContext *tc, CPSR cpsr) const
Check an Advaned SIMD access against CPTR_EL2 and CPTR_EL3.
MachInst encoding() const
Returns the real encoding of the instruction: the machInst field is in fact always 64 bit wide and co...
bool shift_carry_rs(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
static unsigned getCurSveVecLenInQWords(ThreadContext *tc)
Fault checkForWFxTrap32(ThreadContext *tc, ExceptionLevel tgtEl, bool isWfe) const
Check if WFE/WFI instruction execution in aarch32 should be trapped.
static T cSwap(T val, bool big)
void printVecPredReg(std::ostream &os, RegIndex reg_idx) const
Fault sveAccessTrap(ExceptionLevel el) const
Trap an access to SVE registers due to access control bits.
static uint32_t spsrWriteByInstr(uint32_t spsr, uint32_t val, uint8_t byteMask, bool affectState)
Fault checkFPAdvSIMDEnabled64(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check an Advaned SIMD access against CPACR_EL1, CPTR_EL2, and CPTR_EL3.
int32_t shift_rm_imm(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
static T cSwap(T val, bool big)
void printTarget(std::ostream &os, Addr target, const loader::SymbolTable *symtab) const
Fault checkSETENDEnabled(ThreadContext *tc, CPSR cpsr) const
Check if SETEND instruction execution in aarch32 should be trapped.
static unsigned getCurSmeVecLen(ThreadContext *tc)
SelfDebug * getSelfDebug() const
static bool haveEL(ThreadContext *tc, ArmISA::ExceptionLevel el)
Return true if the system implements a specific exception level.
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
virtual const PCStateBase & pcState() const =0
virtual PCStateBase * clone() const =0
Base, ISA-independent static instruction class.
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
const char * mnemonic
Base mnemonic (e.g., "add").
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
bool badMode(ThreadContext *tc, OperatingMode mode)
badMode is checking if the execution mode provided as an argument is valid and implemented.
bool isSecure(ThreadContext *tc)
Bitfield< 23, 20 > advsimd
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::shared_ptr< FaultBase > Fault
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.