Пример #1
0
/*-----------------------------------------------------------------*/
static char *getMemCache(unsigned int addr,int cachenum, unsigned int size)
{
  char *resp, *buf;
  unsigned int laddr;
  memcache_t *cache = &memCache[cachenum];

  if ( cache->size <=   0 ||
       cache->addr > addr ||
       cache->addr + cache->size < addr + size )
    {
      if ( cachenum == IMEM_CACHE )
        {
          sendSim("di 0x0 0xff\n");
        }
      else if ( cachenum == SREG_CACHE )
        {
          sendSim("ds 0x80 0xff\n");
        }
      else
        {
          laddr = addr & 0xffffffc0;
          sprintf(cache->buffer,"dx 0x%x 0x%x\n",laddr,laddr+0xff );
          sendSim(cache->buffer);
        }
      waitForSim(100,NULL);
      resp = simResponse();
      cache->addr = strtol(resp,0,0);
      buf = cache->buffer;
      cache->size = 0;
      while ( *resp && *(resp+1) && *(resp+2))
        {
          /* cache is a stringbuffer with ascii data like
             " 00 00 00 00 00 00 00 00"
          */
          resp += 2;
          laddr = 0;
          /* skip thru the address part */
          while (isxdigit(*resp))
              resp++;
          while ( *resp && *resp != '\n')
            {
              if ( laddr < 24 )
                {
                  laddr++ ;
                  *buf++ = *resp ;
                }
              resp++;
            }
          resp++ ;
          cache->size += 8;
        }
      *buf = '\0';
      if ( cache->addr > addr ||
           cache->addr + cache->size < addr + size )
        {
          return NULL;
        }
    }
  return cache->buffer + (addr - cache->addr)*3;
}
Пример #2
0
/*-----------------------------------------------------------------*/
void closeSimulator (void)
{
#ifdef _WIN32
  if ( ! simin || ! simout || INVALID_SOCKET == sock )
#else
  if ( ! simin || ! simout || sock == -1 )
#endif
    {
      simactive = 0;
      return;
    }
  simactive = 0;
  sendSim("quit\n");
  fclose (simin);
  fclose (simout);
  shutdown(sock, 2);
#ifdef _WIN32
  closesocket(sock);
  sock = -1;
  if (NULL != simPid)
      TerminateProcess(simPid->hProcess, 0);
  // Close process and thread handles.
  CloseHandle(simPid->hProcess);
  CloseHandle(simPid->hThread);
#else
  close(sock);
  sock = -1;
  if ( simPid > 0 )
      kill (simPid,SIGKILL);
#endif
}
Пример #3
0
int simSetValue (unsigned int addr,char mem, unsigned int size, unsigned long val)
{
  unsigned int i;
  char cachenr;
  char buffer[40];
  char *s;

  if ( size <= 0 )
      return 0;

  cachenr = getMemString(buffer, 1, &addr, mem, size);
  if ( cachenr < NMEM_CACHE )
    {
      invalidateCache(cachenr);
    }
  s = buffer + strlen(buffer) -1;
  for ( i = 0 ; i < size ; i++ )
    {
      sprintf(s," 0x%lx", val & 0xff);
      s += strlen(s);
      val >>= 8;
    }
  sprintf(s,"\n");
  sendSim(buffer);
  waitForSim(100,NULL);
  simResponse();
  return 0;
}
Пример #4
0
/*-----------------------------------------------------------------*/
void closeSimulator (void)
{
#ifdef _WIN32
    if ( ! simin || ! simout || INVALID_SOCKET == sock )
#else
    if ( ! simin || ! simout || sock == -1 )
#endif
    {
        simactive = 0;
        return;
    }
    simactive = 0;
    sendSim("quit\n");
    shutdown(sock, 2);
#ifdef _WIN32
    closesocket(sock);
    sock = -1;
    if (NULL != simPid)
    {
        TerminateProcess(simPid->hProcess, 0);
        // Close process and thread handles.
        CloseHandle(simPid->hProcess);
        CloseHandle(simPid->hThread);
    }
#else
    close(sock);
    sock = -1;
    if ( simPid > 0 )
        kill (simPid,SIGKILL);
#endif
    /* simin/simout are now dead as they are both associated with the closed socket */
    simin = NULL;
    simout = NULL;
}
Пример #5
0
/*-----------------------------------------------------------------*/
void simReset (void)
{
  invalidateCache(XMEM_CACHE);
  invalidateCache(IMEM_CACHE);
  invalidateCache(SREG_CACHE);
  sendSim("res\n");
  waitForSim(100, NULL);
}
Пример #6
0
/*-----------------------------------------------------------------*/
void simClearBP (unsigned int addr)
{
  char buff[50];

  sprintf(buff, "clear 0x%x\n", addr);
  sendSim(buff);
  waitForSim(100, NULL);
}
Пример #7
0
/*-----------------------------------------------------------------*/
void simSetBP (unsigned int addr)
{
  char buff[50];

  sprintf(buff, "break 0x%x\n", addr);
  sendSim(buff);
  waitForSim(100, NULL);
}
Пример #8
0
void simSetPC( unsigned int addr )
{
  char buffer[40];
  sprintf(buffer,"pc %d\n", addr);
  sendSim(buffer);
  waitForSim(100,NULL);
  simResponse();
}
Пример #9
0
/*-----------------------------------------------------------------*/
void simLoadFile (char *s)
{
  char buff[128];

  sprintf(buff, "file \"%s\"\n", s);
  printf("%s",buff);
  sendSim(buff);
  waitForSim(500, NULL);
}
Пример #10
0
/*-----------------------------------------------------------------*/
unsigned int simGoTillBp ( unsigned int gaddr)
{
  char *sr;
  int wait_ms = 1000;

  invalidateCache(XMEM_CACHE);
  invalidateCache(IMEM_CACHE);
  invalidateCache(SREG_CACHE);
  if (gaddr == 0)
    {
      /* initial start, start & stop from address 0 */
      //char buf[20];

      // this program is setting up a bunch of breakpoints automatically
      // at key places.  Like at startup & main() and other function
      // entry points.  So we don't need to setup one here..
      //sendSim("break 0x0\n");
      //sleep(1);
      //waitForSim();

      sendSim("reset\n");
      waitForSim(wait_ms, NULL);
      sendSim("run 0x0\n");
    }
  else if (gaddr == -1)
    { /* resume */
      sendSim ("run\n");
      wait_ms = 100;
    }
  else if (gaddr == 1 )
    { /* nexti or next */
      sendSim ("next\n");
      wait_ms = 100;
    }
  else if (gaddr == 2 )
    { /* stepi or step */
      sendSim ("step\n");
      wait_ms = 100;
    }
  else
    {
      printf("Error, simGoTillBp > 0!\n");
      exit(1);
    }

  waitForSim(wait_ms, NULL);

  /* get the simulator response */
  sr = simResponse();
  /* check for errors */
  while ( *sr )
    {
      while ( *sr && *sr != 'E' )
          sr++ ;
      if ( !*sr )
          break;
      if ( ! strncmp(sr, "Error:", 6))
        {
          fputs(sr, stdout);
          break;
        }
      sr++ ;
    }

  nointerrupt = 1;
  /* get answer of stop command */
  if ( userinterrupt )
      waitForSim(wait_ms, NULL);

  /* better solution: ask pc */
  sendSim ("pc\n");
  waitForSim(100, NULL);
  sr = simResponse();
  nointerrupt = 0;

  gaddr = strtol(sr+3, 0, 0);
  return gaddr;
}
Пример #11
0
/*-----------------------------------------------------------------*/
unsigned long simGetValue (unsigned int addr,char mem, unsigned int size)
{
  unsigned int b[4] = {0,0,0,0}; /* can be a max of four bytes long */
  char cachenr;
  char buffer[40];
  char *resp;

  if ( size <= 0 )
      return 0;

  cachenr = getMemString(buffer, 0, &addr, mem, size);

  resp = NULL;
  if ( cachenr < NMEM_CACHE )
    {
      resp = getMemCache(addr,cachenr,size);
    }
  if ( !resp )
    {
      /* create the simulator command */
      sendSim(buffer);
      waitForSim(100,NULL);
      resp = simResponse();

      /* got the response we need to parse it the response
         is of the form
         [address] [v] [v] [v] ... special case in
         case of bit variables which case it becomes
         [address] [assembler bit address] [v] */
      /* first skip thru white space */
      resp = trim_left(resp);

      if (strncmp(resp, "0x",2) == 0)
          resp += 2;

      /* skip thru the address part */
      while (isxdigit(*resp))
          resp++;
    }
  /* make the branch for bit variables */
  if ( cachenr == BIT_CACHE)
    {
      /* skip until newline */
      while (*resp && *resp != '\n' )
          resp++ ;
      if ( *--resp != '0' )
          b[0] = 1;
    }
  else
    {
      unsigned int i;

      for (i = 0 ; i < size ; i++ )
        {
          /* skip white space */
          resp = trim_left(resp);

          b[i] = strtol(resp,&resp,16);
        }
    }

  return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24 ;
}