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.
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.
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.
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,
22 LDEMUL_BEFORE_PARSE=gldz80_before_parse
23 LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file
24 LDEMUL_AFTER_OPEN=gldz80_after_open
27 /* --- \begin{z80.em} */
28 /* Codes for machine types, bitwise or gives the code to use for the
30 #define M_Z80STRICT 0x01
32 #define M_Z80FULL 0x07
37 #define M_EZ80_Z80 0x80
38 #define M_EZ80_ADL 0x100
39 #define M_ARCH_MASK 0xFF0
41 /* Bitwise or of the machine types seen so far. */
42 static int result_mach_type;
45 ${LDEMUL_BEFORE_PARSE} (void)
47 #ifndef TARGET_ /* I.e., if not generic. */
48 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
49 #endif /* not TARGET_ */
54 /* Update result_mach_type. */
56 ${LDEMUL_RECOGNIZED_FILE} (lang_input_statement_type *entry)
58 unsigned long mach_type;
60 mach_type = bfd_get_mach (entry->the_bfd);
63 case bfd_mach_z80strict:
64 result_mach_type |= M_Z80STRICT;
67 result_mach_type |= M_Z80;
69 case bfd_mach_z80full:
70 result_mach_type |= M_Z80FULL;
73 result_mach_type |= M_R800;
76 result_mach_type |= M_GBZ80;
79 result_mach_type |= M_Z180;
81 case bfd_mach_ez80_z80:
82 result_mach_type |= M_EZ80_Z80;
84 case bfd_mach_ez80_adl:
85 result_mach_type |= M_EZ80_ADL;
88 einfo (_("%P: warning: unknown machine type %u"), (unsigned)mach_type);
89 result_mach_type |= M_Z80ANY;
94 /* Set the machine type of the output file based on result_mach_type. */
96 gldz80_after_open (void)
98 unsigned long mach_type;
100 after_open_default ();
102 switch (result_mach_type & M_ARCH_MASK)
104 case M_Z80 & M_ARCH_MASK:
110 case M_EZ80_Z80 | M_Z180:
111 /* valid combination */
113 case M_EZ80_Z80 | M_EZ80_ADL:
114 case M_EZ80_Z80 | M_EZ80_ADL | M_Z180:
115 case M_EZ80_ADL | M_Z180:
116 /* combination may cause invalid objdump output */
117 /* but it is possible for mixed ADL/Z80 code */
118 einfo (_("%P: warning: mixing ADL and Z80 mode binaries, objdump may generate invalid output"));
121 /* invalid combination: for example Z180 + R800 */
122 einfo (_("%P: warning: incompatible object files linked, result code might not work"));
125 if ((result_mach_type & M_EZ80_ADL) == M_EZ80_ADL)
126 mach_type = bfd_mach_ez80_adl;
127 else if ((result_mach_type & M_EZ80_Z80) == M_EZ80_Z80)
128 mach_type = bfd_mach_ez80_z80;
129 else if ((result_mach_type & M_Z180) == M_Z180)
130 mach_type = bfd_mach_z180;
131 else if ((result_mach_type & M_R800) == M_R800)
132 mach_type = bfd_mach_r800;
133 else if ((result_mach_type & M_GBZ80) == M_GBZ80)
134 mach_type = bfd_mach_gbz80;
135 else if ((result_mach_type & M_Z80FULL) == M_Z80FULL)
136 mach_type = bfd_mach_z80full; /* TODO: remove it */
137 else if ((result_mach_type & M_Z80) == M_Z80)
138 mach_type = bfd_mach_z80;
139 else if ((result_mach_type & M_Z80STRICT) == M_Z80STRICT)
140 mach_type = bfd_mach_z80strict; /* TODO: remove this */
142 mach_type = bfd_arch_unknown;
144 bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach_type);
146 /* --- \end{z80.em} */