⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdb-6.1-bdm-m68k.patch

📁 WaitForSingleObject 摩托罗拉的68k源程序
💻 PATCH
📖 第 1 页 / 共 5 页
字号:
+{+  char          *p;+  int           version;+  unsigned long csr;++  if (bdm_debug_level)+    printf_filtered ("bdm open called\n");+  +  if (bdmIsOpen ())+    bdm_close (0);+  if (name == NULL)+    error ("Use `target bdm <DEVICE-NAME>' to use the bdm target");++  bdm_ptid = null_ptid;++  /*+   * Find the first whitespace character after device and chop it off+   */+  for (p = name; (*p != '\0') && (!isspace (*p)); p++) ;+  if ((*p == '\0') && (p == name))+    error ("Please include the name the bdm port device.");+  dev_name = savestring (name, p - name);++  target_preopen (from_tty);+  unpush_target (&bdm_ops);++  if (bdmOpen (dev_name) < 0)+    bdm_report_error ();+  if (bdmStatus () & (BDM_TARGETPOWER | BDM_TARGETNC)) {+    bdmClose ();+    error ("Target or cable problem");+  }++  /*+   * Ask the driver for it's version.+   * We are only interested in the major number when checking the +   * driver version number.+   */+  if (bdmGetDrvVersion (&version) < 0)+    bdm_report_error ();+  if ((version & 0xff00) != (BDM_DRV_VERSION & 0xff00)) {+    printf_filtered ("Incorrect driver version, looking for %i.%i"\+                     " and found %i.%i\n", +                     BDM_DRV_VERSION >> 8, BDM_DRV_VERSION & 0xff, +                     version >> 8, version  & 0xff);+    bdmClose ();+    error ("Can't run with incorrect BDM driver version");+  }++  /*+   * Get the processor type.+   */+  if (bdmGetProcessor (&cpu_type) < 0)+    bdm_report_error ();+  switch (cpu_type) {+    case BDM_CPU32:+      bdm_reg_names = cpu32_reg_names;+      breakpointCode = cpu32_breakpoint;+      breakpointSize = sizeof cpu32_breakpoint;+      break;++    case BDM_COLDFIRE:+      bdm_reg_names = cf_reg_names;+      breakpointCode = cf_breakpoint;+      breakpointSize = sizeof cf_breakpoint;+      cf_init_watchpoints();++      /*+       * Read the CSR register to determine the debug module+       * version.+       */+      if (bdmReadSystemRegister (BDM_REG_CSR, &csr) < 0)+        bdm_report_error ();+      cf_debug_ver = (csr >> 20) & 0x0f;+      +      /*+       * If the processor is a version 0 read the PC and VBR+       * an if they can be read read the mbar. If that fails+       * we have a 5282.+       */+      reg_to_dev_num[13] = BDM_REG_RAMBAR;+      reg_to_dev_num[14] = BDM_REG_MBAR;+      reg_to_dev_num[15] = -1;+      reg_to_dev_num[16] = -1;+      reg_to_dev_num[17] = -1;+      reg_to_dev_num[18] = -1;+      reg_to_dev_num[19] = -1;+      reg_to_dev_num[20] = -1;+      reg_to_dev_num[21] = -1;+      reg_to_dev_num[22] = -1;++      if (cf_debug_ver == 0) {+        unsigned long junk;+        if ((bdmReadSystemRegister (BDM_REG_RPC, &junk) == 0) &&+            (bdmReadSystemRegister (BDM_REG_VBR, &junk) == 0)) {+          if (bdmReadSystemRegister (BDM_REG_MBAR, &junk) < 0) {+            bdm_reg_names = cf5282_reg_names;+            reg_to_dev_num[13] = 0xc05;+            reg_to_dev_num[14] = 0xc04;+            reg_to_dev_num[15] = 0x804;+            reg_to_dev_num[16] = 0x805;+            reg_to_dev_num[17] = 0x806;+            reg_to_dev_num[18] = 0x809;+            reg_to_dev_num[19] = 0x80a;+            reg_to_dev_num[20] = 0x80b;+            reg_to_dev_num[21] = 0x807;+            reg_to_dev_num[22] = 0x808;+            printf_filtered ("Detected MCF5282\n");+          }+          else {+            bdm_reg_names = cf5272_reg_names;+            reg_to_dev_num[13] = BDM_REG_RAMBAR;+            reg_to_dev_num[14] = BDM_REG_MBAR;+            reg_to_dev_num[15] = 0x804;+            reg_to_dev_num[16] = 0x805;+            reg_to_dev_num[17] = 0x806;+            printf_filtered ("Detected V2 core\n");+          }+        }+      }+      break;++    default:+      bdmClose ();+      error ("Unknown processor type returned from the driver.");+  }++  push_target (&bdm_ops);++  if (bdm_delay >= 0)+    bdm_setdelay (bdm_delay);+  else+    bdm_setdelay (BDM_DEFAULT_DELAY);+  if (from_tty)+    printf_filtered ("GDB target %s connected to %s\n",+                     target_shortname, dev_name);+  if (cpu_type == BDM_COLDFIRE)+    printf_filtered (" Coldfire debug module version is %ld (%s)\n",+                     cf_debug_ver,+                     cf_debug_ver == 0 ? "5206(e)/5272/5282" : "5307/5407(e)");+}++/*+ * Terminate current application and return to system prompt.+ * On a target, just let the program keep on running+ */+static void+bdm_kill (void)+{+  if (bdm_debug_level)+    printf_filtered ("bdm kill called\n");+#ifdef BDM_GDB_RELEASE_CPU_ON_EXIT+  if (bdm_get_status () & BDM_TARGETSTOPPED)+    bdm_go ();+#else  +  bdm_stop_chip ();+  bdm_reset ();+#endif+  BDM_FREE_PROG_LOADED ();+}++static void+bdm_close (int quitting)+{+  if (bdm_debug_level)+    printf_filtered ("bdm close called\n");+  bdm_gdb_is_quitting = quitting;+  have_atemp = 0;+  if (quitting)+    bdm_kill ();+  bdmClose ();+  BDM_FREE_PROG_LOADED ();+  inferior_ptid = bdm_ptid = null_ptid;+}++static void+bdm_attach (char *args, int from_tty)+{+  if (bdm_debug_level)+    printf_filtered ("bdm attach called\n");+  bdm_open (args, from_tty);+}++/*+ * _detach -- Terminate the open connection to the remote debugger.+ * takes a program previously attached to and detaches it.+ * We better not have left any breakpoints+ * in the program or it'll die when it hits one.+ * Close the open connection to the remote debugger.+ * Use this when you want to detach and do something else+ * with your gdb.+ */+static void+bdm_detach (char *args, int from_tty)+{+  if (bdm_debug_level)+    printf_filtered ("bdm detach called\n");+  BDM_FREE_PROG_LOADED ();+  inferior_ptid = bdm_ptid = null_ptid;+  pop_target ();    /* calls bdm_close to do the real work */+}++/*+ * _resume -- Tell the remote machine to resume.+ */+static void+bdm_resume (ptid_t pid, int step, enum target_signal sig)+{+  if (bdm_debug_level)+    printf_filtered ("bdm resume called\n");+  if (step)+    bdm_step_chip ();+  else+    bdm_go ();+  bdm_ptid = pid_to_ptid (42000);+}++/*+ * We have fallen into an exception supported by the runtime system.+ * by executing a `breakpoint' instruction.+ */+static void +analyze_exception (struct target_waitstatus *status)+{+  unsigned long pc, sp;+  unsigned short vec;+  char opcode[20]; /* `big enough' */++  if (cpu_type == BDM_CPU32) {+    if (bdmReadSystemRegister (BDM_REG_PCC, &pc) < 0)+      bdm_report_error ();+  }+  else {+    if (bdmReadSystemRegister (BDM_REG_RPC, &pc) < 0)+      bdm_report_error ();+    if (pc)+      pc -= 2;+  }+  status->kind = TARGET_WAITKIND_STOPPED;++  /*+   * See if it was a `breakpoint' instruction+   */+  if (bdmReadMemory (pc, opcode, breakpointSize) < 0)+    bdm_report_error ();+  if (memcmp (breakpointCode, opcode, breakpointSize) == 0) {+    if (bdmWriteSystemRegister (BDM_REG_RPC, pc) < 0)+      bdm_report_error ();+    status->value.sig = TARGET_SIGNAL_TRAP;+    return;+  }+  /*+   * FIXME: Why an illegal instruction signal ?+   */+  status->value.sig = TARGET_SIGNAL_ILL;+}++static int sigintFlag;+static void +bdm_signal_handler (int s)+{+  sigintFlag++;+}++/*+ * Wait until the remote machine stops, then return,+ * storing status in status just as `wait' would.+ */+static ptid_t+bdm_wait (ptid_t pid, struct target_waitstatus *status)+{+  unsigned long csr;+  int bdm_stat;+  int detach = 0;+  int ui_count = 0;+  void (*ofunc) ();++  hit_watchpoint = 0;+  if (bdm_gdb_no_wait) {+    status->kind = TARGET_WAITKIND_STOPPED;+    status->value.sig = TARGET_SIGNAL_GRANT;+    return bdm_ptid;+  }++  status->kind = TARGET_WAITKIND_EXITED;+  status->value.integer = 0;++  /*+   * Catch SIGINT signals+   */+  sigintFlag = 0;+  ofunc = signal (SIGINT, bdm_signal_handler);++  /*+   * A work around a problem with the 5206e processor. Not sure+   * what the issue is. It could be the processor.+   */+  if (cpu_type == BDM_COLDFIRE && cf_debug_ver == 0)+    nap (10000);++  /*+   * Wait here till the target requires service+   */+  while ((bdm_stat = bdm_get_status ()) == 0) {+    ui_count = 0;+    while (ui_count++ < 6) {+      nap (50000);++      /* N.B. The UI may destroy our world (for instance by calling+         remote_stop,) in which case we want to get out of here as+         quickly as possible.  It is not safe to touch scb, since+         someone else might have freed it.  The ui_loop_hook signals that +         we should exit by returning 1. */++      if (ui_loop_hook)+        detach = ui_loop_hook (0);++      if (detach || sigintFlag)+        bdm_stop_chip ();+    }+  }+  +  signal (SIGINT, ofunc);++  /*+   * Determine why the target stopped+   */+  switch (bdm_stat) {+    case BDM_TARGETNC:+      status->kind = TARGET_WAITKIND_EXITED;+      status->value.integer = 9999;+      break;+    case BDM_TARGETPOWER:+      status->kind = TARGET_WAITKIND_STOPPED;+      status->value.sig = TARGET_SIGNAL_PWR;+      break;+    case BDM_TARGETRESET:+      status->kind = TARGET_WAITKIND_STOPPED;+      status->value.sig = TARGET_SIGNAL_ABRT;+      break;+    case BDM_TARGETSTOPPED:+    case BDM_TARGETHALT:+    case BDM_TARGETSTOPPED | BDM_TARGETHALT:+      if (sigintFlag) {+        status->kind = TARGET_WAITKIND_STOPPED;+        status->value.sig = TARGET_SIGNAL_TSTP;+      }+      else {+        if (cpu_type == BDM_CPU32) {+          if (!have_atemp+              && (bdmReadSystemRegister (BDM_REG_ATEMP, &atemp) < 0))+            bdm_report_error ();+          switch (atemp & 0xffff) {+            case 0xffff:  /* double bus fault */+              status->kind = TARGET_WAITKIND_STOPPED;+              status->value.sig = TARGET_SIGNAL_BUS;+              break;+            case 0x0:  /* HW bkpt */+              status->kind = TARGET_WAITKIND_STOPPED;+              status->value.sig = TARGET_SIGNAL_TRAP;+              break;+            case 0x1:  /* background mode */+              analyze_exception (status);+              break;+            default:+              printf_filtered ("bdm_wait: Unknown atemp:%#lx\n", atemp);+              status->kind = TARGET_WAITKIND_STOPPED;+              status->value.sig = TARGET_SIGNAL_GRANT;+          }+        }+        else {+          if (bdmReadSystemRegister (BDM_REG_CSR, &csr) < 0)+            bdm_report_error ();+          if (csr & 0x08000000)  {                /* double bus fault */+            status->kind = TARGET_WAITKIND_STOPPED;+            status->value.sig = TARGET_SIGNAL_BUS;+          }+          else  {+            if (csr & 0x04000000)  {          /* hardware trigger */+              hit_watchpoint = 1;+              status->kind = TARGET_WAITKIND_STOPPED;+              status->value.sig = TARGET_SIGNAL_TRAP;+            }+            else  {+              if (csr & 0x01000000)  {      /* -BKPT signal */+                status->kind = TARGET_WAITKIND_STOPPED;+                status->value.sig = TARGET_SIGNAL_TRAP;+              }+              else  {+                if (csr & 0x02000000)  {    /* HALT/software bkpt */+                  analyze_exception (status);+                }+                else  {+                  printf_filtered ("bdm_wait: Unknown csr:%#lx",+                                   csr);+                  status->kind = TARGET_WAITKIND_STOPPED;+                  status->value.sig = TARGET_SIGNAL_GRANT;+                }+              }+            }+          }+        }+      }+      break;+    default:+      printf_filtered ("bdm_wait: Unknown BDM status: %#x", bdm_stat);+      break;+  }+  have_atemp = 0;+  return bdm_ptid;+}++/* This is called not only when we first attach, but also when the+   user types "run" after having attached.  */+static void+bdm_create_inferior (char *execfile, char *args, char **env)+{+  CORE_ADDR addr = -1;;+  +  if (bdm_debug_level)+    printf_filtered ("bdm create inferior called\n");++  if (!bdmIsOpen ())+    error ("Not attached to the target. Use `target bdm <DEVICE-NAME>' command to attach.\n");++  /*+   * If we do not load an executable, reset and step the processor to get a+   * valid PC.+   */+  +  if (bdm_no_load)+  {+    bdm_reset ();+    bdm_step_chip ();+  }+  else+  {+    bdm_load (execfile, 0);+    addr = bfd_get_start_address (exec_bfd);+  }+  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -