minor bugfixes and missing members corrected

float_support
Anton Lydike 4 years ago
parent dd79c11b3b
commit 3c0e357ca0

@ -1,5 +1,5 @@
import traceback import traceback
from dataclasses import dataclass from typing import Tuple
from .Exceptions import * from .Exceptions import *
from .helpers import * from .helpers import *
@ -8,11 +8,11 @@ from .Registers import Registers
from .Syscall import SyscallInterface, Syscall from .Syscall import SyscallInterface, Syscall
import typing import typing
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from . import MMU, Executable, LoadedExecutable, LoadedInstruction from . import MMU, Executable, LoadedExecutable, LoadedInstruction
class CPU: class CPU:
def __init__(self, conf: RunConfig): def __init__(self, conf: RunConfig):
from . import MMU from . import MMU
@ -23,7 +23,7 @@ class CPU:
self.conf = conf self.conf = conf
self.mmu = MMU(conf) self.mmu = MMU(conf)
self.regs = Registers() self.regs = Registers(conf)
self.syscall_int = SyscallInterface() self.syscall_int = SyscallInterface()
def load(self, e: 'Executable'): def load(self, e: 'Executable'):
@ -48,10 +48,12 @@ class CPU:
self.pc += 1 self.pc += 1
self.__run_instruction(ins) self.__run_instruction(ins)
except RiscemuBaseException as ex: except RiscemuBaseException as ex:
print("[CPU] excpetion caught at {}:".format(ins)) print(FMT_ERROR + "[CPU] excpetion caught at {}:".format(ins) + FMT_NONE)
print(" " + ex.message()) print(" " + ex.message())
traceback.print_exception(type(ex), ex, ex.__traceback__) traceback.print_exception(type(ex), ex, ex.__traceback__)
print("Program exited with code {}".format(self.exit_code))
def __run_instruction(self, ins: 'LoadedInstruction'): def __run_instruction(self, ins: 'LoadedInstruction'):
name = 'instruction_' + ins.name name = 'instruction_' + ins.name
if hasattr(self, name): if hasattr(self, name):
@ -276,9 +278,6 @@ class CPU:
addr = ins.get_imm(0) addr = ins.get_imm(0)
self.pc = addr self.pc = addr
def instruction_jr(self, ins: 'LoadedInstruction'):
INS_NOT_IMPLEMENTED(ins)
def instruction_jal(self, ins: 'LoadedInstruction'): def instruction_jal(self, ins: 'LoadedInstruction'):
reg = 'ra' # default register is ra reg = 'ra' # default register is ra
if len(ins.args) == 1: if len(ins.args) == 1:
@ -305,11 +304,11 @@ class CPU:
self.instruction_scall(ins) self.instruction_scall(ins)
def instruction_ebreak(self, ins: 'LoadedInstruction'): def instruction_ebreak(self, ins: 'LoadedInstruction'):
self.instruction_ebreak(ins) self.instruction_sbreak(ins)
def instruction_scall(self, ins: 'LoadedInstruction'): def instruction_scall(self, ins: 'LoadedInstruction'):
ASSERT_LEN(ins.args, 0) ASSERT_LEN(ins.args, 0)
syscall = Syscall(self.regs.get('a7'), self.regs) syscall = Syscall(self.regs.get('a7'), self.regs, self)
self.syscall_int.handle_syscall(syscall) self.syscall_int.handle_syscall(syscall)
def instruction_sbreak(self, ins: 'LoadedInstruction'): def instruction_sbreak(self, ins: 'LoadedInstruction'):
@ -317,14 +316,11 @@ class CPU:
import code import code
code.interact(local=dict(globals(), **locals())) code.interact(local=dict(globals(), **locals()))
def instruction_nop(self, ins: 'LoadedInstruction'): def instruction_nop(self, ins: 'LoadedInstruction'):
pass pass
@staticmethod @staticmethod
def all_instructions(): def all_instructions():
for method in vars(CPU): for method in vars(CPU):
if method.startswith('instruction_'): if method.startswith('instruction_'):
yield method[12:] yield method[12:]

@ -21,7 +21,7 @@ loop:
# exit gracefully # exit gracefully
addi a0, zero, 0 addi a0, zero, 0
addi a7, zero, 93 addi a7, zero, 93
dbg # launch debugger ebreak # launch debugger
scall # exit with code 0 scall # exit with code 0
""" """
tk = RiscVTokenizer(RiscVInput(example_progr)) tk = RiscVTokenizer(RiscVInput(example_progr))
@ -36,11 +36,10 @@ loop:
exe = ep.get_execuable() exe = ep.get_execuable()
cpu = CPU() cpu = CPU(RunConfig())
le = cpu.load(exe) le = cpu.load(exe)
cpu.run_loaded(le) cpu.run_loaded(le)
print('a')

Loading…
Cancel
Save