ldstflags.hh revision 5912
12968SN/A/*
22968SN/A * Copyright (c) 2007 The Hewlett-Packard Development Company
32968SN/A * All rights reserved.
49988Snilay@cs.wisc.edu *
58835SAli.Saidi@ARM.com * Redistribution and use of this software in source and binary forms,
69988Snilay@cs.wisc.edu * with or without modification, are permitted provided that the
77935SN/A * following conditions are met:
87935SN/A *
97935SN/A * The software must be used only for Non-Commercial Use which means any
102968SN/A * use which is NOT directed to receiving any direct monetary
112968SN/A * compensation for, or commercial advantage from such use.  Illustrative
122968SN/A * examples of non-commercial use are academic research, personal study,
1310315Snilay@cs.wisc.edu * teaching, education and corporate research & development.
144463SN/A * Illustrative examples of commercial use are distributing products for
152968SN/A * commercial advantage and providing services using the software for
169885Sstever@gmail.com * commercial advantage.
179885Sstever@gmail.com *
1810315Snilay@cs.wisc.edu * If you wish to use this software or functionality therein that may be
199988Snilay@cs.wisc.edu * covered by patents for commercial use, please contact:
202968SN/A *     Director of Intellectual Property Licensing
2110315Snilay@cs.wisc.edu *     Office of Strategy and Technology
2210315Snilay@cs.wisc.edu *     Hewlett-Packard Company
237670SN/A *     1501 Page Mill Road
2410315Snilay@cs.wisc.edu *     Palo Alto, California  94304
252968SN/A *
269481Snilay@cs.wisc.edu * Redistributions of source code must retain the above copyright notice,
278721SN/A * this list of conditions and the following disclaimer.  Redistributions
288721SN/A * in binary form must reproduce the above copyright notice, this list of
2910315Snilay@cs.wisc.edu * conditions and the following disclaimer in the documentation and/or
3010315Snilay@cs.wisc.edu * other materials provided with the distribution.  Neither the name of
313140SN/A * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
322968SN/A * contributors may be used to endorse or promote products derived from
332968SN/A * this software without specific prior written permission.  No right of
347935SN/A * sublicense is granted herewith.  Derivatives of the software and
357935SN/A * output created using the software may be prepared, but only for
367935SN/A * Non-Commercial Uses.  Derivatives of the software may be shared with
377935SN/A * others provided: (i) the others agree to abide by the list of
387935SN/A * conditions herein which includes the Non-Commercial Use restrictions;
397935SN/A * and (ii) such Derivatives of the software include the above copyright
407935SN/A * notice to acknowledge the contribution from this software where
418983Snate@binkert.org * applicable, this list of conditions and the disclaimer below.
422968SN/A *
432968SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
442968SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
459885Sstever@gmail.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
464463SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
479988Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
488721SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
498721SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
508721SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
518983Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
528983Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
532968SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
549885Sstever@gmail.com *
559885Sstever@gmail.com * Authors: Gabe Black
569885Sstever@gmail.com */
5710315Snilay@cs.wisc.edu
589988Snilay@cs.wisc.edu#ifndef __ARCH_X86_INSTS_MICROLDSTOP_HH__
5910315Snilay@cs.wisc.edu#define __ARCH_X86_INSTS_MICROLDSTOP_HH__
609885Sstever@gmail.com
619885Sstever@gmail.com#include "arch/x86/insts/microop.hh"
622968SN/A#include "mem/packet.hh"
632968SN/A#include "mem/request.hh"
649481Snilay@cs.wisc.edu
6510315Snilay@cs.wisc.edunamespace X86ISA
665876SN/A{
679885Sstever@gmail.com    static const Request::FlagsType SegmentFlagMask = mask(4);
683171SN/A    static const int FlagShift = 4;
693638SN/A    enum FlagBit {
703638SN/A        CPL0FlagBit = 1
713638SN/A    };
722968SN/A
739988Snilay@cs.wisc.edu    /**
748983Snate@binkert.org     * Base class for load and store ops
752968SN/A     */
762968SN/A    class LdStOp : public X86MicroopBase
775723SN/A    {
789481Snilay@cs.wisc.edu      protected:
792968SN/A        const uint8_t scale;
802968SN/A        const RegIndex index;
812968SN/A        const RegIndex base;
822968SN/A        const uint64_t disp;
832968SN/A        const uint8_t segment;
845575SN/A        const RegIndex data;
852968SN/A        const uint8_t dataSize;
863140SN/A        const uint8_t addressSize;
879885Sstever@gmail.com        const Request::FlagsType memFlags;
885509SN/A        RegIndex foldOBit, foldABit;
895509SN/A
9010315Snilay@cs.wisc.edu        //Constructor
919481Snilay@cs.wisc.edu        LdStOp(ExtMachInst _machInst,
922968SN/A                const char * mnem, const char * _instMnem,
934938SN/A                bool isMicro, bool isDelayed, bool isFirst, bool isLast,
942968SN/A                uint8_t _scale, RegIndex _index, RegIndex _base,
958835SAli.Saidi@ARM.com                uint64_t _disp, uint8_t _segment,
964463SN/A                RegIndex _data,
974463SN/A                uint8_t _dataSize, uint8_t _addressSize,
984463SN/A                Request::FlagsType _memFlags,
994463SN/A                OpClass __opClass) :
1004463SN/A        X86MicroopBase(machInst, mnem, _instMnem,
1019885Sstever@gmail.com                isMicro, isDelayed, isFirst, isLast, __opClass),
1028983Snate@binkert.org                scale(_scale), index(_index), base(_base),
1034463SN/A                disp(_disp), segment(_segment),
1049885Sstever@gmail.com                data(_data),
10510636Snilay@cs.wisc.edu                dataSize(_dataSize), addressSize(_addressSize),
1069988Snilay@cs.wisc.edu                memFlags(_memFlags | _segment)
1076123SN/A        {
1089481Snilay@cs.wisc.edu            foldOBit = (dataSize == 1 && !_machInst.rex.present) ? 1 << 6 : 0;
1098241SN/A            foldABit =
1104463SN/A                (addressSize == 1 && !_machInst.rex.present) ? 1 << 6 : 0;
1114463SN/A        }
1125876SN/A
1138835SAli.Saidi@ARM.com        std::string generateDisassembly(Addr pc,
1149481Snilay@cs.wisc.edu            const SymbolTable *symtab) const;
11510036SAli.Saidi@ARM.com
1164463SN/A        template<class Context, class MemType>
1178835SAli.Saidi@ARM.com        Fault read(Context *xc, Addr EA, MemType & Mem, unsigned flags) const
1189885Sstever@gmail.com        {
1199481Snilay@cs.wisc.edu            Fault fault = NoFault;
1204463SN/A            switch(dataSize)
1214463SN/A            {
1224463SN/A              case 1:
1239481Snilay@cs.wisc.edu                fault = xc->read(EA, (uint8_t&)Mem, flags);
1244463SN/A                break;
1259885Sstever@gmail.com              case 2:
1269885Sstever@gmail.com                fault = xc->read(EA, (uint16_t&)Mem, flags);
1279885Sstever@gmail.com                break;
1289885Sstever@gmail.com              case 4:
1299885Sstever@gmail.com                fault = xc->read(EA, (uint32_t&)Mem, flags);
1309988Snilay@cs.wisc.edu                break;
1319885Sstever@gmail.com              case 8:
13210036SAli.Saidi@ARM.com                fault = xc->read(EA, (uint64_t&)Mem, flags);
1339885Sstever@gmail.com                break;
1349885Sstever@gmail.com              default:
1352968SN/A                panic("Bad operand size %d for read at %#x.\n", dataSize, EA);
1366024SN/A            }
1379988Snilay@cs.wisc.edu            return fault;
1382968SN/A        }
1392968SN/A
1404463SN/A        template<class Context, class MemType>
1414463SN/A        Fault write(Context *xc, MemType & Mem, Addr EA, unsigned flags) const
1429885Sstever@gmail.com        {
1438983Snate@binkert.org            Fault fault = NoFault;
1444463SN/A            switch(dataSize)
1459885Sstever@gmail.com            {
14610636Snilay@cs.wisc.edu              case 1:
1479988Snilay@cs.wisc.edu                fault = xc->write((uint8_t&)Mem, EA, flags, 0);
1486123SN/A                break;
1499481Snilay@cs.wisc.edu              case 2:
1508241SN/A                fault = xc->write((uint16_t&)Mem, EA, flags, 0);
1514463SN/A                break;
1524463SN/A              case 4:
1535876SN/A                fault = xc->write((uint32_t&)Mem, EA, flags, 0);
1548835SAli.Saidi@ARM.com                break;
1559481Snilay@cs.wisc.edu              case 8:
15610036SAli.Saidi@ARM.com                fault = xc->write((uint64_t&)Mem, EA, flags, 0);
1574463SN/A                break;
1588835SAli.Saidi@ARM.com              default:
1599885Sstever@gmail.com                panic("Bad operand size %d for write at %#x.\n", dataSize, EA);
1609481Snilay@cs.wisc.edu            }
1614463SN/A            return fault;
1624463SN/A        }
1634463SN/A
1649481Snilay@cs.wisc.edu        uint64_t
1654463SN/A        get(PacketPtr pkt) const
1669885Sstever@gmail.com        {
1679885Sstever@gmail.com            switch(dataSize)
1689885Sstever@gmail.com            {
1699885Sstever@gmail.com              case 1:
1709885Sstever@gmail.com                return pkt->get<uint8_t>();
1719988Snilay@cs.wisc.edu              case 2:
1729885Sstever@gmail.com                return pkt->get<uint16_t>();
17310036SAli.Saidi@ARM.com              case 4:
1749885Sstever@gmail.com                return pkt->get<uint32_t>();
1759885Sstever@gmail.com              case 8:
1765723SN/A                return pkt->get<uint64_t>();
1775723SN/A              default:
1789988Snilay@cs.wisc.edu                panic("Bad operand size %d for read at %#x.\n",
1795723SN/A                        dataSize, pkt->getAddr());
1809481Snilay@cs.wisc.edu            }
1819481Snilay@cs.wisc.edu        }
1829988Snilay@cs.wisc.edu    };
18310036SAli.Saidi@ARM.com}
1849481Snilay@cs.wisc.edu
1852968SN/A#endif //__ARCH_X86_INSTS_MICROLDSTOP_HH__
1866024SN/A