priv.isa revision 2482
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 //If the processor isn't in privileged mode, fault out right away 95 if(!PstatePriv) 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(!PstatePriv && TickNpt) 112 return new PrivilegedAction 113 114 %(code)s; 115 %(op_wb)s; 116 } 117}}; 118 119// Primary format for integer operate instructions: 120def format Priv(code, *opt_flags) {{ 121 uses_imm = (code.find('Rs2_or_imm13') != -1) 122 if uses_imm: 123 orig_code = code 124 code = re.sub(r'Rs2_or_imm13', 'Rs2', orig_code) 125 imm_code = re.sub(r'Rs2_or_imm13(\.\w+)?', 'imm', orig_code) 126 cblk = CodeBlock(code) 127 iop = InstObjParams(name, Name, 'Priv', cblk, opt_flags) 128 header_output = BasicDeclare.subst(iop) 129 decoder_output = BasicConstructor.subst(iop) 130 exec_output = PrivExecute.subst(iop) 131 if uses_imm: 132 imm_cblk = CodeBlock(imm_code) 133 imm_iop = InstObjParams(name, Name + 'Imm', 'PrivImm', imm_cblk, 134 opt_flags) 135 header_output += BasicDeclare.subst(imm_iop) 136 decoder_output += BasicConstructor.subst(imm_iop) 137 exec_output += PrivExecute.subst(imm_iop) 138 decode_block = ROrImmDecode.subst(iop) 139 else: 140 decode_block = BasicDecode.subst(iop) 141}}; 142 143// Primary format for integer operate instructions: 144def format PrivTick(code, *opt_flags) {{ 145 uses_imm = (code.find('Rs2_or_imm13') != -1) 146 if uses_imm: 147 orig_code = code 148 code = re.sub(r'Rs2_or_imm13', 'Rs2', orig_code) 149 imm_code = re.sub(r'Rs2_or_imm13(\.\w+)?', 'imm', orig_code) 150 cblk = CodeBlock(code) 151 iop = InstObjParams(name, Name, 'PrivTick', cblk, opt_flags) 152 header_output = BasicDeclare.subst(iop) 153 decoder_output = BasicConstructor.subst(iop) 154 exec_output = PrivTickExecute.subst(iop) 155 if uses_imm: 156 imm_cblk = CodeBlock(imm_code) 157 imm_iop = InstObjParams(name, Name + 'Imm', 'PrivTickImm', imm_cblk, 158 opt_flags) 159 header_output += BasicDeclare.subst(imm_iop) 160 decoder_output += BasicConstructor.subst(imm_iop) 161 exec_output += PrivTickExecute.subst(imm_iop) 162 decode_block = Rb2OrImmDecode.subst(iop) 163 else: 164 decode_block = BasicDecode.subst(iop) 165}}; 166