allow unaligned access exception to be raised in ISACaller mem simulator
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 10 May 2021 14:41:14 +0000 (15:41 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 10 May 2021 14:41:14 +0000 (15:41 +0100)
src/openpower/decoder/isa/mem.py

index c92d70adcb4f0891ba4cbeaeb215326675e75316..2b6c118dd8b87f6aefe8579e3ebc77edeaff8121 100644 (file)
@@ -27,6 +27,9 @@ def swap_order(x, nbytes):
     return x
 
 
+class MemException(Exception):
+    pass
+
 
 class Mem:
 
@@ -72,7 +75,10 @@ class Mem:
                 swap, check_in_mem, instr_fetch)
         remainder = address & (self.bytes_per_word - 1)
         address = address >> self.word_log2
-        assert remainder & (width - 1) == 0, "Unaligned access unsupported!"
+        if remainder & (width - 1) != 0:
+            exc = MemException("unaligned", "Unaligned access unsupported!")
+            exc.dar = address
+            raise exc
         if address in self.mem:
             val = self.mem[address]
         elif check_in_mem:
@@ -97,7 +103,10 @@ class Mem:
         addr = addr >> self.word_log2
         print("Writing 0x{:x} to ST 0x{:x} "
               "memaddr 0x{:x}/{:x}".format(v, staddr, addr, remainder, swap))
-        assert remainder & (width - 1) == 0, "Unaligned access unsupported!"
+        if remainder & (width - 1) != 0:
+            exc = MemException("unaligned", "Unaligned access unsupported!")
+            exc.dar = address
+            raise exc
         if swap:
             v = swap_order(v, width)
         if width != self.bytes_per_word: