mem.isa revision 4056:f8f1dffc5913
12650Ssaidi@eecs.umich.edu// -*- mode:c++ -*-
22650Ssaidi@eecs.umich.edu
32650Ssaidi@eecs.umich.edu// Copyright (c) 2006 The Regents of The University of Michigan
42650Ssaidi@eecs.umich.edu// All rights reserved.
52650Ssaidi@eecs.umich.edu//
62650Ssaidi@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
72650Ssaidi@eecs.umich.edu// modification, are permitted provided that the following conditions are
82650Ssaidi@eecs.umich.edu// met: redistributions of source code must retain the above copyright
92650Ssaidi@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
102650Ssaidi@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
112650Ssaidi@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
122650Ssaidi@eecs.umich.edu// documentation and/or other materials provided with the distribution;
132650Ssaidi@eecs.umich.edu// neither the name of the copyright holders nor the names of its
142650Ssaidi@eecs.umich.edu// contributors may be used to endorse or promote products derived from
152650Ssaidi@eecs.umich.edu// this software without specific prior written permission.
162650Ssaidi@eecs.umich.edu//
172650Ssaidi@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182650Ssaidi@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192650Ssaidi@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202650Ssaidi@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212650Ssaidi@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222650Ssaidi@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232650Ssaidi@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242650Ssaidi@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252650Ssaidi@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262650Ssaidi@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272650Ssaidi@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282650Ssaidi@eecs.umich.edu//
292650Ssaidi@eecs.umich.edu// Authors: Steve Reinhardt
302650Ssaidi@eecs.umich.edu//          Korey Sewell
312650Ssaidi@eecs.umich.edu
322650Ssaidi@eecs.umich.edu////////////////////////////////////////////////////////////////////
332650Ssaidi@eecs.umich.edu//
3410687SAndreas.Sandberg@ARM.com// Memory-format instructions
353836Ssaidi@eecs.umich.edu//
363804Ssaidi@eecs.umich.edu
3712334Sgabeblack@google.comoutput header {{
383569Sgblack@eecs.umich.edu    /**
396022Sgblack@eecs.umich.edu     * Base class for general Mips memory-format instructions.
403468Sgblack@eecs.umich.edu     */
413468Sgblack@eecs.umich.edu    class Memory : public MipsStaticInst
423806Ssaidi@eecs.umich.edu    {
433468Sgblack@eecs.umich.edu      protected:
443468Sgblack@eecs.umich.edu
453468Sgblack@eecs.umich.edu        /// Memory request flags.  See mem_req_base.hh.
463603Ssaidi@eecs.umich.edu        unsigned memAccessFlags;
4713913Sgabeblack@google.com        /// Pointer to EAComp object.
4813913Sgabeblack@google.com        const StaticInstPtr eaCompPtr;
4913913Sgabeblack@google.com        /// Pointer to MemAcc object.
5013913Sgabeblack@google.com        const StaticInstPtr memAccPtr;
5113913Sgabeblack@google.com
525358Sgblack@eecs.umich.edu        /// Displacement for EA calculation (signed).
533804Ssaidi@eecs.umich.edu        int32_t disp;
547741Sgblack@eecs.umich.edu
554997Sgblack@eecs.umich.edu        /// Constructor
564997Sgblack@eecs.umich.edu        Memory(const char *mnem, MachInst _machInst, OpClass __opClass,
574997Sgblack@eecs.umich.edu               StaticInstPtr _eaCompPtr = nullStaticInstPtr,
587741Sgblack@eecs.umich.edu               StaticInstPtr _memAccPtr = nullStaticInstPtr)
594990Sgblack@eecs.umich.edu            : MipsStaticInst(mnem, _machInst, __opClass),
606022Sgblack@eecs.umich.edu              memAccessFlags(0), eaCompPtr(_eaCompPtr), memAccPtr(_memAccPtr),
616022Sgblack@eecs.umich.edu              disp(sext<16>(OFFSET))
624990Sgblack@eecs.umich.edu        {
634990Sgblack@eecs.umich.edu        }
644990Sgblack@eecs.umich.edu
654990Sgblack@eecs.umich.edu        std::string
664990Sgblack@eecs.umich.edu        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
674990Sgblack@eecs.umich.edu
684990Sgblack@eecs.umich.edu      public:
694990Sgblack@eecs.umich.edu
704990Sgblack@eecs.umich.edu        const StaticInstPtr &eaCompInst() const { return eaCompPtr; }
713804Ssaidi@eecs.umich.edu        const StaticInstPtr &memAccInst() const { return memAccPtr; }
723804Ssaidi@eecs.umich.edu    };
733804Ssaidi@eecs.umich.edu
743804Ssaidi@eecs.umich.edu     /**
753804Ssaidi@eecs.umich.edu     * Base class for a few miscellaneous memory-format insts
763804Ssaidi@eecs.umich.edu     * that don't interpret the disp field
773804Ssaidi@eecs.umich.edu     */
783804Ssaidi@eecs.umich.edu    class MemoryNoDisp : public Memory
793881Ssaidi@eecs.umich.edu    {
803804Ssaidi@eecs.umich.edu      protected:
813836Ssaidi@eecs.umich.edu        /// Constructor
823836Ssaidi@eecs.umich.edu        MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
833836Ssaidi@eecs.umich.edu                     StaticInstPtr _eaCompPtr = nullStaticInstPtr,
843881Ssaidi@eecs.umich.edu                     StaticInstPtr _memAccPtr = nullStaticInstPtr)
853881Ssaidi@eecs.umich.edu            : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr)
863804Ssaidi@eecs.umich.edu        {
873804Ssaidi@eecs.umich.edu        }
883804Ssaidi@eecs.umich.edu
893804Ssaidi@eecs.umich.edu        std::string
903804Ssaidi@eecs.umich.edu        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
913804Ssaidi@eecs.umich.edu    };
923804Ssaidi@eecs.umich.edu}};
933804Ssaidi@eecs.umich.edu
943804Ssaidi@eecs.umich.edu
953468Sgblack@eecs.umich.eduoutput decoder {{
963468Sgblack@eecs.umich.edu    std::string
973804Ssaidi@eecs.umich.edu    Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
983804Ssaidi@eecs.umich.edu    {
993804Ssaidi@eecs.umich.edu        return csprintf("%-10s %c%d, %d(r%d)", mnemonic,
1003804Ssaidi@eecs.umich.edu                        flags[IsFloating] ? 'f' : 'r', RT, disp, RS);
1013468Sgblack@eecs.umich.edu    }
1023468Sgblack@eecs.umich.edu
1034070Ssaidi@eecs.umich.edu    std::string
1044070Ssaidi@eecs.umich.edu    MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
1054070Ssaidi@eecs.umich.edu    {
1064070Ssaidi@eecs.umich.edu        return csprintf("%-10s %c%d, r%d(r%d)", mnemonic,
1074070Ssaidi@eecs.umich.edu                        flags[IsFloating] ? 'f' : 'r',
1083804Ssaidi@eecs.umich.edu                        flags[IsFloating] ? FD : RD,
1093804Ssaidi@eecs.umich.edu                        RS, RT);
1103804Ssaidi@eecs.umich.edu    }
1113804Ssaidi@eecs.umich.edu}};
1123804Ssaidi@eecs.umich.edu
1133804Ssaidi@eecs.umich.edudef template LoadStoreDeclare {{
1145555Snate@binkert.org    /**
1155555Snate@binkert.org     * Static instruction class for "%(mnemonic)s".
1165555Snate@binkert.org     */
1173804Ssaidi@eecs.umich.edu    class %(class_name)s : public %(base_class)s
1183804Ssaidi@eecs.umich.edu    {
1194070Ssaidi@eecs.umich.edu      protected:
1204070Ssaidi@eecs.umich.edu
1219446SAndreas.Sandberg@ARM.com        /**
1229446SAndreas.Sandberg@ARM.com         * "Fake" effective address computation class for "%(mnemonic)s".
12311341Sandreas.hansson@arm.com         */
1249446SAndreas.Sandberg@ARM.com        class EAComp : public %(base_class)s
1254070Ssaidi@eecs.umich.edu        {
1263804Ssaidi@eecs.umich.edu          public:
1273804Ssaidi@eecs.umich.edu            /// Constructor
1283826Ssaidi@eecs.umich.edu            EAComp(MachInst machInst);
1293804Ssaidi@eecs.umich.edu
1303804Ssaidi@eecs.umich.edu            %(BasicExecDeclare)s
1313804Ssaidi@eecs.umich.edu        };
1323804Ssaidi@eecs.umich.edu
1333804Ssaidi@eecs.umich.edu        /**
1343804Ssaidi@eecs.umich.edu         * "Fake" memory access instruction class for "%(mnemonic)s".
1353804Ssaidi@eecs.umich.edu         */
1363804Ssaidi@eecs.umich.edu        class MemAcc : public %(base_class)s
1373804Ssaidi@eecs.umich.edu        {
1383804Ssaidi@eecs.umich.edu          public:
1393804Ssaidi@eecs.umich.edu            /// Constructor
1403804Ssaidi@eecs.umich.edu            MemAcc(MachInst machInst);
1413804Ssaidi@eecs.umich.edu
1423804Ssaidi@eecs.umich.edu            %(BasicExecDeclare)s
1433804Ssaidi@eecs.umich.edu        };
1443804Ssaidi@eecs.umich.edu
1453804Ssaidi@eecs.umich.edu      public:
1464990Sgblack@eecs.umich.edu
1473804Ssaidi@eecs.umich.edu        /// Constructor.
1483804Ssaidi@eecs.umich.edu        %(class_name)s(MachInst machInst);
1493834Sgblack@eecs.umich.edu
1503804Ssaidi@eecs.umich.edu        %(BasicExecDeclare)s
1513804Ssaidi@eecs.umich.edu
1524990Sgblack@eecs.umich.edu        %(InitiateAccDeclare)s
1533826Ssaidi@eecs.umich.edu
15412749Sgiacomo.travaglini@arm.com        %(CompleteAccDeclare)s
15512749Sgiacomo.travaglini@arm.com    };
1566022Sgblack@eecs.umich.edu}};
1573804Ssaidi@eecs.umich.edu
1585034Smilesck@eecs.umich.edu
1595034Smilesck@eecs.umich.edudef template InitiateAccDeclare {{
1603804Ssaidi@eecs.umich.edu    Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
16111341Sandreas.hansson@arm.com}};
16210194SGeoffrey.Blake@arm.com
1637741Sgblack@eecs.umich.edu
16411341Sandreas.hansson@arm.comdef template CompleteAccDeclare {{
1655358Sgblack@eecs.umich.edu    Fault completeAcc(PacketPtr, %(CPU_exec_context)s *, Trace::InstRecord *) const;
1665358Sgblack@eecs.umich.edu}};
1675358Sgblack@eecs.umich.edu
1685358Sgblack@eecs.umich.edu
1693826Ssaidi@eecs.umich.edudef template EACompConstructor {{
1703826Ssaidi@eecs.umich.edu    /** TODO: change op_class to AddrGenOp or something (requires
17112406Sgabeblack@google.com     * creating new member of OpClass enum in op_class.hh, updating
17212749Sgiacomo.travaglini@arm.com     * config files, etc.). */
17312406Sgabeblack@google.com    inline %(class_name)s::EAComp::EAComp(MachInst machInst)
17412749Sgiacomo.travaglini@arm.com        : %(base_class)s("%(mnemonic)s (EAComp)", machInst, IntAluOp)
17512406Sgabeblack@google.com    {
17612406Sgabeblack@google.com        %(constructor)s;
17712749Sgiacomo.travaglini@arm.com    }
17812749Sgiacomo.travaglini@arm.com}};
1799180Sandreas.hansson@arm.com
1809180Sandreas.hansson@arm.com
1814070Ssaidi@eecs.umich.edudef template MemAccConstructor {{
1823804Ssaidi@eecs.umich.edu    inline %(class_name)s::MemAcc::MemAcc(MachInst machInst)
1834990Sgblack@eecs.umich.edu        : %(base_class)s("%(mnemonic)s (MemAcc)", machInst, %(op_class)s)
18411168Sandreas.hansson@arm.com    {
18511168Sandreas.hansson@arm.com        %(constructor)s;
1864990Sgblack@eecs.umich.edu    }
1876022Sgblack@eecs.umich.edu}};
1886022Sgblack@eecs.umich.edu
1896022Sgblack@eecs.umich.edu
1903804Ssaidi@eecs.umich.edudef template LoadStoreConstructor {{
1914990Sgblack@eecs.umich.edu    inline %(class_name)s::%(class_name)s(MachInst machInst)
1923804Ssaidi@eecs.umich.edu         : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
1933826Ssaidi@eecs.umich.edu                          new EAComp(machInst), new MemAcc(machInst))
1944070Ssaidi@eecs.umich.edu    {
1954070Ssaidi@eecs.umich.edu        %(constructor)s;
1964070Ssaidi@eecs.umich.edu    }
1974070Ssaidi@eecs.umich.edu}};
1983836Ssaidi@eecs.umich.edu
1993836Ssaidi@eecs.umich.edu
2003804Ssaidi@eecs.umich.edudef template EACompExecute {{
2013804Ssaidi@eecs.umich.edu    Fault
2023468Sgblack@eecs.umich.edu    %(class_name)s::EAComp::execute(%(CPU_exec_context)s *xc,
2032650Ssaidi@eecs.umich.edu                                   Trace::InstRecord *traceData) const
2042650Ssaidi@eecs.umich.edu    {
205        Addr EA;
206        Fault fault = NoFault;
207
208        %(fp_enable_check)s;
209        %(op_decl)s;
210        %(op_rd)s;
211        %(ea_code)s;
212
213        if (fault == NoFault) {
214            %(op_wb)s;
215            xc->setEA(EA);
216        }
217
218        return fault;
219    }
220}};
221
222def template LoadMemAccExecute {{
223    Fault
224    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
225                                   Trace::InstRecord *traceData) const
226    {
227        Addr EA;
228        Fault fault = NoFault;
229
230        %(fp_enable_check)s;
231        %(op_decl)s;
232        %(op_rd)s;
233        EA = xc->getEA();
234
235        if (fault == NoFault) {
236            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
237            %(memacc_code)s;
238        }
239
240        if (fault == NoFault) {
241            %(op_wb)s;
242        }
243
244        return fault;
245    }
246}};
247
248
249def template LoadExecute {{
250    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
251                                  Trace::InstRecord *traceData) const
252    {
253        Addr EA;
254        Fault fault = NoFault;
255
256        %(fp_enable_check)s;
257        %(op_decl)s;
258        %(op_rd)s;
259        %(ea_code)s;
260
261        if (fault == NoFault) {
262            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
263            %(memacc_code)s;
264        }
265
266        if (fault == NoFault) {
267            %(op_wb)s;
268        }
269
270        return fault;
271    }
272}};
273
274
275def template LoadInitiateAcc {{
276    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
277                                      Trace::InstRecord *traceData) const
278    {
279        Addr EA;
280        Fault fault = NoFault;
281
282        %(fp_enable_check)s;
283        %(op_src_decl)s;
284        %(op_rd)s;
285        %(ea_code)s;
286
287        if (fault == NoFault) {
288            fault = xc->read(EA, (uint%(mem_acc_size)d_t &)Mem, memAccessFlags);
289        }
290
291        return fault;
292    }
293}};
294
295
296def template LoadCompleteAcc {{
297    Fault %(class_name)s::completeAcc(PacketPtr pkt,
298                                      %(CPU_exec_context)s *xc,
299                                      Trace::InstRecord *traceData) const
300    {
301        Fault fault = NoFault;
302
303        %(fp_enable_check)s;
304        %(op_decl)s;
305
306        Mem = pkt->get<typeof(Mem)>();
307
308        if (fault == NoFault) {
309            %(memacc_code)s;
310        }
311
312        if (fault == NoFault) {
313            %(op_wb)s;
314        }
315
316        return fault;
317    }
318}};
319
320
321def template StoreMemAccExecute {{
322    Fault
323    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
324                                   Trace::InstRecord *traceData) const
325    {
326        Addr EA;
327        Fault fault = NoFault;
328
329        %(fp_enable_check)s;
330        %(op_decl)s;
331        %(op_rd)s;
332        EA = xc->getEA();
333
334        if (fault == NoFault) {
335            %(memacc_code)s;
336        }
337
338        if (fault == NoFault) {
339            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
340                              memAccessFlags, NULL);
341            if (traceData) { traceData->setData(Mem); }
342        }
343
344        if (fault == NoFault) {
345            %(postacc_code)s;
346        }
347
348        if (fault == NoFault) {
349            %(op_wb)s;
350        }
351
352        return fault;
353    }
354}};
355
356def template StoreCondMemAccExecute {{
357    Fault
358    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
359                                   Trace::InstRecord *traceData) const
360    {
361        Addr EA;
362        Fault fault = NoFault;
363        uint64_t write_result = 0;
364
365        %(fp_enable_check)s;
366        %(op_decl)s;
367        %(op_rd)s;
368        EA = xc->getEA();
369
370        if (fault == NoFault) {
371            %(memacc_code)s;
372        }
373
374        if (fault == NoFault) {
375            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
376                              memAccessFlags, &write_result);
377            if (traceData) { traceData->setData(Mem); }
378        }
379
380        if (fault == NoFault) {
381            %(postacc_code)s;
382        }
383
384        if (fault == NoFault) {
385            %(op_wb)s;
386        }
387
388        return fault;
389    }
390}};
391
392
393def template StoreExecute {{
394    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
395                                  Trace::InstRecord *traceData) const
396    {
397        Addr EA;
398        Fault fault = NoFault;
399
400        %(fp_enable_check)s;
401        %(op_decl)s;
402        %(op_rd)s;
403        %(ea_code)s;
404
405        if (fault == NoFault) {
406            %(memacc_code)s;
407        }
408
409        if (fault == NoFault) {
410            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
411                              memAccessFlags, NULL);
412            if (traceData) { traceData->setData(Mem); }
413        }
414
415        if (fault == NoFault) {
416            %(postacc_code)s;
417        }
418
419        if (fault == NoFault) {
420            %(op_wb)s;
421        }
422
423        return fault;
424    }
425}};
426
427def template StoreCondExecute {{
428    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
429                                  Trace::InstRecord *traceData) const
430    {
431        Addr EA;
432        Fault fault = NoFault;
433        uint64_t write_result = 0;
434
435        %(fp_enable_check)s;
436        %(op_decl)s;
437        %(op_rd)s;
438        %(ea_code)s;
439
440        if (fault == NoFault) {
441            %(memacc_code)s;
442        }
443
444        if (fault == NoFault) {
445            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
446                              memAccessFlags, &write_result);
447            if (traceData) { traceData->setData(Mem); }
448        }
449
450        if (fault == NoFault) {
451            %(postacc_code)s;
452        }
453
454        if (fault == NoFault) {
455            %(op_wb)s;
456        }
457
458        return fault;
459    }
460}};
461
462def template StoreInitiateAcc {{
463    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
464                                      Trace::InstRecord *traceData) const
465    {
466        Addr EA;
467        Fault fault = NoFault;
468
469        %(fp_enable_check)s;
470        %(op_decl)s;
471        %(op_rd)s;
472        %(ea_code)s;
473
474        if (fault == NoFault) {
475            %(memacc_code)s;
476        }
477
478        if (fault == NoFault) {
479            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
480                              memAccessFlags, NULL);
481            if (traceData) { traceData->setData(Mem); }
482        }
483
484        return fault;
485    }
486}};
487
488
489def template StoreCompleteAcc {{
490    Fault %(class_name)s::completeAcc(PacketPtr pkt,
491                                      %(CPU_exec_context)s *xc,
492                                      Trace::InstRecord *traceData) const
493    {
494        Fault fault = NoFault;
495
496        %(fp_enable_check)s;
497        %(op_dest_decl)s;
498
499        if (fault == NoFault) {
500            %(postacc_code)s;
501        }
502
503        if (fault == NoFault) {
504            %(op_wb)s;
505        }
506
507        return fault;
508    }
509}};
510
511def template StoreCondCompleteAcc {{
512    Fault %(class_name)s::completeAcc(PacketPtr pkt,
513                                      %(CPU_exec_context)s *xc,
514                                      Trace::InstRecord *traceData) const
515    {
516        Fault fault = NoFault;
517
518        %(fp_enable_check)s;
519        %(op_dest_decl)s;
520
521        uint64_t write_result = pkt->req->getExtraData();
522
523        if (fault == NoFault) {
524            %(postacc_code)s;
525        }
526
527        if (fault == NoFault) {
528            %(op_wb)s;
529        }
530
531        return fault;
532    }
533}};
534
535
536def template MiscMemAccExecute {{
537    Fault %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
538                                          Trace::InstRecord *traceData) const
539    {
540        Addr EA;
541        Fault fault = NoFault;
542
543        %(fp_enable_check)s;
544        %(op_decl)s;
545        %(op_rd)s;
546        EA = xc->getEA();
547
548        if (fault == NoFault) {
549            %(memacc_code)s;
550        }
551
552        return NoFault;
553    }
554}};
555
556def template MiscExecute {{
557    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
558                                  Trace::InstRecord *traceData) const
559    {
560        Addr EA;
561        Fault fault = NoFault;
562
563        %(fp_enable_check)s;
564        %(op_decl)s;
565        %(op_rd)s;
566        %(ea_code)s;
567
568        if (fault == NoFault) {
569            %(memacc_code)s;
570        }
571
572        return NoFault;
573    }
574}};
575
576def template MiscInitiateAcc {{
577    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
578                                      Trace::InstRecord *traceData) const
579    {
580        panic("Misc instruction does not support split access method!");
581        return NoFault;
582    }
583}};
584
585
586def template MiscCompleteAcc {{
587    Fault %(class_name)s::completeAcc(PacketPtr pkt,
588                                      %(CPU_exec_context)s *xc,
589                                      Trace::InstRecord *traceData) const
590    {
591        panic("Misc instruction does not support split access method!");
592
593        return NoFault;
594    }
595}};
596
597def format LoadMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
598                     mem_flags = [], inst_flags = []) {{
599    (header_output, decoder_output, decode_block, exec_output) = \
600        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
601                      decode_template = ImmNopCheckDecode,
602                      exec_template_base = 'Load')
603}};
604
605def format StoreMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
606                     mem_flags = [], inst_flags = []) {{
607    (header_output, decoder_output, decode_block, exec_output) = \
608        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
609                      exec_template_base = 'Store')
610}};
611
612def format LoadIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
613                     mem_flags = [], inst_flags = []) {{
614    (header_output, decoder_output, decode_block, exec_output) = \
615        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
616                      decode_template = ImmNopCheckDecode,
617                      exec_template_base = 'Load')
618}};
619
620def format StoreIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
621                     mem_flags = [], inst_flags = []) {{
622    (header_output, decoder_output, decode_block, exec_output) = \
623        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
624                      exec_template_base = 'Store')
625}};
626
627def format LoadUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
628                     mem_flags = [], inst_flags = []) {{
629    decl_code = 'uint32_t mem_word = Mem.uw;\n'
630    decl_code += 'uint32_t unalign_addr = Rs + disp;\n'
631    decl_code += 'uint32_t byte_offset = unalign_addr & 3;\n'
632    decl_code += '#if BYTE_ORDER == BIG_ENDIAN\n'
633    decl_code += '\tbyte_offset ^= 3;\n'
634    decl_code += '#endif\n'
635
636    memacc_code = decl_code + memacc_code
637
638    (header_output, decoder_output, decode_block, exec_output) = \
639        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
640                      decode_template = ImmNopCheckDecode,
641                      exec_template_base = 'Load')
642}};
643
644def format StoreUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
645                     mem_flags = [], inst_flags = []) {{
646    decl_code = 'uint32_t mem_word = 0;\n'
647    decl_code += 'uint32_t unaligned_addr = Rs + disp;\n'
648    decl_code += 'uint32_t byte_offset = unaligned_addr & 3;\n'
649    decl_code += '#if BYTE_ORDER == BIG_ENDIAN\n'
650    decl_code += '\tbyte_offset ^= 3;\n'
651    decl_code += '#endif\n'
652    decl_code += 'fault = xc->read(EA, (uint32_t&)mem_word, memAccessFlags);\n'
653    memacc_code = decl_code + memacc_code + '\nMem = mem_word;\n'
654
655    (header_output, decoder_output, decode_block, exec_output) = \
656        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
657                      exec_template_base = 'Store')
658}};
659
660def format Prefetch(ea_code = {{ EA = Rs + disp; }},
661                          mem_flags = [], pf_flags = [], inst_flags = []) {{
662    pf_mem_flags = mem_flags + pf_flags + ['NO_FAULT']
663    pf_inst_flags = inst_flags + ['IsMemRef', 'IsLoad',
664                                  'IsDataPrefetch', 'MemReadOp']
665
666    (header_output, decoder_output, decode_block, exec_output) = \
667        LoadStoreBase(name, Name, ea_code,
668                      'xc->prefetch(EA, memAccessFlags);',
669                      pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
670
671}};
672
673def format StoreCond(memacc_code, postacc_code,
674                     ea_code = {{ EA = Rs + disp; }},
675                     mem_flags = [], inst_flags = []) {{
676    (header_output, decoder_output, decode_block, exec_output) = \
677        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
678                      postacc_code, exec_template_base = 'StoreCond')
679}};
680