Add support for the GBZ80 and Z80N variants of the Z80 architecture, and add DWARF...
[deliverable/binutils-gdb.git] / ld / emultempl / z80.em
CommitLineData
3c9b82ba
NC
1# This shell script emits C code -*- C -*-
2# to keep track of the machine type of Z80 object files
3# It does some substitutions.
b3adc24a 4# Copyright (C) 2005-2020 Free Software Foundation, Inc.
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
3c9b82ba 21
92b93329 22fragment <<EOF
3c9b82ba 23/* --- \begin{z80.em} */
9fc0b501
SB
24
25#include "elf/z80.h"
3c9b82ba 26
92b93329 27static void
9fc0b501
SB
28gld${EMULATION_NAME}_after_open (void);
29
30static int result_mach_type;
31
32struct z80_mach_info
3c9b82ba 33{
9fc0b501
SB
34 unsigned eflags;
35 unsigned bfd_mach;
36 const int *compat; /* back compatible machines */
37};
3c9b82ba 38
9fc0b501
SB
39static const int
40back_compat_z80[] = {bfd_mach_z80, -1};
3c9b82ba 41
9fc0b501
SB
42static const int
43back_compat_z180[] = {bfd_mach_z180, bfd_mach_z80, -1};
44
45static const int
46back_compat_ez80[] = {bfd_mach_ez80_z80, bfd_mach_z180, bfd_mach_z80, -1};
47
48static const struct z80_mach_info
49z80_mach_info[] =
3c9b82ba 50{
9fc0b501
SB
51 { EF_Z80_MACH_Z80, bfd_mach_z80, NULL },
52 { EF_Z80_MACH_Z80, bfd_mach_z80strict, back_compat_z80 },
53 { EF_Z80_MACH_Z80, bfd_mach_z80full, back_compat_z80 },
54 { EF_Z80_MACH_Z180, bfd_mach_z180, back_compat_z80 },
55 { EF_Z80_MACH_EZ80_Z80, bfd_mach_ez80_z80, back_compat_z180 },
56 { EF_Z80_MACH_EZ80_ADL, bfd_mach_ez80_adl, back_compat_ez80 },
57 { EF_Z80_MACH_Z80N, bfd_mach_z80n, back_compat_z80 },
58 { EF_Z80_MACH_GBZ80, bfd_mach_gbz80, NULL },
59 { EF_Z80_MACH_R800, bfd_mach_r800, back_compat_z80 }
60};
61/*
62static const struct z80_mach_info *
63z80_mach_info_by_eflags (unsigned int eflags)
64{
65 const struct z80_mach_info *p;
66 const struct z80_mach_info *e;
3c9b82ba 67
9fc0b501
SB
68 eflags &= EF_Z80_MACH_MSK;
69 p = &z80_mach_info[0];
70 e = &z80_mach_info[sizeof(z80_mach_info)/sizeof(*z80_mach_info)];
71 for (; p != e; ++p)
72 if (eflags == p->eflags)
73 return p;
74 return NULL;
75}*/
76
77static const struct z80_mach_info *
78z80_mach_info_by_mach (unsigned int bfd_mach)
79{
80 const struct z80_mach_info *p;
81 const struct z80_mach_info *e;
82
83 p = &z80_mach_info[0];
84 e = &z80_mach_info[sizeof(z80_mach_info)/sizeof(*z80_mach_info)];
85 for (; p != e; ++p)
86 if (bfd_mach == p->bfd_mach)
87 return p;
88 return NULL;
89}
90
91static const struct z80_mach_info *
92z80_combine_mach (const struct z80_mach_info *m1,
93 const struct z80_mach_info *m2)
94{
95 int i;
96 int mach;
97 if (m1->compat != NULL)
98 for (i = 0; (mach = m1->compat[i]) >= 0; ++i)
99 if ((unsigned)mach == m2->bfd_mach)
100 return m1;
101 if (m2->compat != NULL)
102 for (i = 0; (mach = m2->compat[i]) >= 0; ++i)
103 if ((unsigned)mach == m1->bfd_mach)
104 return m2;
105 /* incompatible mach */
106 return NULL;
3c9b82ba
NC
107}
108
109/* Set the machine type of the output file based on result_mach_type. */
110static void
9fc0b501 111z80_after_open (void)
3c9b82ba 112{
9fc0b501
SB
113 const struct z80_mach_info *mach = NULL;
114 bfd *abfd;
3c9b82ba 115
9fc0b501
SB
116 /* For now, make sure all object files are of the same architecture.
117 We may try to merge object files with different architecture together. */
118 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
3c9b82ba 119 {
9fc0b501
SB
120 const struct z80_mach_info *new_mach;
121 /*new_mach = z80_mach_info_by_eflags (elf_elfheader (abfd)->e_flags);*/
122 new_mach = z80_mach_info_by_mach(bfd_get_mach (abfd));
123 if (mach == NULL)
124 mach = new_mach;
125 else if (mach != new_mach)
126 mach = z80_combine_mach (mach, new_mach);
127 if (mach == NULL)
128 einfo (_("%F%P: %pB: Instruction sets of object files incompatible\n"),
129 abfd);
130 }
131 if (mach != NULL)
132 {
133 bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach->bfd_mach);
134 result_mach_type = mach->bfd_mach;
3c9b82ba 135 }
6655dba2 136 else
9fc0b501
SB
137 einfo (_("%F%P: %pB: Unknown machine type\n"),
138 abfd);
6655dba2 139
9fc0b501
SB
140 /* Call the standard elf routine. */
141 gld${EMULATION_NAME}_after_open ();
3c9b82ba 142}
9fc0b501
SB
143
144#ifndef TARGET_IS_elf32z80
145static void
146gld${EMULATION_NAME}_after_open (void)
147{
148}
149#endif
150
3c9b82ba
NC
151/* --- \end{z80.em} */
152EOF
9fc0b501
SB
153
154LDEMUL_AFTER_OPEN=z80_after_open
This page took 0.752981 seconds and 4 git commands to generate.