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

📄 mpcbdm.c

📁 powerpc内核mpc860芯片 linux操作系统下交叉调试程序
💻 C
📖 第 1 页 / 共 5 页
字号:
int	mpcbdm_thread_alive (int th){ 	return 1;}/* Clean up connection to a remote debugger.  *//* ARGSUSED */void mpcbdm_close (int quitting){  /* if (mpcbdm_desc)    SERIAL_CLOSE (mpcbdm_desc);  mpcbdm_desc = NULL; */}/* Stub for catch_errors.  */static int mpcbdm_start_remote (PTR dummy){	int nResult;	int port;	if (!dummy)	{		if (PP.port == -1)		{			printf_filtered("port number is required\n");			return 0;		}		else		{			port = PP.port; /* preveously used port*/		}	}	else /* port number specified */	{		PP.port = -1;		port = (int)strtoul((char*) dummy,0,0); /* read port number */	}	immediate_quit = 1; 	  /* Allow user to interrupt it */	nResult = PortInit(port);	if (nResult == RETURN_FAIL)	{		printf_filtered("error on opening printer port %d\n",port);		return 0;	}	mpcbdm_icr_or = 0; /* init core interrupt counter *//* setup processor vor debugging */	ppc_bdm_stop();	ppc_bdm_init();	immediate_quit = 0;/* This is really the job of start_remote however, that makes an assumption   that the target is about to print out a status message of some sort.  That   doesn't happen here (in fact, it may not be possible to get the monitor to   send the appropriate packet).  */	flush_cached_frames ();	registers_changed ();	stop_pc = read_pc ();	set_current_frame (create_new_frame (read_fp (), stop_pc));	select_frame (get_current_frame (), 0);	print_stack_frame (selected_frame, -1, 1);	return 1;}/* Open a connection to a remote debugger.   NAME is the filename used for communication.  *//* static DCACHE *mpcbdm_dcache; */void mpcbdm_open (char *name, int from_tty){	unsigned char buf[10], *p;	int status;	target_preopen (from_tty);	current_ops = &mpcbdm_ops;	unpush_target (current_ops);	/* mpcbdm_dcache = dcache_init (mpcbdm_read_bytes, mpcbdm_write_bytes); */	// printf("FP_REGNUM=%d\n", FP_REGNUM);	printf_filtered("MPCBDM version %s\n",sVersion);/*	if (from_tty)	{		puts_filtered ("Remote target MPCBDM connected to parallel port ");		puts_filtered (name);		puts_filtered ("\n");	}*/	push_target (current_ops);    /* Switch to using remote target now */  /* Without this, some commands which require an active target (such as kill)     won't work.  This variable serves (at least) double duty as both the pid     of the target process (if it has such), and as a flag indicating that a     target is active.  These functions should be split out into seperate     variables, especially since GDB will someday have a notion of debugging     several processes.  */	inferior_pid = 42000;  /* Start the remote connection; if error (0), discard this target.     In particular, if the user quits, be sure to discard it     (we'd be in an inconsistent state otherwise).  */	if (!catch_errors (mpcbdm_start_remote, name,		"Couldn't establish connection to remote target\n",		RETURN_MASK_ALL))	{    	pop_target();		error("Failed to connect to target 'mpcbdm'");	}}/* This takes a program previously attached to and detaches it.  After   this is done, GDB can be used to debug some other program.  We   better not have left any breakpoints in the target program or it'll   die when it hits one.  */void mpcbdm_detach (char *args, int from_tty){	if (args)		error ("Argument given to \"detach\" when remotely debugging.");	pop_target ();	if (from_tty)		puts_filtered ("Ending remote debugging.\n");}/* Tell the remote machine to resume.  */void mpcbdm_resume (int pid, int step, enum target_signal siggnal){	if (mpcbdm_verbose&VERBOSE_TAR)	{		printf("mpcbdm_resume %s\n", step?"step":"run");	}	/* dcache_flush (mpcbdm_dcache); */	if(step) ppc_bdm_step();	else ppc_bdm_run();}/* 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).  */void mpcbdm_prepare_to_store (void){}/* Read or write LEN bytes from inferior memory at MEMADDR, transferring   to or from debugger address MYADDR.  Write to inferior if SHOULD_WRITE is   nonzero.  Returns length of data written or read; 0 for error.  */int mpcbdm_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,						int should_write, struct target_ops *target){	u_int val;	u_int n;	u_int mem = memaddr;	if (mpcbdm_verbose&VERBOSE_TAR)	{		printf("mpcbdm_xfer_memory: memaddr 0x%08x myaddr 0x%08x len %d write %d\n",memaddr,myaddr,len,should_write);	}	if(should_write)	{		ppc_bdm_write_block(mem, myaddr, len);	}	else	{		ppc_bdm_read_block(mem, myaddr, len);	}	return len;}void mpcbdm_files_info (struct target_ops *ignore){ 	puts_filtered ("Debugging a MPC target through the BDM interface over a parallel port.\n");}void mpcbdm_kill (void){  /* For some mysterious reason, wait_for_inferior calls kill instead of     mourn after it gets TARGET_WAITKIND_SIGNALLED.  Work around it.  */	if (mpcbdm_kill_kludge)	{		mpcbdm_kill_kludge = 0;		target_mourn_inferior ();		return;	}/* Don't wait for it to die.  I'm not really sure it matters whether   we do or not.  */	target_mourn_inferior ();}void mpcbdm_mourn (void){	unpush_target (current_ops);	generic_mourn_inferior ();}/* All we actually do is set the PC to the start address of exec_bfd, and start   the program at that point.  */void mpcbdm_create_inferior (char *exec_file, char *args, char **env){	if (args && *args)		error ("Args are not supported by BDM.");	clear_proceed_status ();	proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);}void mpcbdm_load (char *args, int from_tty){	if (mpcbdm_verbose&VERBOSE_TAR)	{		printf("mpcbdm_load: args %s from_tty %d\n",args,from_tty);	}	generic_load (args, from_tty);/*FP	inferior_pid = 0;*//* This is necessary because many things were based on the PC at the time that   we attached to the monitor, which is no longer valid now that we have loaded   new code (and just changed the PC).  Another way to do this might be to call   normal_stop, except that the stack may not be valid, and things would get   horribly confused... */	clear_symtab_users ();}/* This should be defined for each target *//* But we want to be able to compile this file for some configurations   not yet supported fully */int mpcbdm_insert_breakpoint (CORE_ADDR addr, char *contents_cache){	int i;	unsigned int ictrl;	unsigned int hwmask;	if (mpcbdm_hwbrk)	/*use MPC hardware registers?*/	{		for (i = 0; i < mpcbdm_maxhwbrk; i++)		{			if (!hwbrk_used[i])				break;		}		if (i >= mpcbdm_maxhwbrk)		{			printf("too many hardware breakpoints: only %d supported\n",mpcbdm_maxhwbrk);			return 1;		}		ictrl = bdm_getspr(SPR_ICTRL);				/*mask for ictrl: CTx = 100 | IWx = 10 | SIWxEN = 1*/		hwmask = (1<<(31-i*3)) | (1<<(19-i*2)) | (1<<(11-i));		if (mpcbdm_verbose&VERBOSE_BRK)			printf("enable hardware breakpoint %d : addr 0x%08x ICTRL mask = 0x%08x\n",i,addr,hwmask);		ictrl |= hwmask; /*enable CMPx*/		bdm_setspr(SPR_ICTRL,ictrl);		bdm_setspr(SPR_CMPA+i, (unsigned int) addr);		hwbrk_used[i] = 1; /* remember break point and addr*/		hwbrk_adr[i] = (unsigned int) addr;				return 0;	}		/* use illegal opcodes for software emulation exception*/		target_read_memory (addr, contents_cache, sizeof (break_insn));	target_write_memory (addr, break_insn, sizeof (break_insn));	return 0;}int mpcbdm_remove_breakpoint (CORE_ADDR addr, char *contents_cache){	int i;	unsigned int ictrl;	unsigned int hwmask;	if (mpcbdm_hwbrk)	/*use MPC hardware registers?*/	{		for (i = 0; i < mpcbdm_maxhwbrk; i++)		{			if (hwbrk_used[i] && (hwbrk_adr[i] == (unsigned int) addr)) /* brkp found?*/				break;		}		if (i >= mpcbdm_maxhwbrk)		{			printf("no matching hardware breakpoint found\n");			return 1;		}		ictrl = bdm_getspr(SPR_ICTRL);		hwmask = (1<<(31-i*3)) | (1<<(19-i*2)) | (1<<(11-i));		if (mpcbdm_verbose&VERBOSE_BRK)			printf("disable hardware breakpoint %d : addr 0x%08x ICTRL mask = 0x%08x\n",i,addr,hwmask);		ictrl &= ~hwmask; /*disable CMPx*/		bdm_setspr(SPR_ICTRL,ictrl);		hwbrk_used[i] = 0;		return 0;	}	/* use illegal opcodes for software emulation exception*/		target_write_memory (addr, contents_cache, sizeof (break_insn));	return 0;}static void bdm_command (char *args, int from_tty){	error ("try 'help mpcbdm' for target specific commands");}static void mpcbdm_reset_command (char *args, int from_tty){	if (mpcbdm_verbose&VERBOSE_TAR)	{		printf("mpcbdm_reset_command: args %s from_tty %d\n",args,from_tty);	}	ppc_bdm_stop();}static void mpcbdm_restart_command (char *args, int from_tty){	if (mpcbdm_verbose&VERBOSE_TAR)	{		printf("mpcbdm_restart_command: args %s from_tty %d\n",args,from_tty);	}	mpcbdm_start_remote(args);}/* Temporary replacement for target_store_registers().  This prevents   generic_load from trying to set the PC.  */static void noop_store_registers (int regno){}static int findsprnum(char *pch){	int n;	char *p;	for(p = pch; *p ; ) *p++ = toupper(*p);	for(n = 0; sprnames[n].name; ++n)	{		if(!strcmp(sprnames[n].name, pch)) return sprnames[n].num;	}	return -1;}void print_spr_info(int num,u_int val, int bName, int bDef, int bVal, int bPretty){	int i;	int index;	int startbit,bit;	int len;	int bFirstPrinted;	int bSPRI;	u_int bitmask;	u_int bitfieldmask;	u_int bitfieldval;	char *pFormat;	char *pFieldName;	char *pFieldNameEnd;	char FieldName[255];	index = -1;	for(i = 0; sprnames[i].name ; ++i)	{		if(sprnames[i].num == num)		{			index = i;			break;		}	}		bSPRI = (num & SPRI_MASK);	num &= (GPR_REG_MASK-1); /*remove register markings*/	if (index < 0) /*not in sprnames*/	{		if (bName)		{			if (bSPRI)				printf("SPRI 0x%x", num);			else			printf("SPR %d", num);		}		if (bVal)		{			printf(" = 0x%08x", val);		}		return;	}		pFormat = sprnames[i].Namefield;		if (!pFormat)	/*no bitfield description available?*/	{		if (bDef) 		{			if (bSPRI)			{				printf("IMMR + 0x%x",num);			}			else			{				printf("SPR %d",num);			}			if ((bName) && (sprnames[i].name))				printf(" : %s", sprnames[i].name);		}		else if ((bName) && (sprnames[i].name))			printf("%s", sprnames[i].name);		if (bVal)			printf(" = 0x%08x", val);		if (bDef) 		{			if (sprnames[i].Longname) printf(" , %s", sprnames[i].Longname);			if (sprnames[i].Reference) printf(" , %s", sprnames[i].Reference);			if ((sprnames[i].Longname) || (sprnames[i].Reference)) printf("\n");		}		return; /*for no Format description, we are finished here */	}/*start of pretty print*/	if (bDef) /* print name and format description field?*/	{		printf("%s := (%s)\n",sprnames[index].name,sprnames[index].Namefield);		if (bSPRI)			printf("IMMR + 0x%x:",num);		else			printf("SPR %d:",num);		if (sprnames[i].Longname)		{			printf("%s", sprnames[i].Longname);			if (sprnames[i].Reference) printf(", ");		}		if (sprnames[i].Reference) printf("%s", sprnames[i].Reference);			printf("\n");	}	if (bName)	{	 	if (sprnames[i].name) printf("%s", sprnames[i].name);		else		{ 			if (bSPRI)				printf("IMMR + 0x%x",num);			else				printf("SPR %d",num);		}	}	if (bVal)	{		printf(" = 0x%08x", val);	}	if (bPretty)	{		startbit = 0;		bFirstPrinted = 0;		if (isdigit(*pFormat))	/*extra case first field starting not at bit zero*/		{			i = sscanf(pFormat,"%d",&startbit);			if ((startbit<0) || (startbit >PPC_BITS)|| (i!=1))			{				printf("\nerror in bitfield description string %s\n",sprnames[index].Namefield);				printf(" wrong bit position %d at %s\n",startbit, pFormat);				return;			}			do			{				pFormat++;			} while (isdigit(*pFormat));		}		while ((*pFormat))		{			pFieldName = pFormat;			pFormat = strchr(pFormat,'|');			if (!pFormat) /*last entry*/			{				bit = PPC_BITS; /*reached last bit*/				len = strlen(pFieldName);			}			else			{				len = pFormat-pFieldName;				pFormat++; /*skip |*/				if (isdigit(*pFormat))	/*bitfield or single bit*/				{					i = sscanf(pFormat,"%d",&bit);					if ((bit<0) || (bit >PPC_BITS) ||(bit <=startbit) || (i!=1))					{						printf("error in bitfield description string %s\n",sprnames[index].Namefield);						printf(" wrong bit position %d at %s\n",bit,pFormat);						return;					}

⌨️ 快捷键说明

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