mem.isa revision 12234
1// -*- mode:c++ -*- 2 3// Copyright (c) 2009 The University of Edinburgh 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: redistributions of source code must retain the above copyright 9// notice, this list of conditions and the following disclaimer; 10// redistributions in binary form must reproduce the above copyright 11// notice, this list of conditions and the following disclaimer in the 12// documentation and/or other materials provided with the distribution; 13// neither the name of the copyright holders nor the names of its 14// contributors may be used to endorse or promote products derived from 15// this software without specific prior written permission. 16// 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28// 29// Authors: Timothy M. Jones 30 31//////////////////////////////////////////////////////////////////// 32// 33// Memory-format instructions 34// 35 36def template LoadStoreDeclare {{ 37 /** 38 * Static instruction class for "%(mnemonic)s". 39 */ 40 class %(class_name)s : public %(base_class)s 41 { 42 public: 43 44 /// Constructor. 45 %(class_name)s(ExtMachInst machInst); 46 47 %(BasicExecDeclare)s 48 49 %(InitiateAccDeclare)s 50 51 %(CompleteAccDeclare)s 52 }; 53}}; 54 55 56def template InitiateAccDeclare {{ 57 Fault initiateAcc(ExecContext *, Trace::InstRecord *) const; 58}}; 59 60 61def template CompleteAccDeclare {{ 62 Fault completeAcc(PacketPtr, ExecContext *, Trace::InstRecord *) const; 63}}; 64 65 66def template LoadStoreConstructor {{ 67 %(class_name)s::%(class_name)s(ExtMachInst machInst) 68 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s) 69 { 70 %(constructor)s; 71 } 72}}; 73 74 75def template LoadExecute {{ 76 Fault %(class_name)s::execute(ExecContext *xc, 77 Trace::InstRecord *traceData) const 78 { 79 Addr EA; 80 Fault fault = NoFault; 81 82 %(op_decl)s; 83 %(op_rd)s; 84 %(ea_code)s; 85 86 if (fault == NoFault) { 87 fault = readMemAtomic(xc, traceData, EA, Mem, memAccessFlags); 88 %(memacc_code)s; 89 } 90 91 if (fault == NoFault) { 92 %(op_wb)s; 93 } 94 95 return fault; 96 } 97}}; 98 99 100def template LoadInitiateAcc {{ 101 Fault %(class_name)s::initiateAcc(ExecContext *xc, 102 Trace::InstRecord *traceData) const 103 { 104 Addr EA; 105 Fault fault = NoFault; 106 107 %(op_src_decl)s; 108 %(op_rd)s; 109 %(ea_code)s; 110 111 if (fault == NoFault) { 112 fault = initiateMemRead(xc, traceData, EA, Mem, memAccessFlags); 113 xc->setEA(EA); 114 } 115 116 return fault; 117 } 118}}; 119 120 121def template LoadCompleteAcc {{ 122 Fault %(class_name)s::completeAcc(PacketPtr pkt, 123 ExecContext *xc, 124 Trace::InstRecord *traceData) const 125 { 126 Addr M5_VAR_USED EA; 127 Fault fault = NoFault; 128 129 %(op_decl)s; 130 %(op_rd)s; 131 132 EA = xc->getEA(); 133 134 getMem(pkt, Mem, traceData); 135 136 if (fault == NoFault) { 137 %(memacc_code)s; 138 } 139 140 if (fault == NoFault) { 141 %(op_wb)s; 142 } 143 144 return fault; 145 } 146}}; 147 148 149def template StoreExecute {{ 150 Fault %(class_name)s::execute(ExecContext *xc, 151 Trace::InstRecord *traceData) const 152 { 153 Addr EA; 154 Fault fault = NoFault; 155 156 %(op_decl)s; 157 %(op_rd)s; 158 %(ea_code)s; 159 160 if (fault == NoFault) { 161 %(memacc_code)s; 162 } 163 164 if (fault == NoFault) { 165 fault = writeMemAtomic(xc, traceData, Mem, EA, memAccessFlags, 166 NULL); 167 } 168 169 if (fault == NoFault) { 170 %(op_wb)s; 171 } 172 173 return fault; 174 } 175}}; 176 177 178def template StoreInitiateAcc {{ 179 Fault %(class_name)s::initiateAcc(ExecContext *xc, 180 Trace::InstRecord *traceData) const 181 { 182 Addr EA; 183 Fault fault = NoFault; 184 185 %(op_decl)s; 186 %(op_rd)s; 187 %(ea_code)s; 188 189 if (fault == NoFault) { 190 %(memacc_code)s; 191 } 192 193 if (fault == NoFault) { 194 fault = writeMemTiming(xc, traceData, Mem, EA, memAccessFlags, 195 NULL); 196 } 197 198 // Need to write back any potential address register update 199 if (fault == NoFault) { 200 %(op_wb)s; 201 } 202 203 return fault; 204 } 205}}; 206 207 208def template StoreCompleteAcc {{ 209 Fault %(class_name)s::completeAcc(PacketPtr pkt, ExecContext *xc, 210 Trace::InstRecord *traceData) const 211 { 212 return NoFault; 213 } 214}}; 215 216 217// The generic memory operation generator. This is called when two versions 218// of an instruction are needed - when Ra == 0 and otherwise. This is so 219// that instructions can use the value 0 when Ra == 0 but avoid having a 220// dependence on Ra. 221let {{ 222 223def GenMemOp(name, Name, memacc_code, ea_code, ea_code_ra0, base, 224 load_or_store, mem_flags = [], inst_flags = []): 225 226 # First the version where Ra is non-zero 227 (header_output, decoder_output, decode_block, exec_output) = \ 228 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 229 base_class = base, 230 decode_template = CheckRaDecode, 231 exec_template_base = load_or_store) 232 233 # Now another version where Ra == 0 234 (header_output_ra0, decoder_output_ra0, _, exec_output_ra0) = \ 235 LoadStoreBase(name, Name + 'RaZero', ea_code_ra0, memacc_code, 236 mem_flags, inst_flags, 237 base_class = base, 238 exec_template_base = load_or_store) 239 240 # Finally, add to the other outputs 241 header_output += header_output_ra0 242 decoder_output += decoder_output_ra0 243 exec_output += exec_output_ra0 244 return (header_output, decoder_output, decode_block, exec_output) 245 246}}; 247 248 249def format LoadIndexOp(memacc_code, ea_code = {{ EA = Ra + Rb; }}, 250 ea_code_ra0 = {{ EA = Rb; }}, 251 mem_flags = [], inst_flags = []) {{ 252 (header_output, decoder_output, decode_block, exec_output) = \ 253 GenMemOp(name, Name, memacc_code, ea_code, ea_code_ra0, 254 'MemOp', 'Load', mem_flags, inst_flags) 255}}; 256 257 258def format StoreIndexOp(memacc_code, ea_code = {{ EA = Ra + Rb; }}, 259 ea_code_ra0 = {{ EA = Rb; }}, 260 mem_flags = [], inst_flags = []) {{ 261 (header_output, decoder_output, decode_block, exec_output) = \ 262 GenMemOp(name, Name, memacc_code, ea_code, ea_code_ra0, 263 'MemOp', 'Store', mem_flags, inst_flags) 264}}; 265 266 267def format LoadIndexUpdateOp(memacc_code, ea_code = {{ EA = Ra + Rb; }}, 268 mem_flags = [], inst_flags = []) {{ 269 270 # Add in the update code 271 memacc_code += 'Ra = EA;' 272 273 # Generate the class 274 (header_output, decoder_output, decode_block, exec_output) = \ 275 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 276 base_class = 'MemOp', 277 exec_template_base = 'Load') 278}}; 279 280 281def format StoreIndexUpdateOp(memacc_code, ea_code = {{ EA = Ra + Rb; }}, 282 mem_flags = [], inst_flags = []) {{ 283 284 # Add in the update code 285 memacc_code += 'Ra = EA;' 286 287 # Generate the class 288 (header_output, decoder_output, decode_block, exec_output) = \ 289 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 290 base_class = 'MemOp', 291 exec_template_base = 'Store') 292}}; 293 294 295def format LoadDispOp(memacc_code, ea_code = {{ EA = Ra + disp; }}, 296 ea_code_ra0 = {{ EA = disp; }}, 297 mem_flags = [], inst_flags = []) {{ 298 (header_output, decoder_output, decode_block, exec_output) = \ 299 GenMemOp(name, Name, memacc_code, ea_code, ea_code_ra0, 300 'MemDispOp', 'Load', mem_flags, inst_flags) 301}}; 302 303 304def format StoreDispOp(memacc_code, ea_code = {{ EA = Ra + disp; }}, 305 ea_code_ra0 = {{ EA = disp; }}, 306 mem_flags = [], inst_flags = []) {{ 307 (header_output, decoder_output, decode_block, exec_output) = \ 308 GenMemOp(name, Name, memacc_code, ea_code, ea_code_ra0, 309 'MemDispOp', 'Store', mem_flags, inst_flags) 310}}; 311 312 313def format LoadDispUpdateOp(memacc_code, ea_code = {{ EA = Ra + disp; }}, 314 mem_flags = [], inst_flags = []) {{ 315 316 # Add in the update code 317 memacc_code += 'Ra = EA;' 318 319 # Generate the class 320 (header_output, decoder_output, decode_block, exec_output) = \ 321 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 322 base_class = 'MemDispOp', 323 exec_template_base = 'Load') 324}}; 325 326 327def format StoreDispUpdateOp(memacc_code, ea_code = {{ EA = Ra + disp; }}, 328 mem_flags = [], inst_flags = []) {{ 329 330 # Add in the update code 331 memacc_code += 'Ra = EA;' 332 333 # Generate the class 334 (header_output, decoder_output, decode_block, exec_output) = \ 335 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 336 base_class = 'MemDispOp', 337 exec_template_base = 'Store') 338}}; 339