From 3c9b82baee30a1d3cfeb419643c6363dc9267208 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 25 Oct 2005 17:40:19 +0000 Subject: [PATCH] Add support for the Z80 processor family --- bfd/ChangeLog | 17 + bfd/Makefile.am | 10 + bfd/Makefile.in | 10 + bfd/archures.c | 7 + bfd/bfd-in2.h | 8 + bfd/coff-z80.c | 244 ++++ bfd/coffcode.h | 35 + bfd/config.bfd | 6 + bfd/configure | 1 + bfd/configure.in | 1 + bfd/cpu-z80.c | 57 + bfd/libbfd.h | 1 + bfd/reloc.c | 5 + bfd/targets.c | 2 + gas/ChangeLog | 17 + gas/Makefile.am | 3 + gas/Makefile.in | 3 + gas/app.c | 54 + gas/config/obj-coff.h | 5 + gas/config/tc-z80.c | 2061 +++++++++++++++++++++++++++ gas/config/tc-z80.h | 103 ++ gas/configure.tgt | 4 +- gas/doc/Makefile.am | 1 + gas/doc/Makefile.in | 7 +- gas/doc/all.texi | 1 + gas/doc/as.texinfo | 64 + gas/doc/c-z80.texi | 248 ++++ gas/testsuite/ChangeLog | 13 + gas/testsuite/gas/all/gas.exp | 26 +- gas/testsuite/gas/macros/macros.exp | 2 + gas/testsuite/gas/z80/quotes.d | 9 + gas/testsuite/gas/z80/quotes.s | 11 + gas/testsuite/gas/z80/redef.d | 8 + gas/testsuite/gas/z80/redef.s | 11 + gas/testsuite/gas/z80/z80.exp | 10 + include/ChangeLog | 6 +- include/coff/ChangeLog | 5 + include/coff/internal.h | 6 +- include/coff/z80.h | 51 + include/dis-asm.h | 1 + include/elf/ChangeLog | 5 + include/opcode/ChangeLog | 4 + ld/ChangeLog | 10 + ld/Makefile.am | 5 + ld/Makefile.in | 5 + ld/NEWS | 2 + ld/configure.tgt | 2 + ld/emulparams/z80.sh | 6 + ld/emultempl/z80.em | 85 ++ ld/scripttempl/z80.sc | 35 + ld/testsuite/ld-checks/checks.exp | 1 + ld/testsuite/ld-scripts/align.exp | 4 + opcodes/ChangeLog | 8 + opcodes/Makefile.am | 4 + opcodes/Makefile.in | 4 + opcodes/configure | 1 + opcodes/configure.in | 1 + opcodes/disassemble.c | 6 + opcodes/z80-dis.c | 620 ++++++++ 59 files changed, 3927 insertions(+), 15 deletions(-) create mode 100644 bfd/coff-z80.c create mode 100644 bfd/cpu-z80.c create mode 100644 gas/config/tc-z80.c create mode 100644 gas/config/tc-z80.h create mode 100644 gas/doc/c-z80.texi create mode 100644 gas/testsuite/gas/z80/quotes.d create mode 100644 gas/testsuite/gas/z80/quotes.s create mode 100644 gas/testsuite/gas/z80/redef.d create mode 100644 gas/testsuite/gas/z80/redef.s create mode 100644 gas/testsuite/gas/z80/z80.exp create mode 100644 include/coff/z80.h create mode 100644 ld/emulparams/z80.sh create mode 100644 ld/emultempl/z80.em create mode 100644 ld/scripttempl/z80.sc create mode 100644 opcodes/z80-dis.c diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 9e6dec8a185..c12c6ace830 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,20 @@ +2005-10-25 Arnold Metselaar + + * Makefile.am: Add rules for coff-z80 and cpu-z80. + * Makefile.in: Regenerated. + * archures.c: Add bfd_arch_z80 and support for it. + * coffcode.h(coff_set_arch_mach_hook): Add case Z80MAGIC. + (coff_set_flags): Add case bfd_arch_z80. + * config.bfd: Add z80coff_vec. + * configure.in: Add z80coff_vec. + * reloc.c: Add BFD_RELOC_Z80_DISP8 + * targets.c: Add z80coff_vec. + * coff-z80.c: New file + * cpu-z80.c: New file + * configure: Regenerated. + * libbfd.h: Regenerated. + * bfd-in2.h: Regenerated. + 2005-10-26 Alan Modra PR ld/1540 diff --git a/bfd/Makefile.am b/bfd/Makefile.am index d090ad3a039..46978a57f43 100644 --- a/bfd/Makefile.am +++ b/bfd/Makefile.am @@ -111,6 +111,7 @@ ALL_MACHINES = \ cpu-w65.lo \ cpu-xstormy16.lo \ cpu-xtensa.lo \ + cpu-z80.lo \ cpu-z8k.lo ALL_MACHINES_CFILES = \ @@ -171,6 +172,7 @@ ALL_MACHINES_CFILES = \ cpu-w65.c \ cpu-xstormy16.c \ cpu-xtensa.c \ + cpu-z80.c \ cpu-z8k.c # The .o files needed by all of the 32 bit vectors that are configured into @@ -214,6 +216,7 @@ BFD32_BACKENDS = \ coff-u68k.lo \ coff-we32k.lo \ coff-w65.lo \ + coff-z80.lo \ coff-z8k.lo \ cofflink.lo \ dwarf1.lo \ @@ -384,6 +387,7 @@ BFD32_BACKENDS_CFILES = \ coff-u68k.c \ coff-we32k.c \ coff-w65.c \ + coff-z80.c \ coff-z8k.c \ cofflink.c \ dwarf1.c \ @@ -1084,6 +1088,8 @@ cpu-xstormy16.lo: cpu-xstormy16.c ./bfd.h ./config.h \ $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-xtensa.lo: cpu-xtensa.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h +cpu-z80.lo: cpu-z80.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ + $(INCDIR)/hashtab.h cpu-z8k.lo: cpu-z8k.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h aout-adobe.lo: aout-adobe.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ @@ -1241,6 +1247,10 @@ coff-w65.lo: coff-w65.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/w65.h \ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \ libcoff.h coffcode.h coffswap.h +coff-z80.lo: coff-z80.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ + $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/z80.h \ + $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \ + libcoff.h coffcode.h coffswap.h coff-z8k.lo: coff-z8k.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/z8k.h \ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \ diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 6c3f5980e45..ba368427ce9 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -348,6 +348,7 @@ ALL_MACHINES = \ cpu-w65.lo \ cpu-xstormy16.lo \ cpu-xtensa.lo \ + cpu-z80.lo \ cpu-z8k.lo ALL_MACHINES_CFILES = \ @@ -408,6 +409,7 @@ ALL_MACHINES_CFILES = \ cpu-w65.c \ cpu-xstormy16.c \ cpu-xtensa.c \ + cpu-z80.c \ cpu-z8k.c @@ -452,6 +454,7 @@ BFD32_BACKENDS = \ coff-u68k.lo \ coff-we32k.lo \ coff-w65.lo \ + coff-z80.lo \ coff-z8k.lo \ cofflink.lo \ dwarf1.lo \ @@ -622,6 +625,7 @@ BFD32_BACKENDS_CFILES = \ coff-u68k.c \ coff-we32k.c \ coff-w65.c \ + coff-z80.c \ coff-z8k.c \ cofflink.c \ dwarf1.c \ @@ -1651,6 +1655,8 @@ cpu-xstormy16.lo: cpu-xstormy16.c ./bfd.h ./config.h \ $(INCDIR)/filenames.h $(INCDIR)/hashtab.h cpu-xtensa.lo: cpu-xtensa.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h +cpu-z80.lo: cpu-z80.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ + $(INCDIR)/hashtab.h cpu-z8k.lo: cpu-z8k.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h aout-adobe.lo: aout-adobe.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ @@ -1808,6 +1814,10 @@ coff-w65.lo: coff-w65.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/w65.h \ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \ libcoff.h coffcode.h coffswap.h +coff-z80.lo: coff-z80.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ + $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/z80.h \ + $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \ + libcoff.h coffcode.h coffswap.h coff-z8k.lo: coff-z8k.c ./bfd.h ./config.h $(INCDIR)/filenames.h \ $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/coff/z8k.h \ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \ diff --git a/bfd/archures.c b/bfd/archures.c index 74d2b712ed5..a96771cf8da 100644 --- a/bfd/archures.c +++ b/bfd/archures.c @@ -365,6 +365,11 @@ DESCRIPTION . bfd_arch_maxq, {* Dallas MAXQ 10/20 *} .#define bfd_mach_maxq10 10 .#define bfd_mach_maxq20 20 +. bfd_arch_z80, +.#define bfd_mach_z80strict 1 {* No undocumented opcodes. *} +.#define bfd_mach_z80 3 {* With ixl, ixh, iyl, and iyh. *} +.#define bfd_mach_z80full 7 {* All undocumented instructions. *} +.#define bfd_mach_r800 11 {* R800: successor with multiplication. *} . bfd_arch_last . }; */ @@ -461,6 +466,7 @@ extern const bfd_arch_info_type bfd_we32k_arch; extern const bfd_arch_info_type bfd_w65_arch; extern const bfd_arch_info_type bfd_xstormy16_arch; extern const bfd_arch_info_type bfd_xtensa_arch; +extern const bfd_arch_info_type bfd_z80_arch; extern const bfd_arch_info_type bfd_z8k_arch; static const bfd_arch_info_type * const bfd_archures_list[] = @@ -524,6 +530,7 @@ static const bfd_arch_info_type * const bfd_archures_list[] = &bfd_we32k_arch, &bfd_xstormy16_arch, &bfd_xtensa_arch, + &bfd_z80_arch, &bfd_z8k_arch, #endif 0 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 6cf7e3c955c..7afe43725a7 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1953,6 +1953,11 @@ enum bfd_architecture bfd_arch_maxq, /* Dallas MAXQ 10/20 */ #define bfd_mach_maxq10 10 #define bfd_mach_maxq20 20 + bfd_arch_z80, +#define bfd_mach_z80strict 1 /* No undocumented opcodes. */ +#define bfd_mach_z80 3 /* With ixl, ixh, iyl, and iyh. */ +#define bfd_mach_z80full 7 /* All undocumented instructions. */ +#define bfd_mach_r800 11 /* R800: successor with multiplication. */ bfd_arch_last }; @@ -4058,6 +4063,9 @@ internally by the linker after analysis of a BFD_RELOC_XTENSA_ASM_EXPAND. */ BFD_RELOC_XTENSA_ASM_SIMPLIFY, +/* 8 bit signed offset in (ix+d) or (iy+d). */ + BFD_RELOC_Z80_DISP8, + /* DJNZ offset. */ BFD_RELOC_Z8K_DISP7, diff --git a/bfd/coff-z80.c b/bfd/coff-z80.c new file mode 100644 index 00000000000..fe401d77b86 --- /dev/null +++ b/bfd/coff-z80.c @@ -0,0 +1,244 @@ +/* BFD back-end for Zilog Z80 COFF binaries. + Copyright 2005 Free Software Foundation, Inc. + Contributed by Arnold Metselaar + + 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. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" +#include "bfdlink.h" +#include "coff/z80.h" +#include "coff/internal.h" +#include "libcoff.h" + +#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 0 + +static reloc_howto_type r_imm32 = +HOWTO (R_IMM32, 0, 1, 32, FALSE, 0, + complain_overflow_dont, 0, "r_imm32", TRUE, 0xffffffff, 0xffffffff, + FALSE); + +static reloc_howto_type r_imm16 = +HOWTO (R_IMM16, 0, 1, 16, FALSE, 0, + complain_overflow_dont, 0, "r_imm16", TRUE, 0x0000ffff, 0x0000ffff, + FALSE); + +static reloc_howto_type r_imm8 = +HOWTO (R_IMM8, 0, 0, 8, FALSE, 0, + complain_overflow_bitfield, 0, "r_imm8", TRUE, 0x000000ff, 0x000000ff, + FALSE); + +static reloc_howto_type r_jr = +HOWTO (R_JR, 0, 0, 8, TRUE, 0, + complain_overflow_signed, 0, "r_jr", FALSE, 0, 0xFF, + FALSE); + +static reloc_howto_type r_off8 = +HOWTO (R_OFF8, 0, 0, 8, FALSE, 0, + complain_overflow_signed, 0,"r_off8", FALSE, 0, 0xff, + FALSE); + + +#define BADMAG(x) Z80BADMAG(x) +#define Z80 1 /* Customize coffcode.h. */ +#define __A_MAGIC_SET__ + +/* Code to swap in the reloc. */ + +#define SWAP_IN_RELOC_OFFSET H_GET_32 +#define SWAP_OUT_RELOC_OFFSET H_PUT_32 + +#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \ + dst->r_stuff[0] = 'S'; \ + dst->r_stuff[1] = 'C'; + +/* Code to turn a r_type into a howto ptr, uses the above howto table. */ + +static void +rtype2howto (arelent *internal, struct internal_reloc *dst) +{ + switch (dst->r_type) + { + default: + abort (); + break; + case R_IMM8: + internal->howto = &r_imm8; + break; + case R_IMM16: + internal->howto = &r_imm16; + break; + case R_IMM32: + internal->howto = &r_imm32; + break; + case R_JR: + internal->howto = &r_jr; + break; + case R_OFF8: + internal->howto = &r_off8; + break; + } +} + +#define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry) + +static reloc_howto_type * +coff_z80_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, + bfd_reloc_code_real_type code) +{ + switch (code) + { + case BFD_RELOC_8: return & r_imm8; + case BFD_RELOC_16: return & r_imm16; + case BFD_RELOC_32: return & r_imm32; + case BFD_RELOC_8_PCREL: return & r_jr; + case BFD_RELOC_Z80_DISP8: return & r_off8; + default: BFD_FAIL (); + return NULL; + } +} + +/* Perform any necessary magic to the addend in a reloc entry. */ + +#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \ + cache_ptr->addend = ext_reloc.r_offset; + +#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ + reloc_processing(relent, reloc, symbols, abfd, section) + +static void +reloc_processing (arelent *relent, + struct internal_reloc *reloc, + asymbol **symbols, + bfd *abfd, + asection *section) +{ + relent->address = reloc->r_vaddr; + rtype2howto (relent, reloc); + + if (reloc->r_symndx > 0) + relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; + else + relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; + + relent->addend = reloc->r_offset; + relent->address -= section->vma; +} + +static void +extra_case (bfd *in_abfd, + struct bfd_link_info *link_info, + struct bfd_link_order *link_order, + arelent *reloc, + bfd_byte *data, + unsigned int *src_ptr, + unsigned int *dst_ptr) +{ + asection * input_section = link_order->u.indirect.section; + int val; + + switch (reloc->howto->type) + { + case R_OFF8: + val = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + if (val>127 || val<-128) /* Test for overflow. */ + { + if (! ((*link_info->callbacks->reloc_overflow) + (link_info, NULL, + bfd_asymbol_name (*reloc->sym_ptr_ptr), + reloc->howto->name, reloc->addend, input_section->owner, + input_section, reloc->address))) + abort (); + } + bfd_put_8 (in_abfd, val, data + *dst_ptr); + (*dst_ptr) += 1; + (*src_ptr) += 1; + break; + + case R_IMM8: + val = bfd_get_16 ( in_abfd, data+*src_ptr) + + bfd_coff_reloc16_get_value (reloc, link_info, input_section); + bfd_put_8 (in_abfd, val, data + *dst_ptr); + (*dst_ptr) += 1; + (*src_ptr) += 1; + break; + + case R_IMM16: + val = bfd_get_16 ( in_abfd, data+*src_ptr) + + bfd_coff_reloc16_get_value (reloc, link_info, input_section); + bfd_put_16 (in_abfd, val, data + *dst_ptr); + (*dst_ptr) += 2; + (*src_ptr) += 2; + break; + + case R_IMM32: + val = bfd_get_32 ( in_abfd, data+*src_ptr) + + bfd_coff_reloc16_get_value (reloc, link_info, input_section); + bfd_put_32 (in_abfd, val, data + *dst_ptr); + (*dst_ptr) += 4; + (*src_ptr) += 4; + break; + + case R_JR: + { + bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + bfd_vma dot = (link_order->offset + + *dst_ptr + + input_section->output_section->vma); + int gap = dst - dot - 1; /* -1, Since the offset is relative + to the value of PC after reading + the offset. */ + + if (gap >= 128 || gap < -128) + { + if (! ((*link_info->callbacks->reloc_overflow) + (link_info, NULL, + bfd_asymbol_name (*reloc->sym_ptr_ptr), + reloc->howto->name, reloc->addend, input_section->owner, + input_section, reloc->address))) + abort (); + } + bfd_put_8 (in_abfd, gap, data + *dst_ptr); + (*dst_ptr)++; + (*src_ptr)++; + break; + } + + default: + abort (); + } +} + +#define coff_reloc16_extra_cases extra_case +#define coff_bfd_reloc_type_lookup coff_z80_reloc_type_lookup + +#include "coffcode.h" + +#undef coff_bfd_get_relocated_section_contents +#define coff_bfd_get_relocated_section_contents \ + bfd_coff_reloc16_get_relocated_section_contents + +#undef coff_bfd_relax_section +#define coff_bfd_relax_section bfd_coff_reloc16_relax_section + +CREATE_LITTLE_COFF_TARGET_VEC (z80coff_vec, "coff-z80", 0, 0, '\0', NULL, + COFF_SWAP_TABLE) + diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 3b94dff431a..aaf79c10325 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -1955,6 +1955,23 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr) machine = 88100; break; #endif +#ifdef Z80MAGIC + case Z80MAGIC: + arch = bfd_arch_z80; + switch (internal_f->f_flags & F_MACHMASK) + { + case 0: + case bfd_mach_z80strict << 12: + case bfd_mach_z80 << 12: + case bfd_mach_z80full << 12: + case bfd_mach_r800 << 12: + machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12; + break; + default: + return FALSE; + } + break; +#endif #ifdef Z8KMAGIC case Z8KMAGIC: arch = bfd_arch_z8k; @@ -2555,6 +2572,24 @@ coff_set_flags (bfd * abfd, { switch (bfd_get_arch (abfd)) { +#ifdef Z80MAGIC + case bfd_arch_z80: + *magicp = Z80MAGIC; + switch (bfd_get_mach (abfd)) + { + case 0: + case bfd_mach_z80strict: + case bfd_mach_z80: + case bfd_mach_z80full: + case bfd_mach_r800: + *flagsp = bfd_get_mach (abfd) << 12; + break; + default: + return FALSE; + } + return TRUE; +#endif + #ifdef Z8KMAGIC case bfd_arch_z8k: *magicp = Z8KMAGIC; diff --git a/bfd/config.bfd b/bfd/config.bfd index aec10e18233..ab47fa3cc25 100644 --- a/bfd/config.bfd +++ b/bfd/config.bfd @@ -101,6 +101,7 @@ v850*) targ_archs=bfd_v850_arch ;; x86_64) targ_archs=bfd_i386_arch ;; xscale*) targ_archs=bfd_arm_arch ;; xtensa*) targ_archs=bfd_xtensa_arch ;; +z80|r800) targ_archs=bfd_z80_arch ;; z8k*) targ_archs=bfd_z8k_arch ;; am33_2.0) targ_archs=bfd_mn10300_arch ;; *) targ_archs=bfd_${targ_cpu}_arch ;; @@ -1366,6 +1367,11 @@ case "${targ}" in targ_selvecs=bfd_elf32_xtensa_be_vec ;; + z80-*-*) + targ_defvec=z80coff_vec + targ_underscore=no + ;; + z8k*-*-*) targ_defvec=z8kcoff_vec targ_underscore=yes diff --git a/bfd/configure b/bfd/configure index 179967607f6..d7f01e6c440 100755 --- a/bfd/configure +++ b/bfd/configure @@ -13190,6 +13190,7 @@ do vms_vax_vec) tb="$tb vms.lo vms-hdr.lo vms-gsd.lo vms-tir.lo vms-misc.lo" ;; w65_vec) tb="$tb coff-w65.lo reloc16.lo" ;; we32kcoff_vec) tb="$tb coff-we32k.lo" ;; + z80coff_vec) tb="$tb coff-z80.lo reloc16.lo" ;; z8kcoff_vec) tb="$tb coff-z8k.lo reloc16.lo cofflink.lo" ;; # These appear out of order in targets.c diff --git a/bfd/configure.in b/bfd/configure.in index 7ace2196d06..1a7dc84de5b 100644 --- a/bfd/configure.in +++ b/bfd/configure.in @@ -811,6 +811,7 @@ do vms_vax_vec) tb="$tb vms.lo vms-hdr.lo vms-gsd.lo vms-tir.lo vms-misc.lo" ;; w65_vec) tb="$tb coff-w65.lo reloc16.lo" ;; we32kcoff_vec) tb="$tb coff-we32k.lo" ;; + z80coff_vec) tb="$tb coff-z80.lo reloc16.lo" ;; z8kcoff_vec) tb="$tb coff-z8k.lo reloc16.lo cofflink.lo" ;; # These appear out of order in targets.c diff --git a/bfd/cpu-z80.c b/bfd/cpu-z80.c new file mode 100644 index 00000000000..3fd6fd48176 --- /dev/null +++ b/bfd/cpu-z80.c @@ -0,0 +1,57 @@ +/* BFD library support routines for the Z80 architecture. + Copyright 2005 Free Software Foundation, Inc. + Contributed by Arnold Metselaar + + 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. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" + +const bfd_arch_info_type bfd_z80_arch; + +/* This routine is provided two arch_infos and + returns whether they'd be compatible. */ + +static const bfd_arch_info_type * +compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b) +{ + if (a->arch != b->arch) + return NULL; + + if (a->mach == b->mach) + return a; + + return (a->arch == bfd_arch_z80) ? & bfd_z80_arch : NULL; +} + +#define N(name,print,default,next) \ +{ 16, 16, 8, bfd_arch_z80, name, "z80", print, 0, default, \ + compatible, bfd_default_scan, next } + +#define M(n) &arch_info_struct[n] + +static const bfd_arch_info_type arch_info_struct[] = +{ + N (bfd_mach_z80strict, "z80-strict", FALSE, M(1)), + N (bfd_mach_z80, "z80", FALSE, M(2)), + N (bfd_mach_z80full, "z80-full", FALSE, M(3)), + N (bfd_mach_r800, "r800", FALSE, NULL) +}; + +const bfd_arch_info_type bfd_z80_arch = N (0, "z80-any", TRUE, M(0)); diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 9125663515b..91f6f8bdea3 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -1830,6 +1830,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_XTENSA_OP2", "BFD_RELOC_XTENSA_ASM_EXPAND", "BFD_RELOC_XTENSA_ASM_SIMPLIFY", + "BFD_RELOC_Z80_DISP8", "BFD_RELOC_Z8K_DISP7", "BFD_RELOC_Z8K_CALLR", "BFD_RELOC_Z8K_IMM4L", diff --git a/bfd/reloc.c b/bfd/reloc.c index ba8e14c7a42..ea73d137372 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -4574,6 +4574,11 @@ ENUMDOC internally by the linker after analysis of a BFD_RELOC_XTENSA_ASM_EXPAND. +ENUM + BFD_RELOC_Z80_DISP8 +ENUMDOC + 8 bit signed offset in (ix+d) or (iy+d). + ENUM BFD_RELOC_Z8K_DISP7 ENUMDOC diff --git a/bfd/targets.c b/bfd/targets.c index 78449711c02..8f5795c24a4 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -782,6 +782,7 @@ extern const bfd_target vms_alpha_vec; extern const bfd_target vms_vax_vec; extern const bfd_target w65_vec; extern const bfd_target we32kcoff_vec; +extern const bfd_target z80coff_vec; extern const bfd_target z8kcoff_vec; /* These are always included. */ @@ -1134,6 +1135,7 @@ static const bfd_target * const _bfd_target_vector[] = { &vms_vax_vec, &w65_vec, &we32kcoff_vec, + &z80coff_vec, &z8kcoff_vec, &bfd_elf32_am33lin_vec, #endif /* not SELECT_VECS */ diff --git a/gas/ChangeLog b/gas/ChangeLog index 2ff1e5043f3..58816b9f9b6 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,20 @@ +2005-10-25 Arnold Metselaar + + * Makefile.am: Add Z80 cpu. + * Makefile.in: Regenerated. + * app.c (do_scrub_chars): Correctly scrub "ex af,af'" + and disallow newlines in quoted strings. + * configure.tgt: Add z80-*-coff. + * config/obj-coff.h: Add format "coff-z80". + * doc/Makefile.am: Add c-z80.texi. + * doc/Makefile.in: Regenerated. + * doc/all.texi: Add Z80. + * doc/c-z80.texi: New file + * doc/as.texinfo: Add z80 options and some z80-related remarks. + * config/tc-z80.c: New file + * config/tc-z80.h: New file + * NEWS: Mention new support. + 2005-10-25 H.J. Lu * write.c (adjust_reloc_syms): Undo the change made on diff --git a/gas/Makefile.am b/gas/Makefile.am index e373978a6f4..0867a9a93d3 100644 --- a/gas/Makefile.am +++ b/gas/Makefile.am @@ -88,6 +88,7 @@ CPU_TYPES = \ v850 \ xstormy16 \ xtensa \ + z80 \ z8k # Object format types. This is only used for dependency information. @@ -270,6 +271,7 @@ TARGET_CPU_CFILES = \ config/tc-v850.c \ config/tc-xstormy16.c \ config/tc-xtensa.c \ + config/tc-z80.c \ config/tc-z8k.c TARGET_CPU_HFILES = \ @@ -319,6 +321,7 @@ TARGET_CPU_HFILES = \ config/tc-v850.h \ config/tc-xstormy16.h \ config/tc-xtensa.h \ + config/tc-z80.h \ config/tc-z8k.h # OBJ files in config diff --git a/gas/Makefile.in b/gas/Makefile.in index 4a8c2741658..c8a3492a4bf 100644 --- a/gas/Makefile.in +++ b/gas/Makefile.in @@ -318,6 +318,7 @@ CPU_TYPES = \ v850 \ xstormy16 \ xtensa \ + z80 \ z8k @@ -498,6 +499,7 @@ TARGET_CPU_CFILES = \ config/tc-v850.c \ config/tc-xstormy16.c \ config/tc-xtensa.c \ + config/tc-z80.c \ config/tc-z8k.c TARGET_CPU_HFILES = \ @@ -547,6 +549,7 @@ TARGET_CPU_HFILES = \ config/tc-v850.h \ config/tc-xstormy16.h \ config/tc-xtensa.h \ + config/tc-z80.h \ config/tc-z8k.h diff --git a/gas/app.c b/gas/app.c index 14f2f14b663..3ff7f61e210 100644 --- a/gas/app.c +++ b/gas/app.c @@ -375,6 +375,10 @@ do_scrub_chars (int (*get) (char *, int), char *tostart, int tolen) predicate. 15: After seeing a `(' at state 1, looking for a `)' as predicate. +#endif +#ifdef TC_Z80 + 16: After seeing an 'a' or an 'A' at the start of a symbol + 17: After seeing an 'f' or an 'F' in state 16 #endif */ @@ -664,6 +668,32 @@ do_scrub_chars (int (*get) (char *, int), char *tostart, int tolen) state = 1; PUT ('|'); continue; +#endif +#ifdef TC_Z80 + case 16: + /* We have seen an 'a' at the start of a symbol, look for an 'f'. */ + ch = GET (); + if (ch == 'f' || ch == 'F') + { + state = 17; + PUT (ch); + } + else + { + state = 9; + break; + } + case 17: + /* We have seen "af" at the start of a symbol, + a ' here is a part of that symbol. */ + ch = GET (); + state = 9; + if (ch == '\'') + /* Change to avoid warning about unclosed string. */ + PUT ('`'); + else + UNGET (ch); + break; #endif } @@ -1242,6 +1272,30 @@ do_scrub_chars (int (*get) (char *, int), char *tostart, int tolen) break; } +#ifdef TC_Z80 + /* "af'" is a symbol containing '\''. */ + if (state == 3 && (ch == 'a' || ch == 'A')) + { + state = 16; + PUT (ch); + ch = GET (); + if (ch == 'f' || ch == 'F') + { + state = 17; + PUT (ch); + break; + } + else + { + state = 9; + if (!IS_SYMBOL_COMPONENT (ch)) + { + UNGET (ch); + break; + } + } + } +#endif if (state == 3) state = 9; diff --git a/gas/config/obj-coff.h b/gas/config/obj-coff.h index 81577c8d842..4c7c68d77a7 100644 --- a/gas/config/obj-coff.h +++ b/gas/config/obj-coff.h @@ -85,6 +85,11 @@ #define TARGET_FORMAT "coff-Intel-little" #endif +#ifdef TC_Z80 +#include "coff/z80.h" +#define TARGET_FORMAT "coff-z80" +#endif + #ifdef TC_Z8K #include "coff/z8k.h" #define TARGET_FORMAT "coff-z8k" diff --git a/gas/config/tc-z80.c b/gas/config/tc-z80.c new file mode 100644 index 00000000000..28f69b1d54b --- /dev/null +++ b/gas/config/tc-z80.c @@ -0,0 +1,2061 @@ +/* tc-z80.c -- Assemble code for the Zilog Z80 and ASCII R800 + Copyright 2005 Free Software Foundation, Inc. + Contributed by Arnold Metselaar + + 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 2, 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. */ + +#include "as.h" +#include "listing.h" +#include "bfd.h" +#include "safe-ctype.h" +#include "subsegs.h" +#include "symbols.h" +#include "libiberty.h" + +/* Exported constants. */ +const char comment_chars[] = ";\0"; +const char line_comment_chars[] = "#;\0"; +const char line_separator_chars[] = "\0"; +const char EXP_CHARS[] = "eE\0"; +const char FLT_CHARS[] = "RrFf\0"; + +/* For machine specific options. */ +const char * md_shortopts = ""; /* None yet. */ + +enum options +{ + OPTION_MACH_Z80 = OPTION_MD_BASE, + OPTION_MACH_R800, + OPTION_MACH_IUD, + OPTION_MACH_WUD, + OPTION_MACH_FUD, + OPTION_MACH_IUP, + OPTION_MACH_WUP, + OPTION_MACH_FUP +}; + +#define INS_Z80 1 +#define INS_UNDOC 2 +#define INS_UNPORT 4 +#define INS_R800 8 + +struct option md_longopts[] = +{ + { "z80", no_argument, NULL, OPTION_MACH_Z80}, + { "r800", no_argument, NULL, OPTION_MACH_R800}, + { "ignore-undocumented-instructions", no_argument, NULL, OPTION_MACH_IUD }, + { "Wnud", no_argument, NULL, OPTION_MACH_IUD }, + { "warn-undocumented-instructions", no_argument, NULL, OPTION_MACH_WUD }, + { "Wud", no_argument, NULL, OPTION_MACH_WUD }, + { "forbid-undocumented-instructions", no_argument, NULL, OPTION_MACH_FUD }, + { "Fud", no_argument, NULL, OPTION_MACH_FUD }, + { "ignore-unportable-instructions", no_argument, NULL, OPTION_MACH_IUP }, + { "Wnup", no_argument, NULL, OPTION_MACH_IUP }, + { "warn-unportable-instructions", no_argument, NULL, OPTION_MACH_WUP }, + { "Wup", no_argument, NULL, OPTION_MACH_WUP }, + { "forbid-unportable-instructions", no_argument, NULL, OPTION_MACH_FUP }, + { "Fup", no_argument, NULL, OPTION_MACH_FUP }, + + { NULL, no_argument, NULL, 0 } +} ; + +size_t md_longopts_size = sizeof (md_longopts); + +extern int coff_flags; +/* Instruction classes that silently assembled. */ +static int ins_ok = INS_Z80 | INS_UNDOC; +/* Instruction classes that generate errors. */ +static int ins_err = INS_R800; +/* Instruction classes actually used, determines machine type. */ +static int ins_used = INS_Z80; + +int +md_parse_option (int c, char* arg ATTRIBUTE_UNUSED) +{ + switch (c) + { + default: + return 0; + case OPTION_MACH_Z80: + ins_ok &= ~INS_R800; + ins_err |= INS_R800; + break; + case OPTION_MACH_R800: + ins_ok = INS_Z80 | INS_UNDOC | INS_R800; + ins_err = INS_UNPORT; + break; + case OPTION_MACH_IUD: + ins_ok |= INS_UNDOC; + ins_err &= ~INS_UNDOC; + break; + case OPTION_MACH_IUP: + ins_ok |= INS_UNDOC | INS_UNPORT; + ins_err &= ~(INS_UNDOC | INS_UNPORT); + break; + case OPTION_MACH_WUD: + if ((ins_ok & INS_R800) == 0) + { + ins_ok &= ~(INS_UNDOC|INS_UNPORT); + ins_err &= ~INS_UNDOC; + } + break; + case OPTION_MACH_WUP: + ins_ok &= ~INS_UNPORT; + ins_err &= ~(INS_UNDOC|INS_UNPORT); + break; + case OPTION_MACH_FUD: + if ((ins_ok & INS_R800) == 0) + { + ins_ok &= (INS_UNDOC | INS_UNPORT); + ins_err |= INS_UNDOC | INS_UNPORT; + } + break; + case OPTION_MACH_FUP: + ins_ok &= ~INS_UNPORT; + ins_err |= INS_UNPORT; + break; + } + + return 1; +} + +void +md_show_usage (FILE * f) +{ + fprintf (f, "\n\ +CPU model/instruction set options:\n\ +\n\ + -z80\t\t assemble for Z80\n\ + -ignore-undocumented-instructions\n\ + -Wnud\n\ +\tsilently assemble undocumented Z80-instructions that work on R800\n\ + -ignore-unportable-instructions\n\ + -Wnup\n\ +\tsilently assemble all undocumented Z80-instructions\n\ + -warn-undocumented-instructions\n\ + -Wud\n\ +\tissue warnings for undocumented Z80-instructions that work on R800\n\ + -warn-unportable-instructions\n\ + -Wup\n\ +\tissue warnings for other undocumented Z80-instructions\n\ + -forbid-undocumented-instructions\n\ + -Fud\n\ +\ttreat all undocumented z80-instructions as errors\n\ + -forbid-unportable-instructions\n\ + -Fup\n\ +\ttreat undocumented z80-instructions that do not work on R800 as errors\n\ + -r800\t assemble for R800\n\n\ +Default: -z80 -ignore-undocument-instructions -warn-unportable-instructions.\n"); +} + +static symbolS * zero; + +void +md_begin (void) +{ + expressionS nul; + char * p; + + p = input_line_pointer; + input_line_pointer = "0"; + nul.X_md=0; + expression (& nul); + input_line_pointer = p; + zero = make_expr_symbol (& nul); + /* We do not use relaxation (yet). */ + linkrelax = 0; +} + +void +z80_md_end (void) +{ + int mach_type; + + if (ins_used & (INS_UNPORT | INS_R800)) + ins_used |= INS_UNDOC; + + switch (ins_used) + { + case INS_Z80: + mach_type = bfd_mach_z80strict; + break; + case INS_Z80|INS_UNDOC: + mach_type = bfd_mach_z80; + break; + case INS_Z80|INS_UNDOC|INS_UNPORT: + mach_type = bfd_mach_z80full; + break; + case INS_Z80|INS_UNDOC|INS_R800: + mach_type = bfd_mach_r800; + break; + default: + mach_type = 0; + } + + bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach_type); +} + +/* Port specific features. */ +const pseudo_typeS md_pseudo_table[] = +{ + { "defs", s_space, 1}, /* Synonym for ds on some assemblers. */ + { "ds", s_space, 1}, /* Fill with bytes rather than words. */ + { "psect", obj_coff_section, 0}, /* TODO: Translate attributes. */ + { "set", 0, 0}, /* Real instruction on z80. */ + { NULL, 0, 0 } +} ; + +static const char * +skip_space (const char *s) +{ + while (*s == ' ' || *s == '\t') + ++s; + return s; +} + +/* A non-zero return-value causes a continue in the + function read_a_source_file () in ../read.c. */ +int +z80_start_line_hook (void) +{ + char *p, quote; + char buf[4]; + + /* Convert one character constants. */ + for (p = input_line_pointer; *p && *p != '\n'; ++p) + { + switch (*p) + { + case '\'': + if (p[1] != 0 && p[1] != '\'' && p[2] == '\'') + { + snprintf (buf, 4, "%3d", (unsigned char)p[1]); + *p++ = buf[0]; + *p++ = buf[1]; + *p++ = buf[2]; + break; + } + case '"': + for (quote = *p++; quote != *p && '\n' != *p; ++p) + /* No escapes. */ ; + if (quote != *p) + { + as_bad (_("-- unterminated string")); + ignore_rest_of_line (); + return 1; + } + break; + } + } + /* Check for