priv.isa revision 2488
1//////////////////////////////////////////////////////////////////// 2// 3// Privilege mode instructions 4// 5 6output header {{ 7 /** 8 * Base class for privelege mode operations. 9 */ 10 class Priv : public SparcStaticInst 11 { 12 protected: 13 // Constructor 14 Priv(const char *mnem, ExtMachInst _machInst, OpClass __opClass) : 15 SparcStaticInst(mnem, _machInst, __opClass) 16 { 17 } 18 19 std::string generateDisassembly(Addr pc, 20 const SymbolTable *symtab) const; 21 }; 22 23 /** 24 * Base class for user mode "tick" access. 25 */ 26 class PrivTick : public SparcStaticInst 27 { 28 protected: 29 // Constructor 30 PrivTick(const char *mnem, ExtMachInst _machInst, 31 OpClass __opClass) : 32 SparcStaticInst(mnem, _machInst, __opClass) 33 { 34 } 35 36 std::string generateDisassembly(Addr pc, 37 const SymbolTable *symtab) const; 38 }; 39 40 /** 41 * Base class for privelege mode operations with immediates. 42 */ 43 class PrivImm : public Priv 44 { 45 protected: 46 // Constructor 47 PrivImm(const char *mnem, ExtMachInst _machInst, 48 OpClass __opClass) : 49 Priv(mnem, _machInst, __opClass), imm(SIMM13) 50 { 51 } 52 53 uint32_t imm; 54 }; 55 56 /** 57 * Base class for user mode "tick" access with immediates. 58 */ 59 class PrivTickImm : public PrivTick 60 { 61 protected: 62 // Constructor 63 PrivTickImm(const char *mnem, ExtMachInst _machInst, 64 OpClass __opClass) : 65 PrivTick(mnem, _machInst, __opClass), imm(SIMM13) 66 { 67 } 68 69 uint32_t imm; 70 }; 71}}; 72 73output decoder {{ 74 std::string Priv::generateDisassembly(Addr pc, 75 const SymbolTable *symtab) const 76 { 77 return "Privileged Instruction"; 78 } 79 80 std::string PrivTick::generateDisassembly(Addr pc, 81 const SymbolTable *symtab) const 82 { 83 return "Regular access to Tick"; 84 } 85}}; 86 87def template PrivExecute {{ 88 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 89 Trace::InstRecord *traceData) const 90 { 91 %(op_decl)s; 92 %(op_rd)s; 93 94 //Since these are processed inside templates and not in codeblocks, 95 //They aren't translated by the isa_parser. Their names begin with 96 //underscores so they don't cause conflicts. 97 uint32_t _PstatePriv = xc->readMiscReg(MISCREG_PSTATE_PRIV); 98 99 //If the processor isn't in privileged mode, fault out right away 100 if(!_PstatePriv) 101 return new PrivilegedOpcode; 102 103 %(code)s; 104 %(op_wb)s; 105 return NoFault; 106 } 107}}; 108 109def template PrivTickExecute {{ 110 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 111 Trace::InstRecord *traceData) const 112 { 113 %(op_decl)s; 114 %(op_rd)s; 115 116 //Since these are processed inside templates and not in codeblocks, 117 //They aren't translated by the isa_parser. Their names begin with 118 //underscores so they don't cause conflicts. 119 uint32_t _PstatePriv = xc->readMiscReg(MISCREG_PSTATE_PRIV); 120 uint32_t _TickNpt = xc->readMiscReg(MISCREG_TICK_NPT); 121 //If the processor isn't in privileged mode, fault out right away 122 if(!_PstatePriv && _TickNpt) 123 return new PrivilegedAction; 124 125 %(code)s; 126 %(op_wb)s; 127 return NoFault; 128 } 129}}; 130 131// Primary format for integer operate instructions: 132def format Priv(code, *opt_flags) {{ 133 uses_imm = (code.find('Rs2_or_imm13') != -1) 134 if uses_imm: 135 orig_code = code 136 code = re.sub(r'Rs2_or_imm13', 'Rs2', orig_code) 137 imm_code = re.sub(r'Rs2_or_imm13(\.\w+)?', 'imm', orig_code) 138 cblk = CodeBlock(code) 139 iop = InstObjParams(name, Name, 'Priv', cblk, opt_flags) 140 header_output = BasicDeclare.subst(iop) 141 decoder_output = BasicConstructor.subst(iop) 142 exec_output = PrivExecute.subst(iop) 143 if uses_imm: 144 imm_cblk = CodeBlock(imm_code) 145 imm_iop = InstObjParams(name, Name + 'Imm', 'PrivImm', imm_cblk, 146 opt_flags) 147 header_output += BasicDeclare.subst(imm_iop) 148 decoder_output += BasicConstructor.subst(imm_iop) 149 exec_output += PrivExecute.subst(imm_iop) 150 decode_block = ROrImmDecode.subst(iop) 151 else: 152 decode_block = BasicDecode.subst(iop) 153}}; 154 155// Primary format for integer operate instructions: 156def format PrivTick(code, *opt_flags) {{ 157 uses_imm = (code.find('Rs2_or_imm13') != -1) 158 if uses_imm: 159 orig_code = code 160 code = re.sub(r'Rs2_or_imm13', 'Rs2', orig_code) 161 imm_code = re.sub(r'Rs2_or_imm13(\.\w+)?', 'imm', orig_code) 162 cblk = CodeBlock(code) 163 iop = InstObjParams(name, Name, 'PrivTick', cblk, opt_flags) 164 header_output = BasicDeclare.subst(iop) 165 decoder_output = BasicConstructor.subst(iop) 166 exec_output = PrivTickExecute.subst(iop) 167 if uses_imm: 168 imm_cblk = CodeBlock(imm_code) 169 imm_iop = InstObjParams(name, Name + 'Imm', 'PrivTickImm', imm_cblk, 170 opt_flags) 171 header_output += BasicDeclare.subst(imm_iop) 172 decoder_output += BasicConstructor.subst(imm_iop) 173 exec_output += PrivTickExecute.subst(imm_iop) 174 decode_block = Rb2OrImmDecode.subst(iop) 175 else: 176 decode_block = BasicDecode.subst(iop) 177}}; 178