aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl
diff options
context:
space:
mode:
authorSergey Belyashov <sergey.belyashov@gmail.com>2020-01-02 14:10:40 +0000
committerNick Clifton <nickc@redhat.com>2020-01-02 14:14:59 +0000
commit6655dba246bd164d953fe220a0e3d4eed85bb268 (patch)
tree423258b5dadb447dc649e71c6ce48aaeed8ba385 /ld/emultempl
parent0db131fb835e4c4f6a024e86743467e7e01c965e (diff)
downloadgdb-6655dba246bd164d953fe220a0e3d4eed85bb268.zip
gdb-6655dba246bd164d953fe220a0e3d4eed85bb268.tar.gz
gdb-6655dba246bd164d953fe220a0e3d4eed85bb268.tar.bz2
Add support for the GBZ80, Z180, and eZ80 variants of the Z80 architecure. Add an ELF based target for these as well.
PR 25224 bfd * Makefile.am: Add z80-elf target support. * configure.ac: Likewise. * targets.c: Likewise. * config.bfd: Add z80-elf target support and new arches: ez80 and z180. * elf32-z80.c: New file. * archures.c: Add new z80 architectures: eZ80 and Z180. * coffcode.h: Likewise. * cpu-z80.c: Likewise. * bfd-in2.h: Likewise plus additional Z80 relocations. * coff-z80.c: Add new relocations for Z80 target and local label check. gas * config/tc-z80.c: Add new architectures: Z180 and eZ80. Add support for assembler code generated by SDCC. Add new relocation types. Add z80-elf target support. * config/tc-z80.h: Add z80-elf target support. Enable dollar local labels. Local labels starts from ".L". * testsuite/gas/all/fwdexp.d: Fix failure due to symbol conflict. * testsuite/gas/all/fwdexp.s: Likewise. * testsuite/gas/z80/suffix.d: Fix failure on ELF target. * testsuite/gas/z80/z80.exp: Add new tests * testsuite/gas/z80/dollar.d: New file. * testsuite/gas/z80/dollar.s: New file. * testsuite/gas/z80/ez80_adl_all.d: New file. * testsuite/gas/z80/ez80_adl_all.s: New file. * testsuite/gas/z80/ez80_adl_suf.d: New file. * testsuite/gas/z80/ez80_isuf.s: New file. * testsuite/gas/z80/ez80_z80_all.d: New file. * testsuite/gas/z80/ez80_z80_all.s: New file. * testsuite/gas/z80/ez80_z80_suf.d: New file. * testsuite/gas/z80/r800_extra.d: New file. * testsuite/gas/z80/r800_extra.s: New file. * testsuite/gas/z80/r800_ii8.d: New file. * testsuite/gas/z80/r800_z80_doc.d: New file. * testsuite/gas/z80/z180.d: New file. * testsuite/gas/z80/z180.s: New file. * testsuite/gas/z80/z180_z80_doc.d: New file. * testsuite/gas/z80/z80_doc.d: New file. * testsuite/gas/z80/z80_doc.s: New file. * testsuite/gas/z80/z80_ii8.d: New file. * testsuite/gas/z80/z80_ii8.s: New file. * testsuite/gas/z80/z80_in_f_c.d: New file. * testsuite/gas/z80/z80_in_f_c.s: New file. * testsuite/gas/z80/z80_op_ii_ld.d: New file. * testsuite/gas/z80/z80_op_ii_ld.s: New file. * testsuite/gas/z80/z80_out_c_0.d: New file. * testsuite/gas/z80/z80_out_c_0.s: New file. * testsuite/gas/z80/z80_reloc.d: New file. * testsuite/gas/z80/z80_reloc.s: New file. * testsuite/gas/z80/z80_sli.d: New file. * testsuite/gas/z80/z80_sli.s: New file. ld * Makefile.am: Add new target z80-elf * configure.tgt: Likewise. * emultempl/z80.em: Add support for eZ80 and Z180 architectures. * emulparams/elf32z80.sh: New file. * emultempl/z80elf.em: Likewise. * testsuite/ld-z80/arch_ez80_adl.d: Likewise. * testsuite/ld-z80/arch_ez80_z80.d: Likewise. * testsuite/ld-z80/arch_r800.d: Likewise. * testsuite/ld-z80/arch_z180.d: Likewise. * testsuite/ld-z80/arch_z80.d: Likewise. * testsuite/ld-z80/comb_arch_ez80_z80.d: Likewise. * testsuite/ld-z80/comb_arch_z180.d: Likewise. * testsuite/ld-z80/labels.s: Likewise. * testsuite/ld-z80/relocs.s: Likewise. * testsuite/ld-z80/relocs_b_ez80.d: Likewise. * testsuite/ld-z80/relocs_b_z80.d: Likewise. * testsuite/ld-z80/relocs_f_z80.d: Likewise. * testsuite/ld-z80/z80.exp: Likewise. opcodes * z80-dis.c: Add support for eZ80 and Z80 instructions.
Diffstat (limited to 'ld/emultempl')
-rw-r--r--ld/emultempl/z80.em79
-rw-r--r--ld/emultempl/z80elf.em133
2 files changed, 194 insertions, 18 deletions
diff --git a/ld/emultempl/z80.em b/ld/emultempl/z80.em
index 639650d..4c36cd8 100644
--- a/ld/emultempl/z80.em
+++ b/ld/emultempl/z80.em
@@ -27,11 +27,16 @@ fragment <<EOF
/* --- \begin{z80.em} */
/* Codes for machine types, bitwise or gives the code to use for the
output. */
-#define M_Z80STRICT 1
-#define M_Z80 3
-#define M_Z80FULL 7
-#define M_R800 11
-#define M_Z80ANY 15
+#define M_Z80STRICT 0x01
+#define M_Z80 0x03
+#define M_Z80FULL 0x07
+#define M_R800 0x10
+#define M_Z80ANY 0x0f
+#define M_GBZ80 0x20
+#define M_Z180 0x40
+#define M_EZ80_Z80 0x80
+#define M_EZ80_ADL 0x100
+#define M_ARCH_MASK 0xFF0
/* Bitwise or of the machine types seen so far. */
static int result_mach_type;
@@ -42,7 +47,7 @@ ${LDEMUL_BEFORE_PARSE} (void)
#ifndef TARGET_ /* I.e., if not generic. */
ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
#endif /* not TARGET_ */
- result_mach_type = M_Z80STRICT;
+ result_mach_type = 0;
}
@@ -67,7 +72,20 @@ ${LDEMUL_RECOGNIZED_FILE} (lang_input_statement_type *entry)
case bfd_mach_r800:
result_mach_type |= M_R800;
break;
+ case bfd_mach_gbz80:
+ result_mach_type |= M_GBZ80;
+ break;
+ case bfd_mach_z180:
+ result_mach_type |= M_Z180;
+ break;
+ case bfd_mach_ez80_z80:
+ result_mach_type |= M_EZ80_Z80;
+ break;
+ case bfd_mach_ez80_adl:
+ result_mach_type |= M_EZ80_ADL;
+ break;
default:
+ einfo (_("%P: warning: unknown machine type %u"), (unsigned)mach_type);
result_mach_type |= M_Z80ANY;
}
return FALSE;
@@ -81,23 +99,48 @@ gldz80_after_open (void)
after_open_default ();
- switch (result_mach_type)
+ switch (result_mach_type & M_ARCH_MASK)
{
- case M_Z80STRICT:
- mach_type = bfd_mach_z80strict;
- break;
- case M_Z80:
- mach_type = bfd_mach_z80;
- break;
- case M_Z80FULL:
- mach_type = bfd_mach_z80full;
- break;
+ case M_Z80 & M_ARCH_MASK:
case M_R800:
- mach_type = bfd_mach_r800;
+ case M_Z180:
+ case M_GBZ80:
+ case M_EZ80_Z80:
+ case M_EZ80_ADL:
+ case M_EZ80_Z80 | M_Z180:
+ /* valid combination */
+ break;
+ case M_EZ80_Z80 | M_EZ80_ADL:
+ case M_EZ80_Z80 | M_EZ80_ADL | M_Z180:
+ case M_EZ80_ADL | M_Z180:
+ /* combination may cause invalid objdump output */
+ /* but it is possible for mixed ADL/Z80 code */
+ einfo (_("%P: warning: mixing ADL and Z80 mode binaries, objdump may generate invalid output"));
break;
default:
- mach_type = 0;
+ /* invalid combination: for example Z180 + R800 */
+ einfo (_("%P: warning: incompatible object files linked, result code might not work"));
}
+
+ if ((result_mach_type & M_EZ80_ADL) == M_EZ80_ADL)
+ mach_type = bfd_mach_ez80_adl;
+ else if ((result_mach_type & M_EZ80_Z80) == M_EZ80_Z80)
+ mach_type = bfd_mach_ez80_z80;
+ else if ((result_mach_type & M_Z180) == M_Z180)
+ mach_type = bfd_mach_z180;
+ else if ((result_mach_type & M_R800) == M_R800)
+ mach_type = bfd_mach_r800;
+ else if ((result_mach_type & M_GBZ80) == M_GBZ80)
+ mach_type = bfd_mach_gbz80;
+ else if ((result_mach_type & M_Z80FULL) == M_Z80FULL)
+ mach_type = bfd_mach_z80full; /* TODO: remove it */
+ else if ((result_mach_type & M_Z80) == M_Z80)
+ mach_type = bfd_mach_z80;
+ else if ((result_mach_type & M_Z80STRICT) == M_Z80STRICT)
+ mach_type = bfd_mach_z80strict; /* TODO: remove this */
+ else
+ mach_type = bfd_arch_unknown;
+
bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach_type);
}
/* --- \end{z80.em} */
diff --git a/ld/emultempl/z80elf.em b/ld/emultempl/z80elf.em
new file mode 100644
index 0000000..7a55fff
--- /dev/null
+++ b/ld/emultempl/z80elf.em
@@ -0,0 +1,133 @@
+# This shell script emits C code -*- C -*-
+# to keep track of the machine type of Z80 object files
+# It does some substitutions.
+# Copyright (C) 2005-2019 Free Software Foundation, Inc.
+# This file is part of the GNU Binutils.
+#
+# 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.
+
+fragment <<EOF
+/* --- \begin{z80.em} */
+
+#include "elf/z80.h"
+
+static void
+gld${EMULATION_NAME}_after_open (void);
+
+static int result_mach_type;
+
+/* Set the machine type of the output file based on result_mach_type. */
+static void
+z80_elf_after_open (void)
+{
+ unsigned int mach = 0;
+ bfd *abfd;
+
+ /* For now, make sure all object files are of the same architecture.
+ We may try to merge object files with different architecture together. */
+ for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
+ {
+ unsigned long new_mach;
+ new_mach = elf_elfheader (abfd)->e_flags & 0xff;
+ if (!mach)
+ mach = new_mach;
+ else if (mach != new_mach)
+ {
+ if ((new_mach == EF_Z80_MACH_R800 || mach == EF_Z80_MACH_R800) ||
+ (new_mach == EF_Z80_MACH_GBZ80 || mach == EF_Z80_MACH_GBZ80))
+ einfo (_("%F%P: %pB: Istruction set of object files mismatched\n"),
+ abfd);
+ else if (mach < new_mach)
+ mach = new_mach;
+ }
+ }
+ switch (mach & 0xff)
+ {
+ case EF_Z80_MACH_Z80:
+ mach = bfd_mach_z80;
+ break;
+ case EF_Z80_MACH_Z180:
+ mach = bfd_mach_z180;
+ break;
+ case EF_Z80_MACH_R800:
+ mach = bfd_mach_r800;
+ break;
+ case EF_Z80_MACH_EZ80_Z80:
+ mach = bfd_mach_ez80_z80;
+ break;
+ case EF_Z80_MACH_EZ80_ADL:
+ mach = bfd_mach_ez80_adl;
+ break;
+ case EF_Z80_MACH_GBZ80:
+ mach = bfd_mach_gbz80;
+ break;
+ default:
+ mach = (unsigned)-1;
+ }
+
+ bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach);
+ result_mach_type = mach;
+
+ /* Call the standard elf routine. */
+ gld${EMULATION_NAME}_after_open ();
+}
+
+static void
+z80_elf_finish (void)
+{
+ bfd *abfd;
+
+ abfd = link_info.output_bfd;
+
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ {
+ unsigned e_flags;
+ switch (result_mach_type)
+ {
+ case bfd_mach_z80strict:
+ case bfd_mach_z80:
+ case bfd_mach_z80full:
+ e_flags = EF_Z80_MACH_Z80;
+ break;
+ case bfd_mach_r800:
+ e_flags = EF_Z80_MACH_R800;
+ break;
+ case bfd_mach_gbz80:
+ e_flags = EF_Z80_MACH_GBZ80;
+ break;
+ case bfd_mach_z180:
+ e_flags = EF_Z80_MACH_Z180;
+ break;
+ case bfd_mach_ez80_z80:
+ e_flags = EF_Z80_MACH_EZ80_Z80;
+ break;
+ case bfd_mach_ez80_adl:
+ e_flags = EF_Z80_MACH_EZ80_ADL;
+ break;
+ default:
+ e_flags = ~0;
+ }
+ elf_elfheader (abfd)->e_flags = (elf_elfheader (abfd)->e_flags & ~0xff) | e_flags;
+ }
+
+ finish_default ();
+}
+
+/* --- \end{z80.em} */
+EOF
+
+LDEMUL_AFTER_OPEN=z80_elf_after_open
+LDEMUL_FINISH=z80_elf_finish