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))