15666Sgblack@eecs.umich.edu// Copyright (c) 2008 The Regents of The University of Michigan
25666Sgblack@eecs.umich.edu// All rights reserved.
35666Sgblack@eecs.umich.edu//
45666Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
55666Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are
65666Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright
75666Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
85666Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
95666Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
105666Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution;
115666Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its
125666Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from
135666Sgblack@eecs.umich.edu// this software without specific prior written permission.
145666Sgblack@eecs.umich.edu//
155666Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165666Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
175666Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
185666Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
195666Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205666Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
215666Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225666Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235666Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245666Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
255666Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265666Sgblack@eecs.umich.edu//
275666Sgblack@eecs.umich.edu// Authors: Gabe Black
285666Sgblack@eecs.umich.edu
295666Sgblack@eecs.umich.edudef template MicroRomConstructor {{
305666Sgblack@eecs.umich.edu
315666Sgblack@eecs.umich.edu    %(define_generators)s
325666Sgblack@eecs.umich.edu    const MicroPC X86ISA::MicrocodeRom::numMicroops = %(num_microops)s;
335666Sgblack@eecs.umich.edu
345666Sgblack@eecs.umich.edu    X86ISA::MicrocodeRom::MicrocodeRom()
355666Sgblack@eecs.umich.edu    {
365666Sgblack@eecs.umich.edu        using namespace RomLabels;
375666Sgblack@eecs.umich.edu        genFuncs = new GenFunc[numMicroops];
385666Sgblack@eecs.umich.edu        %(alloc_generators)s;
395666Sgblack@eecs.umich.edu    }
405666Sgblack@eecs.umich.edu}};
415666Sgblack@eecs.umich.edu
425666Sgblack@eecs.umich.edulet {{
435666Sgblack@eecs.umich.edu    from micro_asm import Rom
445666Sgblack@eecs.umich.edu
455666Sgblack@eecs.umich.edu    class X86MicrocodeRom(Rom):
465666Sgblack@eecs.umich.edu        def __init__(self, name):
475666Sgblack@eecs.umich.edu            super(X86MicrocodeRom, self).__init__(name)
485666Sgblack@eecs.umich.edu            self.directives = {}
495666Sgblack@eecs.umich.edu
505666Sgblack@eecs.umich.edu        def add_microop(self, mnemonic, microop):
515666Sgblack@eecs.umich.edu            microop.mnemonic = mnemonic
525666Sgblack@eecs.umich.edu            microop.micropc = len(self.microops)
535666Sgblack@eecs.umich.edu            self.microops.append(microop)
545666Sgblack@eecs.umich.edu
555666Sgblack@eecs.umich.edu
565666Sgblack@eecs.umich.edu        def getDeclaration(self):
575666Sgblack@eecs.umich.edu            declareLabels = "namespace RomLabels {\n"
585676Sgblack@eecs.umich.edu            for (label, microop) in self.labels.items():
595676Sgblack@eecs.umich.edu                declareLabels += "const static uint64_t label_%s = %d;\n" \
605676Sgblack@eecs.umich.edu                                  % (label, microop.micropc)
615666Sgblack@eecs.umich.edu            for (label, microop) in self.externs.items():
625666Sgblack@eecs.umich.edu                declareLabels += \
635666Sgblack@eecs.umich.edu                    "const static MicroPC extern_label_%s = %d;\n" \
645666Sgblack@eecs.umich.edu                        % (label, microop.micropc)
655666Sgblack@eecs.umich.edu            declareLabels += "}\n"
665666Sgblack@eecs.umich.edu            return declareLabels;
675666Sgblack@eecs.umich.edu
685666Sgblack@eecs.umich.edu        def getDefinition(self):
695666Sgblack@eecs.umich.edu            numMicroops = len(self.microops)
705666Sgblack@eecs.umich.edu            allocGenerators = ''
715666Sgblack@eecs.umich.edu            micropc = 0
725666Sgblack@eecs.umich.edu            define_generators = '''
735666Sgblack@eecs.umich.edu                namespace
745666Sgblack@eecs.umich.edu                {
755666Sgblack@eecs.umich.edu                    static const char romMnemonic[] = "Microcode_ROM";
765666Sgblack@eecs.umich.edu            '''
775666Sgblack@eecs.umich.edu            for op in self.microops:
785666Sgblack@eecs.umich.edu                define_generators += op.getGeneratorDef(micropc)
795666Sgblack@eecs.umich.edu                allocGenerators += "genFuncs[%d] = %s;\n" % \
805666Sgblack@eecs.umich.edu                        (micropc, op.getGenerator(micropc))
815666Sgblack@eecs.umich.edu                micropc += 1
825666Sgblack@eecs.umich.edu            define_generators += "}\n"
835666Sgblack@eecs.umich.edu            iop = InstObjParams(self.name, self.name, "MicrocodeRom",
845666Sgblack@eecs.umich.edu                                {"code" : "",
855666Sgblack@eecs.umich.edu                                 "define_generators" : define_generators,
865666Sgblack@eecs.umich.edu                                 "num_microops" : numMicroops,
875666Sgblack@eecs.umich.edu                                 "alloc_generators" : allocGenerators
885666Sgblack@eecs.umich.edu                                })
895666Sgblack@eecs.umich.edu            return MicroRomConstructor.subst(iop);
905666Sgblack@eecs.umich.edu}};
91