Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/xtensa-isa.c
Line
Count
Source
1
/* Configurable Xtensa ISA support.
2
   Copyright (C) 2003-2026 Free Software Foundation, Inc.
3
4
   This file is part of BFD, the Binary File Descriptor library.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include "bfd.h"
23
#include "libbfd.h"
24
#include "xtensa-isa.h"
25
#include "xtensa-isa-internal.h"
26
#include "xtensa-dynconfig.h"
27
28
static xtensa_isa_status xtisa_errno;
29
static char xtisa_error_msg[1024];
30
31
32
xtensa_isa_status
33
xtensa_isa_errno (xtensa_isa isa __attribute__ ((unused)))
34
0
{
35
0
  return xtisa_errno;
36
0
}
37
38
39
char *
40
xtensa_isa_error_msg (xtensa_isa isa __attribute__ ((unused)))
41
0
{
42
0
  return xtisa_error_msg;
43
0
}
44
45
46
#define CHECK_ALLOC(MEM,ERRVAL) \
47
12
  do { \
48
12
    if ((MEM) == 0) \
49
12
      { \
50
0
  xtisa_errno = xtensa_isa_out_of_memory; \
51
0
  strcpy (xtisa_error_msg, "out of memory"); \
52
0
  return (ERRVAL); \
53
0
      } \
54
12
  } while (0)
55
56
#define CHECK_ALLOC_FOR_INIT(MEM,ERRVAL,ERRNO_P,ERROR_MSG_P) \
57
21
  do { \
58
21
    if ((MEM) == 0) \
59
21
      { \
60
0
  xtisa_errno = xtensa_isa_out_of_memory; \
61
0
  strcpy (xtisa_error_msg, "out of memory"); \
62
0
  if (ERRNO_P) *(ERRNO_P) = xtisa_errno; \
63
0
  if (ERROR_MSG_P) *(ERROR_MSG_P) = xtisa_error_msg; \
64
0
  return (ERRVAL); \
65
0
      } \
66
21
  } while (0)
67
68
69

70
/* Instruction buffers.  */
71
72
int
73
xtensa_insnbuf_size (xtensa_isa isa)
74
14.3M
{
75
14.3M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
76
14.3M
  return intisa->insnbuf_size;
77
14.3M
}
78
79
80
xtensa_insnbuf
81
xtensa_insnbuf_alloc (xtensa_isa isa)
82
11
{
83
11
  xtensa_insnbuf result = (xtensa_insnbuf)
84
11
    malloc (xtensa_insnbuf_size (isa) * sizeof (xtensa_insnbuf_word));
85
11
  CHECK_ALLOC (result, 0);
86
11
  return result;
87
11
}
88
89
90
void
91
xtensa_insnbuf_free (xtensa_isa isa __attribute__ ((unused)),
92
         xtensa_insnbuf buf)
93
0
{
94
0
  free (buf);
95
0
}
96
97
98
/* Given <byte_index>, the index of a byte in a xtensa_insnbuf, our
99
   internal representation of a xtensa instruction word, return the index of
100
   its word and the bit index of its low order byte in the xtensa_insnbuf.  */
101
102
static inline int
103
byte_to_word_index (int byte_index)
104
26.5M
{
105
26.5M
  return byte_index / sizeof (xtensa_insnbuf_word);
106
26.5M
}
107
108
109
static inline int
110
byte_to_bit_index (int byte_index)
111
26.5M
{
112
26.5M
  return (byte_index & 0x3) * 8;
113
26.5M
}
114
115
116
/* Copy an instruction in the 32-bit words pointed at by "insn" to
117
   characters pointed at by "cp".  This is more complicated than you
118
   might think because we want 16-bit instructions in bytes 2 & 3 for
119
   big-endian configurations.  This function allows us to specify
120
   which byte in "insn" to start with and which way to increment,
121
   allowing trivial implementation for both big- and little-endian
122
   configurations....and it seems to make pretty good code for
123
   both.  */
124
125
int
126
xtensa_insnbuf_to_chars (xtensa_isa isa,
127
       const xtensa_insnbuf insn,
128
       unsigned char *cp,
129
       int num_chars)
130
361
{
131
361
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
132
361
  int insn_size = xtensa_isa_maxlength (isa);
133
361
  int fence_post, start, increment, i, byte_count;
134
361
  xtensa_format fmt;
135
136
361
  if (num_chars == 0)
137
0
    num_chars = insn_size;
138
139
361
  if (intisa->is_big_endian)
140
0
    {
141
0
      start = insn_size - 1;
142
0
      increment = -1;
143
0
    }
144
361
  else
145
361
    {
146
361
      start = 0;
147
361
      increment = 1;
148
361
    }
149
150
  /* Find the instruction format.  Do nothing if the buffer does not contain
151
     a valid instruction since we need to know how many bytes to copy.  */
152
361
  fmt = xtensa_format_decode (isa, insn);
153
361
  if (fmt == XTENSA_UNDEFINED)
154
0
    return XTENSA_UNDEFINED;
155
156
361
  byte_count = xtensa_format_length (isa, fmt);
157
361
  if (byte_count == XTENSA_UNDEFINED)
158
0
    return XTENSA_UNDEFINED;
159
160
361
  if (byte_count > num_chars)
161
0
    {
162
0
      xtisa_errno = xtensa_isa_buffer_overflow;
163
0
      strcpy (xtisa_error_msg, "output buffer too small for instruction");
164
0
      return XTENSA_UNDEFINED;
165
0
    }
166
167
361
  fence_post = start + (byte_count * increment);
168
169
1.75k
  for (i = start; i != fence_post; i += increment, ++cp)
170
1.39k
    {
171
1.39k
      int word_inx = byte_to_word_index (i);
172
1.39k
      int bit_inx = byte_to_bit_index (i);
173
174
1.39k
      *cp = (insn[word_inx] >> bit_inx) & 0xff;
175
1.39k
    }
176
177
361
  return byte_count;
178
361
}
179
180
181
/* Inward conversion from byte stream to xtensa_insnbuf.  See
182
   xtensa_insnbuf_to_chars for a discussion of why this is complicated
183
   by endianness.  */
184
185
int
186
xtensa_insnbuf_from_chars (xtensa_isa isa,
187
         xtensa_insnbuf insn,
188
         const unsigned char *cp,
189
         int num_chars)
190
7.16M
{
191
7.16M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
192
7.16M
  int max_size, insn_size, fence_post, start, increment, i;
193
194
7.16M
  max_size = xtensa_isa_maxlength (isa);
195
196
  /* No insn is smaller than 2 bytes, and we must be able to read
197
     at least one byte to decode the insn.  */
198
7.16M
  if (num_chars < 2)
199
4.12k
    return XTENSA_UNDEFINED;
200
201
  /* Decode the instruction length so we know how many bytes to read.  */
202
7.15M
  insn_size = (intisa->length_decode_fn) (cp);
203
7.15M
  if (insn_size == XTENSA_UNDEFINED)
204
0
    return XTENSA_UNDEFINED;
205
206
7.15M
  if (num_chars < insn_size)
207
3.59k
    return XTENSA_UNDEFINED;
208
7.15M
  if (num_chars > insn_size)
209
5.82M
    num_chars = insn_size;
210
211
7.15M
  if (intisa->is_big_endian)
212
0
    {
213
0
      start = max_size - 1;
214
0
      increment = -1;
215
0
    }
216
7.15M
  else
217
7.15M
    {
218
7.15M
      start = 0;
219
7.15M
      increment = 1;
220
7.15M
    }
221
222
7.15M
  fence_post = start + (num_chars * increment);
223
7.15M
  memset (insn, 0, xtensa_insnbuf_size (isa) * sizeof (xtensa_insnbuf_word));
224
225
33.6M
  for (i = start; i != fence_post; i += increment, ++cp)
226
26.5M
    {
227
26.5M
      int word_inx = byte_to_word_index (i);
228
26.5M
      int bit_inx = byte_to_bit_index (i);
229
230
26.5M
      insn[word_inx] |= (unsigned) (*cp & 0xff) << bit_inx;
231
26.5M
    }
232
7.15M
  return 0;
233
7.15M
}
234
235

236
/* ISA information.  */
237
238
extern xtensa_isa_internal xtensa_modules;
239
240
static xtensa_isa_internal *xtensa_get_modules (void)
241
3
{
242
3
  static xtensa_isa_internal *modules;
243
244
3
  if (!modules)
245
3
    modules = (xtensa_isa_internal *) xtensa_load_config ("xtensa_modules",
246
3
                &xtensa_modules,
247
3
                NULL);
248
3
  return modules;
249
3
}
250
251
xtensa_isa
252
xtensa_isa_init (xtensa_isa_status *errno_p, char **error_msg_p)
253
3
{
254
3
  xtensa_isa_internal *isa = xtensa_get_modules ();
255
3
  int n, is_user;
256
257
  /* Set up the opcode name lookup table.  */
258
3
  isa->opname_lookup_table =
259
3
    bfd_malloc (isa->num_opcodes * sizeof (xtensa_lookup_entry));
260
3
  CHECK_ALLOC_FOR_INIT (isa->opname_lookup_table, NULL, errno_p, error_msg_p);
261
1.59k
  for (n = 0; n < isa->num_opcodes; n++)
262
1.59k
    {
263
1.59k
      isa->opname_lookup_table[n].key = isa->opcodes[n].name;
264
1.59k
      isa->opname_lookup_table[n].u.opcode = n;
265
1.59k
    }
266
3
  qsort (isa->opname_lookup_table, isa->num_opcodes,
267
3
   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
268
269
  /* Set up the state name lookup table.  */
270
3
  isa->state_lookup_table =
271
3
    bfd_malloc (isa->num_states * sizeof (xtensa_lookup_entry));
272
3
  CHECK_ALLOC_FOR_INIT (isa->state_lookup_table, NULL, errno_p, error_msg_p);
273
270
  for (n = 0; n < isa->num_states; n++)
274
267
    {
275
267
      isa->state_lookup_table[n].key = isa->states[n].name;
276
267
      isa->state_lookup_table[n].u.state = n;
277
267
    }
278
3
  qsort (isa->state_lookup_table, isa->num_states,
279
3
   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
280
281
  /* Set up the sysreg name lookup table.  */
282
3
  isa->sysreg_lookup_table =
283
3
    bfd_malloc (isa->num_sysregs * sizeof (xtensa_lookup_entry));
284
3
  CHECK_ALLOC_FOR_INIT (isa->sysreg_lookup_table, NULL, errno_p, error_msg_p);
285
225
  for (n = 0; n < isa->num_sysregs; n++)
286
222
    {
287
222
      isa->sysreg_lookup_table[n].key = isa->sysregs[n].name;
288
222
      isa->sysreg_lookup_table[n].u.sysreg = n;
289
222
    }
290
3
  qsort (isa->sysreg_lookup_table, isa->num_sysregs,
291
3
   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
292
293
  /* Set up the user & system sysreg number tables.  */
294
9
  for (is_user = 0; is_user < 2; is_user++)
295
6
    {
296
6
      isa->sysreg_table[is_user] =
297
6
  bfd_malloc ((isa->max_sysreg_num[is_user] + 1)
298
6
        * sizeof (xtensa_sysreg));
299
6
      CHECK_ALLOC_FOR_INIT (isa->sysreg_table[is_user], NULL,
300
6
          errno_p, error_msg_p);
301
302
1.45k
      for (n = 0; n <= isa->max_sysreg_num[is_user]; n++)
303
1.44k
  isa->sysreg_table[is_user][n] = XTENSA_UNDEFINED;
304
6
    }
305
225
  for (n = 0; n < isa->num_sysregs; n++)
306
222
    {
307
222
      xtensa_sysreg_internal *sreg = &isa->sysregs[n];
308
222
      is_user = sreg->is_user;
309
310
222
      if (sreg->number >= 0)
311
222
  isa->sysreg_table[is_user][sreg->number] = n;
312
222
    }
313
314
  /* Set up the interface lookup table.  */
315
3
  isa->interface_lookup_table =
316
3
    bfd_malloc (isa->num_interfaces * sizeof (xtensa_lookup_entry));
317
3
  CHECK_ALLOC_FOR_INIT (isa->interface_lookup_table, NULL, errno_p,
318
3
      error_msg_p);
319
3
  for (n = 0; n < isa->num_interfaces; n++)
320
0
    {
321
0
      isa->interface_lookup_table[n].key = isa->interfaces[n].name;
322
0
      isa->interface_lookup_table[n].u.intf = n;
323
0
    }
324
3
  qsort (isa->interface_lookup_table, isa->num_interfaces,
325
3
   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
326
327
  /* Set up the funcUnit lookup table.  */
328
3
  isa->funcUnit_lookup_table =
329
3
    bfd_malloc (isa->num_funcUnits * sizeof (xtensa_lookup_entry));
330
3
  CHECK_ALLOC_FOR_INIT (isa->funcUnit_lookup_table, NULL, errno_p,
331
3
      error_msg_p);
332
3
  for (n = 0; n < isa->num_funcUnits; n++)
333
0
    {
334
0
      isa->funcUnit_lookup_table[n].key = isa->funcUnits[n].name;
335
0
      isa->funcUnit_lookup_table[n].u.fun = n;
336
0
    }
337
3
  qsort (isa->funcUnit_lookup_table, isa->num_funcUnits,
338
3
   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
339
340
3
  isa->insnbuf_size = ((isa->insn_size + sizeof (xtensa_insnbuf_word) - 1) /
341
3
           sizeof (xtensa_insnbuf_word));
342
343
3
  return (xtensa_isa) isa;
344
3
}
345
346
347
void
348
xtensa_isa_free (xtensa_isa isa)
349
0
{
350
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
351
0
  int n;
352
353
  /* With this version of the code, the xtensa_isa structure is not
354
     dynamically allocated, so this function is not essential.  Free
355
     the memory allocated by xtensa_isa_init and restore the xtensa_isa
356
     structure to its initial state.  */
357
358
0
  free (intisa->opname_lookup_table);
359
0
  intisa->opname_lookup_table = 0;
360
361
0
  free (intisa->state_lookup_table);
362
0
  intisa->state_lookup_table = 0;
363
364
0
  free (intisa->sysreg_lookup_table);
365
0
  intisa->sysreg_lookup_table = 0;
366
367
0
  for (n = 0; n < 2; n++)
368
0
    {
369
0
      free (intisa->sysreg_table[n]);
370
0
      intisa->sysreg_table[n] = 0;
371
0
    }
372
373
0
  free (intisa->interface_lookup_table);
374
0
  intisa->interface_lookup_table = 0;
375
376
0
  free (intisa->funcUnit_lookup_table);
377
0
  intisa->funcUnit_lookup_table = 0;
378
0
}
379
380
381
int
382
xtensa_isa_name_compare (const void *v1, const void *v2)
383
14.2k
{
384
14.2k
  xtensa_lookup_entry *e1 = (xtensa_lookup_entry *) v1;
385
14.2k
  xtensa_lookup_entry *e2 = (xtensa_lookup_entry *) v2;
386
387
14.2k
  return strcasecmp (e1->key, e2->key);
388
14.2k
}
389
390
391
int
392
xtensa_isa_maxlength (xtensa_isa isa)
393
21.4M
{
394
21.4M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
395
21.4M
  return intisa->insn_size;
396
21.4M
}
397
398
399
int
400
xtensa_isa_length_from_chars (xtensa_isa isa, const unsigned char *cp)
401
0
{
402
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
403
0
  return (intisa->length_decode_fn) (cp);
404
0
}
405
406
407
int
408
xtensa_isa_num_pipe_stages (xtensa_isa isa)
409
0
{
410
0
  xtensa_opcode opcode;
411
0
  xtensa_funcUnit_use *use;
412
0
  int num_opcodes, num_uses;
413
0
  int i, stage;
414
0
  static int max_stage = XTENSA_UNDEFINED;
415
416
  /* Only compute the value once.  */
417
0
  if (max_stage != XTENSA_UNDEFINED)
418
0
    return max_stage + 1;
419
420
0
  num_opcodes = xtensa_isa_num_opcodes (isa);
421
0
  for (opcode = 0; opcode < num_opcodes; opcode++)
422
0
    {
423
0
      num_uses = xtensa_opcode_num_funcUnit_uses (isa, opcode);
424
0
      for (i = 0; i < num_uses; i++)
425
0
  {
426
0
    use = xtensa_opcode_funcUnit_use (isa, opcode, i);
427
0
    stage = use->stage;
428
0
    if (stage > max_stage)
429
0
      max_stage = stage;
430
0
  }
431
0
    }
432
433
0
  return max_stage + 1;
434
0
}
435
436
437
int
438
xtensa_isa_num_formats (xtensa_isa isa)
439
0
{
440
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
441
0
  return intisa->num_formats;
442
0
}
443
444
445
int
446
xtensa_isa_num_opcodes (xtensa_isa isa)
447
0
{
448
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
449
0
  return intisa->num_opcodes;
450
0
}
451
452
453
int
454
xtensa_isa_num_regfiles (xtensa_isa isa)
455
0
{
456
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
457
0
  return intisa->num_regfiles;
458
0
}
459
460
461
int
462
xtensa_isa_num_states (xtensa_isa isa)
463
0
{
464
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
465
0
  return intisa->num_states;
466
0
}
467
468
469
int
470
xtensa_isa_num_sysregs (xtensa_isa isa)
471
0
{
472
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
473
0
  return intisa->num_sysregs;
474
0
}
475
476
477
int
478
xtensa_isa_num_interfaces (xtensa_isa isa)
479
0
{
480
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
481
0
  return intisa->num_interfaces;
482
0
}
483
484
485
int
486
xtensa_isa_num_funcUnits (xtensa_isa isa)
487
0
{
488
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
489
0
  return intisa->num_funcUnits;
490
0
}
491
492
493

494
/* Instruction formats.  */
495
496
497
#define CHECK_FORMAT(INTISA,FMT,ERRVAL) \
498
52.2M
  do { \
499
52.2M
    if ((FMT) < 0 || (FMT) >= (INTISA)->num_formats) \
500
52.2M
      { \
501
0
  xtisa_errno = xtensa_isa_bad_format; \
502
0
  strcpy (xtisa_error_msg, "invalid format specifier"); \
503
0
  return (ERRVAL); \
504
0
      } \
505
52.2M
  } while (0)
506
507
508
#define CHECK_SLOT(INTISA,FMT,SLOT,ERRVAL) \
509
39.3M
  do { \
510
39.3M
    if ((SLOT) < 0 || (SLOT) >= (INTISA)->formats[FMT].num_slots) \
511
39.3M
      { \
512
1.70k
  xtisa_errno = xtensa_isa_bad_slot; \
513
1.70k
  strcpy (xtisa_error_msg, "invalid slot specifier"); \
514
1.70k
  return (ERRVAL); \
515
1.70k
      } \
516
39.3M
  } while (0)
517
518
519
const char *
520
xtensa_format_name (xtensa_isa isa, xtensa_format fmt)
521
0
{
522
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
523
0
  CHECK_FORMAT (intisa, fmt, NULL);
524
0
  return intisa->formats[fmt].name;
525
0
}
526
527
528
xtensa_format
529
xtensa_format_lookup (xtensa_isa isa, const char *fmtname)
530
0
{
531
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
532
0
  int fmt;
533
534
0
  if (!fmtname || !*fmtname)
535
0
    {
536
0
      xtisa_errno = xtensa_isa_bad_format;
537
0
      strcpy (xtisa_error_msg, "invalid format name");
538
0
      return XTENSA_UNDEFINED;
539
0
    }
540
541
0
  for (fmt = 0; fmt < intisa->num_formats; fmt++)
542
0
    {
543
0
      if (strcasecmp (fmtname, intisa->formats[fmt].name) == 0)
544
0
  return fmt;
545
0
    }
546
547
0
  xtisa_errno = xtensa_isa_bad_format;
548
0
  sprintf (xtisa_error_msg, "format \"%s\" not recognized", fmtname);
549
0
  return XTENSA_UNDEFINED;
550
0
}
551
552
553
xtensa_format
554
xtensa_format_decode (xtensa_isa isa, const xtensa_insnbuf insn)
555
7.16M
{
556
7.16M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
557
7.16M
  xtensa_format fmt;
558
559
7.16M
  fmt = (intisa->format_decode_fn) (insn);
560
7.16M
  if (fmt != XTENSA_UNDEFINED)
561
6.41M
    return fmt;
562
563
749k
  xtisa_errno = xtensa_isa_bad_format;
564
749k
  strcpy (xtisa_error_msg, "cannot decode instruction format");
565
749k
  return XTENSA_UNDEFINED;
566
7.16M
}
567
568
569
int
570
xtensa_format_encode (xtensa_isa isa, xtensa_format fmt, xtensa_insnbuf insn)
571
0
{
572
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
573
0
  CHECK_FORMAT (intisa, fmt, -1);
574
0
  (*intisa->formats[fmt].encode_fn) (insn);
575
0
  return 0;
576
0
}
577
578
579
int
580
xtensa_format_length (xtensa_isa isa, xtensa_format fmt)
581
6.40M
{
582
6.40M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
583
6.40M
  CHECK_FORMAT (intisa, fmt, XTENSA_UNDEFINED);
584
6.40M
  return intisa->formats[fmt].length;
585
6.40M
}
586
587
588
int
589
xtensa_format_num_slots (xtensa_isa isa, xtensa_format fmt)
590
6.40M
{
591
6.40M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
592
6.40M
  CHECK_FORMAT (intisa, fmt, XTENSA_UNDEFINED);
593
6.40M
  return intisa->formats[fmt].num_slots;
594
6.40M
}
595
596
597
xtensa_opcode
598
xtensa_format_slot_nop_opcode (xtensa_isa isa, xtensa_format fmt, int slot)
599
0
{
600
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
601
0
  int slot_id;
602
603
0
  CHECK_FORMAT (intisa, fmt, XTENSA_UNDEFINED);
604
0
  CHECK_SLOT (intisa, fmt, slot, XTENSA_UNDEFINED);
605
606
0
  slot_id = intisa->formats[fmt].slot_id[slot];
607
0
  return xtensa_opcode_lookup (isa, intisa->slots[slot_id].nop_name);
608
0
}
609
610
611
int
612
xtensa_format_get_slot (xtensa_isa isa, xtensa_format fmt, int slot,
613
      const xtensa_insnbuf insn, xtensa_insnbuf slotbuf)
614
14.4M
{
615
14.4M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
616
14.4M
  int slot_id;
617
618
14.4M
  CHECK_FORMAT (intisa, fmt, -1);
619
14.4M
  CHECK_SLOT (intisa, fmt, slot, -1);
620
621
14.4M
  slot_id = intisa->formats[fmt].slot_id[slot];
622
14.4M
  (*intisa->slots[slot_id].get_fn) (insn, slotbuf);
623
14.4M
  return 0;
624
14.4M
}
625
626
627
int
628
xtensa_format_set_slot (xtensa_isa isa, xtensa_format fmt, int slot,
629
      xtensa_insnbuf insn, const xtensa_insnbuf slotbuf)
630
361
{
631
361
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
632
361
  int slot_id;
633
634
361
  CHECK_FORMAT (intisa, fmt, -1);
635
361
  CHECK_SLOT (intisa, fmt, slot, -1);
636
637
361
  slot_id = intisa->formats[fmt].slot_id[slot];
638
361
  (*intisa->slots[slot_id].set_fn) (insn, slotbuf);
639
361
  return 0;
640
361
}
641
642
643

644
/* Opcode information.  */
645
646
647
#define CHECK_OPCODE(INTISA,OPC,ERRVAL) \
648
107M
  do { \
649
107M
    if ((OPC) < 0 || (OPC) >= (INTISA)->num_opcodes) \
650
107M
      { \
651
0
  xtisa_errno = xtensa_isa_bad_opcode; \
652
0
  strcpy (xtisa_error_msg, "invalid opcode specifier"); \
653
0
  return (ERRVAL); \
654
0
      } \
655
107M
  } while (0)
656
657
658
xtensa_opcode
659
xtensa_opcode_lookup (xtensa_isa isa, const char *opname)
660
10
{
661
10
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
662
10
  xtensa_lookup_entry entry, *result = 0;
663
664
10
  if (!opname || !*opname)
665
0
    {
666
0
      xtisa_errno = xtensa_isa_bad_opcode;
667
0
      strcpy (xtisa_error_msg, "invalid opcode name");
668
0
      return XTENSA_UNDEFINED;
669
0
    }
670
671
10
  if (intisa->num_opcodes != 0)
672
10
    {
673
10
      entry.key = opname;
674
10
      result = bsearch (&entry, intisa->opname_lookup_table,
675
10
      intisa->num_opcodes, sizeof (xtensa_lookup_entry),
676
10
      xtensa_isa_name_compare);
677
10
    }
678
679
10
  if (!result)
680
1
    {
681
1
      xtisa_errno = xtensa_isa_bad_opcode;
682
1
      sprintf (xtisa_error_msg, "opcode \"%s\" not recognized", opname);
683
1
      return XTENSA_UNDEFINED;
684
1
    }
685
686
9
  return result->u.opcode;
687
10
}
688
689
690
xtensa_opcode
691
xtensa_opcode_decode (xtensa_isa isa, xtensa_format fmt, int slot,
692
          const xtensa_insnbuf slotbuf)
693
14.4M
{
694
14.4M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
695
14.4M
  int slot_id;
696
14.4M
  xtensa_opcode opc;
697
698
14.4M
  CHECK_FORMAT (intisa, fmt, XTENSA_UNDEFINED);
699
14.4M
  CHECK_SLOT (intisa, fmt, slot, XTENSA_UNDEFINED);
700
701
14.4M
  slot_id = intisa->formats[fmt].slot_id[slot];
702
703
14.4M
  opc = (intisa->slots[slot_id].opcode_decode_fn) (slotbuf);
704
14.4M
  if (opc != XTENSA_UNDEFINED)
705
14.4M
    return opc;
706
707
0
  xtisa_errno = xtensa_isa_bad_opcode;
708
0
  strcpy (xtisa_error_msg, "cannot decode opcode");
709
0
  return XTENSA_UNDEFINED;
710
14.4M
}
711
712
713
int
714
xtensa_opcode_encode (xtensa_isa isa, xtensa_format fmt, int slot,
715
          xtensa_insnbuf slotbuf, xtensa_opcode opc)
716
0
{
717
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
718
0
  int slot_id;
719
0
  xtensa_opcode_encode_fn encode_fn;
720
721
0
  CHECK_FORMAT (intisa, fmt, -1);
722
0
  CHECK_SLOT (intisa, fmt, slot, -1);
723
0
  CHECK_OPCODE (intisa, opc, -1);
724
725
0
  slot_id = intisa->formats[fmt].slot_id[slot];
726
0
  encode_fn = intisa->opcodes[opc].encode_fns[slot_id];
727
0
  if (!encode_fn)
728
0
    {
729
0
      xtisa_errno = xtensa_isa_wrong_slot;
730
0
      sprintf (xtisa_error_msg,
731
0
         "opcode \"%s\" is not allowed in slot %d of format \"%s\"",
732
0
         intisa->opcodes[opc].name, slot, intisa->formats[fmt].name);
733
0
      return -1;
734
0
    }
735
0
  (*encode_fn) (slotbuf);
736
0
  return 0;
737
0
}
738
739
740
const char *
741
xtensa_opcode_name (xtensa_isa isa, xtensa_opcode opc)
742
8.57M
{
743
8.57M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
744
8.57M
  CHECK_OPCODE (intisa, opc, NULL);
745
8.57M
  return intisa->opcodes[opc].name;
746
8.57M
}
747
748
749
int
750
xtensa_opcode_is_branch (xtensa_isa isa, xtensa_opcode opc)
751
7.24M
{
752
7.24M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
753
7.24M
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
754
7.24M
  if ((intisa->opcodes[opc].flags & XTENSA_OPCODE_IS_BRANCH) != 0)
755
527k
    return 1;
756
6.71M
  return 0;
757
7.24M
}
758
759
760
int
761
xtensa_opcode_is_jump (xtensa_isa isa, xtensa_opcode opc)
762
6.71M
{
763
6.71M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
764
6.71M
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
765
6.71M
  if ((intisa->opcodes[opc].flags & XTENSA_OPCODE_IS_JUMP) != 0)
766
145k
    return 1;
767
6.57M
  return 0;
768
6.71M
}
769
770
771
int
772
xtensa_opcode_is_loop (xtensa_isa isa, xtensa_opcode opc)
773
0
{
774
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
775
0
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
776
0
  if ((intisa->opcodes[opc].flags & XTENSA_OPCODE_IS_LOOP) != 0)
777
0
    return 1;
778
0
  return 0;
779
0
}
780
781
782
int
783
xtensa_opcode_is_call (xtensa_isa isa, xtensa_opcode opc)
784
6.57M
{
785
6.57M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
786
6.57M
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
787
6.57M
  if ((intisa->opcodes[opc].flags & XTENSA_OPCODE_IS_CALL) != 0)
788
267k
    return 1;
789
6.30M
  return 0;
790
6.57M
}
791
792
793
int
794
xtensa_opcode_num_operands (xtensa_isa isa, xtensa_opcode opc)
795
7.24M
{
796
7.24M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
797
7.24M
  int iclass_id;
798
799
7.24M
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
800
7.24M
  iclass_id = intisa->opcodes[opc].iclass_id;
801
7.24M
  return intisa->iclasses[iclass_id].num_operands;
802
7.24M
}
803
804
805
int
806
xtensa_opcode_num_stateOperands (xtensa_isa isa, xtensa_opcode opc)
807
0
{
808
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
809
0
  int iclass_id;
810
811
0
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
812
0
  iclass_id = intisa->opcodes[opc].iclass_id;
813
0
  return intisa->iclasses[iclass_id].num_stateOperands;
814
0
}
815
816
817
int
818
xtensa_opcode_num_interfaceOperands (xtensa_isa isa, xtensa_opcode opc)
819
0
{
820
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
821
0
  int iclass_id;
822
823
0
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
824
0
  iclass_id = intisa->opcodes[opc].iclass_id;
825
0
  return intisa->iclasses[iclass_id].num_interfaceOperands;
826
0
}
827
828
829
int
830
xtensa_opcode_num_funcUnit_uses (xtensa_isa isa, xtensa_opcode opc)
831
0
{
832
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
833
0
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
834
0
  return intisa->opcodes[opc].num_funcUnit_uses;
835
0
}
836
837
838
xtensa_funcUnit_use *
839
xtensa_opcode_funcUnit_use (xtensa_isa isa, xtensa_opcode opc, int u)
840
0
{
841
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
842
0
  CHECK_OPCODE (intisa, opc, NULL);
843
0
  if (u < 0 || u >= intisa->opcodes[opc].num_funcUnit_uses)
844
0
    {
845
0
      xtisa_errno = xtensa_isa_bad_funcUnit;
846
0
      sprintf (xtisa_error_msg, "invalid functional unit use number (%d); "
847
0
         "opcode \"%s\" has %d", u, intisa->opcodes[opc].name,
848
0
         intisa->opcodes[opc].num_funcUnit_uses);
849
0
      return NULL;
850
0
    }
851
0
  return &intisa->opcodes[opc].funcUnit_uses[u];
852
0
}
853
854
855

856
/* Operand information.  */
857
858
859
#define CHECK_OPERAND(INTISA,OPC,ICLASS,OPND,ERRVAL) \
860
71.1M
  do { \
861
71.1M
    if ((OPND) < 0 || (OPND) >= (ICLASS)->num_operands) \
862
71.1M
      { \
863
0
  xtisa_errno = xtensa_isa_bad_operand; \
864
0
  sprintf (xtisa_error_msg, "invalid operand number (%d); " \
865
0
     "opcode \"%s\" has %d operands", (OPND), \
866
0
     (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_operands); \
867
0
  return (ERRVAL); \
868
0
      } \
869
71.1M
  } while (0)
870
871
872
static xtensa_operand_internal *
873
get_operand (xtensa_isa_internal *intisa, xtensa_opcode opc, int opnd)
874
60.4M
{
875
60.4M
  xtensa_iclass_internal *iclass;
876
60.4M
  int iclass_id, operand_id;
877
878
60.4M
  CHECK_OPCODE (intisa, opc, NULL);
879
60.4M
  iclass_id = intisa->opcodes[opc].iclass_id;
880
60.4M
  iclass = &intisa->iclasses[iclass_id];
881
60.4M
  CHECK_OPERAND (intisa, opc, iclass, opnd, NULL);
882
60.4M
  operand_id = iclass->operands[opnd].u.operand_id;
883
60.4M
  return &intisa->operands[operand_id];
884
60.4M
}
885
886
887
const char *
888
xtensa_operand_name (xtensa_isa isa, xtensa_opcode opc, int opnd)
889
0
{
890
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
891
0
  xtensa_operand_internal *intop;
892
893
0
  intop = get_operand (intisa, opc, opnd);
894
0
  if (!intop) return NULL;
895
0
  return intop->name;
896
0
}
897
898
899
int
900
xtensa_operand_is_visible (xtensa_isa isa, xtensa_opcode opc, int opnd)
901
10.7M
{
902
10.7M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
903
10.7M
  xtensa_iclass_internal *iclass;
904
10.7M
  int iclass_id, operand_id;
905
10.7M
  xtensa_operand_internal *intop;
906
907
10.7M
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
908
10.7M
  iclass_id = intisa->opcodes[opc].iclass_id;
909
10.7M
  iclass = &intisa->iclasses[iclass_id];
910
10.7M
  CHECK_OPERAND (intisa, opc, iclass, opnd, XTENSA_UNDEFINED);
911
912
  /* Special case for "sout" operands.  */
913
10.7M
  if (iclass->operands[opnd].inout == 's')
914
17.3k
    return 0;
915
916
10.6M
  operand_id = iclass->operands[opnd].u.operand_id;
917
10.6M
  intop = &intisa->operands[operand_id];
918
919
10.6M
  if ((intop->flags & XTENSA_OPERAND_IS_INVISIBLE) == 0)
920
10.4M
    return 1;
921
285k
  return 0;
922
10.6M
}
923
924
925
char
926
xtensa_operand_inout (xtensa_isa isa, xtensa_opcode opc, int opnd)
927
0
{
928
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
929
0
  xtensa_iclass_internal *iclass;
930
0
  int iclass_id;
931
0
  char inout;
932
933
0
  CHECK_OPCODE (intisa, opc, 0);
934
0
  iclass_id = intisa->opcodes[opc].iclass_id;
935
0
  iclass = &intisa->iclasses[iclass_id];
936
0
  CHECK_OPERAND (intisa, opc, iclass, opnd, 0);
937
0
  inout = iclass->operands[opnd].inout;
938
939
  /* Special case for "sout" operands.  */
940
0
  if (inout == 's')
941
0
    return 'o';
942
943
0
  return inout;
944
0
}
945
946
947
int
948
xtensa_operand_get_field (xtensa_isa isa, xtensa_opcode opc, int opnd,
949
        xtensa_format fmt, int slot,
950
        const xtensa_insnbuf slotbuf, uint32 *valp)
951
10.4M
{
952
10.4M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
953
10.4M
  xtensa_operand_internal *intop;
954
10.4M
  int slot_id;
955
10.4M
  xtensa_get_field_fn get_fn;
956
957
10.4M
  intop = get_operand (intisa, opc, opnd);
958
10.4M
  if (!intop) return -1;
959
960
10.4M
  CHECK_FORMAT (intisa, fmt, -1);
961
10.4M
  CHECK_SLOT (intisa, fmt, slot, -1);
962
963
10.4M
  slot_id = intisa->formats[fmt].slot_id[slot];
964
10.4M
  if (intop->field_id == XTENSA_UNDEFINED)
965
0
    {
966
0
      xtisa_errno = xtensa_isa_no_field;
967
0
      strcpy (xtisa_error_msg, "implicit operand has no field");
968
0
      return -1;
969
0
    }
970
10.4M
  get_fn = intisa->slots[slot_id].get_field_fns[intop->field_id];
971
10.4M
  if (!get_fn)
972
0
    {
973
0
      xtisa_errno = xtensa_isa_wrong_slot;
974
0
      sprintf (xtisa_error_msg,
975
0
         "operand \"%s\" does not exist in slot %d of format \"%s\"",
976
0
         intop->name, slot, intisa->formats[fmt].name);
977
0
      return -1;
978
0
    }
979
10.4M
  *valp = (*get_fn) (slotbuf);
980
10.4M
  return 0;
981
10.4M
}
982
983
984
int
985
xtensa_operand_set_field (xtensa_isa isa, xtensa_opcode opc, int opnd,
986
        xtensa_format fmt, int slot,
987
        xtensa_insnbuf slotbuf, uint32 val)
988
361
{
989
361
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
990
361
  xtensa_operand_internal *intop;
991
361
  int slot_id;
992
361
  xtensa_set_field_fn set_fn;
993
994
361
  intop = get_operand (intisa, opc, opnd);
995
361
  if (!intop) return -1;
996
997
361
  CHECK_FORMAT (intisa, fmt, -1);
998
361
  CHECK_SLOT (intisa, fmt, slot, -1);
999
1000
361
  slot_id = intisa->formats[fmt].slot_id[slot];
1001
361
  if (intop->field_id == XTENSA_UNDEFINED)
1002
0
    {
1003
0
      xtisa_errno = xtensa_isa_no_field;
1004
0
      strcpy (xtisa_error_msg, "implicit operand has no field");
1005
0
      return -1;
1006
0
    }
1007
361
  set_fn = intisa->slots[slot_id].set_field_fns[intop->field_id];
1008
361
  if (!set_fn)
1009
0
    {
1010
0
      xtisa_errno = xtensa_isa_wrong_slot;
1011
0
      sprintf (xtisa_error_msg,
1012
0
         "operand \"%s\" does not exist in slot %d of format \"%s\"",
1013
0
         intop->name, slot, intisa->formats[fmt].name);
1014
0
      return -1;
1015
0
    }
1016
361
  (*set_fn) (slotbuf, val);
1017
361
  return 0;
1018
361
}
1019
1020
1021
int
1022
xtensa_operand_encode (xtensa_isa isa, xtensa_opcode opc, int opnd,
1023
           uint32 *valp)
1024
535
{
1025
535
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1026
535
  xtensa_operand_internal *intop;
1027
535
  uint32 test_val, orig_val;
1028
1029
535
  intop = get_operand (intisa, opc, opnd);
1030
535
  if (!intop)
1031
0
    return -1;
1032
1033
535
  if (!intop->encode)
1034
49
    {
1035
      /* This is a default operand for a field.  How can we tell if the
1036
   value fits in the field?  Write the value into the field,
1037
   read it back, and then make sure we get the same value.  */
1038
49
      static xtensa_insnbuf tmpbuf = 0;
1039
49
      int slot_id;
1040
1041
49
      if (!tmpbuf)
1042
1
  {
1043
1
    tmpbuf = xtensa_insnbuf_alloc (isa);
1044
1
    CHECK_ALLOC (tmpbuf, -1);
1045
1
  }
1046
1047
      /* A default operand is always associated with a field,
1048
   but check just to be sure....  */
1049
49
      if (intop->field_id == XTENSA_UNDEFINED)
1050
0
  {
1051
0
    xtisa_errno = xtensa_isa_internal_error;
1052
0
    strcpy (xtisa_error_msg, "operand has no field");
1053
0
    return -1;
1054
0
  }
1055
1056
      /* Find some slot that includes the field.  */
1057
49
      for (slot_id = 0; slot_id < intisa->num_slots; slot_id++)
1058
49
  {
1059
49
    xtensa_get_field_fn get_fn =
1060
49
      intisa->slots[slot_id].get_field_fns[intop->field_id];
1061
49
    xtensa_set_field_fn set_fn =
1062
49
      intisa->slots[slot_id].set_field_fns[intop->field_id];
1063
1064
49
    if (get_fn && set_fn)
1065
49
      {
1066
49
        (*set_fn) (tmpbuf, *valp);
1067
49
        return ((*get_fn) (tmpbuf) != *valp);
1068
49
      }
1069
49
  }
1070
1071
      /* Couldn't find any slot containing the field....  */
1072
0
      xtisa_errno = xtensa_isa_no_field;
1073
0
      strcpy (xtisa_error_msg, "field does not exist in any slot");
1074
0
      return -1;
1075
49
    }
1076
1077
  /* Encode the value.  In some cases, the encoding function may detect
1078
     errors, but most of the time the only way to determine if the value
1079
     was successfully encoded is to decode it and check if it matches
1080
     the original value.  */
1081
486
  orig_val = *valp;
1082
486
  if ((*intop->encode) (valp)
1083
486
      || (test_val = *valp, (*intop->decode) (&test_val))
1084
486
      || test_val != orig_val)
1085
170
    {
1086
170
      xtisa_errno = xtensa_isa_bad_value;
1087
170
      sprintf (xtisa_error_msg, "cannot encode operand value 0x%08x", *valp);
1088
170
      return -1;
1089
170
    }
1090
1091
316
  return 0;
1092
486
}
1093
1094
1095
int
1096
xtensa_operand_decode (xtensa_isa isa, xtensa_opcode opc, int opnd,
1097
           uint32 *valp)
1098
10.4M
{
1099
10.4M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1100
10.4M
  xtensa_operand_internal *intop;
1101
1102
10.4M
  intop = get_operand (intisa, opc, opnd);
1103
10.4M
  if (!intop) return -1;
1104
1105
  /* Use identity function for "default" operands.  */
1106
10.4M
  if (!intop->decode)
1107
356k
    return 0;
1108
1109
10.0M
  if ((*intop->decode) (valp))
1110
0
    {
1111
0
      xtisa_errno = xtensa_isa_bad_value;
1112
0
      sprintf (xtisa_error_msg, "cannot decode operand value 0x%08x", *valp);
1113
0
      return -1;
1114
0
    }
1115
10.0M
  return 0;
1116
10.0M
}
1117
1118
1119
int
1120
xtensa_operand_is_register (xtensa_isa isa, xtensa_opcode opc, int opnd)
1121
10.4M
{
1122
10.4M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1123
10.4M
  xtensa_operand_internal *intop;
1124
1125
10.4M
  intop = get_operand (intisa, opc, opnd);
1126
10.4M
  if (!intop) return XTENSA_UNDEFINED;
1127
1128
10.4M
  if ((intop->flags & XTENSA_OPERAND_IS_REGISTER) != 0)
1129
6.90M
    return 1;
1130
3.50M
  return 0;
1131
10.4M
}
1132
1133
1134
xtensa_regfile
1135
xtensa_operand_regfile (xtensa_isa isa, xtensa_opcode opc, int opnd)
1136
6.89M
{
1137
6.89M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1138
6.89M
  xtensa_operand_internal *intop;
1139
1140
6.89M
  intop = get_operand (intisa, opc, opnd);
1141
6.89M
  if (!intop) return XTENSA_UNDEFINED;
1142
1143
6.89M
  return intop->regfile;
1144
6.89M
}
1145
1146
1147
int
1148
xtensa_operand_num_regs (xtensa_isa isa, xtensa_opcode opc, int opnd)
1149
7.06M
{
1150
7.06M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1151
7.06M
  xtensa_operand_internal *intop;
1152
1153
7.06M
  intop = get_operand (intisa, opc, opnd);
1154
7.06M
  if (!intop) return XTENSA_UNDEFINED;
1155
1156
7.06M
  return intop->num_regs;
1157
7.06M
}
1158
1159
1160
int
1161
xtensa_operand_is_known_reg (xtensa_isa isa, xtensa_opcode opc, int opnd)
1162
0
{
1163
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1164
0
  xtensa_operand_internal *intop;
1165
1166
0
  intop = get_operand (intisa, opc, opnd);
1167
0
  if (!intop) return XTENSA_UNDEFINED;
1168
1169
0
  if ((intop->flags & XTENSA_OPERAND_IS_UNKNOWN) == 0)
1170
0
    return 1;
1171
0
  return 0;
1172
0
}
1173
1174
1175
int
1176
xtensa_operand_is_PCrelative (xtensa_isa isa, xtensa_opcode opc, int opnd)
1177
13.9M
{
1178
13.9M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1179
13.9M
  xtensa_operand_internal *intop;
1180
1181
13.9M
  intop = get_operand (intisa, opc, opnd);
1182
13.9M
  if (!intop) return XTENSA_UNDEFINED;
1183
1184
13.9M
  if ((intop->flags & XTENSA_OPERAND_IS_PCRELATIVE) != 0)
1185
2.65M
    return 1;
1186
11.2M
  return 0;
1187
13.9M
}
1188
1189
1190
int
1191
xtensa_operand_do_reloc (xtensa_isa isa, xtensa_opcode opc, int opnd,
1192
       uint32 *valp, uint32 pc)
1193
535
{
1194
535
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1195
535
  xtensa_operand_internal *intop;
1196
1197
535
  intop = get_operand (intisa, opc, opnd);
1198
535
  if (!intop) return -1;
1199
1200
535
  if ((intop->flags & XTENSA_OPERAND_IS_PCRELATIVE) == 0)
1201
309
    return 0;
1202
1203
226
  if (!intop->do_reloc)
1204
0
    {
1205
0
      xtisa_errno = xtensa_isa_internal_error;
1206
0
      strcpy (xtisa_error_msg, "operand missing do_reloc function");
1207
0
      return -1;
1208
0
    }
1209
1210
226
  if ((*intop->do_reloc) (valp, pc))
1211
0
    {
1212
0
      xtisa_errno = xtensa_isa_bad_value;
1213
0
      sprintf (xtisa_error_msg,
1214
0
         "do_reloc failed for value 0x%08x at PC 0x%08x", *valp, pc);
1215
0
      return -1;
1216
0
    }
1217
1218
226
  return 0;
1219
226
}
1220
1221
1222
int
1223
xtensa_operand_undo_reloc (xtensa_isa isa, xtensa_opcode opc, int opnd,
1224
         uint32 *valp, uint32 pc)
1225
1.32M
{
1226
1.32M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1227
1.32M
  xtensa_operand_internal *intop;
1228
1229
1.32M
  intop = get_operand (intisa, opc, opnd);
1230
1.32M
  if (!intop) return -1;
1231
1232
1.32M
  if ((intop->flags & XTENSA_OPERAND_IS_PCRELATIVE) == 0)
1233
0
    return 0;
1234
1235
1.32M
  if (!intop->undo_reloc)
1236
0
    {
1237
0
      xtisa_errno = xtensa_isa_internal_error;
1238
0
      strcpy (xtisa_error_msg, "operand missing undo_reloc function");
1239
0
      return -1;
1240
0
    }
1241
1242
1.32M
  if ((*intop->undo_reloc) (valp, pc))
1243
0
    {
1244
0
      xtisa_errno = xtensa_isa_bad_value;
1245
0
      sprintf (xtisa_error_msg,
1246
0
         "undo_reloc failed for value 0x%08x at PC 0x%08x", *valp, pc);
1247
0
      return -1;
1248
0
    }
1249
1250
1.32M
  return 0;
1251
1.32M
}
1252
1253
1254

1255
/* State Operands.  */
1256
1257
1258
#define CHECK_STATE_OPERAND(INTISA,OPC,ICLASS,STOP,ERRVAL) \
1259
0
  do { \
1260
0
    if ((STOP) < 0 || (STOP) >= (ICLASS)->num_stateOperands) \
1261
0
      { \
1262
0
  xtisa_errno = xtensa_isa_bad_operand; \
1263
0
  sprintf (xtisa_error_msg, "invalid state operand number (%d); " \
1264
0
     "opcode \"%s\" has %d state operands", (STOP), \
1265
0
     (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_stateOperands); \
1266
0
  return (ERRVAL); \
1267
0
      } \
1268
0
  } while (0)
1269
1270
1271
xtensa_state
1272
xtensa_stateOperand_state (xtensa_isa isa, xtensa_opcode opc, int stOp)
1273
0
{
1274
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1275
0
  xtensa_iclass_internal *iclass;
1276
0
  int iclass_id;
1277
1278
0
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
1279
0
  iclass_id = intisa->opcodes[opc].iclass_id;
1280
0
  iclass = &intisa->iclasses[iclass_id];
1281
0
  CHECK_STATE_OPERAND (intisa, opc, iclass, stOp, XTENSA_UNDEFINED);
1282
0
  return iclass->stateOperands[stOp].u.state;
1283
0
}
1284
1285
1286
char
1287
xtensa_stateOperand_inout (xtensa_isa isa, xtensa_opcode opc, int stOp)
1288
0
{
1289
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1290
0
  xtensa_iclass_internal *iclass;
1291
0
  int iclass_id;
1292
1293
0
  CHECK_OPCODE (intisa, opc, 0);
1294
0
  iclass_id = intisa->opcodes[opc].iclass_id;
1295
0
  iclass = &intisa->iclasses[iclass_id];
1296
0
  CHECK_STATE_OPERAND (intisa, opc, iclass, stOp, 0);
1297
0
  return iclass->stateOperands[stOp].inout;
1298
0
}
1299
1300
1301

1302
/* Interface Operands.  */
1303
1304
1305
#define CHECK_INTERFACE_OPERAND(INTISA,OPC,ICLASS,IFOP,ERRVAL) \
1306
0
  do { \
1307
0
    if ((IFOP) < 0 || (IFOP) >= (ICLASS)->num_interfaceOperands) \
1308
0
      { \
1309
0
  xtisa_errno = xtensa_isa_bad_operand; \
1310
0
  sprintf (xtisa_error_msg, "invalid interface operand number (%d); " \
1311
0
     "opcode \"%s\" has %d interface operands", (IFOP), \
1312
0
     (INTISA)->opcodes[(OPC)].name, \
1313
0
     (ICLASS)->num_interfaceOperands); \
1314
0
  return (ERRVAL); \
1315
0
      } \
1316
0
  } while (0)
1317
1318
1319
xtensa_interface
1320
xtensa_interfaceOperand_interface (xtensa_isa isa, xtensa_opcode opc,
1321
           int ifOp)
1322
0
{
1323
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1324
0
  xtensa_iclass_internal *iclass;
1325
0
  int iclass_id;
1326
1327
0
  CHECK_OPCODE (intisa, opc, XTENSA_UNDEFINED);
1328
0
  iclass_id = intisa->opcodes[opc].iclass_id;
1329
0
  iclass = &intisa->iclasses[iclass_id];
1330
0
  CHECK_INTERFACE_OPERAND (intisa, opc, iclass, ifOp, XTENSA_UNDEFINED);
1331
0
  return iclass->interfaceOperands[ifOp];
1332
0
}
1333
1334
1335

1336
/* Register Files.  */
1337
1338
1339
#define CHECK_REGFILE(INTISA,RF,ERRVAL) \
1340
7.06M
  do { \
1341
7.06M
    if ((RF) < 0 || (RF) >= (INTISA)->num_regfiles) \
1342
7.06M
      { \
1343
0
  xtisa_errno = xtensa_isa_bad_regfile; \
1344
0
  strcpy (xtisa_error_msg, "invalid regfile specifier"); \
1345
0
  return (ERRVAL); \
1346
0
      } \
1347
7.06M
  } while (0)
1348
1349
1350
xtensa_regfile
1351
xtensa_regfile_lookup (xtensa_isa isa, const char *name)
1352
0
{
1353
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1354
0
  int n;
1355
1356
0
  if (!name || !*name)
1357
0
    {
1358
0
      xtisa_errno = xtensa_isa_bad_regfile;
1359
0
      strcpy (xtisa_error_msg, "invalid regfile name");
1360
0
      return XTENSA_UNDEFINED;
1361
0
    }
1362
1363
  /* The expected number of regfiles is small; use a linear search.  */
1364
0
  for (n = 0; n < intisa->num_regfiles; n++)
1365
0
    {
1366
0
      if (!filename_cmp (intisa->regfiles[n].name, name))
1367
0
  return n;
1368
0
    }
1369
1370
0
  xtisa_errno = xtensa_isa_bad_regfile;
1371
0
  sprintf (xtisa_error_msg, "regfile \"%s\" not recognized", name);
1372
0
  return XTENSA_UNDEFINED;
1373
0
}
1374
1375
1376
xtensa_regfile
1377
xtensa_regfile_lookup_shortname (xtensa_isa isa, const char *shortname)
1378
0
{
1379
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1380
0
  int n;
1381
1382
0
  if (!shortname || !*shortname)
1383
0
    {
1384
0
      xtisa_errno = xtensa_isa_bad_regfile;
1385
0
      strcpy (xtisa_error_msg, "invalid regfile shortname");
1386
0
      return XTENSA_UNDEFINED;
1387
0
    }
1388
1389
  /* The expected number of regfiles is small; use a linear search.  */
1390
0
  for (n = 0; n < intisa->num_regfiles; n++)
1391
0
    {
1392
      /* Ignore regfile views since they always have the same shortnames
1393
   as their parents.  */
1394
0
      if (intisa->regfiles[n].parent != n)
1395
0
  continue;
1396
0
      if (!filename_cmp (intisa->regfiles[n].shortname, shortname))
1397
0
  return n;
1398
0
    }
1399
1400
0
  xtisa_errno = xtensa_isa_bad_regfile;
1401
0
  sprintf (xtisa_error_msg, "regfile shortname \"%s\" not recognized",
1402
0
     shortname);
1403
0
  return XTENSA_UNDEFINED;
1404
0
}
1405
1406
1407
const char *
1408
xtensa_regfile_name (xtensa_isa isa, xtensa_regfile rf)
1409
0
{
1410
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1411
0
  CHECK_REGFILE (intisa, rf, NULL);
1412
0
  return intisa->regfiles[rf].name;
1413
0
}
1414
1415
1416
const char *
1417
xtensa_regfile_shortname (xtensa_isa isa, xtensa_regfile rf)
1418
7.06M
{
1419
7.06M
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1420
7.06M
  CHECK_REGFILE (intisa, rf, NULL);
1421
7.06M
  return intisa->regfiles[rf].shortname;
1422
7.06M
}
1423
1424
1425
xtensa_regfile
1426
xtensa_regfile_view_parent (xtensa_isa isa, xtensa_regfile rf)
1427
0
{
1428
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1429
0
  CHECK_REGFILE (intisa, rf, XTENSA_UNDEFINED);
1430
0
  return intisa->regfiles[rf].parent;
1431
0
}
1432
1433
1434
int
1435
xtensa_regfile_num_bits (xtensa_isa isa, xtensa_regfile rf)
1436
0
{
1437
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1438
0
  CHECK_REGFILE (intisa, rf, XTENSA_UNDEFINED);
1439
0
  return intisa->regfiles[rf].num_bits;
1440
0
}
1441
1442
1443
int
1444
xtensa_regfile_num_entries (xtensa_isa isa, xtensa_regfile rf)
1445
0
{
1446
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1447
0
  CHECK_REGFILE (intisa, rf, XTENSA_UNDEFINED);
1448
0
  return intisa->regfiles[rf].num_entries;
1449
0
}
1450
1451
1452

1453
/* Processor States.  */
1454
1455
1456
#define CHECK_STATE(INTISA,ST,ERRVAL) \
1457
0
  do { \
1458
0
    if ((ST) < 0 || (ST) >= (INTISA)->num_states) \
1459
0
      { \
1460
0
  xtisa_errno = xtensa_isa_bad_state; \
1461
0
  strcpy (xtisa_error_msg, "invalid state specifier"); \
1462
0
  return (ERRVAL); \
1463
0
      } \
1464
0
  } while (0)
1465
1466
1467
xtensa_state
1468
xtensa_state_lookup (xtensa_isa isa, const char *name)
1469
0
{
1470
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1471
0
  xtensa_lookup_entry entry, *result = 0;
1472
1473
0
  if (!name || !*name)
1474
0
    {
1475
0
      xtisa_errno = xtensa_isa_bad_state;
1476
0
      strcpy (xtisa_error_msg, "invalid state name");
1477
0
      return XTENSA_UNDEFINED;
1478
0
    }
1479
1480
0
  if (intisa->num_states != 0)
1481
0
    {
1482
0
      entry.key = name;
1483
0
      result = bsearch (&entry, intisa->state_lookup_table, intisa->num_states,
1484
0
      sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
1485
0
    }
1486
1487
0
  if (!result)
1488
0
    {
1489
0
      xtisa_errno = xtensa_isa_bad_state;
1490
0
      sprintf (xtisa_error_msg, "state \"%s\" not recognized", name);
1491
0
      return XTENSA_UNDEFINED;
1492
0
    }
1493
1494
0
  return result->u.state;
1495
0
}
1496
1497
1498
const char *
1499
xtensa_state_name (xtensa_isa isa, xtensa_state st)
1500
0
{
1501
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1502
0
  CHECK_STATE (intisa, st, NULL);
1503
0
  return intisa->states[st].name;
1504
0
}
1505
1506
1507
int
1508
xtensa_state_num_bits (xtensa_isa isa, xtensa_state st)
1509
0
{
1510
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1511
0
  CHECK_STATE (intisa, st, XTENSA_UNDEFINED);
1512
0
  return intisa->states[st].num_bits;
1513
0
}
1514
1515
1516
int
1517
xtensa_state_is_exported (xtensa_isa isa, xtensa_state st)
1518
0
{
1519
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1520
0
  CHECK_STATE (intisa, st, XTENSA_UNDEFINED);
1521
0
  if ((intisa->states[st].flags & XTENSA_STATE_IS_EXPORTED) != 0)
1522
0
    return 1;
1523
0
  return 0;
1524
0
}
1525
1526
1527
int
1528
xtensa_state_is_shared_or (xtensa_isa isa, xtensa_state st)
1529
0
{
1530
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1531
0
  CHECK_STATE (intisa, st, XTENSA_UNDEFINED);
1532
0
  if ((intisa->states[st].flags & XTENSA_STATE_IS_SHARED_OR) != 0)
1533
0
    return 1;
1534
0
  return 0;
1535
0
}
1536
1537
1538

1539
/* Sysregs.  */
1540
1541
1542
#define CHECK_SYSREG(INTISA,SYSREG,ERRVAL) \
1543
0
  do { \
1544
0
    if ((SYSREG) < 0 || (SYSREG) >= (INTISA)->num_sysregs) \
1545
0
      { \
1546
0
  xtisa_errno = xtensa_isa_bad_sysreg; \
1547
0
  strcpy (xtisa_error_msg, "invalid sysreg specifier"); \
1548
0
  return (ERRVAL); \
1549
0
      } \
1550
0
  } while (0)
1551
1552
1553
xtensa_sysreg
1554
xtensa_sysreg_lookup (xtensa_isa isa, int num, int is_user)
1555
0
{
1556
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1557
1558
0
  if (is_user != 0)
1559
0
    is_user = 1;
1560
1561
0
  if (num < 0 || num > intisa->max_sysreg_num[is_user]
1562
0
      || intisa->sysreg_table[is_user][num] == XTENSA_UNDEFINED)
1563
0
    {
1564
0
      xtisa_errno = xtensa_isa_bad_sysreg;
1565
0
      strcpy (xtisa_error_msg, "sysreg not recognized");
1566
0
      return XTENSA_UNDEFINED;
1567
0
    }
1568
1569
0
  return intisa->sysreg_table[is_user][num];
1570
0
}
1571
1572
1573
xtensa_sysreg
1574
xtensa_sysreg_lookup_name (xtensa_isa isa, const char *name)
1575
0
{
1576
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1577
0
  xtensa_lookup_entry entry, *result = 0;
1578
1579
0
  if (!name || !*name)
1580
0
    {
1581
0
      xtisa_errno = xtensa_isa_bad_sysreg;
1582
0
      strcpy (xtisa_error_msg, "invalid sysreg name");
1583
0
      return XTENSA_UNDEFINED;
1584
0
    }
1585
1586
0
  if (intisa->num_sysregs != 0)
1587
0
    {
1588
0
      entry.key = name;
1589
0
      result = bsearch (&entry, intisa->sysreg_lookup_table,
1590
0
      intisa->num_sysregs, sizeof (xtensa_lookup_entry),
1591
0
      xtensa_isa_name_compare);
1592
0
    }
1593
1594
0
  if (!result)
1595
0
    {
1596
0
      xtisa_errno = xtensa_isa_bad_sysreg;
1597
0
      sprintf (xtisa_error_msg, "sysreg \"%s\" not recognized", name);
1598
0
      return XTENSA_UNDEFINED;
1599
0
    }
1600
1601
0
  return result->u.sysreg;
1602
0
}
1603
1604
1605
const char *
1606
xtensa_sysreg_name (xtensa_isa isa, xtensa_sysreg sysreg)
1607
0
{
1608
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1609
0
  CHECK_SYSREG (intisa, sysreg, NULL);
1610
0
  return intisa->sysregs[sysreg].name;
1611
0
}
1612
1613
1614
int
1615
xtensa_sysreg_number (xtensa_isa isa, xtensa_sysreg sysreg)
1616
0
{
1617
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1618
0
  CHECK_SYSREG (intisa, sysreg, XTENSA_UNDEFINED);
1619
0
  return intisa->sysregs[sysreg].number;
1620
0
}
1621
1622
1623
int
1624
xtensa_sysreg_is_user (xtensa_isa isa, xtensa_sysreg sysreg)
1625
0
{
1626
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1627
0
  CHECK_SYSREG (intisa, sysreg, XTENSA_UNDEFINED);
1628
0
  if (intisa->sysregs[sysreg].is_user)
1629
0
    return 1;
1630
0
  return 0;
1631
0
}
1632
1633
1634

1635
/* Interfaces.  */
1636
1637
1638
#define CHECK_INTERFACE(INTISA,INTF,ERRVAL) \
1639
0
  do { \
1640
0
    if ((INTF) < 0 || (INTF) >= (INTISA)->num_interfaces) \
1641
0
      { \
1642
0
  xtisa_errno = xtensa_isa_bad_interface; \
1643
0
  strcpy (xtisa_error_msg, "invalid interface specifier"); \
1644
0
  return (ERRVAL); \
1645
0
      } \
1646
0
  } while (0)
1647
1648
1649
xtensa_interface
1650
xtensa_interface_lookup (xtensa_isa isa, const char *ifname)
1651
0
{
1652
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1653
0
  xtensa_lookup_entry entry, *result = 0;
1654
1655
0
  if (!ifname || !*ifname)
1656
0
    {
1657
0
      xtisa_errno = xtensa_isa_bad_interface;
1658
0
      strcpy (xtisa_error_msg, "invalid interface name");
1659
0
      return XTENSA_UNDEFINED;
1660
0
    }
1661
1662
0
  if (intisa->num_interfaces != 0)
1663
0
    {
1664
0
      entry.key = ifname;
1665
0
      result = bsearch (&entry, intisa->interface_lookup_table,
1666
0
      intisa->num_interfaces, sizeof (xtensa_lookup_entry),
1667
0
      xtensa_isa_name_compare);
1668
0
    }
1669
1670
0
  if (!result)
1671
0
    {
1672
0
      xtisa_errno = xtensa_isa_bad_interface;
1673
0
      sprintf (xtisa_error_msg, "interface \"%s\" not recognized", ifname);
1674
0
      return XTENSA_UNDEFINED;
1675
0
    }
1676
1677
0
  return result->u.intf;
1678
0
}
1679
1680
1681
const char *
1682
xtensa_interface_name (xtensa_isa isa, xtensa_interface intf)
1683
0
{
1684
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1685
0
  CHECK_INTERFACE (intisa, intf, NULL);
1686
0
  return intisa->interfaces[intf].name;
1687
0
}
1688
1689
1690
int
1691
xtensa_interface_num_bits (xtensa_isa isa, xtensa_interface intf)
1692
0
{
1693
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1694
0
  CHECK_INTERFACE (intisa, intf, XTENSA_UNDEFINED);
1695
0
  return intisa->interfaces[intf].num_bits;
1696
0
}
1697
1698
1699
char
1700
xtensa_interface_inout (xtensa_isa isa, xtensa_interface intf)
1701
0
{
1702
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1703
0
  CHECK_INTERFACE (intisa, intf, 0);
1704
0
  return intisa->interfaces[intf].inout;
1705
0
}
1706
1707
1708
int
1709
xtensa_interface_has_side_effect (xtensa_isa isa, xtensa_interface intf)
1710
0
{
1711
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1712
0
  CHECK_INTERFACE (intisa, intf, XTENSA_UNDEFINED);
1713
0
  if ((intisa->interfaces[intf].flags & XTENSA_INTERFACE_HAS_SIDE_EFFECT) != 0)
1714
0
    return 1;
1715
0
  return 0;
1716
0
}
1717
1718
1719
int
1720
xtensa_interface_class_id (xtensa_isa isa, xtensa_interface intf)
1721
0
{
1722
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1723
0
  CHECK_INTERFACE (intisa, intf, XTENSA_UNDEFINED);
1724
0
  return intisa->interfaces[intf].class_id;
1725
0
}
1726
1727
1728

1729
/* Functional Units.  */
1730
1731
1732
#define CHECK_FUNCUNIT(INTISA,FUN,ERRVAL) \
1733
0
  do { \
1734
0
    if ((FUN) < 0 || (FUN) >= (INTISA)->num_funcUnits) \
1735
0
      { \
1736
0
  xtisa_errno = xtensa_isa_bad_funcUnit; \
1737
0
  strcpy (xtisa_error_msg, "invalid functional unit specifier"); \
1738
0
  return (ERRVAL); \
1739
0
      } \
1740
0
  } while (0)
1741
1742
1743
xtensa_funcUnit
1744
xtensa_funcUnit_lookup (xtensa_isa isa, const char *fname)
1745
0
{
1746
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1747
0
  xtensa_lookup_entry entry, *result = 0;
1748
1749
0
  if (!fname || !*fname)
1750
0
    {
1751
0
      xtisa_errno = xtensa_isa_bad_funcUnit;
1752
0
      strcpy (xtisa_error_msg, "invalid functional unit name");
1753
0
      return XTENSA_UNDEFINED;
1754
0
    }
1755
1756
0
  if (intisa->num_funcUnits != 0)
1757
0
    {
1758
0
      entry.key = fname;
1759
0
      result = bsearch (&entry, intisa->funcUnit_lookup_table,
1760
0
      intisa->num_funcUnits, sizeof (xtensa_lookup_entry),
1761
0
      xtensa_isa_name_compare);
1762
0
    }
1763
1764
0
  if (!result)
1765
0
    {
1766
0
      xtisa_errno = xtensa_isa_bad_funcUnit;
1767
0
      sprintf (xtisa_error_msg,
1768
0
         "functional unit \"%s\" not recognized", fname);
1769
0
      return XTENSA_UNDEFINED;
1770
0
    }
1771
1772
0
  return result->u.fun;
1773
0
}
1774
1775
1776
const char *
1777
xtensa_funcUnit_name (xtensa_isa isa, xtensa_funcUnit fun)
1778
0
{
1779
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1780
0
  CHECK_FUNCUNIT (intisa, fun, NULL);
1781
0
  return intisa->funcUnits[fun].name;
1782
0
}
1783
1784
1785
int
1786
xtensa_funcUnit_num_copies (xtensa_isa isa, xtensa_funcUnit fun)
1787
0
{
1788
0
  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
1789
0
  CHECK_FUNCUNIT (intisa, fun, XTENSA_UNDEFINED);
1790
0
  return intisa->funcUnits[fun].num_copies;
1791
0
}
1792