3 // Copyright (c) 2007 MIPS Technologies, Inc.
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
39 * Base class for general Mips memory-format instructions.
41 class Memory : public MipsStaticInst
44 /// Memory request flags. See mem_req_base.hh.
45 Request::Flags memAccessFlags;
47 /// Displacement for EA calculation (signed).
51 Memory(const char *mnem, MachInst _machInst, OpClass __opClass)
52 : MipsStaticInst(mnem, _machInst, __opClass),
53 disp(sext<16>(OFFSET))
57 std::string generateDisassembly(
58 Addr pc, const SymbolTable *symtab) const override;
62 * Base class for a few miscellaneous memory-format insts
63 * that don't interpret the disp field
65 class MemoryNoDisp : public Memory
69 MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
70 : Memory(mnem, _machInst, __opClass)
74 std::string generateDisassembly(
75 Addr pc, const SymbolTable *symtab) const override;
82 Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
84 return csprintf("%-10s %c%d, %d(r%d)", mnemonic,
85 flags[IsFloating] ? 'f' : 'r', RT, disp, RS);
89 MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
91 return csprintf("%-10s %c%d, r%d(r%d)", mnemonic,
92 flags[IsFloating] ? 'f' : 'r',
93 flags[IsFloating] ? FD : RD,
100 uint64_t getMemData(ExecContext *xc, Packet *packet);
105 /** return data in cases where there the size of data is only
108 uint64_t getMemData(ExecContext *xc, Packet *packet) {
109 switch (packet->getSize())
112 return packet->getLE<uint8_t>();
115 return packet->getLE<uint16_t>();
118 return packet->getLE<uint32_t>();
121 return packet->getLE<uint64_t>();
124 panic("bad store data size = %d", packet->getSize());
132 def template LoadStoreDeclare {{
134 * Static instruction class for "%(mnemonic)s".
136 class %(class_name)s : public %(base_class)s
141 %(class_name)s(ExtMachInst machInst);
143 Fault execute(ExecContext *, Trace::InstRecord *) const override;
144 Fault initiateAcc(ExecContext *, Trace::InstRecord *) const override;
145 Fault completeAcc(Packet *, ExecContext *,
146 Trace::InstRecord *) const override;
151 def template LoadStoreConstructor {{
152 %(class_name)s::%(class_name)s(ExtMachInst machInst)
153 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
159 def template LoadExecute {{
160 Fault %(class_name)s::execute(ExecContext *xc,
161 Trace::InstRecord *traceData) const
164 Fault fault = NoFault;
166 if (this->isFloating()) {
177 if (fault == NoFault) {
178 fault = readMemAtomicLE(xc, traceData, EA, Mem, memAccessFlags);
182 if (fault == NoFault) {
191 def template LoadInitiateAcc {{
192 Fault %(class_name)s::initiateAcc(ExecContext *xc,
193 Trace::InstRecord *traceData) const
196 Fault fault = NoFault;
198 if (this->isFloating()) {
209 if (fault == NoFault) {
210 fault = initiateMemRead(xc, traceData, EA, Mem, memAccessFlags);
217 def template LoadCompleteAcc {{
218 Fault %(class_name)s::completeAcc(Packet *pkt, ExecContext *xc,
219 Trace::InstRecord *traceData) const
221 Fault fault = NoFault;
223 if (this->isFloating()) {
233 getMemLE(pkt, Mem, traceData);
235 if (fault == NoFault) {
239 if (fault == NoFault) {
247 def template StoreExecute {{
248 Fault %(class_name)s::execute(ExecContext *xc,
249 Trace::InstRecord *traceData) const
252 Fault fault = NoFault;
259 if (fault == NoFault) {
263 if (fault == NoFault) {
264 fault = writeMemAtomicLE(xc, traceData, Mem, EA, memAccessFlags,
268 if (fault == NoFault) {
272 if (fault == NoFault) {
281 def template StoreFPExecute {{
282 Fault %(class_name)s::execute(ExecContext *xc,
283 Trace::InstRecord *traceData) const
286 Fault fault = NoFault;
295 if (fault == NoFault) {
299 if (fault == NoFault) {
300 fault = writeMemAtomicLE(xc, traceData, Mem, EA, memAccessFlags,
304 if (fault == NoFault) {
308 if (fault == NoFault) {
316 def template StoreCondExecute {{
317 Fault %(class_name)s::execute(ExecContext *xc,
318 Trace::InstRecord *traceData) const
321 Fault fault = NoFault;
322 uint64_t write_result = 0;
329 if (fault == NoFault) {
333 if (fault == NoFault) {
334 fault = writeMemAtomicLE(xc, traceData, Mem, EA, memAccessFlags,
338 if (fault == NoFault) {
342 if (fault == NoFault) {
350 def template StoreInitiateAcc {{
351 Fault %(class_name)s::initiateAcc(ExecContext *xc,
352 Trace::InstRecord *traceData) const
355 Fault fault = NoFault;
362 if (fault == NoFault) {
366 if (fault == NoFault) {
367 fault = writeMemTimingLE(xc, traceData, Mem, EA, memAccessFlags,
376 def template StoreCompleteAcc {{
377 Fault %(class_name)s::completeAcc(Packet *pkt,
379 Trace::InstRecord *traceData) const
385 def template StoreCondCompleteAcc {{
386 Fault %(class_name)s::completeAcc(Packet *pkt,
388 Trace::InstRecord *traceData) const
390 Fault fault = NoFault;
395 uint64_t write_result = pkt->req->getExtraData();
397 if (fault == NoFault) {
401 if (fault == NoFault) {
409 def template MiscExecute {{
410 Fault %(class_name)s::execute(ExecContext *xc,
411 Trace::InstRecord *traceData) const
413 Addr EA M5_VAR_USED = 0;
414 Fault fault = NoFault;
421 if (fault == NoFault) {
429 def template MiscInitiateAcc {{
430 Fault %(class_name)s::initiateAcc(ExecContext *xc,
431 Trace::InstRecord *traceData) const
433 panic("Misc instruction does not support split access method!");
439 def template MiscCompleteAcc {{
440 Fault %(class_name)s::completeAcc(Packet *pkt, ExecContext *xc,
441 Trace::InstRecord *traceData) const
443 panic("Misc instruction does not support split access method!");
449 def format LoadMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
450 mem_flags = [], inst_flags = []) {{
451 (header_output, decoder_output, decode_block, exec_output) = \
452 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
453 decode_template = ImmNopCheckDecode,
454 exec_template_base = 'Load')
458 def format StoreMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
459 mem_flags = [], inst_flags = []) {{
460 (header_output, decoder_output, decode_block, exec_output) = \
461 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
462 exec_template_base = 'Store')
465 def format LoadIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
466 mem_flags = [], inst_flags = []) {{
467 inst_flags += ['IsIndexed']
468 (header_output, decoder_output, decode_block, exec_output) = \
469 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
470 decode_template = ImmNopCheckDecode,
471 exec_template_base = 'Load')
474 def format StoreIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
475 mem_flags = [], inst_flags = []) {{
476 inst_flags += ['IsIndexed']
477 (header_output, decoder_output, decode_block, exec_output) = \
478 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
479 exec_template_base = 'Store')
482 def format LoadFPIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
483 mem_flags = [], inst_flags = []) {{
484 inst_flags += ['IsIndexed', 'IsFloating']
485 (header_output, decoder_output, decode_block, exec_output) = \
486 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
487 decode_template = ImmNopCheckDecode,
488 exec_template_base = 'Load')
491 def format StoreFPIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
492 mem_flags = [], inst_flags = []) {{
493 inst_flags += ['IsIndexed', 'IsFloating']
494 (header_output, decoder_output, decode_block, exec_output) = \
495 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
496 exec_template_base = 'Store')
500 def format LoadUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
501 mem_flags = [], inst_flags = []) {{
503 uint32_t mem_word = Mem_uw;
504 uint32_t unalign_addr = Rs + disp;
505 uint32_t byte_offset = unalign_addr & 3;
506 if (GuestByteOrder == BigEndianByteOrder)
510 memacc_code = decl_code + memacc_code
512 (header_output, decoder_output, decode_block, exec_output) = \
513 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
514 decode_template = ImmNopCheckDecode,
515 exec_template_base = 'Load')
518 def format StoreUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
519 mem_flags = [], inst_flags = []) {{
521 uint32_t mem_word = 0;
522 uint32_t unaligned_addr = Rs + disp;
523 uint32_t byte_offset = unaligned_addr & 3;
524 if (GuestByteOrder == BigEndianByteOrder)
526 fault = readMemAtomicLE(xc, traceData, EA, mem_word, memAccessFlags);
528 memacc_code = decl_code + memacc_code + '\nMem = mem_word;\n'
530 (header_output, decoder_output, decode_block, exec_output) = \
531 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
532 exec_template_base = 'Store')
535 def format Prefetch(ea_code = {{ EA = Rs + disp; }},
536 mem_flags = [], pf_flags = [], inst_flags = []) {{
537 pf_mem_flags = mem_flags + pf_flags + ['PREFETCH']
538 pf_inst_flags = inst_flags
540 (header_output, decoder_output, decode_block, exec_output) = \
541 LoadStoreBase(name, Name, ea_code,
542 'warn_once("Prefetching not implemented for MIPS\\n");',
543 pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
547 def format StoreCond(memacc_code, postacc_code,
548 ea_code = {{ EA = Rs + disp; }},
549 mem_flags = [], inst_flags = []) {{
550 (header_output, decoder_output, decode_block, exec_output) = \
551 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
552 postacc_code, exec_template_base = 'StoreCond')