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