[Priv] small fixes for overlooked things
This commit is contained in:
parent
85af9b992f
commit
c963fe3989
@ -2,6 +2,7 @@ from typing import Dict, Union, Callable, Optional
|
||||
from collections import defaultdict
|
||||
from .privmodes import PrivModes
|
||||
from .Exceptions import IllegalInstructionTrap
|
||||
from ..helpers import to_unsigned
|
||||
|
||||
MSTATUS_OFFSETS = {
|
||||
'uie': 0,
|
||||
@ -74,12 +75,14 @@ class CSR:
|
||||
def __init__(self):
|
||||
self.regs = defaultdict(lambda: 0)
|
||||
self.listeners = defaultdict(lambda: (lambda x, y: None))
|
||||
self.virtual_regs = dict()
|
||||
#TODO: implement write masks (bitmasks which control writeable bits in registers
|
||||
|
||||
def set(self, addr: Union[str, int], val: int):
|
||||
addr = self._addr_to_name(addr)
|
||||
if addr is None:
|
||||
return
|
||||
val = to_unsigned(val)
|
||||
self.listeners[addr](self.regs[addr], val)
|
||||
self.regs[addr] = val
|
||||
|
||||
@ -135,7 +138,7 @@ class CSR:
|
||||
raise IllegalInstructionTrap()
|
||||
|
||||
def assert_can_write(self, mode: PrivModes, addr: int):
|
||||
if (addr >> 8) & 3 > mode.value() or addr >> 10 == 11:
|
||||
if (addr >> 8) & 3 > mode.value or addr >> 10 == 11:
|
||||
raise IllegalInstructionTrap()
|
||||
|
||||
def _addr_to_name(self, addr: Union[str, int]) -> Optional[int]:
|
||||
|
@ -69,10 +69,11 @@ class PrivCPU(CPU):
|
||||
ins = None
|
||||
try:
|
||||
while not self.exit:
|
||||
self.step(verbose=False)
|
||||
self.step(verbose)
|
||||
except RiscemuBaseException as ex:
|
||||
if isinstance(ex, LaunchDebuggerException):
|
||||
self.launch_debug = True
|
||||
self.pc += self.INS_XLEN
|
||||
else:
|
||||
print(FMT_ERROR + "[CPU] excpetion caught at 0x{:08X}: {}:".format(self.pc - 1, ins) + FMT_NONE)
|
||||
print(ex.message())
|
||||
|
@ -130,5 +130,4 @@ class PrivRV32I(RV32I):
|
||||
|
||||
def parse_mem_ins(self, ins: 'LoadedInstruction') -> Tuple[str, int]:
|
||||
ASSERT_LEN(ins.args, 3)
|
||||
print("dop")
|
||||
return ins.get_reg(1), self.get_reg_content(ins, 0) + ins.get_imm(2)
|
||||
|
Loading…
Reference in New Issue
Block a user