kernel-mode #1

Manually merged
anton merged 69 commits from kernel-mode into master 2021-11-16 08:02:40 +01:00
3 changed files with 6 additions and 3 deletions
Showing only changes of commit c963fe3989 - Show all commits

View File

@ -2,6 +2,7 @@ from typing import Dict, Union, Callable, Optional
from collections import defaultdict from collections import defaultdict
from .privmodes import PrivModes from .privmodes import PrivModes
from .Exceptions import IllegalInstructionTrap from .Exceptions import IllegalInstructionTrap
from ..helpers import to_unsigned
MSTATUS_OFFSETS = { MSTATUS_OFFSETS = {
'uie': 0, 'uie': 0,
@ -74,12 +75,14 @@ class CSR:
def __init__(self): def __init__(self):
self.regs = defaultdict(lambda: 0) self.regs = defaultdict(lambda: 0)
self.listeners = defaultdict(lambda: (lambda x, y: None)) self.listeners = defaultdict(lambda: (lambda x, y: None))
self.virtual_regs = dict()
#TODO: implement write masks (bitmasks which control writeable bits in registers #TODO: implement write masks (bitmasks which control writeable bits in registers
def set(self, addr: Union[str, int], val: int): def set(self, addr: Union[str, int], val: int):
addr = self._addr_to_name(addr) addr = self._addr_to_name(addr)
if addr is None: if addr is None:
return return
val = to_unsigned(val)
self.listeners[addr](self.regs[addr], val) self.listeners[addr](self.regs[addr], val)
self.regs[addr] = val self.regs[addr] = val
@ -135,7 +138,7 @@ class CSR:
raise IllegalInstructionTrap() raise IllegalInstructionTrap()
def assert_can_write(self, mode: PrivModes, addr: int): 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() raise IllegalInstructionTrap()
def _addr_to_name(self, addr: Union[str, int]) -> Optional[int]: def _addr_to_name(self, addr: Union[str, int]) -> Optional[int]:

View File

@ -69,10 +69,11 @@ class PrivCPU(CPU):
ins = None ins = None
try: try:
while not self.exit: while not self.exit:
self.step(verbose=False) self.step(verbose)
except RiscemuBaseException as ex: except RiscemuBaseException as ex:
if isinstance(ex, LaunchDebuggerException): if isinstance(ex, LaunchDebuggerException):
self.launch_debug = True self.launch_debug = True
self.pc += self.INS_XLEN
else: else:
print(FMT_ERROR + "[CPU] excpetion caught at 0x{:08X}: {}:".format(self.pc - 1, ins) + FMT_NONE) print(FMT_ERROR + "[CPU] excpetion caught at 0x{:08X}: {}:".format(self.pc - 1, ins) + FMT_NONE)
print(ex.message()) print(ex.message())

View File

@ -130,5 +130,4 @@ class PrivRV32I(RV32I):
def parse_mem_ins(self, ins: 'LoadedInstruction') -> Tuple[str, int]: def parse_mem_ins(self, ins: 'LoadedInstruction') -> Tuple[str, int]:
ASSERT_LEN(ins.args, 3) ASSERT_LEN(ins.args, 3)
print("dop")
return ins.get_reg(1), self.get_reg_content(ins, 0) + ins.get_imm(2) return ins.get_reg(1), self.get_reg_content(ins, 0) + ins.get_imm(2)