diff -rc coff2flt-0.5/Makefile coff2flt/Makefile *** coff2flt-0.5/Makefile Mon Sep 6 14:29:42 1999 --- coff2flt/Makefile Mon Dec 31 11:47:27 2001 *************** *** 1,11 **** OBJS = coff2flt.o ! CROSSCC = $(CROSS)gcc ! TOOLDIR = /opt/uClinux CC = gcc ! CFLAGS = -O2 -I$(TOOLDIR)/include ! LDFLAGS = -L$(TOOLDIR)/lib -lbfd -liberty all: coff2flt --- 1,12 ---- OBJS = coff2flt.o ! ARCH=H8300H + CROSSCC = $(CROSS)gcc + TOOLDIR = /usr CC = gcc ! CFLAGS = -O2 -g -I /usr/include/h8300-hitachi-hms ! LDFLAGS = -L /home/ysato/uCdev/binutils/bfd -lbfd -L /home/ysato/uCdev/binutils/libiberty -liberty all: coff2flt coff2flt のみに存在します: coff2flt diff -rc coff2flt-0.5/coff2flt.c coff2flt/coff2flt.c *** coff2flt-0.5/coff2flt.c Sun Sep 12 17:26:45 1999 --- coff2flt/coff2flt.c Sun Feb 3 20:39:50 2002 *************** *** 170,175 **** --- 170,256 ---- return -1; } + #if ARCH == H8300H + + struct flat_reloc * + output_relocs (bfd *input_bfd, asymbol **symbols, int number_of_symbols, unsigned long *n_relocs) + { + asection *relocs_sec = bfd_get_section_by_name (input_bfd, ".emreloc"); + bfd_size_type relocs_size; + long reloc_size; + arelent **reloc_vector = NULL; + unsigned long* flat_relocs; + bfd_byte* relocs; + long reloc_count, count; + bfd_byte* rel; + int i; + asection* a_sec; + int nsections = bfd_count_sections(input_bfd); + unsigned long * resid_from_secndx = malloc(sizeof(long)*nsections); + int data_start; + + *n_relocs = 0; + + if (!relocs_sec) + return NULL; + + a_sec = bfd_get_section_by_name (input_bfd, ".data"); + + if (!relocs) + return NULL; + + relocs_size = bfd_section_size (input_bfd, relocs_sec); + + if (!relocs_size) + return NULL; + + relocs = (bfd_byte*) xmalloc (relocs_size); + if (!bfd_get_section_contents (input_bfd, relocs_sec, relocs, 0, relocs_size)) { + einfo (E_FILE, "can't read .emreloc' section"); + free (relocs); + return 0; + } + + reloc_count = 0; + flat_relocs = 0; + + data_start = bfd_section_vma(input_bfd, a_sec); + if (verbose) + printf("Data_start = 0x%08x\n", data_start); + + for ( rel = relocs; rel < relocs + relocs_size; rel += 12) + { + unsigned int type, reloffset; + asection *sec, *relsec; + CONST char *relsecname, *symsecname; + char relbuffer[32], symbuffer[32]; + + reloffset = bfd_get_32 (input_bfd, rel); + if (reloffset == 0xffffffff) + continue; + + relsec = bfd_get_section_by_name(input_bfd,(char *)rel+4); + + if (verbose) + ewhere ("%s+0x%04x", relsec->name, reloffset); + + flat_relocs = realloc(flat_relocs, (reloc_count+1) * sizeof(unsigned long)); + flat_relocs[reloc_count] = relsec->vma+reloffset; + if (verbose) + printf("Reloc offset = (%s)0x%06x\n", relsec->name,relsec->vma+reloffset); + + reloc_count++; + + + } + + free (relocs); + + + *n_relocs = reloc_count; + return (struct flat_reloc *)flat_relocs; + } + #else #define UNSPECIFIED_RESID 3 struct flat_reloc * output_relocs (bfd *input_bfd, asymbol **symbols, int number_of_symbols, unsigned long *n_relocs, unsigned char * data) *************** *** 354,359 **** --- 435,441 ---- *n_relocs = reloc_count; return flat_relocs; } + #endif #if 0 /* shared lib symbols stuff */ *************** *** 463,480 **** unsigned long data_len; unsigned long bss_len; unsigned long text_len; unsigned long reloc_len; unsigned long data_vma; unsigned long bss_vma; unsigned long text_vma; void *text; void *data; unsigned long *reloc; struct flat_hdr hdr; ! program = argv[0]; progname = argv[0]; --- 545,565 ---- unsigned long data_len; unsigned long bss_len; unsigned long text_len; + unsigned long rodata_len; unsigned long reloc_len; unsigned long data_vma; unsigned long bss_vma; unsigned long text_vma; + unsigned long rodata_vma; void *text; void *data; + void *rodata; unsigned long *reloc; struct flat_hdr hdr; ! int output; program = argv[0]; progname = argv[0]; *************** *** 483,490 **** usage(); stack = 4096; ! ! while ((opt = getopt(argc, argv, "vs:o:")) != -1) { switch (opt) { case 'v': --- 568,575 ---- usage(); stack = 4096; ! output = 0x0f; ! while ((opt = getopt(argc, argv, "vs:o:d:")) != -1) { switch (opt) { case 'v': *************** *** 496,501 **** --- 581,589 ---- case 's': stack = atoi(optarg); break; + case 'd': + output = atoi(optarg); + break; default: fprintf(stderr, "%s Unknown option\n", argv[0]); usage(); *************** *** 550,574 **** bss_vma = s->vma; /* data_len = s->vma - data_vma; */ /* what is this for? */ ! reloc = (unsigned long *)output_relocs (bf, symbol_table, number_of_symbols, &reloc_len, data); /* Fill in the binflt_flat header */ memcpy(hdr.magic,"bFLT",4); hdr.version = htonl(2); ! hdr.entry = htonl(16 * 4); /* FIXME */ ! hdr.data_start = htonl(16 * 4 + text_len); ! hdr.data_end = htonl(16 * 4 + text_len + data_len); ! hdr.bss_end = htonl(16 * 4 + text_len + data_len + bss_len); hdr.stack_size = htonl(stack); /* FIXME */ ! hdr.reloc_start = htonl(16 * 4 + text_len + data_len); hdr.reloc_count = htonl(reloc_len); bzero(hdr.filler, sizeof(hdr.filler)); for (i=0; ivma; /* data_len = s->vma - data_vma; */ /* what is this for? */ ! s = bfd_get_section_by_name (bf, ".rodata"); ! if (s) { ! rodata_len = s->_raw_size; ! rodata_vma = s->vma; ! rodata = malloc(rodata_len); ! ! if (bfd_get_section_contents(bf, ! s, ! rodata, ! 0, ! s->_raw_size) == false) { ! fprintf(stderr, "read error section %s\n", s->name); ! exit(2); ! } ! } else { ! rodata_len = rodata_vma = 0; ! rodata = NULL; ! } ! ! reloc = (unsigned long *)output_relocs (bf, symbol_table, number_of_symbols, &reloc_len); /* Fill in the binflt_flat header */ memcpy(hdr.magic,"bFLT",4); hdr.version = htonl(2); ! hdr.entry = htonl(16 * 4 + bf -> start_address); /* Fixed ysato */ ! hdr.data_start = htonl(16 * 4 + text_len + rodata_len); ! hdr.data_end = htonl(16 * 4 + text_len + data_len + rodata_len); ! hdr.bss_end = htonl(16 * 4 + text_len + data_len + rodata_len + bss_len); hdr.stack_size = htonl(stack); /* FIXME */ ! hdr.reloc_start = htonl(16 * 4 + text_len + data_len + rodata_len); hdr.reloc_count = htonl(reloc_len); bzero(hdr.filler, sizeof(hdr.filler)); for (i=0; i