7a287066b351d075ae7b7985263098e6f9bbfa1a
[gem5.git] / src / arch / sparc / isa / formats / mem / swap.isa
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 // 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
31 {
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;
36 Addr EA;
37 %(fp_enable_check)s;
38 %(op_decl)s;
39 uint64_t mem_data = 0;
40
41 %(op_rd)s;
42 %(ea_code)s;
43 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);
44 %(fault_check)s;
45 if (fault == NoFault) {
46 %(code)s;
47 }
48 if (storeCond && fault == NoFault) {
49 %(EA_trunc)s
50 fault = writeMemAtomicBE(xc, traceData, Mem, EA,
51 %(asi_val)s, &mem_data);
52 }
53 if (fault == NoFault) {
54 // Handle the swapping
55 %(postacc_code)s;
56 }
57 if (fault == NoFault) {
58 // Write the resulting state to the execution context
59 %(op_wb)s;
60 }
61
62 return fault;
63 }
64 }};
65
66
67 def template SwapInitiateAcc {{
68 Fault %(class_name)s::initiateAcc(ExecContext * xc,
69 Trace::InstRecord * traceData) const
70 {
71 Fault fault = NoFault;
72 Addr EA;
73 %(fp_enable_check)s;
74 uint64_t mem_data = 0;
75 %(op_decl)s;
76 %(op_rd)s;
77 %(ea_code)s;
78
79 DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);
80 %(fault_check)s;
81
82 if (fault == NoFault) {
83 %(code)s;
84 }
85 if (fault == NoFault) {
86 %(EA_trunc)s
87 fault = writeMemTimingBE(xc, traceData, Mem, EA, %(asi_val)s,
88 &mem_data);
89 }
90 return fault;
91 }
92 }};
93
94
95
96 def template SwapCompleteAcc {{
97 Fault %(class_name)s::completeAcc(PacketPtr pkt, ExecContext * xc,
98 Trace::InstRecord * traceData) const
99 {
100 Fault fault = NoFault;
101 %(op_decl)s;
102
103 getMemBE(pkt, Mem, traceData);
104 uint64_t mem_data = Mem;
105
106 if (fault == NoFault) {
107 // Handle the swapping
108 %(postacc_code)s;
109 }
110 if (fault == NoFault) {
111 // Write the resulting state to the execution context
112 %(op_wb)s;
113 }
114
115 return fault;
116 }
117 }};
118
119 let {{
120 SwapFuncs = [SwapExecute, SwapInitiateAcc, SwapCompleteAcc]
121 }};
122
123
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, '|')
128
129 (header_output,
130 decoder_output,
131 exec_output,
132 decode_block) = doMemFormat(code, SwapFuncs, '', name, Name, flags,
133 ["IsStoreConditional"], postacc_code)
134 }};
135
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, '|')
141 (header_output,
142 decoder_output,
143 exec_output,
144 decode_block) = doMemFormat(code, SwapFuncs, AlternateASIPrivFaultCheck,
145 name, Name, flags, ["IsStoreConditional"], postacc_code)
146 }};
147
148
149 let {{
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)
165 }};
166
167
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, '|')
173 (header_output,
174 decoder_output,
175 exec_output,
176 decode_block) = doCasFormat(code, SwapFuncs, AlternateASIPrivFaultCheck,
177 name, Name, flags, ["IsStoreConditional"], postacc_code)
178 }};
179
180