From 291f44a19267df16d5ff0e8582a604d1a26a177d Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Tue, 25 May 2021 10:24:24 +0200 Subject: [PATCH] [CSR] unknown csr names now fail without exception --- riscemu/priv/CSR.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/riscemu/priv/CSR.py b/riscemu/priv/CSR.py index 50ec515..26b204c 100644 --- a/riscemu/priv/CSR.py +++ b/riscemu/priv/CSR.py @@ -65,20 +65,22 @@ class CSR: def __init__(self): self.regs = defaultdict(lambda: 0) - self.listeners = defaultdict(lambda: (lambda x, y: ())) + self.listeners = defaultdict(lambda: (lambda x, y: None)) def set(self, addr: Union[str, int], val: int): if isinstance(addr, str): - if not addr in self.name_to_addr: + if addr not in self.name_to_addr: print("Unknown CSR register {}".format(addr)) + return addr = self.name_to_addr[addr] self.listeners[addr](self.regs[addr], val) self.regs[addr] = val def get(self, addr: Union[str, int]): if isinstance(addr, str): - if not addr in self.name_to_addr: + if addr not in self.name_to_addr: print("Unknown CSR register {}".format(addr)) + return addr = self.name_to_addr[addr] return self.regs[addr]