ARM: Clean up use of TBit and JBit.
Rather tha constantly using ULL(1) << PcXBitShift define those directly. Additionally, add some helper functions to further clean up the code.
This commit is contained in:
parent
aef4a9904e
commit
b331b02669
9 changed files with 31 additions and 25 deletions
|
@ -140,7 +140,7 @@ ArmFault::invoke(ThreadContext *tc, StaticInstPtr inst)
|
||||||
}
|
}
|
||||||
|
|
||||||
Addr pc M5_VAR_USED = tc->readPC();
|
Addr pc M5_VAR_USED = tc->readPC();
|
||||||
Addr newPc = getVector(tc) | (sctlr.te ? (ULL(1) << PcTBitShift) : 0);
|
Addr newPc = getVector(tc) | (sctlr.te ? PcTBit : 0);
|
||||||
DPRINTF(Faults, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x\n",
|
DPRINTF(Faults, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x\n",
|
||||||
name(), cpsr, pc, tc->readIntReg(INTREG_LR), newPc);
|
name(), cpsr, pc, tc->readIntReg(INTREG_LR), newPc);
|
||||||
tc->setPC(newPc);
|
tc->setPC(newPc);
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#define __ARCH_ARM_INSTS_STATICINST_HH__
|
#define __ARCH_ARM_INSTS_STATICINST_HH__
|
||||||
|
|
||||||
#include "arch/arm/faults.hh"
|
#include "arch/arm/faults.hh"
|
||||||
|
#include "arch/arm/utility.hh"
|
||||||
#include "base/trace.hh"
|
#include "base/trace.hh"
|
||||||
#include "cpu/static_inst.hh"
|
#include "cpu/static_inst.hh"
|
||||||
|
|
||||||
|
@ -219,8 +220,7 @@ class ArmStaticInst : public StaticInst
|
||||||
readPC(XC *xc)
|
readPC(XC *xc)
|
||||||
{
|
{
|
||||||
Addr pc = xc->readPC();
|
Addr pc = xc->readPC();
|
||||||
Addr tBit = pc & (ULL(1) << PcTBitShift);
|
if (isThumb(pc))
|
||||||
if (tBit)
|
|
||||||
return pc + 4;
|
return pc + 4;
|
||||||
else
|
else
|
||||||
return pc + 8;
|
return pc + 8;
|
||||||
|
@ -232,7 +232,7 @@ class ArmStaticInst : public StaticInst
|
||||||
setNextPC(XC *xc, Addr val)
|
setNextPC(XC *xc, Addr val)
|
||||||
{
|
{
|
||||||
Addr npc = xc->readNextPC();
|
Addr npc = xc->readNextPC();
|
||||||
if (npc & (ULL(1) << PcTBitShift)) {
|
if (isThumb(npc)) {
|
||||||
val &= ~mask(1);
|
val &= ~mask(1);
|
||||||
} else {
|
} else {
|
||||||
val &= ~mask(2);
|
val &= ~mask(2);
|
||||||
|
@ -280,8 +280,8 @@ class ArmStaticInst : public StaticInst
|
||||||
setIWNextPC(XC *xc, Addr val)
|
setIWNextPC(XC *xc, Addr val)
|
||||||
{
|
{
|
||||||
Addr stateBits = xc->readPC() & PcModeMask;
|
Addr stateBits = xc->readPC() & PcModeMask;
|
||||||
Addr jBit = (ULL(1) << PcJBitShift);
|
Addr jBit = PcJBit;
|
||||||
Addr tBit = (ULL(1) << PcTBitShift);
|
Addr tBit = PcTBit;
|
||||||
bool thumbEE = (stateBits == (tBit | jBit));
|
bool thumbEE = (stateBits == (tBit | jBit));
|
||||||
|
|
||||||
Addr newPc = (val & ~PcModeMask);
|
Addr newPc = (val & ~PcModeMask);
|
||||||
|
@ -312,8 +312,8 @@ class ArmStaticInst : public StaticInst
|
||||||
setAIWNextPC(XC *xc, Addr val)
|
setAIWNextPC(XC *xc, Addr val)
|
||||||
{
|
{
|
||||||
Addr stateBits = xc->readPC() & PcModeMask;
|
Addr stateBits = xc->readPC() & PcModeMask;
|
||||||
Addr jBit = (ULL(1) << PcJBitShift);
|
Addr jBit = PcJBit;
|
||||||
Addr tBit = (ULL(1) << PcTBitShift);
|
Addr tBit = PcTBit;
|
||||||
if (!jBit && !tBit) {
|
if (!jBit && !tBit) {
|
||||||
setIWNextPC(xc, val);
|
setIWNextPC(xc, val);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -173,7 +173,7 @@ ISA::readMiscReg(int misc_reg, ThreadContext *tc)
|
||||||
cpsr.j = 1;
|
cpsr.j = 1;
|
||||||
else
|
else
|
||||||
cpsr.j = 0;
|
cpsr.j = 0;
|
||||||
if (pc & (ULL(1) << PcTBitShift))
|
if (isThumb(pc))
|
||||||
cpsr.t = 1;
|
cpsr.t = 1;
|
||||||
else
|
else
|
||||||
cpsr.t = 0;
|
cpsr.t = 0;
|
||||||
|
@ -241,9 +241,9 @@ ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
|
||||||
miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
|
miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
|
||||||
Addr npc = tc->readNextPC() & ~PcModeMask;
|
Addr npc = tc->readNextPC() & ~PcModeMask;
|
||||||
if (cpsr.j)
|
if (cpsr.j)
|
||||||
npc = npc | (ULL(1) << PcJBitShift);
|
npc = npc | PcJBit;
|
||||||
if (cpsr.t)
|
if (cpsr.t)
|
||||||
npc = npc | (ULL(1) << PcTBitShift);
|
npc = npc | PcTBit;
|
||||||
|
|
||||||
tc->setNextPC(npc);
|
tc->setNextPC(npc);
|
||||||
} else if (misc_reg >= MISCREG_CP15_UNIMP_START &&
|
} else if (misc_reg >= MISCREG_CP15_UNIMP_START &&
|
||||||
|
|
|
@ -51,8 +51,7 @@ let {{
|
||||||
'''
|
'''
|
||||||
if (link):
|
if (link):
|
||||||
bCode += '''
|
bCode += '''
|
||||||
Addr tBit = curPc & (ULL(1) << PcTBitShift);
|
if (!isThumb(curPc))
|
||||||
if (!tBit)
|
|
||||||
LR = curPc - 4;
|
LR = curPc - 4;
|
||||||
else
|
else
|
||||||
LR = curPc | 1;
|
LR = curPc | 1;
|
||||||
|
@ -67,10 +66,7 @@ let {{
|
||||||
|
|
||||||
# BX, BLX
|
# BX, BLX
|
||||||
blxCode = '''
|
blxCode = '''
|
||||||
Addr curPc = readPC(xc);
|
Addr curPc M5_VAR_USED = readPC(xc);
|
||||||
Addr tBit = curPc & (ULL(1) << PcTBitShift);
|
|
||||||
bool arm = !tBit;
|
|
||||||
arm = arm; // In case it's not used otherwise.
|
|
||||||
%(link)s
|
%(link)s
|
||||||
// Switch modes
|
// Switch modes
|
||||||
%(branch)s
|
%(branch)s
|
||||||
|
@ -86,7 +82,7 @@ let {{
|
||||||
Name += "Imm"
|
Name += "Imm"
|
||||||
# Since we're switching ISAs, the target ISA will be the opposite
|
# Since we're switching ISAs, the target ISA will be the opposite
|
||||||
# of the current ISA. !arm is whether the target is ARM.
|
# of the current ISA. !arm is whether the target is ARM.
|
||||||
newPC = '(!arm ? (roundDown(curPc, 4) + imm) : (curPc + imm))'
|
newPC = '(isThumb(curPc) ? (roundDown(curPc, 4) + imm) : (curPc + imm))'
|
||||||
base = "BranchImmCond"
|
base = "BranchImmCond"
|
||||||
declare = BranchImmCondDeclare
|
declare = BranchImmCondDeclare
|
||||||
constructor = BranchImmCondConstructor
|
constructor = BranchImmCondConstructor
|
||||||
|
@ -101,14 +97,14 @@ let {{
|
||||||
// The immediate version of the blx thumb instruction
|
// The immediate version of the blx thumb instruction
|
||||||
// is 32 bits wide, but "next pc" doesn't reflect that
|
// is 32 bits wide, but "next pc" doesn't reflect that
|
||||||
// so we don't want to substract 2 from it at this point
|
// so we don't want to substract 2 from it at this point
|
||||||
if (arm)
|
if (!isThumb(curPc))
|
||||||
LR = curPc - 4;
|
LR = curPc - 4;
|
||||||
else
|
else
|
||||||
LR = curPc | 1;
|
LR = curPc | 1;
|
||||||
'''
|
'''
|
||||||
elif link:
|
elif link:
|
||||||
linkStr = '''
|
linkStr = '''
|
||||||
if (arm)
|
if (!isThumb(curPc))
|
||||||
LR = curPc - 4;
|
LR = curPc - 4;
|
||||||
else
|
else
|
||||||
LR = (curPc - 2) | 1;
|
LR = (curPc - 2) | 1;
|
||||||
|
@ -119,7 +115,7 @@ let {{
|
||||||
if imm and link: #blx with imm
|
if imm and link: #blx with imm
|
||||||
branchStr = '''
|
branchStr = '''
|
||||||
Addr tempPc = ((%(newPC)s) & mask(32)) | (curPc & ~mask(32));
|
Addr tempPc = ((%(newPC)s) & mask(32)) | (curPc & ~mask(32));
|
||||||
FNPC = tempPc ^ (ULL(1) << PcTBitShift);
|
FNPC = tempPc ^ PcTBit;
|
||||||
'''
|
'''
|
||||||
else:
|
else:
|
||||||
branchStr = "IWNPC = %(newPC)s;"
|
branchStr = "IWNPC = %(newPC)s;"
|
||||||
|
|
|
@ -638,7 +638,7 @@ let {{
|
||||||
exec_output += PredOpExecute.subst(mcr15UserIop)
|
exec_output += PredOpExecute.subst(mcr15UserIop)
|
||||||
|
|
||||||
enterxCode = '''
|
enterxCode = '''
|
||||||
FNPC = NPC | (1ULL << PcJBitShift) | (1ULL << PcTBitShift);
|
FNPC = NPC | PcJBit | PcTBit;
|
||||||
'''
|
'''
|
||||||
enterxIop = InstObjParams("enterx", "Enterx", "PredOp",
|
enterxIop = InstObjParams("enterx", "Enterx", "PredOp",
|
||||||
{ "code": enterxCode,
|
{ "code": enterxCode,
|
||||||
|
@ -648,7 +648,7 @@ let {{
|
||||||
exec_output += PredOpExecute.subst(enterxIop)
|
exec_output += PredOpExecute.subst(enterxIop)
|
||||||
|
|
||||||
leavexCode = '''
|
leavexCode = '''
|
||||||
FNPC = (NPC & ~(1ULL << PcJBitShift)) | (1ULL << PcTBitShift);
|
FNPC = (NPC & ~PcJBit) | PcTBit;
|
||||||
'''
|
'''
|
||||||
leavexIop = InstObjParams("leavex", "Leavex", "PredOp",
|
leavexIop = InstObjParams("leavex", "Leavex", "PredOp",
|
||||||
{ "code": leavexCode,
|
{ "code": leavexCode,
|
||||||
|
|
|
@ -127,7 +127,9 @@ namespace ArmISA
|
||||||
// These otherwise unused bits of the PC are used to select a mode
|
// These otherwise unused bits of the PC are used to select a mode
|
||||||
// like the J and T bits of the CPSR.
|
// like the J and T bits of the CPSR.
|
||||||
static const Addr PcJBitShift = 33;
|
static const Addr PcJBitShift = 33;
|
||||||
|
static const Addr PcJBit = ULL(1) << PcJBitShift;
|
||||||
static const Addr PcTBitShift = 34;
|
static const Addr PcTBitShift = 34;
|
||||||
|
static const Addr PcTBit = ULL(1) << PcTBitShift;
|
||||||
static const Addr PcModeMask = (ULL(1) << PcJBitShift) |
|
static const Addr PcModeMask = (ULL(1) << PcJBitShift) |
|
||||||
(ULL(1) << PcTBitShift);
|
(ULL(1) << PcTBitShift);
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
|
|
||||||
#include "arch/arm/isa_traits.hh"
|
#include "arch/arm/isa_traits.hh"
|
||||||
#include "arch/arm/predecoder.hh"
|
#include "arch/arm/predecoder.hh"
|
||||||
|
#include "arch/arm/utility.hh"
|
||||||
#include "base/trace.hh"
|
#include "base/trace.hh"
|
||||||
#include "cpu/thread_context.hh"
|
#include "cpu/thread_context.hh"
|
||||||
|
|
||||||
|
@ -151,7 +152,7 @@ Predecoder::moreBytes(Addr pc, Addr fetchPC, MachInst inst)
|
||||||
{
|
{
|
||||||
data = inst;
|
data = inst;
|
||||||
offset = (fetchPC >= pc) ? 0 : pc - fetchPC;
|
offset = (fetchPC >= pc) ? 0 : pc - fetchPC;
|
||||||
emi.thumb = (pc & (ULL(1) << PcTBitShift)) ? 1 : 0;
|
emi.thumb = isThumb(pc);
|
||||||
FPSCR fpscr = tc->readMiscReg(MISCREG_FPSCR);
|
FPSCR fpscr = tc->readMiscReg(MISCREG_FPSCR);
|
||||||
emi.fpscrLen = fpscr.len;
|
emi.fpscrLen = fpscr.len;
|
||||||
emi.fpscrStride = fpscr.stride;
|
emi.fpscrStride = fpscr.stride;
|
||||||
|
|
|
@ -362,7 +362,7 @@ ArmLiveProcess::argsInit(int intSize, int pageSize)
|
||||||
|
|
||||||
Addr prog_entry = objFile->entryPoint();
|
Addr prog_entry = objFile->entryPoint();
|
||||||
if (arch == ObjectFile::Thumb)
|
if (arch == ObjectFile::Thumb)
|
||||||
prog_entry = (prog_entry & ~mask(1)) | (ULL(1) << PcTBitShift);
|
prog_entry = (prog_entry & ~mask(1)) | PcTBit;
|
||||||
tc->setPC(prog_entry);
|
tc->setPC(prog_entry);
|
||||||
tc->setNextPC(prog_entry + sizeof(MachInst));
|
tc->setNextPC(prog_entry + sizeof(MachInst));
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#ifndef __ARCH_ARM_UTILITY_HH__
|
#ifndef __ARCH_ARM_UTILITY_HH__
|
||||||
#define __ARCH_ARM_UTILITY_HH__
|
#define __ARCH_ARM_UTILITY_HH__
|
||||||
|
|
||||||
|
#include "arch/arm/isa_traits.hh"
|
||||||
#include "arch/arm/miscregs.hh"
|
#include "arch/arm/miscregs.hh"
|
||||||
#include "arch/arm/types.hh"
|
#include "arch/arm/types.hh"
|
||||||
#include "base/misc.hh"
|
#include "base/misc.hh"
|
||||||
|
@ -92,6 +93,12 @@ namespace ArmISA {
|
||||||
tc->activate(0);
|
tc->activate(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
isThumb(Addr pc)
|
||||||
|
{
|
||||||
|
return (pc & PcTBit);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
copyRegs(ThreadContext *src, ThreadContext *dest)
|
copyRegs(ThreadContext *src, ThreadContext *dest)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue