kernel-mode #1
@ -31,6 +31,7 @@ def _window_loop(textIO: 'TextIO'):
|
|||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("[TextIO] module works best with PySimpleGui!")
|
print("[TextIO] module works best with PySimpleGui!")
|
||||||
|
textIO.set_sg_window(None)
|
||||||
|
|
||||||
|
|
||||||
class TextIO(IOModule):
|
class TextIO(IOModule):
|
||||||
|
@ -111,10 +111,10 @@ class PrivCPU(CPU):
|
|||||||
def get_tokenizer(self, tokenizer_input):
|
def get_tokenizer(self, tokenizer_input):
|
||||||
raise NotImplementedError("Not supported!")
|
raise NotImplementedError("Not supported!")
|
||||||
|
|
||||||
def run(self):
|
def run(self, verbose: bool = False):
|
||||||
print(FMT_CPU + '[CPU] Started running from 0x{:08X} ({})'.format(self.pc, "kernel") + FMT_NONE)
|
print(FMT_CPU + '[CPU] Started running from 0x{:08X} ({})'.format(self.pc, "kernel") + FMT_NONE)
|
||||||
self._time_start = time.perf_counter_ns() // self.TIME_RESOLUTION_NS
|
self._time_start = time.perf_counter_ns() // self.TIME_RESOLUTION_NS
|
||||||
self._run()
|
self._run(verbose)
|
||||||
|
|
||||||
def _init_csr(self):
|
def _init_csr(self):
|
||||||
# set up CSR
|
# set up CSR
|
||||||
@ -170,7 +170,7 @@ class PrivCPU(CPU):
|
|||||||
self._timer_step()
|
self._timer_step()
|
||||||
self._check_interrupt()
|
self._check_interrupt()
|
||||||
ins = self.mmu.read_ins(self.pc)
|
ins = self.mmu.read_ins(self.pc)
|
||||||
if verbose:
|
if verbose and self.mode == PrivModes.USER:
|
||||||
print(FMT_CPU + " Running 0x{:08X}:{} {}".format(self.pc, FMT_NONE, ins))
|
print(FMT_CPU + " Running 0x{:08X}:{} {}".format(self.pc, FMT_NONE, ins))
|
||||||
self.run_instruction(ins)
|
self.run_instruction(ins)
|
||||||
self.pc += self.INS_XLEN
|
self.pc += self.INS_XLEN
|
||||||
@ -190,8 +190,8 @@ class PrivCPU(CPU):
|
|||||||
# select best interrupt
|
# select best interrupt
|
||||||
# TODO: actually select based on the official ranking
|
# TODO: actually select based on the official ranking
|
||||||
trap = self.pending_traps.pop() # use the most recent trap
|
trap = self.pending_traps.pop() # use the most recent trap
|
||||||
if not isinstance(trap, TimerInterrupt):
|
if not isinstance(trap, TimerInterrupt) or True:
|
||||||
print(FMT_CPU + "[CPU] taking trap {}!".format(trap) + FMT_NONE)
|
print(FMT_CPU + "[CPU] [{}] taking trap {}!".format(self.cycle, trap) + FMT_NONE)
|
||||||
|
|
||||||
if trap.priv != PrivModes.MACHINE:
|
if trap.priv != PrivModes.MACHINE:
|
||||||
print(FMT_CPU + "[CPU] Trap not targeting machine mode encountered! - undefined behaviour!" + FMT_NONE)
|
print(FMT_CPU + "[CPU] Trap not targeting machine mode encountered! - undefined behaviour!" + FMT_NONE)
|
||||||
|
@ -8,6 +8,7 @@ from ..instructions.RV32I import *
|
|||||||
from ..Exceptions import INS_NOT_IMPLEMENTED
|
from ..Exceptions import INS_NOT_IMPLEMENTED
|
||||||
from .Exceptions import *
|
from .Exceptions import *
|
||||||
from .privmodes import PrivModes
|
from .privmodes import PrivModes
|
||||||
|
from ..colors import FMT_CPU, FMT_NONE
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
@ -78,6 +79,16 @@ class PrivRV32I(RV32I):
|
|||||||
mepc = self.cpu.csr.get('mepc')
|
mepc = self.cpu.csr.get('mepc')
|
||||||
self.cpu.pc = mepc
|
self.cpu.pc = mepc
|
||||||
|
|
||||||
|
sec = self.mmu.get_sec_containing(mepc)
|
||||||
|
if sec is not None:
|
||||||
|
print(FMT_CPU + "[CPU] [{}] returning to mode: {} in binary {}, section {}, addr 0x{:x}".format(
|
||||||
|
self.cpu.cycle,
|
||||||
|
PrivModes(mpp),
|
||||||
|
sec.owner,
|
||||||
|
sec.name,
|
||||||
|
mepc
|
||||||
|
) + FMT_NONE)
|
||||||
|
|
||||||
def instruction_uret(self, ins: 'LoadedInstruction'):
|
def instruction_uret(self, ins: 'LoadedInstruction'):
|
||||||
raise IllegalInstructionTrap(ins)
|
raise IllegalInstructionTrap(ins)
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--kernel', type=str, help='Kernel elf loaded with user programs', nargs='?')
|
parser.add_argument('--kernel', type=str, help='Kernel elf loaded with user programs', nargs='?')
|
||||||
parser.add_argument('--image', type=str, help='Memory image containing kernel', nargs='?')
|
parser.add_argument('--image', type=str, help='Memory image containing kernel', nargs='?')
|
||||||
|
|
||||||
|
parser.add_argument('-v', '--verbose', help="Verbose output", action='store_true')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
mmu = None
|
mmu = None
|
||||||
|
|
||||||
@ -26,10 +28,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if mmu is None:
|
if mmu is None:
|
||||||
print("You must specify one of --kernel or --image for running in privilege mode!")
|
print("You must specify one of --kernel or --image for running in privilege mode!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
cpu = PrivCPU(RunConfig(), mmu)
|
cpu = PrivCPU(RunConfig(), mmu)
|
||||||
|
cpu.run(args.verbose)
|
||||||
cpu.run()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user