42 #ifndef __ARCH_ARM_INSTS_STATICINST_HH__ 43 #define __ARCH_ARM_INSTS_STATICINST_HH__ 66 uint32_t
type, uint32_t cfval)
const;
68 uint32_t
type, uint32_t cfval)
const;
71 uint32_t
type, uint32_t cfval)
const;
73 uint32_t
type, uint32_t cfval)
const;
78 uint64_t shiftAmt, uint8_t
width)
const;
82 saturateOp(int32_t &res, int64_t op1, int64_t op2,
bool sub=
false)
84 int64_t midRes = sub ? (op1 - op2) : (op1 + op2);
87 res = (
LL(1) << (
width - 1)) - 1;
101 if (op >= (
LL(1) << width)) {
104 }
else if (op < -(
LL(1) << width)) {
115 uSaturateOp(uint32_t &res, int64_t op1, int64_t op2,
bool sub=
false)
117 int64_t midRes = sub ? (op1 - op2) : (op1 + op2);
118 if (midRes >= (
LL(1) <<
width)) {
121 }
else if (midRes < 0) {
133 if (op >= (
LL(1) << width)) {
160 uint8_t opWidth = 0)
const;
163 bool isSveVecReg =
false)
const;
168 const std::string &suffix =
"",
169 bool withPred =
true,
170 bool withCond64 =
false,
175 bool noImplicit=
false)
const;
177 const std::string &prefix,
const Addr addr,
178 const std::string &suffix)
const;
180 bool immShift, uint32_t shiftAmt,
184 int64_t shiftAmt)
const;
188 void printDataInst(std::ostream &os,
bool withImm,
bool immShift,
bool s,
202 static inline uint32_t
206 bool privileged = (cpsr.mode !=
MODE_USER);
211 uint32_t bitMask = 0;
213 if (
bits(byteMask, 3)) {
214 unsigned lowIdx = affectState ? 24 : 27;
215 bitMask = bitMask |
mask(31, lowIdx);
217 if (
bits(byteMask, 2)) {
218 bitMask = bitMask |
mask(19, 16);
220 if (
bits(byteMask, 1)) {
221 unsigned highIdx = affectState ? 15 : 9;
222 unsigned lowIdx = (privileged && (isSecure || scr.aw || haveVirt))
224 bitMask = bitMask |
mask(highIdx, lowIdx);
226 if (
bits(byteMask, 0)) {
229 if ( (!nmfi || !((val >> 6) & 0x1)) &&
230 (isSecure || scr.fw || haveVirt) ) {
237 bool validModeChange =
true;
242 if (!isSecure && newMode ==
MODE_MON)
243 validModeChange =
false;
244 if (!isSecure && newMode ==
MODE_FIQ && nsacr.rfr ==
'1')
245 validModeChange =
false;
248 if (scr.ns ==
'0' && newMode ==
MODE_HYP)
249 validModeChange =
false;
253 validModeChange =
false;
257 validModeChange =
false;
259 if (!opModeIs64(oldMode) && opModeIs64(newMode))
260 validModeChange =
false;
264 if (validModeChange) {
265 bitMask = bitMask |
mask(5);
267 warn_once(
"Illegal change to CPSR mode attempted\n");
270 warn_once(
"Ignoring write of bad mode to CPSR.\n");
274 bitMask = bitMask | (1 << 5);
277 return ((uint32_t)cpsr & ~bitMask) | (val & bitMask);
280 static inline uint32_t
282 uint8_t byteMask,
bool affectState)
284 uint32_t bitMask = 0;
286 if (
bits(byteMask, 3))
287 bitMask = bitMask |
mask(31, 24);
288 if (
bits(byteMask, 2))
289 bitMask = bitMask |
mask(19, 16);
290 if (
bits(byteMask, 1))
291 bitMask = bitMask |
mask(15, 8);
292 if (
bits(byteMask, 0))
293 bitMask = bitMask |
mask(7, 0);
295 return ((spsr & ~bitMask) | (val & bitMask));
323 template<
class T,
class E>
327 const unsigned count =
sizeof(T) /
sizeof(
E);
332 conv.tVal =
htole(val);
334 for (
unsigned i = 0;
i <
count;
i++) {
335 conv.eVals[
i] =
letobe(conv.eVals[
i]);
338 for (
unsigned i = 0;
i <
count;
i++) {
339 conv.eVals[
i] = conv.eVals[
i];
342 return letoh(conv.tVal);
367 return std::make_shared<UndefinedInstruction>(
machInst,
false,
412 CPSR cpsr, CPACR cpacr)
const;
421 CPSR cpsr, CPACR cpacr,
422 NSACR nsacr, FPEXC fpexc,
423 bool fpexc_check,
bool advsimd)
const;
561 #endif //__ARCH_ARM_INSTS_STATICINST_HH__ int32_t shift_rm_imm(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
CPSR getPSTATEFromPSR(ThreadContext *tc, CPSR cpsr, CPSR spsr) const
Get the new PSTATE from a SPSR register in preparation for an exception return.
void advancePC(PCState &pcState) const override
void printMnemonic(std::ostream &os, const std::string &suffix="", bool withPred=true, bool withCond64=false, ConditionCode cond64=COND_UC) const
static T cSwap(T val, bool big)
Fault checkSveTrap(ThreadContext *tc, CPSR cpsr) const
Check an SVE access against CPTR_EL2 and CPTR_EL3.
bool haveSecurity() const
Returns true if this system implements the Security Extensions.
#define LL(N)
int64_t constant
Fault checkForWFxTrap32(ThreadContext *tc, ExceptionLevel tgtEl, bool isWfe) const
Check if WFE/WFI instruction execution in aarch32 should be trapped.
ArmStaticInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
void printExtendOperand(bool firstOperand, std::ostream &os, IntRegIndex rm, ArmExtendType type, int64_t shiftAmt) const
Fault checkSveEnabled(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check an SVE access against CPACR_EL1, CPTR_EL2, and CPTR_EL3.
static T cSwap(T val, bool big)
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 bool saturateOp(int32_t &res, int64_t op1, int64_t op2, bool sub=false)
const char * mnemonic
Base mnemonic (e.g., "add").
virtual PCState pcState() const =0
bool shift_carry_imm(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
virtual void annotateFault(ArmFault *fault)
Fault undefinedFault64(ThreadContext *tc, ExceptionLevel el) const
UNDEFINED behaviour in AArch64.
static uint32_t cpsrWriteByInstr(CPSR cpsr, uint32_t val, SCR scr, NSACR nsacr, uint8_t byteMask, bool affectState, bool nmfi, ThreadContext *tc)
static Addr readPC(ExecContext *xc)
bool isWFxTrapping(ThreadContext *tc, ExceptionLevel targetEL, bool isWfe) const
ThreadContext is the external interface to all thread state for anything outside of the CPU...
static unsigned getCurSveVecLenInBits(ThreadContext *tc)
Fault checkFPAdvSIMDEnabled64(ThreadContext *tc, CPSR cpsr, CPACR cpacr) const
Check an Advaned SIMD access against CPACR_EL1, CPTR_EL2, and CPTR_EL3.
Fault undefinedFault32(ThreadContext *tc, ExceptionLevel el) const
UNDEFINED behaviour in AArch32.
void printVecPredReg(std::ostream &os, RegIndex reg_idx) const
const ExtMachInst machInst
The binary machine instruction.
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Fault checkForWFxTrap64(ThreadContext *tc, ExceptionLevel tgtEl, bool isWfe) const
Check if WFE/WFI instruction execution in aarch64 should be trapped.
Fault sveAccessTrap(ExceptionLevel el) const
Trap an access to SVE registers due to access control bits.
static void setIWNextPC(ExecContext *xc, Addr val)
void printCondition(std::ostream &os, unsigned code, bool noImplicit=false) const
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)...
int64_t shiftReg64(uint64_t base, uint64_t shiftAmt, ArmShiftType type, uint8_t width) const
Fault softwareBreakpoint32(ExecContext *xc, uint16_t imm) const
Trigger a Software Breakpoint.
void printShiftOperand(std::ostream &os, IntRegIndex rm, bool immShift, uint32_t shiftAmt, IntRegIndex rs, ArmShiftType type) const
static bool uSaturateOp(uint32_t &res, int64_t op1, int64_t op2, bool sub=false)
bool haveVirtualization() const
Returns true if this system implements the virtualization Extensions.
static void setNextPC(ExecContext *xc, Addr val)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Fault checkSETENDEnabled(ThreadContext *tc, CPSR cpsr) const
Check if SETEND instruction execution in aarch32 should be trapped.
static uint32_t spsrWriteByInstr(uint32_t spsr, uint32_t val, uint8_t byteMask, bool affectState)
int64_t extendReg64(uint64_t base, ArmExtendType type, uint64_t shiftAmt, uint8_t width) const
void printMiscReg(std::ostream &os, RegIndex reg_idx) const
static bool satInt(int32_t &res, int64_t op, int width)
uint8_t getIntWidth() const
bool shift_carry_rs(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
static void setAIWNextPC(ExecContext *xc, Addr val)
int32_t shift_rm_rs(uint32_t base, uint32_t shamt, uint32_t type, uint32_t cfval) const
GenericISA::SimplePCState< MachInst > PCState
void printPFflags(std::ostream &os, int flag) const
Bitfield< 23, 20 > advsimd
static unsigned getCurSveVecLenInQWords(ThreadContext *tc)
Base, ISA-independent static instruction class.
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Fault disabledFault() const
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.
void printFloatReg(std::ostream &os, RegIndex reg_idx) const
Fault checkFPAdvSIMDTrap64(ThreadContext *tc, CPSR cpsr) const
Check an Advaned SIMD access against CPTR_EL2 and CPTR_EL3.
bool inSecureState(ThreadContext *tc)
T bits(T val, int first, int 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.
void printMemSymbol(std::ostream &os, const SymbolTable *symtab, const std::string &prefix, const Addr addr, const std::string &suffix) const
Fault trapWFx(ThreadContext *tc, CPSR cpsr, SCR scr, bool isWfe) const
WFE/WFI trapping helper function.
std::shared_ptr< FaultBase > Fault
static unsigned getCurSveVecLen(ThreadContext *tc)
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...
ssize_t instSize() const
Returns the byte size of current instruction.
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
void printTarget(std::ostream &os, Addr target, const SymbolTable *symtab) const
void printDataInst(std::ostream &os, bool withImm) const
MachInst encoding() const
Returns the real encoding of the instruction: the machInst field is in fact always 64 bit wide and co...
Fault advSIMDFPAccessTrap64(ExceptionLevel el) const
Trap an access to Advanced SIMD or FP registers due to access control bits.
static bool uSatInt(int32_t &res, int64_t op, int width)