Added supoort for program interrupt for Privileged type instruction.
* Added flag IsPrivileged to check wheather instruction is
privileged or not.
* Define bit number to be set in MSR for corresponding interrupt.
* Added Program interrupt handler with privileged type interrupt handler.
* Add IsPrivileged flag in all privileged instructions
* Add checker for PR bit inorder to verify mode for privilege instructions
and raise interrupt if needed.
Change-Id: I2aeb1a603568a6f80cd074bf67d4a528ebb6a5bd
Signed-off-by: Kajol Jain <kajoljain797@gmail.com>
#include "cpu/thread_context.hh"
#include "sim/faults.hh"
+#define SRR1_PRI_BIT 17
+
#define setbit(shift, mask) ( (uint64_t)1 << shift | mask)
#define unsetbit(shift,mask) ( ~((uint64_t)1 << shift) & mask)
#define setBitMask(shift) ( (uint64_t)1 << shift)
};
+//TODO: Need to add Floating point and TM Bad thing fault handler
+class ProgramInterrupt : public PowerInterrupt
+{
+ public:
+ ProgramInterrupt()
+ {
+ }
+ virtual void invoke(ThreadContext * tc, const StaticInstPtr &inst =
+ StaticInst::nullStaticInstPtr ,uint64_t bitSet = 0)
+ {
+ tc->setIntReg(INTREG_SRR0, tc->instAddr() + 4);
+ PowerInterrupt::updateSRR1(tc, bitSet);
+ PowerInterrupt::updateMsr(tc);
+ tc->pcState(ProgramPCSet);
+ }
+};
+
+class ProgramPriInterrupt : public ProgramInterrupt
+{
+ public:
+ ProgramPriInterrupt()
+ {
+ }
+ virtual void invoke(ThreadContext * tc, const StaticInstPtr &inst =
+ StaticInst::nullStaticInstPtr)
+ {
+ ProgramInterrupt::invoke(tc, inst, setBitMask(SRR1_PRI_BIT));
+ }
+};
class SystemCallInterrupt : public PowerInterrupt
{
MSR = insertBits(MSR,11,6,bits(SRR1,11,6));
MSR = insertBits(MSR,3,0,bits(SRR1,3,0));
NIA = SRR0 & -4ULL;
- }});
+ }}, [ IsPrivileged ]);
274: hrfid({{
if((bits(MSR,34,32)!=0x02)|(bits(HSRR1,34,32)!=0x00))
MSR = insertBits(MSR,34,32,bits(HSRR1,34,32));
0x2c9: mthdec({{HDEC = Rs;}});
0x24a: mtpcr({{PCR = Rs;}});
}
- 83: mfmsr({{ Rt = MSR }});
+
+ 83: mfmsr({{ Rt = MSR; }}, [ IsPrivileged ]);
+
178: mtmsrd({{
if (L == 0 ) {
uint64_t val = bits(Rs, 34, 32);
MSR = insertBits(MSR,15,bits(Rs,15));
MSR = insertBits(MSR,1,bits(Rs,1));
}
- }});
+ }}, [ IsPrivileged ]);
}
// Integer logic instructions use source registers Rs and Rb,
54: dcbst({{ }});
982: icbi({{ }});
306: tlbie({{ }});
- 274: tlbiel({{ }});
+ 274: tlbiel({{ }}, [ IsPrivileged ]);
566: tlbsync({{ }});
- 498: slbia({{ }});
+ 498: slbia({{ }}, [ IsPrivileged ]);
}
// These instructions are of XO form with bit 21 as the OE bit.
}};
+// Check the PR bit in MSR (which is bit number 14 of MSR)
+// to see if Program interrupt is there.
+
+let {{
+
+def GetPriCode(code):
+ cond_code = 'if (bits(MSR,14)==1) {\n'
+ cond_code += 'fault=std::make_shared<ProgramPriInterrupt>();\n'
+ cond_code += '} else {\n'
+ cond_code += code + '\n'
+ cond_code += '}\n'
+ return cond_code
+
+}};
// A basic integer instruction.
-def format IntOp(code, inst_flags = []) {{
+def format IntOp(code,inst_flags = []) {{
+ if 'IsPrivileged' in inst_flags:
+ code = GetPriCode(code)
(header_output, decoder_output, decode_block, exec_output) = \
GenAluOp(name, Name, 'IntOp', code, inst_flags, BasicDecode,
BasicConstructor)
}
}};
+// Check the PR bit in MSR (which is bit number 14 of MSR)
+// to see if Program interrupt is there.
+
+let {{
+
+def GetPriCode(code):
+ cond_code = 'if (bits(MSR,14)==1) {\n'
+ cond_code += 'fault=std::make_shared<ProgramPriInterrupt>();\n'
+ cond_code += '} else {\n'
+ cond_code += code + '\n'
+ cond_code += '}\n'
+ return cond_code
+
+}};
def format MiscOp(code, opt_flags = []) {{
+ if 'IsPrivileged' in opt_flags:
+ code = GetPriCode(code)
iop = InstObjParams(name, Name, 'IntOp',
{"code": code},
opt_flags)
'IsSyscall', # Causes a system call to be emulated in syscall
# emulation mode.
+ 'IsPrivileged', # Is flag to check instruction is privileged or not
# Flags for microcode
'IsMacroop', # Is a macroop containing microops
bool isIprAccess() const { return flags[IsIprAccess]; }
bool isUnverifiable() const { return flags[IsUnverifiable]; }
bool isSyscall() const { return flags[IsSyscall]; }
+ bool isPrivileged() const { return flags[IsPrivileged]; }
bool isMacroop() const { return flags[IsMacroop]; }
bool isMicroop() const { return flags[IsMicroop]; }
bool isDelayedCommit() const { return flags[IsDelayedCommit]; }