specop.isa revision 7087:fb8d5786ff30
1// Copyright (c) 2007-2008 The Hewlett-Packard Development Company 2// All rights reserved. 3// 4// The license below extends only to copyright in the software and shall 5// not be construed as granting a license to any other intellectual 6// property including but not limited to intellectual property relating 7// to a hardware implementation of the functionality of the software 8// licensed hereunder. You may use the software subject to the license 9// terms below provided that you ensure that this notice is replicated 10// unmodified and in its entirety in all distributions of the software, 11// modified or unmodified, in source code or in binary form. 12// 13// Redistribution and use in source and binary forms, with or without 14// modification, are permitted provided that the following conditions are 15// met: redistributions of source code must retain the above copyright 16// notice, this list of conditions and the following disclaimer; 17// redistributions in binary form must reproduce the above copyright 18// notice, this list of conditions and the following disclaimer in the 19// documentation and/or other materials provided with the distribution; 20// neither the name of the copyright holders nor the names of its 21// contributors may be used to endorse or promote products derived from 22// this software without specific prior written permission. 23// 24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35// 36// Authors: Gabe Black 37 38////////////////////////////////////////////////////////////////////////// 39// 40// Fault Microop 41// 42////////////////////////////////////////////////////////////////////////// 43 44output header {{ 45 class MicroFaultBase : public X86ISA::X86MicroopBase 46 { 47 protected: 48 Fault fault; 49 uint8_t cc; 50 51 public: 52 MicroFaultBase(ExtMachInst _machInst, const char * instMnem, 53 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 54 Fault _fault, uint8_t _cc); 55 56 MicroFaultBase(ExtMachInst _machInst, const char * instMnem, 57 Fault _fault, uint8_t _cc); 58 59 std::string generateDisassembly(Addr pc, 60 const SymbolTable *symtab) const; 61 }; 62 63 class MicroHalt : public X86ISA::X86MicroopBase 64 { 65 public: 66 MicroHalt(ExtMachInst _machInst, const char * instMnem, 67 bool isMicro, bool isDelayed, bool isFirst, bool isLast) : 68 X86MicroopBase(_machInst, "halt", instMnem, 69 isMicro, isDelayed, isFirst, isLast, No_OpClass) 70 { 71 } 72 73 MicroHalt(ExtMachInst _machInst, const char * instMnem) : 74 X86MicroopBase(_machInst, "halt", instMnem, 75 false, false, false, false, No_OpClass) 76 { 77 } 78 79 %(BasicExecDeclare)s 80 81 std::string generateDisassembly(Addr pc, 82 const SymbolTable *symtab) const; 83 }; 84}}; 85 86def template MicroFaultDeclare {{ 87 class %(class_name)s : public %(base_class)s 88 { 89 private: 90 void buildMe(); 91 public: 92 %(class_name)s(ExtMachInst _machInst, const char * instMnem, 93 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 94 Fault _fault, uint8_t _cc); 95 96 %(class_name)s(ExtMachInst _machInst, const char * instMnem, 97 Fault _fault, uint8_t _cc); 98 99 %(BasicExecDeclare)s 100 }; 101}}; 102 103def template MicroFaultExecute {{ 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 if (%(cond_test)s) { 110 //Return the fault we were constructed with 111 return fault; 112 } else { 113 return NoFault; 114 } 115 } 116}}; 117 118output exec {{ 119 Fault 120 MicroHalt::execute(%(CPU_exec_context)s *xc, 121 Trace::InstRecord * traceData) const 122 { 123 xc->tcBase()->suspend(); 124 return NoFault; 125 } 126}}; 127 128output decoder {{ 129 inline MicroFaultBase::MicroFaultBase( 130 ExtMachInst machInst, const char * instMnem, 131 Fault _fault, uint8_t _cc) : 132 X86MicroopBase(machInst, "fault", instMnem, 133 false, false, false, false, No_OpClass), 134 fault(_fault), cc(_cc) 135 { 136 } 137 138 inline MicroFaultBase::MicroFaultBase( 139 ExtMachInst machInst, const char * instMnem, 140 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 141 Fault _fault, uint8_t _cc) : 142 X86MicroopBase(machInst, "fault", instMnem, 143 isMicro, isDelayed, isFirst, isLast, No_OpClass), 144 fault(_fault), cc(_cc) 145 { 146 } 147}}; 148 149def template MicroFaultConstructor {{ 150 151 inline void %(class_name)s::buildMe() 152 { 153 %(constructor)s; 154 } 155 156 inline %(class_name)s::%(class_name)s( 157 ExtMachInst machInst, const char * instMnem, 158 Fault _fault, uint8_t _cc) : 159 %(base_class)s(machInst, instMnem, _fault, _cc) 160 { 161 buildMe(); 162 } 163 164 inline %(class_name)s::%(class_name)s( 165 ExtMachInst machInst, const char * instMnem, 166 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 167 Fault _fault, uint8_t _cc) : 168 %(base_class)s(machInst, instMnem, 169 isMicro, isDelayed, isFirst, isLast, _fault, _cc) 170 { 171 buildMe(); 172 } 173}}; 174 175output decoder {{ 176 std::string MicroFaultBase::generateDisassembly(Addr pc, 177 const SymbolTable *symtab) const 178 { 179 std::stringstream response; 180 181 printMnemonic(response, instMnem, mnemonic); 182 if(fault) 183 response << fault->name(); 184 else 185 response << "No Fault"; 186 187 return response.str(); 188 } 189 190 std::string MicroHalt::generateDisassembly(Addr pc, 191 const SymbolTable *symtab) const 192 { 193 std::stringstream response; 194 195 printMnemonic(response, instMnem, mnemonic); 196 197 return response.str(); 198 } 199}}; 200 201let {{ 202 class Fault(X86Microop): 203 className = "MicroFault" 204 def __init__(self, fault, flags=None): 205 self.fault = fault 206 if flags: 207 if not isinstance(flags, (list, tuple)): 208 raise Exception, "flags must be a list or tuple of flags" 209 self.cond = " | ".join(flags) 210 self.className += "Flags" 211 else: 212 self.cond = "0" 213 214 def getAllocator(self, *microFlags): 215 allocator = '''new %(class_name)s(machInst, macrocodeBlock 216 %(flags)s, %(fault)s, %(cc)s)''' % { 217 "class_name" : self.className, 218 "flags" : self.microFlagsText(microFlags), 219 "fault" : self.fault, 220 "cc" : self.cond} 221 return allocator 222 223 iop = InstObjParams("fault", "MicroFaultFlags", "MicroFaultBase", 224 {"code": "", 225 "cond_test": "checkCondition(ccFlagBits, cc)"}) 226 exec_output = MicroFaultExecute.subst(iop) 227 header_output = MicroFaultDeclare.subst(iop) 228 decoder_output = MicroFaultConstructor.subst(iop) 229 iop = InstObjParams("fault", "MicroFault", "MicroFaultBase", 230 {"code": "", 231 "cond_test": "true"}) 232 exec_output += MicroFaultExecute.subst(iop) 233 header_output += MicroFaultDeclare.subst(iop) 234 decoder_output += MicroFaultConstructor.subst(iop) 235 microopClasses["fault"] = Fault 236 237 class Halt(X86Microop): 238 className = "MicroHalt" 239 def __init__(self): 240 pass 241 242 def getAllocator(self, *microFlags): 243 return "new MicroHalt(machInst, macrocodeBlock %s)" % \ 244 self.microFlagsText(microFlags) 245 246 microopClasses["halt"] = Halt 247}}; 248