1 // Copyright (c) 2007 The Regents of The University of Michigan
2 // All rights reserved.
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.
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.
27 // This template provides the execute functions for a swap
28 def template SwapExecute {{
29 Fault %(class_name)s::execute(ExecContext *xc,
30 Trace::InstRecord *traceData) const
32 Fault fault = NoFault;
33 // This is to support the conditional store in cas instructions.
34 // It should be optomized out in all the others
35 bool storeCond = true;
39 uint64_t mem_data = 0;
43 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);
45 if (fault == NoFault) {
48 if (storeCond && fault == NoFault) {
50 fault = writeMemAtomicBE(xc, traceData, Mem, EA,
51 %(asi_val)s, &mem_data);
53 if (fault == NoFault) {
54 // Handle the swapping
57 if (fault == NoFault) {
58 // Write the resulting state to the execution context
67 def template SwapInitiateAcc {{
68 Fault %(class_name)s::initiateAcc(ExecContext * xc,
69 Trace::InstRecord * traceData) const
71 Fault fault = NoFault;
74 uint64_t mem_data = 0;
79 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);
82 if (fault == NoFault) {
85 if (fault == NoFault) {
87 fault = writeMemTimingBE(xc, traceData, Mem, EA, %(asi_val)s,
96 def template SwapCompleteAcc {{
97 Fault %(class_name)s::completeAcc(PacketPtr pkt, ExecContext * xc,
98 Trace::InstRecord * traceData) const
100 Fault fault = NoFault;
103 getMemBE(pkt, Mem, traceData);
104 uint64_t mem_data = Mem;
106 if (fault == NoFault) {
107 // Handle the swapping
110 if (fault == NoFault) {
111 // Write the resulting state to the execution context
120 SwapFuncs = [SwapExecute, SwapInitiateAcc, SwapCompleteAcc]
124 def format Swap(code, postacc_code, mem_flags, *opt_flags) {{
125 mem_flags = makeList(mem_flags)
126 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ]
127 flags = string.join(mem_flags, '|')
132 decode_block) = doMemFormat(code, SwapFuncs, '', name, Name, flags,
133 ["IsStoreConditional"], postacc_code)
136 def format SwapAlt(code, postacc_code, mem_flags, *opt_flags) {{
137 mem_flags = makeList(mem_flags)
138 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ]
139 mem_flags.append("EXT_ASI")
140 flags = string.join(mem_flags, '|')
144 decode_block) = doMemFormat(code, SwapFuncs, AlternateASIPrivFaultCheck,
145 name, Name, flags, ["IsStoreConditional"], postacc_code)
150 def doCasFormat(code, execute, faultCode, name, Name, mem_flags, opt_flags, postacc_code = ''):
151 addrCalcReg = 'EA = Rs1;'
152 iop = InstObjParams(name, Name, 'Mem',
153 {"code": code, "postacc_code" : postacc_code,
154 "fault_check": faultCode, "ea_code": addrCalcReg,
155 "EA_trunc" : TruncateEA}, opt_flags)
156 header_output = MemDeclare.subst(iop)
157 decoder_output = BasicConstructor.subst(iop)
158 decode_block = BasicDecode.subst(iop)
159 microParams = {"code": code, "postacc_code" : postacc_code,
160 "ea_code" : addrCalcReg, "fault_check" : faultCode,
161 "EA_trunc" : TruncateEA}
162 exec_output = doSplitExecute(execute, name, Name, mem_flags,
163 ["IsStoreConditional"], microParams);
164 return (header_output, decoder_output, exec_output, decode_block)
168 def format CasAlt(code, postacc_code, mem_flags, *opt_flags) {{
169 mem_flags = makeList(mem_flags)
170 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ]
171 mem_flags.append("EXT_ASI")
172 flags = string.join(mem_flags, '|')
176 decode_block) = doCasFormat(code, SwapFuncs, AlternateASIPrivFaultCheck,
177 name, Name, flags, ["IsStoreConditional"], postacc_code)