📄 gdb-4.18-bdm-m68k.patch
字号:
++ 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 wrong BDM driver");+ }++ /*+ * 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;+ 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 ("Remote %s connected to %s\n", target_shortname, dev_name);+}++/*+ * 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_get_status () & BDM_TARGETSTOPPED)+ bdm_go ();+}++static void+bdm_close (quitting)+int quitting;+{+ if (quitting)+ bdm_kill ();+ bdmClose ();+}++/*+ * _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)+{+ pop_target (); /* calls bdm_close to do the real work */+}++/*+ * _resume -- Tell the remote machine to resume.+ */+static void+bdm_resume (int pid, int step, enum target_signal sig)+{+ if (step)+ bdm_step_chip ();+ else+ bdm_go ();+}++/*+ * 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 int+bdm_wait (int pid, struct target_waitstatus *status)+{+ unsigned long csr;+ int bdm_stat;+ void (*ofunc) ();++ if (bdm_gdb_no_wait) {+ status->kind = TARGET_WAITKIND_STOPPED;+ status->value.sig = TARGET_SIGNAL_GRANT;+ return 0;+ }+ + status->kind = TARGET_WAITKIND_EXITED;+ status->value.integer = 0;++ /*+ * Catch SIGINT signals+ */+ sigintFlag = 0;+ ofunc = signal (SIGINT, bdm_signal_handler);++ /*+ * Wait here till the target requires service+ */+ while ((bdm_stat = bdm_get_status ()) == 0) {+ nap (500000);+ if (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 (!haveAtemp+ && (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 ();+ switch (csr & 0x0f000000) {+ case 0x08000000: /* double bus fault */+ status->kind = TARGET_WAITKIND_STOPPED;+ status->value.sig = TARGET_SIGNAL_BUS;+ break;+ case 0x04000000: /* HW bkpt */+ case 0x03000000: /* we have both, treat it as a brk signal */+ case 0x01000000: /* bkpt signal asserted */+ status->kind = TARGET_WAITKIND_STOPPED;+ status->value.sig = TARGET_SIGNAL_TRAP;+ break;+ case 0x02000000: /* background mode */+ analyze_exception (status);+ break;+ default:+ 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;+ }+ haveAtemp = 0;+ return 0;+}++/* This is called not only when we first attach, but also when the+ user types "run" after having attached. */+void+bdm_create_inferior (char *execfile, char *args, char **env)+{+ char *prg_file = NULL;+ unsigned long entry_pt;++ clear_proceed_status ();+ init_wait_for_inferior ();+ if (*args) {+ prg_file = args;+ }+ else {+ prg_file = execfile;+ }+ if (!(prg_file) && !(bdm_prog_loaded))+ error ("No program specified to run\n");+ if (bdm_prog_loaded)+ printf_filtered ("Note: `%s' has already been loaded.\n", bdm_prog_loaded);+ if (query ("Do you want to download `%s'?", prg_file))+ bdm_load (prg_file, 0);+ if (bdmReadSystemRegister (BDM_REG_RPC, &entry_pt) < 0)+ bdm_report_error ();+ proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);+}++/*+ * Fetch register REGNO, or all user registers if REGNO is -1.+ */+static void+bdm_fetch_register (int regno)+{+ unsigned long l;+ char cbuf[4];+ int ret;++ if (regno < 0) {+ for (regno = 0 ; regno < NUM_REGS ; regno++)+ bdm_fetch_register (regno);+ }+ else {+ /*+ * When the target is running the + * cpu registers can not be accessed.+ */+ if (bdm_gdb_no_wait && (bdm_get_status () == 0)) {+ l = 0;+ ret = 0;+ }+ else {+ if (regno < 16) {+ ret = bdmReadRegister (regno, &l);+ }+ else {+ if ((regno - 16) < (sizeof (reg_to_dev_num) / sizeof (int))) {+ ret = bdmReadSystemRegister (reg_to_dev_num[regno - 16], &l);+ }+ else {+ error ("Bad register number (%d)", regno); + return;+ }+ }+ }+ if (ret < 0)+ bdm_report_error ();+ cbuf[0] = l >> 24;+ cbuf[1] = l >> 16;+ cbuf[2] = l >> 8;+ cbuf[3] = l;+ supply_register (regno, cbuf);+ }+}++void+bdm_prepare_to_store (void)+{+ /* Do nothing, since we can store individual regs */+}++/*+ * Store register REGNO, or all user registers if REGNO == -1.+ */+void+bdm_store_register (int regno)+{+ unsigned long l;+ int ret;++ if (bdm_gdb_no_wait && (bdm_get_status () == 0))+ return;+ + if (regno == -1) {+ for (regno = 0 ; regno < NUM_REGS ; regno++)+ bdm_store_register (regno);+ }+ else {+ l = read_register (regno);+ if (regno < 16) {+ ret = bdmWriteRegister (regno, l);+ }+ else {+ if ((regno - 16) < (sizeof (reg_to_dev_num) / sizeof (int))) {+ ret = bdmWriteSystemRegister (reg_to_dev_num[regno - 16], l);+ }+ else {+ error ("Bad register number (%d)", regno); + return;+ }+ }+ if (ret < 0)+ bdm_report_error ();+ }+}++/*+ * Transfer memory contents between target and host+ */+static int+bdm_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, struct target_ops *t)+{+ int ret;++ if (write)+ ret = bdmWriteMemory (memaddr, myaddr, len);+ else+ ret = bdmReadMemory (memaddr, myaddr, len);+ if (ret < 0)+ bdm_report_error ();+ return len;+}++static void+bdm_files_info (struct target_ops *t)+{+ printf_filtered ("target %s is attached to %s\n", t->to_shortname, dev_name);+ if (bdm_prog_loaded) {+ printf_filtered ("and running program %s\n", bdm_prog_loaded);+ }+ else {+ printf_filtered ("no program loaded\n");+ }+}++/*+ * Load a file.+ */+static void+bdm_load (char *args, int from_tty)+{+ char *p;++ if (bdm_prog_loaded) {+ free (bdm_prog_loaded);+ bdm_prog_loaded = NULL;+ }+ if (!args) {+ error (+ "The bdmload command must include the filename to load.\n"+ "You may want to use 'run', which uses the file given\n"+ "on the command line when gdb was invoked.");+ }+ if ((bdm_get_status () & BDM_TARGETSTOPPED) == 0)+ bdm_stop_chip ();++ /* strip off additional (unwanted) arguments after file name */+ for (p = args; (*p != '\0') && (!isspace (*p)); p++) ;+ *p = '\0';++ if (loadExecutable (args) < 0)+ error ("%s", downloadErrorString);+ bdm_prog_loaded = savestring (args, strlen (args));+}++struct target_ops bdm_ops;++static void+init_bdm_ops(void)+{+ bdm_ops.to_shortname = "bdm";+ bdm_ops.to_longname = "CPU32 and Coldfire Background Debug Mode Interface for downloading and remote debugging";+ bdm_ops.to_doc = "Uses the Public Domain Background Debug Mode Interface connected to the\n"+"BDM-port of the CPU32 or Coldfire based microcontroller and to a parallel port\n"+"of the PC.\n"+"Usage: target bdm <device>\n"+"where <device> is the BDM character special file (e.g. /dev/bdm0).";+ bdm_ops.to_open = bdm_open;+ bdm_ops.to_close = bdm_close;+ bdm_ops.to_detach = bdm_detach;+ bdm_ops.to_resume = bdm_resume;+ bdm_ops.to_wait = bdm_wait;+ bdm_ops.to_fetch_registers = bdm_fetch_register;+ bdm_ops.to_store_registers = bdm_store_register;+ bdm_ops.to_prepare_to_store = bdm_prepare_to_store;+ bdm_ops.to_xfer_memory = bdm_xfer_inferior_memory;+ bdm_ops.to_files_info = bdm_files_info;+ bdm_ops.to_insert_breakpoint = memory_insert_breakpoint;+ bdm_ops.to_remove_breakpoint = memory_remove_breakpoint;+ bdm_ops.to_kill = bdm_kill;+ bdm_ops.to_load = bdm_load;+ bdm_ops.to_create_inferior = bdm_create_inferior;+ bdm_ops.to_mourn_inferior = generic_mourn_inferior;+ bdm_ops.to_can_run = bdm_can_run;+ bdm_ops.to_stratum = process_stratum;+ bdm_ops.to_has_all_memory = 1;+ bdm_ops.to_has_memory = 1;+ bdm_ops.to_has_stack = 1;+ bdm_ops.to_has_registers = 1;+ bdm_ops.to_has_execution = 1;+ bdm_ops.to_magic = OPS_MAGIC;+};++void+_initialize_remote_bdmcf (void)+{+ init_bdm_ops ();+ add_com ("bdm_reset", class_obscure,+ (void (*)(char *, int))bdm_reset,+ "Reset target and enter BDM mode.");+ add_com ("bdm_release", class_obscure,+ (void (*)(char *, int))bdm_release_chip,+ "Reset target without BDM-mode.");+ add_com ("bdm_status", class_obscure,+ (void (*)(char *, int))bdm_get_status_interactive,+ "Show status of bdm interface\n");+ add_com ("bdm_setdelay", class_obscure,+ bdm_setdelay_interactive,+ "set delay for download");+ add_com ("bdm_setdebug", class_obscure,+ bdm_setdebug_interactive,+ "enable/disable BDM diagnostic messages");+ add_com ("bdm_setdriverdebug", class_obscure,+ bdm_setdriverdebug_interactive,+ "enable/disable BDM driver diagnostic messages");+ add_com ("bdm_no_wait", class_obscure,+ bdm_set_no_wait,+ "Cause GDB to not wait for the target to stop when running.");+ add_com ("bdm_wait", class_obscure,+ bdm_set_wait,+ "Cause GDB to wait for the target to stop when running.");+ add_com ("bdm_stop", class_obscure,+ bdm_issue_stop,+ "Stop the target if running.");+ add_target (&bdm_ops);+}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -