xref: /openbsd/gnu/usr.bin/binutils/bfd/cpu-h8500.c (revision 007c2a45)
12159047fSniklas /* BFD library support routines for the H8/500 architecture.
2*007c2a45Smiod    Copyright 1993, 1995, 2000, 2001, 2002, 2003
3*007c2a45Smiod    Free Software Foundation, Inc.
42159047fSniklas    Hacked by Steve Chamberlain of Cygnus Support.
52159047fSniklas 
62159047fSniklas This file is part of BFD, the Binary File Descriptor library.
72159047fSniklas 
82159047fSniklas This program is free software; you can redistribute it and/or modify
92159047fSniklas it under the terms of the GNU General Public License as published by
102159047fSniklas the Free Software Foundation; either version 2 of the License, or
112159047fSniklas (at your option) any later version.
122159047fSniklas 
132159047fSniklas This program is distributed in the hope that it will be useful,
142159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
152159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162159047fSniklas GNU General Public License for more details.
172159047fSniklas 
182159047fSniklas You should have received a copy of the GNU General Public License
192159047fSniklas along with this program; if not, write to the Free Software
202159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
212159047fSniklas 
222159047fSniklas #include "bfd.h"
232159047fSniklas #include "sysdep.h"
242159047fSniklas #include "libbfd.h"
252159047fSniklas 
26c074d1c9Sdrahn static bfd_boolean scan_mach
27c074d1c9Sdrahn   PARAMS ((const struct bfd_arch_info *, const char *));
282159047fSniklas 
29c074d1c9Sdrahn #if 0
302159047fSniklas /*
312159047fSniklas Relocations for the Z8K
322159047fSniklas 
332159047fSniklas */
342159047fSniklas static bfd_reloc_status_type
352159047fSniklas howto16_callback (abfd, reloc_entry, symbol_in, data,
362159047fSniklas 		  ignore_input_section, ignore_bfd)
372159047fSniklas      bfd *abfd;
382159047fSniklas      arelent *reloc_entry;
39*007c2a45Smiod      struct bfd_symbol *symbol_in;
402159047fSniklas      PTR data;
412159047fSniklas      asection *ignore_input_section;
422159047fSniklas      bfd *ignore_bfd;
432159047fSniklas {
442159047fSniklas   long relocation = 0;
452159047fSniklas   bfd_vma addr = reloc_entry->address;
462159047fSniklas   long x = bfd_get_16 (abfd, (bfd_byte *)data + addr);
472159047fSniklas 
482159047fSniklas   HOWTO_PREPARE(relocation, symbol_in);
492159047fSniklas 
502159047fSniklas   x = (x + relocation + reloc_entry->addend);
512159047fSniklas 
522159047fSniklas   bfd_put_16 (abfd, x, (bfd_byte *)data + addr);
532159047fSniklas   return bfd_reloc_ok;
542159047fSniklas }
552159047fSniklas 
562159047fSniklas static bfd_reloc_status_type
572159047fSniklas howto8_callback (abfd, reloc_entry, symbol_in, data,
582159047fSniklas 		 ignore_input_section, ignore_bfd)
592159047fSniklas      bfd *abfd;
602159047fSniklas      arelent *reloc_entry;
61*007c2a45Smiod      struct bfd_symbol *symbol_in;
622159047fSniklas      PTR data;
632159047fSniklas      asection *ignore_input_section;
642159047fSniklas      bfd *ignore_bfd;
652159047fSniklas {
662159047fSniklas   long relocation = 0;
672159047fSniklas   bfd_vma addr = reloc_entry->address;
682159047fSniklas   long x = bfd_get_8 (abfd, (bfd_byte *)data + addr);
692159047fSniklas 
702159047fSniklas   HOWTO_PREPARE(relocation, symbol_in);
712159047fSniklas 
722159047fSniklas   x = (x + relocation + reloc_entry->addend);
732159047fSniklas 
742159047fSniklas   bfd_put_8 (abfd, x, (bfd_byte *)data + addr);
752159047fSniklas   return bfd_reloc_ok;
762159047fSniklas }
772159047fSniklas 
782159047fSniklas static bfd_reloc_status_type
792159047fSniklas howto8_FFnn_callback (abfd, reloc_entry, symbol_in, data,
802159047fSniklas 		      ignore_input_section, ignore_bfd)
812159047fSniklas      bfd *abfd;
822159047fSniklas      arelent *reloc_entry;
83*007c2a45Smiod      struct bfd_symbol *symbol_in;
842159047fSniklas      PTR data;
852159047fSniklas      asection *ignore_input_section;
862159047fSniklas      bfd *ignore_bfd;
872159047fSniklas {
882159047fSniklas   long relocation = 0;
892159047fSniklas   bfd_vma addr = reloc_entry->address;
902159047fSniklas 
912159047fSniklas   long x = bfd_get_8 (abfd, (bfd_byte *)data + addr);
922159047fSniklas   abort ();
932159047fSniklas   HOWTO_PREPARE(relocation, symbol_in);
942159047fSniklas 
952159047fSniklas   x = (x + relocation + reloc_entry->addend);
962159047fSniklas 
972159047fSniklas   bfd_put_8 (abfd, x, (bfd_byte *)data + addr);
982159047fSniklas   return bfd_reloc_ok;
992159047fSniklas }
1002159047fSniklas 
1012159047fSniklas static bfd_reloc_status_type
1022159047fSniklas howto8_pcrel_callback (abfd, reloc_entry, symbol_in, data,
1032159047fSniklas 		       ignore_input_section, ignore_bfd)
1042159047fSniklas      bfd *abfd;
1052159047fSniklas      arelent *reloc_entry;
106*007c2a45Smiod      struct bfd_symbol *symbol_in;
1072159047fSniklas      PTR data;
1082159047fSniklas      asection *ignore_input_section;
1092159047fSniklas      bfd *ignore_bfd;
1102159047fSniklas {
1112159047fSniklas   long relocation = 0;
1122159047fSniklas   bfd_vma addr = reloc_entry->address;
1132159047fSniklas   long x = bfd_get_8 (abfd, (bfd_byte *)data + addr);
1142159047fSniklas   abort ();
1152159047fSniklas   HOWTO_PREPARE(relocation, symbol_in);
1162159047fSniklas 
1172159047fSniklas   x = (x + relocation + reloc_entry->addend);
1182159047fSniklas 
1192159047fSniklas   bfd_put_8 (abfd, x, (bfd_byte *)data + addr);
1202159047fSniklas   return bfd_reloc_ok;
1212159047fSniklas }
1222159047fSniklas 
1232159047fSniklas static reloc_howto_type howto_16
124c074d1c9Sdrahn   = NEWHOWTO (howto16_callback, "abs16", 1, FALSE, FALSE);
1252159047fSniklas static reloc_howto_type howto_8
126c074d1c9Sdrahn   = NEWHOWTO (howto8_callback, "abs8", 0, FALSE, FALSE);
1272159047fSniklas 
1282159047fSniklas static reloc_howto_type howto_8_FFnn
129c074d1c9Sdrahn   = NEWHOWTO (howto8_FFnn_callback, "ff00+abs8", 0, FALSE, FALSE);
1302159047fSniklas 
1312159047fSniklas static reloc_howto_type howto_8_pcrel
132c074d1c9Sdrahn   = NEWHOWTO (howto8_pcrel_callback, "pcrel8", 0, FALSE, TRUE);
1332159047fSniklas 
1342159047fSniklas static reloc_howto_type *
1352159047fSniklas local_bfd_reloc_type_lookup (arch, code)
1362159047fSniklas      const struct bfd_arch_info *arch;
1372159047fSniklas      bfd_reloc_code_real_type code;
1382159047fSniklas {
1392159047fSniklas   switch (code) {
1402159047fSniklas   case BFD_RELOC_16:
1412159047fSniklas     return &howto_16;
1422159047fSniklas   case BFD_RELOC_8_FFnn:
1432159047fSniklas     return &howto_8_FFnn;
1442159047fSniklas   case BFD_RELOC_8:
1452159047fSniklas     return &howto_8;
1462159047fSniklas   case BFD_RELOC_8_PCREL:
1472159047fSniklas     return &howto_8_pcrel;
1482159047fSniklas   }
1492159047fSniklas   return (reloc_howto_type *)NULL;
1502159047fSniklas }
1512159047fSniklas #endif
1522159047fSniklas 
153c074d1c9Sdrahn static bfd_boolean
scan_mach(info,string)1542159047fSniklas scan_mach (info, string)
155f7cc78ecSespie      const struct bfd_arch_info *info ATTRIBUTE_UNUSED;
1562159047fSniklas      const char *string;
1572159047fSniklas {
158c074d1c9Sdrahn   if (strcmp (string,"h8/500") == 0)
159c074d1c9Sdrahn     return TRUE;
160c074d1c9Sdrahn   if (strcmp (string,"H8/500") == 0)
161c074d1c9Sdrahn     return TRUE;
162c074d1c9Sdrahn   if (strcmp (string,"h8500") == 0)
163c074d1c9Sdrahn     return TRUE;
164c074d1c9Sdrahn   if (strcmp (string,"H8500") == 0)
165c074d1c9Sdrahn     return TRUE;
166c074d1c9Sdrahn   return FALSE;
1672159047fSniklas }
1682159047fSniklas 
1692159047fSniklas #if 0 /* not used currently */
1702159047fSniklas /* This routine is provided two arch_infos and returns whether
1712159047fSniklas    they'd be compatible */
1722159047fSniklas 
1732159047fSniklas static const bfd_arch_info_type *
1742159047fSniklas compatible (a,b)
1752159047fSniklas      const bfd_arch_info_type *a;
1762159047fSniklas      const bfd_arch_info_type *b;
1772159047fSniklas {
1782159047fSniklas   if (a->arch != b->arch || a->mach != b->mach)
1792159047fSniklas    return NULL;
1802159047fSniklas   return a;
1812159047fSniklas }
1822159047fSniklas #endif
1832159047fSniklas 
1842159047fSniklas const bfd_arch_info_type bfd_h8500_arch =
1852159047fSniklas {
1862159047fSniklas   16,				/* 16 bits in a word */
1872159047fSniklas   24,				/* 24 bits in an address */
1882159047fSniklas   8,				/* 8 bits in a byte */
1892159047fSniklas   bfd_arch_h8500,
1902159047fSniklas   0,				/* only 1 machine */
1912159047fSniklas   "h8500",			/* arch_name  */
1922159047fSniklas   "h8500",			/* printable name */
1932159047fSniklas   1,
194c074d1c9Sdrahn   TRUE,				/* the default machine */
1952159047fSniklas   bfd_default_compatible,
1962159047fSniklas   scan_mach,
1972159047fSniklas   0,
1982159047fSniklas };
199