| 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 | LDEMUL_BEFORE_PARSE=gldz80_before_parse |
| 23 | LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file |
| 24 | LDEMUL_AFTER_OPEN=gldz80_after_open |
| 25 | |
| 26 | fragment <<EOF |
| 27 | /* --- \begin{z80.em} */ |
| 28 | /* Codes for machine types, bitwise or gives the code to use for the |
| 29 | output. */ |
| 30 | #define M_Z80STRICT 0x01 |
| 31 | #define M_Z80 0x03 |
| 32 | #define M_Z80FULL 0x07 |
| 33 | #define M_R800 0x10 |
| 34 | #define M_Z80ANY 0x0f |
| 35 | #define M_GBZ80 0x20 |
| 36 | #define M_Z180 0x40 |
| 37 | #define M_EZ80_Z80 0x80 |
| 38 | #define M_EZ80_ADL 0x100 |
| 39 | #define M_ARCH_MASK 0xFF0 |
| 40 | |
| 41 | /* Bitwise or of the machine types seen so far. */ |
| 42 | static int result_mach_type; |
| 43 | |
| 44 | static void |
| 45 | ${LDEMUL_BEFORE_PARSE} (void) |
| 46 | { |
| 47 | #ifndef TARGET_ /* I.e., if not generic. */ |
| 48 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
| 49 | #endif /* not TARGET_ */ |
| 50 | result_mach_type = 0; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /* Update result_mach_type. */ |
| 55 | static bfd_boolean |
| 56 | ${LDEMUL_RECOGNIZED_FILE} (lang_input_statement_type *entry) |
| 57 | { |
| 58 | unsigned long mach_type; |
| 59 | |
| 60 | mach_type = bfd_get_mach (entry->the_bfd); |
| 61 | switch (mach_type) |
| 62 | { |
| 63 | case bfd_mach_z80strict: |
| 64 | result_mach_type |= M_Z80STRICT; |
| 65 | break; |
| 66 | case bfd_mach_z80: |
| 67 | result_mach_type |= M_Z80; |
| 68 | break; |
| 69 | case bfd_mach_z80full: |
| 70 | result_mach_type |= M_Z80FULL; |
| 71 | break; |
| 72 | case bfd_mach_r800: |
| 73 | result_mach_type |= M_R800; |
| 74 | break; |
| 75 | case bfd_mach_gbz80: |
| 76 | result_mach_type |= M_GBZ80; |
| 77 | break; |
| 78 | case bfd_mach_z180: |
| 79 | result_mach_type |= M_Z180; |
| 80 | break; |
| 81 | case bfd_mach_ez80_z80: |
| 82 | result_mach_type |= M_EZ80_Z80; |
| 83 | break; |
| 84 | case bfd_mach_ez80_adl: |
| 85 | result_mach_type |= M_EZ80_ADL; |
| 86 | break; |
| 87 | default: |
| 88 | einfo (_("%P: warning: unknown machine type %u"), (unsigned)mach_type); |
| 89 | result_mach_type |= M_Z80ANY; |
| 90 | } |
| 91 | return FALSE; |
| 92 | } |
| 93 | |
| 94 | /* Set the machine type of the output file based on result_mach_type. */ |
| 95 | static void |
| 96 | gldz80_after_open (void) |
| 97 | { |
| 98 | unsigned long mach_type; |
| 99 | |
| 100 | after_open_default (); |
| 101 | |
| 102 | switch (result_mach_type & M_ARCH_MASK) |
| 103 | { |
| 104 | case M_Z80 & M_ARCH_MASK: |
| 105 | case M_R800: |
| 106 | case M_Z180: |
| 107 | case M_GBZ80: |
| 108 | case M_EZ80_Z80: |
| 109 | case M_EZ80_ADL: |
| 110 | case M_EZ80_Z80 | M_Z180: |
| 111 | /* valid combination */ |
| 112 | break; |
| 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")); |
| 119 | break; |
| 120 | default: |
| 121 | /* invalid combination: for example Z180 + R800 */ |
| 122 | einfo (_("%P: warning: incompatible object files linked, result code might not work")); |
| 123 | } |
| 124 | |
| 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 */ |
| 141 | else |
| 142 | mach_type = bfd_arch_unknown; |
| 143 | |
| 144 | bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach_type); |
| 145 | } |
| 146 | /* --- \end{z80.em} */ |
| 147 | EOF |