From: Nick Clifton Date: Thu, 16 Apr 2009 15:39:48 +0000 (+0000) Subject: Add new binutils target: moxie X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=20135e4cea8994900955e560910b2e675881fa95;p=binutils-gdb.git Add new binutils target: moxie --- diff --git a/ChangeLog b/ChangeLog index 7aba867ebdc..3ae61a1cd09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-15 Anthony Green + + * configure.ac: Ditto. + * configure: Rebuilt. + 2009-04-09 Kaveh R. Ghazi * configure.ac: Bump minimum GMP/MPFR versions to 4.2 and 2.3.1. diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6e4b535fb0a..0917e65159f 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2009-04-15 Anthony Green + + * targets.c: Add moxie support. + * Makefile.am: Ditto. + * Makefile.in: Rebuilt. + * cpu-moxie.c, elf32-moxie.c: New files. + * archures.c: Add moxie support. + * configure.in: Add moxie support. + * configure: Rebuilt. + * config.bfd, archures.c: Add moxie support. + * bfd-in2.h: Rebuilt. + 2009-04-15 Christophe Lyon * elf32-arm.c (elf32_arm_final_link_relocate): Don't convert ARM diff --git a/bfd/Makefile.am b/bfd/Makefile.am index c55450ea1c8..683599ada7d 100644 --- a/bfd/Makefile.am +++ b/bfd/Makefile.am @@ -74,6 +74,7 @@ ALL_MACHINES = \ cpu-dlx.lo \ cpu-fr30.lo \ cpu-frv.lo \ + cpu-moxie.lo \ cpu-h8300.lo \ cpu-h8500.lo \ cpu-hppa.lo \ @@ -141,6 +142,7 @@ ALL_MACHINES_CFILES = \ cpu-dlx.c \ cpu-fr30.c \ cpu-frv.c \ + cpu-moxie.c \ cpu-h8300.c \ cpu-h8500.c \ cpu-hppa.c \ @@ -258,6 +260,7 @@ BFD32_BACKENDS = \ elf32-dlx.lo \ elf32-fr30.lo \ elf32-frv.lo \ + elf32-moxie.lo \ elf32-gen.lo \ elf32-h8300.lo \ elf32-hppa.lo \ @@ -440,6 +443,7 @@ BFD32_BACKENDS_CFILES = \ elf32-dlx.c \ elf32-fr30.c \ elf32-frv.c \ + elf32-moxie.c \ elf32-gen.c \ elf32-h8300.c \ elf32-hppa.c \ @@ -1119,6 +1123,7 @@ cpu-d30v.lo: cpu-d30v.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-dlx.lo: cpu-dlx.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-fr30.lo: cpu-fr30.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-frv.lo: cpu-frv.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h +cpu-moxie.lo: cpu-moxie.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-h8300.lo: cpu-h8300.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-h8500.lo: cpu-h8500.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-hppa.lo: cpu-hppa.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h @@ -1421,6 +1426,11 @@ elf32-frv.lo: elf32-frv.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/frv.h \ $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/dwarf2.h \ elf32-target.h +elf32-moxie.lo: elf32-moxie.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ + elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h \ + $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/moxie.h \ + $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/dwarf2.h \ + elf32-target.h elf32-gen.lo: elf32-gen.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h \ $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h elf32-target.h diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 190888e5309..24c8ee16b03 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -340,6 +340,7 @@ ALL_MACHINES = \ cpu-dlx.lo \ cpu-fr30.lo \ cpu-frv.lo \ + cpu-moxie.lo \ cpu-h8300.lo \ cpu-h8500.lo \ cpu-hppa.lo \ @@ -407,6 +408,7 @@ ALL_MACHINES_CFILES = \ cpu-dlx.c \ cpu-fr30.c \ cpu-frv.c \ + cpu-moxie.c \ cpu-h8300.c \ cpu-h8500.c \ cpu-hppa.c \ @@ -525,6 +527,7 @@ BFD32_BACKENDS = \ elf32-dlx.lo \ elf32-fr30.lo \ elf32-frv.lo \ + elf32-moxie.lo \ elf32-gen.lo \ elf32-h8300.lo \ elf32-hppa.lo \ @@ -707,6 +710,7 @@ BFD32_BACKENDS_CFILES = \ elf32-dlx.c \ elf32-fr30.c \ elf32-frv.c \ + elf32-moxie.c \ elf32-gen.c \ elf32-h8300.c \ elf32-hppa.c \ @@ -1716,6 +1720,7 @@ cpu-d30v.lo: cpu-d30v.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-dlx.lo: cpu-dlx.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-fr30.lo: cpu-fr30.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-frv.lo: cpu-frv.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h +cpu-moxie.lo: cpu-moxie.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-h8300.lo: cpu-h8300.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-h8500.lo: cpu-h8500.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-hppa.lo: cpu-hppa.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h @@ -2018,6 +2023,11 @@ elf32-frv.lo: elf32-frv.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/frv.h \ $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/dwarf2.h \ elf32-target.h +elf32-moxie.lo: elf32-moxie.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ + elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h \ + $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/moxie.h \ + $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/dwarf2.h \ + elf32-target.h elf32-gen.lo: elf32-gen.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h \ $(INCDIR)/elf/internal.h $(INCDIR)/bfdlink.h elf32-target.h diff --git a/bfd/archures.c b/bfd/archures.c index b0bf14078a3..0a785423cfd 100644 --- a/bfd/archures.c +++ b/bfd/archures.c @@ -331,6 +331,8 @@ DESCRIPTION .#define bfd_mach_frvtomcat 499 {* fr500 prototype *} .#define bfd_mach_fr500 500 .#define bfd_mach_fr550 550 +. bfd_arch_moxie, {* The moxie processor *} +.#define bfd_mach_moxie 1 . bfd_arch_mcore, . bfd_arch_mep, .#define bfd_mach_mep 1 @@ -467,6 +469,7 @@ extern const bfd_arch_info_type bfd_d30v_arch; extern const bfd_arch_info_type bfd_dlx_arch; extern const bfd_arch_info_type bfd_fr30_arch; extern const bfd_arch_info_type bfd_frv_arch; +extern const bfd_arch_info_type bfd_moxie_arch; extern const bfd_arch_info_type bfd_h8300_arch; extern const bfd_arch_info_type bfd_h8500_arch; extern const bfd_arch_info_type bfd_hppa_arch; @@ -539,6 +542,7 @@ static const bfd_arch_info_type * const bfd_archures_list[] = &bfd_dlx_arch, &bfd_fr30_arch, &bfd_frv_arch, + &bfd_moxie_arch, &bfd_h8300_arch, &bfd_h8500_arch, &bfd_hppa_arch, diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 6629ed79852..bb2cbc3c061 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1968,6 +1968,8 @@ enum bfd_architecture #define bfd_mach_frvtomcat 499 /* fr500 prototype */ #define bfd_mach_fr500 500 #define bfd_mach_fr550 550 + bfd_arch_moxie, /* The moxie. */ +#define bfd_mach_moxie 1 bfd_arch_mcore, bfd_arch_mep, #define bfd_mach_mep 1 diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 4f53e470e42..35c6f707582 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -944,7 +944,8 @@ handle_COMDAT (bfd * abfd, but there's some checking we can do to be sure. */ - if (! (isym.n_sclass == C_STAT + if (! ((isym.n_sclass == C_STAT + || isym.n_sclass == C_EXT) && isym.n_type == T_NULL && isym.n_value == 0)) abort (); @@ -954,7 +955,7 @@ handle_COMDAT (bfd * abfd, names like .text$foo__Fv (in the case of a function). See comment above for more. */ - if (strcmp (name, symname) != 0) + if (isym.n_sclass == C_STAT && strcmp (name, symname) != 0) _bfd_error_handler (_("%B: warning: COMDAT symbol '%s' does not match section name '%s'"), abfd, symname, name); diff --git a/bfd/config.bfd b/bfd/config.bfd index 90826583925..9e9e021c15a 100644 --- a/bfd/config.bfd +++ b/bfd/config.bfd @@ -413,6 +413,10 @@ case "${targ}" in targ_selvecs=bfd_elf32_frv_vec ;; + moxie-*-elf) + targ_defvec=bfd_elf32_moxie_vec + ;; + h8300*-*-rtemscoff*) targ_defvec=h8300coff_vec targ_underscore=yes diff --git a/bfd/configure b/bfd/configure index 288137bcb5f..41520b24fb7 100755 --- a/bfd/configure +++ b/bfd/configure @@ -20969,6 +20969,7 @@ do bfd_elf32_fr30_vec) tb="$tb elf32-fr30.lo elf32.lo $elf" ;; bfd_elf32_frv_vec) tb="$tb elf32-frv.lo elf32.lo $elf" ;; bfd_elf32_frvfdpic_vec) tb="$tb elf32-frv.lo elf32.lo $elf" ;; + bfd_elf32_moxie_vec) tb="$tb elf32-moxie.lo elf32.lo $elf" ;; bfd_elf32_h8300_vec) tb="$tb elf32-h8300.lo elf32.lo $elf" ;; bfd_elf32_hppa_linux_vec) tb="$tb elf32-hppa.lo elf32.lo $elf" ;; bfd_elf32_hppa_nbsd_vec) tb="$tb elf32-hppa.lo elf32.lo $elf" ;; diff --git a/bfd/configure.in b/bfd/configure.in index 5704a0d4efb..868730aa40f 100644 --- a/bfd/configure.in +++ b/bfd/configure.in @@ -690,6 +690,7 @@ do bfd_elf32_fr30_vec) tb="$tb elf32-fr30.lo elf32.lo $elf" ;; bfd_elf32_frv_vec) tb="$tb elf32-frv.lo elf32.lo $elf" ;; bfd_elf32_frvfdpic_vec) tb="$tb elf32-frv.lo elf32.lo $elf" ;; + bfd_elf32_moxie_vec) tb="$tb elf32-moxie.lo elf32.lo $elf" ;; bfd_elf32_h8300_vec) tb="$tb elf32-h8300.lo elf32.lo $elf" ;; bfd_elf32_hppa_linux_vec) tb="$tb elf32-hppa.lo elf32.lo $elf" ;; bfd_elf32_hppa_nbsd_vec) tb="$tb elf32-hppa.lo elf32.lo $elf" ;; diff --git a/bfd/cpu-moxie.c b/bfd/cpu-moxie.c new file mode 100644 index 00000000000..39debbc09c2 --- /dev/null +++ b/bfd/cpu-moxie.c @@ -0,0 +1,40 @@ +/* BFD support for the moxie processor. + Copyright 2009 Free Software Foundation, Inc. + Written by Anthony Green + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "sysdep.h" +#include "bfd.h" +#include "libbfd.h" + + +const bfd_arch_info_type bfd_moxie_arch = + { + 32, /* 32 bits in a word. */ + 32, /* 32 bits in an address. */ + 8, /* 8 bits in a byte. */ + bfd_arch_moxie, /* enum bfd_architecture arch. */ + bfd_mach_moxie, + "moxie", /* Arch name. */ + "moxie", /* Printable name. */ + 2, /* Unsigned int section alignment power. */ + TRUE, /* The one and only. */ + bfd_default_compatible, + bfd_default_scan , + 0, + }; diff --git a/bfd/elf32-moxie.c b/bfd/elf32-moxie.c new file mode 100644 index 00000000000..e3f01d2e8ca --- /dev/null +++ b/bfd/elf32-moxie.c @@ -0,0 +1,378 @@ +/* moxie-specific support for 32-bit ELF. + Copyright 2008 Anthony Green. + Copyright 2009 Free Software Foundation, Inc. + + Copied from elf32-fr30.c which is.. + Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Free Software Foundation, Inc. + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include "sysdep.h" +#include "bfd.h" +#include "libbfd.h" +#include "elf-bfd.h" +#include "elf/moxie.h" + +/* Forward declarations. */ + +static reloc_howto_type moxie_elf_howto_table [] = +{ + /* This reloc does nothing. */ + HOWTO (R_MOXIE_NONE, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_MOXIE_NONE", /* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + 0, /* dst_mask */ + FALSE), /* pcrel_offset */ + + /* A 32 bit absolute relocation. */ + HOWTO (R_MOXIE_32, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_MOXIE_32", /* name */ + FALSE, /* partial_inplace */ + 0x00000000, /* src_mask */ + 0xffffffff, /* dst_mask */ + FALSE), /* pcrel_offset */ +}; + +/* Map BFD reloc types to MOXIE ELF reloc types. */ + +struct moxie_reloc_map +{ + bfd_reloc_code_real_type bfd_reloc_val; + unsigned int moxie_reloc_val; +}; + +static const struct moxie_reloc_map moxie_reloc_map [] = +{ + { BFD_RELOC_NONE, R_MOXIE_NONE }, + { BFD_RELOC_32, R_MOXIE_32 }, +}; + +static reloc_howto_type * +moxie_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, + bfd_reloc_code_real_type code) +{ + unsigned int i; + + for (i = sizeof (moxie_reloc_map) / sizeof (moxie_reloc_map[0]); + --i;) + if (moxie_reloc_map [i].bfd_reloc_val == code) + return & moxie_elf_howto_table [moxie_reloc_map[i].moxie_reloc_val]; + + return NULL; +} + +static reloc_howto_type * +moxie_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) +{ + unsigned int i; + + for (i = 0; + i < sizeof (moxie_elf_howto_table) / sizeof (moxie_elf_howto_table[0]); + i++) + if (moxie_elf_howto_table[i].name != NULL + && strcasecmp (moxie_elf_howto_table[i].name, r_name) == 0) + return &moxie_elf_howto_table[i]; + + return NULL; +} + +/* Set the howto pointer for an MOXIE ELF reloc. */ + +static void +moxie_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, + arelent *cache_ptr, + Elf_Internal_Rela *dst) +{ + unsigned int r_type; + + r_type = ELF32_R_TYPE (dst->r_info); + BFD_ASSERT (r_type < (unsigned int) R_MOXIE_max); + cache_ptr->howto = & moxie_elf_howto_table [r_type]; +} + +/* Perform a single relocation. By default we use the standard BFD + routines, but a few relocs, we have to do them ourselves. */ + +static bfd_reloc_status_type +moxie_final_link_relocate (reloc_howto_type *howto, + bfd *input_bfd, + asection *input_section, + bfd_byte *contents, + Elf_Internal_Rela *rel, + bfd_vma relocation) +{ + bfd_reloc_status_type r = bfd_reloc_ok; + + switch (howto->type) + { + default: + r = _bfd_final_link_relocate (howto, input_bfd, input_section, + contents, rel->r_offset, + relocation, rel->r_addend); + } + + return r; +} + +/* Relocate an MOXIE ELF section. + + The RELOCATE_SECTION function is called by the new ELF backend linker + to handle the relocations for a section. + + The relocs are always passed as Rela structures; if the section + actually uses Rel structures, the r_addend field will always be + zero. + + This function is responsible for adjusting the section contents as + necessary, and (if using Rela relocs and generating a relocatable + output file) adjusting the reloc addend as necessary. + + This function does not have to worry about setting the reloc + address or the reloc symbol index. + + LOCAL_SYMS is a pointer to the swapped in local symbols. + + LOCAL_SECTIONS is an array giving the section in the input file + corresponding to the st_shndx field of each local symbol. + + The global hash table entry for the global symbols can be found + via elf_sym_hashes (input_bfd). + + When generating relocatable output, this function must handle + STB_LOCAL/STT_SECTION symbols specially. The output symbol is + going to be the section symbol corresponding to the output + section, which means that the addend must be adjusted + accordingly. */ + +static bfd_boolean +moxie_elf_relocate_section (bfd *output_bfd, + struct bfd_link_info *info, + bfd *input_bfd, + asection *input_section, + bfd_byte *contents, + Elf_Internal_Rela *relocs, + Elf_Internal_Sym *local_syms, + asection **local_sections) +{ + Elf_Internal_Shdr *symtab_hdr; + struct elf_link_hash_entry **sym_hashes; + Elf_Internal_Rela *rel; + Elf_Internal_Rela *relend; + + symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; + sym_hashes = elf_sym_hashes (input_bfd); + relend = relocs + input_section->reloc_count; + + for (rel = relocs; rel < relend; rel ++) + { + reloc_howto_type *howto; + unsigned long r_symndx; + Elf_Internal_Sym *sym; + asection *sec; + struct elf_link_hash_entry *h; + bfd_vma relocation; + bfd_reloc_status_type r; + const char *name; + int r_type; + + r_type = ELF32_R_TYPE (rel->r_info); + + r_symndx = ELF32_R_SYM (rel->r_info); + + howto = moxie_elf_howto_table + ELF32_R_TYPE (rel->r_info); + h = NULL; + sym = NULL; + sec = NULL; + + if (r_symndx < symtab_hdr->sh_info) + { + sym = local_syms + r_symndx; + sec = local_sections [r_symndx]; + relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); + + name = bfd_elf_string_from_elf_section + (input_bfd, symtab_hdr->sh_link, sym->st_name); + name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; + } + else + { + bfd_boolean unresolved_reloc, warned; + + RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, + r_symndx, symtab_hdr, sym_hashes, + h, sec, relocation, + unresolved_reloc, warned); + + name = h->root.root.string; + } + + if (sec != NULL && elf_discarded_section (sec)) + { + /* For relocs against symbols from removed linkonce sections, + or sections discarded by a linker script, we just want the + section contents zeroed. Avoid any special processing. */ + _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); + rel->r_info = 0; + rel->r_addend = 0; + continue; + } + + if (info->relocatable) + continue; + + r = moxie_final_link_relocate (howto, input_bfd, input_section, + contents, rel, relocation); + + if (r != bfd_reloc_ok) + { + const char * msg = NULL; + + switch (r) + { + case bfd_reloc_overflow: + r = info->callbacks->reloc_overflow + (info, (h ? &h->root : NULL), name, howto->name, + (bfd_vma) 0, input_bfd, input_section, rel->r_offset); + break; + + case bfd_reloc_undefined: + r = info->callbacks->undefined_symbol + (info, name, input_bfd, input_section, rel->r_offset, + TRUE); + break; + + case bfd_reloc_outofrange: + msg = _("internal error: out of range error"); + break; + + case bfd_reloc_notsupported: + msg = _("internal error: unsupported relocation error"); + break; + + case bfd_reloc_dangerous: + msg = _("internal error: dangerous relocation"); + break; + + default: + msg = _("internal error: unknown error"); + break; + } + + if (msg) + r = info->callbacks->warning + (info, msg, name, input_bfd, input_section, rel->r_offset); + + if (! r) + return FALSE; + } + } + + return TRUE; +} + +/* Return the section that should be marked against GC for a given + relocation. */ + +static asection * +moxie_elf_gc_mark_hook (asection *sec, + struct bfd_link_info *info, + Elf_Internal_Rela *rel, + struct elf_link_hash_entry *h, + Elf_Internal_Sym *sym) +{ + return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); +} + +/* Look through the relocs for a section during the first phase. + Since we don't do .gots or .plts, we just need to consider the + virtual table relocs for gc. */ + +static bfd_boolean +moxie_elf_check_relocs (bfd *abfd, + struct bfd_link_info *info, + asection *sec, + const Elf_Internal_Rela *relocs) +{ + Elf_Internal_Shdr *symtab_hdr; + struct elf_link_hash_entry **sym_hashes; + const Elf_Internal_Rela *rel; + const Elf_Internal_Rela *rel_end; + + if (info->relocatable) + return TRUE; + + symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + sym_hashes = elf_sym_hashes (abfd); + + rel_end = relocs + sec->reloc_count; + for (rel = relocs; rel < rel_end; rel++) + { + struct elf_link_hash_entry *h; + unsigned long r_symndx; + + r_symndx = ELF32_R_SYM (rel->r_info); + if (r_symndx < symtab_hdr->sh_info) + h = NULL; + else + { + h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + while (h->root.type == bfd_link_hash_indirect + || h->root.type == bfd_link_hash_warning) + h = (struct elf_link_hash_entry *) h->root.u.i.link; + } + } + + return TRUE; +} + +#define ELF_ARCH bfd_arch_moxie +#define ELF_MACHINE_CODE EM_MOXIE +#define ELF_MAXPAGESIZE 0x1 + +#define TARGET_BIG_SYM bfd_elf32_moxie_vec +#define TARGET_BIG_NAME "elf32-moxie" + +#define elf_info_to_howto_rel NULL +#define elf_info_to_howto moxie_info_to_howto_rela +#define elf_backend_relocate_section moxie_elf_relocate_section +#define elf_backend_gc_mark_hook moxie_elf_gc_mark_hook +#define elf_backend_check_relocs moxie_elf_check_relocs + +#define elf_backend_can_gc_sections 1 +#define elf_backend_rela_normal 1 + +#define bfd_elf32_bfd_reloc_type_lookup moxie_reloc_type_lookup +#define bfd_elf32_bfd_reloc_name_lookup moxie_reloc_name_lookup + +#include "elf32-target.h" diff --git a/bfd/targets.c b/bfd/targets.c index aef9c29b78c..a52b37d4428 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -589,6 +589,7 @@ extern const bfd_target bfd_elf32_dlx_big_vec; extern const bfd_target bfd_elf32_fr30_vec; extern const bfd_target bfd_elf32_frv_vec; extern const bfd_target bfd_elf32_frvfdpic_vec; +extern const bfd_target bfd_elf32_moxie_vec; extern const bfd_target bfd_elf32_h8300_vec; extern const bfd_target bfd_elf32_hppa_linux_vec; extern const bfd_target bfd_elf32_hppa_nbsd_vec; @@ -923,6 +924,7 @@ static const bfd_target * const _bfd_target_vector[] = &bfd_elf32_fr30_vec, &bfd_elf32_frv_vec, &bfd_elf32_frvfdpic_vec, + &bfd_elf32_moxie_vec, &bfd_elf32_h8300_vec, &bfd_elf32_hppa_linux_vec, &bfd_elf32_hppa_nbsd_vec, diff --git a/binutils/ChangeLog b/binutils/ChangeLog index d8b033081d0..4f755b972fa 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,7 @@ +2009-04-15 Anthony Green + + * MAINTAINERS: Add myself and Moxie port maintainer. + 2009-04-14 Dave Korn * objcopy.c (enum long_section_name_handling): New enum type. diff --git a/binutils/MAINTAINERS b/binutils/MAINTAINERS index c5cd2071152..57a11a67d45 100644 --- a/binutils/MAINTAINERS +++ b/binutils/MAINTAINERS @@ -92,6 +92,7 @@ responsibility among the other maintainers. MAXQ Inderpreet Singh MEP Dave Brolley MIPS Eric Christopher + Moxie Anthony Green MMIX Hans-Peter Nilsson MN10300 Eric Christopher MN10300 Alexandre Oliva diff --git a/configure b/configure index bfb1d6b81f8..8559109b63b 100755 --- a/configure +++ b/configure @@ -2,7 +2,7 @@ # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59. # -# Copyright (C) 2003 Free Software Foundation, Inc. +# Copyright (C) 2003, 2008 Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## --------------------- ## @@ -2409,6 +2409,10 @@ case "${target}" in frv-*-*) noconfigdirs="$noconfigdirs ${libgcj}" ;; + moxie-*-*) + noconfigdirs="$noconfigdirs ${libgcj}" + noconfigdirs="$noconfigdirs gprof" + ;; h8300*-*-*) noconfigdirs="$noconfigdirs target-libgloss ${libgcj}" ;; diff --git a/configure.ac b/configure.ac index fd961226481..ee63082d62c 100644 --- a/configure.ac +++ b/configure.ac @@ -644,6 +644,10 @@ case "${target}" in frv-*-*) noconfigdirs="$noconfigdirs ${libgcj}" ;; + moxie-*-*) + noconfigdirs="$noconfigdirs ${libgcj}" + noconfigdirs="$noconfigdirs gprof" + ;; h8300*-*-*) noconfigdirs="$noconfigdirs target-libgloss ${libgcj}" ;; diff --git a/gas/ChangeLog b/gas/ChangeLog index b837c17c2b7..a3442b36c0a 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,10 @@ +2008-04-15 Anthony Green + + * config/tc-moxie.h: New file. + * config/tc-moxie.c: New file. + * configure: Add support for moxie. + * configure.tgt: Add support for moxie. + 2009-04-16 Jan Beulich * expr.c: Include limits.h if available, and #define CHAR_BITS diff --git a/gas/config/tc-moxie.c b/gas/config/tc-moxie.c new file mode 100644 index 00000000000..84563ce555c --- /dev/null +++ b/gas/config/tc-moxie.c @@ -0,0 +1,731 @@ +/* tc-moxie.c -- Assemble code for moxie + Copyright 2009 + Free Software Foundation, Inc. + + This file is part of GAS, the GNU Assembler. + + GAS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GAS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GAS; see the file COPYING. If not, write to + the Free Software Foundation, 51 Franklin Street - Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* Contributed by Anthony Green . */ + +#include "as.h" +#include "safe-ctype.h" +#include "opcode/moxie.h" +#include "elf/moxie.h" + +extern const moxie_opc_info_t moxie_opc_info[128]; + +const char comment_chars[] = "#"; +const char line_separator_chars[] = ";"; +const char line_comment_chars[] = "#"; + +static int pending_reloc; +static struct hash_control *opcode_hash_control; + +const pseudo_typeS md_pseudo_table[] = +{ + {0, 0, 0} +}; + +const char FLT_CHARS[] = "rRsSfFdDxXpP"; +const char EXP_CHARS[] = "eE"; + +void +md_operand (expressionS *op __attribute__((unused))) +{ + /* Empty for now. */ +} + +/* This function is called once, at assembler startup time. It sets + up the hash table with all the opcodes in it, and also initializes + some aliases for compatibility with other assemblers. */ + +void +md_begin (void) +{ + int count; + const moxie_opc_info_t *opcode; + opcode_hash_control = hash_new (); + + /* Insert names into hash table. */ + for (count = 0, opcode = moxie_form1_opc_info; count++ < 64; opcode++) + hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + + for (count = 0, opcode = moxie_form2_opc_info; count++ < 4; opcode++) + hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + + for (count = 0, opcode = moxie_form3_opc_info; count++ < 4; opcode++) + hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + + bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0); +} + +/* Parse an expression and then restore the input line pointer. */ + +static char * +parse_exp_save_ilp (char *s, expressionS *op) +{ + char *save = input_line_pointer; + + input_line_pointer = s; + expression (op); + s = input_line_pointer; + input_line_pointer = save; + return s; +} + +static int +parse_register_operand (char **ptr) +{ + int reg; + char *s = *ptr; + + if (*s != '$') + { + as_bad ("expecting register"); + ignore_rest_of_line (); + return -1; + } + if (s[1] == 'f' && s[2] == 'p') + { + *ptr += 3; + return 0; + } + if (s[1] == 's' && s[2] == 'p') + { + *ptr += 3; + return 1; + } + if (s[1] == 'r') + { + reg = s[2] - '0'; + if ((reg < 0) || (reg > 9)) + { + as_bad ("illegal register number"); + ignore_rest_of_line (); + return -1; + } + if (reg == 1) + { + int r2 = s[3] - '0'; + if ((r2 >= 0) && (r2 <= 3)) + { + reg = 10 + r2; + *ptr += 1; + } + } + } + else + { + as_bad ("illegal register number"); + ignore_rest_of_line (); + return -1; + } + + *ptr += 3; + + return reg + 2; +} + +/* This is the guts of the machine-dependent assembler. STR points to + a machine dependent instruction. This function is supposed to emit + the frags/bytes it assembles to. */ + +void +md_assemble (char *str) +{ + char *op_start; + char *op_end; + + moxie_opc_info_t *opcode; + char *p; + char pend; + + unsigned short iword = 0; + + int nlen = 0; + + /* Drop leading whitespace. */ + while (*str == ' ') + str++; + + /* Find the op code end. */ + op_start = str; + for (op_end = str; + *op_end && !is_end_of_line[*op_end & 0xff] && *op_end != ' '; + op_end++) + nlen++; + + pend = *op_end; + *op_end = 0; + + if (nlen == 0) + as_bad (_("can't find opcode ")); + opcode = (moxie_opc_info_t *) hash_find (opcode_hash_control, op_start); + *op_end = pend; + + if (opcode == NULL) + { + as_bad (_("unknown opcode %s"), op_start); + return; + } + + p = frag_more (2); + + switch (opcode->itype) + { + case MOXIE_F2_A8V: + iword = (1<<15) | (opcode->opcode << 12); + while (ISSPACE (*op_end)) + op_end++; + { + expressionS arg; + int reg; + reg = parse_register_operand (&op_end); + iword += (reg << 8); + if (*op_end != ',') + as_warn ("expecting comma delimeted register operands"); + op_end++; + op_end = parse_exp_save_ilp (op_end, &arg); + fix_new_exp (frag_now, + ((p+1) - frag_now->fr_literal), + 1, + &arg, + 0, + BFD_RELOC_8); + } + break; + case MOXIE_F1_AB: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + int dest, src; + dest = parse_register_operand (&op_end); + if (*op_end != ',') + as_warn ("expecting comma delimeted register operands"); + op_end++; + src = parse_register_operand (&op_end); + iword += (dest << 4) + src; + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + } + break; + case MOXIE_F1_A4: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + expressionS arg; + char *where; + int regnum; + + regnum = parse_register_operand (&op_end); + while (ISSPACE (*op_end)) + op_end++; + + iword += (regnum << 4); + + if (*op_end != ',') + { + as_bad ("expecting comma delimited operands"); + ignore_rest_of_line (); + return; + } + op_end++; + + op_end = parse_exp_save_ilp (op_end, &arg); + where = frag_more (4); + fix_new_exp (frag_now, + (where - frag_now->fr_literal), + 4, + &arg, + 0, + BFD_RELOC_32); + } + break; + case MOXIE_F1_4: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + expressionS arg; + char *where; + + op_end = parse_exp_save_ilp (op_end, &arg); + where = frag_more (4); + fix_new_exp (frag_now, + (where - frag_now->fr_literal), + 4, + &arg, + 0, + BFD_RELOC_32); + } + break; + case MOXIE_F1_NARG: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + break; + case MOXIE_F1_A: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + int reg; + reg = parse_register_operand (&op_end); + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + iword += (reg << 4); + } + break; + case MOXIE_F1_ABi: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + int a, b; + a = parse_register_operand (&op_end); + if (*op_end != ',') + as_warn ("expecting comma delimeted register operands"); + op_end++; + if (*op_end != '(') + { + as_bad ("expecting indirect register `($rA)'"); + ignore_rest_of_line (); + return; + } + op_end++; + b = parse_register_operand (&op_end); + if (*op_end != ')') + { + as_bad ("missing closing parenthesis"); + ignore_rest_of_line (); + return; + } + op_end++; + iword += (a << 4) + b; + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + } + break; + case MOXIE_F1_AiB: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + int a, b; + if (*op_end != '(') + { + as_bad ("expecting indirect register `($rA)'"); + ignore_rest_of_line (); + return; + } + op_end++; + a = parse_register_operand (&op_end); + if (*op_end != ')') + { + as_bad ("missing closing parenthesis"); + ignore_rest_of_line (); + return; + } + op_end++; + if (*op_end != ',') + as_warn ("expecting comma delimeted register operands"); + op_end++; + b = parse_register_operand (&op_end); + iword += (a << 4) + b; + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + } + break; + case MOXIE_F1_4A: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + expressionS arg; + char *where; + int a; + + op_end = parse_exp_save_ilp (op_end, &arg); + where = frag_more (4); + fix_new_exp (frag_now, + (where - frag_now->fr_literal), + 4, + &arg, + 0, + BFD_RELOC_32); + + if (*op_end != ',') + { + as_bad ("expecting comma delimited operands"); + ignore_rest_of_line (); + return; + } + op_end++; + + a = parse_register_operand (&op_end); + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + + iword += (a << 4); + } + break; + case MOXIE_F1_ABi4: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + expressionS arg; + char *offset; + int a, b; + + a = parse_register_operand (&op_end); + while (ISSPACE (*op_end)) + op_end++; + + if (*op_end != ',') + { + as_bad ("expecting comma delimited operands"); + ignore_rest_of_line (); + return; + } + op_end++; + + op_end = parse_exp_save_ilp (op_end, &arg); + offset = frag_more (4); + fix_new_exp (frag_now, + (offset - frag_now->fr_literal), + 4, + &arg, + 0, + BFD_RELOC_32); + + if (*op_end != '(') + { + as_bad ("expecting indirect register `($rX)'"); + ignore_rest_of_line (); + return; + } + op_end++; + b = parse_register_operand (&op_end); + if (*op_end != ')') + { + as_bad ("missing closing parenthesis"); + ignore_rest_of_line (); + return; + } + op_end++; + + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + + iword += (a << 4) + b; + } + break; + case MOXIE_F1_AiB4: + iword = opcode->opcode << 8; + while (ISSPACE (*op_end)) + op_end++; + { + expressionS arg; + char *offset; + int a, b; + + op_end = parse_exp_save_ilp (op_end, &arg); + offset = frag_more (4); + fix_new_exp (frag_now, + (offset - frag_now->fr_literal), + 4, + &arg, + 0, + BFD_RELOC_32); + + if (*op_end != '(') + { + as_bad ("expecting indirect register `($rX)'"); + ignore_rest_of_line (); + return; + } + op_end++; + a = parse_register_operand (&op_end); + if (*op_end != ')') + { + as_bad ("missing closing parenthesis"); + ignore_rest_of_line (); + return; + } + op_end++; + + if (*op_end != ',') + { + as_bad ("expecting comma delimited operands"); + ignore_rest_of_line (); + return; + } + op_end++; + + b = parse_register_operand (&op_end); + while (ISSPACE (*op_end)) + op_end++; + + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + + iword += (a << 4) + b; + } + break; + case MOXIE_F2_NARG: + iword = opcode->opcode << 12; + while (ISSPACE (*op_end)) + op_end++; + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + break; + default: + abort(); + } + + md_number_to_chars (p, iword, 2); + + while (ISSPACE (*op_end)) + op_end++; + + if (*op_end != 0) + as_warn ("extra stuff on line ignored"); + + if (pending_reloc) + as_bad ("Something forgot to clean up\n"); +} + +/* Turn a string in input_line_pointer into a floating point constant + of type type, and store the appropriate bytes in *LITP. The number + of LITTLENUMS emitted is stored in *SIZEP . An error message is + returned, or NULL on OK. */ + +char * +md_atof (int type, char *litP, int *sizeP) +{ + int prec; + LITTLENUM_TYPE words[4]; + char *t; + int i; + + switch (type) + { + case 'f': + prec = 2; + break; + + case 'd': + prec = 4; + break; + + default: + *sizeP = 0; + return _("bad call to md_atof"); + } + + t = atof_ieee (input_line_pointer, type, words); + if (t) + input_line_pointer = t; + + *sizeP = prec * 2; + + for (i = prec - 1; i >= 0; i--) + { + md_number_to_chars (litP, (valueT) words[i], 2); + litP += 2; + } + + return NULL; +} + +const char *md_shortopts = ""; + +struct option md_longopts[] = +{ + {NULL, no_argument, NULL, 0} +}; +size_t md_longopts_size = sizeof (md_longopts); + +/* We have no target specific options yet, so these next + two functions are empty. */ +int +md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED) +{ + return 0; +} + +void +md_show_usage (FILE *stream ATTRIBUTE_UNUSED) +{ +} + +/* Apply a fixup to the object file. */ + +void +md_apply_fix (fixS *fixP ATTRIBUTE_UNUSED, valueT * valP ATTRIBUTE_UNUSED, segT seg ATTRIBUTE_UNUSED) +{ + char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; + long val = *valP; + long max, min; + int shift; + + max = min = 0; + shift = 0; + switch (fixP->fx_r_type) + { + case BFD_RELOC_32: + *buf++ = val >> 24; + *buf++ = val >> 16; + *buf++ = val >> 8; + *buf++ = val >> 0; + break; + + case BFD_RELOC_16: + *buf++ = val >> 8; + *buf++ = val >> 0; + break; + + case BFD_RELOC_8: + *buf++ = val; + break; + + default: + abort (); + } + + if (max != 0 && (val < min || val > max)) + as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range")); + + if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) + fixP->fx_done = 1; +} + +/* Put number into target byte order (big endian). */ + +void +md_number_to_chars (char *ptr, valueT use, int nbytes) +{ + number_to_chars_bigendian (ptr, use, nbytes); +} + +/* Generate a machine-dependent relocation. */ +arelent * +tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP) +{ + arelent *relP; + bfd_reloc_code_real_type code; + + switch (fixP->fx_r_type) + { + case BFD_RELOC_32: + code = fixP->fx_r_type; + break; + default: + as_bad_where (fixP->fx_file, fixP->fx_line, + _("Semantics error. This type of operand can not be relocated, it must be an assembly-time constant")); + return 0; + } + + relP = xmalloc (sizeof (arelent)); + assert (relP != 0); + relP->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); + *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy); + relP->address = fixP->fx_frag->fr_address + fixP->fx_where; + + relP->addend = fixP->fx_offset; + + /* This is the standard place for KLUDGEs to work around bugs in + bfd_install_relocation (first such note in the documentation + appears with binutils-2.8). + + That function bfd_install_relocation does the wrong thing with + putting stuff into the addend of a reloc (it should stay out) for a + weak symbol. The really bad thing is that it adds the + "segment-relative offset" of the symbol into the reloc. In this + case, the reloc should instead be relative to the symbol with no + other offset than the assembly code shows; and since the symbol is + weak, any local definition should be ignored until link time (or + thereafter). + To wit: weaksym+42 should be weaksym+42 in the reloc, + not weaksym+(offset_from_segment_of_local_weaksym_definition) + + To "work around" this, we subtract the segment-relative offset of + "known" weak symbols. This evens out the extra offset. + + That happens for a.out but not for ELF, since for ELF, + bfd_install_relocation uses the "special function" field of the + howto, and does not execute the code that needs to be undone. */ + + if (OUTPUT_FLAVOR == bfd_target_aout_flavour + && fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy) + && ! bfd_is_und_section (S_GET_SEGMENT (fixP->fx_addsy))) + { + relP->addend -= S_GET_VALUE (fixP->fx_addsy); + } + + relP->howto = bfd_reloc_type_lookup (stdoutput, code); + if (! relP->howto) + { + const char *name; + + name = S_GET_NAME (fixP->fx_addsy); + if (name == NULL) + name = _(""); + as_fatal (_("Cannot generate relocation type for symbol %s, code %s"), + name, bfd_get_reloc_code_name (code)); + } + + return relP; +} + +/* Decide from what point a pc-relative relocation is relative to, + relative to the pc-relative fixup. Er, relatively speaking. */ +long +md_pcrel_from (fixS *fixP) +{ + valueT addr = fixP->fx_where + fixP->fx_frag->fr_address; + + fprintf (stderr, "md_pcrel_from 0x%d\n", fixP->fx_r_type); + + switch (fixP->fx_r_type) + { + case BFD_RELOC_32: + return addr + 4; + default: + abort (); + return addr; + } +} diff --git a/gas/config/tc-moxie.h b/gas/config/tc-moxie.h new file mode 100644 index 00000000000..db1d01aa8cf --- /dev/null +++ b/gas/config/tc-moxie.h @@ -0,0 +1,47 @@ +/* tc-moxie.h -- Header file for tc-moxie.c. + + Copyright 2009 Free Software Foundation, Inc. + + This file is part of GAS, the GNU Assembler. + + GAS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GAS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with GAS; see the file COPYING. If not, write to the Free Software + Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + +#define TC_MOXIE 1 +#define TARGET_BYTES_BIG_ENDIAN 1 +#define WORKING_DOT_WORD + +/* This macro is the BFD target name to use when creating the output + file. This will normally depend upon the `OBJ_FMT' macro. */ +#define TARGET_FORMAT "elf32-moxie" + +/* This macro is the BFD architecture to pass to `bfd_set_arch_mach'. */ +#define TARGET_ARCH bfd_arch_moxie + +#define md_undefined_symbol(NAME) 0 + +/* These macros must be defined, but is will be a fatal assembler + error if we ever hit them. */ +#define md_estimate_size_before_relax(A, B) (as_fatal (_("estimate size\n")), 0) +#define md_convert_frag(B, S, F) (as_fatal (_("convert_frag\n")), 0) + +/* If you define this macro, it should return the offset between the + address of a PC relative fixup and the position from which the PC + relative adjustment should be made. On many processors, the base + of a PC relative instruction is the next instruction, so this + macro would return the length of an instruction. */ +#define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from (FIX) +extern long md_pcrel_from (struct fix *); + +#define md_section_align(SEGMENT, SIZE) (SIZE) diff --git a/gas/configure.tgt b/gas/configure.tgt index e3eadac3199..9d722ed378f 100644 --- a/gas/configure.tgt +++ b/gas/configure.tgt @@ -148,6 +148,8 @@ case ${generic_target} in frv-*-*linux*) fmt=elf em=linux;; frv-*-*) fmt=elf ;; + moxie-*-*) fmt=elf ;; + hppa-*-linux*) case ${cpu} in hppa*64*) fmt=elf em=hppalinux64 ;; diff --git a/include/dis-asm.h b/include/dis-asm.h index d5d14c6750f..95d141ffa23 100644 --- a/include/dis-asm.h +++ b/include/dis-asm.h @@ -259,6 +259,7 @@ extern int print_insn_mep (bfd_vma, disassemble_info *); extern int print_insn_mmix (bfd_vma, disassemble_info *); extern int print_insn_mn10200 (bfd_vma, disassemble_info *); extern int print_insn_mn10300 (bfd_vma, disassemble_info *); +extern int print_insn_moxie (bfd_vma, disassemble_info *); extern int print_insn_msp430 (bfd_vma, disassemble_info *); extern int print_insn_mt (bfd_vma, disassemble_info *); extern int print_insn_ns32k (bfd_vma, disassemble_info *); diff --git a/include/elf/ChangeLog b/include/elf/ChangeLog index f6e73fd8785..c7dc5e36477 100644 --- a/include/elf/ChangeLog +++ b/include/elf/ChangeLog @@ -1,3 +1,8 @@ +2009-04-15 Anthony Green + + * common.h (EM_MOXIE): Define. + * moxie.h: New file. + 2009-04-07 DJ Delorie * mep.h (EF_MEP_CPU_C5): New. diff --git a/include/elf/common.h b/include/elf/common.h index a669507d392..a343daaf349 100644 --- a/include/elf/common.h +++ b/include/elf/common.h @@ -339,6 +339,8 @@ #define EM_CYGNUS_MEP 0xF00D /* Toshiba MeP */ +#define EM_MOXIE 0xFEED /* Moxie */ + /* Old Sunplus S+core7 backend magic number. Written in the absence of an ABI. */ #define EM_SCORE_OLD 95 diff --git a/include/elf/moxie.h b/include/elf/moxie.h new file mode 100644 index 00000000000..49781a6c1db --- /dev/null +++ b/include/elf/moxie.h @@ -0,0 +1,31 @@ +/* moxie ELF support for BFD. + Copyright 2009 Free Software Foundation, Inc. + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _ELF_MOXIE_H +#define _ELF_MOXIE_H + +#include "elf/reloc-macros.h" + +/* Relocation types. */ +START_RELOC_NUMBERS (elf_moxie_reloc_type) + RELOC_NUMBER (R_MOXIE_NONE, 0) + RELOC_NUMBER (R_MOXIE_32, 1) +END_RELOC_NUMBERS (R_MOXIE_max) + +#endif /* _ELF_MOXIE_H */ diff --git a/include/opcode/ChangeLog b/include/opcode/ChangeLog index ad7bc61a3d4..0985425fbf8 100644 --- a/include/opcode/ChangeLog +++ b/include/opcode/ChangeLog @@ -1,3 +1,7 @@ +2009-04-15 Anthony Green + + * moxie.h: Created. + 2009-04-06 DJ Delorie * h8300.h: Add relaxation attributes to MOVA opcodes. diff --git a/include/opcode/moxie.h b/include/opcode/moxie.h new file mode 100644 index 00000000000..c996fe584e4 --- /dev/null +++ b/include/opcode/moxie.h @@ -0,0 +1,68 @@ +/* Definitions for decoding the moxie opcode table. + Copyright 2009 Free Software Foundation, Inc. + Contributed by Anthony Green (green@moxielogic.com). + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. */ + +/* Form 1 instructions come in different flavors: + + Some have no arguments (MOXIE_F1_NARG) + Some only use the A operand (MOXIE_F1_A) + Some use A and B registers (MOXIE_F1_AB) + Some use A and consume a 4 byte immediate value (MOXIE_F1_A4) + Some use just a 4 byte immediate value (MOXIE_F1_4) + Some use B and an indirect A (MOXIE_F1_AiB) + Some use A and an indirect B (MOXIE_F1_ABi) + Some consume a 4 byte immediate value and use X (MOXIE_F1_4A) + Some use B and an indirect A plus 4 bytes (MOXIE_F1_AiB4) + Some use A and an indirect B plus 4 bytes (MOXIE_F1_ABi4) + + Form 2 instructions also come in different flavors: + + Some have no arguments (MOXIE_F2_NARG) + Some use the A register and an 8-bit value (MOXIE_F2_A8V) + + Form 3 instructions also come in different flavors: + + Some have no arguments (MOXIE_F3_NARG). */ + +#define MOXIE_F1_NARG 0x100 +#define MOXIE_F1_A 0x101 +#define MOXIE_F1_AB 0x102 +/* #define MOXIE_F1_ABC 0x103 */ +#define MOXIE_F1_A4 0x104 +#define MOXIE_F1_4 0x105 +#define MOXIE_F1_AiB 0x106 +#define MOXIE_F1_ABi 0x107 +#define MOXIE_F1_4A 0x108 +#define MOXIE_F1_AiB4 0x109 +#define MOXIE_F1_ABi4 0x10a + +#define MOXIE_F2_NARG 0x200 +#define MOXIE_F2_A8V 0x201 + +#define MOXIE_F3_NARG 0x300 + +typedef struct moxie_opc_info_t +{ + short opcode; + unsigned itype; + const char * name; +} moxie_opc_info_t; + +extern const moxie_opc_info_t moxie_form1_opc_info[64]; +extern const moxie_opc_info_t moxie_form2_opc_info[4]; +extern const moxie_opc_info_t moxie_form3_opc_info[4]; diff --git a/ld/ChangeLog b/ld/ChangeLog index 39e5555c27e..099275dd487 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2009-04-15 Anthony Green + + * configure.tgt: Add moxie support. + * Makefile.am: Add moxie files. + * Makefile.in: Rebuilt. + * emulparams/elf32moxie.sh: New file. + * scripttempl/moxie.sc: New file. + 2009-04-15 Kazu Hirata * ldlang.c: Do not include limits.h. diff --git a/ld/Makefile.am b/ld/Makefile.am index 2d0aed9456c..6a4139a1851 100644 --- a/ld/Makefile.am +++ b/ld/Makefile.am @@ -176,6 +176,7 @@ ALL_EMULATIONS = \ eelf32elmipvxworks.o \ eelf32fr30.o \ eelf32frv.o \ + eelf32moxie.o \ eelf32i370.o \ eelf32ip2k.o \ eelf32iq2000.o \ @@ -727,6 +728,9 @@ eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \ $(srcdir)/emulparams/elf32frv.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32frvfd "$(tdir_frv)" +eelf32moxie.c: $(srcdir)/emulparams/elf32moxie.sh \ + $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} + ${GENSCRIPTS} elf32moxie "$(tdir_moxie)" eelf32mcore.c: $(srcdir)/emulparams/elf32mcore.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32mcore "$(tdir_mcore)" diff --git a/ld/Makefile.in b/ld/Makefile.in index b9a9ccdc01e..ae084a5f137 100644 --- a/ld/Makefile.in +++ b/ld/Makefile.in @@ -441,6 +441,7 @@ ALL_EMULATIONS = \ eelf32elmipvxworks.o \ eelf32fr30.o \ eelf32frv.o \ + eelf32moxie.o \ eelf32i370.o \ eelf32ip2k.o \ eelf32iq2000.o \ @@ -1574,6 +1575,9 @@ eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \ $(srcdir)/emulparams/elf32frv.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32frvfd "$(tdir_frv)" +eelf32moxie.c: $(srcdir)/emulparams/elf32moxie.sh \ + $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} + ${GENSCRIPTS} elf32moxie "$(tdir_moxie)" eelf32mcore.c: $(srcdir)/emulparams/elf32mcore.sh \ $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32mcore "$(tdir_mcore)" diff --git a/ld/configure.tgt b/ld/configure.tgt index 329399f07e7..ebe3f236ff6 100644 --- a/ld/configure.tgt +++ b/ld/configure.tgt @@ -152,6 +152,8 @@ fr30-*-*) targ_emul=elf32fr30 frv-*-*linux*) targ_emul=elf32frvfd ;; frv-*-*) targ_emul=elf32frv ; targ_extra_emuls="elf32frvfd" ;; +moxie-*-*) targ_emul=elf32moxie + ;; h8300-*-hms* | h8300-*-coff* | h8300-*-rtemscoff*) targ_emul=h8300; targ_extra_emuls="h8300h h8300s h8300hn h8300sn h8300sx h8300sxn" ;; h8300-*-elf* | h8300-*-rtems*) diff --git a/ld/emulparams/elf32moxie.sh b/ld/emulparams/elf32moxie.sh new file mode 100644 index 00000000000..2ed270850c2 --- /dev/null +++ b/ld/emulparams/elf32moxie.sh @@ -0,0 +1,8 @@ +SCRIPT_NAME=elf +TEMPLATE_NAME=generic +EXTRA_EM_FILE=genelf +OUTPUT_FORMAT="elf32-moxie" +TEXT_START_ADDR=0x1000 +MAXPAGESIZE="CONSTANT (MAXPAGESIZE)" +ARCH=moxie +STACK_ADDR=0x200000 diff --git a/ld/scripttempl/moxie.sc b/ld/scripttempl/moxie.sc new file mode 100644 index 00000000000..f7d788ff658 --- /dev/null +++ b/ld/scripttempl/moxie.sc @@ -0,0 +1,52 @@ +TORS=".tors : + { + ___ctors = . ; + *(.ctors) + ___ctors_end = . ; + ___dtors = . ; + *(.dtors) + ___dtors_end = . ; + } > ram" + +cat < ram} + ${CONSTRUCTING+${TORS}} + .data : + { + *(.data) + ${RELOCATING+ _edata = . ; } + } ${RELOCATING+ > ram} + .bss : + { + ${RELOCATING+ _bss_start = . ; } + *(.bss) + *(COMMON) + ${RELOCATING+ _end = . ; } + } ${RELOCATING+ > ram} + .stack ${RELOCATING+ 0x30000 } : + { + ${RELOCATING+ _stack = . ; } + *(.stack) + } ${RELOCATING+ > ram} + .stab 0 ${RELOCATING+(NOLOAD)} : + { + *(.stab) + } + .stabstr 0 ${RELOCATING+(NOLOAD)} : + { + *(.stabstr) + } +} +EOF diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index a8f748e2b22..8209771d8b1 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,12 @@ +2009-04-15 Anthony Green + + * moxie-opc.c, moxie-dis.c: Created. + * Makefile.am: Build the moxie source files. + * configure.in: Add moxie support. + * Makefile.in, configure: Rebuilt. + * disassemble.c (disassembler): Add moxie support. + (ARCH_moxie): Define. + 2009-04-15 Jan Beulich * i386-opc.tbl (protb, protw, protd, protq): Set opcode diff --git a/opcodes/Makefile.am b/opcodes/Makefile.am index f6b575019d9..24c92964e75 100644 --- a/opcodes/Makefile.am +++ b/opcodes/Makefile.am @@ -98,6 +98,8 @@ CFILES = \ frv-dis.c \ frv-ibld.c \ frv-opc.c \ + moxie-dis.c \ + moxie-opc.c \ h8300-dis.c \ h8500-dis.c \ hppa-dis.c \ @@ -256,6 +258,8 @@ ALL_MACHINES = \ frv-dis.lo \ frv-ibld.lo \ frv-opc.lo \ + moxie-dis.lo \ + moxie-opc.lo \ h8300-dis.lo \ h8500-dis.lo \ hppa-dis.lo \ @@ -790,6 +794,11 @@ frv-opc.lo: frv-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \ $(BFD_H) $(INCDIR)/symcat.h frv-desc.h $(INCDIR)/opcode/cgen-bitset.h \ $(INCDIR)/opcode/cgen.h frv-opc.h $(INCDIR)/libiberty.h \ $(INCDIR)/elf/frv.h $(INCDIR)/elf/reloc-macros.h +moxie-dis.lo: moxie-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/opcode/moxie.h $(INCDIR)/dis-asm.h $(BFD_H) \ + $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h +moxie-opc.lo: moxie-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/opcode/moxie.h h8300-dis.lo: h8300-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \ $(INCDIR)/opcode/h8300.h $(INCDIR)/dis-asm.h $(BFD_H) \ $(INCDIR)/symcat.h opintl.h $(INCDIR)/libiberty.h diff --git a/opcodes/Makefile.in b/opcodes/Makefile.in index afbaf2d1f38..f0f4a91e334 100644 --- a/opcodes/Makefile.in +++ b/opcodes/Makefile.in @@ -337,6 +337,8 @@ CFILES = \ frv-dis.c \ frv-ibld.c \ frv-opc.c \ + moxie-dis.c \ + moxie-opc.c \ h8300-dis.c \ h8500-dis.c \ hppa-dis.c \ @@ -495,6 +497,8 @@ ALL_MACHINES = \ frv-dis.lo \ frv-ibld.lo \ frv-opc.lo \ + moxie-dis.lo \ + moxie-opc.lo \ h8300-dis.lo \ h8500-dis.lo \ hppa-dis.lo \ @@ -1355,6 +1359,11 @@ frv-opc.lo: frv-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \ $(BFD_H) $(INCDIR)/symcat.h frv-desc.h $(INCDIR)/opcode/cgen-bitset.h \ $(INCDIR)/opcode/cgen.h frv-opc.h $(INCDIR)/libiberty.h \ $(INCDIR)/elf/frv.h $(INCDIR)/elf/reloc-macros.h +moxie-dis.lo: moxie-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/opcode/moxie.h $(INCDIR)/dis-asm.h $(BFD_H) \ + $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h +moxie-opc.lo: moxie-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/opcode/moxie.h h8300-dis.lo: h8300-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \ $(INCDIR)/opcode/h8300.h $(INCDIR)/dis-asm.h $(BFD_H) \ $(INCDIR)/symcat.h opintl.h $(INCDIR)/libiberty.h diff --git a/opcodes/configure b/opcodes/configure index e4377619437..ba23a48fca7 100755 --- a/opcodes/configure +++ b/opcodes/configure @@ -12765,6 +12765,7 @@ if test x${all_targets} = xfalse ; then bfd_dlx_arch) ta="$ta dlx-dis.lo" ;; bfd_fr30_arch) ta="$ta fr30-asm.lo fr30-desc.lo fr30-dis.lo fr30-ibld.lo fr30-opc.lo" using_cgen=yes ;; bfd_frv_arch) ta="$ta frv-asm.lo frv-desc.lo frv-dis.lo frv-ibld.lo frv-opc.lo" using_cgen=yes ;; + bfd_moxie_arch) ta="$ta moxie-dis.lo moxie-opc.lo" ;; bfd_h8300_arch) ta="$ta h8300-dis.lo" ;; bfd_h8500_arch) ta="$ta h8500-dis.lo" ;; bfd_hppa_arch) ta="$ta hppa-dis.lo" ;; diff --git a/opcodes/configure.in b/opcodes/configure.in index 2ecff8cc5fc..7aa9eda9c31 100644 --- a/opcodes/configure.in +++ b/opcodes/configure.in @@ -216,6 +216,7 @@ if test x${all_targets} = xfalse ; then bfd_dlx_arch) ta="$ta dlx-dis.lo" ;; bfd_fr30_arch) ta="$ta fr30-asm.lo fr30-desc.lo fr30-dis.lo fr30-ibld.lo fr30-opc.lo" using_cgen=yes ;; bfd_frv_arch) ta="$ta frv-asm.lo frv-desc.lo frv-dis.lo frv-ibld.lo frv-opc.lo" using_cgen=yes ;; + bfd_moxie_arch) ta="$ta moxie-dis.lo moxie-opc.lo" ;; bfd_h8300_arch) ta="$ta h8300-dis.lo" ;; bfd_h8500_arch) ta="$ta h8500-dis.lo" ;; bfd_hppa_arch) ta="$ta hppa-dis.lo" ;; diff --git a/opcodes/moxie-dis.c b/opcodes/moxie-dis.c new file mode 100644 index 00000000000..b1d123f5a44 --- /dev/null +++ b/opcodes/moxie-dis.c @@ -0,0 +1,184 @@ +/* Disassemble moxie instructions. + Copyright 2009 + Free Software Foundation, Inc. + + This file is part of the GNU opcodes library. + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include +#include "sysdep.h" +#define STATIC_TABLE +#define DEFINE_TABLE + +#include "opcode/moxie.h" +#include "dis-asm.h" + +static fprintf_ftype fpr; +static void *stream; + +/* Macros to extract operands from the instruction word. */ +#define OP_A(i) ((i >> 4) & 0xf) +#define OP_B(i) (i & 0xf) + +static const char * reg_names[16] = + { "$fp", "$sp", "$r0", "$r1", "$r2", "$r3", "$r4", "$r5", + "$r6", "$r7", "$r8", "$r9", "$r10", "$r11", "$r12", "$r13" }; + +int +print_insn_moxie (bfd_vma addr, struct disassemble_info * info) +{ + int length = 2; + int status; + stream = info->stream; + const moxie_opc_info_t * opcode; + bfd_byte buffer[4]; + unsigned short iword; + fpr = info->fprintf_func; + + if ((status = info->read_memory_func (addr, buffer, 2, info))) + goto fail; + iword = bfd_getb16 (buffer); + + /* Form 1 instructions have the high bit set to 0. */ + if ((iword & (1<<15)) == 0) + { + /* Extract the Form 1 opcode. */ + opcode = &moxie_form1_opc_info[iword >> 8]; + switch (opcode->itype) + { + case MOXIE_F1_NARG: + fpr (stream, "%s", opcode->name); + break; + case MOXIE_F1_A: + fpr (stream, "%s\t%s", opcode->name, + reg_names[OP_A(iword)]); + break; + case MOXIE_F1_AB: + fpr (stream, "%s\t%s, %s", opcode->name, + reg_names[OP_A(iword)], + reg_names[OP_B(iword)]); + break; + case MOXIE_F1_A4: + { + unsigned imm; + if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) + goto fail; + imm = bfd_getb32 (buffer); + fpr (stream, "%s\t%s, 0x%x", opcode->name, + reg_names[OP_A(iword)], imm); + length = 6; + } + break; + case MOXIE_F1_4: + { + unsigned imm; + if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) + goto fail; + imm = bfd_getb32 (buffer); + fpr (stream, "%s\t0x%x", opcode->name, imm); + length = 6; + } + break; + case MOXIE_F1_AiB: + fpr (stream, "%s\t(%s), %s", opcode->name, + reg_names[OP_A(iword)], reg_names[OP_B(iword)]); + break; + case MOXIE_F1_ABi: + fpr (stream, "%s\t%s, (%s)", opcode->name, + reg_names[OP_A(iword)], reg_names[OP_B(iword)]); + break; + case MOXIE_F1_4A: + { + unsigned imm; + if ((status = info->read_memory_func (addr + 2, buffer, 4, info))) + goto fail; + imm = bfd_getb32 (buffer); + fpr (stream, "%s\t0x%x, %s", + opcode->name, imm, reg_names[OP_A(iword)]); + length = 6; + } + break; + case MOXIE_F1_AiB4: + { + unsigned imm; + if ((status = info->read_memory_func (addr+2, buffer, 4, info))) + goto fail; + imm = bfd_getb32 (buffer); + fpr (stream, "%s\t0x%x(%s), %s", opcode->name, + imm, + reg_names[OP_A(iword)], + reg_names[OP_B(iword)]); + length = 6; + } + break; + case MOXIE_F1_ABi4: + { + unsigned imm; + if ((status = info->read_memory_func (addr+2, buffer, 4, info))) + goto fail; + imm = bfd_getb32 (buffer); + fpr (stream, "%s\t%s, 0x%x(%s)", + opcode->name, + reg_names[OP_A(iword)], + imm, + reg_names[OP_B(iword)]); + length = 6; + } + break; + default: + abort (); + } + } + else if ((iword & (1<<14)) == 0) + { + /* Extract the Form 2 opcode. */ + opcode = &moxie_form2_opc_info[(iword >> 12) & 3]; + switch (opcode->itype) + { + case MOXIE_F2_A8V: + fpr (stream, "%s\t%s, 0x%x", + opcode->name, + reg_names[(iword >> 8) & 0xf], + iword & ((1 << 8) - 1)); + break; + case MOXIE_F2_NARG: + fpr (stream, "%s", opcode->name); + break; + default: + abort(); + } + } + else + { + /* Extract the Form 3 opcode. */ + opcode = &moxie_form2_opc_info[(iword >> 12) & 3]; + switch (opcode->itype) + { + case MOXIE_F3_NARG: + fpr (stream, "%s", opcode->name); + break; + default: + abort(); + } + } + + return length; + + fail: + info->memory_error_func (status, addr, info); + return -1; +} diff --git a/opcodes/moxie-opc.c b/opcodes/moxie-opc.c new file mode 100644 index 00000000000..559cd115e8c --- /dev/null +++ b/opcodes/moxie-opc.c @@ -0,0 +1,136 @@ +/* moxie-opc.c -- Definitions for moxie opcodes. + Copyright 2009 Free Software Foundation, Inc. + Contributed by Anthony Green (green@moxielogic.com). + + This file is part of the GNU opcodes library. + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with this file; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include "sysdep.h" +#include "opcode/moxie.h" + +/* The moxie processor's 16-bit instructions come in two forms: + + FORM 1 instructions start with a 0 bit... + + 0oooooooaaaabbbb + 0 F + + ooooooo - form 1 opcode number + aaaa - operand A + bbbb - operand B + + FORM 2 instructions start with bits "10"... + + 10ooaaaavvvvvvvv + 0 F + + oo - form 2 opcode number + aaaa - operand A + vvvvvvvv - 8-bit immediate value + + FORM 3 instructions start with a bits "11"... + + 11oovvvvvvvvvvvv + 0 F + + oo - form 3 opcode number + vvvvvvvvvvvv - 12-bit immediate value. */ + +const moxie_opc_info_t moxie_form1_opc_info[64] = + { + { 0x00, MOXIE_F1_NARG, "nop" }, + { 0x01, MOXIE_F1_A4, "ldi.l" }, + { 0x02, MOXIE_F1_AB, "mov" }, + { 0x03, MOXIE_F1_4, "jsra" }, + { 0x04, MOXIE_F1_NARG, "ret" }, + { 0x05, MOXIE_F1_AB, "add.l" }, + { 0x06, MOXIE_F1_AB, "push" }, + { 0x07, MOXIE_F1_AB, "pop" }, + { 0x08, MOXIE_F1_A4, "lda.l" }, + { 0x09, MOXIE_F1_4A, "sta.l" }, + { 0x0a, MOXIE_F1_ABi, "ld.l" }, + { 0x0b, MOXIE_F1_AiB, "st.l" }, + { 0x0c, MOXIE_F1_ABi4, "ldo.l" }, + { 0x0d, MOXIE_F1_AiB4, "sto.l" }, + { 0x0e, MOXIE_F1_AB, "cmp" }, + { 0x0f, MOXIE_F1_4, "beq" }, + { 0x10, MOXIE_F1_4, "bne" }, + { 0x11, MOXIE_F1_4, "blt" }, + { 0x12, MOXIE_F1_4, "bgt" }, + { 0x13, MOXIE_F1_4, "bltu" }, + { 0x14, MOXIE_F1_4, "bgtu" }, + { 0x15, MOXIE_F1_4, "bge" }, + { 0x16, MOXIE_F1_4, "ble" }, + { 0x17, MOXIE_F1_4, "bgeu" }, + { 0x18, MOXIE_F1_4, "bleu" }, + { 0x19, MOXIE_F1_A, "jsr" }, + { 0x1a, MOXIE_F1_4, "jmpa" }, + { 0x1b, MOXIE_F1_A4, "ldi.b" }, + { 0x1c, MOXIE_F1_ABi, "ld.b" }, + { 0x1d, MOXIE_F1_A4, "lda.b" }, + { 0x1e, MOXIE_F1_AiB, "st.b" }, + { 0x1f, MOXIE_F1_4A, "sta.b" }, + { 0x20, MOXIE_F1_A4, "ldi.s" }, + { 0x21, MOXIE_F1_ABi, "ld.s" }, + { 0x22, MOXIE_F1_A4, "lda.s" }, + { 0x23, MOXIE_F1_AiB, "st.s" }, + { 0x24, MOXIE_F1_4A, "sta.s" }, + { 0x25, MOXIE_F1_A, "jmp" }, + { 0x26, MOXIE_F1_AB, "and" }, + { 0x27, MOXIE_F1_AB, "lshr" }, + { 0x28, MOXIE_F1_AB, "ashl" }, + { 0x29, MOXIE_F1_AB, "sub.l" }, + { 0x2a, MOXIE_F1_AB, "neg" }, + { 0x2b, MOXIE_F1_AB, "or" }, + { 0x2c, MOXIE_F1_AB, "not" }, + { 0x2d, MOXIE_F1_AB, "ashr" }, + { 0x2e, MOXIE_F1_AB, "xor" }, + { 0x2f, MOXIE_F1_AB, "mul.l" }, + { 0x30, MOXIE_F1_4, "swi" }, + { 0x31, MOXIE_F1_AB, "div.l" }, + { 0x32, MOXIE_F1_AB, "udiv.l" }, + { 0x33, MOXIE_F1_AB, "mod.l" }, + { 0x34, MOXIE_F1_AB, "umod.l" }, + { 0x35, MOXIE_F1_NARG, "brk" }, + { 0x36, MOXIE_F1_ABi4, "ldo.b" }, + { 0x37, MOXIE_F1_AiB4, "sto.b" }, + { 0x38, MOXIE_F1_ABi4, "ldo.s" }, + { 0x39, MOXIE_F1_AiB4, "sto.s" }, + { 0x3a, MOXIE_F1_NARG, "bad" }, + { 0x3b, MOXIE_F1_NARG, "bad" }, + { 0x3c, MOXIE_F1_NARG, "bad" }, + { 0x3d, MOXIE_F1_NARG, "bad" }, + { 0x3e, MOXIE_F1_NARG, "bad" }, + { 0x3f, MOXIE_F1_NARG, "bad" } + }; + +const moxie_opc_info_t moxie_form2_opc_info[4] = + { + { 0x00, MOXIE_F2_A8V, "inc" }, + { 0x01, MOXIE_F2_A8V, "dec" }, + { 0x02, MOXIE_F2_A8V, "gsr" }, + { 0x03, MOXIE_F2_A8V, "ssr" } + }; + +const moxie_opc_info_t moxie_form3_opc_info[4] = + { + { 0x00, MOXIE_F2_NARG, "bad" }, + { 0x01, MOXIE_F2_NARG, "bad" }, + { 0x02, MOXIE_F2_NARG, "bad" }, + { 0x03, MOXIE_F2_NARG, "bad" } + }; +