ldr.isa revision 7292
11689SN/A// -*- mode:c++ -*-
213601Sgiacomo.travaglini@arm.com
39919Ssteve.reinhardt@amd.com// Copyright (c) 2010 ARM Limited
48707Sandreas.hansson@arm.com// All rights reserved
58707Sandreas.hansson@arm.com//
68707Sandreas.hansson@arm.com// The license below extends only to copyright in the software and shall
78707Sandreas.hansson@arm.com// not be construed as granting a license to any other intellectual
88707Sandreas.hansson@arm.com// property including but not limited to intellectual property relating
98707Sandreas.hansson@arm.com// to a hardware implementation of the functionality of the software
108707Sandreas.hansson@arm.com// licensed hereunder.  You may use the software subject to the license
118707Sandreas.hansson@arm.com// terms below provided that you ensure that this notice is replicated
128707Sandreas.hansson@arm.com// unmodified and in its entirety in all distributions of the software,
138707Sandreas.hansson@arm.com// modified or unmodified, in source code or in binary form.
148707Sandreas.hansson@arm.com//
151689SN/A// Redistribution and use in source and binary forms, with or without
167897Shestness@cs.utexas.edu// modification, are permitted provided that the following conditions are
171689SN/A// met: redistributions of source code must retain the above copyright
181689SN/A// notice, this list of conditions and the following disclaimer;
191689SN/A// redistributions in binary form must reproduce the above copyright
201689SN/A// notice, this list of conditions and the following disclaimer in the
211689SN/A// documentation and/or other materials provided with the distribution;
221689SN/A// neither the name of the copyright holders nor the names of its
231689SN/A// contributors may be used to endorse or promote products derived from
241689SN/A// this software without specific prior written permission.
251689SN/A//
261689SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
271689SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
281689SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
291689SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
301689SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
311689SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
321689SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
331689SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
341689SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
351689SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
361689SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
371689SN/A//
381689SN/A// Authors: Gabe Black
391689SN/A
401689SN/Alet {{
412665Ssaidi@eecs.umich.edu
422665Ssaidi@eecs.umich.edu    header_output = ""
432756Sksewell@umich.edu    decoder_output = ""
447897Shestness@cs.utexas.edu    exec_output = ""
451689SN/A
461689SN/A    def loadImmClassName(post, add, writeback, \
472325SN/A                         size=4, sign=False, user=False):
482325SN/A        return memClassName("LOAD_IMM", post, add, writeback,
491060SN/A                            size, sign, user)
501060SN/A
511060SN/A    def loadRegClassName(post, add, writeback, \
522292SN/A                         size=4, sign=False, user=False):
532292SN/A        return memClassName("LOAD_REG", post, add, writeback,
541681SN/A                            size, sign, user)
551060SN/A
5612109SRekai.GonzalezAlberquilla@arm.com    def loadDoubleImmClassName(post, add, writeback):
572980Sgblack@eecs.umich.edu        return memClassName("LOAD_IMMD", post, add, writeback, 4, False, False)
581060SN/A
596658Snate@binkert.org    def loadDoubleRegClassName(post, add, writeback):
601717SN/A        return memClassName("LOAD_REGD", post, add, writeback, 4, False, False)
611717SN/A
622292SN/A    def emitLoad(name, Name, imm, eaCode, accCode, \
632292SN/A                 memFlags, instFlags, base, double=False):
648229Snate@binkert.org        global header_output, decoder_output, exec_output
658229Snate@binkert.org
668229Snate@binkert.org        (newHeader,
678229Snate@binkert.org         newDecoder,
682817Sksewell@umich.edu         newExec) = loadStoreBase(name, Name, imm,
698229Snate@binkert.org                                  eaCode, accCode,
701060SN/A                                  memFlags, instFlags, double,
711060SN/A                                  base, execTemplateBase = 'Load')
722316SN/A
732316SN/A        header_output += newHeader
742680Sktlim@umich.edu        decoder_output += newDecoder
752817Sksewell@umich.edu        exec_output += newExec
762817Sksewell@umich.edu
772843Sktlim@umich.edu    def buildImmLoad(mnem, post, add, writeback, \
782843Sktlim@umich.edu                     size=4, sign=False, user=False, \
792669Sktlim@umich.edu                     prefetch=False, ldrex=False):
801060SN/A        name = mnem
811060SN/A        Name = loadImmClassName(post, add, writeback, \
828737Skoansin.tan@gmail.com                                size, sign, user)
835529Snate@binkert.org
842733Sktlim@umich.edu        if add:
851060SN/A            op = " +"
861060SN/A        else:
871060SN/A            op = " -"
885529Snate@binkert.org
892292SN/A        offset = op + " imm"
902292SN/A        eaCode = "EA = Base"
911060SN/A        if not post:
921060SN/A            eaCode += offset
932348SN/A        eaCode += ";"
942348SN/A
952348SN/A        if prefetch:
962348SN/A            Name = "%s_%s" % (mnem.upper(), Name)
972348SN/A            memFlags = ["Request::PREFETCH"]
981060SN/A            accCode = '''
992733Sktlim@umich.edu            uint64_t temp = Mem%s;\n
1001060SN/A            temp = temp;
1011060SN/A            ''' % buildMemSuffix(sign, size)
1022325SN/A        else:
1031060SN/A            if ldrex:
1041061SN/A                memFlags = ["Request::LLSC"]
1054329Sktlim@umich.edu                Name = "%s_%s" % (mnem.upper(), Name)
1061060SN/A            else:
10712109SRekai.GonzalezAlberquilla@arm.com                memFlags = []
10812109SRekai.GonzalezAlberquilla@arm.com            accCode = "IWDest = Mem%s;\n" % buildMemSuffix(sign, size)
10912109SRekai.GonzalezAlberquilla@arm.com        if writeback:
11013610Sgiacomo.gabrielli@arm.com            accCode += "Base = Base %s;\n" % offset
11113610Sgiacomo.gabrielli@arm.com        base = buildMemBase("MemoryImm", post, writeback)
1125595Sgblack@eecs.umich.edu
1132292SN/A        emitLoad(name, Name, True, eaCode, accCode, memFlags, [], base)
1142292SN/A
1152292SN/A    def buildRfeLoad(mnem, post, add, writeback):
1162292SN/A        name = mnem
1172817Sksewell@umich.edu        Name = "RFE_" + loadImmClassName(post, add, writeback, 8)
1182829Sksewell@umich.edu
1191060SN/A        offset = 0
1201060SN/A        if post != add:
1211060SN/A            offset += 4
1221060SN/A        if not add:
1231060SN/A            offset -= 8
1242307SN/A
1252307SN/A        eaCode = "EA = Base + %d;" % offset
1261060SN/A
1271060SN/A        wbDiff = -8
12812406Sgabeblack@google.com        if add:
12912406Sgabeblack@google.com            wbDiff = 8
13013590Srekai.gonzalezalberquilla@arm.com        accCode = '''
1313781Sgblack@eecs.umich.edu        NPC = bits(Mem.ud, 31, 0);
1322292SN/A        uint32_t newCpsr = cpsrWriteByInstr(Cpsr | CondCodes,
1331060SN/A                                            bits(Mem.ud, 63, 32),
1341060SN/A                                            0xF, true);
1351060SN/A        Cpsr = ~CondCodesMask & newCpsr;
1368707Sandreas.hansson@arm.com        CondCodes = CondCodesMask & newCpsr;
1378707Sandreas.hansson@arm.com        '''
1388707Sandreas.hansson@arm.com        if writeback:
1398707Sandreas.hansson@arm.com            accCode += "Base = Base + %s;\n" % wbDiff
1409608Sandreas.hansson@arm.com
1418707Sandreas.hansson@arm.com        global header_output, decoder_output, exec_output
1428707Sandreas.hansson@arm.com
1438707Sandreas.hansson@arm.com        (newHeader,
1448707Sandreas.hansson@arm.com         newDecoder,
1458707Sandreas.hansson@arm.com         newExec) = RfeBase(name, Name, eaCode, accCode, [], [])
1468707Sandreas.hansson@arm.com
1478707Sandreas.hansson@arm.com        header_output += newHeader
1488707Sandreas.hansson@arm.com        decoder_output += newDecoder
1499608Sandreas.hansson@arm.com        exec_output += newExec
1508707Sandreas.hansson@arm.com
1518707Sandreas.hansson@arm.com    def buildRegLoad(mnem, post, add, writeback, \
1528707Sandreas.hansson@arm.com                     size=4, sign=False, user=False, prefetch=False):
1538707Sandreas.hansson@arm.com        name = mnem
1548707Sandreas.hansson@arm.com        Name = loadRegClassName(post, add, writeback,
1558707Sandreas.hansson@arm.com                                size, sign, user)
1568975Sandreas.hansson@arm.com
1578707Sandreas.hansson@arm.com        if add:
1588707Sandreas.hansson@arm.com            op = " +"
15910713Sandreas.hansson@arm.com        else:
1608707Sandreas.hansson@arm.com            op = " -"
1618707Sandreas.hansson@arm.com
1628707Sandreas.hansson@arm.com        offset = op + " shift_rm_imm(Index, shiftAmt," + \
1638707Sandreas.hansson@arm.com                      " shiftType, CondCodes<29:>)"
1648707Sandreas.hansson@arm.com        eaCode = "EA = Base"
1659608Sandreas.hansson@arm.com        if not post:
1668707Sandreas.hansson@arm.com            eaCode += offset
1678707Sandreas.hansson@arm.com        eaCode += ";"
1688707Sandreas.hansson@arm.com
1698707Sandreas.hansson@arm.com        if prefetch:
1708707Sandreas.hansson@arm.com            Name = "%s_%s" % (mnem.upper(), Name)
17110529Smorr@cs.wisc.edu            memFlags = ["Request::PREFETCH"]
1728707Sandreas.hansson@arm.com            accCode = '''
1738707Sandreas.hansson@arm.com            uint64_t temp = Mem%s;\n
1748707Sandreas.hansson@arm.com            temp = temp;
1758707Sandreas.hansson@arm.com            ''' % buildMemSuffix(sign, size)
17610529Smorr@cs.wisc.edu        else:
17710529Smorr@cs.wisc.edu            memFlags = []
1788707Sandreas.hansson@arm.com            accCode = "IWDest = Mem%s;\n" % buildMemSuffix(sign, size)
1798707Sandreas.hansson@arm.com        if writeback:
1808707Sandreas.hansson@arm.com            accCode += "Base = Base %s;\n" % offset
1818707Sandreas.hansson@arm.com        base = buildMemBase("MemoryReg", post, writeback)
1828707Sandreas.hansson@arm.com
1838707Sandreas.hansson@arm.com        emitLoad(name, Name, False, eaCode, accCode, \
1848707Sandreas.hansson@arm.com                 memFlags, [], base)
1858975Sandreas.hansson@arm.com
1868975Sandreas.hansson@arm.com    def buildDoubleImmLoad(mnem, post, add, writeback, ldrex=False):
1878707Sandreas.hansson@arm.com        name = mnem
1889608Sandreas.hansson@arm.com        Name = loadDoubleImmClassName(post, add, writeback)
1899608Sandreas.hansson@arm.com
1909608Sandreas.hansson@arm.com        if add:
1919608Sandreas.hansson@arm.com            op = " +"
1929608Sandreas.hansson@arm.com        else:
1938707Sandreas.hansson@arm.com            op = " -"
19410713Sandreas.hansson@arm.com
1958707Sandreas.hansson@arm.com        offset = op + " imm"
1968707Sandreas.hansson@arm.com        eaCode = "EA = Base"
1978707Sandreas.hansson@arm.com        if not post:
1988707Sandreas.hansson@arm.com            eaCode += offset
1998707Sandreas.hansson@arm.com        eaCode += ";"
2008711Sandreas.hansson@arm.com
2018707Sandreas.hansson@arm.com        accCode = '''
2028922Swilliam.wang@arm.com        Dest = bits(Mem.ud, 31, 0);
2038707Sandreas.hansson@arm.com        Dest2 = bits(Mem.ud, 63, 32);
2048707Sandreas.hansson@arm.com        '''
2052292SN/A        if ldrex:
20612127Sspwilson2@wisc.edu            memFlags = ["Request::LLSC"]
2071060SN/A            Name = "%s_%s" % (mnem.upper(), Name)
20813641Sqtt2@cornell.edu        else:
20913641Sqtt2@cornell.edu            memFlags = []
21013641Sqtt2@cornell.edu        if writeback:
2112292SN/A            accCode += "Base = Base %s;\n" % offset
2129180Sandreas.hansson@arm.com        base = buildMemBase("MemoryDImm", post, writeback)
2131060SN/A
2141060SN/A        emitLoad(name, Name, True, eaCode, accCode, \
2159179Sandreas.hansson@arm.com                 memFlags, [], base, double=True)
2161060SN/A
2179179Sandreas.hansson@arm.com    def buildDoubleRegLoad(mnem, post, add, writeback):
2181060SN/A        name = mnem
2191060SN/A        Name = loadDoubleRegClassName(post, add, writeback)
2202292SN/A
2211060SN/A        if add:
2221060SN/A            op = " +"
2231060SN/A        else:
2241060SN/A            op = " -"
2251060SN/A
2261060SN/A        offset = op + " shift_rm_imm(Index, shiftAmt," + \
2279444SAndreas.Sandberg@ARM.com                      " shiftType, CondCodes<29:>)"
22810913Sandreas.sandberg@arm.com        eaCode = "EA = Base"
2299444SAndreas.Sandberg@ARM.com        if not post:
2309444SAndreas.Sandberg@ARM.com            eaCode += offset
2319444SAndreas.Sandberg@ARM.com        eaCode += ";"
2329444SAndreas.Sandberg@ARM.com
2339444SAndreas.Sandberg@ARM.com        accCode = '''
2349444SAndreas.Sandberg@ARM.com        Dest = bits(Mem.ud, 31, 0);
2359444SAndreas.Sandberg@ARM.com        Dest2 = bits(Mem.ud, 63, 32);
2369444SAndreas.Sandberg@ARM.com        '''
2379444SAndreas.Sandberg@ARM.com        if writeback:
2389444SAndreas.Sandberg@ARM.com            accCode += "Base = Base %s;\n" % offset
2399444SAndreas.Sandberg@ARM.com        base = buildMemBase("MemoryDReg", post, writeback)
2409444SAndreas.Sandberg@ARM.com
2419444SAndreas.Sandberg@ARM.com        emitLoad(name, Name, False, eaCode, accCode,
2429444SAndreas.Sandberg@ARM.com                 [], [], base, double=True)
2439444SAndreas.Sandberg@ARM.com
2449444SAndreas.Sandberg@ARM.com    def buildLoads(mnem, size=4, sign=False, user=False):
2459444SAndreas.Sandberg@ARM.com        buildImmLoad(mnem, True, True, True, size, sign, user)
2469444SAndreas.Sandberg@ARM.com        buildRegLoad(mnem, True, True, True, size, sign, user)
2479444SAndreas.Sandberg@ARM.com        buildImmLoad(mnem, True, False, True, size, sign, user)
2489444SAndreas.Sandberg@ARM.com        buildRegLoad(mnem, True, False, True, size, sign, user)
2499444SAndreas.Sandberg@ARM.com        buildImmLoad(mnem, False, True, True, size, sign, user)
2509444SAndreas.Sandberg@ARM.com        buildRegLoad(mnem, False, True, True, size, sign, user)
2519444SAndreas.Sandberg@ARM.com        buildImmLoad(mnem, False, False, True, size, sign, user)
2529444SAndreas.Sandberg@ARM.com        buildRegLoad(mnem, False, False, True, size, sign, user)
2539444SAndreas.Sandberg@ARM.com        buildImmLoad(mnem, False, True, False, size, sign, user)
2541060SN/A        buildRegLoad(mnem, False, True, False, size, sign, user)
2552292SN/A        buildImmLoad(mnem, False, False, False, size, sign, user)
2565595Sgblack@eecs.umich.edu        buildRegLoad(mnem, False, False, False, size, sign, user)
2572292SN/A
2581755SN/A    def buildDoubleLoads(mnem):
2591060SN/A        buildDoubleImmLoad(mnem, True, True, True)
2602292SN/A        buildDoubleRegLoad(mnem, True, True, True)
26111169Sandreas.hansson@arm.com        buildDoubleImmLoad(mnem, True, False, True)
2621684SN/A        buildDoubleRegLoad(mnem, True, False, True)
26310023Smatt.horsnell@ARM.com        buildDoubleImmLoad(mnem, False, True, True)
26410023Smatt.horsnell@ARM.com        buildDoubleRegLoad(mnem, False, True, True)
26510023Smatt.horsnell@ARM.com        buildDoubleImmLoad(mnem, False, False, True)
26610023Smatt.horsnell@ARM.com        buildDoubleRegLoad(mnem, False, False, True)
26711169Sandreas.hansson@arm.com        buildDoubleImmLoad(mnem, False, True, False)
26810023Smatt.horsnell@ARM.com        buildDoubleRegLoad(mnem, False, True, False)
2695358Sgblack@eecs.umich.edu        buildDoubleImmLoad(mnem, False, False, False)
2705358Sgblack@eecs.umich.edu        buildDoubleRegLoad(mnem, False, False, False)
2715358Sgblack@eecs.umich.edu
2725358Sgblack@eecs.umich.edu    def buildRfeLoads(mnem):
2735358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, True, True, True)
2745358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, True, True, False)
2755358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, True, False, True)
2765358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, True, False, False)
2775358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, False, True, True)
2785358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, False, True, False)
2795358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, False, False, True)
2805358Sgblack@eecs.umich.edu        buildRfeLoad(mnem, False, False, False)
2815358Sgblack@eecs.umich.edu
2825358Sgblack@eecs.umich.edu    def buildPrefetches(mnem):
2835358Sgblack@eecs.umich.edu        buildRegLoad(mnem, False, False, False, size=1, prefetch=True)
2845358Sgblack@eecs.umich.edu        buildImmLoad(mnem, False, False, False, size=1, prefetch=True)
2852292SN/A        buildRegLoad(mnem, False, True, False, size=1, prefetch=True)
2862292SN/A        buildImmLoad(mnem, False, True, False, size=1, prefetch=True)
2872292SN/A
2881684SN/A    buildLoads("ldr")
2891684SN/A    buildLoads("ldrt", user=True)
2902292SN/A    buildLoads("ldrb", size=1)
29111169Sandreas.hansson@arm.com    buildLoads("ldrbt", size=1, user=True)
2921060SN/A    buildLoads("ldrsb", size=1, sign=True)
29311169Sandreas.hansson@arm.com    buildLoads("ldrsbt", size=1, sign=True, user=True)
2949427SAndreas.Sandberg@ARM.com    buildLoads("ldrh", size=2)
2952834Sksewell@umich.edu    buildLoads("ldrht", size=2, user=True)
2962834Sksewell@umich.edu    buildLoads("hdrsh", size=2, sign=True)
2972834Sksewell@umich.edu    buildLoads("ldrsht", size=2, sign=True, user=True)
2982834Sksewell@umich.edu
2992829Sksewell@umich.edu    buildDoubleLoads("ldrd")
3006221Snate@binkert.org
3012875Sksewell@umich.edu    buildRfeLoads("rfe")
3022875Sksewell@umich.edu
3036221Snate@binkert.org    buildPrefetches("pld")
3042829Sksewell@umich.edu    buildPrefetches("pldw")
3052292SN/A    buildPrefetches("pli")
3066221Snate@binkert.org
3071060SN/A    buildImmLoad("ldrex", False, True, False, size=4, ldrex=True)
3082292SN/A    buildImmLoad("ldrexh", False, True, False, size=2, ldrex=True)
3096221Snate@binkert.org    buildImmLoad("ldrexb", False, True, False, size=1, ldrex=True)
3102292SN/A    buildDoubleImmLoad("ldrexd", False, True, False, ldrex=True)
3112292SN/A}};
31211169Sandreas.hansson@arm.com