Rizin
unix-like reverse engineering framework and cli tools
cpu-tricore.c
Go to the documentation of this file.
1 /* BFD support for Infineon's TriCore architecture.
2  Copyright (C) 1998-2003 Free Software Foundation, Inc.
3  Contributed by Michael Schumacher (mike@hightec-rt.com).
4 
5 This file is part of BFD, the Binary File Descriptor library.
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 2 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, MA 02110-1335 USA */
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <sys/types.h>
24 #include <stdbool.h>
25 
26 //#include "bfd.h"
27 #include "sysdep.h"
28 #include "disas-asm.h"
29 //#include "libbfd.h"
30 #include "opcode/tricore.h"
31 
32 /* Opcode masks for TriCore's various instruction formats. */
33 
34 unsigned long tricore_mask_abs;
35 unsigned long tricore_mask_absb;
36 unsigned long tricore_mask_b;
37 unsigned long tricore_mask_bit;
38 unsigned long tricore_mask_bo;
39 unsigned long tricore_mask_bol;
40 unsigned long tricore_mask_brc;
41 unsigned long tricore_mask_brn;
42 unsigned long tricore_mask_brr;
43 unsigned long tricore_mask_rc;
44 unsigned long tricore_mask_rcpw;
45 unsigned long tricore_mask_rcr;
46 unsigned long tricore_mask_rcrr;
47 unsigned long tricore_mask_rcrw;
48 unsigned long tricore_mask_rlc;
49 unsigned long tricore_mask_rr;
50 unsigned long tricore_mask_rr1;
51 unsigned long tricore_mask_rr2;
52 unsigned long tricore_mask_rrpw;
53 unsigned long tricore_mask_rrr;
54 unsigned long tricore_mask_rrr1;
55 unsigned long tricore_mask_rrr2;
56 unsigned long tricore_mask_rrrr;
57 unsigned long tricore_mask_rrrw;
58 unsigned long tricore_mask_sys;
59 unsigned long tricore_mask_sb;
60 unsigned long tricore_mask_sbc;
61 unsigned long tricore_mask_sbr;
62 unsigned long tricore_mask_sbrn;
63 unsigned long tricore_mask_sc;
64 unsigned long tricore_mask_slr;
65 unsigned long tricore_mask_slro;
66 unsigned long tricore_mask_sr;
67 unsigned long tricore_mask_src;
68 unsigned long tricore_mask_sro;
69 unsigned long tricore_mask_srr;
70 unsigned long tricore_mask_srrs;
71 unsigned long tricore_mask_ssr;
72 unsigned long tricore_mask_ssro;
74 
75 int
77  const bfd_arch_info_type *info;
78  const char *string;
79 {
80  return true;
81 }
82 
83 const bfd_arch_info_type *
85  const bfd_arch_info_type *a;
86  const bfd_arch_info_type *b;
87 {
88  if (a->arch != b->arch) {
89  return NULL;
90  }
91 
92  if (a->bits_per_word != b->bits_per_word) {
93  return NULL;
94  }
95 
96  if (a->mach > b->mach) {
97  return a;
98  }
99 
100  if (b->mach > a->mach) {
101  return b;
102  }
103 
104  return a;
105 }
106 
107 void tricore_init_arch_vars PARAMS ((unsigned long));
108 
109 /* Describe the various flavours of the TriCore architecture. */
110 
112 {
113  /* Rider-A ISA. */
114  {
115  32, /* 32 bits per word. */
116  32, /* 32 bits per address. */
117  8, /* 8 bits per byte. */
118  bfd_arch_tricore, /* Architecture type. */
119  bfd_mach_rider_a, /* Machine type. */
120  "tricore", /* Name of architecture (internal use). */
121  "TriCore:Rider-A", /* Name of architecture to print. */
122  3, /* Align sections on 8 byte boundaries. */
123  false, /* No, this is ain't the default arch type. */
124  bfd_default_compatible, /* We're compatible with ourselves. */
125  bfd_default_scan, /* Let BFD find the default arch. */
126  &arch_info_struct[1] /* Next TriCore architecture. */
127  },
128 
129  /* Rider-D ISA. */
130  {
131  32, /* 32 bits per word. */
132  32, /* 32 bits per address. */
133  8, /* 8 bits per byte. */
134  bfd_arch_tricore, /* Architecture type. */
135  bfd_mach_rider_d, /* Machine type. */
136  "tricore", /* Name of architecture (internal use). */
137  "TriCore:Rider-D", /* Name of architecture to print. */
138  3, /* Align sections on 8 byte boundaries. */
139  false, /* No, this is ain't the default arch type. */
140  bfd_default_compatible, /* We're compatible with ourselves. */
141  bfd_default_scan, /* Let BFD find the default arch. */
142  &arch_info_struct[2] /* Next TriCore architecture. */
143  },
144 
145  /* TriCore V2 ISA. */
146  {
147  32, /* 32 bits per word. */
148  32, /* 32 bits per address. */
149  8, /* 8 bits per byte. */
150  bfd_arch_tricore, /* Architecture type. */
151  bfd_mach_rider_2, /* Machine type. */
152  "tricore", /* Name of architecture (internal use). */
153  "TriCore:V2", /* Name of architecture to print. */
154  3, /* Align sections on 8 byte boundaries. */
155  false, /* No, this is ain't the default arch type. */
156  bfd_default_compatible, /* We're compatible with ourselves. */
157  bfd_default_scan, /* Let BFD find the default arch. */
158  (bfd_arch_info_type *) 0 /* No more arch types for TriCore. */
159  }
160 };
161 
163 {
164  /* Rider-B ISA. */
165  32, /* 32 bits per word. */
166  32, /* 32 bits per address. */
167  8, /* 8 bits per byte. */
168  bfd_arch_tricore, /* Architecture type. */
169  bfd_mach_rider_b, /* Machine type. */
170  "tricore", /* Name of architecture (internal use). */
171  "TriCore:Rider-B", /* Name of architecture to print. */
172  3, /* Align sections on 8 byte boundaries. */
173  true, /* Yes, this is the default arch type. */
174  bfd_default_compatible, /* We're compatible with ourselves. */
175  bfd_default_scan, /* Let BFD find the default arch. */
176  &arch_info_struct[0] /* Next arch type for TriCore. */
177 };
178 
179 /* Initialize the architecture-specific variables. This must be called
180  by the assembler and disassembler prior to encoding/decoding any
181  TriCore instructions; the linker (or more precisely, the specific
182  back-end, bfd/elf32-tricore.c:tricore_elf32_relocate_section) will
183  also have to call this if it ever accesses the variables below, but
184  it currently doesn't. */
185 
186 void
188  unsigned long mach;
189 {
190  switch (mach & bfd_mach_rider_mask)
191  {
192  case bfd_mach_rider_a:
193  tricore_mask_abs = 0x0c0000ff;
194  tricore_mask_absb = 0x0c0000ff;
195  tricore_mask_b = 0x000000ff;
196  tricore_mask_bit = 0x006000ff;
197  tricore_mask_bo = 0x0fc000ff;
198  tricore_mask_bol = 0x000000ff;
199  tricore_mask_brc = 0x800000ff;
200  tricore_mask_brn = 0x8000007f;
201  tricore_mask_brr = 0x800000ff;
202  tricore_mask_rc = 0x0fe000ff;
203  tricore_mask_rcpw = 0x006000ff;
204  tricore_mask_rcr = 0x00e000ff;
205  tricore_mask_rcrr = 0x00e000ff;
206  tricore_mask_rcrw = 0x00e000ff;
207  tricore_mask_rlc = 0x000000ff;
208  tricore_mask_rr = 0x0ff000ff;
209  tricore_mask_rrpw = 0x006000ff;
210  tricore_mask_rrr = 0x00f000ff;
211  tricore_mask_rrr1 = 0x00fc00ff;
212  tricore_mask_rrr2 = 0x00ff00ff;
213  tricore_mask_rrrr = 0x00e000ff;
214  tricore_mask_rrrw = 0x00e000ff;
215  tricore_mask_sys = 0x07c000ff;
216  tricore_mask_sb = 0x00ff;
217  tricore_mask_sbc = 0x00ff;
218  tricore_mask_sbr = 0x00ff;
219  tricore_mask_sbrn = 0x007f;
220  tricore_mask_sc = 0x00ff;
221  tricore_mask_slr = 0x00ff;
222  tricore_mask_slro = 0x00ff;
223  tricore_mask_sr = 0xf0ff;
224  tricore_mask_src = 0x00ff;
225  tricore_mask_sro = 0x00ff;
226  tricore_mask_srr = 0x00ff;
227  tricore_mask_srrs = 0x003f;
228  tricore_mask_ssr = 0x00ff;
229  tricore_mask_ssro = 0x00ff;
230  break;
231 
232  case bfd_mach_rider_b: /* Same as bfd_mach_rider_d! */
233  case bfd_mach_rider_2:
234  tricore_mask_abs = 0x0c0000ff;
235  tricore_mask_absb = 0x0c0000ff;
236  tricore_mask_b = 0x000000ff;
237  tricore_mask_bit = 0x006000ff;
238  tricore_mask_bo = 0x0fc000ff;
239  tricore_mask_bol = 0x000000ff;
240  tricore_mask_brc = 0x800000ff;
241  tricore_mask_brn = 0x8000007f;
242  tricore_mask_brr = 0x800000ff;
243  tricore_mask_rc = 0x0fe000ff;
244  tricore_mask_rcpw = 0x006000ff;
245  tricore_mask_rcr = 0x00e000ff;
246  tricore_mask_rcrr = 0x00e000ff;
247  tricore_mask_rcrw = 0x00e000ff;
248  tricore_mask_rlc = 0x000000ff;
249  tricore_mask_rr = 0x0ff300ff;
250  tricore_mask_rr1 = 0x0ffc00ff;
251  tricore_mask_rr2 = 0x0fff00ff;
252  tricore_mask_rrpw = 0x006000ff;
253  tricore_mask_rrr = 0x00f300ff;
254  tricore_mask_rrr1 = 0x00fc00ff;
255  tricore_mask_rrr2 = 0x00ff00ff;
256  tricore_mask_rrrr = 0x00e000ff;
257  tricore_mask_rrrw = 0x00e000ff;
258  if ((mach & bfd_mach_rider_mask) == bfd_mach_rider_2) {
259  tricore_mask_sys = 0x0fc000ff;
260  } else {
261  tricore_mask_sys = 0x07c000ff;
262  }
263  tricore_mask_sb = 0x00ff;
264  tricore_mask_sbc = 0x00ff;
265  tricore_mask_sbr = 0x00ff;
266  tricore_mask_sbrn = 0x00ff;
267  tricore_mask_sc = 0x00ff;
268  tricore_mask_slr = 0x00ff;
269  tricore_mask_slro = 0x00ff;
270  tricore_mask_sr = 0xf0ff;
271  tricore_mask_src = 0x00ff;
272  tricore_mask_sro = 0x00ff;
273  tricore_mask_srr = 0x00ff;
274  tricore_mask_srrs = 0x003f;
275  tricore_mask_ssr = 0x00ff;
276  tricore_mask_ssro = 0x00ff;
277  break;
278  }
279 
280  /* Now fill in tricore_opmask[]. */
281 
321 }
322 
323 /* End of cpu-tricore.c. */
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
unsigned long tricore_mask_brn
Definition: cpu-tricore.c:41
unsigned long tricore_mask_ssr
Definition: cpu-tricore.c:71
unsigned long tricore_mask_rrrr
Definition: cpu-tricore.c:56
unsigned long tricore_mask_rrr
Definition: cpu-tricore.c:53
unsigned long tricore_mask_ssro
Definition: cpu-tricore.c:72
unsigned long tricore_mask_srr
Definition: cpu-tricore.c:69
unsigned long tricore_mask_sb
Definition: cpu-tricore.c:59
unsigned long tricore_mask_bo
Definition: cpu-tricore.c:38
unsigned long tricore_mask_rcr
Definition: cpu-tricore.c:45
unsigned long tricore_mask_sc
Definition: cpu-tricore.c:63
unsigned long tricore_mask_slr
Definition: cpu-tricore.c:64
unsigned long tricore_mask_rc
Definition: cpu-tricore.c:43
unsigned long tricore_mask_rrpw
Definition: cpu-tricore.c:52
unsigned long tricore_mask_srrs
Definition: cpu-tricore.c:70
unsigned long tricore_mask_bol
Definition: cpu-tricore.c:39
unsigned long tricore_mask_slro
Definition: cpu-tricore.c:65
unsigned long tricore_mask_rr
Definition: cpu-tricore.c:49
unsigned long tricore_mask_rrr2
Definition: cpu-tricore.c:55
int bfd_default_scan(bfd_arch_info_type *info, const char *string) const
Definition: cpu-tricore.c:76
const bfd_arch_info_type bfd_tricore_arch
Definition: cpu-tricore.c:162
unsigned long tricore_mask_bit
Definition: cpu-tricore.c:37
unsigned long tricore_mask_brc
Definition: cpu-tricore.c:40
unsigned long tricore_mask_rr2
Definition: cpu-tricore.c:51
unsigned long tricore_mask_sro
Definition: cpu-tricore.c:68
unsigned long tricore_mask_rcpw
Definition: cpu-tricore.c:44
unsigned long tricore_mask_sbr
Definition: cpu-tricore.c:61
unsigned long tricore_mask_b
Definition: cpu-tricore.c:36
unsigned long tricore_mask_sys
Definition: cpu-tricore.c:58
void tricore_init_arch_vars(unsigned long mach)
Definition: cpu-tricore.c:187
unsigned long tricore_mask_rlc
Definition: cpu-tricore.c:48
void tricore_init_arch_vars PARAMS((unsigned long))
unsigned long tricore_mask_sbrn
Definition: cpu-tricore.c:62
unsigned long tricore_mask_abs
Definition: cpu-tricore.c:34
unsigned long tricore_mask_rrrw
Definition: cpu-tricore.c:57
unsigned long tricore_opmask[TRICORE_FMT_MAX]
Definition: cpu-tricore.c:73
const bfd_arch_info_type * bfd_default_compatible(bfd_arch_info_type *a, const bfd_arch_info_type *b) const
Definition: cpu-tricore.c:84
unsigned long tricore_mask_rcrw
Definition: cpu-tricore.c:47
unsigned long tricore_mask_rrr1
Definition: cpu-tricore.c:54
unsigned long tricore_mask_rcrr
Definition: cpu-tricore.c:46
static const bfd_arch_info_type arch_info_struct[]
Definition: cpu-tricore.c:111
unsigned long tricore_mask_sr
Definition: cpu-tricore.c:66
unsigned long tricore_mask_src
Definition: cpu-tricore.c:67
unsigned long tricore_mask_absb
Definition: cpu-tricore.c:35
unsigned long tricore_mask_sbc
Definition: cpu-tricore.c:60
unsigned long tricore_mask_rr1
Definition: cpu-tricore.c:50
unsigned long tricore_mask_brr
Definition: cpu-tricore.c:42
#define NULL
Definition: cris-opc.c:27
@ bfd_arch_tricore
Definition: mybfd.h:1872
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
#define bfd_mach_rider_d
Definition: tricore.h:42
@ TRICORE_FMT_RLC
Definition: tricore.h:75
@ TRICORE_FMT_BO
Definition: tricore.h:65
@ TRICORE_FMT_SRC
Definition: tricore.h:97
@ TRICORE_FMT_SRO
Definition: tricore.h:98
@ TRICORE_FMT_SYS
Definition: tricore.h:85
@ TRICORE_FMT_SBRN
Definition: tricore.h:92
@ TRICORE_FMT_RR
Definition: tricore.h:76
@ TRICORE_FMT_RRPW
Definition: tricore.h:79
@ TRICORE_FMT_MAX
Definition: tricore.h:103
@ TRICORE_FMT_RR1
Definition: tricore.h:77
@ TRICORE_FMT_SSR
Definition: tricore.h:101
@ TRICORE_FMT_RRRR
Definition: tricore.h:83
@ TRICORE_FMT_RRR2
Definition: tricore.h:82
@ TRICORE_FMT_SLR
Definition: tricore.h:94
@ TRICORE_FMT_ABS
Definition: tricore.h:61
@ TRICORE_FMT_RCR
Definition: tricore.h:72
@ TRICORE_FMT_RRR
Definition: tricore.h:80
@ TRICORE_FMT_SR
Definition: tricore.h:96
@ TRICORE_FMT_RCRW
Definition: tricore.h:74
@ TRICORE_FMT_SSRO
Definition: tricore.h:102
@ TRICORE_FMT_SLRO
Definition: tricore.h:95
@ TRICORE_FMT_SC
Definition: tricore.h:93
@ TRICORE_FMT_RRRW
Definition: tricore.h:84
@ TRICORE_FMT_BOL
Definition: tricore.h:66
@ TRICORE_FMT_BRN
Definition: tricore.h:68
@ TRICORE_FMT_B
Definition: tricore.h:63
@ TRICORE_FMT_RCPW
Definition: tricore.h:71
@ TRICORE_FMT_SBC
Definition: tricore.h:90
@ TRICORE_FMT_RRR1
Definition: tricore.h:81
@ TRICORE_FMT_BRR
Definition: tricore.h:69
@ TRICORE_FMT_RCRR
Definition: tricore.h:73
@ TRICORE_FMT_ABSB
Definition: tricore.h:62
@ TRICORE_FMT_RR2
Definition: tricore.h:78
@ TRICORE_FMT_SRR
Definition: tricore.h:99
@ TRICORE_FMT_RC
Definition: tricore.h:70
@ TRICORE_FMT_SRRS
Definition: tricore.h:100
@ TRICORE_FMT_BRC
Definition: tricore.h:67
@ TRICORE_FMT_BIT
Definition: tricore.h:64
@ TRICORE_FMT_SBR
Definition: tricore.h:91
@ TRICORE_FMT_SB
Definition: tricore.h:89
#define bfd_mach_rider_2
Definition: tricore.h:41
#define bfd_mach_rider_mask
Definition: tricore.h:43
#define bfd_mach_rider_a
Definition: tricore.h:38
#define bfd_mach_rider_b
Definition: tricore.h:39