priv.isa revision 2469
1//////////////////////////////////////////////////////////////////// 2// 3// Privelege 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 //If the processor isn't in privileged mode, fault out right away 95 if(!pstate_priv) 96 return new PrivilegedOpCode 97 98 %(code)s; 99 %(op_wb)s; 100 } 101}}; 102 103def template PrivTickExecute {{ 104 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 105 Trace::InstRecord *traceData) const 106 { 107 %(op_decl)s; 108 %(op_rd)s; 109 110 //If the processor isn't in privileged mode, fault out right away 111 if(!pstate_priv && tick_npt) 112 return new PrivilegedAction 113 114 %(code)s; 115 %(op_wb)s; 116 } 117}}; 118 119def template Rb2OrImm13Decode {{ 120 { 121 return (I ? (SparcStaticInst *)(new %(class_name)sImm(machInst)) 122 : (SparcStaticInst *)(new %(class_name)s(machInst))); 123 } 124}}; 125 126// Primary format for integer operate instructions: 127def format Priv(code, *opt_flags) {{ 128 uses_imm = (code.find('Rs2_or_imm13') != -1) 129 if uses_imm: 130 orig_code = code 131 code = re.sub(r'Rs2_or_imm', 'Rs2', orig_code) 132 imm_code = re.sub(r'Rs2_or_imm(\.\w+)?', 'imm', orig_code) 133 cblk = CodeBlock(code) 134 iop = InstObjParams(name, Name, 'Priv', cblk, opt_flags) 135 header_output = BasicDeclare.subst(iop) 136 decoder_output = BasicConstructor.subst(iop) 137 exec_output = PrivExecute.subst(iop) 138 if uses_imm: 139 imm_cblk = CodeBlock(imm_code) 140 imm_iop = InstObjParams(name, Name + 'Imm', 'PrivImm', imm_cblk, 141 opt_flags) 142 header_output += BasicDeclare.subst(imm_iop) 143 decoder_output += BasicConstructor.subst(imm_iop) 144 exec_output += PrivExecute.subst(imm_iop) 145 decode_block = Rb2OrImm13Decode.subst(iop) 146 else: 147 decode_block = BasicDecode.subst(iop) 148}}; 149 150// Primary format for integer operate instructions: 151def format PrivTick(code, *opt_flags) {{ 152 uses_imm = (code.find('Rs2_or_imm13') != -1) 153 if uses_imm: 154 orig_code = code 155 code = re.sub(r'Rs2_or_imm', 'Rs2', orig_code) 156 imm_code = re.sub(r'Rs2_or_imm(\.\w+)?', 'imm', orig_code) 157 cblk = CodeBlock(code) 158 iop = InstObjParams(name, Name, 'PrivTick', cblk, opt_flags) 159 header_output = BasicDeclare.subst(iop) 160 decoder_output = BasicConstructor.subst(iop) 161 exec_output = PrivTickExecute.subst(iop) 162 if uses_imm: 163 imm_cblk = CodeBlock(imm_code) 164 imm_iop = InstObjParams(name, Name + 'Imm', 'PrivTickImm', imm_cblk, 165 opt_flags) 166 header_output += BasicDeclare.subst(imm_iop) 167 decoder_output += BasicConstructor.subst(imm_iop) 168 exec_output += PrivTickExecute.subst(imm_iop) 169 decode_block = Rb2OrImm13Decode.subst(iop) 170 else: 171 decode_block = BasicDecode.subst(iop) 172}}; 173