mem.isa revision 7133:4a1af4580b7d
111901Sjason@lowepower.com// -*- mode:c++ -*-
211901Sjason@lowepower.com
311901Sjason@lowepower.com// Copyright (c) 2010 ARM Limited
411901Sjason@lowepower.com// All rights reserved
511901Sjason@lowepower.com//
611901Sjason@lowepower.com// The license below extends only to copyright in the software and shall
711901Sjason@lowepower.com// not be construed as granting a license to any other intellectual
811901Sjason@lowepower.com// property including but not limited to intellectual property relating
911901Sjason@lowepower.com// to a hardware implementation of the functionality of the software
1011901Sjason@lowepower.com// licensed hereunder.  You may use the software subject to the license
1111901Sjason@lowepower.com// terms below provided that you ensure that this notice is replicated
1211901Sjason@lowepower.com// unmodified and in its entirety in all distributions of the software,
1311901Sjason@lowepower.com// modified or unmodified, in source code or in binary form.
1411901Sjason@lowepower.com//
1511901Sjason@lowepower.com// Redistribution and use in source and binary forms, with or without
1611901Sjason@lowepower.com// modification, are permitted provided that the following conditions are
1711901Sjason@lowepower.com// met: redistributions of source code must retain the above copyright
1811901Sjason@lowepower.com// notice, this list of conditions and the following disclaimer;
1911901Sjason@lowepower.com// redistributions in binary form must reproduce the above copyright
2011901Sjason@lowepower.com// notice, this list of conditions and the following disclaimer in the
2111901Sjason@lowepower.com// documentation and/or other materials provided with the distribution;
2211901Sjason@lowepower.com// neither the name of the copyright holders nor the names of its
2311901Sjason@lowepower.com// contributors may be used to endorse or promote products derived from
2411901Sjason@lowepower.com// this software without specific prior written permission.
2511901Sjason@lowepower.com//
2611901Sjason@lowepower.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2711901Sjason@lowepower.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2811901Sjason@lowepower.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2911901Sjason@lowepower.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3011901Sjason@lowepower.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3111901Sjason@lowepower.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3211901Sjason@lowepower.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3311901Sjason@lowepower.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3411901Sjason@lowepower.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3511901Sjason@lowepower.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3611901Sjason@lowepower.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3711901Sjason@lowepower.com//
3811901Sjason@lowepower.com// Authors: Gabe Black
3912883Sjason@lowepower.com
4012883Sjason@lowepower.comlet {{
4112883Sjason@lowepower.com    def loadStoreBase(name, Name, imm, eaCode, accCode, memFlags,
4212883Sjason@lowepower.com                      instFlags, base = 'Memory', execTemplateBase = ''):
4312883Sjason@lowepower.com        # Make sure flags are in lists (convert to lists if not).
4412883Sjason@lowepower.com        memFlags = makeList(memFlags)
4512883Sjason@lowepower.com        instFlags = makeList(instFlags)
4612883Sjason@lowepower.com
4712883Sjason@lowepower.com        # This shouldn't be part of the eaCode, but until the exec templates
4812883Sjason@lowepower.com        # are converted over it's the easiest place to put it.
4912883Sjason@lowepower.com        eaCode += '\n    unsigned memAccessFlags = '
5012883Sjason@lowepower.com        if memFlags:
5112883Sjason@lowepower.com            eaCode += (string.join(memFlags, '|') + ';')
5211901Sjason@lowepower.com        else:
5311901Sjason@lowepower.com            eaCode += '0;'
5411901Sjason@lowepower.com
5511901Sjason@lowepower.com        iop = InstObjParams(name, Name, base,
5611901Sjason@lowepower.com                            {'ea_code': eaCode,
5711901Sjason@lowepower.com                             'memacc_code': accCode,
5811901Sjason@lowepower.com                             'predicate_test': predicateTest},
5911901Sjason@lowepower.com                            instFlags)
6011901Sjason@lowepower.com
6111901Sjason@lowepower.com        fullExecTemplate = eval(execTemplateBase + 'Execute')
6211901Sjason@lowepower.com        initiateAccTemplate = eval(execTemplateBase + 'InitiateAcc')
6311901Sjason@lowepower.com        completeAccTemplate = eval(execTemplateBase + 'CompleteAcc')
6411901Sjason@lowepower.com
6511901Sjason@lowepower.com        if imm:
6611901Sjason@lowepower.com            declareTemplate = LoadStoreImmDeclare
6711901Sjason@lowepower.com            constructTemplate = LoadStoreImmConstructor
6811901Sjason@lowepower.com        else:
6911901Sjason@lowepower.com            declareTemplate = LoadStoreRegDeclare
7011901Sjason@lowepower.com            constructTemplate = LoadStoreRegConstructor
7111901Sjason@lowepower.com
7211901Sjason@lowepower.com        # (header_output, decoder_output, decode_block, exec_output)
7311901Sjason@lowepower.com        return (declareTemplate.subst(iop),
7411901Sjason@lowepower.com                constructTemplate.subst(iop),
7511901Sjason@lowepower.com                fullExecTemplate.subst(iop)
7611901Sjason@lowepower.com                + initiateAccTemplate.subst(iop)
7711901Sjason@lowepower.com                + completeAccTemplate.subst(iop))
7811901Sjason@lowepower.com
7911901Sjason@lowepower.com    def memClassName(base, post, add, writeback, \
8013398Santhony.gutierrez@amd.com                     size=4, sign=False, user=False):
8113398Santhony.gutierrez@amd.com        Name = base
8213398Santhony.gutierrez@amd.com
8313398Santhony.gutierrez@amd.com        if post:
8413398Santhony.gutierrez@amd.com            Name += '_PY'
8513398Santhony.gutierrez@amd.com        else:
8613398Santhony.gutierrez@amd.com            Name += '_PN'
8713398Santhony.gutierrez@amd.com
8813398Santhony.gutierrez@amd.com        if add:
8913398Santhony.gutierrez@amd.com            Name += '_AY'
9013398Santhony.gutierrez@amd.com        else:
9113398Santhony.gutierrez@amd.com            Name += '_AN'
9213398Santhony.gutierrez@amd.com
9311901Sjason@lowepower.com        if writeback:
9411901Sjason@lowepower.com            Name += '_WY'
9511901Sjason@lowepower.com        else:
9611901Sjason@lowepower.com            Name += '_WN'
9711901Sjason@lowepower.com
9811901Sjason@lowepower.com        Name += ('_SZ%d' % size)
9911901Sjason@lowepower.com
10011901Sjason@lowepower.com        if sign:
10112562Ssiddhesh.poyarekar@gmail.com            Name += '_SY'
10212562Ssiddhesh.poyarekar@gmail.com        else:
10312562Ssiddhesh.poyarekar@gmail.com            Name += '_SN'
10411901Sjason@lowepower.com
10511901Sjason@lowepower.com        if user:
10611901Sjason@lowepower.com            Name += '_UY'
10711901Sjason@lowepower.com        else:
10811901Sjason@lowepower.com            Name += '_UN'
10911901Sjason@lowepower.com
11011901Sjason@lowepower.com        return Name
11111901Sjason@lowepower.com
11211901Sjason@lowepower.com    def buildMemSuffix(sign, size):
11311901Sjason@lowepower.com        if size == 4:
11411901Sjason@lowepower.com            memSuffix = ''
11511901Sjason@lowepower.com        elif size == 2:
11611901Sjason@lowepower.com            if sign:
11711901Sjason@lowepower.com                memSuffix = '.sh'
11811901Sjason@lowepower.com            else:
11911901Sjason@lowepower.com                memSuffix = '.uh'
12011901Sjason@lowepower.com        elif size == 1:
12111901Sjason@lowepower.com            if sign:
12211901Sjason@lowepower.com                memSuffix = '.sb'
12311901Sjason@lowepower.com            else:
12411901Sjason@lowepower.com                memSuffix = '.ub'
12511901Sjason@lowepower.com        else:
12611901Sjason@lowepower.com            raise Exception, "Unrecognized size for load %d" % size
12711901Sjason@lowepower.com
12811901Sjason@lowepower.com        return memSuffix
12911901Sjason@lowepower.com
13011901Sjason@lowepower.com    def buildMemBase(base, post, writeback):
13111901Sjason@lowepower.com        if post and writeback:
13211901Sjason@lowepower.com            base = "MemoryPostIndex<%s>" % base
13311901Sjason@lowepower.com        elif not post and writeback:
13411901Sjason@lowepower.com            base = "MemoryPreIndex<%s>" % base
13511901Sjason@lowepower.com        elif not post and not writeback:
13611901Sjason@lowepower.com            base = "MemoryOffset<%s>" % base
13711977Sjason@lowepower.com        else:
13811977Sjason@lowepower.com            raise Exception, "Illegal combination of post and writeback"
13911977Sjason@lowepower.com        return base
14011977Sjason@lowepower.com}};
14111901Sjason@lowepower.com
14211901Sjason@lowepower.com