3 // Copyright (c) 2003-2005 The Regents of The University of Michigan
4 // All rights reserved.
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.
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.
29 // Authors: Steve Reinhardt
32 ////////////////////////////////////////////////////////////////////
34 // Memory-format instructions: LoadAddress, Load, Store
39 * Base class for general Alpha memory-format instructions.
41 class Memory : public AlphaStaticInst
45 /// Memory request flags. See mem_req_base.hh.
46 Request::Flags memAccessFlags;
49 Memory(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
50 : AlphaStaticInst(mnem, _machInst, __opClass)
55 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
59 * Base class for memory-format instructions using a 32-bit
60 * displacement (i.e. most of them).
62 class MemoryDisp32 : public Memory
65 /// Displacement for EA calculation (signed).
69 MemoryDisp32(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
70 : Memory(mnem, _machInst, __opClass),
78 * Base class for a few miscellaneous memory-format insts
79 * that don't interpret the disp field: wh64, fetch, fetch_m, ecb.
80 * None of these instructions has a destination register either.
82 class MemoryNoDisp : public Memory
86 MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
87 : Memory(mnem, _machInst, __opClass)
92 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
99 Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
101 return csprintf("%-10s %c%d,%d(r%d)", mnemonic,
102 flags[IsFloating] ? 'f' : 'r', RA, MEMDISP, RB);
106 MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
108 return csprintf("%-10s (r%d)", mnemonic, RB);
112 def format LoadAddress(code) {{
113 iop = InstObjParams(name, Name, 'MemoryDisp32', code)
114 header_output = BasicDeclare.subst(iop)
115 decoder_output = BasicConstructor.subst(iop)
116 decode_block = BasicDecode.subst(iop)
117 exec_output = BasicExecute.subst(iop)
121 def template LoadStoreDeclare {{
123 * Static instruction class for "%(mnemonic)s".
125 class %(class_name)s : public %(base_class)s
130 %(class_name)s(ExtMachInst machInst);
136 %(InitiateAccDeclare)s
138 %(CompleteAccDeclare)s
143 def template EACompDeclare {{
144 Fault eaComp(%(CPU_exec_context)s *, Trace::InstRecord *) const;
147 def template InitiateAccDeclare {{
148 Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
152 def template CompleteAccDeclare {{
153 Fault completeAcc(PacketPtr, %(CPU_exec_context)s *,
154 Trace::InstRecord *) const;
157 def template LoadStoreConstructor {{
158 %(class_name)s::%(class_name)s(ExtMachInst machInst)
159 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
165 def template EACompExecute {{
166 Fault %(class_name)s::eaComp(CPU_EXEC_CONTEXT *xc,
167 Trace::InstRecord *traceData) const
170 Fault fault = NoFault;
177 if (fault == NoFault) {
187 def template LoadExecute {{
188 Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
189 Trace::InstRecord *traceData) const
192 Fault fault = NoFault;
199 if (fault == NoFault) {
200 fault = readMemAtomic(xc, traceData, EA, Mem, memAccessFlags);
204 if (fault == NoFault) {
213 def template LoadInitiateAcc {{
214 Fault %(class_name)s::initiateAcc(CPU_EXEC_CONTEXT *xc,
215 Trace::InstRecord *traceData) const
218 Fault fault = NoFault;
225 if (fault == NoFault) {
226 fault = initiateMemRead(xc, traceData, EA, Mem, memAccessFlags);
234 def template LoadCompleteAcc {{
235 Fault %(class_name)s::completeAcc(PacketPtr pkt,
236 CPU_EXEC_CONTEXT *xc,
237 Trace::InstRecord *traceData) const
239 Fault fault = NoFault;
244 getMem(pkt, Mem, traceData);
246 if (fault == NoFault) {
250 if (fault == NoFault) {
259 def template StoreExecute {{
260 Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
261 Trace::InstRecord *traceData) const
264 Fault fault = NoFault;
271 if (fault == NoFault) {
275 if (fault == NoFault) {
276 fault = writeMemAtomic(xc, traceData, Mem, EA,
277 memAccessFlags, NULL);
280 if (fault == NoFault) {
284 if (fault == NoFault) {
292 def template StoreCondExecute {{
293 Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
294 Trace::InstRecord *traceData) const
297 Fault fault = NoFault;
298 uint64_t write_result = 0;
305 if (fault == NoFault) {
309 if (fault == NoFault) {
310 fault = writeMemAtomic(xc, traceData, Mem, EA,
311 memAccessFlags, &write_result);
314 if (fault == NoFault) {
318 if (fault == NoFault) {
326 def template StoreInitiateAcc {{
327 Fault %(class_name)s::initiateAcc(CPU_EXEC_CONTEXT *xc,
328 Trace::InstRecord *traceData) const
331 Fault fault = NoFault;
338 if (fault == NoFault) {
342 if (fault == NoFault) {
343 fault = writeMemTiming(xc, traceData, Mem, EA,
344 memAccessFlags, NULL);
352 def template StoreCompleteAcc {{
353 Fault %(class_name)s::completeAcc(PacketPtr pkt,
354 CPU_EXEC_CONTEXT *xc,
355 Trace::InstRecord *traceData) const
362 def template StoreCondCompleteAcc {{
363 Fault %(class_name)s::completeAcc(PacketPtr pkt,
364 CPU_EXEC_CONTEXT *xc,
365 Trace::InstRecord *traceData) const
367 Fault fault = NoFault;
372 uint64_t write_result = pkt->req->getExtraData();
374 if (fault == NoFault) {
378 if (fault == NoFault) {
387 def template MiscExecute {{
388 Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
389 Trace::InstRecord *traceData) const
392 Fault fault = NoFault;
399 warn_once("Prefetch instructions in Alpha do not do anything\n");
400 if (fault == NoFault) {
408 // Prefetches in Alpha don't actually do anything
409 // They just build an effective address and complete
410 def template MiscInitiateAcc {{
411 Fault %(class_name)s::initiateAcc(CPU_EXEC_CONTEXT *xc,
412 Trace::InstRecord *traceData) const
414 warn("initiateAcc undefined: Misc instruction does not support split "
421 def template MiscCompleteAcc {{
422 Fault %(class_name)s::completeAcc(PacketPtr pkt,
423 CPU_EXEC_CONTEXT *xc,
424 Trace::InstRecord *traceData) const
426 warn("completeAcc undefined: Misc instruction does not support split "
434 // load instructions use Ra as dest, so check for
435 // Ra == 31 to detect nops
436 def template LoadNopCheckDecode {{
438 AlphaStaticInst *i = new %(class_name)s(machInst);
447 // for some load instructions, Ra == 31 indicates a prefetch (not a nop)
448 def template LoadPrefetchCheckDecode {{
451 return new %(class_name)s(machInst);
454 return new %(class_name)sPrefetch(machInst);
461 def LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
462 postacc_code = '', base_class = 'MemoryDisp32',
463 decode_template = BasicDecode, exec_template_base = ''):
464 # Make sure flags are in lists (convert to lists if not).
465 mem_flags = makeList(mem_flags)
466 inst_flags = makeList(inst_flags)
468 iop = InstObjParams(name, Name, base_class,
469 { 'ea_code':ea_code, 'memacc_code':memacc_code, 'postacc_code':postacc_code },
473 mem_flags = [ 'Request::%s' % flag for flag in mem_flags ]
474 s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';'
479 # The InitiateAcc template is the same for StoreCond templates as the
480 # corresponding Store template..
481 StoreCondInitiateAcc = StoreInitiateAcc
483 fullExecTemplate = eval(exec_template_base + 'Execute')
484 initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
485 completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
487 # (header_output, decoder_output, decode_block, exec_output)
488 return (LoadStoreDeclare.subst(iop),
489 LoadStoreConstructor.subst(iop),
490 decode_template.subst(iop),
491 fullExecTemplate.subst(iop)
492 + EACompExecute.subst(iop)
493 + initiateAccTemplate.subst(iop)
494 + completeAccTemplate.subst(iop))
497 def format LoadOrNop(memacc_code, ea_code = {{ EA = Rb + disp; }},
498 mem_flags = [], inst_flags = []) {{
499 (header_output, decoder_output, decode_block, exec_output) = \
500 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
501 decode_template = LoadNopCheckDecode,
502 exec_template_base = 'Load')
506 // Note that the flags passed in apply only to the prefetch version
507 def format LoadOrPrefetch(memacc_code, ea_code = {{ EA = Rb + disp; }},
508 mem_flags = [], pf_flags = [], inst_flags = []) {{
509 # declare the load instruction object and generate the decode block
510 (header_output, decoder_output, decode_block, exec_output) = \
511 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
512 decode_template = LoadPrefetchCheckDecode,
513 exec_template_base = 'Load')
515 # Declare the prefetch instruction object.
517 # Make sure flag args are lists so we can mess with them.
518 mem_flags = makeList(mem_flags)
519 pf_flags = makeList(pf_flags)
520 inst_flags = makeList(inst_flags)
522 pf_mem_flags = mem_flags + pf_flags + ['PREFETCH']
523 pf_inst_flags = inst_flags
525 (pf_header_output, pf_decoder_output, _, pf_exec_output) = \
526 LoadStoreBase(name, Name + 'Prefetch', ea_code, ';',
527 pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
529 header_output += pf_header_output
530 decoder_output += pf_decoder_output
531 exec_output += pf_exec_output
535 def format Store(memacc_code, ea_code = {{ EA = Rb + disp; }},
536 mem_flags = [], inst_flags = []) {{
537 (header_output, decoder_output, decode_block, exec_output) = \
538 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
539 exec_template_base = 'Store')
543 def format StoreCond(memacc_code, postacc_code,
544 ea_code = {{ EA = Rb + disp; }},
545 mem_flags = [], inst_flags = []) {{
546 (header_output, decoder_output, decode_block, exec_output) = \
547 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
548 postacc_code, exec_template_base = 'StoreCond')
552 // Use 'MemoryNoDisp' as base: for wh64, fetch, ecb
553 def format MiscPrefetch(ea_code, memacc_code,
554 mem_flags = [], inst_flags = []) {{
555 (header_output, decoder_output, decode_block, exec_output) = \
556 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
557 base_class = 'MemoryNoDisp', exec_template_base = 'Misc')