📄 mpcbdm.c
字号:
do { pFormat++; } while (isdigit(*pFormat)); } else bit = startbit + 1; } strncpy(FieldName,pFieldName,len); FieldName[len]= 0; bitmask = PPC_BIT(startbit); bitfieldval = 0; for (i = startbit; i<bit;i++) { bitfieldval = (bitfieldval << 1); if (val & bitmask) bitfieldval |=1; bitmask = bitmask >> 1; } if (len != 0) /*name, no spare bit field?*/ { if (bit-startbit >1) /*multi bitfield*/ { if (!bFirstPrinted) { bFirstPrinted = 1; printf(" = ("); } else printf("|"); printf("%s=0x%x",FieldName,bitfieldval); } else if (bitfieldval) /*single bit*/ { if (!bFirstPrinted) { bFirstPrinted = 1; printf(" = ("); } else printf("|"); printf("%s",FieldName); } } if (bit >= PPC_BITS) { break; } startbit = bit; } if (bFirstPrinted) printf(")"); }}static void mpcbdm_spr_command (char *args, int from_tty){ int reg; u_int val; char *name; char *svalue = 0; char *pch; int i; int num; if (!args) { printf_filtered("List of supported SPRs:\n"); for(i = 0; sprnames[i].name ; ++i) { printf_filtered("%s",sprnames[i].name); num = sprnames[i].num; if (num & SPRI_MASK) printf_filtered("\tIMMR + 0x%x",num & ~SPRI_MASK); else if (num & SPR_MASK) printf_filtered("\t"); else printf_filtered("\tSPR %d ",num); if (sprnames[i].Longname) { printf_filtered("\t%s", sprnames[i].Longname); } printf_filtered("\n"); } return; } if (mpcbdm_reattach) { printf_filtered("!C\n"); return; } if (pch = strchr(args,'=')) /*set command ?*/ { svalue = pch+1; while(*svalue <= 040) ++svalue; /*read spaces*/ *pch-- = 0; while(*pch <= 040) *pch-- = 0; } if (isdigit(*args)) /*spr by number?*/ { reg = strtol(args,0,0); } else /*by name?*/ { reg = findsprnum(args); } if (reg < 0) { printf_filtered("Invalid SPR\n"); return; } if (svalue) /*set command?*/ { val = strtoul(svalue,0,0); bdm_setspr(reg,val); /*set value*/ } else /* show register */ { if (reg == SPR_ICR) /* reading ICR clears bits, so show old values */ { val = LastICR; } else val = bdm_getspr(reg); print_spr_info(reg,val,1,1,1,1); /* show register name, def, val and pretty */ printf_filtered("\n"); }}/************************************************************ routines from ppc-bdm.c ************************************************************//* Wait until the remote machine stops, then return, storing status in STATUS just as `wait' would. Returns "pid" (though it's not clear what, if anything, that means in the case of this target). */static int bdm_ppc_wait (int pid, struct target_waitstatus *target_status){ int stop_reason; if (mpcbdm_verbose&VERBOSE_SER) { printf("bdm_ppc_wait:\n"); } target_status->kind = TARGET_WAITKIND_STOPPED; stop_reason = ppc_bdm_wait(); if (stop_reason) { target_status->value.sig = TARGET_SIGNAL_INT; return inferior_pid; } target_status->value.sig = TARGET_SIGNAL_TRAP; /* XXX for now */ return inferior_pid;}/* Read the remote registers into regs. Fetch register REGNO, or all registers if REGNO == -1 */static void bdm_ppc_fetch_registers (int regno){ int i; int first; int last; int val; if (mpcbdm_verbose&VERBOSE_SER) { printf("bdm_ppc_fetch_registers: regno %d",regno); } if(regno == -1) { first = 0; last = NUM_REGS-1; } else { first = last = regno; } for (i = first; i <= last; i++) { if(i == MQ_REGNUM || (i >= FP0_REGNUM && i <= FPLAST_REGNUM)) { supply_register(i, 0); continue; } val = ppc_read_bdm_register(bdm_regmap[i]); supply_register(i, (char*)&val); }}/* Store register REGNO, or all registers if REGNO == -1, from the contents of REGISTERS. FIXME: ignores errors. */static void bdm_ppc_store_registers (int regno){ int i; int first; int last; int val; if (mpcbdm_verbose&VERBOSE_TAR) { printf("bdm_ppc_store_registers: regno %d",regno); } if(regno == -1) { first = 0; last = NUM_REGS-1; } else { first = last = regno; } for (i = first; i <= last; i++) { if(i == MQ_REGNUM || (i >= FP0_REGNUM && i <= FPLAST_REGNUM)) continue; memcpy (&val , ®isters[REGISTER_BYTE (i)], REGISTER_RAW_SIZE (i)); ppc_write_bdm_register(bdm_regmap[i], val); }}/* Define the target subroutine names */static void init_mpcbdm_ops(void){ mpcbdm_ops.to_shortname = "mpcbdm"; mpcbdm_ops.to_longname = "Background Debug Mode Interface for Motorola MPC-Family"; mpcbdm_ops.to_doc = "Use On-Chip Debugging on MPC's via parallel port BDM interface" ; /* to_doc */ mpcbdm_ops.to_open = mpcbdm_open; mpcbdm_ops.to_close = mpcbdm_close; mpcbdm_ops.to_attach = NULL; mpcbdm_ops.to_post_attach = NULL; mpcbdm_ops.to_require_attach = NULL; mpcbdm_ops.to_detach = mpcbdm_detach; mpcbdm_ops.to_require_detach = NULL; mpcbdm_ops.to_resume = mpcbdm_resume; mpcbdm_ops.to_wait = bdm_ppc_wait; mpcbdm_ops.to_post_wait = NULL; mpcbdm_ops.to_fetch_registers = bdm_ppc_fetch_registers; mpcbdm_ops.to_store_registers = bdm_ppc_store_registers; mpcbdm_ops.to_prepare_to_store = mpcbdm_prepare_to_store; mpcbdm_ops.to_xfer_memory = mpcbdm_xfer_memory; mpcbdm_ops.to_files_info = mpcbdm_files_info; mpcbdm_ops.to_insert_breakpoint = mpcbdm_insert_breakpoint; mpcbdm_ops.to_remove_breakpoint = mpcbdm_remove_breakpoint; mpcbdm_ops.to_terminal_init = NULL; mpcbdm_ops.to_terminal_inferior = NULL; mpcbdm_ops.to_terminal_ours_for_output = NULL; mpcbdm_ops.to_terminal_ours = NULL; mpcbdm_ops.to_terminal_info = NULL; mpcbdm_ops.to_kill = mpcbdm_kill; mpcbdm_ops.to_load = mpcbdm_load; mpcbdm_ops.to_lookup_symbol = NULL; mpcbdm_ops.to_create_inferior = mpcbdm_create_inferior; mpcbdm_ops.to_post_startup_inferior = NULL; mpcbdm_ops.to_acknowledge_created_inferior = NULL; mpcbdm_ops.to_clone_and_follow_inferior = NULL; mpcbdm_ops.to_post_follow_inferior_by_clone = NULL; mpcbdm_ops.to_insert_fork_catchpoint = NULL; mpcbdm_ops.to_remove_fork_catchpoint = NULL; mpcbdm_ops.to_insert_vfork_catchpoint = NULL; mpcbdm_ops.to_remove_vfork_catchpoint = NULL; mpcbdm_ops.to_has_forked = NULL; mpcbdm_ops.to_has_vforked = NULL; mpcbdm_ops.to_can_follow_vfork_prior_to_exec = NULL; mpcbdm_ops.to_post_follow_vfork = NULL; mpcbdm_ops.to_insert_exec_catchpoint = NULL; mpcbdm_ops.to_remove_exec_catchpoint = NULL; mpcbdm_ops.to_has_execd = NULL; mpcbdm_ops.to_reported_exec_events_per_exec_call = NULL; mpcbdm_ops.to_has_exited = NULL; mpcbdm_ops.to_mourn_inferior = mpcbdm_mourn; mpcbdm_ops.to_can_run = 0; mpcbdm_ops.to_notice_signals = 0; mpcbdm_ops.to_thread_alive = mpcbdm_thread_alive; mpcbdm_ops.to_stop = ppc_bdm_stop; mpcbdm_ops.to_pid_to_exec_file = NULL; mpcbdm_ops.to_core_file_to_sym_file = NULL; mpcbdm_ops.to_stratum = process_stratum; mpcbdm_ops.DONT_USE = NULL; mpcbdm_ops.to_has_all_memory = 1; mpcbdm_ops.to_has_memory = 1; mpcbdm_ops.to_has_stack = 1; mpcbdm_ops.to_has_registers = 1; mpcbdm_ops.to_has_execution = 1; mpcbdm_ops.to_sections = NULL; mpcbdm_ops.to_sections_end = NULL; mpcbdm_ops.to_magic = OPS_MAGIC ; } /* init_mpcbdm_ops *//************************************************************ mpcbdm obscure routines ************************************************************/static void mpcbdm_obscure_upms(char *args, int from_tty){ int n; printf("============\n"); for(n = 0; n < 64; ++n) { bdm_setspr(SPRI_MCR, (01 << 30) | n); printf("MDR%02d=0x%08x ", n, bdm_getspr(SPRI_MDR)); if(!((n+1) % 4)) printf("\n"); } printf("============\n"); printf("BR0=0x%08x\n", bdm_getspr(SPRI_BRx(0))); printf("OR0=0x%08x\n", bdm_getspr(SPRI_ORx(0))); printf("BR1=0x%08x\n", bdm_getspr(SPRI_BRx(1))); printf("OR1=0x%08x\n", bdm_getspr(SPRI_ORx(1))); printf("BR2=0x%08x\n", bdm_getspr(SPRI_BRx(2))); printf("OR2=0x%08x\n", bdm_getspr(SPRI_ORx(2))); printf("MAMR=0x%08x\n", bdm_getspr(SPRI_MAMR)); printf("MAR=0x%08x\n", bdm_getspr(SPRI_MAR)); printf("MDR=0x%08x\n", bdm_getspr(SPRI_MDR)); printf("MCR=0x%08x\n", bdm_getspr(SPRI_MCR)); printf("MSTAT=0x%08x\n", bdm_getspr(SPRI_MSTAT));}static void show_spr(char *args, int from_tty){ int i; u_int val; int RegList[] = { SPR_SRR0, SPR_SRR1, SPR_MSR, SPR_BAR, SPR_DAR, SPR_DSISR, SPR_DER, SPR_ICR, SPR_ICTRL, SPRI_PLPRCR, SPRI_RSR, SPRI_SCCR, SPRI_SYPCR, SPRI_SIUMCR, 0 }; for (i = 0; RegList[i]; i++) { val = bdm_getspr(RegList[i]); print_spr_info(RegList[i], val,1,0,0,0); /* show name*/ printf_filtered("\t"); print_spr_info(RegList[i], val,0,0,1,1); /* val and pretty */ printf_filtered("\n"); }}/****************************************************************** memory dump routines ******************************************************************/static char * parse_filename(char** sArgs){ char *fq; char *lq; if (!sArgs) return NULL; if (!(*sArgs)) return NULL; fq = strchr(*sArgs,'\"'); /* get first double quote */ if (!fq) return NULL; lq = strrchr(*sArgs,'\"'); /* get last double quote */ if ((!lq) || (lq <= fq)) return NULL; (*lq) = 0; /* set end of filename string FIXME: better copy name, instead of messing arround?*/ (*sArgs) = lq + 1; /* adjust argument pointer */ return fq + 1; /*return pointer to beginning of filename*/}/*****************************************************************/static void mem_load(char * sFilename, u_int start, u_int len){ FILE * f; u_int nTotal; u_int nBuffer; u_int nLeft; int nResult; printf_filtered("mem load \"%s\" to 0x%08x len %d\n", sFilename, start, len); if (!sFilename) { error("parameter syntax error."); return; } f = fopen(sFilename, "rb"); if(!f) { error("failed to open input file."); return; } if (!len) { nResult = fseek(f, 0, SEEK_END); if (nResult) { error("fseek error."); if (f) fclose(f); return; } len = ftell(f); printf_filtered(" len = 0x%08x, total file length\n", len); rewind(f); } for (nTotal = 0, nLeft = len; nLeft > 0; nTotal += nBuffer, nLeft -= nBuffer) { if(nLeft > MAXBUFFERLEN) { nBuffer = MAXBUFFERLEN; } else { nBuffer = nLeft; } nResult = fread(FileBuffer, 1, nBuffer, f); if (nResult != nBuffer) { error("read error."); break; } ppc_bdm_write_block(start + nTotal, FileBuffer, nBuffer); } if (f) fclose(f);}/*****************************************************************/static void mem_save(char * sFilename, u_int start, u_int len){ FILE * f; u_int nTotal; u_int nBuffer; u_int nLeft; int nResult; printf_filtered("mem save \"%s\" from 0x%08x len %d\n", sFilename, start, len); if ((!sFilename) || (!len)) { error("parameter syntax error."); return; } f = fopen(sFilename, "wb"); if(!f) { error("failed to open output file."); return; } for (nTotal = 0, nLeft = len; nLeft > 0; nTotal += nBuffer, nLeft -= nBuffer) { if(nLeft > MAXBUFFERLEN) { nBuffer = MAXBUFFERLEN; } else { nBuffer = nLeft; } ppc_bdm_read_block(start + nTotal, FileBuffer, nBuffer); nResult = fwrite(FileBuffer, 1, nBuffer, f); if (nResult != nBuffer) { error("write error."); break; } } if (f) fclose(f);}/*****************************************************************/static void mpcbdm_mem(char *args, int from_tty){ u_int MemStart,MemEnd,MemLen; /* memory range */ char *sParse; char *sFilename; if (args != 0) /* arguments ?*/ { sParse = args; if (strncmp(sParse,"load ",5) == 0) { sParse +=5; sFilename = parse_filename(&sParse); if (!sFilename) { printf_filtered("error while parsing filename\n"); return; } MemStart = strtoul(sParse,&sParse,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -