コード例 #1
0
ファイル: Vamos.py プロジェクト: thorfdbg/amitools
    def __init__(self, raw_mem, cpu, traps, cfg):
        self.raw_mem = raw_mem
        self.ram_size = raw_mem.get_ram_size() * 1024  # in bytes
        self.cpu = cpu
        self.cpu_type = cfg.cpu
        self.traps = traps
        self.cfg = cfg
        #sys.settrace(Tracer().traceit)

        # too much RAM requested?
        # our "custom chips" start at $BFxxxx so we allow RAM only to be below
        if self.ram_size >= 0xbf0000 and self.cfg.hw_access != "disable":
            raise VamosConfigError(
                "Too much RAM configured! Only up to $BF0000 allowed.")

        # setup custom chips
        if self.cfg.hw_access != "disable":
            self.hw_access = HardwareAccess(raw_mem)
            self._setup_hw_access()

        # path manager
        self.path_mgr = PathManager(cfg)

        # create a label manager and error tracker
        if self.cfg.label_mgr != "disable":
            self.label_mgr = LabelManager()
        else:
            self.label_mgr = None
        self.error_tracker = ErrorTracker(cpu, self.label_mgr)
        if self.label_mgr != None:
            self.label_mgr.error_tracker = self.error_tracker

        # set a label for first two dwords
        if self.label_mgr != None:
            label = LabelRange("zero_page", 0, 8)
            self.label_mgr.add_label(label)

        # create memory access
        self.mem = MainMemory(raw_mem, self.error_tracker)
        self.mem.ctx = self
        self._setup_memory(raw_mem)

        # create memory allocator
        self.mem_begin = 0x1000
        self.alloc = MemoryAlloc(self.mem, 0, self.ram_size, self.mem_begin,
                                 self.label_mgr)

        # create segment loader
        self.seg_loader = SegmentLoader(self.mem, self.alloc, self.label_mgr,
                                        self.path_mgr)

        # lib manager
        self.lib_mgr = LibManager(self.label_mgr, cfg)

        # no current process right now
        self.process = None
        self.proc_list = []
コード例 #2
0
    def __init__(self, machine, cfg):
        self.machine = machine
        self.mem = machine.get_mem()
        self.raw_mem = self.mem
        self.ram_size = self.mem.get_ram_size_bytes()
        self.cpu = machine.get_cpu()
        self.cpu_type = machine.get_cpu_type()
        self.traps = machine.get_traps()
        self.cfg = cfg

        # too much RAM requested?
        # our "custom chips" start at $BFxxxx so we allow RAM only to be below
        if self.ram_size >= 0xbf0000 and self.cfg.hw_access != "disable":
            raise VamosConfigError(
                "Too much RAM configured! Only up to $BF0000 allowed.")

        # setup custom chips
        if self.cfg.hw_access != "disable":
            self.hw_access = HardwareAccess(self.mem)
            self._setup_hw_access()

        # path manager
        self.path_mgr = PathManager(cfg)

        # create a label manager and error tracker
        self.label_mgr = machine.get_label_mgr()

        # set a label for first region
        if self.label_mgr:
            label = LabelRange("vbr", 0, 0x400)
            self.label_mgr.add_label(label)
            # shutdown range
            label = LabelRange("machine", 0x400, 0x800)
            self.label_mgr.add_label(label)

        # create memory access
        self.trace_mgr = TraceManager(self.cpu, self.label_mgr)
        if cfg.internal_memory_trace:
            self.mem = TraceMemory(self.mem, self.trace_mgr)
            if not log_mem_int.isEnabledFor(logging.INFO):
                log_mem_int.setLevel(logging.INFO)
        # enable mem trace?
        if cfg.memory_trace:
            self.machine.set_cpu_mem_trace_hook(self.trace_mgr.trace_mem)
            if not log_mem.isEnabledFor(logging.INFO):
                log_mem.setLevel(logging.INFO)
        # instr trace
        if cfg.instr_trace:
            if not log_instr.isEnabledFor(logging.INFO):
                log_instr.setLevel(logging.INFO)
            cpu = self.cpu
            trace_mgr = self.trace_mgr
            state = CPUState()

            def instr_hook():
                # add register dump
                if cfg.reg_dump:
                    state.get(cpu)
                    res = state.dump()
                    for r in res:
                        log_instr.info(r)
                # disassemble line
                pc = cpu.r_reg(REG_PC)
                trace_mgr.trace_code_line(pc)

            self.machine.set_instr_hook(instr_hook)

        # create memory allocator
        self.mem_begin = 0x1000
        self.mem_size = self.ram_size - self.mem_begin
        self.alloc = MemoryAlloc(self.mem, self.mem_begin, self.mem_size,
                                 self.label_mgr)

        # create segment loader
        self.seg_loader = SegmentLoader(self.alloc, self.path_mgr)

        # setup lib manager
        profiler_cfg = self._get_profiler_config(cfg)
        self.exec_ctx = ExecLibCtx(self.machine, self.alloc, self.seg_loader,
                                   self.path_mgr)
        self.dos_ctx = DosLibCtx(self.machine, self.alloc, self.seg_loader,
                                 self.path_mgr, self.run_command,
                                 self.start_sub_process)
        self.lib_mgr = LibManager(self.machine,
                                  self.alloc,
                                  self.seg_loader,
                                  self.cfg,
                                  profiler_cfg=profiler_cfg)
        self.lib_mgr.add_ctx('exec.library', self.exec_ctx)
        self.lib_mgr.add_ctx('dos.library', self.dos_ctx)
        self.lib_mgr.bootstrap_exec()

        # no current process right now
        self.process = None
        self.proc_list = []
コード例 #3
0
    def __init__(self, raw_mem, cpu, traps, cfg):
        self.raw_mem = raw_mem
        self.ram_size = raw_mem.get_ram_size_kib() * 1024  # in bytes
        self.cpu = cpu
        self.cpu_type = cfg.cpu
        self.traps = traps
        self.cfg = cfg

        # too much RAM requested?
        # our "custom chips" start at $BFxxxx so we allow RAM only to be below
        if self.ram_size >= 0xbf0000 and self.cfg.hw_access != "disable":
            raise VamosConfigError(
                "Too much RAM configured! Only up to $BF0000 allowed.")

        # setup custom chips
        if self.cfg.hw_access != "disable":
            self.hw_access = HardwareAccess(raw_mem)
            self._setup_hw_access()

        # path manager
        self.path_mgr = PathManager(cfg)

        def terminate_func():
            self.raw_mem.set_all_to_end()

        # create a label manager and error tracker
        self.label_mgr = LabelManager()
        self.error_tracker = ErrorTracker(cpu, self.label_mgr, terminate_func)
        self.label_mgr.error_tracker = self.error_tracker

        # set a label for first region
        label = LabelRange("zero_page", 0, 0x400)
        self.label_mgr.add_label(label)

        # shutdown range
        label = LabelRange("shutdown", 0x400, 0x800)
        self.label_mgr.add_label(label)

        # create memory access
        self.trace_mgr = TraceManager(cpu, self.label_mgr)
        if cfg.internal_memory_trace:
            self.mem = TraceMemory(raw_mem, self.trace_mgr)
            if not log_mem_int.isEnabledFor(logging.INFO):
                log_mem_int.setLevel(logging.INFO)
        else:
            self.mem = raw_mem
        self._setup_memory(raw_mem)

        # create memory allocator
        self.mem_begin = 0x1000
        self.mem_size = self.ram_size - self.mem_begin
        self.alloc = MemoryAlloc(self.mem, self.mem_begin, self.mem_size,
                                 self.label_mgr)

        # create segment loader
        self.seg_loader = SegmentLoader(self.mem, self.alloc)

        # setup lib context
        ctx_map = LibCtxMap()
        self.exec_ctx = ExecLibCtx(self.cpu, self.mem, self.cpu_type,
                                   self.ram_size, self.label_mgr, self.alloc,
                                   self.traps, self.seg_loader, self.path_mgr)
        self.dos_ctx = DosLibCtx(self.cpu, self.mem, self.alloc, self.path_mgr,
                                 self.seg_loader, self.run_command,
                                 self.start_sub_process)
        ctx_map.set_default_ctx(LibCtx(self.cpu, self.mem))
        ctx_map.add_ctx('exec.library', self.exec_ctx)
        ctx_map.add_ctx('dos.library', self.dos_ctx)

        # lib manager
        self.lib_reg = LibRegistry()
        self.lib_mgr = LibManager(self.label_mgr, self.lib_reg, ctx_map, cfg,
                                  self.error_tracker)
        self.exec_ctx.set_lib_mgr(self.lib_mgr)

        # no current process right now
        self.process = None
        self.proc_list = []