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