12a6b7db3Sskrll /* BFD library support routines for the Z80 architecture.
2*cb63e24eSchristos Copyright (C) 2005-2024 Free Software Foundation, Inc.
32a6b7db3Sskrll Contributed by Arnold Metselaar <arnold_m@operamail.com>
42a6b7db3Sskrll
52a6b7db3Sskrll This file is part of BFD, the Binary File Descriptor library.
62a6b7db3Sskrll
72a6b7db3Sskrll This program is free software; you can redistribute it and/or modify
82a6b7db3Sskrll it under the terms of the GNU General Public License as published by
92a6b7db3Sskrll the Free Software Foundation; either version 3 of the License, or
102a6b7db3Sskrll (at your option) any later version.
112a6b7db3Sskrll
122a6b7db3Sskrll This program is distributed in the hope that it will be useful,
132a6b7db3Sskrll but WITHOUT ANY WARRANTY; without even the implied warranty of
142a6b7db3Sskrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152a6b7db3Sskrll GNU General Public License for more details.
162a6b7db3Sskrll
172a6b7db3Sskrll You should have received a copy of the GNU General Public License
182a6b7db3Sskrll along with this program; if not, write to the Free Software
192a6b7db3Sskrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
202a6b7db3Sskrll MA 02110-1301, USA. */
212a6b7db3Sskrll
222a6b7db3Sskrll #include "sysdep.h"
232a6b7db3Sskrll #include "bfd.h"
242a6b7db3Sskrll #include "libbfd.h"
252a6b7db3Sskrll
262a6b7db3Sskrll const bfd_arch_info_type bfd_z80_arch;
272a6b7db3Sskrll
282a6b7db3Sskrll /* This routine is provided two arch_infos and
292a6b7db3Sskrll returns whether they'd be compatible. */
302a6b7db3Sskrll
312a6b7db3Sskrll static const bfd_arch_info_type *
compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)322a6b7db3Sskrll compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
332a6b7db3Sskrll {
344f645668Schristos if (a->arch != b->arch || a->arch != bfd_arch_z80)
352a6b7db3Sskrll return NULL;
362a6b7db3Sskrll
372a6b7db3Sskrll if (a->mach == b->mach)
382a6b7db3Sskrll return a;
394f645668Schristos switch (a->mach)
404f645668Schristos {
414f645668Schristos case bfd_mach_z80:
424f645668Schristos case bfd_mach_z80full:
434f645668Schristos case bfd_mach_z80strict:
444f645668Schristos switch (b->mach)
454f645668Schristos {
464f645668Schristos case bfd_mach_z80:
474f645668Schristos case bfd_mach_z80full:
484f645668Schristos case bfd_mach_z80strict:
494f645668Schristos return & bfd_z80_arch;
504f645668Schristos case bfd_mach_z180:
514f645668Schristos case bfd_mach_ez80_z80:
524f645668Schristos case bfd_mach_ez80_adl:
534f645668Schristos case bfd_mach_z80n:
544f645668Schristos case bfd_mach_r800:
554f645668Schristos return b;
564f645668Schristos }
574f645668Schristos break;
584f645668Schristos case bfd_mach_z80n:
594f645668Schristos case bfd_mach_r800:
604f645668Schristos switch (b->mach)
614f645668Schristos {
624f645668Schristos case bfd_mach_z80:
634f645668Schristos case bfd_mach_z80full:
644f645668Schristos case bfd_mach_z80strict:
654f645668Schristos return a;
664f645668Schristos }
674f645668Schristos break;
684f645668Schristos case bfd_mach_z180:
694f645668Schristos switch (b->mach)
704f645668Schristos {
714f645668Schristos case bfd_mach_z80:
724f645668Schristos case bfd_mach_z80full:
734f645668Schristos case bfd_mach_z80strict:
744f645668Schristos return a;
754f645668Schristos case bfd_mach_ez80_z80:
764f645668Schristos case bfd_mach_ez80_adl:
774f645668Schristos return b;
784f645668Schristos }
794f645668Schristos break;
804f645668Schristos case bfd_mach_ez80_z80:
814f645668Schristos case bfd_mach_ez80_adl:
824f645668Schristos switch (b->mach)
834f645668Schristos {
844f645668Schristos case bfd_mach_z80:
854f645668Schristos case bfd_mach_z80full:
864f645668Schristos case bfd_mach_z80strict:
874f645668Schristos case bfd_mach_z180:
884f645668Schristos case bfd_mach_ez80_z80:
894f645668Schristos return a;
904f645668Schristos case bfd_mach_ez80_adl:
914f645668Schristos return b;
924f645668Schristos }
934f645668Schristos break;
944f645668Schristos case bfd_mach_gbz80:
954f645668Schristos return NULL;
964f645668Schristos }
972a6b7db3Sskrll
984f645668Schristos return NULL;
992a6b7db3Sskrll }
1002a6b7db3Sskrll
1016f4ced0bSchristos #define N(name,print,bits,default,next) \
1026f4ced0bSchristos { 16, bits, 8, bfd_arch_z80, name, "z80", print, 0, default, \
1036f4ced0bSchristos compatible, bfd_default_scan, bfd_arch_default_fill, next, 0 }
1042a6b7db3Sskrll
1052a6b7db3Sskrll #define M(n) &arch_info_struct[n]
1062a6b7db3Sskrll
1072a6b7db3Sskrll static const bfd_arch_info_type arch_info_struct[] =
1082a6b7db3Sskrll {
1094f645668Schristos N (bfd_mach_z80, "z80", 16, true, M(1)),
1104f645668Schristos N (bfd_mach_z80strict, "z80-strict", 16, false, M(2)),
1114f645668Schristos N (bfd_mach_z80full, "z80-full", 16, false, M(3)),
1124f645668Schristos N (bfd_mach_r800, "r800", 16, false, M(4)),
1134f645668Schristos N (bfd_mach_gbz80, "gbz80", 16, false, M(5)),
1144f645668Schristos N (bfd_mach_z180, "z180", 16, false, M(6)),
1154f645668Schristos N (bfd_mach_z80n, "z80n", 16, false, M(7)),
1164f645668Schristos N (bfd_mach_ez80_z80, "ez80-z80", 16, false, M(8)),
1174f645668Schristos N (bfd_mach_ez80_adl, "ez80-adl", 24, false, NULL)
1182a6b7db3Sskrll };
1192a6b7db3Sskrll
1206f4ced0bSchristos const bfd_arch_info_type bfd_z80_arch =
1214f645668Schristos N (bfd_mach_z80, "z80", 16, true, M(1));
122