Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 134112
Collapse All | Expand All

(-)bfd/tekhex.c (-24 / +58 lines)
Lines 264-299 typedef struct tekhex_data_struct Link Here
264
264
265
#define enda(x) (x->vma + x->size)
265
#define enda(x) (x->vma + x->size)
266
266
267
static bfd_vma
267
static bfd_boolean
268
getvalue (char **srcp)
268
getvalue (char **srcp, bfd_vma *valuep)
269
{
269
{
270
  char *src = *srcp;
270
  char *src = *srcp;
271
  bfd_vma value = 0;
271
  bfd_vma value = 0;
272
  unsigned int len = hex_value(*src++);
272
  unsigned int len;
273
274
  if (!ISHEX (*src))
275
    return FALSE;
273
276
277
  len = hex_value (*src++);
274
  if (len == 0)
278
  if (len == 0)
275
    len = 16;
279
    len = 16;
276
  while (len--)
280
  while (len--)
277
    value = value << 4 | hex_value(*src++);
281
    {
282
      if (!ISHEX (*src))
283
	return FALSE;
284
      value = value << 4 | hex_value (*src++);
285
    }
278
286
279
  *srcp = src;
287
  *srcp = src;
280
  return value;
288
  *valuep = value;
289
  return TRUE;
281
}
290
}
282
291
283
static unsigned int
292
static bfd_boolean
284
getsym (char *dstp, char **srcp)
293
getsym (char *dstp, char **srcp, unsigned int *lenp)
285
{
294
{
286
  char *src = *srcp;
295
  char *src = *srcp;
287
  unsigned int i;
296
  unsigned int i;
288
  unsigned int len = hex_value(*src++);
297
  unsigned int len;
298
  
299
  if (!ISHEX (*src))
300
    return FALSE;
289
301
302
  len = hex_value (*src++);
290
  if (len == 0)
303
  if (len == 0)
291
    len = 16;
304
    len = 16;
292
  for (i = 0; i < len; i++)
305
  for (i = 0; i < len; i++)
293
    dstp[i] = src[i];
306
    dstp[i] = src[i];
294
  dstp[i] = 0;
307
  dstp[i] = 0;
295
  *srcp = src + i;
308
  *srcp = src + i;
296
  return len;
309
  *lenp = len;
310
  return TRUE;
297
}
311
}
298
312
299
static struct data_struct *
313
static struct data_struct *
Lines 333-343 insert_byte (bfd *abfd, int value, bfd_v Link Here
333
/* The first pass is to find the names of all the sections, and see
347
/* The first pass is to find the names of all the sections, and see
334
  how big the data is.  */
348
  how big the data is.  */
335
349
336
static void
350
static bfd_boolean
337
first_phase (bfd *abfd, int type, char *src)
351
first_phase (bfd *abfd, int type, char *src)
338
{
352
{
339
  asection *section = bfd_abs_section_ptr;
353
  asection *section = bfd_abs_section_ptr;
340
  unsigned int len;
354
  unsigned int len;
355
  bfd_vma val;
341
  char sym[17];			/* A symbol can only be 16chars long.  */
356
  char sym[17];			/* A symbol can only be 16chars long.  */
342
357
343
  switch (type)
358
  switch (type)
Lines 345-351 first_phase (bfd *abfd, int type, char * Link Here
345
    case '6':
360
    case '6':
346
      /* Data record - read it and store it.  */
361
      /* Data record - read it and store it.  */
347
      {
362
      {
348
	bfd_vma addr = getvalue (&src);
363
	bfd_vma addr;
364
365
	if (!getvalue (&src, &addr))
366
	  return FALSE;
349
367
350
	while (*src)
368
	while (*src)
351
	  {
369
	  {
Lines 355-371 first_phase (bfd *abfd, int type, char * Link Here
355
	  }
373
	  }
356
      }
374
      }
357
375
358
      return;
376
      return TRUE;
359
    case '3':
377
    case '3':
360
      /* Symbol record, read the segment.  */
378
      /* Symbol record, read the segment.  */
361
      len = getsym (sym, &src);
379
      if (!getsym (sym, &src, &len))
380
	return FALSE;
362
      section = bfd_get_section_by_name (abfd, sym);
381
      section = bfd_get_section_by_name (abfd, sym);
363
      if (section == NULL)
382
      if (section == NULL)
364
	{
383
	{
365
	  char *n = bfd_alloc (abfd, (bfd_size_type) len + 1);
384
	  char *n = bfd_alloc (abfd, (bfd_size_type) len + 1);
366
385
367
	  if (!n)
386
	  if (!n)
368
	    abort ();		/* FIXME.  */
387
	    return FALSE;
369
	  memcpy (n, sym, len + 1);
388
	  memcpy (n, sym, len + 1);
370
	  section = bfd_make_section (abfd, n);
389
	  section = bfd_make_section (abfd, n);
371
	}
390
	}
Lines 375-382 first_phase (bfd *abfd, int type, char * Link Here
375
	    {
394
	    {
376
	    case '1':		/* Section range.  */
395
	    case '1':		/* Section range.  */
377
	      src++;
396
	      src++;
378
	      section->vma = getvalue (&src);
397
	      if (!getvalue (&src, &section->vma))
379
	      section->size = getvalue (&src) - section->vma;
398
		return FALSE;
399
	      if (!getvalue (&src, &val))
400
		return FALSE;
401
	      section->size = val - section->vma;
380
	      section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
402
	      section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
381
	      break;
403
	      break;
382
	    case '0':
404
	    case '0':
Lines 393-427 first_phase (bfd *abfd, int type, char * Link Here
393
		char stype = (*src);
415
		char stype = (*src);
394
416
395
		if (!new)
417
		if (!new)
396
		  abort ();	/* FIXME.  */
418
		  return FALSE;
397
		new->symbol.the_bfd = abfd;
419
		new->symbol.the_bfd = abfd;
398
		src++;
420
		src++;
399
		abfd->symcount++;
421
		abfd->symcount++;
400
		abfd->flags |= HAS_SYMS;
422
		abfd->flags |= HAS_SYMS;
401
		new->prev = abfd->tdata.tekhex_data->symbols;
423
		new->prev = abfd->tdata.tekhex_data->symbols;
402
		abfd->tdata.tekhex_data->symbols = new;
424
		abfd->tdata.tekhex_data->symbols = new;
403
		len = getsym (sym, &src);
425
		if (!getsym (sym, &src, &len))
426
		  return FALSE;
404
		new->symbol.name = bfd_alloc (abfd, (bfd_size_type) len + 1);
427
		new->symbol.name = bfd_alloc (abfd, (bfd_size_type) len + 1);
405
		if (!new->symbol.name)
428
		if (!new->symbol.name)
406
		  abort ();	/* FIXME.  */
429
		  return FALSE;
407
		memcpy ((char *) (new->symbol.name), sym, len + 1);
430
		memcpy ((char *) (new->symbol.name), sym, len + 1);
408
		new->symbol.section = section;
431
		new->symbol.section = section;
409
		if (stype <= '4')
432
		if (stype <= '4')
410
		  new->symbol.flags = (BSF_GLOBAL | BSF_EXPORT);
433
		  new->symbol.flags = (BSF_GLOBAL | BSF_EXPORT);
411
		else
434
		else
412
		  new->symbol.flags = BSF_LOCAL;
435
		  new->symbol.flags = BSF_LOCAL;
413
		new->symbol.value = getvalue (&src) - section->vma;
436
		if (!getvalue (&src, &val))
437
		  return FALSE;
438
		new->symbol.value = val - section->vma;
414
	      }
439
	      }
440
	    default:
441
	      return FALSE;
415
	    }
442
	    }
416
	}
443
	}
417
    }
444
    }
445
446
  return TRUE;
418
}
447
}
419
448
420
/* Pass over a tekhex, calling one of the above functions on each
449
/* Pass over a tekhex, calling one of the above functions on each
421
   record.  */
450
   record.  */
422
451
423
static void
452
static bfd_boolean
424
pass_over (bfd *abfd, void (*func) (bfd *, int, char *))
453
pass_over (bfd *abfd, bfd_boolean (*func) (bfd *, int, char *))
425
{
454
{
426
  unsigned int chars_on_line;
455
  unsigned int chars_on_line;
427
  bfd_boolean eof = FALSE;
456
  bfd_boolean eof = FALSE;
Lines 462-469 pass_over (bfd *abfd, void (*func) (bfd Link Here
462
      /* Put a null at the end.  */
491
      /* Put a null at the end.  */
463
      src[chars_on_line] = 0;
492
      src[chars_on_line] = 0;
464
493
465
      func (abfd, type, src);
494
      if (!func (abfd, type, src))
495
	return FALSE;
466
    }
496
    }
497
498
  return TRUE;
467
}
499
}
468
500
469
static long
501
static long
Lines 524-530 tekhex_object_p (bfd *abfd) Link Here
524
556
525
  tekhex_mkobject (abfd);
557
  tekhex_mkobject (abfd);
526
558
527
  pass_over (abfd, first_phase);
559
  if (!pass_over (abfd, first_phase))
560
    return NULL;
561
528
  return abfd->xvec;
562
  return abfd->xvec;
529
}
563
}
530
564

Return to bug 134112