decoder.hh revision 9024:5851586f399c
12623SN/A/* 22623SN/A * Copyright (c) 2012 Google 32623SN/A * All rights reserved. 42623SN/A * 52623SN/A * Redistribution and use in source and binary forms, with or without 62623SN/A * modification, are permitted provided that the following conditions are 72623SN/A * met: redistributions of source code must retain the above copyright 82623SN/A * notice, this list of conditions and the following disclaimer; 92623SN/A * redistributions in binary form must reproduce the above copyright 102623SN/A * notice, this list of conditions and the following disclaimer in the 112623SN/A * documentation and/or other materials provided with the distribution; 122623SN/A * neither the name of the copyright holders nor the names of its 132623SN/A * contributors may be used to endorse or promote products derived from 142623SN/A * this software without specific prior written permission. 152623SN/A * 162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Gabe Black 292623SN/A */ 302623SN/A 312623SN/A#ifndef __ARCH_POWER_DECODER_HH__ 322623SN/A#define __ARCH_POWER_DECODER_HH__ 332623SN/A 342623SN/A#include "arch/generic/decode_cache.hh" 356973Stjones1@inf.ed.ac.uk#include "arch/types.hh" 365529Snate@binkert.org#include "cpu/static_inst.hh" 375529Snate@binkert.org 382623SN/Aclass ThreadContext; 392623SN/A 402623SN/Anamespace PowerISA 412623SN/A{ 425529Snate@binkert.org 432623SN/Aclass Decoder 442623SN/A{ 452623SN/A protected: 462623SN/A ThreadContext * tc; 472623SN/A 482839Sktlim@umich.edu // The extended machine instruction being generated 492798Sktlim@umich.edu ExtMachInst emi; 502623SN/A bool instDone; 512623SN/A 525728Sgblack@eecs.umich.edu public: 535728Sgblack@eecs.umich.edu Decoder(ThreadContext * _tc) : tc(_tc), instDone(false) 545728Sgblack@eecs.umich.edu { 555728Sgblack@eecs.umich.edu } 565728Sgblack@eecs.umich.edu 575728Sgblack@eecs.umich.edu ThreadContext * 585728Sgblack@eecs.umich.edu getTC() 595728Sgblack@eecs.umich.edu { 605728Sgblack@eecs.umich.edu return tc; 615728Sgblack@eecs.umich.edu } 625728Sgblack@eecs.umich.edu 635728Sgblack@eecs.umich.edu void 645728Sgblack@eecs.umich.edu setTC(ThreadContext * _tc) 655728Sgblack@eecs.umich.edu { 665728Sgblack@eecs.umich.edu tc = _tc; 675728Sgblack@eecs.umich.edu } 685728Sgblack@eecs.umich.edu 695728Sgblack@eecs.umich.edu void 705728Sgblack@eecs.umich.edu process() 715728Sgblack@eecs.umich.edu { 725728Sgblack@eecs.umich.edu } 735728Sgblack@eecs.umich.edu 745728Sgblack@eecs.umich.edu void 755728Sgblack@eecs.umich.edu reset() 765728Sgblack@eecs.umich.edu { 775728Sgblack@eecs.umich.edu instDone = false; 785728Sgblack@eecs.umich.edu } 795728Sgblack@eecs.umich.edu 805728Sgblack@eecs.umich.edu // Use this to give data to the predecoder. This should be used 815728Sgblack@eecs.umich.edu // when there is control flow. 825728Sgblack@eecs.umich.edu void 835728Sgblack@eecs.umich.edu moreBytes(const PCState &pc, Addr fetchPC, MachInst inst) 845728Sgblack@eecs.umich.edu { 855728Sgblack@eecs.umich.edu emi = inst; 865728Sgblack@eecs.umich.edu instDone = true; 875728Sgblack@eecs.umich.edu } 885728Sgblack@eecs.umich.edu 895728Sgblack@eecs.umich.edu // Use this to give data to the predecoder. This should be used 905728Sgblack@eecs.umich.edu // when instructions are executed in order. 915728Sgblack@eecs.umich.edu void 925728Sgblack@eecs.umich.edu moreBytes(MachInst machInst) 935728Sgblack@eecs.umich.edu { 945728Sgblack@eecs.umich.edu moreBytes(0, 0, machInst); 955728Sgblack@eecs.umich.edu } 965728Sgblack@eecs.umich.edu 975728Sgblack@eecs.umich.edu bool 985728Sgblack@eecs.umich.edu needMoreBytes() 995894Sgblack@eecs.umich.edu { 1005894Sgblack@eecs.umich.edu return true; 1015894Sgblack@eecs.umich.edu } 1025894Sgblack@eecs.umich.edu 1035894Sgblack@eecs.umich.edu bool 1045894Sgblack@eecs.umich.edu instReady() 1056023Snate@binkert.org { 1066023Snate@binkert.org return instDone; 1075894Sgblack@eecs.umich.edu } 1085894Sgblack@eecs.umich.edu protected: 1096023Snate@binkert.org /// A cache of decoded instruction objects. 1107944SGiacomo.Gabrielli@arm.com static GenericISA::BasicDecodeCache defaultCache; 1117945SAli.Saidi@ARM.com 1127945SAli.Saidi@ARM.com public: 1137945SAli.Saidi@ARM.com StaticInstPtr decodeInst(ExtMachInst mach_inst); 1147945SAli.Saidi@ARM.com 1157944SGiacomo.Gabrielli@arm.com /// Decode a machine instruction. 1167944SGiacomo.Gabrielli@arm.com /// @param mach_inst The binary instruction to decode. 1176023Snate@binkert.org /// @retval A pointer to the corresponding StaticInst object. 1186023Snate@binkert.org StaticInstPtr 1195894Sgblack@eecs.umich.edu decode(ExtMachInst mach_inst, Addr addr) 1205894Sgblack@eecs.umich.edu { 1215894Sgblack@eecs.umich.edu return defaultCache.decode(this, mach_inst, addr); 1225894Sgblack@eecs.umich.edu } 1235894Sgblack@eecs.umich.edu 1245894Sgblack@eecs.umich.edu StaticInstPtr 1256973Stjones1@inf.ed.ac.uk decode(PowerISA::PCState &nextPC) 1266973Stjones1@inf.ed.ac.uk { 1276973Stjones1@inf.ed.ac.uk if (!instDone) 1285894Sgblack@eecs.umich.edu return NULL; 1295894Sgblack@eecs.umich.edu instDone = false; 1305894Sgblack@eecs.umich.edu return decode(emi, nextPC.instAddr()); 1315894Sgblack@eecs.umich.edu } 1325894Sgblack@eecs.umich.edu}; 1335894Sgblack@eecs.umich.edu 1345894Sgblack@eecs.umich.edu} // namespace PowerISA 1355744Sgblack@eecs.umich.edu 1365728Sgblack@eecs.umich.edu#endif // __ARCH_POWER_DECODER_HH__ 1375728Sgblack@eecs.umich.edu