xref: /netbsd-src/external/gpl3/binutils/dist/bfd/cpu-kvx.c (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1*cb63e24eSchristos /* BFD support for KVX.
2*cb63e24eSchristos    Copyright (C) 2009-2024 Free Software Foundation, Inc.
3*cb63e24eSchristos    Contributed by Kalray SA.
4*cb63e24eSchristos 
5*cb63e24eSchristos    This file is part of BFD, the Binary File Descriptor library.
6*cb63e24eSchristos 
7*cb63e24eSchristos    This program is free software; you can redistribute it and/or modify
8*cb63e24eSchristos    it under the terms of the GNU General Public License as published by
9*cb63e24eSchristos    the Free Software Foundation; either version 3 of the License, or
10*cb63e24eSchristos    (at your option) any later version.
11*cb63e24eSchristos 
12*cb63e24eSchristos    This program is distributed in the hope that it will be useful,
13*cb63e24eSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*cb63e24eSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*cb63e24eSchristos    GNU General Public License for more details.
16*cb63e24eSchristos 
17*cb63e24eSchristos    You should have received a copy of the GNU General Public License
18*cb63e24eSchristos    along with this program; see the file COPYING3. If not,
19*cb63e24eSchristos    see <http://www.gnu.org/licenses/>.  */
20*cb63e24eSchristos 
21*cb63e24eSchristos #include "sysdep.h"
22*cb63e24eSchristos #include "bfd.h"
23*cb63e24eSchristos #include "libbfd.h"
24*cb63e24eSchristos 
25*cb63e24eSchristos /* This routine is provided two arch_infos and returns if machines
26*cb63e24eSchristos    are compatible.
27*cb63e24eSchristos */
28*cb63e24eSchristos 
29*cb63e24eSchristos static const bfd_arch_info_type *
kvx_compatible(const bfd_arch_info_type * a,const bfd_arch_info_type * b)30*cb63e24eSchristos kvx_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
31*cb63e24eSchristos {
32*cb63e24eSchristos   long amach =  a->mach, bmach =  b->mach;
33*cb63e24eSchristos   /* If a & b are for different architecture we can do nothing.  */
34*cb63e24eSchristos   if (a->arch != b->arch)
35*cb63e24eSchristos     return NULL;
36*cb63e24eSchristos 
37*cb63e24eSchristos   if ((amach == bfd_mach_kv3_1_64 && bmach == bfd_mach_kv3_1_usr)
38*cb63e24eSchristos       || (amach == bfd_mach_kv3_2_64 && bmach == bfd_mach_kv3_2_usr))
39*cb63e24eSchristos     return b;
40*cb63e24eSchristos 
41*cb63e24eSchristos   if ((bmach == bfd_mach_kv3_1_64 && amach == bfd_mach_kv3_1_usr)
42*cb63e24eSchristos       || (bmach == bfd_mach_kv3_2_64 && amach == bfd_mach_kv3_2_usr))
43*cb63e24eSchristos     return a;
44*cb63e24eSchristos 
45*cb63e24eSchristos   /* Otherwise if either a or b is the 'default' machine
46*cb63e24eSchristos    * then it can be polymorphed into the other.
47*cb63e24eSchristos    * This will enable to execute merge_private_bfd_data
48*cb63e24eSchristos    */
49*cb63e24eSchristos   if (a->the_default)
50*cb63e24eSchristos     return b;
51*cb63e24eSchristos 
52*cb63e24eSchristos   if (b->the_default)
53*cb63e24eSchristos     return a;
54*cb63e24eSchristos 
55*cb63e24eSchristos   /* We do not want to transmute some machine into another one */
56*cb63e24eSchristos   if (amach != bmach)
57*cb63e24eSchristos     return NULL;
58*cb63e24eSchristos 
59*cb63e24eSchristos   /* If a & b are for the same machine then all is well.  */
60*cb63e24eSchristos   if (amach == bmach)
61*cb63e24eSchristos     return a;
62*cb63e24eSchristos 
63*cb63e24eSchristos   return NULL;
64*cb63e24eSchristos }
65*cb63e24eSchristos 
66*cb63e24eSchristos static bool
scan(const struct bfd_arch_info * info,const char * string)67*cb63e24eSchristos scan (const struct bfd_arch_info *info, const char *string)
68*cb63e24eSchristos {
69*cb63e24eSchristos   /* First test for an exact match.  */
70*cb63e24eSchristos   if (strcasecmp (string, info->printable_name) == 0)
71*cb63e24eSchristos     return true;
72*cb63e24eSchristos 
73*cb63e24eSchristos   /* Finally check for the default architecture.  */
74*cb63e24eSchristos   if (strcasecmp (string, "kvx") == 0)
75*cb63e24eSchristos     return info->the_default;
76*cb63e24eSchristos 
77*cb63e24eSchristos   return false;
78*cb63e24eSchristos }
79*cb63e24eSchristos 
80*cb63e24eSchristos #define N(addr_bits, machine, print, default, next)            \
81*cb63e24eSchristos {                                                              \
82*cb63e24eSchristos   32,                          /* 32 bits in a word.  */       \
83*cb63e24eSchristos   addr_bits,                   /* bits in an address.  */      \
84*cb63e24eSchristos   8,                           /* 8 bits in a byte.  */        \
85*cb63e24eSchristos   bfd_arch_kvx,                                                 \
86*cb63e24eSchristos   machine,                     /* Machine number.  */          \
87*cb63e24eSchristos   "kvx",                        /* Architecture name.   */      \
88*cb63e24eSchristos   print,                       /* Printable name.  */          \
89*cb63e24eSchristos   4,                           /* Section align power.  */     \
90*cb63e24eSchristos   default,                     /* Is this the default ?  */    \
91*cb63e24eSchristos   kvx_compatible,					       \
92*cb63e24eSchristos   scan,                                                        \
93*cb63e24eSchristos   bfd_arch_default_fill,                                       \
94*cb63e24eSchristos   next,                                                \
95*cb63e24eSchristos           0                                            \
96*cb63e24eSchristos }
97*cb63e24eSchristos 
98*cb63e24eSchristos 
99*cb63e24eSchristos const bfd_arch_info_type bfd_kv4_1_usr_arch =
100*cb63e24eSchristos   N (64 , bfd_mach_kv4_1_usr , "kvx:kv4-1:usr" , false , NULL);
101*cb63e24eSchristos 
102*cb63e24eSchristos const bfd_arch_info_type bfd_kv3_2_usr_arch =
103*cb63e24eSchristos   N (64 , bfd_mach_kv3_2_usr , "kvx:kv3-2:usr" , false , &bfd_kv4_1_usr_arch);
104*cb63e24eSchristos 
105*cb63e24eSchristos const bfd_arch_info_type bfd_kv3_1_usr_arch =
106*cb63e24eSchristos   N (64 , bfd_mach_kv3_1_usr , "kvx:kv3-1:usr" , false , &bfd_kv3_2_usr_arch);
107*cb63e24eSchristos 
108*cb63e24eSchristos const bfd_arch_info_type bfd_kv4_1_64_arch =
109*cb63e24eSchristos   N (64 , bfd_mach_kv4_1_64  , "kvx:kv4-1:64"  , false , &bfd_kv3_1_usr_arch);
110*cb63e24eSchristos 
111*cb63e24eSchristos const bfd_arch_info_type bfd_kv3_2_64_arch =
112*cb63e24eSchristos   N (64 , bfd_mach_kv3_2_64  , "kvx:kv3-2:64"  , false , &bfd_kv4_1_64_arch);
113*cb63e24eSchristos 
114*cb63e24eSchristos const bfd_arch_info_type bfd_kv3_1_64_arch =
115*cb63e24eSchristos   N (64 , bfd_mach_kv3_1_64  , "kvx:kv3-1:64"  , false , &bfd_kv3_2_64_arch);
116*cb63e24eSchristos 
117*cb63e24eSchristos const bfd_arch_info_type bfd_kv4_1_arch =
118*cb63e24eSchristos   N (32 , bfd_mach_kv4_1     , "kvx:kv4-1"     , false , &bfd_kv3_1_64_arch);
119*cb63e24eSchristos 
120*cb63e24eSchristos const bfd_arch_info_type bfd_kv3_2_arch =
121*cb63e24eSchristos   N (32 , bfd_mach_kv3_2     , "kvx:kv3-2"     , false , &bfd_kv4_1_arch);
122*cb63e24eSchristos 
123*cb63e24eSchristos const bfd_arch_info_type bfd_kvx_arch =
124*cb63e24eSchristos   N (32 , bfd_mach_kv3_1     , "kvx:kv3-1"     , true  , &bfd_kv3_2_arch);
125