View | Details | Raw Unified
Collapse All | Expand All

(-) bfd/tekhex.c (-24 / +58 lines)
 Lines 264-299   typedef struct tekhex_data_struct Link Here 
#define enda(x) (x->vma + x->size)
#define enda(x) (x->vma + x->size)
static bfd_vma
static bfd_boolean
getvalue (char **srcp)
getvalue (char **srcp, bfd_vma *valuep)
{
{
  char *src = *srcp;
  char *src = *srcp;
  bfd_vma value = 0;
  bfd_vma value = 0;
  unsigned int len = hex_value(*src++);
  unsigned int len;
  if (!ISHEX (*src))
    return FALSE;
  len = hex_value (*src++);
  if (len == 0)
  if (len == 0)
    len = 16;
    len = 16;
  while (len--)
  while (len--)
    value = value << 4 | hex_value(*src++);
    {
      if (!ISHEX (*src))
	return FALSE;
      value = value << 4 | hex_value (*src++);
    }
  *srcp = src;
  *srcp = src;
  return value;
  *valuep = value;
  return TRUE;
}
}
static unsigned int
static bfd_boolean
getsym (char *dstp, char **srcp)
getsym (char *dstp, char **srcp, unsigned int *lenp)
{
{
  char *src = *srcp;
  char *src = *srcp;
  unsigned int i;
  unsigned int i;
  unsigned int len = hex_value(*src++);
  unsigned int len;
  
  if (!ISHEX (*src))
    return FALSE;
  len = hex_value (*src++);
  if (len == 0)
  if (len == 0)
    len = 16;
    len = 16;
  for (i = 0; i < len; i++)
  for (i = 0; i < len; i++)
    dstp[i] = src[i];
    dstp[i] = src[i];
  dstp[i] = 0;
  dstp[i] = 0;
  *srcp = src + i;
  *srcp = src + i;
  return len;
  *lenp = len;
  return TRUE;
}
}
static struct data_struct *
static struct data_struct *
 Lines 333-343   insert_byte (bfd *abfd, int value, bfd_v Link Here 
/* The first pass is to find the names of all the sections, and see
/* The first pass is to find the names of all the sections, and see
  how big the data is.  */
  how big the data is.  */
static void
static bfd_boolean
first_phase (bfd *abfd, int type, char *src)
first_phase (bfd *abfd, int type, char *src)
{
{
  asection *section = bfd_abs_section_ptr;
  asection *section = bfd_abs_section_ptr;
  unsigned int len;
  unsigned int len;
  bfd_vma val;
  char sym[17];			/* A symbol can only be 16chars long.  */
  char sym[17];			/* A symbol can only be 16chars long.  */
  switch (type)
  switch (type)
 Lines 345-351   first_phase (bfd *abfd, int type, char * Link Here 
    case '6':
    case '6':
      /* Data record - read it and store it.  */
      /* Data record - read it and store it.  */
      {
      {
	bfd_vma addr = getvalue (&src);
	bfd_vma addr;
	if (!getvalue (&src, &addr))
	  return FALSE;
	while (*src)
	while (*src)
	  {
	  {
 Lines 355-371   first_phase (bfd *abfd, int type, char * Link Here 
	  }
	  }
      }
      }
      return;
      return TRUE;
    case '3':
    case '3':
      /* Symbol record, read the segment.  */
      /* Symbol record, read the segment.  */
      len = getsym (sym, &src);
      if (!getsym (sym, &src, &len))
	return FALSE;
      section = bfd_get_section_by_name (abfd, sym);
      section = bfd_get_section_by_name (abfd, sym);
      if (section == NULL)
      if (section == NULL)
	{
	{
	  char *n = bfd_alloc (abfd, (bfd_size_type) len + 1);
	  char *n = bfd_alloc (abfd, (bfd_size_type) len + 1);
	  if (!n)
	  if (!n)
	    abort ();		/* FIXME.  */
	    return FALSE;
	  memcpy (n, sym, len + 1);
	  memcpy (n, sym, len + 1);
	  section = bfd_make_section (abfd, n);
	  section = bfd_make_section (abfd, n);
	}
	}
 Lines 375-382   first_phase (bfd *abfd, int type, char * Link Here 
	    {
	    {
	    case '1':		/* Section range.  */
	    case '1':		/* Section range.  */
	      src++;
	      src++;
	      section->vma = getvalue (&src);
	      if (!getvalue (&src, &section->vma))
	      section->size = getvalue (&src) - section->vma;
		return FALSE;
	      if (!getvalue (&src, &val))
		return FALSE;
	      section->size = val - section->vma;
	      section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
	      section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
	      break;
	      break;
	    case '0':
	    case '0':
 Lines 393-427   first_phase (bfd *abfd, int type, char * Link Here 
		char stype = (*src);
		char stype = (*src);
		if (!new)
		if (!new)
		  abort ();	/* FIXME.  */
		  return FALSE;
		new->symbol.the_bfd = abfd;
		new->symbol.the_bfd = abfd;
		src++;
		src++;
		abfd->symcount++;
		abfd->symcount++;
		abfd->flags |= HAS_SYMS;
		abfd->flags |= HAS_SYMS;
		new->prev = abfd->tdata.tekhex_data->symbols;
		new->prev = abfd->tdata.tekhex_data->symbols;
		abfd->tdata.tekhex_data->symbols = new;
		abfd->tdata.tekhex_data->symbols = new;
		len = getsym (sym, &src);
		if (!getsym (sym, &src, &len))
		  return FALSE;
		new->symbol.name = bfd_alloc (abfd, (bfd_size_type) len + 1);
		new->symbol.name = bfd_alloc (abfd, (bfd_size_type) len + 1);
		if (!new->symbol.name)
		if (!new->symbol.name)
		  abort ();	/* FIXME.  */
		  return FALSE;
		memcpy ((char *) (new->symbol.name), sym, len + 1);
		memcpy ((char *) (new->symbol.name), sym, len + 1);
		new->symbol.section = section;
		new->symbol.section = section;
		if (stype <= '4')
		if (stype <= '4')
		  new->symbol.flags = (BSF_GLOBAL | BSF_EXPORT);
		  new->symbol.flags = (BSF_GLOBAL | BSF_EXPORT);
		else
		else
		  new->symbol.flags = BSF_LOCAL;
		  new->symbol.flags = BSF_LOCAL;
		new->symbol.value = getvalue (&src) - section->vma;
		if (!getvalue (&src, &val))
		  return FALSE;
		new->symbol.value = val - section->vma;
	      }
	      }
	    default:
	      return FALSE;
	    }
	    }
	}
	}
    }
    }
  return TRUE;
}
}
/* Pass over a tekhex, calling one of the above functions on each
/* Pass over a tekhex, calling one of the above functions on each
   record.  */
   record.  */
static void
static bfd_boolean
pass_over (bfd *abfd, void (*func) (bfd *, int, char *))
pass_over (bfd *abfd, bfd_boolean (*func) (bfd *, int, char *))
{
{
  unsigned int chars_on_line;
  unsigned int chars_on_line;
  bfd_boolean eof = FALSE;
  bfd_boolean eof = FALSE;
 Lines 462-469   pass_over (bfd *abfd, void (*func) (bfd Link Here 
      /* Put a null at the end.  */
      /* Put a null at the end.  */
      src[chars_on_line] = 0;
      src[chars_on_line] = 0;
      func (abfd, type, src);
      if (!func (abfd, type, src))
	return FALSE;
    }
    }
  return TRUE;
}
}
static long
static long
 Lines 524-530   tekhex_object_p (bfd *abfd) Link Here 
  tekhex_mkobject (abfd);
  tekhex_mkobject (abfd);
  pass_over (abfd, first_phase);
  if (!pass_over (abfd, first_phase))
    return NULL;
  return abfd->xvec;
  return abfd->xvec;
}
}