Exemplo n.º 1
0
    def from_cfg(cls, machine_cfg, use_labels=False):
        """extract machine parameters from the config

        return new Machine() or None on config error
        """
        cpu = machine_cfg.cpu
        cpu_type, cpu_name = cls.parse_cpu_type(cpu)
        if cpu_type is None:
            log_machine.error("invalid CPU type given: %s", cpu)
            return None
        ram_size = machine_cfg.ram_size
        cycles_per_run = machine_cfg.cycles_per_run
        max_cycles = machine_cfg.max_cycles
        log_machine.info(
            "cpu=%s(%d), ram_size=%d, labels=%s, "
            "cycles_per_run=%d, max_cycles=%d",
            cpu_name,
            cpu_type,
            ram_size,
            use_labels,
            cycles_per_run,
            max_cycles,
        )
        return cls(
            cpu_type,
            ram_size,
            raise_on_main_run=False,
            use_labels=use_labels,
            cycles_per_run=cycles_per_run,
            max_cycles=max_cycles,
            cpu_name=cpu_name,
        )
Exemplo n.º 2
0
 def report_error(self, error):
     # get run nesting
     nesting = self.machine.get_run_nesting()
     log_machine.error("----- ERROR in CPU Run #%d -----", nesting)
     self._log_run_state()
     self._log_mem_info(error)
     self._log_cpu_state()
     self._log_exc(error)
Exemplo n.º 3
0
 def report_error(self, error):
   # get run nesting
   nesting = self.machine.get_run_nesting()
   log_machine.error("----- ERROR in CPU Run #%d -----", nesting)
   self._log_run_state()
   self._log_mem_info(error)
   self._log_cpu_state()
   self._log_exc(error)
Exemplo n.º 4
0
 def _log_run_state(self):
     # get current run_state
     run_state = self.machine.get_cur_run_state()
     log_machine.error(
         "Run: '%s': Initial PC=%06x, SP=%06x",
         run_state.name,
         run_state.pc,
         run_state.sp,
     )
Exemplo n.º 5
0
 def _log_mem_info(self, error):
     # memory error?
     if isinstance(error, InvalidMemoryAccessError):
         addr = error.addr
         if self.label_mgr:
             label, offset = self.label_mgr.get_label_offset(addr)
         else:
             label, offset = None, 0
         if label is not None:
             log_machine.error("@%08x -> +%06x %s", addr, offset, label)
Exemplo n.º 6
0
 def _log_exc(self, error):
     # show traceback if exception is pending
     if sys.exc_info()[0]:
         lines = traceback.format_exc().split("\n")
         for line in lines:
             if line != "":
                 log_machine.error(line)
     else:
         etype = error.__class__.__name__
         log_machine.error("%s: %s", etype, error)
Exemplo n.º 7
0
 def _log_mem_info(self, error):
   # memory error?
   if isinstance(error, InvalidMemoryAccessError):
     addr = error.addr
     if self.label_mgr:
       label, offset = self.label_mgr.get_label_offset(addr)
     else:
       label, offset = None, 0
     if label is not None:
       log_machine.error("@%08x -> +%06x %s", addr, offset, label)
Exemplo n.º 8
0
 def _log_exc(self, error):
   # show traceback if exception is pending
   if sys.exc_info()[0]:
     lines = traceback.format_exc().split('\n')
     for line in lines:
       if line != "":
         log_machine.error(line)
   else:
     etype = error.__class__.__name__
     log_machine.error("%s: %s", etype, error)
Exemplo n.º 9
0
 def _log_stack(self, sp):
     ram_total = self.machine.get_ram_total()
     vals = []
     for x in range(-32, 32, 4):
         addr = sp + x
         if addr >= 0 and addr < ram_total:
             val = self.mem.r32(sp + x)
             vals.append("SP%+03d=%06x" % (x, val))
         else:
             vals.append("SP%+03d=------" % x)
     log_machine.error(" ".join(vals[0:8]))
     log_machine.error(" ".join(vals[8:]))
Exemplo n.º 10
0
 def _log_stack(self, sp):
   ram_total = self.machine.get_ram_total()
   vals = []
   for x in range(-32, 32, 4):
     addr = sp + x
     if addr >= 0 and addr < ram_total:
       val = self.mem.r32(sp + x)
       vals.append("SP%+03d=%06x" % (x, val))
     else:
       vals.append("SP%+03d=------" % x)
   log_machine.error(" ".join(vals[0:8]))
   log_machine.error(" ".join(vals[8:]))
Exemplo n.º 11
0
 def _log_cpu_state(self):
     # give CPU state dump
     cpu_state = CPUState()
     cpu_state.get(self.cpu)
     pc = cpu_state.pc
     if self.label_mgr:
         label, offset = self.label_mgr.get_label_offset(pc)
     else:
         label, offset = None, 0
     if label is not None:
         log_machine.error("PC=%08x -> +%06x %s", pc, offset, label)
     for d in cpu_state.dump():
         log_machine.error(d)
     # stack range dump
     sp = cpu_state.ax[7]
     self._log_stack(sp)
Exemplo n.º 12
0
 def _log_cpu_state(self):
   # give CPU state dump
   cpu_state = CPUState()
   cpu_state.get(self.cpu)
   pc = cpu_state.pc
   if self.label_mgr:
     label, offset = self.label_mgr.get_label_offset(pc)
   else:
     label, offset = None, 0
   if label is not None:
     log_machine.error("PC=%08x -> +%06x %s", pc, offset, label)
   for d in cpu_state.dump():
     log_machine.error(d)
   # stack range dump
   sp = cpu_state.ax[7]
   self._log_stack(sp)
Exemplo n.º 13
0
  def from_cfg(cls, machine_cfg, use_labels=False):
    """extract machine parameters from the config

       return new Machine() or None on config error
    """
    cpu = machine_cfg.cpu
    cpu_type, cpu_name = cls.parse_cpu_type(cpu)
    if cpu_type is None:
      log_machine.error("invalid CPU type given: %s", cpu)
      return None
    ram_size = machine_cfg.ram_size
    cycles_per_run = machine_cfg.cycles_per_run
    max_cycles = machine_cfg.max_cycles
    log_machine.info("cpu=%s(%d), ram_size=%d, labels=%s, "
                     "cycles_per_run=%d, max_cycles=%d",
                     cpu_name, cpu_type, ram_size, use_labels,
                     cycles_per_run, max_cycles)
    return cls(cpu_type, ram_size,
               raise_on_main_run=False,
               use_labels=use_labels,
               cycles_per_run=cycles_per_run,
               max_cycles=max_cycles,
               cpu_name=cpu_name)
Exemplo n.º 14
0
 def _log_run_state(self):
   # get current run_state
   run_state = self.machine.get_cur_run_state()
   log_machine.error("Run: '%s': Initial PC=%06x, SP=%06x",
                     run_state.name, run_state.pc, run_state.sp)