str.isa revision 7345
17119SN/A// -*- mode:c++ -*- 27119SN/A 37119SN/A// Copyright (c) 2010 ARM Limited 47119SN/A// All rights reserved 57119SN/A// 67119SN/A// The license below extends only to copyright in the software and shall 77119SN/A// not be construed as granting a license to any other intellectual 87119SN/A// property including but not limited to intellectual property relating 97119SN/A// to a hardware implementation of the functionality of the software 107119SN/A// licensed hereunder. You may use the software subject to the license 117119SN/A// terms below provided that you ensure that this notice is replicated 127119SN/A// unmodified and in its entirety in all distributions of the software, 137119SN/A// modified or unmodified, in source code or in binary form. 147119SN/A// 157119SN/A// Redistribution and use in source and binary forms, with or without 167119SN/A// modification, are permitted provided that the following conditions are 177119SN/A// met: redistributions of source code must retain the above copyright 187119SN/A// notice, this list of conditions and the following disclaimer; 197119SN/A// redistributions in binary form must reproduce the above copyright 207119SN/A// notice, this list of conditions and the following disclaimer in the 217119SN/A// documentation and/or other materials provided with the distribution; 227119SN/A// neither the name of the copyright holders nor the names of its 237119SN/A// contributors may be used to endorse or promote products derived from 247119SN/A// this software without specific prior written permission. 257119SN/A// 267119SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 277119SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 287119SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 297119SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 307119SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 317119SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 327119SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 337119SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 347119SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 357119SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 367119SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 377119SN/A// 387119SN/A// Authors: Gabe Black 397119SN/A 407119SN/Alet {{ 417119SN/A 427119SN/A header_output = "" 437119SN/A decoder_output = "" 447119SN/A exec_output = "" 457119SN/A 467120Sgblack@eecs.umich.edu def storeImmClassName(post, add, writeback, \ 477120Sgblack@eecs.umich.edu size=4, sign=False, user=False): 487120Sgblack@eecs.umich.edu return memClassName("STORE_IMM", post, add, writeback, 497119SN/A size, sign, user) 507119SN/A 517120Sgblack@eecs.umich.edu def storeRegClassName(post, add, writeback, \ 527120Sgblack@eecs.umich.edu size=4, sign=False, user=False): 537120Sgblack@eecs.umich.edu return memClassName("STORE_REG", post, add, writeback, 547119SN/A size, sign, user) 557119SN/A 567128Sgblack@eecs.umich.edu def storeDoubleImmClassName(post, add, writeback): 577128Sgblack@eecs.umich.edu return memClassName("STORE_IMMD", post, add, writeback, 587128Sgblack@eecs.umich.edu 4, False, False) 597128Sgblack@eecs.umich.edu 607128Sgblack@eecs.umich.edu def storeDoubleRegClassName(post, add, writeback): 617128Sgblack@eecs.umich.edu return memClassName("STORE_REGD", post, add, writeback, 627128Sgblack@eecs.umich.edu 4, False, False) 637128Sgblack@eecs.umich.edu 647303Sgblack@eecs.umich.edu def emitStore(name, Name, imm, eaCode, accCode, postAccCode, \ 657303Sgblack@eecs.umich.edu memFlags, instFlags, base, double=False, strex=False, 667303Sgblack@eecs.umich.edu execTemplateBase = 'Store'): 677119SN/A global header_output, decoder_output, exec_output 687119SN/A 697119SN/A (newHeader, 707119SN/A newDecoder, 717132Sgblack@eecs.umich.edu newExec) = loadStoreBase(name, Name, imm, 727303Sgblack@eecs.umich.edu eaCode, accCode, postAccCode, 737303Sgblack@eecs.umich.edu memFlags, instFlags, double, strex, 747303Sgblack@eecs.umich.edu base, execTemplateBase = execTemplateBase) 757119SN/A 767119SN/A header_output += newHeader 777119SN/A decoder_output += newDecoder 787119SN/A exec_output += newExec 797119SN/A 807120Sgblack@eecs.umich.edu def buildImmStore(mnem, post, add, writeback, \ 817345Sgblack@eecs.umich.edu size=4, sign=False, user=False, \ 827345Sgblack@eecs.umich.edu strex=False, vstr=False): 837119SN/A name = mnem 847120Sgblack@eecs.umich.edu Name = storeImmClassName(post, add, writeback, \ 857120Sgblack@eecs.umich.edu size, sign, user) 867119SN/A 877119SN/A if add: 887119SN/A op = " +" 897119SN/A else: 907119SN/A op = " -" 917119SN/A 927119SN/A offset = op + " imm" 937119SN/A eaCode = "EA = Base" 947119SN/A if not post: 957119SN/A eaCode += offset 967119SN/A eaCode += ";" 977119SN/A 987345Sgblack@eecs.umich.edu if vstr: 997345Sgblack@eecs.umich.edu accCode = ''' 1007345Sgblack@eecs.umich.edu Mem%(suffix)s = cSwap(FpDest.uw, ((CPSR)Cpsr).e); 1017345Sgblack@eecs.umich.edu ''' % { "suffix" : buildMemSuffix(sign, size) } 1027345Sgblack@eecs.umich.edu else: 1037345Sgblack@eecs.umich.edu accCode = ''' 1047345Sgblack@eecs.umich.edu Mem%(suffix)s = cSwap(Dest%(suffix)s, ((CPSR)Cpsr).e); 1057345Sgblack@eecs.umich.edu ''' % { "suffix" : buildMemSuffix(sign, size) } 1067119SN/A if writeback: 1077119SN/A accCode += "Base = Base %s;\n" % offset 1087119SN/A 1097303Sgblack@eecs.umich.edu memFlags = ["ArmISA::TLB::MustBeOne", "%d" % (size - 1)] 1107303Sgblack@eecs.umich.edu if strex: 1117303Sgblack@eecs.umich.edu memFlags.append("Request::LLSC") 1127303Sgblack@eecs.umich.edu Name = "%s_%s" % (mnem.upper(), Name) 1137303Sgblack@eecs.umich.edu base = buildMemBase("MemoryExImm", post, writeback) 1147303Sgblack@eecs.umich.edu postAccCode = "Result = !writeResult;" 1157303Sgblack@eecs.umich.edu execTemplateBase = 'StoreEx' 1167303Sgblack@eecs.umich.edu else: 1177345Sgblack@eecs.umich.edu if vstr: 1187345Sgblack@eecs.umich.edu Name = "%s_%s" % (mnem.upper(), Name) 1197345Sgblack@eecs.umich.edu else: 1207345Sgblack@eecs.umich.edu memFlags.append("ArmISA::TLB::AllowUnaligned") 1217303Sgblack@eecs.umich.edu base = buildMemBase("MemoryImm", post, writeback) 1227303Sgblack@eecs.umich.edu postAccCode = "" 1237303Sgblack@eecs.umich.edu execTemplateBase = 'Store' 1247303Sgblack@eecs.umich.edu 1257303Sgblack@eecs.umich.edu emitStore(name, Name, True, eaCode, accCode, postAccCode, \ 1267303Sgblack@eecs.umich.edu memFlags, [], base, strex=strex, 1277303Sgblack@eecs.umich.edu execTemplateBase = execTemplateBase) 1287119SN/A 1297313Sgblack@eecs.umich.edu def buildSrsStore(mnem, post, add, writeback): 1307313Sgblack@eecs.umich.edu name = mnem 1317313Sgblack@eecs.umich.edu Name = "SRS_" + storeImmClassName(post, add, writeback, 8) 1327313Sgblack@eecs.umich.edu 1337313Sgblack@eecs.umich.edu offset = 0 1347313Sgblack@eecs.umich.edu if post != add: 1357313Sgblack@eecs.umich.edu offset += 4 1367313Sgblack@eecs.umich.edu if not add: 1377313Sgblack@eecs.umich.edu offset -= 8 1387313Sgblack@eecs.umich.edu 1397313Sgblack@eecs.umich.edu eaCode = "EA = SpMode + %d;" % offset 1407313Sgblack@eecs.umich.edu 1417313Sgblack@eecs.umich.edu wbDiff = -8 1427313Sgblack@eecs.umich.edu if add: 1437313Sgblack@eecs.umich.edu wbDiff = 8 1447313Sgblack@eecs.umich.edu accCode = ''' 1457313Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 1467313Sgblack@eecs.umich.edu Mem.ud = (uint64_t)cSwap(LR.uw, cpsr.e) | 1477313Sgblack@eecs.umich.edu ((uint64_t)cSwap(Spsr.uw, cpsr.e) << 32); 1487313Sgblack@eecs.umich.edu ''' 1497313Sgblack@eecs.umich.edu if writeback: 1507313Sgblack@eecs.umich.edu accCode += "SpMode = SpMode + %s;\n" % wbDiff 1517313Sgblack@eecs.umich.edu 1527313Sgblack@eecs.umich.edu global header_output, decoder_output, exec_output 1537313Sgblack@eecs.umich.edu 1547313Sgblack@eecs.umich.edu (newHeader, 1557313Sgblack@eecs.umich.edu newDecoder, 1567313Sgblack@eecs.umich.edu newExec) = SrsBase(name, Name, eaCode, accCode, 1577313Sgblack@eecs.umich.edu ["ArmISA::TLB::AlignWord", "ArmISA::TLB::MustBeOne"], []) 1587313Sgblack@eecs.umich.edu 1597313Sgblack@eecs.umich.edu header_output += newHeader 1607313Sgblack@eecs.umich.edu decoder_output += newDecoder 1617313Sgblack@eecs.umich.edu exec_output += newExec 1627313Sgblack@eecs.umich.edu 1637120Sgblack@eecs.umich.edu def buildRegStore(mnem, post, add, writeback, \ 1647303Sgblack@eecs.umich.edu size=4, sign=False, user=False, strex=False): 1657119SN/A name = mnem 1667120Sgblack@eecs.umich.edu Name = storeRegClassName(post, add, writeback, 1677120Sgblack@eecs.umich.edu size, sign, user) 1687119SN/A 1697119SN/A if add: 1707119SN/A op = " +" 1717119SN/A else: 1727119SN/A op = " -" 1737119SN/A 1747119SN/A offset = op + " shift_rm_imm(Index, shiftAmt," + \ 1757119SN/A " shiftType, CondCodes<29:>)" 1767119SN/A eaCode = "EA = Base" 1777119SN/A if not post: 1787119SN/A eaCode += offset 1797119SN/A eaCode += ";" 1807119SN/A 1817296Sgblack@eecs.umich.edu accCode = "Mem%(suffix)s = cSwap(Dest%(suffix)s, ((CPSR)Cpsr).e);" % \ 1827296Sgblack@eecs.umich.edu { "suffix" : buildMemSuffix(sign, size) } 1837119SN/A if writeback: 1847119SN/A accCode += "Base = Base %s;\n" % offset 1857132Sgblack@eecs.umich.edu base = buildMemBase("MemoryReg", post, writeback) 1867119SN/A 1877303Sgblack@eecs.umich.edu emitStore(name, Name, False, eaCode, accCode, "",\ 1887294Sgblack@eecs.umich.edu ["ArmISA::TLB::MustBeOne", \ 1897294Sgblack@eecs.umich.edu "ArmISA::TLB::AllowUnaligned", \ 1907294Sgblack@eecs.umich.edu "%d" % (size - 1)], [], base) 1917119SN/A 1927345Sgblack@eecs.umich.edu def buildDoubleImmStore(mnem, post, add, writeback, \ 1937345Sgblack@eecs.umich.edu strex=False, vstr=False): 1947128Sgblack@eecs.umich.edu name = mnem 1957128Sgblack@eecs.umich.edu Name = storeDoubleImmClassName(post, add, writeback) 1967128Sgblack@eecs.umich.edu 1977128Sgblack@eecs.umich.edu if add: 1987128Sgblack@eecs.umich.edu op = " +" 1997128Sgblack@eecs.umich.edu else: 2007128Sgblack@eecs.umich.edu op = " -" 2017128Sgblack@eecs.umich.edu 2027128Sgblack@eecs.umich.edu offset = op + " imm" 2037128Sgblack@eecs.umich.edu eaCode = "EA = Base" 2047128Sgblack@eecs.umich.edu if not post: 2057128Sgblack@eecs.umich.edu eaCode += offset 2067128Sgblack@eecs.umich.edu eaCode += ";" 2077128Sgblack@eecs.umich.edu 2087345Sgblack@eecs.umich.edu if vstr: 2097345Sgblack@eecs.umich.edu accCode = ''' 2107345Sgblack@eecs.umich.edu uint64_t swappedMem = (uint64_t)FpDest.uw | 2117345Sgblack@eecs.umich.edu ((uint64_t)FpDest2.uw << 32); 2127345Sgblack@eecs.umich.edu Mem.ud = cSwap(swappedMem, ((CPSR)Cpsr).e); 2137345Sgblack@eecs.umich.edu ''' 2147345Sgblack@eecs.umich.edu else: 2157345Sgblack@eecs.umich.edu accCode = ''' 2167345Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 2177345Sgblack@eecs.umich.edu Mem.ud = (uint64_t)cSwap(Dest.uw, cpsr.e) | 2187345Sgblack@eecs.umich.edu ((uint64_t)cSwap(Dest2.uw, cpsr.e) << 32); 2197345Sgblack@eecs.umich.edu ''' 2207128Sgblack@eecs.umich.edu if writeback: 2217128Sgblack@eecs.umich.edu accCode += "Base = Base %s;\n" % offset 2227128Sgblack@eecs.umich.edu 2237303Sgblack@eecs.umich.edu memFlags = ["ArmISA::TLB::MustBeOne", 2247303Sgblack@eecs.umich.edu "ArmISA::TLB::AlignWord"] 2257303Sgblack@eecs.umich.edu if strex: 2267303Sgblack@eecs.umich.edu memFlags.append("Request::LLSC") 2277303Sgblack@eecs.umich.edu base = buildMemBase("MemoryExDImm", post, writeback) 2287303Sgblack@eecs.umich.edu postAccCode = "Result = !writeResult;" 2297303Sgblack@eecs.umich.edu else: 2307303Sgblack@eecs.umich.edu base = buildMemBase("MemoryDImm", post, writeback) 2317303Sgblack@eecs.umich.edu postAccCode = "" 2327345Sgblack@eecs.umich.edu if vstr or strex: 2337345Sgblack@eecs.umich.edu Name = "%s_%s" % (mnem.upper(), Name) 2347303Sgblack@eecs.umich.edu 2357303Sgblack@eecs.umich.edu emitStore(name, Name, True, eaCode, accCode, postAccCode, \ 2367303Sgblack@eecs.umich.edu memFlags, [], base, double=True, strex=strex) 2377128Sgblack@eecs.umich.edu 2387128Sgblack@eecs.umich.edu def buildDoubleRegStore(mnem, post, add, writeback): 2397128Sgblack@eecs.umich.edu name = mnem 2407128Sgblack@eecs.umich.edu Name = storeDoubleRegClassName(post, add, writeback) 2417128Sgblack@eecs.umich.edu 2427128Sgblack@eecs.umich.edu if add: 2437128Sgblack@eecs.umich.edu op = " +" 2447128Sgblack@eecs.umich.edu else: 2457128Sgblack@eecs.umich.edu op = " -" 2467128Sgblack@eecs.umich.edu 2477128Sgblack@eecs.umich.edu offset = op + " shift_rm_imm(Index, shiftAmt," + \ 2487128Sgblack@eecs.umich.edu " shiftType, CondCodes<29:>)" 2497128Sgblack@eecs.umich.edu eaCode = "EA = Base" 2507128Sgblack@eecs.umich.edu if not post: 2517128Sgblack@eecs.umich.edu eaCode += offset 2527128Sgblack@eecs.umich.edu eaCode += ";" 2537128Sgblack@eecs.umich.edu 2547296Sgblack@eecs.umich.edu accCode = ''' 2557296Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 2567296Sgblack@eecs.umich.edu Mem.ud = (uint64_t)cSwap(Dest.uw, cpsr.e) | 2577296Sgblack@eecs.umich.edu ((uint64_t)cSwap(Dest2.uw, cpsr.e) << 32); 2587296Sgblack@eecs.umich.edu ''' 2597128Sgblack@eecs.umich.edu if writeback: 2607128Sgblack@eecs.umich.edu accCode += "Base = Base %s;\n" % offset 2617279Sgblack@eecs.umich.edu base = buildMemBase("MemoryDReg", post, writeback) 2627128Sgblack@eecs.umich.edu 2637303Sgblack@eecs.umich.edu memFlags = ["ArmISA::TLB::MustBeOne", 2647303Sgblack@eecs.umich.edu "ArmISA::TLB::AlignWord"] 2657303Sgblack@eecs.umich.edu 2667303Sgblack@eecs.umich.edu emitStore(name, Name, False, eaCode, accCode, "", \ 2677303Sgblack@eecs.umich.edu memFlags, [], base, double=True) 2687128Sgblack@eecs.umich.edu 2697120Sgblack@eecs.umich.edu def buildStores(mnem, size=4, sign=False, user=False): 2707120Sgblack@eecs.umich.edu buildImmStore(mnem, True, True, True, size, sign, user) 2717120Sgblack@eecs.umich.edu buildRegStore(mnem, True, True, True, size, sign, user) 2727120Sgblack@eecs.umich.edu buildImmStore(mnem, True, False, True, size, sign, user) 2737120Sgblack@eecs.umich.edu buildRegStore(mnem, True, False, True, size, sign, user) 2747120Sgblack@eecs.umich.edu buildImmStore(mnem, False, True, True, size, sign, user) 2757120Sgblack@eecs.umich.edu buildRegStore(mnem, False, True, True, size, sign, user) 2767120Sgblack@eecs.umich.edu buildImmStore(mnem, False, False, True, size, sign, user) 2777120Sgblack@eecs.umich.edu buildRegStore(mnem, False, False, True, size, sign, user) 2787120Sgblack@eecs.umich.edu buildImmStore(mnem, False, True, False, size, sign, user) 2797120Sgblack@eecs.umich.edu buildRegStore(mnem, False, True, False, size, sign, user) 2807120Sgblack@eecs.umich.edu buildImmStore(mnem, False, False, False, size, sign, user) 2817120Sgblack@eecs.umich.edu buildRegStore(mnem, False, False, False, size, sign, user) 2827119SN/A 2837128Sgblack@eecs.umich.edu def buildDoubleStores(mnem): 2847128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, True, True, True) 2857128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, True, True, True) 2867128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, True, False, True) 2877128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, True, False, True) 2887128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, True, True) 2897128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, True, True) 2907128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, False, True) 2917128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, False, True) 2927128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, True, False) 2937128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, True, False) 2947128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, False, False) 2957128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, False, False) 2967128Sgblack@eecs.umich.edu 2977313Sgblack@eecs.umich.edu def buildSrsStores(mnem): 2987313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, True, True) 2997313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, True, False) 3007313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, False, True) 3017313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, False, False) 3027313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, True, True) 3037313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, True, False) 3047313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, False, True) 3057313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, False, False) 3067313Sgblack@eecs.umich.edu 3077120Sgblack@eecs.umich.edu buildStores("str") 3087120Sgblack@eecs.umich.edu buildStores("strt", user=True) 3097120Sgblack@eecs.umich.edu buildStores("strb", size=1) 3107120Sgblack@eecs.umich.edu buildStores("strbt", size=1, user=True) 3117120Sgblack@eecs.umich.edu buildStores("strh", size=2) 3127120Sgblack@eecs.umich.edu buildStores("strht", size=2, user=True) 3137128Sgblack@eecs.umich.edu 3147313Sgblack@eecs.umich.edu buildSrsStores("srs") 3157313Sgblack@eecs.umich.edu 3167128Sgblack@eecs.umich.edu buildDoubleStores("strd") 3177303Sgblack@eecs.umich.edu 3187303Sgblack@eecs.umich.edu buildImmStore("strex", False, True, False, size=4, strex=True) 3197303Sgblack@eecs.umich.edu buildImmStore("strexh", False, True, False, size=2, strex=True) 3207303Sgblack@eecs.umich.edu buildImmStore("strexb", False, True, False, size=1, strex=True) 3217303Sgblack@eecs.umich.edu buildDoubleImmStore("strexd", False, True, False, strex=True) 3227345Sgblack@eecs.umich.edu 3237345Sgblack@eecs.umich.edu buildImmStore("vstr", False, True, False, size=4, vstr=True) 3247345Sgblack@eecs.umich.edu buildImmStore("vstr", False, False, False, size=4, vstr=True) 3257345Sgblack@eecs.umich.edu buildDoubleImmStore("vstr", False, True, False, vstr=True) 3267345Sgblack@eecs.umich.edu buildDoubleImmStore("vstr", False, False, False, vstr=True) 3277119SN/A}}; 328