Add support for the GBZ80 and Z80N variants of the Z80 architecture, and add DWARF...
[deliverable/binutils-gdb.git] / ld / emultempl / z80.em
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.
4 # Copyright (C) 2005-2020 Free Software Foundation, Inc.
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.
21
22 fragment <<EOF
23 /* --- \begin{z80.em} */
24
25 #include "elf/z80.h"
26
27 static void
28 gld${EMULATION_NAME}_after_open (void);
29
30 static int result_mach_type;
31
32 struct z80_mach_info
33 {
34 unsigned eflags;
35 unsigned bfd_mach;
36 const int *compat; /* back compatible machines */
37 };
38
39 static const int
40 back_compat_z80[] = {bfd_mach_z80, -1};
41
42 static const int
43 back_compat_z180[] = {bfd_mach_z180, bfd_mach_z80, -1};
44
45 static const int
46 back_compat_ez80[] = {bfd_mach_ez80_z80, bfd_mach_z180, bfd_mach_z80, -1};
47
48 static const struct z80_mach_info
49 z80_mach_info[] =
50 {
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 /*
62 static const struct z80_mach_info *
63 z80_mach_info_by_eflags (unsigned int eflags)
64 {
65 const struct z80_mach_info *p;
66 const struct z80_mach_info *e;
67
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
77 static const struct z80_mach_info *
78 z80_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
91 static const struct z80_mach_info *
92 z80_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;
107 }
108
109 /* Set the machine type of the output file based on result_mach_type. */
110 static void
111 z80_after_open (void)
112 {
113 const struct z80_mach_info *mach = NULL;
114 bfd *abfd;
115
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)
119 {
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;
135 }
136 else
137 einfo (_("%F%P: %pB: Unknown machine type\n"),
138 abfd);
139
140 /* Call the standard elf routine. */
141 gld${EMULATION_NAME}_after_open ();
142 }
143
144 #ifndef TARGET_IS_elf32z80
145 static void
146 gld${EMULATION_NAME}_after_open (void)
147 {
148 }
149 #endif
150
151 /* --- \end{z80.em} */
152 EOF
153
154 LDEMUL_AFTER_OPEN=z80_after_open
This page took 0.046106 seconds and 4 git commands to generate.