swap.isa revision 5736:426510e758ad
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 { 50 %(code)s; 51 } 52 if(storeCond && fault == NoFault) 53 { 54 %(EA_trunc)s 55 fault = xc->write((uint%(mem_acc_size)s_t)Mem, 56 EA, %(asi_val)s, &mem_data); 57 } 58 if(fault == NoFault) 59 { 60 //Handle the swapping 61 %(postacc_code)s; 62 } 63 if(fault == NoFault) 64 { 65 //Write the resulting state to the execution context 66 %(op_wb)s; 67 } 68 69 return fault; 70 } 71}}; 72 73 74def template SwapInitiateAcc {{ 75 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s * xc, 76 Trace::InstRecord * traceData) const 77 { 78 Fault fault = NoFault; 79 Addr EA; 80 %(fp_enable_check)s; 81 uint64_t mem_data = 0; 82 %(op_decl)s; 83 %(op_rd)s; 84 %(ea_code)s; 85 86 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA); 87 %(fault_check)s; 88 89 if(fault == NoFault) 90 { 91 %(code)s; 92 } 93 if(fault == NoFault) 94 { 95 %(EA_trunc)s 96 fault = xc->write((uint%(mem_acc_size)s_t)Mem, 97 EA, %(asi_val)s, &mem_data); 98 } 99 return fault; 100 } 101}}; 102 103 104 105def template SwapCompleteAcc {{ 106 Fault %(class_name)s::completeAcc(PacketPtr pkt, %(CPU_exec_context)s * xc, 107 Trace::InstRecord * traceData) const 108 { 109 Fault fault = NoFault; 110 %(op_decl)s; 111 112 uint64_t mem_data = pkt->get<uint%(mem_acc_size)s_t>(); 113 114 if(fault == NoFault) 115 { 116 //Handle the swapping 117 %(postacc_code)s; 118 } 119 if(fault == NoFault) 120 { 121 //Write the resulting state to the execution context 122 %(op_wb)s; 123 } 124 125 return fault; 126 } 127}}; 128 129let {{ 130 SwapFuncs = [SwapExecute, SwapInitiateAcc, SwapCompleteAcc] 131}}; 132 133 134def format Swap(code, postacc_code, mem_flags, *opt_flags) {{ 135 mem_flags = makeList(mem_flags) 136 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 137 flags = string.join(mem_flags, '|') 138 139 (header_output, 140 decoder_output, 141 exec_output, 142 decode_block) = doMemFormat(code, SwapFuncs, '', name, Name, flags, 143 ["IsStoreConditional"], postacc_code) 144}}; 145 146def format SwapAlt(code, postacc_code, mem_flags, *opt_flags) {{ 147 mem_flags = makeList(mem_flags) 148 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 149 mem_flags.append("EXT_ASI") 150 flags = string.join(mem_flags, '|') 151 (header_output, 152 decoder_output, 153 exec_output, 154 decode_block) = doMemFormat(code, SwapFuncs, AlternateASIPrivFaultCheck, 155 name, Name, flags, ["IsStoreConditional"], postacc_code) 156}}; 157 158 159let {{ 160 def doCasFormat(code, execute, faultCode, name, Name, mem_flags, opt_flags, postacc_code = ''): 161 addrCalcReg = 'EA = Rs1;' 162 iop = InstObjParams(name, Name, 'Mem', 163 {"code": code, "postacc_code" : postacc_code, 164 "fault_check": faultCode, "ea_code": addrCalcReg, 165 "EA_trunc" : TruncateEA}, opt_flags) 166 header_output = MemDeclare.subst(iop) 167 decoder_output = BasicConstructor.subst(iop) 168 decode_block = BasicDecode.subst(iop) 169 microParams = {"code": code, "postacc_code" : postacc_code, 170 "ea_code" : addrCalcReg, "fault_check" : faultCode, 171 "EA_trunc" : TruncateEA} 172 exec_output = doSplitExecute(execute, name, Name, mem_flags, 173 ["IsStoreConditional"], microParams); 174 return (header_output, decoder_output, exec_output, decode_block) 175}}; 176 177 178def format CasAlt(code, postacc_code, mem_flags, *opt_flags) {{ 179 mem_flags = makeList(mem_flags) 180 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 181 mem_flags.append("EXT_ASI") 182 flags = string.join(mem_flags, '|') 183 (header_output, 184 decoder_output, 185 exec_output, 186 decode_block) = doCasFormat(code, SwapFuncs, AlternateASIPrivFaultCheck, 187 name, Name, flags, ["IsStoreConditional"], postacc_code) 188}}; 189 190 191