17087Snate@binkert.org// Copyright (c) 2007-2008 The Hewlett-Packard Development Company
211328Ssteve.reinhardt@amd.com// Copyright (c) 2015 Advanced Micro Devices, Inc.
37087Snate@binkert.org// All rights reserved.
47087Snate@binkert.org//
57087Snate@binkert.org// The license below extends only to copyright in the software and shall
67087Snate@binkert.org// not be construed as granting a license to any other intellectual
77087Snate@binkert.org// property including but not limited to intellectual property relating
87087Snate@binkert.org// to a hardware implementation of the functionality of the software
97087Snate@binkert.org// licensed hereunder.  You may use the software subject to the license
107087Snate@binkert.org// terms below provided that you ensure that this notice is replicated
117087Snate@binkert.org// unmodified and in its entirety in all distributions of the software,
127087Snate@binkert.org// modified or unmodified, in source code or in binary form.
137087Snate@binkert.org//
144158Sgblack@eecs.umich.edu// Copyright (c) 2007 The Regents of The University of Michigan
159921Syasuko.eckert@amd.com// Copyright (c) 2012 Mark D. Hill and David A. Wood
169921Syasuko.eckert@amd.com// Copyright (c) 2012-2013 Advanced Micro Devices, Inc.
174158Sgblack@eecs.umich.edu// All rights reserved.
184158Sgblack@eecs.umich.edu//
194158Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
204158Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are
214158Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright
224158Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
234158Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
244158Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
254158Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution;
264158Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its
274158Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from
284158Sgblack@eecs.umich.edu// this software without specific prior written permission.
294158Sgblack@eecs.umich.edu//
304158Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
314158Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
324158Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
334158Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
344158Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
354158Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
364158Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
374158Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
384158Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
394158Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
404158Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
414158Sgblack@eecs.umich.edu//
424158Sgblack@eecs.umich.edu// Authors: Gabe Black
434158Sgblack@eecs.umich.edu
444158Sgblack@eecs.umich.edudef operand_types {{
458449Sgblack@eecs.umich.edu    'sb' : 'int8_t',
468449Sgblack@eecs.umich.edu    'ub' : 'uint8_t',
478449Sgblack@eecs.umich.edu    'sw' : 'int16_t',
488449Sgblack@eecs.umich.edu    'uw' : 'uint16_t',
498449Sgblack@eecs.umich.edu    'sdw' : 'int32_t',
508449Sgblack@eecs.umich.edu    'udw' : 'uint32_t',
518449Sgblack@eecs.umich.edu    'sqw' : 'int64_t',
528449Sgblack@eecs.umich.edu    'uqw' : 'uint64_t',
5311328Ssteve.reinhardt@amd.com    'u2qw' : 'std::array<uint64_t, 2>',
548449Sgblack@eecs.umich.edu    'sf' : 'float',
558449Sgblack@eecs.umich.edu    'df' : 'double',
564158Sgblack@eecs.umich.edu}};
574158Sgblack@eecs.umich.edu
586360Sgblack@eecs.umich.edulet {{
596360Sgblack@eecs.umich.edu    def foldInt(idx, foldBit, id):
606360Sgblack@eecs.umich.edu        return ('IntReg', 'uqw', 'INTREG_FOLDED(%s, %s)' % (idx, foldBit),
616360Sgblack@eecs.umich.edu                'IsInteger', id)
626360Sgblack@eecs.umich.edu    def intReg(idx, id):
636360Sgblack@eecs.umich.edu        return ('IntReg', 'uqw', idx, 'IsInteger', id)
646360Sgblack@eecs.umich.edu    def impIntReg(idx, id):
656360Sgblack@eecs.umich.edu        return ('IntReg', 'uqw', 'INTREG_IMPLICIT(%s)' % idx, 'IsInteger', id)
666360Sgblack@eecs.umich.edu    def floatReg(idx, id):
676360Sgblack@eecs.umich.edu        return ('FloatReg', 'df', idx, 'IsFloating', id)
689921Syasuko.eckert@amd.com    def ccReg(idx, id):
699921Syasuko.eckert@amd.com        return ('CCReg', 'uqw', idx, 'IsCC', id)
706360Sgblack@eecs.umich.edu    def controlReg(idx, id, ctype = 'uqw'):
716360Sgblack@eecs.umich.edu        return ('ControlReg', ctype, idx,
726360Sgblack@eecs.umich.edu                (None, None, ['IsSerializeAfter',
736360Sgblack@eecs.umich.edu                              'IsSerializing',
746360Sgblack@eecs.umich.edu                              'IsNonSpeculative']),
756360Sgblack@eecs.umich.edu                id)
768500Sgblack@eecs.umich.edu    def squashCheckReg(idx, id, check, ctype = 'uqw'):
778500Sgblack@eecs.umich.edu        return ('ControlReg', ctype, idx,
788500Sgblack@eecs.umich.edu                (None, None, ['((%s) ? ' % check+ \
798500Sgblack@eecs.umich.edu                                'IsSquashAfter : IsSerializeAfter)',
808500Sgblack@eecs.umich.edu                              'IsSerializing',
818500Sgblack@eecs.umich.edu                              'IsNonSpeculative']),
828500Sgblack@eecs.umich.edu                id)
838500Sgblack@eecs.umich.edu    def squashCReg(idx, id, ctype = 'uqw'):
848500Sgblack@eecs.umich.edu        return squashCheckReg(idx, id, 'true', ctype)
858500Sgblack@eecs.umich.edu    def squashCSReg(idx, id, ctype = 'uqw'):
868500Sgblack@eecs.umich.edu        return squashCheckReg(idx, id, 'dest == SEGMENT_REG_CS', ctype)
878500Sgblack@eecs.umich.edu    def squashCR0Reg(idx, id, ctype = 'uqw'):
888500Sgblack@eecs.umich.edu        return squashCheckReg(idx, id, 'dest == 0', ctype)
896360Sgblack@eecs.umich.edu}};
906360Sgblack@eecs.umich.edu
914158Sgblack@eecs.umich.edudef operands {{
926360Sgblack@eecs.umich.edu        'SrcReg1':       foldInt('src1', 'foldOBit', 1),
936360Sgblack@eecs.umich.edu        'SSrcReg1':      intReg('src1', 1),
946360Sgblack@eecs.umich.edu        'SrcReg2':       foldInt('src2', 'foldOBit', 2),
956360Sgblack@eecs.umich.edu        'SSrcReg2':      intReg('src2', 1),
966360Sgblack@eecs.umich.edu        'Index':         foldInt('index', 'foldABit', 3),
976360Sgblack@eecs.umich.edu        'Base':          foldInt('base', 'foldABit', 4),
986360Sgblack@eecs.umich.edu        'DestReg':       foldInt('dest', 'foldOBit', 5),
996360Sgblack@eecs.umich.edu        'SDestReg':      intReg('dest', 5),
1006360Sgblack@eecs.umich.edu        'Data':          foldInt('data', 'foldOBit', 6),
10111329Salexandru.dutu@amd.com        'DataLow':       foldInt('dataLow', 'foldOBit', 6),
10211329Salexandru.dutu@amd.com        'DataHi':        foldInt('dataHi', 'foldOBit', 6),
1036360Sgblack@eecs.umich.edu        'ProdLow':       impIntReg(0, 7),
1046360Sgblack@eecs.umich.edu        'ProdHi':        impIntReg(1, 8),
1056360Sgblack@eecs.umich.edu        'Quotient':      impIntReg(2, 9),
1066360Sgblack@eecs.umich.edu        'Remainder':     impIntReg(3, 10),
1076360Sgblack@eecs.umich.edu        'Divisor':       impIntReg(4, 11),
1086479Sgblack@eecs.umich.edu        'DoubleBits':    impIntReg(5, 11),
1096360Sgblack@eecs.umich.edu        'Rax':           intReg('(INTREG_RAX)', 12),
1106360Sgblack@eecs.umich.edu        'Rbx':           intReg('(INTREG_RBX)', 13),
1116360Sgblack@eecs.umich.edu        'Rcx':           intReg('(INTREG_RCX)', 14),
1126360Sgblack@eecs.umich.edu        'Rdx':           intReg('(INTREG_RDX)', 15),
1136360Sgblack@eecs.umich.edu        'Rsp':           intReg('(INTREG_RSP)', 16),
1146360Sgblack@eecs.umich.edu        'Rbp':           intReg('(INTREG_RBP)', 17),
1156360Sgblack@eecs.umich.edu        'Rsi':           intReg('(INTREG_RSI)', 18),
1166360Sgblack@eecs.umich.edu        'Rdi':           intReg('(INTREG_RDI)', 19),
1176360Sgblack@eecs.umich.edu        'FpSrcReg1':     floatReg('src1', 20),
1186360Sgblack@eecs.umich.edu        'FpSrcReg2':     floatReg('src2', 21),
1196360Sgblack@eecs.umich.edu        'FpDestReg':     floatReg('dest', 22),
1206360Sgblack@eecs.umich.edu        'FpData':        floatReg('data', 23),
1217789Sgblack@eecs.umich.edu        'RIP':           ('PCState', 'uqw', 'pc',
1227789Sgblack@eecs.umich.edu                          (None, None, 'IsControl'), 50),
1237789Sgblack@eecs.umich.edu        'NRIP':          ('PCState', 'uqw', 'npc',
1247789Sgblack@eecs.umich.edu                          (None, None, 'IsControl'), 50),
1257789Sgblack@eecs.umich.edu        'nuIP':          ('PCState', 'uqw', 'nupc',
1267720Sgblack@eecs.umich.edu                          (None, None, 'IsControl'), 50),
1279212Snilay@cs.wisc.edu        # These registers hold the condition code portion of the flag
1289212Snilay@cs.wisc.edu        # register. The nccFlagBits version holds the rest.
1299921Syasuko.eckert@amd.com        'ccFlagBits':    ccReg('(CCREG_ZAPS)', 60),
1309921Syasuko.eckert@amd.com        'cfofBits':      ccReg('(CCREG_CFOF)', 61),
1319921Syasuko.eckert@amd.com        'dfBit':         ccReg('(CCREG_DF)', 62),
1329921Syasuko.eckert@amd.com        'ecfBit':        ccReg('(CCREG_ECF)', 63),
1339921Syasuko.eckert@amd.com        'ezfBit':        ccReg('(CCREG_EZF)', 64),
1349212Snilay@cs.wisc.edu
1359212Snilay@cs.wisc.edu        # These Pred registers are to be used where reading the portions of
1369212Snilay@cs.wisc.edu        # condition code registers is possibly optional, depending on how the
1379212Snilay@cs.wisc.edu        # check evaluates. There are two checks being specified, one tests if
1389212Snilay@cs.wisc.edu        # a register needs to be read, the other tests whether the register
1399212Snilay@cs.wisc.edu        # needs to be written to. It is unlikely that these would need to be
1409212Snilay@cs.wisc.edu        # used in the actual operation of the instruction. It is expected
1419212Snilay@cs.wisc.edu        # that these are used only in the flag code.
1429212Snilay@cs.wisc.edu
1439212Snilay@cs.wisc.edu        # Rationale behind the checks: at times, we need to partially update
1449212Snilay@cs.wisc.edu        # the condition code bits in a register. So we read the register even
1459212Snilay@cs.wisc.edu        # in the case when the all the bits will be written, or none of the
1469212Snilay@cs.wisc.edu        # bits will be written. The read predicate checks if any of the bits
1479212Snilay@cs.wisc.edu        # would be retained, the write predicate checks if any of the bits
1489212Snilay@cs.wisc.edu        # are being written.
1499212Snilay@cs.wisc.edu
1509921Syasuko.eckert@amd.com        'PredccFlagBits': ('CCReg', 'uqw', '(CCREG_ZAPS)', 'IsCC',
1519212Snilay@cs.wisc.edu                60, None, None, '''(((ext & (PFBit | AFBit | ZFBit | SFBit
1529212Snilay@cs.wisc.edu                )) != (PFBit | AFBit | ZFBit | SFBit )) &&
1539212Snilay@cs.wisc.edu                ((ext & (PFBit | AFBit | ZFBit | SFBit )) != 0))''',
1549212Snilay@cs.wisc.edu                '((ext & (PFBit | AFBit | ZFBit | SFBit )) != 0)'),
1559921Syasuko.eckert@amd.com        'PredcfofBits':   ('CCReg', 'uqw', '(CCREG_CFOF)', 'IsCC',
1569212Snilay@cs.wisc.edu                61, None, None, '''(((ext & CFBit) == 0 ||
1579212Snilay@cs.wisc.edu                (ext & OFBit) == 0) && ((ext & (CFBit | OFBit)) != 0))''',
1589212Snilay@cs.wisc.edu                '((ext & (CFBit | OFBit)) != 0)'),
1599921Syasuko.eckert@amd.com        'PreddfBit':   ('CCReg', 'uqw', '(CCREG_DF)', 'IsCC',
1609212Snilay@cs.wisc.edu                62, None, None, '(false)', '((ext & DFBit) != 0)'),
1619921Syasuko.eckert@amd.com        'PredecfBit':   ('CCReg', 'uqw', '(CCREG_ECF)', 'IsCC',
1629212Snilay@cs.wisc.edu                63, None, None, '(false)', '((ext & ECFBit) != 0)'),
1639921Syasuko.eckert@amd.com        'PredezfBit':   ('CCReg', 'uqw', '(CCREG_EZF)', 'IsCC',
1649212Snilay@cs.wisc.edu                64, None, None, '(false)', '((ext & EZFBit) != 0)'),
1659212Snilay@cs.wisc.edu
1665426Sgblack@eecs.umich.edu        # These register should needs to be more protected so that later
1675082Sgblack@eecs.umich.edu        # instructions don't map their indexes with an old value.
1689211Snilay@cs.wisc.edu        'nccFlagBits':   controlReg('MISCREG_RFLAGS', 65),
1699470Snilay@cs.wisc.edu
1709470Snilay@cs.wisc.edu        # Registers related to the state of x87 floating point unit.
1719211Snilay@cs.wisc.edu        'TOP':           controlReg('MISCREG_X87_TOP', 66, ctype='ub'),
1729470Snilay@cs.wisc.edu        'FSW':           controlReg('MISCREG_FSW', 67, ctype='uw'),
1739471Snilay@cs.wisc.edu        'FTW':           controlReg('MISCREG_FTW', 68, ctype='uw'),
1749582Snilay@cs.wisc.edu        'FCW':           controlReg('MISCREG_FCW', 69, ctype='uw'),
1759470Snilay@cs.wisc.edu
1765294Sgblack@eecs.umich.edu        # The segment base as used by memory instructions.
1776360Sgblack@eecs.umich.edu        'SegBase':       controlReg('MISCREG_SEG_EFF_BASE(segment)', 70),
1785290Sgblack@eecs.umich.edu
1795294Sgblack@eecs.umich.edu        # Operands to get and set registers indexed by the operands of the
1805294Sgblack@eecs.umich.edu        # original instruction.
1818500Sgblack@eecs.umich.edu        'ControlDest':   squashCR0Reg('MISCREG_CR(dest)', 100),
1826360Sgblack@eecs.umich.edu        'ControlSrc1':   controlReg('MISCREG_CR(src1)', 101),
1836360Sgblack@eecs.umich.edu        'DebugDest':     controlReg('MISCREG_DR(dest)', 102),
1846360Sgblack@eecs.umich.edu        'DebugSrc1':     controlReg('MISCREG_DR(src1)', 103),
1858500Sgblack@eecs.umich.edu        'SegBaseDest':   squashCSReg('MISCREG_SEG_BASE(dest)', 104),
1866360Sgblack@eecs.umich.edu        'SegBaseSrc1':   controlReg('MISCREG_SEG_BASE(src1)', 105),
1878500Sgblack@eecs.umich.edu        'SegLimitDest':  squashCSReg('MISCREG_SEG_LIMIT(dest)', 106),
1886360Sgblack@eecs.umich.edu        'SegLimitSrc1':  controlReg('MISCREG_SEG_LIMIT(src1)', 107),
1896360Sgblack@eecs.umich.edu        'SegSelDest':    controlReg('MISCREG_SEG_SEL(dest)', 108),
1906360Sgblack@eecs.umich.edu        'SegSelSrc1':    controlReg('MISCREG_SEG_SEL(src1)', 109),
1918500Sgblack@eecs.umich.edu        'SegAttrDest':   squashCSReg('MISCREG_SEG_ATTR(dest)', 110),
1926360Sgblack@eecs.umich.edu        'SegAttrSrc1':   controlReg('MISCREG_SEG_ATTR(src1)', 111),
1935294Sgblack@eecs.umich.edu
1945294Sgblack@eecs.umich.edu        # Operands to access specific control registers directly.
1958500Sgblack@eecs.umich.edu        'EferOp':        squashCReg('MISCREG_EFER', 200),
1966360Sgblack@eecs.umich.edu        'CR4Op':         controlReg('MISCREG_CR4', 201),
1976360Sgblack@eecs.umich.edu        'DR7Op':         controlReg('MISCREG_DR7', 202),
1986360Sgblack@eecs.umich.edu        'LDTRBase':      controlReg('MISCREG_TSL_BASE', 203),
1996360Sgblack@eecs.umich.edu        'LDTRLimit':     controlReg('MISCREG_TSL_LIMIT', 204),
2006360Sgblack@eecs.umich.edu        'LDTRSel':       controlReg('MISCREG_TSL', 205),
2016360Sgblack@eecs.umich.edu        'GDTRBase':      controlReg('MISCREG_TSG_BASE', 206),
2026360Sgblack@eecs.umich.edu        'GDTRLimit':     controlReg('MISCREG_TSG_LIMIT', 207),
2038500Sgblack@eecs.umich.edu        'CSBase':        squashCReg('MISCREG_CS_EFF_BASE', 208),
2048500Sgblack@eecs.umich.edu        'CSAttr':        squashCReg('MISCREG_CS_ATTR', 209),
2056360Sgblack@eecs.umich.edu        'MiscRegDest':   controlReg('dest', 210),
2066360Sgblack@eecs.umich.edu        'MiscRegSrc1':   controlReg('src1', 211),
2076360Sgblack@eecs.umich.edu        'TscOp':         controlReg('MISCREG_TSC', 212),
2088500Sgblack@eecs.umich.edu        'M5Reg':         squashCReg('MISCREG_M5_REG', 213),
2096360Sgblack@eecs.umich.edu        'Mem':           ('Mem', 'uqw', None, \
2106360Sgblack@eecs.umich.edu                          ('IsMemRef', 'IsLoad', 'IsStore'), 300)
2114158Sgblack@eecs.umich.edu}};
212