From bb770ab43c3d1d84710925339eacad9032d0b7cb Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sun, 17 Apr 2022 10:42:08 +0200 Subject: [PATCH] Logging: Changed verbosity levels at which things are logged for the CPU --- riscemu/CPU.py | 12 ++++++++++-- riscemu/types/cpu.py | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/riscemu/CPU.py b/riscemu/CPU.py index 0fc0197..25539c3 100644 --- a/riscemu/CPU.py +++ b/riscemu/CPU.py @@ -12,7 +12,7 @@ from typing import List, Type import riscemu from .config import RunConfig from .MMU import MMU -from .colors import FMT_CPU, FMT_NONE +from .colors import FMT_CPU, FMT_NONE, FMT_ERROR from .debug import launch_debug_session from .types.exceptions import RiscemuBaseException, LaunchDebuggerException from .syscall import SyscallInterface, get_syscall_symbols @@ -87,7 +87,8 @@ class UserModeCPU(CPU): while not self.halted: self.step(verbose) - print(FMT_CPU + "[CPU] Program exited with code {}".format(self.exit_code) + FMT_NONE) + if self.conf.verbosity > 0: + print(FMT_CPU + "[CPU] Program exited with code {}".format(self.exit_code) + FMT_NONE) def setup_stack(self, stack_size=1024 * 4) -> bool: """ @@ -104,9 +105,16 @@ class UserModeCPU(CPU): ) if not self.mmu.load_section(stack_sec, fixed_position=False): + print(FMT_ERROR + "[CPU] Could not insert stack section!" + FMT_NONE) return False self.regs.set('sp', Int32(stack_sec.base + stack_sec.size)) + + if self.conf.verbosity > 1: + print(FMT_CPU + "[CPU] Created stack of size {} at 0x{:x}".format( + stack_size, stack_sec.base + ) + FMT_NONE) + return True @classmethod diff --git a/riscemu/types/cpu.py b/riscemu/types/cpu.py index 23de29c..75df6c3 100644 --- a/riscemu/types/cpu.py +++ b/riscemu/types/cpu.py @@ -4,7 +4,7 @@ from typing import List, Type, Callable, Set, Dict from ..registers import Registers from ..config import RunConfig -from ..colors import FMT_RED, FMT_NONE +from ..colors import FMT_RED, FMT_NONE, FMT_ERROR, FMT_CPU from . import T_AbsoluteAddress, Instruction, Program, ProgramLoader @@ -84,9 +84,13 @@ class CPU(ABC): def launch(self, program: Program, verbose: bool = False): if program not in self.mmu.programs: - print(FMT_RED + '[CPU] Cannot launch program that\'s not loaded!' + FMT_NONE) + print(FMT_ERROR + '[CPU] Cannot launch program that\'s not loaded!' + FMT_NONE) return - + if self.conf.verbosity > 0: + print(FMT_CPU + "[CPU] Started running from {}".format( + self.mmu.translate_address(program.entrypoint) + ) + FMT_NONE) + print(program) self.pc = program.entrypoint self.run(verbose)