z80.em 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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-2015 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. LDEMUL_BEFORE_PARSE=gldz80_before_parse
  22. LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file
  23. LDEMUL_AFTER_OPEN=gldz80_after_open
  24. fragment <<EOF
  25. /* --- \begin{z80.em} */
  26. /* Codes for machine types, bitwise or gives the code to use for the
  27. output. */
  28. #define M_Z80STRICT 1
  29. #define M_Z80 3
  30. #define M_Z80FULL 7
  31. #define M_R800 11
  32. #define M_Z80ANY 15
  33. /* Bitwise or of the machine types seen so far. */
  34. static int result_mach_type;
  35. static void
  36. ${LDEMUL_BEFORE_PARSE} (void)
  37. {
  38. #ifndef TARGET_ /* I.e., if not generic. */
  39. ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
  40. #endif /* not TARGET_ */
  41. result_mach_type = M_Z80STRICT;
  42. }
  43. /* Update result_mach_type. */
  44. static bfd_boolean
  45. ${LDEMUL_RECOGNIZED_FILE} (lang_input_statement_type *entry)
  46. {
  47. unsigned long mach_type;
  48. mach_type = bfd_get_mach (entry->the_bfd);
  49. switch (mach_type)
  50. {
  51. case bfd_mach_z80strict:
  52. result_mach_type |= M_Z80STRICT;
  53. break;
  54. case bfd_mach_z80:
  55. result_mach_type |= M_Z80;
  56. break;
  57. case bfd_mach_z80full:
  58. result_mach_type |= M_Z80FULL;
  59. break;
  60. case bfd_mach_r800:
  61. result_mach_type |= M_R800;
  62. break;
  63. default:
  64. result_mach_type |= M_Z80ANY;
  65. }
  66. return FALSE;
  67. }
  68. /* Set the machine type of the output file based on result_mach_type. */
  69. static void
  70. gldz80_after_open (void)
  71. {
  72. unsigned long mach_type;
  73. after_open_default ();
  74. switch (result_mach_type)
  75. {
  76. case M_Z80STRICT:
  77. mach_type = bfd_mach_z80strict;
  78. break;
  79. case M_Z80:
  80. mach_type = bfd_mach_z80;
  81. break;
  82. case M_Z80FULL:
  83. mach_type = bfd_mach_z80full;
  84. break;
  85. case M_R800:
  86. mach_type = bfd_mach_r800;
  87. break;
  88. default:
  89. mach_type = 0;
  90. }
  91. bfd_set_arch_mach (link_info.output_bfd, bfd_arch_z80, mach_type);
  92. }
  93. /* --- \end{z80.em} */
  94. EOF