MemMMap: log mmap calls
[openpower-isa.git] / src / openpower / decoder / isa / mem.py
index 14a5f4df5fc09fbc25bef6308b646a60347ed46b..2b3ec844436230e3fb285ba83396ab378afacf69 100644 (file)
@@ -80,6 +80,10 @@ class _ReadReason(enum.Enum):
             return MMapPageFlags.X
         return MMapPageFlags.R
 
+    @cached_property
+    def ld_logs(self):
+        return self is not self.Dump
+
 
 class MemCommon:
     def __init__(self, row_bytes, initial_mem, misaligned_ok):
@@ -111,21 +115,25 @@ class MemCommon:
         raise NotImplementedError
         yield 0
 
-    def _get_shifter_mask(self, wid, remainder):
+    def _get_shifter_mask(self, wid, remainder, do_log=True):
         shifter = ((self.bytes_per_word - wid) - remainder) * \
             8  # bits per byte
         # XXX https://bugs.libre-soc.org/show_bug.cgi?id=377
         # BE/LE mode?
         shifter = remainder * 8
         mask = (1 << (wid * 8)) - 1
-        log("width,rem,shift,mask", wid, remainder, hex(shifter), hex(mask))
+        if do_log:
+            log("width,rem,shift,mask",
+                wid, remainder, hex(shifter), hex(mask))
         return shifter, mask
 
     # TODO: Implement ld/st of lesser width
     def ld(self, address, width=8, swap=True, check_in_mem=False,
            instr_fetch=False, reason=None):
-        log("ld from addr 0x%x width %d" % (address, width),
-            swap, check_in_mem, instr_fetch)
+        do_log = reason is not None and reason.ld_logs
+        if do_log:
+            log("ld from addr 0x%x width %d" % (address, width),
+                swap, check_in_mem, instr_fetch)
         self.last_ld_addr = address  # record last load
         ldaddr = address
         remainder = address & (self.bytes_per_word - 1)
@@ -144,16 +152,19 @@ class MemCommon:
                 return None
             else:
                 val = 0
-        log("ld mem @ 0x%x rem %d : 0x%x" % (ldaddr, remainder, val))
+        if do_log:
+            log("ld mem @ 0x%x rem %d : 0x%x" % (ldaddr, remainder, val))
 
         if width != self.bytes_per_word:
-            shifter, mask = self._get_shifter_mask(width, remainder)
-            log("masking", hex(val), hex(mask << shifter), shifter)
+            shifter, mask = self._get_shifter_mask(width, remainder, do_log)
+            if do_log:
+                log("masking", hex(val), hex(mask << shifter), shifter)
             val = val & (mask << shifter)
             val >>= shifter
         if swap:
             val = swap_order(val, width)
-        log("Read 0x%x from addr 0x%x" % (val, ldaddr))
+        if do_log:
+            log("Read 0x%x from addr 0x%x" % (val, ldaddr))
         return val
 
     def _st(self, addr, v, width=8, swap=True):
@@ -348,7 +359,7 @@ def _make_default_block_addrs():
 DEFAULT_BLOCK_ADDRS = _make_default_block_addrs()
 
 
-@plain_data.plain_data(frozen=True, unsafe_hash=True)
+@plain_data.plain_data(frozen=True, unsafe_hash=True, repr=False)
 class MMapEmuBlock:
     __slots__ = ("addrs", "flags", "file", "file_off")
 
@@ -437,6 +448,18 @@ class MMapEmuBlock:
                 self, addrs=addrs, file_off=file_off))
         return retval
 
+    def __repr__(self):
+        parts = ["MMapEmuBlock(range(0x%X, 0x%X)"
+                 % (self.addrs.start, self.addrs.stop)]
+        if self.flags != MMapPageFlags.NONE:
+            parts.append(", flags=%r" % (self.flags, ))
+        if self.file is not None:
+            parts.append(", file=%r" % (self.file, ))
+        if self.file_off != 0:
+            parts.append(", file_off=0x%X" % (self.file_off, ))
+        parts.append(")")
+        return "".join(parts)
+
 
 # stuff marked "not available" is not in the powerpc64le headers on my system
 LEGACY_MAP_MASK = (
@@ -908,6 +931,7 @@ class MemMMap(MemCommon):
             # memory could be non-zero, mark as modified
             for page_idx in block.page_indexes:
                 self.modified_pages.add(page_idx)
+        log("mmap block=%s" % (block,), kind=LogType.InstrInOuts)
         return block.addrs.start
 
     @staticmethod