swap.isa revision 7741:340b6f01d69b
1// Copyright (c) 2007 The Regents of The University of Michigan 2// All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions are 6// met: redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer; 8// redistributions in binary form must reproduce the above copyright 9// notice, this list of conditions and the following disclaimer in the 10// documentation and/or other materials provided with the distribution; 11// neither the name of the copyright holders nor the names of its 12// contributors may be used to endorse or promote products derived from 13// this software without specific prior written permission. 14// 15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26// 27// Authors: Gabe Black 28// Ali Saidi 29 30// This template provides the execute functions for a swap 31def template SwapExecute {{ 32 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 33 Trace::InstRecord *traceData) const 34 { 35 Fault fault = NoFault; 36 // This is to support the conditional store in cas instructions. 37 // It should be optomized out in all the others 38 bool storeCond = true; 39 Addr EA; 40 %(fp_enable_check)s; 41 %(op_decl)s; 42 uint64_t mem_data = 0; 43 44 %(op_rd)s; 45 %(ea_code)s; 46 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA); 47 %(fault_check)s; 48 if (fault == NoFault) { 49 %(code)s; 50 } 51 if (storeCond && fault == NoFault) { 52 %(EA_trunc)s 53 fault = xc->write((uint%(mem_acc_size)s_t)Mem, 54 EA, %(asi_val)s, &mem_data); 55 } 56 if (fault == NoFault) { 57 // Handle the swapping 58 %(postacc_code)s; 59 } 60 if (fault == NoFault) { 61 // Write the resulting state to the execution context 62 %(op_wb)s; 63 } 64 65 return fault; 66 } 67}}; 68 69 70def template SwapInitiateAcc {{ 71 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s * xc, 72 Trace::InstRecord * traceData) const 73 { 74 Fault fault = NoFault; 75 Addr EA; 76 %(fp_enable_check)s; 77 uint64_t mem_data = 0; 78 %(op_decl)s; 79 %(op_rd)s; 80 %(ea_code)s; 81 82 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA); 83 %(fault_check)s; 84 85 if (fault == NoFault) { 86 %(code)s; 87 } 88 if (fault == NoFault) { 89 %(EA_trunc)s 90 fault = xc->write((uint%(mem_acc_size)s_t)Mem, 91 EA, %(asi_val)s, &mem_data); 92 } 93 return fault; 94 } 95}}; 96 97 98 99def template SwapCompleteAcc {{ 100 Fault %(class_name)s::completeAcc(PacketPtr pkt, %(CPU_exec_context)s * xc, 101 Trace::InstRecord * traceData) const 102 { 103 Fault fault = NoFault; 104 %(op_decl)s; 105 106 uint64_t mem_data = pkt->get<uint%(mem_acc_size)s_t>(); 107 108 if (fault == NoFault) { 109 // Handle the swapping 110 %(postacc_code)s; 111 } 112 if (fault == NoFault) { 113 // Write the resulting state to the execution context 114 %(op_wb)s; 115 } 116 117 return fault; 118 } 119}}; 120 121let {{ 122 SwapFuncs = [SwapExecute, SwapInitiateAcc, SwapCompleteAcc] 123}}; 124 125 126def format Swap(code, postacc_code, mem_flags, *opt_flags) {{ 127 mem_flags = makeList(mem_flags) 128 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 129 flags = string.join(mem_flags, '|') 130 131 (header_output, 132 decoder_output, 133 exec_output, 134 decode_block) = doMemFormat(code, SwapFuncs, '', name, Name, flags, 135 ["IsStoreConditional"], postacc_code) 136}}; 137 138def format SwapAlt(code, postacc_code, mem_flags, *opt_flags) {{ 139 mem_flags = makeList(mem_flags) 140 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 141 mem_flags.append("EXT_ASI") 142 flags = string.join(mem_flags, '|') 143 (header_output, 144 decoder_output, 145 exec_output, 146 decode_block) = doMemFormat(code, SwapFuncs, AlternateASIPrivFaultCheck, 147 name, Name, flags, ["IsStoreConditional"], postacc_code) 148}}; 149 150 151let {{ 152 def doCasFormat(code, execute, faultCode, name, Name, mem_flags, opt_flags, postacc_code = ''): 153 addrCalcReg = 'EA = Rs1;' 154 iop = InstObjParams(name, Name, 'Mem', 155 {"code": code, "postacc_code" : postacc_code, 156 "fault_check": faultCode, "ea_code": addrCalcReg, 157 "EA_trunc" : TruncateEA}, opt_flags) 158 header_output = MemDeclare.subst(iop) 159 decoder_output = BasicConstructor.subst(iop) 160 decode_block = BasicDecode.subst(iop) 161 microParams = {"code": code, "postacc_code" : postacc_code, 162 "ea_code" : addrCalcReg, "fault_check" : faultCode, 163 "EA_trunc" : TruncateEA} 164 exec_output = doSplitExecute(execute, name, Name, mem_flags, 165 ["IsStoreConditional"], microParams); 166 return (header_output, decoder_output, exec_output, decode_block) 167}}; 168 169 170def format CasAlt(code, postacc_code, mem_flags, *opt_flags) {{ 171 mem_flags = makeList(mem_flags) 172 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 173 mem_flags.append("EXT_ASI") 174 flags = string.join(mem_flags, '|') 175 (header_output, 176 decoder_output, 177 exec_output, 178 decode_block) = doCasFormat(code, SwapFuncs, AlternateASIPrivFaultCheck, 179 name, Name, flags, ["IsStoreConditional"], postacc_code) 180}}; 181 182 183