This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

More H8 ELF infrastructure



As folks can probably guess, Joern and I are working on adding ELF support
to the H8 architecture.


This change adds more infrastructure we'll need for that support; specifically
it adds the infrastructure we need to be able to record and examine the
machine type in the ELF header.  Meaning we'll be able to distinguish files
that were compiled for the H8/300 from the H8/300H and from the H8/S.


	* cpu-h8300.c (h8300_scan, compatible): Prototype.
	(h8300_scan): Handle architecture:machine encodings typically
	found in linker scripts.
	* elf.c (prep_headers): Do not try to do H8 machine recognition
	here.
	* elf32-h8300.c:  Add some missing prototypes.
	(elf32_h8_mach, elf32_h8_final_write_processing): New functions.
	(elf32_h8_object_p): Similarly.
	
	* h8.h (EF_H8_MACH): New mask for encoded machine type.
	(E_H8_MACH_H8300, E_H8_MACH_H8300H, E_H8_MACH_H8300S): New
	machine types.

Index: bfd/cpu-h8300.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/cpu-h8300.c,v
retrieving revision 1.35
diff -c -3 -p -r1.35 cpu-h8300.c
*** cpu-h8300.c	2001/03/15 04:23:04	1.35
--- cpu-h8300.c	2001/08/29 17:14:05
***************
*** 1,5 ****
  /* BFD library support routines for the Hitachi H8/300 architecture.
!    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2000
     Free Software Foundation, Inc.
     Hacked by Steve Chamberlain of Cygnus Support.
  
--- 1,5 ----
  /* BFD library support routines for the Hitachi H8/300 architecture.
!    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2000, 2001
     Free Software Foundation, Inc.
     Hacked by Steve Chamberlain of Cygnus Support.
  
*************** Foundation, Inc., 59 Temple Place - Suit
*** 25,30 ****
--- 25,35 ----
  
  int bfd_default_scan_num_mach ();
  
+ static boolean h8300_scan
+   PARAMS ((const struct bfd_arch_info *, const char *));
+ static const bfd_arch_info_type * compatible
+   PARAMS ((const bfd_arch_info_type *, const bfd_arch_info_type *));
+ 
  static boolean
  h8300_scan (info, string)
       const struct bfd_arch_info *info;
*************** h8300_scan (info, string)
*** 52,57 ****
--- 57,74 ----
    string++;
    if (*string == '-')
      string++;
+ 
+   /* In ELF linker scripts, we typically express the architecture/machine
+      as architecture:machine.
+ 
+      So if we've matched so far and encounter a colon, try to match the
+      string following the colon.  */
+   if (*string == ':')
+     {
+       string++;
+       h8300_scan (info, string);
+     }
+ 
    if (*string == 'h' || *string == 'H')
      {
        return (info->mach == bfd_mach_h8300h);
Index: bfd/elf.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf.c,v
retrieving revision 1.285
diff -c -3 -p -r1.285 elf.c
*** elf.c	2001/08/29 01:42:21	1.285
--- elf.c	2001/08/29 17:14:10
*************** prep_headers (abfd)
*** 3502,3520 ****
        break;
  /* end-sanitize-stormy16 */
      case bfd_arch_h8300:
!       switch (bfd_get_mach (abfd))
! 	{
! 	default:
! 	case bfd_mach_h8300:
! 	  i_ehdrp->e_machine = EM_H8_300;
! 	  break;
! 	case bfd_mach_h8300h:
! 	  i_ehdrp->e_machine = EM_H8_300H;
! 	  break;
! 	case bfd_mach_h8300s:
! 	  i_ehdrp->e_machine = EM_H8S;
! 	  break;
! 	}
        break;
      case bfd_arch_h8500:
        i_ehdrp->e_machine = EM_H8_500;
--- 3502,3508 ----
        break;
  /* end-sanitize-stormy16 */
      case bfd_arch_h8300:
!       i_ehdrp->e_machine = EM_H8_300;
        break;
      case bfd_arch_h8500:
        i_ehdrp->e_machine = EM_H8_500;
Index: bfd/elf32-h8300.c
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf32-h8300.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 elf32-h8300.c
*** elf32-h8300.c	2001/08/29 01:42:21	1.2
--- elf32-h8300.c	2001/08/29 17:14:10
*************** static const struct elf_reloc_map h8_rel
*** 184,189 ****
--- 184,198 ----
    { BFD_RELOC_H8_DIR32A16, R_H8_DIR32A16_X },
  };
  
+ static reloc_howto_type *elf32_h8_reloc_type_lookup
+   PARAMS ((bfd *, bfd_reloc_code_real_type));
+ static void elf32_h8_info_to_howto
+   PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
+ static void elf32_h8_info_to_howto_rel
+   PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
+ static int elf32_h8_mach
+   PARAMS ((flagword));
+ 
  static reloc_howto_type *
  elf32_h8_reloc_type_lookup (abfd, code)
       bfd *abfd ATTRIBUTE_UNUSED;
*************** elf32_h8_info_to_howto_rel (abfd, bfd_re
*** 231,236 ****
--- 240,336 ----
    bfd_reloc->howto = &h8_elf_howto_table[r];
  }
  
+ /* Object files encode the specific H8 model they were compiled
+    for in the ELF flags field.
+ 
+    Examine that field and return the proper BFD machine type for
+    the object file.  */
+ static int
+ elf32_h8_mach (flags)
+      flagword flags;
+ {
+   switch (flags & EF_H8_MACH)
+     {
+     case E_H8_MACH_H8300:
+     default:
+       return bfd_mach_h8300;
+ 
+     case E_H8_MACH_H8300H:
+       return bfd_mach_h8300h;
+ 
+     case E_H8_MACH_H8300S:
+       return bfd_mach_h8300s;
+     }
+ }
+ 
+ /* The final processing done just before writing out a H8 ELF object
+    file.  We use this opportunity to encode the BFD machine type
+    into the flags field in the object file.  */
+ 
+ void
+ elf32_h8_final_write_processing (abfd, linker)
+      bfd *abfd;
+      boolean linker ATTRIBUTE_UNUSED;
+ {
+   unsigned long val;
+ 
+   switch (bfd_get_mach (abfd))
+     {
+     default:
+     case bfd_mach_h8300:
+       val = E_H8_MACH_H8300;
+       break;
+ 
+     case bfd_mach_h8300h:
+       val = E_H8_MACH_H8300H;
+       break;
+ 
+     case bfd_mach_h8300s:
+       val = E_H8_MACH_H8300S;
+       break;
+     }
+ 
+   elf_elfheader (abfd)->e_flags &= ~ (EF_H8_MACH);
+   elf_elfheader (abfd)->e_flags |= val;
+ }
+ 
+ /* Return nonzero if ABFD represents a valid H8 ELF object file; also
+    record the encoded machine type found in the ELF flags.  */
+ 
+ boolean
+ elf32_h8_object_p (abfd)
+      bfd *abfd;
+ {
+   bfd_default_set_arch_mach (abfd, bfd_arch_h8300,
+ 			     elf32_h8_mach (elf_elfheader (abfd)->e_flags));
+   return true;
+ }
+ 
+ /* Merge backend specific data from an object file to the output
+    object file when linking.  The only data we need to copy at this
+    time is the architecture/machine information.  */
+ 
+ boolean
+ elf32_h8_merge_private_bfd_data (ibfd, obfd)
+      bfd *ibfd;
+      bfd *obfd;
+ {
+   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+     return true;
+ 
+   if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
+       && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
+     {
+       if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
+                                bfd_get_mach (ibfd)))
+         return false;
+     }
+ 
+   return true;
+ }
+ 
+ 
  #define TARGET_BIG_SYM			bfd_elf32_h8300_vec
  #define TARGET_BIG_NAME			"elf32-h8300"
  #define ELF_ARCH			bfd_arch_h8300
*************** elf32_h8_info_to_howto_rel (abfd, bfd_re
*** 239,244 ****
--- 339,353 ----
  #define bfd_elf32_bfd_reloc_type_lookup elf32_h8_reloc_type_lookup
  #define elf_info_to_howto		elf32_h8_info_to_howto
  #define elf_info_to_howto_rel		elf32_h8_info_to_howto_rel
+ 
+ /* So we can set/examine bits in e_flags to get the specific
+    H8 architecture in use.  */
+ #define elf_backend_final_write_processing \
+   elf32_h8_final_write_processing
+ #define elf_backend_object_p \
+   elf32_h8_object_p
+ #define bfd_elf32_bfd_merge_private_bfd_data \
+   elf32_h8_merge_private_bfd_data
  
  /* ??? when elf_backend_relocate_section is not defined, elf32-target.h
     defaults to using _bfd_generic_link_hash_table_create, but
Index: include/elf/h8.h
===================================================================
RCS file: /cvs/cvsfiles/devo/include/elf/h8.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 h8.h
*** h8.h	2001/08/28 22:35:24	1.2
--- h8.h	2001/08/29 17:14:10
*************** START_RELOC_NUMBERS (elf_h8_reloc_type)
*** 83,86 ****
--- 83,96 ----
    RELOC_NUMBER (R_H8_OPscttop, 141)
  END_RELOC_NUMBERS (R_H8_max)
  
+ /* Machine variant if we know it.  This field was invented at Cygnus,
+    but it is hoped that other vendors will adopt it.  If some standard
+    is developed, this code should be changed to follow it. */
+ 
+ #define EF_H8_MACH		0x00FF0000
+ 
+ #define E_H8_MACH_H8300		0x00800000
+ #define E_H8_MACH_H8300H	0x00810000
+ #define E_H8_MACH_H8300S	0x00820000
+ 
  #endif




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]