Commit | Line | Data |
---|---|---|
6655dba2 SB |
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-2019 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 | /* Set the machine type of the output file based on result_mach_type. */ | |
33 | static void | |
34 | z80_elf_after_open (void) | |
35 | { | |
36 | unsigned int mach = 0; | |
37 | bfd *abfd; | |
38 | ||
39 | /* For now, make sure all object files are of the same architecture. | |
40 | We may try to merge object files with different architecture together. */ | |
41 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) | |
42 | { | |
43 | unsigned long new_mach; | |
44 | new_mach = elf_elfheader (abfd)->e_flags & 0xff; | |
45 | if (!mach) | |
46 | mach = new_mach; | |
47 | else if (mach != new_mach) | |
48 | { | |
49 | if ((new_mach == EF_Z80_MACH_R800 || mach == EF_Z80_MACH_R800) || | |
50 | (new_mach == EF_Z80_MACH_GBZ80 || mach == EF_Z80_MACH_GBZ80)) | |
51 | einfo (_("%F%P: %pB: Istruction set of object files mismatched\n"), | |
52 | abfd); | |
53 | else if (mach < new_mach) | |
54 | mach = new_mach; | |
55 | } | |
56 | } | |
57 | switch (mach & 0xff) | |
58 | { | |
59 | case EF_Z80_MACH_Z80: | |
60 | mach = bfd_mach_z80; | |
61 | break; | |
62 | case EF_Z80_MACH_Z180: | |
63 | mach = bfd_mach_z180; | |
64 | break; | |
65 | case EF_Z80_MACH_R800: | |
66 | mach = bfd_mach_r800; | |
67 | break; | |
68 | case EF_Z80_MACH_EZ80_Z80: | |
69 | mach = bfd_mach_ez80_z80; | |
70 | break; | |
71 | case EF_Z80_MACH_EZ80_ADL: | |
72 | mach = bfd_mach_ez80_adl; | |
73 | break; | |
74 | case EF_Z80_MACH_GBZ80: | |
75 | mach = bfd_mach_gbz80; | |
76 | break; | |
77 | default: | |
78 | mach = (unsigned)-1; | |
79 | } | |
80 | ||
81 | bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach); | |
82 | result_mach_type = mach; | |
83 | ||
84 | /* Call the standard elf routine. */ | |
85 | gld${EMULATION_NAME}_after_open (); | |
86 | } | |
87 | ||
88 | static void | |
89 | z80_elf_finish (void) | |
90 | { | |
91 | bfd *abfd; | |
92 | ||
93 | abfd = link_info.output_bfd; | |
94 | ||
95 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | |
96 | { | |
97 | unsigned e_flags; | |
98 | switch (result_mach_type) | |
99 | { | |
100 | case bfd_mach_z80strict: | |
101 | case bfd_mach_z80: | |
102 | case bfd_mach_z80full: | |
103 | e_flags = EF_Z80_MACH_Z80; | |
104 | break; | |
105 | case bfd_mach_r800: | |
106 | e_flags = EF_Z80_MACH_R800; | |
107 | break; | |
108 | case bfd_mach_gbz80: | |
109 | e_flags = EF_Z80_MACH_GBZ80; | |
110 | break; | |
111 | case bfd_mach_z180: | |
112 | e_flags = EF_Z80_MACH_Z180; | |
113 | break; | |
114 | case bfd_mach_ez80_z80: | |
115 | e_flags = EF_Z80_MACH_EZ80_Z80; | |
116 | break; | |
117 | case bfd_mach_ez80_adl: | |
118 | e_flags = EF_Z80_MACH_EZ80_ADL; | |
119 | break; | |
120 | default: | |
121 | e_flags = ~0; | |
122 | } | |
123 | elf_elfheader (abfd)->e_flags = (elf_elfheader (abfd)->e_flags & ~0xff) | e_flags; | |
124 | } | |
125 | ||
126 | finish_default (); | |
127 | } | |
128 | ||
129 | /* --- \end{z80.em} */ | |
130 | EOF | |
131 | ||
132 | LDEMUL_AFTER_OPEN=z80_elf_after_open | |
133 | LDEMUL_FINISH=z80_elf_finish |