basic.isa revision 5091
13931Ssaidi@eecs.umich.edu// Copyright (c) 2006-2007 The Regents of The University of Michigan 22632Sstever@eecs.umich.edu// All rights reserved. 32632Sstever@eecs.umich.edu// 42632Sstever@eecs.umich.edu// Redistribution and use in source and binary forms, with or without 52632Sstever@eecs.umich.edu// modification, are permitted provided that the following conditions are 62632Sstever@eecs.umich.edu// met: redistributions of source code must retain the above copyright 72632Sstever@eecs.umich.edu// notice, this list of conditions and the following disclaimer; 82632Sstever@eecs.umich.edu// redistributions in binary form must reproduce the above copyright 92632Sstever@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the 102632Sstever@eecs.umich.edu// documentation and/or other materials provided with the distribution; 112632Sstever@eecs.umich.edu// neither the name of the copyright holders nor the names of its 122632Sstever@eecs.umich.edu// contributors may be used to endorse or promote products derived from 132632Sstever@eecs.umich.edu// this software without specific prior written permission. 142632Sstever@eecs.umich.edu// 152632Sstever@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162632Sstever@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172632Sstever@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182632Sstever@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192632Sstever@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202632Sstever@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212632Sstever@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222632Sstever@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232632Sstever@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242632Sstever@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252632Sstever@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262632Sstever@eecs.umich.edu// 272632Sstever@eecs.umich.edu// Authors: Ali Saidi 282632Sstever@eecs.umich.edu// Gabe Black 292632Sstever@eecs.umich.edu// Steve Reinhardt 302022SN/A 312022SN/A// Declarations for execute() methods. 322022SN/Adef template BasicExecDeclare {{ 332022SN/A Fault execute(%(CPU_exec_context)s *, Trace::InstRecord *) const; 342022SN/A}}; 352022SN/A 363275Sgblack@eecs.umich.edu// Definitions of execute methods that panic. 373275Sgblack@eecs.umich.edudef template BasicExecPanic {{ 383275Sgblack@eecs.umich.edu Fault execute(%(CPU_exec_context)s *, Trace::InstRecord *) const 393275Sgblack@eecs.umich.edu { 403275Sgblack@eecs.umich.edu panic("Execute method called when it shouldn't!"); 413918Ssaidi@eecs.umich.edu M5_DUMMY_RETURN 423275Sgblack@eecs.umich.edu } 433275Sgblack@eecs.umich.edu}}; 443275Sgblack@eecs.umich.edu 452022SN/A// Basic instruction class declaration template. 462022SN/Adef template BasicDeclare {{ 472022SN/A /** 482022SN/A * Static instruction class for "%(mnemonic)s". 492022SN/A */ 502022SN/A class %(class_name)s : public %(base_class)s 512022SN/A { 522224SN/A public: 532224SN/A // Constructor. 543384Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst machInst); 552224SN/A %(BasicExecDeclare)s 562224SN/A }; 572022SN/A}}; 582022SN/A 595091Sgblack@eecs.umich.edu// Basic instruction class declaration template. 605091Sgblack@eecs.umich.edudef template BasicDeclareWithMnemonic {{ 615091Sgblack@eecs.umich.edu /** 625091Sgblack@eecs.umich.edu * Static instruction class for "%(mnemonic)s". 635091Sgblack@eecs.umich.edu */ 645091Sgblack@eecs.umich.edu class %(class_name)s : public %(base_class)s 655091Sgblack@eecs.umich.edu { 665091Sgblack@eecs.umich.edu public: 675091Sgblack@eecs.umich.edu // Constructor. 685091Sgblack@eecs.umich.edu %(class_name)s(const char * mnemonic, ExtMachInst machInst); 695091Sgblack@eecs.umich.edu %(BasicExecDeclare)s 705091Sgblack@eecs.umich.edu }; 715091Sgblack@eecs.umich.edu}}; 725091Sgblack@eecs.umich.edu 732022SN/A// Basic instruction class constructor template. 742022SN/Adef template BasicConstructor {{ 753384Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s(ExtMachInst machInst) 762224SN/A : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s) 772022SN/A { 782022SN/A %(constructor)s; 792022SN/A } 802022SN/A}}; 812022SN/A 825091Sgblack@eecs.umich.edu// Basic instruction class constructor template. 835091Sgblack@eecs.umich.edudef template BasicConstructorWithMnemonic {{ 845091Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s(const char * mnemonic, 855091Sgblack@eecs.umich.edu ExtMachInst machInst) 865091Sgblack@eecs.umich.edu : %(base_class)s(mnemonic, machInst, %(op_class)s) 875091Sgblack@eecs.umich.edu { 885091Sgblack@eecs.umich.edu %(constructor)s; 895091Sgblack@eecs.umich.edu } 905091Sgblack@eecs.umich.edu}}; 915091Sgblack@eecs.umich.edu 922022SN/A// Basic instruction class execute method template. 932022SN/Adef template BasicExecute {{ 942224SN/A Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 952224SN/A Trace::InstRecord *traceData) const 962022SN/A { 972224SN/A Fault fault = NoFault; 982022SN/A 993931Ssaidi@eecs.umich.edu %(fp_enable_check)s; 1002224SN/A %(op_decl)s; 1012224SN/A %(op_rd)s; 1022224SN/A %(code)s; 1032022SN/A 1042224SN/A if(fault == NoFault) 1052224SN/A { 1062224SN/A %(op_wb)s; 1072224SN/A } 1082224SN/A return fault; 1092022SN/A } 1102022SN/A}}; 1112022SN/A 1122022SN/A// Basic decode template. 1132022SN/Adef template BasicDecode {{ 1142022SN/A return new %(class_name)s(machInst); 1152022SN/A}}; 1162022SN/A 1173272Sgblack@eecs.umich.edu// Basic decode template, passing mnemonic in as string arg to constructor. 1183272Sgblack@eecs.umich.edudef template BasicDecodeWithMnemonic {{ 1193272Sgblack@eecs.umich.edu return new %(class_name)s("%(mnemonic)s", machInst); 1203272Sgblack@eecs.umich.edu}}; 1213272Sgblack@eecs.umich.edu 1222022SN/A// The most basic instruction format... used only for a few misc. insts 1232022SN/Adef format BasicOperate(code, *flags) {{ 1244362Sgblack@eecs.umich.edu code = filterDoubles(code) 1253792Sgblack@eecs.umich.edu iop = InstObjParams(name, Name, 'SparcStaticInst', code, flags) 1262022SN/A header_output = BasicDeclare.subst(iop) 1272022SN/A decoder_output = BasicConstructor.subst(iop) 1282022SN/A decode_block = BasicDecode.subst(iop) 1292022SN/A exec_output = BasicExecute.subst(iop) 1302022SN/A}}; 1314008Ssaidi@eecs.umich.edu 1324008Ssaidi@eecs.umich.edudef format FpBasic(code, *flags) {{ 1334008Ssaidi@eecs.umich.edu fp_code = """ 1344011Ssaidi@eecs.umich.edu Fsr |= bits(Fsr,4,0) << 5; 1354008Ssaidi@eecs.umich.edu Fsr = insertBits(Fsr,4,0,0); 1364394Ssaidi@eecs.umich.edu int newrnd = M5_FE_TONEAREST; 1374008Ssaidi@eecs.umich.edu switch (Fsr<31:30>) { 1384394Ssaidi@eecs.umich.edu case 0: newrnd = M5_FE_TONEAREST; break; 1394394Ssaidi@eecs.umich.edu case 1: newrnd = M5_FE_TOWARDZERO; break; 1404394Ssaidi@eecs.umich.edu case 2: newrnd = M5_FE_UPWARD; break; 1414394Ssaidi@eecs.umich.edu case 3: newrnd = M5_FE_DOWNWARD; break; 1424008Ssaidi@eecs.umich.edu } 1434394Ssaidi@eecs.umich.edu int oldrnd = m5_fegetround(); 1444394Ssaidi@eecs.umich.edu m5_fesetround(newrnd); 1454008Ssaidi@eecs.umich.edu""" 1464011Ssaidi@eecs.umich.edu 1474008Ssaidi@eecs.umich.edu fp_code += code 1484011Ssaidi@eecs.umich.edu 1494011Ssaidi@eecs.umich.edu 1504008Ssaidi@eecs.umich.edu fp_code += """ 1514394Ssaidi@eecs.umich.edu m5_fesetround(oldrnd); 1524008Ssaidi@eecs.umich.edu""" 1534362Sgblack@eecs.umich.edu fp_code = filterDoubles(fp_code) 1544008Ssaidi@eecs.umich.edu iop = InstObjParams(name, Name, 'SparcStaticInst', fp_code, flags) 1554008Ssaidi@eecs.umich.edu header_output = BasicDeclare.subst(iop) 1564008Ssaidi@eecs.umich.edu decoder_output = BasicConstructor.subst(iop) 1574008Ssaidi@eecs.umich.edu decode_block = BasicDecode.subst(iop) 1584008Ssaidi@eecs.umich.edu exec_output = BasicExecute.subst(iop) 1594008Ssaidi@eecs.umich.edu}}; 160