Ejemplo n.º 1
0
Archivo: capdl.c Proyecto: scan/seL4
static int getDecodedChar(unsigned char *result)
{
    unsigned char c;
    c = getDebugChar();
    if (c == START) {
        return 1;
    }
    if (c == ESCAPE) {
        c = getDebugChar();
        if (c == START) {
            return 1;
        }
        switch (c) {
        case ESCAPE_ESCAPE:
            *result = ESCAPE;
            break;
        case START_ESCAPE:
            *result = START;
            break;
        case END_ESCAPE:
            *result = END;
            break;
        default:
            if (c >= 20 && c < 40) {
                *result = c - 20;
            } else {
                return 1;
            }
        }
        return 0;
    } else {
        *result = c;
        return 0;
    }
}
Ejemplo n.º 2
0
/*
 * Set up exception handlers for tracing and breakpoints
 */
void set_debug_traps(void)
{
	struct hard_trap_info *ht;
	unsigned long flags;
	unsigned char c;

	save_and_cli(flags);

	for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
		saved_vectors[ht->tt] = set_except_vector(ht->tt, trap_low);
#if 1 
	putDebugChar('+'); /* 'hello world' */
	/*
	 * In case GDB is started before us, ack any packets
	 * (presumably "$?#xx") sitting there.
	 */
	while((c = getDebugChar()) != '$');
	while((c = getDebugChar()) != '#');
	c = getDebugChar(); /* eat first csum byte */
	c = getDebugChar(); /* eat second csum byte */
	putDebugChar('+'); /* ack it */
#endif
	initialized = 1;
	restore_flags(flags);
}
Ejemplo n.º 3
0
/* scan for the sequence $<data>#<checksum>     */
static void
getpacket(char *buffer)
{
	unsigned char checksum;
	unsigned char xmitcsum;
	int i;
	int count;
	unsigned char ch;

	do {
		/* wait around for the start character, ignore all other
		 * characters */
		while ((ch = (getDebugChar() & 0x7f)) != '$') {
#ifdef KGDB_DEBUG
			if (kdebug)
				putc(ch);
#endif
			;
		}

		checksum = 0;
		xmitcsum = -1;

		count = 0;

		/* now, read until a # or end of buffer is found */
		while (count < BUFMAX) {
			ch = getDebugChar() & 0x7f;
			if (ch == '#')
				break;
			checksum = checksum + ch;
			buffer[count] = ch;
			count = count + 1;
		}

		if (count >= BUFMAX)
			continue;

		buffer[count] = 0;

		if (ch == '#') {
			xmitcsum = hex(getDebugChar() & 0x7f) << 4;
			xmitcsum |= hex(getDebugChar() & 0x7f);
			if (checksum != xmitcsum)
				putDebugChar('-');	/* failed checksum */
			else {
				putDebugChar('+'); /* successful transfer */
				/* if a sequence char is present, reply the ID */
				if (buffer[2] == ':') {
					putDebugChar(buffer[0]);
					putDebugChar(buffer[1]);
					/* remove sequence chars from buffer */
					count = strlen(buffer);
					for (i=3; i <= count; i++)
						buffer[i-3] = buffer[i];
				}
			}
		}
	} while (checksum != xmitcsum);
}
Ejemplo n.º 4
0
/* Await the sequence $<data>#<checksum> and store <data> in the array buffer
   returned. */
static void
getpacket (char *buffer)
{
	unsigned char checksum;
	unsigned char xmitcsum;
	int i;
	int count;
	char ch;
	do {
		while ((ch = getDebugChar ()) != '$')
			/* Wait for the start character $ and ignore all other characters */;
		checksum = 0;
		xmitcsum = -1;
		count = 0;
		/* Read until a # or the end of the buffer is reached */
		while (count < BUFMAX) {
			ch = getDebugChar ();
			if (ch == '#')
				break;
			checksum = checksum + ch;
			buffer[count] = ch;
			count = count + 1;
		}
		buffer[count] = '\0';
		
		if (ch == '#') {
			xmitcsum = hex (getDebugChar ()) << 4;
			xmitcsum += hex (getDebugChar ());
			if (checksum != xmitcsum) {
				/* Wrong checksum */
				putDebugChar ('-');
			}
			else {
				/* Correct checksum */
				putDebugChar ('+');
				/* If sequence characters are received, reply with them */
				if (buffer[2] == ':') {
					putDebugChar (buffer[0]);
					putDebugChar (buffer[1]);
					/* Remove the sequence characters from the buffer */
					count = gdb_cris_strlen (buffer);
					for (i = 3; i <= count; i++)
						buffer[i - 3] = buffer[i];
				}
			}
		}
	} while (checksum != xmitcsum);
}
Ejemplo n.º 5
0
/*
 * send the packet in buffer.
 */
static void putpacket(char *buffer)
{
    unsigned char checksum;
    int count;
    unsigned char ch;

    /*
     * $<packet info>#<checksum>.
     */

    do {
        putDebugChar('$');
        checksum = 0;
        count = 0;

        while ((ch = buffer[count]) != 0) {
            if (!(putDebugChar(ch)))
                return;
            checksum += ch;
            count += 1;
        }

        putDebugChar('#');
        putDebugChar(hexchars[checksum >> 4]);
        putDebugChar(hexchars[checksum & 0xf]);

    }
    while ((getDebugChar() & 0x7f) != '+');
}
Ejemplo n.º 6
0
static unsigned char *stub_puts(unsigned char *buffer)
{
  unsigned char c, sum;
  int i;

  while (1) {
    putDebugChar('$');

    i = 0;
    sum = 0;
    while ((c = buffer[i++]) != '\0') {
      putDebugChar(c);
      sum += c;
    }

    putDebugChar('#');
    putDebugChar(h2a((sum >> 4) & 0xf));
    putDebugChar(h2a(sum & 0xf));

    if (getDebugChar() == '+')
      break;
  }

  return buffer;
}
Ejemplo n.º 7
0
/* send the packet in buffer.  */
static void
putpacket(unsigned char *buffer)
{
	unsigned char checksum;
	int count;
	unsigned char ch, recv;

	/*  $<packet info>#<checksum>. */
	do {
		putDebugChar('$');
		checksum = 0;
		count = 0;

		while ((ch = buffer[count])) {
			putDebugChar(ch);
			checksum += ch;
			count += 1;
		}

		putDebugChar('#');
		putDebugChar(hexchars[checksum >> 4]);
		putDebugChar(hexchars[checksum & 0xf]);
		recv = getDebugChar();
	} while ((recv & 0x7f) != '+');
}
Ejemplo n.º 8
0
void putpacket (char *buffer) {
    unsigned char checksum;
    int count;
    char ch;

    /*  $<packet info>#<checksum>. */
    do
    {
        putDebugChar ('$');
        checksum = 0;
        count = 0;

        while (ch = buffer[count])
        {
            putDebugChar (ch);
            checksum += ch;
            count += 1;
        }

        putDebugChar ('#');
        putDebugChar (hexchars[checksum >> 4]);
        putDebugChar (hexchars[checksum % 16]);

    }
    while (getDebugChar () != '+');

}
Ejemplo n.º 9
0
/* send the packet in buffer.  */
int putpacket(char *buffer)
{
	unsigned char checksum;
	int count;
	unsigned char ch;

	/*  $<packet info>#<checksum>. */
	do
	{
		if(putDebugChar('$'))
			return 1;
		checksum = 0;
		count = 0;

		while((ch = (buffer[count])))
		{
			if(putDebugChar(ch))
				return 1;
			checksum += ch;
			count += 1;
		}

		if(putDebugChar('#') || putDebugChar(hexchars[checksum >> 4])
		  || putDebugChar(hexchars[checksum & 0xf]))
			return 1;

		if(getDebugChar(&ch))
			return 1;

	}
	while(ch != '+');

	return 0;
}
Ejemplo n.º 10
0
/*
 * Set up exception handlers for tracing and breakpoints
 */
void set_debug_traps(void)
{
//	unsigned long flags;
	unsigned char c;

//	save_and_cli(flags);
	/*
	 * In case GDB is started before us, ack any packets
	 * (presumably "$?#xx") sitting there.
	 */
	while((c = getDebugChar()) != '$');
	while((c = getDebugChar()) != '#');
	c = getDebugChar(); /* eat first csum byte */
	c = getDebugChar(); /* eat second csum byte */
	putDebugChar('+'); /* ack it */

	gdb_stub_initialised = TRUE;
//	restore_flags(flags);
}
Ejemplo n.º 11
0
Archivo: serial.c Proyecto: kisom/pmon
static int serialtest()
{
	int i,j;

	printf("serial test\n");
	initserial(0);
	initserial(1);
	
	for(i=0;i<16;i++)
	{
	if(testDebugChar(0))getDebugChar(0);
	else break;
	}

	for(i=0;i<16;j++)
	{
	if(testDebugChar(1))getDebugChar(1);
	else break;
	}

	printf("serial 0 send data to serial 1...");
	for(i=0;i<10;i++)
	{
	putDebugChar(0,'a'+i);
	for(j=0;j<TIMEOUT;j++)
	{
	if(testDebugChar(1))break;
	}
	if(j==TIMEOUT){printf("timeout");break;}
	printf("%c",getDebugChar(1));
	}
	printf("\n");

	for(i=0;i<16;i++)
	{
	if(testDebugChar(0))getDebugChar(0);
	else break;
	}

	for(i=0;i<16;j++)
	{
	if(testDebugChar(1))getDebugChar(1);
	else break;
	}
	printf("serial 1 send data to serial 0...");

	for(i=0;i<10;i++)
	{
	putDebugChar(1,'a'+i);
	for(j=0;j<TIMEOUT;j++)
	{
	if(testDebugChar(0))break;
	}
	if(j==TIMEOUT){printf("timeout");break;}
	printf("%c",getDebugChar(0));
	}
	printf("\n");
	return 0;
}
Ejemplo n.º 12
0
static void
putpacket (char *buffer)
{
  unsigned char checksum;
  int count;
  unsigned char ch;

  if (strlen(buffer) >= BUFMAX)
    panic("kgdb: buffer overflow");

  /*  $<packet info>#<checksum>. */
  do
    {
/*
 * This is a non-standard hack to allow use of the serial console for
 * operation as well as debugging.  Simply turn on 'remotechat' in gdb.
 *
 * This extension is not part of the Cygnus protocol, is kinda gross,
 * but gets the job done.
 */
#ifdef GDB_REMOTE_CHAT
      putDebugChar ('|');
      putDebugChar ('|');
      putDebugChar ('|');
      putDebugChar ('|');
#endif
      putDebugChar ('$');
      checksum = 0;
      count = 0;

      while ((ch=buffer[count]) != 0)
	{
	  putDebugChar (ch);
	  checksum += ch;
	  count += 1;
	}

      putDebugChar ('#');
      putDebugChar (hexchars[checksum >> 4]);
      putDebugChar (hexchars[checksum & 0xf]);
    }
  while ((getDebugChar () & 0x7f) != '+');
}
Ejemplo n.º 13
0
Archivo: serial.c Proyecto: kisom/pmon
static int cmd_serial(int argc,char **argv)
{
int line;
if(argc!=3)return -1;
line=argv[2][0]-'0';

switch(argv[1][0])
{
case 'i':
	initserial(line);
	break;
case 'r':
	printf("%c\n",getDebugChar(line));break;
case 'w':
	putDebugChar(line,'a');
	break;
case 't':
	printf("%d\n",testDebugChar(line));
	break;
}
return 0;	
	
}
Ejemplo n.º 14
0
static void
putpacket(char *buffer)
{
	int checksum;
	int runlen;
	int encode;
	
	do {
		char *src = buffer;
		putDebugChar ('$');
		checksum = 0;
		while (*src) {
			/* Do run length encoding */
			putDebugChar (*src);
			checksum += *src;
			runlen = 0;
			while (runlen < RUNLENMAX && *src == src[runlen]) {
				runlen++;
			}
			if (runlen > 3) {
				/* Got a useful amount */
				putDebugChar ('*');
				checksum += '*';
				encode = runlen + ' ' - 4;
				putDebugChar (encode);
				checksum += encode;
				src += runlen;
			}
			else {
				src++;
			}
		}
		putDebugChar('#');
		putDebugChar(hex_asc_hi(checksum));
		putDebugChar(hex_asc_lo(checksum));
	} while(kgdb_started && (getDebugChar() != '+'));
}
Ejemplo n.º 15
0
unsigned char *
getpacket (void)
{
    unsigned char *buffer = &remcomInBuffer[0];
    unsigned char checksum;
    unsigned char xmitcsum;
    int count;
    char ch;

    while (1)
    {
        /* wait around for the start character, ignore all other characters */
        while ((ch = getDebugChar ()) != '$')
            ;

retry:
        checksum = 0;
        xmitcsum = -1;
        count = 0;

        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
        {
            ch = getDebugChar ();
            if (ch == '$')
                goto retry;
            if (ch == '#')
                break;
            checksum = checksum + ch;
            buffer[count] = ch;
            count = count + 1;
        }
        buffer[count] = 0;

        if (ch == '#')
        {
            ch = getDebugChar ();
            xmitcsum = hex (ch) << 4;
            ch = getDebugChar ();
            xmitcsum += hex (ch);

            if (checksum != xmitcsum)
            {
                if (remote_debug)
                {
                    /**
                    fprintf (stderr,
                      "bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
                      checksum, xmitcsum, buffer);
                      */
                }
                putDebugChar ('-');	/* failed checksum */
            }
            else
            {
                putDebugChar ('+');	/* successful transfer */

                /* if a sequence char is present, reply the sequence ID */
                if (buffer[2] == ':')
                {
                    putDebugChar (buffer[0]);
                    putDebugChar (buffer[1]);

                    return &buffer[3];
                }

                return &buffer[0];
            }
        }
    }
}
Ejemplo n.º 16
0
Archivo: capdl.c Proyecto: scan/seL4
void capDL(void)
{
    int result;
    int done = 0;
    while (done == 0) {
        unsigned char c;
        do {
            c = getDebugChar();
        } while (c != START);
        do {
            result = getDecodedChar(&c);
            if (result) {
                continue;
            }
            switch (c) {
            case PD_COMMAND: {
                /*pgdir */
                unsigned long arg;
                result = getArg(&arg);
                if (result) {
                    continue;
                }
                sendPD(arg);
                putDebugChar(END);
            }
            break;
            case PT_COMMAND: {
                /*pg table */
                unsigned long arg;
                result = getArg(&arg);
                if (result) {
                    continue;
                }
                sendPT(arg);
                putDebugChar(END);
            }
            break;
            case ASID_POOL_COMMAND: {
                /*asid pool */
                unsigned long arg;
                result = getArg(&arg);
                if (result) {
                    continue;
                }
                sendASIDPool(arg);
                putDebugChar(END);
            }
            break;
            case IO_PT_COMMAND: {
                /*io pt table */
                unsigned long address, level;
                result = getArg(&address);
                if (result) {
                    continue;
                }
                result = getArg(&level);
                if (result) {
                    continue;
                }
                sendIOPT(address, level);
                putDebugChar(END);
            }
            break;
            case IO_SPACE_COMMAND: {
                /*io space */
                unsigned long arg;
                result = getArg(&arg);
                if (result) {
                    continue;
                }
                sendIOSpace(arg);
                putDebugChar(END);
            }
            break;
            case RQ_COMMAND: {
                /*runqueues */
                sendRunqueues();
                putDebugChar(END);
                result = 0;
            }
            break;
            case EP_COMMAND: {
                /*endpoint waiters */
                unsigned long arg;
                result = getArg(&arg);
                if (result) {
                    continue;
                }
                sendEPQueue(arg);
                putDebugChar(END);
            }
            break;
            case CN_COMMAND: {
                /*cnode */
                unsigned long address, sizebits;
                result = getArg(&address);
                if (result) {
                    continue;
                }
                result = getArg(&sizebits);
                if (result) {
                    continue;
                }

                sendCNode(address, sizebits);
                putDebugChar(END);
            }
            break;
            case IRQ_COMMAND: {
                sendIRQNode();
                putDebugChar(END);
                result = 0;
            }
            break;
            case VERSION_COMMAND: {
                sendVersion();
                putDebugChar(END);
            }
            break;
            case DONE: {
                done = 1;
                putDebugChar(END);
            }
            default:
                result = 0;
                break;
            }
        } while (result);
    }
}
/* scan for the sequence $<data>#<checksum>     */
void
getpacket (char *buffer)
{
  unsigned char checksum;
  unsigned char xmitcsum;
  int i;
  int count;
  char ch;

  do
    {
      /* wait around for the start character, ignore all other characters */
      while ((ch = (getDebugChar () & 0x7f)) != '$');
      checksum = 0;
      xmitcsum = -1;

      count = 0;

      /* now, read until a # or end of buffer is found */
      while (count < BUFMAX)
	{
	  ch = getDebugChar () & 0x7f;
	  if (ch == '#')
	    break;
	  checksum = checksum + ch;
	  buffer[count] = ch;
	  count = count + 1;
	}
      buffer[count] = 0;

      if (ch == '#')
	{
	  xmitcsum = hex (getDebugChar () & 0x7f) << 4;
	  xmitcsum += hex (getDebugChar () & 0x7f);
	  if ((remote_debug) && (checksum != xmitcsum))
	    {
	      fprintf (stderr, "bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
		       checksum, xmitcsum, buffer);
	    }

	  if (checksum != xmitcsum)
	    putDebugChar ('-');	/* failed checksum */
	  else
	    {
	      putDebugChar ('+');	/* successful transfer */
	      /* if a sequence char is present, reply the sequence ID */
	      if (buffer[2] == ':')
		{
		  putDebugChar (buffer[0]);
		  putDebugChar (buffer[1]);
		  /* remove sequence chars from buffer */
		  count = strlen (buffer);
		  for (i = 3; i <= count; i++)
		    buffer[i - 3] = buffer[i];
		}
	    }
	}
    }
  while (checksum != xmitcsum);

}
Ejemplo n.º 18
0
Archivo: gdb.c Proyecto: JanmanX/KUDOS
/* scan for the sequence $<data>#<checksum>     */
static unsigned char *getpacket(void)
{
  char *buffer = &remcomInBuffer[0];
  unsigned char checksum;
  unsigned char xmitcsum;
  int count;
  char ch;

  while (1)
    {
      /* wait around for the start character, ignore all other characters */
      while ((ch = getDebugChar ()) != '$' && ch != EOF)
	;

      if (ch == EOF)
          return NULL;
retry:
      checksum = 0;
      xmitcsum = -1;
      count = 0;

      /* now, read until a # or end of buffer is found */
      while (count < BUFMAX)
	{
	  ch = getDebugChar ();
          if (ch == '$')
            goto retry;
	  if (ch == '#')
	    break;
	  checksum = checksum + ch;
	  buffer[count] = ch;
	  count = count + 1;
	}
      buffer[count] = 0;

      if (ch == '#')
	{
	  ch = getDebugChar ();
	  xmitcsum = hex (ch) << 4;
	  ch = getDebugChar ();
	  xmitcsum += hex (ch);

	  if (checksum != xmitcsum)
	    {
	      putDebugChar ('-');	/* failed checksum */
	    }
	  else
	    {
	      putDebugChar ('+');	/* successful transfer */

	      /* if a sequence char is present, reply the sequence ID */
	      if (buffer[2] == ':')
		{
		  putDebugChar (buffer[0]);
		  putDebugChar (buffer[1]);

		  return (unsigned char*)&buffer[3];
		}

	      return (unsigned char*)&buffer[0];
	    }
	}
    }
}
Ejemplo n.º 19
0
static unsigned char *stub_gets(unsigned char *buffer)
{
  int i = 0;
  unsigned char c = 0, sum = 0, datasum = 0;
  enum {
    GETS_STATUS_WAIT_DOLLAR,
    GETS_STATUS_READY_READ,
    GETS_STATUS_READ_DATA,
    GETS_STATUS_READ_SUM_UPPER,
    GETS_STATUS_READ_SUM_LOWER,
    GETS_STATUS_END,
  } status;

  status = GETS_STATUS_WAIT_DOLLAR;

  while (status != GETS_STATUS_END) {
    if (status != GETS_STATUS_READY_READ)
      c = getDebugChar();
    switch (status) {
    case GETS_STATUS_WAIT_DOLLAR:
      if (c == '$') status = GETS_STATUS_READY_READ;
      break;
    case GETS_STATUS_READY_READ:
      i = 0;
      sum = datasum = 0;
      status = GETS_STATUS_READ_DATA;
      break;
    case GETS_STATUS_READ_DATA:
      if (c == '$') {
	status = GETS_STATUS_READY_READ;
	break;
      }
      if (c == '#') {
	buffer[i] = '\0';
	status = GETS_STATUS_READ_SUM_UPPER;
	break;
      }
      sum += c;
      buffer[i++] = c;
      break;
    case GETS_STATUS_READ_SUM_UPPER:
      datasum = a2h(c) << 4;
      status = GETS_STATUS_READ_SUM_LOWER;
      break;
    case GETS_STATUS_READ_SUM_LOWER:
      datasum |= a2h(c);
      if (sum != datasum) {
	putDebugChar('-');
	status = GETS_STATUS_WAIT_DOLLAR;
      } else {
	status = GETS_STATUS_END;
      }
      break;
    default:
      break;
    }
  }

  putDebugChar('+');
  if ((i > 2) && (buffer[2] == ':')) {
    putDebugChar(buffer[0]);
    putDebugChar(buffer[1]);
    return &buffer[3];
  }
  return buffer;
}