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

📄 remote-es1800.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
{  char *rate,  damn_b;} baudtab[] = {  {"0", B0},  {"50", B50},  {"75", B75},  {"110", B110},  {"134", B134},  {"150", B150},  {"200", B200},  {"300", B300},  {"600", B600},  {"1200", B1200},  {"1800", B1800},  {"2400", B2400},  {"4800", B4800},  {"9600", B9600},  {"19200", B19200},  {"38400", B38400},  {0, -1},};static intdamn_b (rate)     char *rate;{  int i;  for (i = 0; baudtab[i].rate != 0; i++)    {      if (!strcmp (rate, baudtab[i].rate))	{	  return (baudtab[i].damn_b);	}    }  error ("Illegal baudrate");}/*  Attaches to a process on the target side    proc_id  - the id of the process to be attached.    from_tty - says whether to be verbose or not */static voides1800_attach (args, from_tty)    char *args;    int from_tty;{  error ("Cannot attach to pid %s, this feature is not implemented yet.",	 args);}/* 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.    args     - arguments given to the 'detach' command   from_tty - says whether to be verbose or not */static voides1800_detach (args, from_tty)     char *args;     int from_tty;{  if (args)    {      error ("Argument given to \"detach\" when remotely debugging.");    }  pop_target ();  if (from_tty)    {      printf ("Ending es1800 remote debugging.\n");    }}/* Tell the remote machine to resume.   step    - single-step or run free   siggnal - the signal value to be given to the target (0 = no signal) */static voides1800_resume (step, siggnal)     int step;     int siggnal;{  char buf[PBUFSIZ];  if (siggnal)    {      error ("Can't send signals to a remote system.");    }  if (step)    {      strcpy (buf,"STP\r");      send (buf);    }  else    {      send_command ("RBK");    }}/* Wait until the remote machine stops, then return,   storing status in STATUS just as `wait' would.   status -  */ static intes1800_wait (status)     WAITTYPE *status;{  unsigned char buf[PBUFSIZ];  int old_timeout = timeout;  WSETEXIT ((*status), 0);  timeout = 0;		/* Don't time out -- user program is running. */  if (!setjmp (interrupt))    {      old_sigint = signal (SIGINT, es1800_request_quit);      while (1)        {	  getmessage (buf, sizeof(buf));	  if (strncmp ( buf, "\r\n* BREAK *", 11) == 0) 	    {	      WSETSTOP ((*status), SIGTRAP);	      send_command ("STP");	/* Restore stack and PC and such */	      if (m68020)		{		  send_command ("STP");		}	      break;	    }	  if (strncmp (buf, "STP\r\n ", 6) == 0)	    {	      WSETSTOP ((*status), SIGTRAP);	      break;	    }	  if (buf[strlen (buf) - 2] == 'R')	    {	      printf ("Unexpected emulator reply: \n%s\n", buf);	    }	  else	    {	      printf ("Unexpected stop: \n%s\n", buf);	      WSETSTOP ((*status), SIGQUIT);	      break;	    }        }    }  else    {      fflush (stdin);      printf ("\nStopping emulator...");      if (!setjmp (interrupt))	{	  old_sigint = signal (SIGINT, es1800_request_quit);	  send_command ("STP");	  printf (" emulator stopped\n");	  WSETSTOP ((*status), SIGINT);        }      else	{	  fflush (stdin);	  es1800_reset ((char*) 1);	}    }  signal (SIGINT, old_sigint);  timeout = old_timeout;  return (0);}/* Fetch register values from remote machine.   regno - the register to be fetched (fetch all registers if -1) */static voides1800_fetch_register (regno)     int regno;{  char buf[PBUFSIZ];  int k;  int r;  char *p;  static char regtab[18][4] =     {      "D0 ", "D1 ", "D2 ", "D3 ", "D4 ", "D5 ", "D6 ", "D7 ",      "A0 ", "A1 ", "A2 ", "A3 ", "A4 ", "A5 ", "A6 ", "SSP",      "SR ", "PC "    };  if ((regno < 15) || (regno == 16) || (regno == 17))    {      r = regno * 4;      send_with_reply (regtab[regno], buf, sizeof (buf));      p = buf;      for (k = 0; k < 4; k++)	{	  if ((p[k*2 + 1] == 0) || (p[k*2 + 2] == 0))	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = (fromhex (p[k*2 + 1]) * 16) + fromhex (p[k*2 + 2]);	}    }  else    {      es1800_fetch_registers ();    }}/* Read the remote registers into REGISTERS.   Always fetches all registers. */static voides1800_fetch_registers (){  char buf[PBUFSIZ];  char SR_buf[PBUFSIZ];  int i;  int k;  int r;  char *p;  send_with_reply ("DR", buf, sizeof (buf));  /* Reply is edited to a string that describes registers byte by byte,     each byte encoded as two hex characters.  */  p = buf;  r = 0;  /*  parsing row one - D0-D7-registers  */  while (*p++ != '\n') {;}  for (i = 4; i < 70; i += (i == 39 ? 3 : 1))    {      for (k = 0; k < 4; k++)	{	  if (p[i+0] == 0 || p[i+1] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = (fromhex (p[i+0]) * 16) + fromhex (p[i+1]);	  i += 2;	}    }  p += i;  /*  parsing row two - A0-A6-registers  */  while (*p++ != '\n') {;}  for (i = 4; i < 61; i += (i == 39 ? 3 : 1))    {      for (k = 0; k < 4; k++)	{	  if (p[i+0] == 0 || p[i+1] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = (fromhex (p[i+0])) * 16 + fromhex (p[i+1]);	  i += 2;	}    }  p += i;  while (*p++ != '\n') {;}  /* fetch SSP-, SR- and PC-registers  */  /* first - check STATUS-word and decide which stackpointer to use */  send_with_reply ("SR", SR_buf, sizeof (SR_buf));  p = SR_buf;  p += 5;  if (m68020)    {      if (*p == '3')		 /* use masterstackpointer MSP */	{	  send_with_reply ("MSP", buf, sizeof (buf));	}      else if (*p == '2')	/* use interruptstackpointer ISP  */	{	  send_with_reply ("ISP", buf, sizeof (buf));	}      else			/* use userstackpointer USP  */	{	  send_with_reply ("USP", buf, sizeof (buf)); 	}      p = buf;      for (k = 0; k<4; k++)	{	  if (p[k*2+1] == 0 || p[k*2+2] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = fromhex (buf[k*2+1]) * 16 + fromhex (buf[k*2+2]);	}      p = SR_buf;      for (k = 0; k < 4; k++)	{	  if (p[k*2+1] == 0 || p[k*2+2] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] =	    fromhex (SR_buf[k*2+1]) * 16 + fromhex (SR_buf[k*2+2]);	}      send_with_reply ("PC", buf, sizeof (buf));      p = buf;      for (k = 0; k<4; k++)	{	  if (p[k*2+1] == 0 || p[k*2+2] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = fromhex (buf[k*2+1]) * 16 + fromhex (buf[k*2+2]);	}    }  else    /* 68000-mode */    {                             if (*p == '2') /* use supervisorstackpointer SSP  */	{	  send_with_reply ("SSP", buf, sizeof (buf)); 	}      else  /* use userstackpointer USP  */	{	  send_with_reply ("USP", buf, sizeof (buf)); 	}      /* fetch STACKPOINTER */      p = buf;      for (k = 0; k < 4; k++)	{	  if (p[k*2 + 1] == 0 || p[k*2 + 2] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = fromhex (buf[k*2+1]) * 16 + fromhex (buf[k*2+2]);	}      /* fetch STATUS */      p = SR_buf;      for (k = 0; k < 4; k++)	{	  if (p[k*2+1] == 0 || p[k*2+2] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] =	    fromhex (SR_buf[k*2+1]) * 16 + fromhex (SR_buf[k*2+2]);	}      /* fetch PC */      send_with_reply ("PC", buf, sizeof (buf));       p = buf;      for (k = 0; k < 4; k++)	{	  if (p[k*2+1] == 0 || p[k*2+2] == 0)	    {	      error ("Emulator reply is too short: %s", buf);	    }	  registers[r++] = fromhex (buf[k*2+1]) * 16 + fromhex (buf[k*2+2]);	}        }}/* Store register value, located in REGISTER, on the target processor.   regno - the register-number of the register to store           (-1 means store them all)   FIXME: Return errno value.  */static voides1800_store_register(regno)     int regno;{  static char regtab[18][4] =    {      "D0 ", "D1 ", "D2 ", "D3 ", "D4 ", "D5 ", "D6 ", "D7 ",      "A0 ", "A1 ", "A2 ", "A3 ", "A4 ", "A5 ", "A6 ", "SSP",      "SR ", "PC "    };  char buf[PBUFSIZ];  char SR_buf[PBUFSIZ];  char stack_pointer[4];  char *p;  int i;  int j;  int k;  unsigned char *r;  r = (unsigned char *) registers;  if (regno == -1)  /* write all registers */    {      j = 0;      k = 18;    }  else              /* write one register */    {      j = regno;      k = regno+1;      r += regno * 4;     }      if ((regno == -1) || (regno == 15))    {      /* fetch current status */      send_with_reply ("SR", SR_buf, sizeof (SR_buf));      p = SR_buf;      p += 5;      if (m68020)	{	  if (*p == '3') /* use masterstackpointer MSP */	    {	      strcpy (stack_pointer,"MSP");  	    }	  else	    {	      if (*p == '2') /* use interruptstackpointer ISP  */		{		  strcpy (stack_pointer,"ISP");  		}	      else		{		  strcpy (stack_pointer,"USP");  /* use userstackpointer USP  */		}	    }	}      else  /* 68000-mode */	{	  if (*p == '2') /* use supervisorstackpointer SSP  */	    {	      strcpy (stack_pointer,"SSP");  	    }	  else	    {	      strcpy (stack_pointer,"USP");/* use userstackpointer USP  */  	    }	}      strcpy (regtab[15],stack_pointer);    }  for (i = j; i<k; i++)    {      buf[0] = regtab[i][0];      buf[1] = regtab[i][1];      buf[2] = regtab[i][2];      buf[3] = '=';      buf[4] = '$';      buf[5] = tohex ((*r >> 4) & 0x0f);      buf[6] = tohex (*r++ & 0x0f);      buf[7] = tohex ((*r >> 4) & 0x0f);      buf[8] = tohex (*r++ & 0x0f);      buf[9] = tohex ((*r >> 4) & 0x0f);      buf[10] = tohex (*r++ & 0x0f);      buf[11] = tohex ((*r >> 4) & 0x0f);      buf[12] = tohex (*r++ & 0x0f);      buf[13] = 0;      send_with_reply (buf, buf, sizeof (buf)); /* FIXME, reply not used? */    }}/* Prepare to store registers.  */static void es1800_prepare_to_store (){  /* Do nothing, since we can store individual regs */}/* Convert hex digit A to a number.  */static intfromhex (a)     int a;{  if (a >= '0' && a <= '9')    {      return a - '0';    }  else if (a >= 'a' && a <= 'f')    {      return a - 'a' + 10;    }  else if (a >= 'A' && a <= 'F')    {      return a - 'A' + 10;    }  else    {      error ("Reply contains invalid hex digit");    }  return (-1);}/* Convert number NIB to a hex digit.  */static inttohex (nib)     int nib;{  if (nib < 10)    {      return ('0' + nib);    }  else    {      return ('A' + nib - 10);    }}/* Read or write LEN bytes from inferior memory at MEMADDR, transferring   to or from debugger address MYADDR.  Write to inferior if WRITE is   nonzero.  Returns length of data written or read; 0 for error.     memaddr - the target's address   myaddr  - gdb's address   len     - number of bytes    write   - write if != 0 otherwise read	*/static intes1800_xfer_inferior_memory (memaddr, myaddr, len, write, tops)     CORE_ADDR memaddr;     char *myaddr;     int len;     int write;     struct target_ops *tops;	/* Unused */{  int origlen = len;  int xfersize;  while (len > 0)    {      xfersize = len > MAXBUFBYTES ? MAXBUFBYTES : len;      if (write)	{	  es1800_write_bytes (memaddr, myaddr, xfersize);	}      else	{	  es1800_read_bytes (memaddr, myaddr, xfersize);	}      memaddr += xfersize;      myaddr += xfersize;      len -= xfersize;    }  return (origlen); /* no error possible */}/* Write memory data directly to the emulator.   This does not inform the data cache; the data cache uses this.

⌨️ 快捷键说明

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