From 26d0a165f7ed8e7820599929427ddb007c744b02 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sun, 27 Mar 2022 18:45:28 +0200 Subject: [PATCH] [priv] added --slowdown flag to slow down emulated clock speed --- riscemu/config.py | 1 + riscemu/priv/PrivCPU.py | 2 ++ riscemu/priv/__main__.py | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/riscemu/config.py b/riscemu/config.py index e5f49a6..a3dc5ae 100644 --- a/riscemu/config.py +++ b/riscemu/config.py @@ -19,6 +19,7 @@ class RunConfig: scall_input: bool = True scall_fs: bool = False verbosity: int = 0 + slowdown: float = 1 CONFIG = RunConfig() diff --git a/riscemu/priv/PrivCPU.py b/riscemu/priv/PrivCPU.py index c74d766..d2481e2 100644 --- a/riscemu/priv/PrivCPU.py +++ b/riscemu/priv/PrivCPU.py @@ -69,6 +69,8 @@ class PrivCPU(CPU): # init csr self._init_csr() + self.TIME_RESOLUTION_NS = int(self.TIME_RESOLUTION_NS * conf.slowdown) + def run(self, verbose=False): if self.pc <= 0: return False diff --git a/riscemu/priv/__main__.py b/riscemu/priv/__main__.py index 6e74029..0f869da 100644 --- a/riscemu/priv/__main__.py +++ b/riscemu/priv/__main__.py @@ -1,8 +1,6 @@ from riscemu import RunConfig from riscemu.types import Program from .PrivCPU import PrivCPU -from .ElfLoader import ElfBinaryFileLoader -from .ImageLoader import MemoryImageLoader import sys @@ -19,9 +17,11 @@ if __name__ == '__main__': parser.add_argument('-v', '--verbose', help="Verbosity level (can be used multiple times)", action='count', default=0) + parser.add_argument('--slowdown', help="Slow down the emulated CPU clock by a factor", type=float, default=1) + args = parser.parse_args() - cpu = PrivCPU(RunConfig(verbosity=args.verbose, debug_on_exception=args.debug_exceptions)) + cpu = PrivCPU(RunConfig(verbosity=args.verbose, debug_on_exception=args.debug_exceptions, slowdown=args.slowdown)) for source_path in args.source: loader = max((loader for loader in cpu.get_loaders()), key=lambda l: l.can_parse(source_path))