From 198d14d5fbf86f9c4e0c1607e545be67845892f6 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sat, 5 Jun 2021 09:29:20 +0200 Subject: [PATCH] [Priv Exceptions] added __repr__ to CpuTrap class --- riscemu/priv/Exceptions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/riscemu/priv/Exceptions.py b/riscemu/priv/Exceptions.py index fd0dac8..a060e79 100644 --- a/riscemu/priv/Exceptions.py +++ b/riscemu/priv/Exceptions.py @@ -1,17 +1,21 @@ from typing import Optional, NewType from enum import Enum from .privmodes import PrivModes +from .CSRConsts import MCAUSE_TRANSLATION import typing + if typing.TYPE_CHECKING: from .ElfLoader import ElfInstruction + class CpuTrapType(Enum): TIMER = 1 SOFTWARE = 2 EXTERNAL = 3 EXCEPTION = 4 + class CpuTrap(BaseException): code: int """ @@ -48,6 +52,16 @@ class CpuTrap(BaseException): def mcause(self): return (self.code << 31) + self.interrupt + def __repr__(self): + name = "Reserved interrupt({}, {})".format(self.interrupt, self.code) + + if (self.interrupt, self.code) in MCAUSE_TRANSLATION: + name = MCAUSE_TRANSLATION[(self.interrupt, self.code)] + "({}, {})".format(self.interrupt, self.code) + + return "{} {{priv={}, type={}, mtval={}}}".format( + name, self.priv.name, self.type.name, self.mtval + ) + class IllegalInstructionTrap(CpuTrap): def __init__(self, ins: 'ElfInstruction'):