str.isa revision 7313
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, \ 817303Sgblack@eecs.umich.edu size=4, sign=False, user=False, strex=False): 827119SN/A name = mnem 837120Sgblack@eecs.umich.edu Name = storeImmClassName(post, add, writeback, \ 847120Sgblack@eecs.umich.edu size, sign, user) 857119SN/A 867119SN/A if add: 877119SN/A op = " +" 887119SN/A else: 897119SN/A op = " -" 907119SN/A 917119SN/A offset = op + " imm" 927119SN/A eaCode = "EA = Base" 937119SN/A if not post: 947119SN/A eaCode += offset 957119SN/A eaCode += ";" 967119SN/A 977296Sgblack@eecs.umich.edu accCode = "Mem%(suffix)s = cSwap(Dest%(suffix)s, ((CPSR)Cpsr).e);" % \ 987296Sgblack@eecs.umich.edu { "suffix" : buildMemSuffix(sign, size) } 997119SN/A if writeback: 1007119SN/A accCode += "Base = Base %s;\n" % offset 1017119SN/A 1027303Sgblack@eecs.umich.edu memFlags = ["ArmISA::TLB::MustBeOne", "%d" % (size - 1)] 1037303Sgblack@eecs.umich.edu if strex: 1047303Sgblack@eecs.umich.edu memFlags.append("Request::LLSC") 1057303Sgblack@eecs.umich.edu Name = "%s_%s" % (mnem.upper(), Name) 1067303Sgblack@eecs.umich.edu base = buildMemBase("MemoryExImm", post, writeback) 1077303Sgblack@eecs.umich.edu postAccCode = "Result = !writeResult;" 1087303Sgblack@eecs.umich.edu execTemplateBase = 'StoreEx' 1097303Sgblack@eecs.umich.edu else: 1107303Sgblack@eecs.umich.edu memFlags.append("ArmISA::TLB::AllowUnaligned") 1117303Sgblack@eecs.umich.edu base = buildMemBase("MemoryImm", post, writeback) 1127303Sgblack@eecs.umich.edu postAccCode = "" 1137303Sgblack@eecs.umich.edu execTemplateBase = 'Store' 1147303Sgblack@eecs.umich.edu 1157303Sgblack@eecs.umich.edu emitStore(name, Name, True, eaCode, accCode, postAccCode, \ 1167303Sgblack@eecs.umich.edu memFlags, [], base, strex=strex, 1177303Sgblack@eecs.umich.edu execTemplateBase = execTemplateBase) 1187119SN/A 1197313Sgblack@eecs.umich.edu def buildSrsStore(mnem, post, add, writeback): 1207313Sgblack@eecs.umich.edu name = mnem 1217313Sgblack@eecs.umich.edu Name = "SRS_" + storeImmClassName(post, add, writeback, 8) 1227313Sgblack@eecs.umich.edu 1237313Sgblack@eecs.umich.edu offset = 0 1247313Sgblack@eecs.umich.edu if post != add: 1257313Sgblack@eecs.umich.edu offset += 4 1267313Sgblack@eecs.umich.edu if not add: 1277313Sgblack@eecs.umich.edu offset -= 8 1287313Sgblack@eecs.umich.edu 1297313Sgblack@eecs.umich.edu eaCode = "EA = SpMode + %d;" % offset 1307313Sgblack@eecs.umich.edu 1317313Sgblack@eecs.umich.edu wbDiff = -8 1327313Sgblack@eecs.umich.edu if add: 1337313Sgblack@eecs.umich.edu wbDiff = 8 1347313Sgblack@eecs.umich.edu accCode = ''' 1357313Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 1367313Sgblack@eecs.umich.edu Mem.ud = (uint64_t)cSwap(LR.uw, cpsr.e) | 1377313Sgblack@eecs.umich.edu ((uint64_t)cSwap(Spsr.uw, cpsr.e) << 32); 1387313Sgblack@eecs.umich.edu ''' 1397313Sgblack@eecs.umich.edu if writeback: 1407313Sgblack@eecs.umich.edu accCode += "SpMode = SpMode + %s;\n" % wbDiff 1417313Sgblack@eecs.umich.edu 1427313Sgblack@eecs.umich.edu global header_output, decoder_output, exec_output 1437313Sgblack@eecs.umich.edu 1447313Sgblack@eecs.umich.edu (newHeader, 1457313Sgblack@eecs.umich.edu newDecoder, 1467313Sgblack@eecs.umich.edu newExec) = SrsBase(name, Name, eaCode, accCode, 1477313Sgblack@eecs.umich.edu ["ArmISA::TLB::AlignWord", "ArmISA::TLB::MustBeOne"], []) 1487313Sgblack@eecs.umich.edu 1497313Sgblack@eecs.umich.edu header_output += newHeader 1507313Sgblack@eecs.umich.edu decoder_output += newDecoder 1517313Sgblack@eecs.umich.edu exec_output += newExec 1527313Sgblack@eecs.umich.edu 1537120Sgblack@eecs.umich.edu def buildRegStore(mnem, post, add, writeback, \ 1547303Sgblack@eecs.umich.edu size=4, sign=False, user=False, strex=False): 1557119SN/A name = mnem 1567120Sgblack@eecs.umich.edu Name = storeRegClassName(post, add, writeback, 1577120Sgblack@eecs.umich.edu size, sign, user) 1587119SN/A 1597119SN/A if add: 1607119SN/A op = " +" 1617119SN/A else: 1627119SN/A op = " -" 1637119SN/A 1647119SN/A offset = op + " shift_rm_imm(Index, shiftAmt," + \ 1657119SN/A " shiftType, CondCodes<29:>)" 1667119SN/A eaCode = "EA = Base" 1677119SN/A if not post: 1687119SN/A eaCode += offset 1697119SN/A eaCode += ";" 1707119SN/A 1717296Sgblack@eecs.umich.edu accCode = "Mem%(suffix)s = cSwap(Dest%(suffix)s, ((CPSR)Cpsr).e);" % \ 1727296Sgblack@eecs.umich.edu { "suffix" : buildMemSuffix(sign, size) } 1737119SN/A if writeback: 1747119SN/A accCode += "Base = Base %s;\n" % offset 1757132Sgblack@eecs.umich.edu base = buildMemBase("MemoryReg", post, writeback) 1767119SN/A 1777303Sgblack@eecs.umich.edu emitStore(name, Name, False, eaCode, accCode, "",\ 1787294Sgblack@eecs.umich.edu ["ArmISA::TLB::MustBeOne", \ 1797294Sgblack@eecs.umich.edu "ArmISA::TLB::AllowUnaligned", \ 1807294Sgblack@eecs.umich.edu "%d" % (size - 1)], [], base) 1817119SN/A 1827303Sgblack@eecs.umich.edu def buildDoubleImmStore(mnem, post, add, writeback, strex=False): 1837128Sgblack@eecs.umich.edu name = mnem 1847128Sgblack@eecs.umich.edu Name = storeDoubleImmClassName(post, add, writeback) 1857128Sgblack@eecs.umich.edu 1867128Sgblack@eecs.umich.edu if add: 1877128Sgblack@eecs.umich.edu op = " +" 1887128Sgblack@eecs.umich.edu else: 1897128Sgblack@eecs.umich.edu op = " -" 1907128Sgblack@eecs.umich.edu 1917128Sgblack@eecs.umich.edu offset = op + " imm" 1927128Sgblack@eecs.umich.edu eaCode = "EA = Base" 1937128Sgblack@eecs.umich.edu if not post: 1947128Sgblack@eecs.umich.edu eaCode += offset 1957128Sgblack@eecs.umich.edu eaCode += ";" 1967128Sgblack@eecs.umich.edu 1977296Sgblack@eecs.umich.edu accCode = ''' 1987296Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 1997296Sgblack@eecs.umich.edu Mem.ud = (uint64_t)cSwap(Dest.uw, cpsr.e) | 2007296Sgblack@eecs.umich.edu ((uint64_t)cSwap(Dest2.uw, cpsr.e) << 32); 2017296Sgblack@eecs.umich.edu ''' 2027128Sgblack@eecs.umich.edu if writeback: 2037128Sgblack@eecs.umich.edu accCode += "Base = Base %s;\n" % offset 2047128Sgblack@eecs.umich.edu 2057303Sgblack@eecs.umich.edu memFlags = ["ArmISA::TLB::MustBeOne", 2067303Sgblack@eecs.umich.edu "ArmISA::TLB::AlignWord"] 2077303Sgblack@eecs.umich.edu if strex: 2087303Sgblack@eecs.umich.edu memFlags.append("Request::LLSC") 2097303Sgblack@eecs.umich.edu Name = "%s_%s" % (mnem.upper(), Name) 2107303Sgblack@eecs.umich.edu base = buildMemBase("MemoryExDImm", post, writeback) 2117303Sgblack@eecs.umich.edu postAccCode = "Result = !writeResult;" 2127303Sgblack@eecs.umich.edu else: 2137303Sgblack@eecs.umich.edu base = buildMemBase("MemoryDImm", post, writeback) 2147303Sgblack@eecs.umich.edu postAccCode = "" 2157303Sgblack@eecs.umich.edu 2167303Sgblack@eecs.umich.edu emitStore(name, Name, True, eaCode, accCode, postAccCode, \ 2177303Sgblack@eecs.umich.edu memFlags, [], base, double=True, strex=strex) 2187128Sgblack@eecs.umich.edu 2197128Sgblack@eecs.umich.edu def buildDoubleRegStore(mnem, post, add, writeback): 2207128Sgblack@eecs.umich.edu name = mnem 2217128Sgblack@eecs.umich.edu Name = storeDoubleRegClassName(post, add, writeback) 2227128Sgblack@eecs.umich.edu 2237128Sgblack@eecs.umich.edu if add: 2247128Sgblack@eecs.umich.edu op = " +" 2257128Sgblack@eecs.umich.edu else: 2267128Sgblack@eecs.umich.edu op = " -" 2277128Sgblack@eecs.umich.edu 2287128Sgblack@eecs.umich.edu offset = op + " shift_rm_imm(Index, shiftAmt," + \ 2297128Sgblack@eecs.umich.edu " shiftType, CondCodes<29:>)" 2307128Sgblack@eecs.umich.edu eaCode = "EA = Base" 2317128Sgblack@eecs.umich.edu if not post: 2327128Sgblack@eecs.umich.edu eaCode += offset 2337128Sgblack@eecs.umich.edu eaCode += ";" 2347128Sgblack@eecs.umich.edu 2357296Sgblack@eecs.umich.edu accCode = ''' 2367296Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 2377296Sgblack@eecs.umich.edu Mem.ud = (uint64_t)cSwap(Dest.uw, cpsr.e) | 2387296Sgblack@eecs.umich.edu ((uint64_t)cSwap(Dest2.uw, cpsr.e) << 32); 2397296Sgblack@eecs.umich.edu ''' 2407128Sgblack@eecs.umich.edu if writeback: 2417128Sgblack@eecs.umich.edu accCode += "Base = Base %s;\n" % offset 2427279Sgblack@eecs.umich.edu base = buildMemBase("MemoryDReg", post, writeback) 2437128Sgblack@eecs.umich.edu 2447303Sgblack@eecs.umich.edu memFlags = ["ArmISA::TLB::MustBeOne", 2457303Sgblack@eecs.umich.edu "ArmISA::TLB::AlignWord"] 2467303Sgblack@eecs.umich.edu 2477303Sgblack@eecs.umich.edu emitStore(name, Name, False, eaCode, accCode, "", \ 2487303Sgblack@eecs.umich.edu memFlags, [], base, double=True) 2497128Sgblack@eecs.umich.edu 2507120Sgblack@eecs.umich.edu def buildStores(mnem, size=4, sign=False, user=False): 2517120Sgblack@eecs.umich.edu buildImmStore(mnem, True, True, True, size, sign, user) 2527120Sgblack@eecs.umich.edu buildRegStore(mnem, True, True, True, size, sign, user) 2537120Sgblack@eecs.umich.edu buildImmStore(mnem, True, False, True, size, sign, user) 2547120Sgblack@eecs.umich.edu buildRegStore(mnem, True, False, True, size, sign, user) 2557120Sgblack@eecs.umich.edu buildImmStore(mnem, False, True, True, size, sign, user) 2567120Sgblack@eecs.umich.edu buildRegStore(mnem, False, True, True, size, sign, user) 2577120Sgblack@eecs.umich.edu buildImmStore(mnem, False, False, True, size, sign, user) 2587120Sgblack@eecs.umich.edu buildRegStore(mnem, False, False, True, size, sign, user) 2597120Sgblack@eecs.umich.edu buildImmStore(mnem, False, True, False, size, sign, user) 2607120Sgblack@eecs.umich.edu buildRegStore(mnem, False, True, False, size, sign, user) 2617120Sgblack@eecs.umich.edu buildImmStore(mnem, False, False, False, size, sign, user) 2627120Sgblack@eecs.umich.edu buildRegStore(mnem, False, False, False, size, sign, user) 2637119SN/A 2647128Sgblack@eecs.umich.edu def buildDoubleStores(mnem): 2657128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, True, True, True) 2667128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, True, True, True) 2677128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, True, False, True) 2687128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, True, False, True) 2697128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, True, True) 2707128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, True, True) 2717128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, False, True) 2727128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, False, True) 2737128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, True, False) 2747128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, True, False) 2757128Sgblack@eecs.umich.edu buildDoubleImmStore(mnem, False, False, False) 2767128Sgblack@eecs.umich.edu buildDoubleRegStore(mnem, False, False, False) 2777128Sgblack@eecs.umich.edu 2787313Sgblack@eecs.umich.edu def buildSrsStores(mnem): 2797313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, True, True) 2807313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, True, False) 2817313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, False, True) 2827313Sgblack@eecs.umich.edu buildSrsStore(mnem, True, False, False) 2837313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, True, True) 2847313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, True, False) 2857313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, False, True) 2867313Sgblack@eecs.umich.edu buildSrsStore(mnem, False, False, False) 2877313Sgblack@eecs.umich.edu 2887120Sgblack@eecs.umich.edu buildStores("str") 2897120Sgblack@eecs.umich.edu buildStores("strt", user=True) 2907120Sgblack@eecs.umich.edu buildStores("strb", size=1) 2917120Sgblack@eecs.umich.edu buildStores("strbt", size=1, user=True) 2927120Sgblack@eecs.umich.edu buildStores("strh", size=2) 2937120Sgblack@eecs.umich.edu buildStores("strht", size=2, user=True) 2947128Sgblack@eecs.umich.edu 2957313Sgblack@eecs.umich.edu buildSrsStores("srs") 2967313Sgblack@eecs.umich.edu 2977128Sgblack@eecs.umich.edu buildDoubleStores("strd") 2987303Sgblack@eecs.umich.edu 2997303Sgblack@eecs.umich.edu buildImmStore("strex", False, True, False, size=4, strex=True) 3007303Sgblack@eecs.umich.edu buildImmStore("strexh", False, True, False, size=2, strex=True) 3017303Sgblack@eecs.umich.edu buildImmStore("strexb", False, True, False, size=1, strex=True) 3027303Sgblack@eecs.umich.edu buildDoubleImmStore("strexd", False, True, False, strex=True) 3037119SN/A}}; 304