buildgcc: Update to binutils-2.26.1 & Fix aarch64 build issue
[coreboot.git] / util / crossgcc / patches / binutils-2.26.1_riscv.patch
blob248ee40f6a447b4f5c0f219dce8564001c512882
1 diff -urN empty/bfd/cpu-riscv.c binutils-2.26.1/bfd/cpu-riscv.c
2 --- empty/bfd/cpu-riscv.c 1970-01-01 08:00:00.000000000 +0800
3 +++ binutils-2.26.1/bfd/cpu-riscv.c 2016-04-03 10:33:12.058793036 +0800
4 @@ -0,0 +1,76 @@
5 +/* BFD backend for RISC-V
6 + Copyright 2011-2015 Free Software Foundation, Inc.
8 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
9 + Based on MIPS target.
11 + This file is part of BFD, the Binary File Descriptor library.
13 + This program is free software; you can redistribute it and/or modify
14 + it under the terms of the GNU General Public License as published by
15 + the Free Software Foundation; either version 3 of the License, or
16 + (at your option) any later version.
18 + This program is distributed in the hope that it will be useful,
19 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 + GNU General Public License for more details.
23 + You should have received a copy of the GNU General Public License
24 + along with this program; see the file COPYING3. If not,
25 + see <http://www.gnu.org/licenses/>. */
27 +#include "sysdep.h"
28 +#include "bfd.h"
29 +#include "libbfd.h"
31 +/* This routine is provided two arch_infos and returns an arch_info
32 + that is compatible with both, or NULL if none exists. */
34 +static const bfd_arch_info_type *
35 +riscv_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
37 + if (a->arch != b->arch)
38 + return NULL;
40 + /* Machine compatibility is checked in
41 + _bfd_riscv_elf_merge_private_bfd_data. */
43 + return a;
46 +#define N(BITS_WORD, BITS_ADDR, NUMBER, PRINT, DEFAULT, NEXT) \
47 + { \
48 + BITS_WORD, /* bits in a word */ \
49 + BITS_ADDR, /* bits in an address */ \
50 + 8, /* 8 bits in a byte */ \
51 + bfd_arch_riscv, \
52 + NUMBER, \
53 + "riscv", \
54 + PRINT, \
55 + 3, \
56 + DEFAULT, \
57 + riscv_compatible, \
58 + bfd_default_scan, \
59 + bfd_arch_default_fill, \
60 + NEXT, \
61 + }
63 +enum
65 + I_riscv64,
66 + I_riscv32
67 +};
69 +#define NN(index) (&arch_info_struct[(index) + 1])
71 +static const bfd_arch_info_type arch_info_struct[] =
73 + N (64, 64, bfd_mach_riscv64, "riscv:rv64", FALSE, NN (I_riscv64)),
74 + N (32, 32, bfd_mach_riscv32, "riscv:rv32", FALSE, 0)
75 +};
77 +/* The default architecture is riscv:rv64. */
79 +const bfd_arch_info_type bfd_riscv_arch =
80 + N (64, 64, 0, "riscv", TRUE, &arch_info_struct[0]);
81 diff -urN empty/bfd/elfnn-riscv.c binutils-2.26.1/bfd/elfnn-riscv.c
82 --- empty/bfd/elfnn-riscv.c 1970-01-01 08:00:00.000000000 +0800
83 +++ binutils-2.26.1/bfd/elfnn-riscv.c 2016-04-03 10:33:12.062126369 +0800
84 @@ -0,0 +1,3022 @@
85 +/* RISC-V-specific support for NN-bit ELF.
86 + Copyright 2011-2015 Free Software Foundation, Inc.
88 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
89 + Based on TILE-Gx and MIPS targets.
91 + This file is part of BFD, the Binary File Descriptor library.
93 + This program is free software; you can redistribute it and/or modify
94 + it under the terms of the GNU General Public License as published by
95 + the Free Software Foundation; either version 3 of the License, or
96 + (at your option) any later version.
98 + This program is distributed in the hope that it will be useful,
99 + but WITHOUT ANY WARRANTY; without even the implied warranty of
100 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 + GNU General Public License for more details.
103 + You should have received a copy of the GNU General Public License
104 + along with this program; see the file COPYING3. If not,
105 + see <http://www.gnu.org/licenses/>. */
107 +/* This file handles RISC-V ELF targets. */
109 +#include "sysdep.h"
110 +#include "bfd.h"
111 +#include "libbfd.h"
112 +#include "bfdlink.h"
113 +#include "genlink.h"
114 +#include "elf-bfd.h"
115 +#include "elfxx-riscv.h"
116 +#include "elf/riscv.h"
117 +#include "opcode/riscv.h"
119 +#define ARCH_SIZE NN
121 +#define MINUS_ONE ((bfd_vma)0 - 1)
123 +#define RISCV_ELF_LOG_WORD_BYTES (ARCH_SIZE == 32 ? 2 : 3)
125 +#define RISCV_ELF_WORD_BYTES (1 << RISCV_ELF_LOG_WORD_BYTES)
127 +/* The name of the dynamic interpreter. This is put in the .interp
128 + section. */
130 +#define ELF64_DYNAMIC_INTERPRETER "/lib/ld.so.1"
131 +#define ELF32_DYNAMIC_INTERPRETER "/lib32/ld.so.1"
133 +#define ELF_ARCH bfd_arch_riscv
134 +#define ELF_TARGET_ID RISCV_ELF_DATA
135 +#define ELF_MACHINE_CODE EM_RISCV
136 +#define ELF_MAXPAGESIZE 0x1000
137 +#define ELF_COMMONPAGESIZE 0x1000
139 +/* The RISC-V linker needs to keep track of the number of relocs that it
140 + decides to copy as dynamic relocs in check_relocs for each symbol.
141 + This is so that it can later discard them if they are found to be
142 + unnecessary. We store the information in a field extending the
143 + regular ELF linker hash table. */
145 +struct riscv_elf_dyn_relocs
147 + struct riscv_elf_dyn_relocs *next;
149 + /* The input section of the reloc. */
150 + asection *sec;
152 + /* Total number of relocs copied for the input section. */
153 + bfd_size_type count;
155 + /* Number of pc-relative relocs copied for the input section. */
156 + bfd_size_type pc_count;
159 +/* RISC-V ELF linker hash entry. */
161 +struct riscv_elf_link_hash_entry
163 + struct elf_link_hash_entry elf;
165 + /* Track dynamic relocs copied for this symbol. */
166 + struct riscv_elf_dyn_relocs *dyn_relocs;
168 +#define GOT_UNKNOWN 0
169 +#define GOT_NORMAL 1
170 +#define GOT_TLS_GD 2
171 +#define GOT_TLS_IE 4
172 +#define GOT_TLS_LE 8
173 + char tls_type;
176 +#define riscv_elf_hash_entry(ent) \
177 + ((struct riscv_elf_link_hash_entry *)(ent))
179 +struct _bfd_riscv_elf_obj_tdata
181 + struct elf_obj_tdata root;
183 + /* tls_type for each local got entry. */
184 + char *local_got_tls_type;
187 +#define _bfd_riscv_elf_tdata(abfd) \
188 + ((struct _bfd_riscv_elf_obj_tdata *) (abfd)->tdata.any)
190 +#define _bfd_riscv_elf_local_got_tls_type(abfd) \
191 + (_bfd_riscv_elf_tdata (abfd)->local_got_tls_type)
193 +#define _bfd_riscv_elf_tls_type(abfd, h, symndx) \
194 + (*((h) != NULL ? &riscv_elf_hash_entry (h)->tls_type \
195 + : &_bfd_riscv_elf_local_got_tls_type (abfd) [symndx]))
197 +#define is_riscv_elf(bfd) \
198 + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
199 + && elf_tdata (bfd) != NULL \
200 + && elf_object_id (bfd) == RISCV_ELF_DATA)
202 +#include "elf/common.h"
203 +#include "elf/internal.h"
205 +struct riscv_elf_link_hash_table
207 + struct elf_link_hash_table elf;
209 + /* Short-cuts to get to dynamic linker sections. */
210 + asection *sdynbss;
211 + asection *srelbss;
212 + asection *sdyntdata;
214 + /* Small local sym to section mapping cache. */
215 + struct sym_cache sym_cache;
219 +/* Get the RISC-V ELF linker hash table from a link_info structure. */
220 +#define riscv_elf_hash_table(p) \
221 + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
222 + == RISCV_ELF_DATA ? ((struct riscv_elf_link_hash_table *) ((p)->hash)) : NULL)
224 +static void
225 +riscv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
226 + arelent *cache_ptr,
227 + Elf_Internal_Rela *dst)
229 + cache_ptr->howto = riscv_elf_rtype_to_howto (ELFNN_R_TYPE (dst->r_info));
232 +static void
233 +riscv_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
235 + const struct elf_backend_data *bed;
236 + bfd_byte *loc;
238 + bed = get_elf_backend_data (abfd);
239 + loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
240 + bed->s->swap_reloca_out (abfd, rel, loc);
243 +/* PLT/GOT stuff */
245 +#define PLT_HEADER_INSNS 8
246 +#define PLT_ENTRY_INSNS 4
247 +#define PLT_HEADER_SIZE (PLT_HEADER_INSNS * 4)
248 +#define PLT_ENTRY_SIZE (PLT_ENTRY_INSNS * 4)
250 +#define GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES
252 +#define GOTPLT_HEADER_SIZE (2 * GOT_ENTRY_SIZE)
254 +#define sec_addr(sec) ((sec)->output_section->vma + (sec)->output_offset)
256 +static bfd_vma
257 +riscv_elf_got_plt_val (bfd_vma plt_index, struct bfd_link_info *info)
259 + return sec_addr (riscv_elf_hash_table (info)->elf.sgotplt)
260 + + GOTPLT_HEADER_SIZE + (plt_index * GOT_ENTRY_SIZE);
263 +#if ARCH_SIZE == 32
264 +# define MATCH_LREG MATCH_LW
265 +#else
266 +# define MATCH_LREG MATCH_LD
267 +#endif
269 +/* Generate a PLT header. */
271 +static void
272 +riscv_make_plt_header (bfd_vma gotplt_addr, bfd_vma addr, uint32_t *entry)
274 + bfd_vma gotplt_offset_high = RISCV_PCREL_HIGH_PART (gotplt_addr, addr);
275 + bfd_vma gotplt_offset_low = RISCV_PCREL_LOW_PART (gotplt_addr, addr);
277 + /* auipc t2, %hi(.got.plt)
278 + sub t1, t1, t3 # shifted .got.plt offset + hdr size + 12
279 + l[w|d] t3, %lo(.got.plt)(t2) # _dl_runtime_resolve
280 + addi t1, t1, -(hdr size + 12) # shifted .got.plt offset
281 + addi t0, t2, %lo(.got.plt) # &.got.plt
282 + srli t1, t1, log2(16/PTRSIZE) # .got.plt offset
283 + l[w|d] t0, PTRSIZE(t0) # link map
284 + jr t3 */
286 + entry[0] = RISCV_UTYPE (AUIPC, X_T2, gotplt_offset_high);
287 + entry[1] = RISCV_RTYPE (SUB, X_T1, X_T1, X_T3);
288 + entry[2] = RISCV_ITYPE (LREG, X_T3, X_T2, gotplt_offset_low);
289 + entry[3] = RISCV_ITYPE (ADDI, X_T1, X_T1, -(PLT_HEADER_SIZE + 12));
290 + entry[4] = RISCV_ITYPE (ADDI, X_T0, X_T2, gotplt_offset_low);
291 + entry[5] = RISCV_ITYPE (SRLI, X_T1, X_T1, 4 - RISCV_ELF_LOG_WORD_BYTES);
292 + entry[6] = RISCV_ITYPE (LREG, X_T0, X_T0, RISCV_ELF_WORD_BYTES);
293 + entry[7] = RISCV_ITYPE (JALR, 0, X_T3, 0);
296 +/* Generate a PLT entry. */
298 +static void
299 +riscv_make_plt_entry (bfd_vma got, bfd_vma addr, uint32_t *entry)
301 + /* auipc t3, %hi(.got.plt entry)
302 + l[w|d] t3, %lo(.got.plt entry)(t3)
303 + jalr t1, t3
304 + nop */
306 + entry[0] = RISCV_UTYPE (AUIPC, X_T3, RISCV_PCREL_HIGH_PART (got, addr));
307 + entry[1] = RISCV_ITYPE (LREG, X_T3, X_T3, RISCV_PCREL_LOW_PART(got, addr));
308 + entry[2] = RISCV_ITYPE (JALR, X_T1, X_T3, 0);
309 + entry[3] = RISCV_NOP;
312 +/* Create an entry in an RISC-V ELF linker hash table. */
314 +static struct bfd_hash_entry *
315 +link_hash_newfunc (struct bfd_hash_entry *entry,
316 + struct bfd_hash_table *table, const char *string)
318 + /* Allocate the structure if it has not already been allocated by a
319 + subclass. */
320 + if (entry == NULL)
322 + entry =
323 + bfd_hash_allocate (table,
324 + sizeof (struct riscv_elf_link_hash_entry));
325 + if (entry == NULL)
326 + return entry;
329 + /* Call the allocation method of the superclass. */
330 + entry = _bfd_elf_link_hash_newfunc (entry, table, string);
331 + if (entry != NULL)
333 + struct riscv_elf_link_hash_entry *eh;
335 + eh = (struct riscv_elf_link_hash_entry *) entry;
336 + eh->dyn_relocs = NULL;
337 + eh->tls_type = GOT_UNKNOWN;
340 + return entry;
343 +/* Create a RISC-V ELF linker hash table. */
345 +static struct bfd_link_hash_table *
346 +riscv_elf_link_hash_table_create (bfd *abfd)
348 + struct riscv_elf_link_hash_table *ret;
349 + bfd_size_type amt = sizeof (struct riscv_elf_link_hash_table);
351 + ret = (struct riscv_elf_link_hash_table *) bfd_zmalloc (amt);
352 + if (ret == NULL)
353 + return NULL;
355 + if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
356 + sizeof (struct riscv_elf_link_hash_entry),
357 + RISCV_ELF_DATA))
359 + free (ret);
360 + return NULL;
363 + return &ret->elf.root;
366 +/* Create the .got section. */
368 +static bfd_boolean
369 +riscv_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
371 + flagword flags;
372 + asection *s, *s_got;
373 + struct elf_link_hash_entry *h;
374 + const struct elf_backend_data *bed = get_elf_backend_data (abfd);
375 + struct elf_link_hash_table *htab = elf_hash_table (info);
377 + /* This function may be called more than once. */
378 + s = bfd_get_linker_section (abfd, ".got");
379 + if (s != NULL)
380 + return TRUE;
382 + flags = bed->dynamic_sec_flags;
384 + s = bfd_make_section_anyway_with_flags (abfd,
385 + (bed->rela_plts_and_copies_p
386 + ? ".rela.got" : ".rel.got"),
387 + (bed->dynamic_sec_flags
388 + | SEC_READONLY));
389 + if (s == NULL
390 + || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
391 + return FALSE;
392 + htab->srelgot = s;
394 + s = s_got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
395 + if (s == NULL
396 + || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
397 + return FALSE;
398 + htab->sgot = s;
400 + /* The first bit of the global offset table is the header. */
401 + s->size += bed->got_header_size;
403 + if (bed->want_got_plt)
405 + s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
406 + if (s == NULL
407 + || !bfd_set_section_alignment (abfd, s,
408 + bed->s->log_file_align))
409 + return FALSE;
410 + htab->sgotplt = s;
412 + /* Reserve room for the header. */
413 + s->size += GOTPLT_HEADER_SIZE;
416 + if (bed->want_got_sym)
418 + /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
419 + section. We don't do this in the linker script because we don't want
420 + to define the symbol if we are not creating a global offset
421 + table. */
422 + h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
423 + "_GLOBAL_OFFSET_TABLE_");
424 + elf_hash_table (info)->hgot = h;
425 + if (h == NULL)
426 + return FALSE;
429 + return TRUE;
432 +/* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
433 + .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
434 + hash table. */
436 +static bfd_boolean
437 +riscv_elf_create_dynamic_sections (bfd *dynobj,
438 + struct bfd_link_info *info)
440 + struct riscv_elf_link_hash_table *htab;
442 + htab = riscv_elf_hash_table (info);
443 + BFD_ASSERT (htab != NULL);
445 + if (!riscv_elf_create_got_section (dynobj, info))
446 + return FALSE;
448 + if (!_bfd_elf_create_dynamic_sections (dynobj, info))
449 + return FALSE;
451 + htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
452 + if (!bfd_link_pic (info))
454 + htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
455 + htab->sdyntdata =
456 + bfd_make_section_anyway_with_flags (dynobj, ".tdata.dyn",
457 + SEC_ALLOC | SEC_THREAD_LOCAL);
460 + if (!htab->elf.splt || !htab->elf.srelplt || !htab->sdynbss
461 + || (!bfd_link_pic (info) && (!htab->srelbss || !htab->sdyntdata)))
462 + abort ();
464 + return TRUE;
467 +/* Copy the extra info we tack onto an elf_link_hash_entry. */
469 +static void
470 +riscv_elf_copy_indirect_symbol (struct bfd_link_info *info,
471 + struct elf_link_hash_entry *dir,
472 + struct elf_link_hash_entry *ind)
474 + struct riscv_elf_link_hash_entry *edir, *eind;
476 + edir = (struct riscv_elf_link_hash_entry *) dir;
477 + eind = (struct riscv_elf_link_hash_entry *) ind;
479 + if (eind->dyn_relocs != NULL)
481 + if (edir->dyn_relocs != NULL)
483 + struct riscv_elf_dyn_relocs **pp;
484 + struct riscv_elf_dyn_relocs *p;
486 + /* Add reloc counts against the indirect sym to the direct sym
487 + list. Merge any entries against the same section. */
488 + for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
490 + struct riscv_elf_dyn_relocs *q;
492 + for (q = edir->dyn_relocs; q != NULL; q = q->next)
493 + if (q->sec == p->sec)
495 + q->pc_count += p->pc_count;
496 + q->count += p->count;
497 + *pp = p->next;
498 + break;
500 + if (q == NULL)
501 + pp = &p->next;
503 + *pp = edir->dyn_relocs;
506 + edir->dyn_relocs = eind->dyn_relocs;
507 + eind->dyn_relocs = NULL;
510 + if (ind->root.type == bfd_link_hash_indirect
511 + && dir->got.refcount <= 0)
513 + edir->tls_type = eind->tls_type;
514 + eind->tls_type = GOT_UNKNOWN;
516 + _bfd_elf_link_hash_copy_indirect (info, dir, ind);
519 +static bfd_boolean
520 +riscv_elf_record_tls_type (bfd *abfd, struct elf_link_hash_entry *h,
521 + unsigned long symndx, char tls_type)
523 + char *new_tls_type = &_bfd_riscv_elf_tls_type (abfd, h, symndx);
524 + *new_tls_type |= tls_type;
525 + if ((*new_tls_type & GOT_NORMAL) && (*new_tls_type & ~GOT_NORMAL))
527 + (*_bfd_error_handler)
528 + (_("%B: `%s' accessed both as normal and thread local symbol"),
529 + abfd, h ? h->root.root.string : "<local>");
530 + return FALSE;
532 + return TRUE;
535 +static bfd_boolean
536 +riscv_elf_record_got_reference (bfd *abfd, struct bfd_link_info *info,
537 + struct elf_link_hash_entry *h, long symndx)
539 + struct riscv_elf_link_hash_table *htab = riscv_elf_hash_table (info);
540 + Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
542 + if (htab->elf.sgot == NULL)
544 + if (!riscv_elf_create_got_section (htab->elf.dynobj, info))
545 + return FALSE;
548 + if (h != NULL)
550 + h->got.refcount += 1;
551 + return TRUE;
554 + /* This is a global offset table entry for a local symbol. */
555 + if (elf_local_got_refcounts (abfd) == NULL)
557 + bfd_size_type size = symtab_hdr->sh_info * (sizeof (bfd_vma) + 1);
558 + if (!(elf_local_got_refcounts (abfd) = bfd_zalloc (abfd, size)))
559 + return FALSE;
560 + _bfd_riscv_elf_local_got_tls_type (abfd)
561 + = (char *) (elf_local_got_refcounts (abfd) + symtab_hdr->sh_info);
563 + elf_local_got_refcounts (abfd) [symndx] += 1;
565 + return TRUE;
568 +static bfd_boolean
569 +bad_static_reloc (bfd *abfd, unsigned r_type, struct elf_link_hash_entry *h)
571 + (*_bfd_error_handler)
572 + (_("%B: relocation %s against `%s' can not be used when making a shared "
573 + "object; recompile with -fPIC"),
574 + abfd, riscv_elf_rtype_to_howto (r_type)->name,
575 + h != NULL ? h->root.root.string : "a local symbol");
576 + bfd_set_error (bfd_error_bad_value);
577 + return FALSE;
579 +/* Look through the relocs for a section during the first phase, and
580 + allocate space in the global offset table or procedure linkage
581 + table. */
583 +static bfd_boolean
584 +riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
585 + asection *sec, const Elf_Internal_Rela *relocs)
587 + struct riscv_elf_link_hash_table *htab;
588 + Elf_Internal_Shdr *symtab_hdr;
589 + struct elf_link_hash_entry **sym_hashes;
590 + const Elf_Internal_Rela *rel;
591 + asection *sreloc = NULL;
593 + if (bfd_link_relocatable (info))
594 + return TRUE;
596 + htab = riscv_elf_hash_table (info);
597 + symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
598 + sym_hashes = elf_sym_hashes (abfd);
600 + if (htab->elf.dynobj == NULL)
601 + htab->elf.dynobj = abfd;
603 + for (rel = relocs; rel < relocs + sec->reloc_count; rel++)
605 + unsigned int r_type;
606 + unsigned long r_symndx;
607 + struct elf_link_hash_entry *h;
609 + r_symndx = ELFNN_R_SYM (rel->r_info);
610 + r_type = ELFNN_R_TYPE (rel->r_info);
612 + if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
614 + (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
615 + abfd, r_symndx);
616 + return FALSE;
619 + if (r_symndx < symtab_hdr->sh_info)
620 + h = NULL;
621 + else
623 + h = sym_hashes[r_symndx - symtab_hdr->sh_info];
624 + while (h->root.type == bfd_link_hash_indirect
625 + || h->root.type == bfd_link_hash_warning)
626 + h = (struct elf_link_hash_entry *) h->root.u.i.link;
628 + /* PR15323, ref flags aren't set for references in the same
629 + object. */
630 + h->root.non_ir_ref = 1;
633 + switch (r_type)
635 + case R_RISCV_TLS_GD_HI20:
636 + if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
637 + || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_GD))
638 + return FALSE;
639 + break;
641 + case R_RISCV_TLS_GOT_HI20:
642 + if (bfd_link_pic (info))
643 + info->flags |= DF_STATIC_TLS;
644 + if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
645 + || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_IE))
646 + return FALSE;
647 + break;
649 + case R_RISCV_GOT_HI20:
650 + if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
651 + || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_NORMAL))
652 + return FALSE;
653 + break;
655 + case R_RISCV_CALL_PLT:
656 + /* This symbol requires a procedure linkage table entry. We
657 + actually build the entry in adjust_dynamic_symbol,
658 + because this might be a case of linking PIC code without
659 + linking in any dynamic objects, in which case we don't
660 + need to generate a procedure linkage table after all. */
662 + if (h != NULL)
664 + h->needs_plt = 1;
665 + h->plt.refcount += 1;
667 + break;
669 + case R_RISCV_CALL:
670 + case R_RISCV_JAL:
671 + case R_RISCV_BRANCH:
672 + case R_RISCV_RVC_BRANCH:
673 + case R_RISCV_RVC_JUMP:
674 + case R_RISCV_PCREL_HI20:
675 + /* In shared libraries, these relocs are known to bind locally. */
676 + if (bfd_link_pic (info))
677 + break;
678 + goto static_reloc;
680 + case R_RISCV_TPREL_HI20:
681 + if (!bfd_link_executable (info))
682 + return bad_static_reloc (abfd, r_type, h);
683 + if (h != NULL)
684 + riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_LE);
685 + goto static_reloc;
687 + case R_RISCV_HI20:
688 + if (bfd_link_pic (info))
689 + return bad_static_reloc (abfd, r_type, h);
690 + /* Fall through. */
692 + case R_RISCV_COPY:
693 + case R_RISCV_JUMP_SLOT:
694 + case R_RISCV_RELATIVE:
695 + case R_RISCV_64:
696 + case R_RISCV_32:
697 + /* Fall through. */
699 + static_reloc:
700 + /* This reloc might not bind locally. */
701 + if (h != NULL)
702 + h->non_got_ref = 1;
704 + if (h != NULL && !bfd_link_pic (info))
706 + /* We may need a .plt entry if the function this reloc
707 + refers to is in a shared lib. */
708 + h->plt.refcount += 1;
711 + /* If we are creating a shared library, and this is a reloc
712 + against a global symbol, or a non PC relative reloc
713 + against a local symbol, then we need to copy the reloc
714 + into the shared library. However, if we are linking with
715 + -Bsymbolic, we do not need to copy a reloc against a
716 + global symbol which is defined in an object we are
717 + including in the link (i.e., DEF_REGULAR is set). At
718 + this point we have not seen all the input files, so it is
719 + possible that DEF_REGULAR is not set now but will be set
720 + later (it is never cleared). In case of a weak definition,
721 + DEF_REGULAR may be cleared later by a strong definition in
722 + a shared library. We account for that possibility below by
723 + storing information in the relocs_copied field of the hash
724 + table entry. A similar situation occurs when creating
725 + shared libraries and symbol visibility changes render the
726 + symbol local.
728 + If on the other hand, we are creating an executable, we
729 + may need to keep relocations for symbols satisfied by a
730 + dynamic library if we manage to avoid copy relocs for the
731 + symbol. */
732 + if ((bfd_link_pic (info)
733 + && (sec->flags & SEC_ALLOC) != 0
734 + && (! riscv_elf_rtype_to_howto (r_type)->pc_relative
735 + || (h != NULL
736 + && (! info->symbolic
737 + || h->root.type == bfd_link_hash_defweak
738 + || !h->def_regular))))
739 + || (!bfd_link_pic (info)
740 + && (sec->flags & SEC_ALLOC) != 0
741 + && h != NULL
742 + && (h->root.type == bfd_link_hash_defweak
743 + || !h->def_regular)))
745 + struct riscv_elf_dyn_relocs *p;
746 + struct riscv_elf_dyn_relocs **head;
748 + /* When creating a shared object, we must copy these
749 + relocs into the output file. We create a reloc
750 + section in dynobj and make room for the reloc. */
751 + if (sreloc == NULL)
753 + sreloc = _bfd_elf_make_dynamic_reloc_section
754 + (sec, htab->elf.dynobj, RISCV_ELF_LOG_WORD_BYTES,
755 + abfd, /*rela?*/ TRUE);
757 + if (sreloc == NULL)
758 + return FALSE;
761 + /* If this is a global symbol, we count the number of
762 + relocations we need for this symbol. */
763 + if (h != NULL)
764 + head = &((struct riscv_elf_link_hash_entry *) h)->dyn_relocs;
765 + else
767 + /* Track dynamic relocs needed for local syms too.
768 + We really need local syms available to do this
769 + easily. Oh well. */
771 + asection *s;
772 + void *vpp;
773 + Elf_Internal_Sym *isym;
775 + isym = bfd_sym_from_r_symndx (&htab->sym_cache,
776 + abfd, r_symndx);
777 + if (isym == NULL)
778 + return FALSE;
780 + s = bfd_section_from_elf_index (abfd, isym->st_shndx);
781 + if (s == NULL)
782 + s = sec;
784 + vpp = &elf_section_data (s)->local_dynrel;
785 + head = (struct riscv_elf_dyn_relocs **) vpp;
788 + p = *head;
789 + if (p == NULL || p->sec != sec)
791 + bfd_size_type amt = sizeof *p;
792 + p = ((struct riscv_elf_dyn_relocs *)
793 + bfd_alloc (htab->elf.dynobj, amt));
794 + if (p == NULL)
795 + return FALSE;
796 + p->next = *head;
797 + *head = p;
798 + p->sec = sec;
799 + p->count = 0;
800 + p->pc_count = 0;
803 + p->count += 1;
804 + p->pc_count += riscv_elf_rtype_to_howto (r_type)->pc_relative;
807 + break;
809 + case R_RISCV_GNU_VTINHERIT:
810 + if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
811 + return FALSE;
812 + break;
814 + case R_RISCV_GNU_VTENTRY:
815 + if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
816 + return FALSE;
817 + break;
819 + default:
820 + break;
824 + return TRUE;
827 +static asection *
828 +riscv_elf_gc_mark_hook (asection *sec,
829 + struct bfd_link_info *info,
830 + Elf_Internal_Rela *rel,
831 + struct elf_link_hash_entry *h,
832 + Elf_Internal_Sym *sym)
834 + if (h != NULL)
835 + switch (ELFNN_R_TYPE (rel->r_info))
837 + case R_RISCV_GNU_VTINHERIT:
838 + case R_RISCV_GNU_VTENTRY:
839 + return NULL;
842 + return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
845 +/* Update the got entry reference counts for the section being removed. */
846 +static bfd_boolean
847 +riscv_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
848 + asection *sec, const Elf_Internal_Rela *relocs)
850 + const Elf_Internal_Rela *rel, *relend;
851 + Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (abfd);
852 + struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (abfd);
853 + bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
855 + if (bfd_link_relocatable (info))
856 + return TRUE;
858 + elf_section_data (sec)->local_dynrel = NULL;
860 + for (rel = relocs, relend = relocs + sec->reloc_count; rel < relend; rel++)
862 + unsigned long r_symndx;
863 + struct elf_link_hash_entry *h = NULL;
865 + r_symndx = ELFNN_R_SYM (rel->r_info);
866 + if (r_symndx >= symtab_hdr->sh_info)
868 + struct riscv_elf_link_hash_entry *eh;
869 + struct riscv_elf_dyn_relocs **pp;
870 + struct riscv_elf_dyn_relocs *p;
872 + h = sym_hashes[r_symndx - symtab_hdr->sh_info];
873 + while (h->root.type == bfd_link_hash_indirect
874 + || h->root.type == bfd_link_hash_warning)
875 + h = (struct elf_link_hash_entry *) h->root.u.i.link;
876 + eh = (struct riscv_elf_link_hash_entry *) h;
877 + for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
878 + if (p->sec == sec)
880 + /* Everything must go for SEC. */
881 + *pp = p->next;
882 + break;
886 + switch (ELFNN_R_TYPE (rel->r_info))
888 + case R_RISCV_GOT_HI20:
889 + case R_RISCV_TLS_GOT_HI20:
890 + case R_RISCV_TLS_GD_HI20:
891 + if (h != NULL)
893 + if (h->got.refcount > 0)
894 + h->got.refcount--;
896 + else
898 + if (local_got_refcounts &&
899 + local_got_refcounts[r_symndx] > 0)
900 + local_got_refcounts[r_symndx]--;
902 + break;
904 + case R_RISCV_HI20:
905 + case R_RISCV_PCREL_HI20:
906 + case R_RISCV_COPY:
907 + case R_RISCV_JUMP_SLOT:
908 + case R_RISCV_RELATIVE:
909 + case R_RISCV_64:
910 + case R_RISCV_32:
911 + case R_RISCV_BRANCH:
912 + case R_RISCV_CALL:
913 + case R_RISCV_JAL:
914 + case R_RISCV_RVC_BRANCH:
915 + case R_RISCV_RVC_JUMP:
916 + if (bfd_link_pic (info))
917 + break;
918 + /* Fall through. */
920 + case R_RISCV_CALL_PLT:
921 + if (h != NULL)
923 + if (h->plt.refcount > 0)
924 + h->plt.refcount--;
926 + break;
928 + default:
929 + break;
933 + return TRUE;
936 +/* Adjust a symbol defined by a dynamic object and referenced by a
937 + regular object. The current definition is in some section of the
938 + dynamic object, but we're not including those sections. We have to
939 + change the definition to something the rest of the link can
940 + understand. */
942 +static bfd_boolean
943 +riscv_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
944 + struct elf_link_hash_entry *h)
946 + struct riscv_elf_link_hash_table *htab;
947 + struct riscv_elf_link_hash_entry * eh;
948 + struct riscv_elf_dyn_relocs *p;
949 + bfd *dynobj;
950 + asection *s;
952 + htab = riscv_elf_hash_table (info);
953 + BFD_ASSERT (htab != NULL);
955 + dynobj = htab->elf.dynobj;
957 + /* Make sure we know what is going on here. */
958 + BFD_ASSERT (dynobj != NULL
959 + && (h->needs_plt
960 + || h->type == STT_GNU_IFUNC
961 + || h->u.weakdef != NULL
962 + || (h->def_dynamic
963 + && h->ref_regular
964 + && !h->def_regular)));
966 + /* If this is a function, put it in the procedure linkage table. We
967 + will fill in the contents of the procedure linkage table later
968 + (although we could actually do it here). */
969 + if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
971 + if (h->plt.refcount <= 0
972 + || SYMBOL_CALLS_LOCAL (info, h)
973 + || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
974 + && h->root.type == bfd_link_hash_undefweak))
976 + /* This case can occur if we saw a R_RISCV_CALL_PLT reloc in an
977 + input file, but the symbol was never referred to by a dynamic
978 + object, or if all references were garbage collected. In such
979 + a case, we don't actually need to build a PLT entry. */
980 + h->plt.offset = (bfd_vma) -1;
981 + h->needs_plt = 0;
984 + return TRUE;
986 + else
987 + h->plt.offset = (bfd_vma) -1;
989 + /* If this is a weak symbol, and there is a real definition, the
990 + processor independent code will have arranged for us to see the
991 + real definition first, and we can just use the same value. */
992 + if (h->u.weakdef != NULL)
994 + BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
995 + || h->u.weakdef->root.type == bfd_link_hash_defweak);
996 + h->root.u.def.section = h->u.weakdef->root.u.def.section;
997 + h->root.u.def.value = h->u.weakdef->root.u.def.value;
998 + return TRUE;
1001 + /* This is a reference to a symbol defined by a dynamic object which
1002 + is not a function. */
1004 + /* If we are creating a shared library, we must presume that the
1005 + only references to the symbol are via the global offset table.
1006 + For such cases we need not do anything here; the relocations will
1007 + be handled correctly by relocate_section. */
1008 + if (bfd_link_pic (info))
1009 + return TRUE;
1011 + /* If there are no references to this symbol that do not use the
1012 + GOT, we don't need to generate a copy reloc. */
1013 + if (!h->non_got_ref)
1014 + return TRUE;
1016 + /* If -z nocopyreloc was given, we won't generate them either. */
1017 + if (info->nocopyreloc)
1019 + h->non_got_ref = 0;
1020 + return TRUE;
1023 + eh = (struct riscv_elf_link_hash_entry *) h;
1024 + for (p = eh->dyn_relocs; p != NULL; p = p->next)
1026 + s = p->sec->output_section;
1027 + if (s != NULL && (s->flags & SEC_READONLY) != 0)
1028 + break;
1031 + /* If we didn't find any dynamic relocs in read-only sections, then
1032 + we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1033 + if (p == NULL)
1035 + h->non_got_ref = 0;
1036 + return TRUE;
1039 + /* We must allocate the symbol in our .dynbss section, which will
1040 + become part of the .bss section of the executable. There will be
1041 + an entry for this symbol in the .dynsym section. The dynamic
1042 + object will contain position independent code, so all references
1043 + from the dynamic object to this symbol will go through the global
1044 + offset table. The dynamic linker will use the .dynsym entry to
1045 + determine the address it must put in the global offset table, so
1046 + both the dynamic object and the regular object will refer to the
1047 + same memory location for the variable. */
1049 + /* We must generate a R_RISCV_COPY reloc to tell the dynamic linker
1050 + to copy the initial value out of the dynamic object and into the
1051 + runtime process image. We need to remember the offset into the
1052 + .rel.bss section we are going to use. */
1053 + if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
1055 + htab->srelbss->size += sizeof (ElfNN_External_Rela);
1056 + h->needs_copy = 1;
1059 + if (eh->tls_type & ~GOT_NORMAL)
1060 + return _bfd_elf_adjust_dynamic_copy (info, h, htab->sdyntdata);
1062 + return _bfd_elf_adjust_dynamic_copy (info, h, htab->sdynbss);
1065 +/* Allocate space in .plt, .got and associated reloc sections for
1066 + dynamic relocs. */
1068 +static bfd_boolean
1069 +allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
1071 + struct bfd_link_info *info;
1072 + struct riscv_elf_link_hash_table *htab;
1073 + struct riscv_elf_link_hash_entry *eh;
1074 + struct riscv_elf_dyn_relocs *p;
1076 + if (h->root.type == bfd_link_hash_indirect)
1077 + return TRUE;
1079 + info = (struct bfd_link_info *) inf;
1080 + htab = riscv_elf_hash_table (info);
1081 + BFD_ASSERT (htab != NULL);
1083 + if (htab->elf.dynamic_sections_created
1084 + && h->plt.refcount > 0)
1086 + /* Make sure this symbol is output as a dynamic symbol.
1087 + Undefined weak syms won't yet be marked as dynamic. */
1088 + if (h->dynindx == -1
1089 + && !h->forced_local)
1091 + if (! bfd_elf_link_record_dynamic_symbol (info, h))
1092 + return FALSE;
1095 + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
1097 + asection *s = htab->elf.splt;
1099 + if (s->size == 0)
1100 + s->size = PLT_HEADER_SIZE;
1102 + h->plt.offset = s->size;
1104 + /* Make room for this entry. */
1105 + s->size += PLT_ENTRY_SIZE;
1107 + /* We also need to make an entry in the .got.plt section. */
1108 + htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
1110 + /* We also need to make an entry in the .rela.plt section. */
1111 + htab->elf.srelplt->size += sizeof (ElfNN_External_Rela);
1113 + /* If this symbol is not defined in a regular file, and we are
1114 + not generating a shared library, then set the symbol to this
1115 + location in the .plt. This is required to make function
1116 + pointers compare as equal between the normal executable and
1117 + the shared library. */
1118 + if (! bfd_link_pic (info)
1119 + && !h->def_regular)
1121 + h->root.u.def.section = s;
1122 + h->root.u.def.value = h->plt.offset;
1125 + else
1127 + h->plt.offset = (bfd_vma) -1;
1128 + h->needs_plt = 0;
1131 + else
1133 + h->plt.offset = (bfd_vma) -1;
1134 + h->needs_plt = 0;
1137 + if (h->got.refcount > 0)
1139 + asection *s;
1140 + bfd_boolean dyn;
1141 + int tls_type = riscv_elf_hash_entry (h)->tls_type;
1143 + /* Make sure this symbol is output as a dynamic symbol.
1144 + Undefined weak syms won't yet be marked as dynamic. */
1145 + if (h->dynindx == -1
1146 + && !h->forced_local)
1148 + if (! bfd_elf_link_record_dynamic_symbol (info, h))
1149 + return FALSE;
1152 + s = htab->elf.sgot;
1153 + h->got.offset = s->size;
1154 + dyn = htab->elf.dynamic_sections_created;
1155 + if (tls_type & (GOT_TLS_GD | GOT_TLS_IE))
1157 + /* TLS_GD needs two dynamic relocs and two GOT slots. */
1158 + if (tls_type & GOT_TLS_GD)
1160 + s->size += 2 * RISCV_ELF_WORD_BYTES;
1161 + htab->elf.srelgot->size += 2 * sizeof (ElfNN_External_Rela);
1164 + /* TLS_IE needs one dynamic reloc and one GOT slot. */
1165 + if (tls_type & GOT_TLS_IE)
1167 + s->size += RISCV_ELF_WORD_BYTES;
1168 + htab->elf.srelgot->size += sizeof (ElfNN_External_Rela);
1171 + else
1173 + s->size += RISCV_ELF_WORD_BYTES;
1174 + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
1175 + htab->elf.srelgot->size += sizeof (ElfNN_External_Rela);
1178 + else
1179 + h->got.offset = (bfd_vma) -1;
1181 + eh = (struct riscv_elf_link_hash_entry *) h;
1182 + if (eh->dyn_relocs == NULL)
1183 + return TRUE;
1185 + /* In the shared -Bsymbolic case, discard space allocated for
1186 + dynamic pc-relative relocs against symbols which turn out to be
1187 + defined in regular objects. For the normal shared case, discard
1188 + space for pc-relative relocs that have become local due to symbol
1189 + visibility changes. */
1191 + if (bfd_link_pic (info))
1193 + if (SYMBOL_CALLS_LOCAL (info, h))
1195 + struct riscv_elf_dyn_relocs **pp;
1197 + for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1199 + p->count -= p->pc_count;
1200 + p->pc_count = 0;
1201 + if (p->count == 0)
1202 + *pp = p->next;
1203 + else
1204 + pp = &p->next;
1208 + /* Also discard relocs on undefined weak syms with non-default
1209 + visibility. */
1210 + if (eh->dyn_relocs != NULL
1211 + && h->root.type == bfd_link_hash_undefweak)
1213 + if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1214 + eh->dyn_relocs = NULL;
1216 + /* Make sure undefined weak symbols are output as a dynamic
1217 + symbol in PIEs. */
1218 + else if (h->dynindx == -1
1219 + && !h->forced_local)
1221 + if (! bfd_elf_link_record_dynamic_symbol (info, h))
1222 + return FALSE;
1226 + else
1228 + /* For the non-shared case, discard space for relocs against
1229 + symbols which turn out to need copy relocs or are not
1230 + dynamic. */
1232 + if (!h->non_got_ref
1233 + && ((h->def_dynamic
1234 + && !h->def_regular)
1235 + || (htab->elf.dynamic_sections_created
1236 + && (h->root.type == bfd_link_hash_undefweak
1237 + || h->root.type == bfd_link_hash_undefined))))
1239 + /* Make sure this symbol is output as a dynamic symbol.
1240 + Undefined weak syms won't yet be marked as dynamic. */
1241 + if (h->dynindx == -1
1242 + && !h->forced_local)
1244 + if (! bfd_elf_link_record_dynamic_symbol (info, h))
1245 + return FALSE;
1248 + /* If that succeeded, we know we'll be keeping all the
1249 + relocs. */
1250 + if (h->dynindx != -1)
1251 + goto keep;
1254 + eh->dyn_relocs = NULL;
1256 + keep: ;
1259 + /* Finally, allocate space. */
1260 + for (p = eh->dyn_relocs; p != NULL; p = p->next)
1262 + asection *sreloc = elf_section_data (p->sec)->sreloc;
1263 + sreloc->size += p->count * sizeof (ElfNN_External_Rela);
1266 + return TRUE;
1269 +/* Find any dynamic relocs that apply to read-only sections. */
1271 +static bfd_boolean
1272 +readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
1274 + struct riscv_elf_link_hash_entry *eh;
1275 + struct riscv_elf_dyn_relocs *p;
1277 + eh = (struct riscv_elf_link_hash_entry *) h;
1278 + for (p = eh->dyn_relocs; p != NULL; p = p->next)
1280 + asection *s = p->sec->output_section;
1282 + if (s != NULL && (s->flags & SEC_READONLY) != 0)
1284 + ((struct bfd_link_info *) inf)->flags |= DF_TEXTREL;
1285 + return FALSE;
1288 + return TRUE;
1291 +static bfd_boolean
1292 +riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
1294 + struct riscv_elf_link_hash_table *htab;
1295 + bfd *dynobj;
1296 + asection *s;
1297 + bfd *ibfd;
1299 + htab = riscv_elf_hash_table (info);
1300 + BFD_ASSERT (htab != NULL);
1301 + dynobj = htab->elf.dynobj;
1302 + BFD_ASSERT (dynobj != NULL);
1304 + if (elf_hash_table (info)->dynamic_sections_created)
1306 + /* Set the contents of the .interp section to the interpreter. */
1307 + if (bfd_link_executable (info) && !info->nointerp)
1309 + s = bfd_get_linker_section (dynobj, ".interp");
1310 + BFD_ASSERT (s != NULL);
1311 + s->size = strlen (ELFNN_DYNAMIC_INTERPRETER) + 1;
1312 + s->contents = (unsigned char *) ELFNN_DYNAMIC_INTERPRETER;
1316 + /* Set up .got offsets for local syms, and space for local dynamic
1317 + relocs. */
1318 + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
1320 + bfd_signed_vma *local_got;
1321 + bfd_signed_vma *end_local_got;
1322 + char *local_tls_type;
1323 + bfd_size_type locsymcount;
1324 + Elf_Internal_Shdr *symtab_hdr;
1325 + asection *srel;
1327 + if (! is_riscv_elf (ibfd))
1328 + continue;
1330 + for (s = ibfd->sections; s != NULL; s = s->next)
1332 + struct riscv_elf_dyn_relocs *p;
1334 + for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
1336 + if (!bfd_is_abs_section (p->sec)
1337 + && bfd_is_abs_section (p->sec->output_section))
1339 + /* Input section has been discarded, either because
1340 + it is a copy of a linkonce section or due to
1341 + linker script /DISCARD/, so we'll be discarding
1342 + the relocs too. */
1344 + else if (p->count != 0)
1346 + srel = elf_section_data (p->sec)->sreloc;
1347 + srel->size += p->count * sizeof (ElfNN_External_Rela);
1348 + if ((p->sec->output_section->flags & SEC_READONLY) != 0)
1349 + info->flags |= DF_TEXTREL;
1354 + local_got = elf_local_got_refcounts (ibfd);
1355 + if (!local_got)
1356 + continue;
1358 + symtab_hdr = &elf_symtab_hdr (ibfd);
1359 + locsymcount = symtab_hdr->sh_info;
1360 + end_local_got = local_got + locsymcount;
1361 + local_tls_type = _bfd_riscv_elf_local_got_tls_type (ibfd);
1362 + s = htab->elf.sgot;
1363 + srel = htab->elf.srelgot;
1364 + for (; local_got < end_local_got; ++local_got, ++local_tls_type)
1366 + if (*local_got > 0)
1368 + *local_got = s->size;
1369 + s->size += RISCV_ELF_WORD_BYTES;
1370 + if (*local_tls_type & GOT_TLS_GD)
1371 + s->size += RISCV_ELF_WORD_BYTES;
1372 + if (bfd_link_pic (info)
1373 + || (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)))
1374 + srel->size += sizeof (ElfNN_External_Rela);
1376 + else
1377 + *local_got = (bfd_vma) -1;
1381 + /* Allocate global sym .plt and .got entries, and space for global
1382 + sym dynamic relocs. */
1383 + elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
1385 + if (htab->elf.sgotplt)
1387 + struct elf_link_hash_entry *got;
1388 + got = elf_link_hash_lookup (elf_hash_table (info),
1389 + "_GLOBAL_OFFSET_TABLE_",
1390 + FALSE, FALSE, FALSE);
1392 + /* Don't allocate .got.plt section if there are no GOT nor PLT
1393 + entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
1394 + if ((got == NULL
1395 + || !got->ref_regular_nonweak)
1396 + && (htab->elf.sgotplt->size == GOTPLT_HEADER_SIZE)
1397 + && (htab->elf.splt == NULL
1398 + || htab->elf.splt->size == 0)
1399 + && (htab->elf.sgot == NULL
1400 + || (htab->elf.sgot->size
1401 + == get_elf_backend_data (output_bfd)->got_header_size)))
1402 + htab->elf.sgotplt->size = 0;
1405 + /* The check_relocs and adjust_dynamic_symbol entry points have
1406 + determined the sizes of the various dynamic sections. Allocate
1407 + memory for them. */
1408 + for (s = dynobj->sections; s != NULL; s = s->next)
1410 + if ((s->flags & SEC_LINKER_CREATED) == 0)
1411 + continue;
1413 + if (s == htab->elf.splt
1414 + || s == htab->elf.sgot
1415 + || s == htab->elf.sgotplt
1416 + || s == htab->sdynbss)
1418 + /* Strip this section if we don't need it; see the
1419 + comment below. */
1421 + else if (strncmp (s->name, ".rela", 5) == 0)
1423 + if (s->size != 0)
1425 + /* We use the reloc_count field as a counter if we need
1426 + to copy relocs into the output file. */
1427 + s->reloc_count = 0;
1430 + else
1432 + /* It's not one of our sections. */
1433 + continue;
1436 + if (s->size == 0)
1438 + /* If we don't need this section, strip it from the
1439 + output file. This is mostly to handle .rela.bss and
1440 + .rela.plt. We must create both sections in
1441 + create_dynamic_sections, because they must be created
1442 + before the linker maps input sections to output
1443 + sections. The linker does that before
1444 + adjust_dynamic_symbol is called, and it is that
1445 + function which decides whether anything needs to go
1446 + into these sections. */
1447 + s->flags |= SEC_EXCLUDE;
1448 + continue;
1451 + if ((s->flags & SEC_HAS_CONTENTS) == 0)
1452 + continue;
1454 + /* Allocate memory for the section contents. Zero the memory
1455 + for the benefit of .rela.plt, which has 4 unused entries
1456 + at the beginning, and we don't want garbage. */
1457 + s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1458 + if (s->contents == NULL)
1459 + return FALSE;
1462 + if (elf_hash_table (info)->dynamic_sections_created)
1464 + /* Add some entries to the .dynamic section. We fill in the
1465 + values later, in riscv_elf_finish_dynamic_sections, but we
1466 + must add the entries now so that we get the correct size for
1467 + the .dynamic section. The DT_DEBUG entry is filled in by the
1468 + dynamic linker and used by the debugger. */
1469 +#define add_dynamic_entry(TAG, VAL) \
1470 + _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1472 + if (bfd_link_executable (info))
1474 + if (!add_dynamic_entry (DT_DEBUG, 0))
1475 + return FALSE;
1478 + if (htab->elf.srelplt->size != 0)
1480 + if (!add_dynamic_entry (DT_PLTGOT, 0)
1481 + || !add_dynamic_entry (DT_PLTRELSZ, 0)
1482 + || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1483 + || !add_dynamic_entry (DT_JMPREL, 0))
1484 + return FALSE;
1487 + if (!add_dynamic_entry (DT_RELA, 0)
1488 + || !add_dynamic_entry (DT_RELASZ, 0)
1489 + || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela)))
1490 + return FALSE;
1492 + /* If any dynamic relocs apply to a read-only section,
1493 + then we need a DT_TEXTREL entry. */
1494 + if ((info->flags & DF_TEXTREL) == 0)
1495 + elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
1497 + if (info->flags & DF_TEXTREL)
1499 + if (!add_dynamic_entry (DT_TEXTREL, 0))
1500 + return FALSE;
1503 +#undef add_dynamic_entry
1505 + return TRUE;
1508 +#define TP_OFFSET 0
1509 +#define DTP_OFFSET 0x800
1511 +/* Return the relocation value for a TLS dtp-relative reloc. */
1513 +static bfd_vma
1514 +dtpoff (struct bfd_link_info *info, bfd_vma address)
1516 + /* If tls_sec is NULL, we should have signalled an error already. */
1517 + if (elf_hash_table (info)->tls_sec == NULL)
1518 + return 0;
1519 + return address - elf_hash_table (info)->tls_sec->vma - DTP_OFFSET;
1522 +/* Return the relocation value for a static TLS tp-relative relocation. */
1524 +static bfd_vma
1525 +tpoff (struct bfd_link_info *info, bfd_vma address)
1527 + /* If tls_sec is NULL, we should have signalled an error already. */
1528 + if (elf_hash_table (info)->tls_sec == NULL)
1529 + return 0;
1530 + return address - elf_hash_table (info)->tls_sec->vma - TP_OFFSET;
1533 +/* Return the global pointer's value, or 0 if it is not in use. */
1535 +static bfd_vma
1536 +riscv_global_pointer_value (struct bfd_link_info *info)
1538 + struct bfd_link_hash_entry *h;
1540 + h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
1541 + if (h == NULL || h->type != bfd_link_hash_defined)
1542 + return 0;
1544 + return h->u.def.value + sec_addr (h->u.def.section);
1547 +/* Emplace a static relocation. */
1549 +static bfd_reloc_status_type
1550 +perform_relocation (const reloc_howto_type *howto,
1551 + const Elf_Internal_Rela *rel,
1552 + bfd_vma value,
1553 + asection *input_section,
1554 + bfd *input_bfd,
1555 + bfd_byte *contents)
1557 + if (howto->pc_relative)
1558 + value -= sec_addr (input_section) + rel->r_offset;
1559 + value += rel->r_addend;
1561 + switch (ELFNN_R_TYPE (rel->r_info))
1563 + case R_RISCV_HI20:
1564 + case R_RISCV_TPREL_HI20:
1565 + case R_RISCV_PCREL_HI20:
1566 + case R_RISCV_GOT_HI20:
1567 + case R_RISCV_TLS_GOT_HI20:
1568 + case R_RISCV_TLS_GD_HI20:
1569 + if (ARCH_SIZE > 32 && !VALID_UTYPE_IMM (RISCV_CONST_HIGH_PART (value)))
1570 + return bfd_reloc_overflow;
1571 + value = ENCODE_UTYPE_IMM (RISCV_CONST_HIGH_PART (value));
1572 + break;
1574 + case R_RISCV_LO12_I:
1575 + case R_RISCV_GPREL_I:
1576 + case R_RISCV_TPREL_LO12_I:
1577 + case R_RISCV_PCREL_LO12_I:
1578 + value = ENCODE_ITYPE_IMM (value);
1579 + break;
1581 + case R_RISCV_LO12_S:
1582 + case R_RISCV_GPREL_S:
1583 + case R_RISCV_TPREL_LO12_S:
1584 + case R_RISCV_PCREL_LO12_S:
1585 + value = ENCODE_STYPE_IMM (value);
1586 + break;
1588 + case R_RISCV_CALL:
1589 + case R_RISCV_CALL_PLT:
1590 + if (ARCH_SIZE > 32 && !VALID_UTYPE_IMM (RISCV_CONST_HIGH_PART (value)))
1591 + return bfd_reloc_overflow;
1592 + value = ENCODE_UTYPE_IMM (RISCV_CONST_HIGH_PART (value))
1593 + | (ENCODE_ITYPE_IMM (value) << 32);
1594 + break;
1596 + case R_RISCV_JAL:
1597 + if (!VALID_UJTYPE_IMM (value))
1598 + return bfd_reloc_overflow;
1599 + value = ENCODE_UJTYPE_IMM (value);
1600 + break;
1602 + case R_RISCV_BRANCH:
1603 + if (!VALID_SBTYPE_IMM (value))
1604 + return bfd_reloc_overflow;
1605 + value = ENCODE_SBTYPE_IMM (value);
1606 + break;
1608 + case R_RISCV_RVC_BRANCH:
1609 + if (!VALID_RVC_B_IMM (value))
1610 + return bfd_reloc_overflow;
1611 + value = ENCODE_RVC_B_IMM (value);
1612 + break;
1614 + case R_RISCV_RVC_JUMP:
1615 + if (!VALID_RVC_J_IMM (value))
1616 + return bfd_reloc_overflow;
1617 + value = ENCODE_RVC_J_IMM (value);
1618 + break;
1620 + case R_RISCV_RVC_LUI:
1621 + if (!VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (value)))
1622 + return bfd_reloc_overflow;
1623 + value = ENCODE_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (value));
1624 + break;
1626 + case R_RISCV_32:
1627 + case R_RISCV_64:
1628 + case R_RISCV_ADD8:
1629 + case R_RISCV_ADD16:
1630 + case R_RISCV_ADD32:
1631 + case R_RISCV_ADD64:
1632 + case R_RISCV_SUB8:
1633 + case R_RISCV_SUB16:
1634 + case R_RISCV_SUB32:
1635 + case R_RISCV_SUB64:
1636 + case R_RISCV_TLS_DTPREL32:
1637 + case R_RISCV_TLS_DTPREL64:
1638 + break;
1640 + default:
1641 + return bfd_reloc_notsupported;
1644 + bfd_vma word = bfd_get (howto->bitsize, input_bfd, contents + rel->r_offset);
1645 + word = (word & ~howto->dst_mask) | (value & howto->dst_mask);
1646 + bfd_put (howto->bitsize, input_bfd, word, contents + rel->r_offset);
1648 + return bfd_reloc_ok;
1651 +/* Remember all PC-relative high-part relocs we've encountered to help us
1652 + later resolve the corresponding low-part relocs. */
1654 +typedef struct {
1655 + bfd_vma address;
1656 + bfd_vma value;
1657 +} riscv_pcrel_hi_reloc;
1659 +typedef struct riscv_pcrel_lo_reloc {
1660 + asection *input_section;
1661 + struct bfd_link_info *info;
1662 + reloc_howto_type *howto;
1663 + const Elf_Internal_Rela *reloc;
1664 + bfd_vma addr;
1665 + const char *name;
1666 + bfd_byte *contents;
1667 + struct riscv_pcrel_lo_reloc *next;
1668 +} riscv_pcrel_lo_reloc;
1670 +typedef struct {
1671 + htab_t hi_relocs;
1672 + riscv_pcrel_lo_reloc *lo_relocs;
1673 +} riscv_pcrel_relocs;
1675 +static hashval_t
1676 +riscv_pcrel_reloc_hash (const void *entry)
1678 + const riscv_pcrel_hi_reloc *e = entry;
1679 + return (hashval_t)(e->address >> 2);
1682 +static bfd_boolean
1683 +riscv_pcrel_reloc_eq (const void *entry1, const void *entry2)
1685 + const riscv_pcrel_hi_reloc *e1 = entry1, *e2 = entry2;
1686 + return e1->address == e2->address;
1689 +static bfd_boolean
1690 +riscv_init_pcrel_relocs (riscv_pcrel_relocs *p)
1693 + p->lo_relocs = NULL;
1694 + p->hi_relocs = htab_create (1024, riscv_pcrel_reloc_hash,
1695 + riscv_pcrel_reloc_eq, free);
1696 + return p->hi_relocs != NULL;
1699 +static void
1700 +riscv_free_pcrel_relocs (riscv_pcrel_relocs *p)
1702 + riscv_pcrel_lo_reloc *cur = p->lo_relocs;
1703 + while (cur != NULL)
1705 + riscv_pcrel_lo_reloc *next = cur->next;
1706 + free (cur);
1707 + cur = next;
1710 + htab_delete (p->hi_relocs);
1713 +static bfd_boolean
1714 +riscv_record_pcrel_hi_reloc (riscv_pcrel_relocs *p, bfd_vma addr, bfd_vma value)
1716 + riscv_pcrel_hi_reloc entry = {addr, value - addr};
1717 + riscv_pcrel_hi_reloc **slot =
1718 + (riscv_pcrel_hi_reloc **) htab_find_slot (p->hi_relocs, &entry, INSERT);
1719 + BFD_ASSERT (*slot == NULL);
1720 + *slot = (riscv_pcrel_hi_reloc *) bfd_malloc (sizeof (riscv_pcrel_hi_reloc));
1721 + if (*slot == NULL)
1722 + return FALSE;
1723 + **slot = entry;
1724 + return TRUE;
1727 +static bfd_boolean
1728 +riscv_record_pcrel_lo_reloc (riscv_pcrel_relocs *p,
1729 + asection *input_section,
1730 + struct bfd_link_info *info,
1731 + reloc_howto_type *howto,
1732 + const Elf_Internal_Rela *reloc,
1733 + bfd_vma addr,
1734 + const char *name,
1735 + bfd_byte *contents)
1737 + riscv_pcrel_lo_reloc *entry;
1738 + entry = (riscv_pcrel_lo_reloc *) bfd_malloc (sizeof (riscv_pcrel_lo_reloc));
1739 + if (entry == NULL)
1740 + return FALSE;
1741 + *entry = (riscv_pcrel_lo_reloc) {input_section, info, howto, reloc, addr,
1742 + name, contents, p->lo_relocs};
1743 + p->lo_relocs = entry;
1744 + return TRUE;
1747 +static bfd_boolean
1748 +riscv_resolve_pcrel_lo_relocs (riscv_pcrel_relocs *p)
1750 + riscv_pcrel_lo_reloc *r;
1751 + for (r = p->lo_relocs; r != NULL; r = r->next)
1753 + bfd *input_bfd = r->input_section->owner;
1754 + riscv_pcrel_hi_reloc search = {r->addr, 0};
1755 + riscv_pcrel_hi_reloc *entry = htab_find (p->hi_relocs, &search);
1756 + if (entry == NULL)
1757 + return ((*r->info->callbacks->reloc_overflow)
1758 + (r->info, NULL, r->name, r->howto->name, (bfd_vma) 0,
1759 + input_bfd, r->input_section, r->reloc->r_offset));
1761 + perform_relocation (r->howto, r->reloc, entry->value, r->input_section,
1762 + input_bfd, r->contents);
1765 + return TRUE;
1768 +/* Relocate a RISC-V ELF section.
1770 + The RELOCATE_SECTION function is called by the new ELF backend linker
1771 + to handle the relocations for a section.
1773 + The relocs are always passed as Rela structures.
1775 + This function is responsible for adjusting the section contents as
1776 + necessary, and (if generating a relocatable output file) adjusting
1777 + the reloc addend as necessary.
1779 + This function does not have to worry about setting the reloc
1780 + address or the reloc symbol index.
1782 + LOCAL_SYMS is a pointer to the swapped in local symbols.
1784 + LOCAL_SECTIONS is an array giving the section in the input file
1785 + corresponding to the st_shndx field of each local symbol.
1787 + The global hash table entry for the global symbols can be found
1788 + via elf_sym_hashes (input_bfd).
1790 + When generating relocatable output, this function must handle
1791 + STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1792 + going to be the section symbol corresponding to the output
1793 + section, which means that the addend must be adjusted
1794 + accordingly. */
1796 +static bfd_boolean
1797 +riscv_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
1798 + bfd *input_bfd, asection *input_section,
1799 + bfd_byte *contents, Elf_Internal_Rela *relocs,
1800 + Elf_Internal_Sym *local_syms,
1801 + asection **local_sections)
1803 + Elf_Internal_Rela *rel;
1804 + Elf_Internal_Rela *relend;
1805 + riscv_pcrel_relocs pcrel_relocs;
1806 + bfd_boolean ret = FALSE;
1807 + asection *sreloc = elf_section_data (input_section)->sreloc;
1808 + struct riscv_elf_link_hash_table *htab = riscv_elf_hash_table (info);
1809 + Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_bfd);
1810 + struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
1811 + bfd_vma *local_got_offsets = elf_local_got_offsets (input_bfd);
1813 + if (!riscv_init_pcrel_relocs (&pcrel_relocs))
1814 + return FALSE;
1816 + relend = relocs + input_section->reloc_count;
1817 + for (rel = relocs; rel < relend; rel++)
1819 + unsigned long r_symndx;
1820 + struct elf_link_hash_entry *h;
1821 + Elf_Internal_Sym *sym;
1822 + asection *sec;
1823 + bfd_vma relocation;
1824 + bfd_reloc_status_type r = bfd_reloc_ok;
1825 + const char *name;
1826 + bfd_vma off, ie_off;
1827 + bfd_boolean unresolved_reloc, is_ie = FALSE;
1828 + bfd_vma pc = sec_addr (input_section) + rel->r_offset;
1829 + int r_type = ELFNN_R_TYPE (rel->r_info), tls_type;
1830 + reloc_howto_type *howto = riscv_elf_rtype_to_howto (r_type);
1831 + const char *msg = NULL;
1833 + if (r_type == R_RISCV_GNU_VTINHERIT || r_type == R_RISCV_GNU_VTENTRY)
1834 + continue;
1836 + /* This is a final link. */
1837 + r_symndx = ELFNN_R_SYM (rel->r_info);
1838 + h = NULL;
1839 + sym = NULL;
1840 + sec = NULL;
1841 + unresolved_reloc = FALSE;
1842 + if (r_symndx < symtab_hdr->sh_info)
1844 + sym = local_syms + r_symndx;
1845 + sec = local_sections[r_symndx];
1846 + relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1848 + else
1850 + bfd_boolean warned, ignored;
1852 + RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1853 + r_symndx, symtab_hdr, sym_hashes,
1854 + h, sec, relocation,
1855 + unresolved_reloc, warned, ignored);
1856 + if (warned)
1858 + /* To avoid generating warning messages about truncated
1859 + relocations, set the relocation's address to be the same as
1860 + the start of this section. */
1861 + if (input_section->output_section != NULL)
1862 + relocation = input_section->output_section->vma;
1863 + else
1864 + relocation = 0;
1868 + if (sec != NULL && discarded_section (sec))
1869 + RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1870 + rel, 1, relend, howto, 0, contents);
1872 + if (bfd_link_relocatable (info))
1873 + continue;
1875 + if (h != NULL)
1876 + name = h->root.root.string;
1877 + else
1879 + name = (bfd_elf_string_from_elf_section
1880 + (input_bfd, symtab_hdr->sh_link, sym->st_name));
1881 + if (name == NULL || *name == '\0')
1882 + name = bfd_section_name (input_bfd, sec);
1885 + switch (r_type)
1887 + case R_RISCV_NONE:
1888 + case R_RISCV_TPREL_ADD:
1889 + case R_RISCV_COPY:
1890 + case R_RISCV_JUMP_SLOT:
1891 + case R_RISCV_RELATIVE:
1892 + /* These require nothing of us at all. */
1893 + continue;
1895 + case R_RISCV_HI20:
1896 + case R_RISCV_BRANCH:
1897 + case R_RISCV_RVC_BRANCH:
1898 + case R_RISCV_RVC_LUI:
1899 + case R_RISCV_LO12_I:
1900 + case R_RISCV_LO12_S:
1901 + /* These require no special handling beyond perform_relocation. */
1902 + break;
1904 + case R_RISCV_GOT_HI20:
1905 + if (h != NULL)
1907 + bfd_boolean dyn, pic;
1909 + off = h->got.offset;
1910 + BFD_ASSERT (off != (bfd_vma) -1);
1911 + dyn = elf_hash_table (info)->dynamic_sections_created;
1912 + pic = bfd_link_pic (info);
1914 + if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
1915 + || (pic && SYMBOL_REFERENCES_LOCAL (info, h)))
1917 + /* This is actually a static link, or it is a
1918 + -Bsymbolic link and the symbol is defined
1919 + locally, or the symbol was forced to be local
1920 + because of a version file. We must initialize
1921 + this entry in the global offset table. Since the
1922 + offset must always be a multiple of the word size,
1923 + we use the least significant bit to record whether
1924 + we have initialized it already.
1926 + When doing a dynamic link, we create a .rela.got
1927 + relocation entry to initialize the value. This
1928 + is done in the finish_dynamic_symbol routine. */
1929 + if ((off & 1) != 0)
1930 + off &= ~1;
1931 + else
1933 + bfd_put_NN (output_bfd, relocation,
1934 + htab->elf.sgot->contents + off);
1935 + h->got.offset |= 1;
1938 + else
1939 + unresolved_reloc = FALSE;
1941 + else
1943 + BFD_ASSERT (local_got_offsets != NULL
1944 + && local_got_offsets[r_symndx] != (bfd_vma) -1);
1946 + off = local_got_offsets[r_symndx];
1948 + /* The offset must always be a multiple of the word size.
1949 + So, we can use the least significant bit to record
1950 + whether we have already processed this entry. */
1951 + if ((off & 1) != 0)
1952 + off &= ~1;
1953 + else
1955 + if (bfd_link_pic (info))
1957 + asection *s;
1958 + Elf_Internal_Rela outrel;
1960 + /* We need to generate a R_RISCV_RELATIVE reloc
1961 + for the dynamic linker. */
1962 + s = htab->elf.srelgot;
1963 + BFD_ASSERT (s != NULL);
1965 + outrel.r_offset = sec_addr (htab->elf.sgot) + off;
1966 + outrel.r_info =
1967 + ELFNN_R_INFO (0, R_RISCV_RELATIVE);
1968 + outrel.r_addend = relocation;
1969 + relocation = 0;
1970 + riscv_elf_append_rela (output_bfd, s, &outrel);
1973 + bfd_put_NN (output_bfd, relocation,
1974 + htab->elf.sgot->contents + off);
1975 + local_got_offsets[r_symndx] |= 1;
1978 + relocation = sec_addr (htab->elf.sgot) + off;
1979 + if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, relocation))
1980 + r = bfd_reloc_overflow;
1981 + break;
1983 + case R_RISCV_ADD8:
1984 + case R_RISCV_ADD16:
1985 + case R_RISCV_ADD32:
1986 + case R_RISCV_ADD64:
1988 + bfd_vma old_value = bfd_get (howto->bitsize, input_bfd,
1989 + contents + rel->r_offset);
1990 + relocation = old_value + relocation;
1992 + break;
1994 + case R_RISCV_SUB8:
1995 + case R_RISCV_SUB16:
1996 + case R_RISCV_SUB32:
1997 + case R_RISCV_SUB64:
1999 + bfd_vma old_value = bfd_get (howto->bitsize, input_bfd,
2000 + contents + rel->r_offset);
2001 + relocation = old_value - relocation;
2003 + break;
2005 + case R_RISCV_CALL_PLT:
2006 + case R_RISCV_CALL:
2007 + case R_RISCV_JAL:
2008 + case R_RISCV_RVC_JUMP:
2009 + if (bfd_link_pic (info) && h != NULL && h->plt.offset != MINUS_ONE)
2011 + /* Refer to the PLT entry. */
2012 + relocation = sec_addr (htab->elf.splt) + h->plt.offset;
2013 + unresolved_reloc = FALSE;
2015 + break;
2017 + case R_RISCV_TPREL_HI20:
2018 + relocation = tpoff (info, relocation);
2019 + break;
2021 + case R_RISCV_TPREL_LO12_I:
2022 + case R_RISCV_TPREL_LO12_S:
2023 + relocation = tpoff (info, relocation);
2024 + if (VALID_ITYPE_IMM (relocation + rel->r_addend))
2026 + /* We can use tp as the base register. */
2027 + bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2028 + insn &= ~(OP_MASK_RS1 << OP_SH_RS1);
2029 + insn |= X_TP << OP_SH_RS1;
2030 + bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
2032 + break;
2034 + case R_RISCV_GPREL_I:
2035 + case R_RISCV_GPREL_S:
2037 + bfd_vma gp = riscv_global_pointer_value (info);
2038 + bfd_boolean x0_base = VALID_ITYPE_IMM (relocation + rel->r_addend);
2039 + if (x0_base || VALID_ITYPE_IMM (relocation + rel->r_addend - gp))
2041 + /* We can use x0 or gp as the base register. */
2042 + bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2043 + insn &= ~(OP_MASK_RS1 << OP_SH_RS1);
2044 + if (!x0_base)
2046 + rel->r_addend -= gp;
2047 + insn |= X_GP << OP_SH_RS1;
2049 + bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
2051 + else
2052 + r = bfd_reloc_overflow;
2053 + break;
2056 + case R_RISCV_PCREL_HI20:
2057 + if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc,
2058 + relocation + rel->r_addend))
2059 + r = bfd_reloc_overflow;
2060 + break;
2062 + case R_RISCV_PCREL_LO12_I:
2063 + case R_RISCV_PCREL_LO12_S:
2064 + if (riscv_record_pcrel_lo_reloc (&pcrel_relocs, input_section, info,
2065 + howto, rel, relocation, name,
2066 + contents))
2067 + continue;
2068 + r = bfd_reloc_overflow;
2069 + break;
2071 + case R_RISCV_TLS_DTPREL32:
2072 + case R_RISCV_TLS_DTPREL64:
2073 + relocation = dtpoff (info, relocation);
2074 + break;
2076 + case R_RISCV_32:
2077 + case R_RISCV_64:
2078 + if ((input_section->flags & SEC_ALLOC) == 0)
2079 + break;
2081 + if ((bfd_link_pic (info)
2082 + && (h == NULL
2083 + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2084 + || h->root.type != bfd_link_hash_undefweak)
2085 + && (! howto->pc_relative
2086 + || !SYMBOL_CALLS_LOCAL (info, h)))
2087 + || (!bfd_link_pic (info)
2088 + && h != NULL
2089 + && h->dynindx != -1
2090 + && !h->non_got_ref
2091 + && ((h->def_dynamic
2092 + && !h->def_regular)
2093 + || h->root.type == bfd_link_hash_undefweak
2094 + || h->root.type == bfd_link_hash_undefined)))
2096 + Elf_Internal_Rela outrel;
2097 + bfd_boolean skip_static_relocation, skip_dynamic_relocation;
2099 + /* When generating a shared object, these relocations
2100 + are copied into the output file to be resolved at run
2101 + time. */
2103 + outrel.r_offset =
2104 + _bfd_elf_section_offset (output_bfd, info, input_section,
2105 + rel->r_offset);
2106 + skip_static_relocation = outrel.r_offset != (bfd_vma) -2;
2107 + skip_dynamic_relocation = outrel.r_offset >= (bfd_vma) -2;
2108 + outrel.r_offset += sec_addr (input_section);
2110 + if (skip_dynamic_relocation)
2111 + memset (&outrel, 0, sizeof outrel);
2112 + else if (h != NULL && h->dynindx != -1
2113 + && !(bfd_link_pic (info)
2114 + && SYMBOLIC_BIND (info, h)
2115 + && h->def_regular))
2117 + outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
2118 + outrel.r_addend = rel->r_addend;
2120 + else
2122 + outrel.r_info = ELFNN_R_INFO (0, R_RISCV_RELATIVE);
2123 + outrel.r_addend = relocation + rel->r_addend;
2126 + riscv_elf_append_rela (output_bfd, sreloc, &outrel);
2127 + if (skip_static_relocation)
2128 + continue;
2130 + break;
2132 + case R_RISCV_TLS_GOT_HI20:
2133 + is_ie = TRUE;
2134 + /* Fall through. */
2136 + case R_RISCV_TLS_GD_HI20:
2137 + if (h != NULL)
2139 + off = h->got.offset;
2140 + h->got.offset |= 1;
2142 + else
2144 + off = local_got_offsets[r_symndx];
2145 + local_got_offsets[r_symndx] |= 1;
2148 + tls_type = _bfd_riscv_elf_tls_type (input_bfd, h, r_symndx);
2149 + BFD_ASSERT (tls_type & (GOT_TLS_IE | GOT_TLS_GD));
2150 + /* If this symbol is referenced by both GD and IE TLS, the IE
2151 + reference's GOT slot follows the GD reference's slots. */
2152 + ie_off = 0;
2153 + if ((tls_type & GOT_TLS_GD) && (tls_type & GOT_TLS_IE))
2154 + ie_off = 2 * GOT_ENTRY_SIZE;
2156 + if ((off & 1) != 0)
2157 + off &= ~1;
2158 + else
2160 + Elf_Internal_Rela outrel;
2161 + int indx = 0;
2162 + bfd_boolean need_relocs = FALSE;
2164 + if (htab->elf.srelgot == NULL)
2165 + abort ();
2167 + if (h != NULL)
2169 + bfd_boolean dyn, pic;
2170 + dyn = htab->elf.dynamic_sections_created;
2171 + pic = bfd_link_pic (info);
2173 + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
2174 + && (!pic || !SYMBOL_REFERENCES_LOCAL (info, h)))
2175 + indx = h->dynindx;
2178 + /* The GOT entries have not been initialized yet. Do it
2179 + now, and emit any relocations. */
2180 + if ((bfd_link_pic (info) || indx != 0)
2181 + && (h == NULL
2182 + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2183 + || h->root.type != bfd_link_hash_undefweak))
2184 + need_relocs = TRUE;
2186 + if (tls_type & GOT_TLS_GD)
2188 + if (need_relocs)
2190 + outrel.r_offset = sec_addr (htab->elf.sgot) + off;
2191 + outrel.r_addend = 0;
2192 + outrel.r_info = ELFNN_R_INFO (indx, R_RISCV_TLS_DTPMODNN);
2193 + bfd_put_NN (output_bfd, 0,
2194 + htab->elf.sgot->contents + off);
2195 + riscv_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
2196 + if (indx == 0)
2198 + BFD_ASSERT (! unresolved_reloc);
2199 + bfd_put_NN (output_bfd,
2200 + dtpoff (info, relocation),
2201 + (htab->elf.sgot->contents + off +
2202 + RISCV_ELF_WORD_BYTES));
2204 + else
2206 + bfd_put_NN (output_bfd, 0,
2207 + (htab->elf.sgot->contents + off +
2208 + RISCV_ELF_WORD_BYTES));
2209 + outrel.r_info = ELFNN_R_INFO (indx, R_RISCV_TLS_DTPRELNN);
2210 + outrel.r_offset += RISCV_ELF_WORD_BYTES;
2211 + riscv_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
2214 + else
2216 + /* If we are not emitting relocations for a
2217 + general dynamic reference, then we must be in a
2218 + static link or an executable link with the
2219 + symbol binding locally. Mark it as belonging
2220 + to module 1, the executable. */
2221 + bfd_put_NN (output_bfd, 1,
2222 + htab->elf.sgot->contents + off);
2223 + bfd_put_NN (output_bfd,
2224 + dtpoff (info, relocation),
2225 + (htab->elf.sgot->contents + off +
2226 + RISCV_ELF_WORD_BYTES));
2230 + if (tls_type & GOT_TLS_IE)
2232 + if (need_relocs)
2234 + bfd_put_NN (output_bfd, 0,
2235 + htab->elf.sgot->contents + off + ie_off);
2236 + outrel.r_offset = sec_addr (htab->elf.sgot)
2237 + + off + ie_off;
2238 + outrel.r_addend = 0;
2239 + if (indx == 0)
2240 + outrel.r_addend = tpoff (info, relocation);
2241 + outrel.r_info = ELFNN_R_INFO (indx, R_RISCV_TLS_TPRELNN);
2242 + riscv_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
2244 + else
2246 + bfd_put_NN (output_bfd, tpoff (info, relocation),
2247 + htab->elf.sgot->contents + off + ie_off);
2252 + BFD_ASSERT (off < (bfd_vma) -2);
2253 + relocation = sec_addr (htab->elf.sgot) + off + (is_ie ? ie_off : 0);
2254 + if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, relocation))
2255 + r = bfd_reloc_overflow;
2256 + unresolved_reloc = FALSE;
2257 + break;
2259 + default:
2260 + r = bfd_reloc_notsupported;
2263 + /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2264 + because such sections are not SEC_ALLOC and thus ld.so will
2265 + not process them. */
2266 + if (unresolved_reloc
2267 + && !((input_section->flags & SEC_DEBUGGING) != 0
2268 + && h->def_dynamic)
2269 + && _bfd_elf_section_offset (output_bfd, info, input_section,
2270 + rel->r_offset) != (bfd_vma) -1)
2272 + (*_bfd_error_handler)
2273 + (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
2274 + input_bfd,
2275 + input_section,
2276 + (long) rel->r_offset,
2277 + howto->name,
2278 + h->root.root.string);
2279 + continue;
2282 + if (r == bfd_reloc_ok)
2283 + r = perform_relocation (howto, rel, relocation, input_section,
2284 + input_bfd, contents);
2286 + switch (r)
2288 + case bfd_reloc_ok:
2289 + continue;
2291 + case bfd_reloc_overflow:
2292 + r = info->callbacks->reloc_overflow
2293 + (info, (h ? &h->root : NULL), name, howto->name,
2294 + (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
2295 + break;
2297 + case bfd_reloc_undefined:
2298 + r = info->callbacks->undefined_symbol
2299 + (info, name, input_bfd, input_section, rel->r_offset,
2300 + TRUE);
2301 + break;
2303 + case bfd_reloc_outofrange:
2304 + msg = _("internal error: out of range error");
2305 + break;
2307 + case bfd_reloc_notsupported:
2308 + msg = _("internal error: unsupported relocation error");
2309 + break;
2311 + case bfd_reloc_dangerous:
2312 + msg = _("internal error: dangerous relocation");
2313 + break;
2315 + default:
2316 + msg = _("internal error: unknown error");
2317 + break;
2320 + if (msg)
2321 + r = info->callbacks->warning
2322 + (info, msg, name, input_bfd, input_section, rel->r_offset);
2323 + goto out;
2326 + ret = riscv_resolve_pcrel_lo_relocs (&pcrel_relocs);
2327 +out:
2328 + riscv_free_pcrel_relocs (&pcrel_relocs);
2329 + return ret;
2332 +/* Finish up dynamic symbol handling. We set the contents of various
2333 + dynamic sections here. */
2335 +static bfd_boolean
2336 +riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
2337 + struct bfd_link_info *info,
2338 + struct elf_link_hash_entry *h,
2339 + Elf_Internal_Sym *sym)
2341 + struct riscv_elf_link_hash_table *htab = riscv_elf_hash_table (info);
2342 + const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
2344 + if (h->plt.offset != (bfd_vma) -1)
2346 + /* We've decided to create a PLT entry for this symbol. */
2347 + bfd_byte *loc;
2348 + bfd_vma i, header_address, plt_idx, got_address;
2349 + uint32_t plt_entry[PLT_ENTRY_INSNS];
2350 + Elf_Internal_Rela rela;
2352 + BFD_ASSERT (h->dynindx != -1);
2354 + /* Calculate the address of the PLT header. */
2355 + header_address = sec_addr (htab->elf.splt);
2357 + /* Calculate the index of the entry. */
2358 + plt_idx = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
2360 + /* Calculate the address of the .got.plt entry. */
2361 + got_address = riscv_elf_got_plt_val (plt_idx, info);
2363 + /* Find out where the .plt entry should go. */
2364 + loc = htab->elf.splt->contents + h->plt.offset;
2366 + /* Fill in the PLT entry itself. */
2367 + riscv_make_plt_entry (got_address, header_address + h->plt.offset,
2368 + plt_entry);
2369 + for (i = 0; i < PLT_ENTRY_INSNS; i++)
2370 + bfd_put_32 (output_bfd, plt_entry[i], loc + 4*i);
2372 + /* Fill in the initial value of the .got.plt entry. */
2373 + loc = htab->elf.sgotplt->contents
2374 + + (got_address - sec_addr (htab->elf.sgotplt));
2375 + bfd_put_NN (output_bfd, sec_addr (htab->elf.splt), loc);
2377 + /* Fill in the entry in the .rela.plt section. */
2378 + rela.r_offset = got_address;
2379 + rela.r_addend = 0;
2380 + rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_JUMP_SLOT);
2382 + loc = htab->elf.srelplt->contents + plt_idx * sizeof (ElfNN_External_Rela);
2383 + bed->s->swap_reloca_out (output_bfd, &rela, loc);
2385 + if (!h->def_regular)
2387 + /* Mark the symbol as undefined, rather than as defined in
2388 + the .plt section. Leave the value alone. */
2389 + sym->st_shndx = SHN_UNDEF;
2390 + /* If the symbol is weak, we do need to clear the value.
2391 + Otherwise, the PLT entry would provide a definition for
2392 + the symbol even if the symbol wasn't defined anywhere,
2393 + and so the symbol would never be NULL. */
2394 + if (!h->ref_regular_nonweak)
2395 + sym->st_value = 0;
2399 + if (h->got.offset != (bfd_vma) -1
2400 + && !(riscv_elf_hash_entry(h)->tls_type & (GOT_TLS_GD | GOT_TLS_IE)))
2402 + asection *sgot;
2403 + asection *srela;
2404 + Elf_Internal_Rela rela;
2406 + /* This symbol has an entry in the GOT. Set it up. */
2408 + sgot = htab->elf.sgot;
2409 + srela = htab->elf.srelgot;
2410 + BFD_ASSERT (sgot != NULL && srela != NULL);
2412 + rela.r_offset = sec_addr (sgot) + (h->got.offset &~ (bfd_vma) 1);
2414 + /* If this is a -Bsymbolic link, and the symbol is defined
2415 + locally, we just want to emit a RELATIVE reloc. Likewise if
2416 + the symbol was forced to be local because of a version file.
2417 + The entry in the global offset table will already have been
2418 + initialized in the relocate_section function. */
2419 + if (bfd_link_pic (info)
2420 + && (info->symbolic || h->dynindx == -1)
2421 + && h->def_regular)
2423 + asection *sec = h->root.u.def.section;
2424 + rela.r_info = ELFNN_R_INFO (0, R_RISCV_RELATIVE);
2425 + rela.r_addend = (h->root.u.def.value
2426 + + sec->output_section->vma
2427 + + sec->output_offset);
2429 + else
2431 + BFD_ASSERT (h->dynindx != -1);
2432 + rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_NN);
2433 + rela.r_addend = 0;
2436 + bfd_put_NN (output_bfd, 0,
2437 + sgot->contents + (h->got.offset & ~(bfd_vma) 1));
2438 + riscv_elf_append_rela (output_bfd, srela, &rela);
2441 + if (h->needs_copy)
2443 + Elf_Internal_Rela rela;
2445 + /* This symbols needs a copy reloc. Set it up. */
2446 + BFD_ASSERT (h->dynindx != -1);
2448 + rela.r_offset = sec_addr (h->root.u.def.section) + h->root.u.def.value;
2449 + rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_COPY);
2450 + rela.r_addend = 0;
2451 + riscv_elf_append_rela (output_bfd, htab->srelbss, &rela);
2454 + /* Mark some specially defined symbols as absolute. */
2455 + if (h == htab->elf.hdynamic
2456 + || (h == htab->elf.hgot || h == htab->elf.hplt))
2457 + sym->st_shndx = SHN_ABS;
2459 + return TRUE;
2462 +/* Finish up the dynamic sections. */
2464 +static bfd_boolean
2465 +riscv_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
2466 + bfd *dynobj, asection *sdyn)
2468 + struct riscv_elf_link_hash_table *htab = riscv_elf_hash_table (info);
2469 + const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
2470 + size_t dynsize = bed->s->sizeof_dyn;
2471 + bfd_byte *dyncon, *dynconend;
2473 + dynconend = sdyn->contents + sdyn->size;
2474 + for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
2476 + Elf_Internal_Dyn dyn;
2477 + asection *s;
2479 + bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
2481 + switch (dyn.d_tag)
2483 + case DT_PLTGOT:
2484 + s = htab->elf.sgotplt;
2485 + dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2486 + break;
2487 + case DT_JMPREL:
2488 + s = htab->elf.srelplt;
2489 + dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2490 + break;
2491 + case DT_PLTRELSZ:
2492 + s = htab->elf.srelplt;
2493 + dyn.d_un.d_val = s->size;
2494 + break;
2495 + default:
2496 + continue;
2499 + bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
2501 + return TRUE;
2504 +static bfd_boolean
2505 +riscv_elf_finish_dynamic_sections (bfd *output_bfd,
2506 + struct bfd_link_info *info)
2508 + bfd *dynobj;
2509 + asection *sdyn;
2510 + struct riscv_elf_link_hash_table *htab;
2512 + htab = riscv_elf_hash_table (info);
2513 + BFD_ASSERT (htab != NULL);
2514 + dynobj = htab->elf.dynobj;
2516 + sdyn = bfd_get_linker_section (dynobj, ".dynamic");
2518 + if (elf_hash_table (info)->dynamic_sections_created)
2520 + asection *splt;
2521 + bfd_boolean ret;
2523 + splt = htab->elf.splt;
2524 + BFD_ASSERT (splt != NULL && sdyn != NULL);
2526 + ret = riscv_finish_dyn (output_bfd, info, dynobj, sdyn);
2528 + if (ret != TRUE)
2529 + return ret;
2531 + /* Fill in the head and tail entries in the procedure linkage table. */
2532 + if (splt->size > 0)
2534 + int i;
2535 + uint32_t plt_header[PLT_HEADER_INSNS];
2536 + riscv_make_plt_header (sec_addr (htab->elf.sgotplt),
2537 + sec_addr (splt), plt_header);
2539 + for (i = 0; i < PLT_HEADER_INSNS; i++)
2540 + bfd_put_32 (output_bfd, plt_header[i], splt->contents + 4*i);
2543 + elf_section_data (splt->output_section)->this_hdr.sh_entsize
2544 + = PLT_ENTRY_SIZE;
2547 + if (htab->elf.sgotplt)
2549 + asection *output_section = htab->elf.sgotplt->output_section;
2551 + if (bfd_is_abs_section (output_section))
2553 + (*_bfd_error_handler)
2554 + (_("discarded output section: `%A'"), htab->elf.sgotplt);
2555 + return FALSE;
2558 + if (htab->elf.sgotplt->size > 0)
2560 + /* Write the first two entries in .got.plt, needed for the dynamic
2561 + linker. */
2562 + bfd_put_NN (output_bfd, (bfd_vma) -1, htab->elf.sgotplt->contents);
2563 + bfd_put_NN (output_bfd, (bfd_vma) 0,
2564 + htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
2567 + elf_section_data (output_section)->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
2570 + if (htab->elf.sgot)
2572 + asection *output_section = htab->elf.sgot->output_section;
2574 + if (htab->elf.sgot->size > 0)
2576 + /* Set the first entry in the global offset table to the address of
2577 + the dynamic section. */
2578 + bfd_vma val = sdyn ? sec_addr (sdyn) : 0;
2579 + bfd_put_NN (output_bfd, val, htab->elf.sgot->contents);
2582 + elf_section_data (output_section)->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
2585 + return TRUE;
2588 +/* Return address for Ith PLT stub in section PLT, for relocation REL
2589 + or (bfd_vma) -1 if it should not be included. */
2591 +static bfd_vma
2592 +riscv_elf_plt_sym_val (bfd_vma i, const asection *plt,
2593 + const arelent *rel ATTRIBUTE_UNUSED)
2595 + return plt->vma + PLT_HEADER_SIZE + i * PLT_ENTRY_SIZE;
2598 +static enum elf_reloc_type_class
2599 +riscv_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
2600 + const asection *rel_sec ATTRIBUTE_UNUSED,
2601 + const Elf_Internal_Rela *rela)
2603 + switch (ELFNN_R_TYPE (rela->r_info))
2605 + case R_RISCV_RELATIVE:
2606 + return reloc_class_relative;
2607 + case R_RISCV_JUMP_SLOT:
2608 + return reloc_class_plt;
2609 + case R_RISCV_COPY:
2610 + return reloc_class_copy;
2611 + default:
2612 + return reloc_class_normal;
2616 +/* Merge backend specific data from an object file to the output
2617 + object file when linking. */
2619 +static bfd_boolean
2620 +_bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
2622 + flagword new_flags = elf_elfheader (ibfd)->e_flags;
2623 + flagword old_flags = elf_elfheader (obfd)->e_flags;
2625 + if (!is_riscv_elf (ibfd) || !is_riscv_elf (obfd))
2626 + return TRUE;
2628 + if (strcmp (bfd_get_target (ibfd), bfd_get_target (obfd)) != 0)
2630 + (*_bfd_error_handler)
2631 + (_("%B: ABI is incompatible with that of the selected emulation"),
2632 + ibfd);
2633 + return FALSE;
2636 + if (!_bfd_elf_merge_object_attributes (ibfd, obfd))
2637 + return FALSE;
2639 + if (! elf_flags_init (obfd))
2641 + elf_flags_init (obfd) = TRUE;
2642 + elf_elfheader (obfd)->e_flags = new_flags;
2643 + return TRUE;
2646 + /* Disallow linking soft-float and hard-float. */
2647 + if ((old_flags ^ new_flags) & EF_RISCV_SOFT_FLOAT)
2649 + (*_bfd_error_handler)
2650 + (_("%B: can't link hard-float modules with soft-float modules"), ibfd);
2651 + goto fail;
2654 + /* Allow linking RVC and non-RVC, and keep the RVC flag. */
2655 + elf_elfheader (obfd)->e_flags |= new_flags & EF_RISCV_RVC;
2657 + return TRUE;
2659 +fail:
2660 + bfd_set_error (bfd_error_bad_value);
2661 + return FALSE;
2664 +/* Delete some bytes from a section while relaxing. */
2666 +static bfd_boolean
2667 +riscv_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, size_t count)
2669 + unsigned int i, symcount;
2670 + bfd_vma toaddr = sec->size;
2671 + struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (abfd);
2672 + Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2673 + unsigned int sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2674 + struct bfd_elf_section_data *data = elf_section_data (sec);
2675 + bfd_byte *contents = data->this_hdr.contents;
2677 + /* Actually delete the bytes. */
2678 + sec->size -= count;
2679 + memmove (contents + addr, contents + addr + count, toaddr - addr - count);
2681 + /* Adjust the location of all of the relocs. Note that we need not
2682 + adjust the addends, since all PC-relative references must be against
2683 + symbols, which we will adjust below. */
2684 + for (i = 0; i < sec->reloc_count; i++)
2685 + if (data->relocs[i].r_offset > addr && data->relocs[i].r_offset < toaddr)
2686 + data->relocs[i].r_offset -= count;
2688 + /* Adjust the local symbols defined in this section. */
2689 + for (i = 0; i < symtab_hdr->sh_info; i++)
2691 + Elf_Internal_Sym *sym = (Elf_Internal_Sym *) symtab_hdr->contents + i;
2692 + if (sym->st_shndx == sec_shndx)
2694 + /* If the symbol is in the range of memory we just moved, we
2695 + have to adjust its value. */
2696 + if (sym->st_value > addr && sym->st_value <= toaddr)
2697 + sym->st_value -= count;
2699 + /* If the symbol *spans* the bytes we just deleted (i.e. its
2700 + *end* is in the moved bytes but its *start* isn't), then we
2701 + must adjust its size. */
2702 + if (sym->st_value <= addr
2703 + && sym->st_value + sym->st_size > addr
2704 + && sym->st_value + sym->st_size <= toaddr)
2705 + sym->st_size -= count;
2709 + /* Now adjust the global symbols defined in this section. */
2710 + symcount = ((symtab_hdr->sh_size / sizeof (ElfNN_External_Sym))
2711 + - symtab_hdr->sh_info);
2713 + for (i = 0; i < symcount; i++)
2715 + struct elf_link_hash_entry *sym_hash = sym_hashes[i];
2717 + if ((sym_hash->root.type == bfd_link_hash_defined
2718 + || sym_hash->root.type == bfd_link_hash_defweak)
2719 + && sym_hash->root.u.def.section == sec)
2721 + /* As above, adjust the value if needed. */
2722 + if (sym_hash->root.u.def.value > addr
2723 + && sym_hash->root.u.def.value <= toaddr)
2724 + sym_hash->root.u.def.value -= count;
2726 + /* As above, adjust the size if needed. */
2727 + if (sym_hash->root.u.def.value <= addr
2728 + && sym_hash->root.u.def.value + sym_hash->size > addr
2729 + && sym_hash->root.u.def.value + sym_hash->size <= toaddr)
2730 + sym_hash->size -= count;
2734 + return TRUE;
2737 +/* Relax AUIPC + JALR into JAL. */
2739 +static bfd_boolean
2740 +_bfd_riscv_relax_call (bfd *abfd, asection *sec, asection *sym_sec,
2741 + struct bfd_link_info *link_info,
2742 + Elf_Internal_Rela *rel,
2743 + bfd_vma symval,
2744 + bfd_boolean *again)
2746 + bfd_byte *contents = elf_section_data (sec)->this_hdr.contents;
2747 + bfd_signed_vma foff = symval - (sec_addr (sec) + rel->r_offset);
2748 + bfd_boolean near_zero = (symval + RISCV_IMM_REACH/2) < RISCV_IMM_REACH;
2749 + bfd_vma auipc, jalr;
2750 + int rd, r_type, len = 4, rvc = elf_elfheader (abfd)->e_flags & EF_RISCV_RVC;
2752 + /* If the call crosses section boundaries, an alignment directive could
2753 + cause the PC-relative offset to later increase. Assume at most
2754 + page-alignment, and account for this by adding some slop. */
2755 + if (VALID_UJTYPE_IMM (foff) && sym_sec->output_section != sec->output_section)
2756 + foff += (foff < 0 ? -ELF_MAXPAGESIZE : ELF_MAXPAGESIZE);
2758 + /* See if this function call can be shortened. */
2759 + if (!VALID_UJTYPE_IMM (foff) && !(!bfd_link_pic (link_info) && near_zero))
2760 + return TRUE;
2762 + /* Shorten the function call. */
2763 + BFD_ASSERT (rel->r_offset + 8 <= sec->size);
2765 + auipc = bfd_get_32 (abfd, contents + rel->r_offset);
2766 + jalr = bfd_get_32 (abfd, contents + rel->r_offset + 4);
2767 + rd = (jalr >> OP_SH_RD) & OP_MASK_RD;
2768 + rvc = rvc && VALID_RVC_J_IMM (foff) && ARCH_SIZE == 32;
2770 + if (rvc && (rd == 0 || rd == X_RA))
2772 + /* Relax to C.J[AL] rd, addr. */
2773 + r_type = R_RISCV_RVC_JUMP;
2774 + auipc = rd == 0 ? MATCH_C_J : MATCH_C_JAL;
2775 + len = 2;
2777 + else if (VALID_UJTYPE_IMM (foff))
2779 + /* Relax to JAL rd, addr. */
2780 + r_type = R_RISCV_JAL;
2781 + auipc = MATCH_JAL | (rd << OP_SH_RD);
2783 + else /* near_zero */
2785 + /* Relax to JALR rd, x0, addr. */
2786 + r_type = R_RISCV_LO12_I;
2787 + auipc = MATCH_JALR | (rd << OP_SH_RD);
2790 + /* Replace the R_RISCV_CALL reloc. */
2791 + rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), r_type);
2792 + /* Replace the AUIPC. */
2793 + bfd_put (8 * len, abfd, auipc, contents + rel->r_offset);
2795 + /* Delete unnecessary JALR. */
2796 + *again = TRUE;
2797 + return riscv_relax_delete_bytes (abfd, sec, rel->r_offset + len, 8 - len);
2800 +/* Relax non-PIC global variable references. */
2802 +static bfd_boolean
2803 +_bfd_riscv_relax_lui (bfd *abfd, asection *sec, asection *sym_sec,
2804 + struct bfd_link_info *link_info,
2805 + Elf_Internal_Rela *rel,
2806 + bfd_vma symval,
2807 + bfd_boolean *again)
2809 + bfd_byte *contents = elf_section_data (sec)->this_hdr.contents;
2810 + bfd_vma gp = riscv_global_pointer_value (link_info);
2811 + int use_rvc = elf_elfheader (abfd)->e_flags & EF_RISCV_RVC;
2813 + /* Mergeable symbols might later move out of range. */
2814 + if (sym_sec->flags & SEC_MERGE)
2815 + return TRUE;
2817 + BFD_ASSERT (rel->r_offset + 4 <= sec->size);
2819 + /* Is the reference in range of x0 or gp? */
2820 + if (VALID_ITYPE_IMM (symval) || VALID_ITYPE_IMM (symval - gp))
2822 + unsigned sym = ELFNN_R_SYM (rel->r_info);
2823 + switch (ELFNN_R_TYPE (rel->r_info))
2825 + case R_RISCV_LO12_I:
2826 + rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_I);
2827 + return TRUE;
2829 + case R_RISCV_LO12_S:
2830 + rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S);
2831 + return TRUE;
2833 + case R_RISCV_HI20:
2834 + /* We can delete the unnecessary LUI and reloc. */
2835 + rel->r_info = ELFNN_R_INFO (0, R_RISCV_NONE);
2836 + *again = TRUE;
2837 + return riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4);
2839 + default:
2840 + abort ();
2844 + /* Can we relax LUI to C.LUI? Alignment might move the section forward;
2845 + account for this assuming page alignment at worst. */
2846 + if (use_rvc
2847 + && ELFNN_R_TYPE (rel->r_info) == R_RISCV_HI20
2848 + && VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval))
2849 + && VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval + ELF_MAXPAGESIZE)))
2851 + /* Replace LUI with C.LUI if legal (i.e., rd != x2/sp). */
2852 + bfd_vma lui = bfd_get_32 (abfd, contents + rel->r_offset);
2853 + if (((lui >> OP_SH_RD) & OP_MASK_RD) == X_SP)
2854 + return TRUE;
2856 + lui = (lui & (OP_MASK_RD << OP_SH_RD)) | MATCH_C_LUI;
2857 + bfd_put_32 (abfd, lui, contents + rel->r_offset);
2859 + /* Replace the R_RISCV_HI20 reloc. */
2860 + rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), R_RISCV_RVC_LUI);
2862 + *again = TRUE;
2863 + return riscv_relax_delete_bytes (abfd, sec, rel->r_offset + 2, 2);
2866 + return TRUE;
2869 +/* Relax non-PIC TLS references. */
2871 +static bfd_boolean
2872 +_bfd_riscv_relax_tls_le (bfd *abfd, asection *sec,
2873 + asection *sym_sec ATTRIBUTE_UNUSED,
2874 + struct bfd_link_info *link_info,
2875 + Elf_Internal_Rela *rel,
2876 + bfd_vma symval,
2877 + bfd_boolean *again)
2879 + /* See if this symbol is in range of tp. */
2880 + if (RISCV_CONST_HIGH_PART (tpoff (link_info, symval)) != 0)
2881 + return TRUE;
2883 + /* We can delete the unnecessary LUI and tp add. The LO12 reloc will be
2884 + made directly tp-relative. */
2885 + BFD_ASSERT (rel->r_offset + 4 <= sec->size);
2886 + rel->r_info = ELFNN_R_INFO (0, R_RISCV_NONE);
2888 + *again = TRUE;
2889 + return riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4);
2892 +/* Implement R_RISCV_ALIGN by deleting excess alignment NOPs. */
2894 +static bfd_boolean
2895 +_bfd_riscv_relax_align (bfd *abfd, asection *sec,
2896 + asection *sym_sec ATTRIBUTE_UNUSED,
2897 + struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
2898 + Elf_Internal_Rela *rel,
2899 + bfd_vma symval,
2900 + bfd_boolean *again ATTRIBUTE_UNUSED)
2902 + bfd_byte *contents = elf_section_data (sec)->this_hdr.contents;
2903 + bfd_vma alignment = 1, pos;
2904 + while (alignment <= rel->r_addend)
2905 + alignment *= 2;
2907 + symval -= rel->r_addend;
2908 + bfd_vma aligned_addr = ((symval - 1) & ~(alignment - 1)) + alignment;
2909 + bfd_vma nop_bytes = aligned_addr - symval;
2911 + /* Once we've handled an R_RISCV_ALIGN, we can't relax anything else. */
2912 + sec->sec_flg0 = TRUE;
2914 + /* Make sure there are enough NOPs to actually achieve the alignment. */
2915 + if (rel->r_addend < nop_bytes)
2916 + return FALSE;
2918 + /* Delete the reloc. */
2919 + rel->r_info = ELFNN_R_INFO (0, R_RISCV_NONE);
2921 + /* If the number of NOPs is already correct, there's nothing to do. */
2922 + if (nop_bytes == rel->r_addend)
2923 + return TRUE;
2925 + /* Write as many RISC-V NOPs as we need. */
2926 + for (pos = 0; pos < (nop_bytes & -4); pos += 4)
2927 + bfd_put_32 (abfd, RISCV_NOP, contents + rel->r_offset + pos);
2929 + /* Write a final RVC NOP if need be. */
2930 + if (nop_bytes % 4 != 0)
2931 + bfd_put_16 (abfd, RVC_NOP, contents + rel->r_offset + pos);
2933 + /* Delete the excess bytes. */
2934 + return riscv_relax_delete_bytes (abfd, sec, rel->r_offset + nop_bytes,
2935 + rel->r_addend - nop_bytes);
2938 +/* Relax a section. Pass 0 shortens code sequences unless disabled.
2939 + Pass 1, which cannot be disabled, handles code alignment directives. */
2941 +static bfd_boolean
2942 +_bfd_riscv_relax_section (bfd *abfd, asection *sec,
2943 + struct bfd_link_info *info, bfd_boolean *again)
2945 + Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (abfd);
2946 + struct riscv_elf_link_hash_table *htab = riscv_elf_hash_table (info);
2947 + struct bfd_elf_section_data *data = elf_section_data (sec);
2948 + Elf_Internal_Rela *relocs;
2949 + bfd_boolean ret = FALSE;
2950 + unsigned int i;
2952 + *again = FALSE;
2954 + if (bfd_link_relocatable (info)
2955 + || sec->sec_flg0
2956 + || (sec->flags & SEC_RELOC) == 0
2957 + || sec->reloc_count == 0
2958 + || (info->disable_target_specific_optimizations
2959 + && info->relax_pass == 0))
2960 + return TRUE;
2962 + /* Read this BFD's relocs if we haven't done so already. */
2963 + if (data->relocs)
2964 + relocs = data->relocs;
2965 + else if (!(relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
2966 + info->keep_memory)))
2967 + goto fail;
2969 + /* Examine and consider relaxing each reloc. */
2970 + for (i = 0; i < sec->reloc_count; i++)
2972 + asection *sym_sec;
2973 + Elf_Internal_Rela *rel = relocs + i;
2974 + typeof (&_bfd_riscv_relax_call) relax_func = NULL;
2975 + int type = ELFNN_R_TYPE (rel->r_info);
2976 + bfd_vma symval;
2978 + if (info->relax_pass == 0)
2980 + if (type == R_RISCV_CALL || type == R_RISCV_CALL_PLT)
2981 + relax_func = _bfd_riscv_relax_call;
2982 + else if (type == R_RISCV_HI20
2983 + || type == R_RISCV_LO12_I
2984 + || type == R_RISCV_LO12_S)
2985 + relax_func = _bfd_riscv_relax_lui;
2986 + else if (type == R_RISCV_TPREL_HI20 || type == R_RISCV_TPREL_ADD)
2987 + relax_func = _bfd_riscv_relax_tls_le;
2989 + else if (type == R_RISCV_ALIGN)
2990 + relax_func = _bfd_riscv_relax_align;
2992 + if (!relax_func)
2993 + continue;
2995 + data->relocs = relocs;
2997 + /* Read this BFD's contents if we haven't done so already. */
2998 + if (!data->this_hdr.contents
2999 + && !bfd_malloc_and_get_section (abfd, sec, &data->this_hdr.contents))
3000 + goto fail;
3002 + /* Read this BFD's symbols if we haven't done so already. */
3003 + if (symtab_hdr->sh_info != 0
3004 + && !symtab_hdr->contents
3005 + && !(symtab_hdr->contents =
3006 + (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
3007 + symtab_hdr->sh_info,
3008 + 0, NULL, NULL, NULL)))
3009 + goto fail;
3011 + /* Get the value of the symbol referred to by the reloc. */
3012 + if (ELFNN_R_SYM (rel->r_info) < symtab_hdr->sh_info)
3014 + /* A local symbol. */
3015 + Elf_Internal_Sym *isym = ((Elf_Internal_Sym *) symtab_hdr->contents
3016 + + ELFNN_R_SYM (rel->r_info));
3018 + if (isym->st_shndx == SHN_UNDEF)
3019 + sym_sec = sec, symval = sec_addr (sec) + rel->r_offset;
3020 + else
3022 + BFD_ASSERT (isym->st_shndx < elf_numsections (abfd));
3023 + sym_sec = elf_elfsections (abfd)[isym->st_shndx]->bfd_section;
3024 + if (sec_addr (sym_sec) == 0)
3025 + continue;
3026 + symval = sec_addr (sym_sec) + isym->st_value;
3029 + else
3031 + unsigned long indx;
3032 + struct elf_link_hash_entry *h;
3034 + indx = ELFNN_R_SYM (rel->r_info) - symtab_hdr->sh_info;
3035 + h = elf_sym_hashes (abfd)[indx];
3037 + while (h->root.type == bfd_link_hash_indirect
3038 + || h->root.type == bfd_link_hash_warning)
3039 + h = (struct elf_link_hash_entry *) h->root.u.i.link;
3041 + if (h->plt.offset != MINUS_ONE)
3042 + symval = sec_addr (htab->elf.splt) + h->plt.offset;
3043 + else if (h->root.u.def.section->output_section == NULL
3044 + || (h->root.type != bfd_link_hash_defined
3045 + && h->root.type != bfd_link_hash_defweak))
3046 + continue;
3047 + else
3048 + symval = sec_addr (h->root.u.def.section) + h->root.u.def.value;
3050 + sym_sec = h->root.u.def.section;
3053 + symval += rel->r_addend;
3055 + if (!relax_func (abfd, sec, sym_sec, info, rel, symval, again))
3056 + goto fail;
3059 + ret = TRUE;
3061 +fail:
3062 + if (relocs != data->relocs)
3063 + free (relocs);
3065 + return ret;
3068 +#define TARGET_LITTLE_SYM riscv_elfNN_vec
3069 +#define TARGET_LITTLE_NAME "elfNN-littleriscv"
3071 +#define elf_backend_reloc_type_class riscv_reloc_type_class
3073 +#define bfd_elfNN_bfd_reloc_name_lookup riscv_reloc_name_lookup
3074 +#define bfd_elfNN_bfd_link_hash_table_create riscv_elf_link_hash_table_create
3075 +#define bfd_elfNN_bfd_reloc_type_lookup riscv_reloc_type_lookup
3076 +#define bfd_elfNN_bfd_merge_private_bfd_data \
3077 + _bfd_riscv_elf_merge_private_bfd_data
3079 +#define elf_backend_copy_indirect_symbol riscv_elf_copy_indirect_symbol
3080 +#define elf_backend_create_dynamic_sections riscv_elf_create_dynamic_sections
3081 +#define elf_backend_check_relocs riscv_elf_check_relocs
3082 +#define elf_backend_adjust_dynamic_symbol riscv_elf_adjust_dynamic_symbol
3083 +#define elf_backend_size_dynamic_sections riscv_elf_size_dynamic_sections
3084 +#define elf_backend_relocate_section riscv_elf_relocate_section
3085 +#define elf_backend_finish_dynamic_symbol riscv_elf_finish_dynamic_symbol
3086 +#define elf_backend_finish_dynamic_sections riscv_elf_finish_dynamic_sections
3087 +#define elf_backend_gc_mark_hook riscv_elf_gc_mark_hook
3088 +#define elf_backend_gc_sweep_hook riscv_elf_gc_sweep_hook
3089 +#define elf_backend_plt_sym_val riscv_elf_plt_sym_val
3090 +#define elf_info_to_howto_rel NULL
3091 +#define elf_info_to_howto riscv_info_to_howto_rela
3092 +#define bfd_elfNN_bfd_relax_section _bfd_riscv_relax_section
3094 +#define elf_backend_init_index_section _bfd_elf_init_1_index_section
3096 +#define elf_backend_can_gc_sections 1
3097 +#define elf_backend_can_refcount 1
3098 +#define elf_backend_want_got_plt 1
3099 +#define elf_backend_plt_readonly 1
3100 +#define elf_backend_plt_alignment 4
3101 +#define elf_backend_want_plt_sym 1
3102 +#define elf_backend_got_header_size (ARCH_SIZE / 8)
3103 +#define elf_backend_rela_normal 1
3104 +#define elf_backend_default_execstack 0
3106 +#include "elfNN-target.h"
3107 diff -urN empty/bfd/elfxx-riscv.c binutils-2.26.1/bfd/elfxx-riscv.c
3108 --- empty/bfd/elfxx-riscv.c 1970-01-01 08:00:00.000000000 +0800
3109 +++ binutils-2.26.1/bfd/elfxx-riscv.c 2016-04-03 10:33:12.062126369 +0800
3110 @@ -0,0 +1,814 @@
3111 +/* RISC-V-specific support for ELF.
3112 + Copyright 2011-2015 Free Software Foundation, Inc.
3114 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
3115 + Based on TILE-Gx and MIPS targets.
3117 + This file is part of BFD, the Binary File Descriptor library.
3119 + This program is free software; you can redistribute it and/or modify
3120 + it under the terms of the GNU General Public License as published by
3121 + the Free Software Foundation; either version 3 of the License, or
3122 + (at your option) any later version.
3124 + This program is distributed in the hope that it will be useful,
3125 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3126 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3127 + GNU General Public License for more details.
3129 + You should have received a copy of the GNU General Public License
3130 + along with this program; see the file COPYING3. If not,
3131 + see <http://www.gnu.org/licenses/>. */
3133 +#include "sysdep.h"
3134 +#include "bfd.h"
3135 +#include "libbfd.h"
3136 +#include "elf-bfd.h"
3137 +#include "elf/riscv.h"
3138 +#include "opcode/riscv.h"
3139 +#include "libiberty.h"
3140 +#include "elfxx-riscv.h"
3141 +#include <stdint.h>
3143 +#define MINUS_ONE ((bfd_vma)0 - 1)
3145 +/* The relocation table used for SHT_RELA sections. */
3147 +static reloc_howto_type howto_table[] =
3149 + /* No relocation. */
3150 + HOWTO (R_RISCV_NONE, /* type */
3151 + 0, /* rightshift */
3152 + 3, /* size */
3153 + 0, /* bitsize */
3154 + FALSE, /* pc_relative */
3155 + 0, /* bitpos */
3156 + complain_overflow_dont, /* complain_on_overflow */
3157 + bfd_elf_generic_reloc, /* special_function */
3158 + "R_RISCV_NONE", /* name */
3159 + FALSE, /* partial_inplace */
3160 + 0, /* src_mask */
3161 + 0, /* dst_mask */
3162 + FALSE), /* pcrel_offset */
3164 + /* 32 bit relocation. */
3165 + HOWTO (R_RISCV_32, /* type */
3166 + 0, /* rightshift */
3167 + 2, /* size */
3168 + 32, /* bitsize */
3169 + FALSE, /* pc_relative */
3170 + 0, /* bitpos */
3171 + complain_overflow_dont, /* complain_on_overflow */
3172 + bfd_elf_generic_reloc, /* special_function */
3173 + "R_RISCV_32", /* name */
3174 + FALSE, /* partial_inplace */
3175 + 0, /* src_mask */
3176 + 0xffffffff, /* dst_mask */
3177 + FALSE), /* pcrel_offset */
3179 + /* 64 bit relocation. */
3180 + HOWTO (R_RISCV_64, /* type */
3181 + 0, /* rightshift */
3182 + 4, /* size */
3183 + 64, /* bitsize */
3184 + FALSE, /* pc_relative */
3185 + 0, /* bitpos */
3186 + complain_overflow_dont, /* complain_on_overflow */
3187 + bfd_elf_generic_reloc, /* special_function */
3188 + "R_RISCV_64", /* name */
3189 + FALSE, /* partial_inplace */
3190 + 0, /* src_mask */
3191 + MINUS_ONE, /* dst_mask */
3192 + FALSE), /* pcrel_offset */
3194 + /* Relocation against a local symbol in a shared object. */
3195 + HOWTO (R_RISCV_RELATIVE, /* type */
3196 + 0, /* rightshift */
3197 + 2, /* size */
3198 + 32, /* bitsize */
3199 + FALSE, /* pc_relative */
3200 + 0, /* bitpos */
3201 + complain_overflow_dont, /* complain_on_overflow */
3202 + bfd_elf_generic_reloc, /* special_function */
3203 + "R_RISCV_RELATIVE", /* name */
3204 + FALSE, /* partial_inplace */
3205 + 0, /* src_mask */
3206 + 0xffffffff, /* dst_mask */
3207 + FALSE), /* pcrel_offset */
3209 + HOWTO (R_RISCV_COPY, /* type */
3210 + 0, /* rightshift */
3211 + 0, /* this one is variable size */
3212 + 0, /* bitsize */
3213 + FALSE, /* pc_relative */
3214 + 0, /* bitpos */
3215 + complain_overflow_bitfield, /* complain_on_overflow */
3216 + bfd_elf_generic_reloc, /* special_function */
3217 + "R_RISCV_COPY", /* name */
3218 + FALSE, /* partial_inplace */
3219 + 0x0, /* src_mask */
3220 + 0x0, /* dst_mask */
3221 + FALSE), /* pcrel_offset */
3223 + HOWTO (R_RISCV_JUMP_SLOT, /* type */
3224 + 0, /* rightshift */
3225 + 4, /* size */
3226 + 64, /* bitsize */
3227 + FALSE, /* pc_relative */
3228 + 0, /* bitpos */
3229 + complain_overflow_bitfield, /* complain_on_overflow */
3230 + bfd_elf_generic_reloc, /* special_function */
3231 + "R_RISCV_JUMP_SLOT", /* name */
3232 + FALSE, /* partial_inplace */
3233 + 0x0, /* src_mask */
3234 + 0x0, /* dst_mask */
3235 + FALSE), /* pcrel_offset */
3237 + /* Dynamic TLS relocations. */
3238 + HOWTO (R_RISCV_TLS_DTPMOD32, /* type */
3239 + 0, /* rightshift */
3240 + 4, /* size */
3241 + 32, /* bitsize */
3242 + FALSE, /* pc_relative */
3243 + 0, /* bitpos */
3244 + complain_overflow_dont, /* complain_on_overflow */
3245 + bfd_elf_generic_reloc, /* special_function */
3246 + "R_RISCV_TLS_DTPMOD32", /* name */
3247 + FALSE, /* partial_inplace */
3248 + MINUS_ONE, /* src_mask */
3249 + MINUS_ONE, /* dst_mask */
3250 + FALSE), /* pcrel_offset */
3252 + HOWTO (R_RISCV_TLS_DTPMOD64, /* type */
3253 + 0, /* rightshift */
3254 + 4, /* size */
3255 + 64, /* bitsize */
3256 + FALSE, /* pc_relative */
3257 + 0, /* bitpos */
3258 + complain_overflow_dont, /* complain_on_overflow */
3259 + bfd_elf_generic_reloc, /* special_function */
3260 + "R_RISCV_TLS_DTPMOD64", /* name */
3261 + FALSE, /* partial_inplace */
3262 + MINUS_ONE, /* src_mask */
3263 + MINUS_ONE, /* dst_mask */
3264 + FALSE), /* pcrel_offset */
3266 + HOWTO (R_RISCV_TLS_DTPREL32, /* type */
3267 + 0, /* rightshift */
3268 + 4, /* size */
3269 + 32, /* bitsize */
3270 + FALSE, /* pc_relative */
3271 + 0, /* bitpos */
3272 + complain_overflow_dont, /* complain_on_overflow */
3273 + bfd_elf_generic_reloc, /* special_function */
3274 + "R_RISCV_TLS_DTPREL32", /* name */
3275 + TRUE, /* partial_inplace */
3276 + MINUS_ONE, /* src_mask */
3277 + MINUS_ONE, /* dst_mask */
3278 + FALSE), /* pcrel_offset */
3280 + HOWTO (R_RISCV_TLS_DTPREL64, /* type */
3281 + 0, /* rightshift */
3282 + 4, /* size */
3283 + 64, /* bitsize */
3284 + FALSE, /* pc_relative */
3285 + 0, /* bitpos */
3286 + complain_overflow_dont, /* complain_on_overflow */
3287 + bfd_elf_generic_reloc, /* special_function */
3288 + "R_RISCV_TLS_DTPREL64", /* name */
3289 + TRUE, /* partial_inplace */
3290 + MINUS_ONE, /* src_mask */
3291 + MINUS_ONE, /* dst_mask */
3292 + FALSE), /* pcrel_offset */
3294 + HOWTO (R_RISCV_TLS_TPREL32, /* type */
3295 + 0, /* rightshift */
3296 + 2, /* size */
3297 + 32, /* bitsize */
3298 + FALSE, /* pc_relative */
3299 + 0, /* bitpos */
3300 + complain_overflow_dont, /* complain_on_overflow */
3301 + bfd_elf_generic_reloc, /* special_function */
3302 + "R_RISCV_TLS_TPREL32", /* name */
3303 + FALSE, /* partial_inplace */
3304 + MINUS_ONE, /* src_mask */
3305 + MINUS_ONE, /* dst_mask */
3306 + FALSE), /* pcrel_offset */
3308 + HOWTO (R_RISCV_TLS_TPREL64, /* type */
3309 + 0, /* rightshift */
3310 + 4, /* size */
3311 + 64, /* bitsize */
3312 + FALSE, /* pc_relative */
3313 + 0, /* bitpos */
3314 + complain_overflow_dont, /* complain_on_overflow */
3315 + bfd_elf_generic_reloc, /* special_function */
3316 + "R_RISCV_TLS_TPREL64", /* name */
3317 + FALSE, /* partial_inplace */
3318 + MINUS_ONE, /* src_mask */
3319 + MINUS_ONE, /* dst_mask */
3320 + FALSE), /* pcrel_offset */
3322 + /* Reserved for future relocs that the dynamic linker must understand. */
3323 + EMPTY_HOWTO (12),
3324 + EMPTY_HOWTO (13),
3325 + EMPTY_HOWTO (14),
3326 + EMPTY_HOWTO (15),
3328 + /* 12-bit PC-relative branch offset. */
3329 + HOWTO (R_RISCV_BRANCH, /* type */
3330 + 0, /* rightshift */
3331 + 2, /* size */
3332 + 32, /* bitsize */
3333 + TRUE, /* pc_relative */
3334 + 0, /* bitpos */
3335 + complain_overflow_signed, /* complain_on_overflow */
3336 + bfd_elf_generic_reloc, /* special_function */
3337 + "R_RISCV_BRANCH", /* name */
3338 + FALSE, /* partial_inplace */
3339 + 0, /* src_mask */
3340 + ENCODE_SBTYPE_IMM (-1U), /* dst_mask */
3341 + TRUE), /* pcrel_offset */
3343 + /* 20-bit PC-relative jump offset. */
3344 + HOWTO (R_RISCV_JAL, /* type */
3345 + 0, /* rightshift */
3346 + 2, /* size */
3347 + 32, /* bitsize */
3348 + TRUE, /* pc_relative */
3349 + 0, /* bitpos */
3350 + complain_overflow_dont, /* complain_on_overflow */
3351 + /* This needs complex overflow
3352 + detection, because the upper 36
3353 + bits must match the PC + 4. */
3354 + bfd_elf_generic_reloc, /* special_function */
3355 + "R_RISCV_JAL", /* name */
3356 + FALSE, /* partial_inplace */
3357 + 0, /* src_mask */
3358 + ENCODE_UJTYPE_IMM (-1U), /* dst_mask */
3359 + TRUE), /* pcrel_offset */
3361 + /* 32-bit PC-relative function call (AUIPC/JALR). */
3362 + HOWTO (R_RISCV_CALL, /* type */
3363 + 0, /* rightshift */
3364 + 2, /* size */
3365 + 64, /* bitsize */
3366 + TRUE, /* pc_relative */
3367 + 0, /* bitpos */
3368 + complain_overflow_dont, /* complain_on_overflow */
3369 + bfd_elf_generic_reloc, /* special_function */
3370 + "R_RISCV_CALL", /* name */
3371 + FALSE, /* partial_inplace */
3372 + 0, /* src_mask */
3373 + ENCODE_UTYPE_IMM (-1U) | ((bfd_vma) ENCODE_ITYPE_IMM (-1U) << 32),
3374 + /* dst_mask */
3375 + TRUE), /* pcrel_offset */
3377 + /* 32-bit PC-relative function call (AUIPC/JALR). */
3378 + HOWTO (R_RISCV_CALL_PLT, /* type */
3379 + 0, /* rightshift */
3380 + 2, /* size */
3381 + 64, /* bitsize */
3382 + TRUE, /* pc_relative */
3383 + 0, /* bitpos */
3384 + complain_overflow_dont, /* complain_on_overflow */
3385 + bfd_elf_generic_reloc, /* special_function */
3386 + "R_RISCV_CALL_PLT", /* name */
3387 + FALSE, /* partial_inplace */
3388 + 0, /* src_mask */
3389 + ENCODE_UTYPE_IMM (-1U) | ((bfd_vma) ENCODE_ITYPE_IMM (-1U) << 32),
3390 + /* dst_mask */
3391 + TRUE), /* pcrel_offset */
3393 + /* High 20 bits of 32-bit PC-relative GOT access. */
3394 + HOWTO (R_RISCV_GOT_HI20, /* type */
3395 + 0, /* rightshift */
3396 + 2, /* size */
3397 + 32, /* bitsize */
3398 + TRUE, /* pc_relative */
3399 + 0, /* bitpos */
3400 + complain_overflow_dont, /* complain_on_overflow */
3401 + bfd_elf_generic_reloc, /* special_function */
3402 + "R_RISCV_GOT_HI20", /* name */
3403 + FALSE, /* partial_inplace */
3404 + 0, /* src_mask */
3405 + ENCODE_UTYPE_IMM (-1U), /* dst_mask */
3406 + FALSE), /* pcrel_offset */
3408 + /* High 20 bits of 32-bit PC-relative TLS IE GOT access. */
3409 + HOWTO (R_RISCV_TLS_GOT_HI20, /* type */
3410 + 0, /* rightshift */
3411 + 2, /* size */
3412 + 32, /* bitsize */
3413 + TRUE, /* pc_relative */
3414 + 0, /* bitpos */
3415 + complain_overflow_dont, /* complain_on_overflow */
3416 + bfd_elf_generic_reloc, /* special_function */
3417 + "R_RISCV_TLS_GOT_HI20", /* name */
3418 + FALSE, /* partial_inplace */
3419 + 0, /* src_mask */
3420 + ENCODE_UTYPE_IMM (-1U), /* dst_mask */
3421 + FALSE), /* pcrel_offset */
3423 + /* High 20 bits of 32-bit PC-relative TLS GD GOT reference. */
3424 + HOWTO (R_RISCV_TLS_GD_HI20, /* type */
3425 + 0, /* rightshift */
3426 + 2, /* size */
3427 + 32, /* bitsize */
3428 + TRUE, /* pc_relative */
3429 + 0, /* bitpos */
3430 + complain_overflow_dont, /* complain_on_overflow */
3431 + bfd_elf_generic_reloc, /* special_function */
3432 + "R_RISCV_TLS_GD_HI20", /* name */
3433 + FALSE, /* partial_inplace */
3434 + 0, /* src_mask */
3435 + ENCODE_UTYPE_IMM (-1U), /* dst_mask */
3436 + FALSE), /* pcrel_offset */
3438 + /* High 20 bits of 32-bit PC-relative reference. */
3439 + HOWTO (R_RISCV_PCREL_HI20, /* type */
3440 + 0, /* rightshift */
3441 + 2, /* size */
3442 + 32, /* bitsize */
3443 + TRUE, /* pc_relative */
3444 + 0, /* bitpos */
3445 + complain_overflow_dont, /* complain_on_overflow */
3446 + bfd_elf_generic_reloc, /* special_function */
3447 + "R_RISCV_PCREL_HI20", /* name */
3448 + FALSE, /* partial_inplace */
3449 + 0, /* src_mask */
3450 + ENCODE_UTYPE_IMM (-1U), /* dst_mask */
3451 + TRUE), /* pcrel_offset */
3453 + /* Low 12 bits of a 32-bit PC-relative load or add. */
3454 + HOWTO (R_RISCV_PCREL_LO12_I, /* type */
3455 + 0, /* rightshift */
3456 + 2, /* size */
3457 + 32, /* bitsize */
3458 + FALSE, /* pc_relative */
3459 + 0, /* bitpos */
3460 + complain_overflow_dont, /* complain_on_overflow */
3461 + bfd_elf_generic_reloc, /* special_function */
3462 + "R_RISCV_PCREL_LO12_I", /* name */
3463 + FALSE, /* partial_inplace */
3464 + 0, /* src_mask */
3465 + ENCODE_ITYPE_IMM (-1U), /* dst_mask */
3466 + FALSE), /* pcrel_offset */
3468 + /* Low 12 bits of a 32-bit PC-relative store. */
3469 + HOWTO (R_RISCV_PCREL_LO12_S, /* type */
3470 + 0, /* rightshift */
3471 + 2, /* size */
3472 + 32, /* bitsize */
3473 + FALSE, /* pc_relative */
3474 + 0, /* bitpos */
3475 + complain_overflow_dont, /* complain_on_overflow */
3476 + bfd_elf_generic_reloc, /* special_function */
3477 + "R_RISCV_PCREL_LO12_S", /* name */
3478 + FALSE, /* partial_inplace */
3479 + 0, /* src_mask */
3480 + ENCODE_STYPE_IMM (-1U), /* dst_mask */
3481 + FALSE), /* pcrel_offset */
3483 + /* High 20 bits of 32-bit absolute address. */
3484 + HOWTO (R_RISCV_HI20, /* type */
3485 + 0, /* rightshift */
3486 + 2, /* size */
3487 + 32, /* bitsize */
3488 + FALSE, /* pc_relative */
3489 + 0, /* bitpos */
3490 + complain_overflow_dont, /* complain_on_overflow */
3491 + bfd_elf_generic_reloc, /* special_function */
3492 + "R_RISCV_HI20", /* name */
3493 + FALSE, /* partial_inplace */
3494 + 0, /* src_mask */
3495 + ENCODE_UTYPE_IMM (-1U), /* dst_mask */
3496 + FALSE), /* pcrel_offset */
3498 + /* High 12 bits of 32-bit load or add. */
3499 + HOWTO (R_RISCV_LO12_I, /* type */
3500 + 0, /* rightshift */
3501 + 2, /* size */
3502 + 32, /* bitsize */
3503 + FALSE, /* pc_relative */
3504 + 0, /* bitpos */
3505 + complain_overflow_dont, /* complain_on_overflow */
3506 + bfd_elf_generic_reloc, /* special_function */
3507 + "R_RISCV_LO12_I", /* name */
3508 + FALSE, /* partial_inplace */
3509 + 0, /* src_mask */
3510 + ENCODE_ITYPE_IMM (-1U), /* dst_mask */
3511 + FALSE), /* pcrel_offset */
3513 + /* High 12 bits of 32-bit store. */
3514 + HOWTO (R_RISCV_LO12_S, /* type */
3515 + 0, /* rightshift */
3516 + 2, /* size */
3517 + 32, /* bitsize */
3518 + FALSE, /* pc_relative */
3519 + 0, /* bitpos */
3520 + complain_overflow_dont, /* complain_on_overflow */
3521 + bfd_elf_generic_reloc, /* special_function */
3522 + "R_RISCV_LO12_S", /* name */
3523 + FALSE, /* partial_inplace */
3524 + 0, /* src_mask */
3525 + ENCODE_STYPE_IMM (-1U), /* dst_mask */
3526 + FALSE), /* pcrel_offset */
3528 + /* High 20 bits of TLS LE thread pointer offset. */
3529 + HOWTO (R_RISCV_TPREL_HI20, /* type */
3530 + 0, /* rightshift */
3531 + 2, /* size */
3532 + 32, /* bitsize */
3533 + FALSE, /* pc_relative */
3534 + 0, /* bitpos */
3535 + complain_overflow_signed, /* complain_on_overflow */
3536 + bfd_elf_generic_reloc, /* special_function */
3537 + "R_RISCV_TPREL_HI20", /* name */
3538 + TRUE, /* partial_inplace */
3539 + 0, /* src_mask */
3540 + ENCODE_UTYPE_IMM (-1U), /* dst_mask */
3541 + FALSE), /* pcrel_offset */
3543 + /* Low 12 bits of TLS LE thread pointer offset for loads and adds. */
3544 + HOWTO (R_RISCV_TPREL_LO12_I, /* type */
3545 + 0, /* rightshift */
3546 + 2, /* size */
3547 + 32, /* bitsize */
3548 + FALSE, /* pc_relative */
3549 + 0, /* bitpos */
3550 + complain_overflow_signed, /* complain_on_overflow */
3551 + bfd_elf_generic_reloc, /* special_function */
3552 + "R_RISCV_TPREL_LO12_I", /* name */
3553 + FALSE, /* partial_inplace */
3554 + 0, /* src_mask */
3555 + ENCODE_ITYPE_IMM (-1U), /* dst_mask */
3556 + FALSE), /* pcrel_offset */
3558 + /* Low 12 bits of TLS LE thread pointer offset for stores. */
3559 + HOWTO (R_RISCV_TPREL_LO12_S, /* type */
3560 + 0, /* rightshift */
3561 + 2, /* size */
3562 + 32, /* bitsize */
3563 + FALSE, /* pc_relative */
3564 + 0, /* bitpos */
3565 + complain_overflow_signed, /* complain_on_overflow */
3566 + bfd_elf_generic_reloc, /* special_function */
3567 + "R_RISCV_TPREL_LO12_S", /* name */
3568 + FALSE, /* partial_inplace */
3569 + 0, /* src_mask */
3570 + ENCODE_STYPE_IMM (-1U), /* dst_mask */
3571 + FALSE), /* pcrel_offset */
3573 + /* TLS LE thread pointer usage. */
3574 + HOWTO (R_RISCV_TPREL_ADD, /* type */
3575 + 0, /* rightshift */
3576 + 2, /* size */
3577 + 32, /* bitsize */
3578 + FALSE, /* pc_relative */
3579 + 0, /* bitpos */
3580 + complain_overflow_dont, /* complain_on_overflow */
3581 + bfd_elf_generic_reloc, /* special_function */
3582 + "R_RISCV_TPREL_ADD", /* name */
3583 + TRUE, /* partial_inplace */
3584 + 0, /* src_mask */
3585 + 0, /* dst_mask */
3586 + FALSE), /* pcrel_offset */
3588 + /* 8-bit in-place addition, for local label subtraction. */
3589 + HOWTO (R_RISCV_ADD8, /* type */
3590 + 0, /* rightshift */
3591 + 0, /* size */
3592 + 32, /* bitsize */
3593 + FALSE, /* pc_relative */
3594 + 0, /* bitpos */
3595 + complain_overflow_dont, /* complain_on_overflow */
3596 + bfd_elf_generic_reloc, /* special_function */
3597 + "R_RISCV_ADD8", /* name */
3598 + FALSE, /* partial_inplace */
3599 + 0, /* src_mask */
3600 + MINUS_ONE, /* dst_mask */
3601 + FALSE), /* pcrel_offset */
3603 + /* 16-bit in-place addition, for local label subtraction. */
3604 + HOWTO (R_RISCV_ADD16, /* type */
3605 + 0, /* rightshift */
3606 + 1, /* size */
3607 + 16, /* bitsize */
3608 + FALSE, /* pc_relative */
3609 + 0, /* bitpos */
3610 + complain_overflow_dont, /* complain_on_overflow */
3611 + bfd_elf_generic_reloc, /* special_function */
3612 + "R_RISCV_ADD16", /* name */
3613 + FALSE, /* partial_inplace */
3614 + 0, /* src_mask */
3615 + MINUS_ONE, /* dst_mask */
3616 + FALSE), /* pcrel_offset */
3618 + /* 32-bit in-place addition, for local label subtraction. */
3619 + HOWTO (R_RISCV_ADD32, /* type */
3620 + 0, /* rightshift */
3621 + 2, /* size */
3622 + 32, /* bitsize */
3623 + FALSE, /* pc_relative */
3624 + 0, /* bitpos */
3625 + complain_overflow_dont, /* complain_on_overflow */
3626 + bfd_elf_generic_reloc, /* special_function */
3627 + "R_RISCV_ADD32", /* name */
3628 + FALSE, /* partial_inplace */
3629 + 0, /* src_mask */
3630 + MINUS_ONE, /* dst_mask */
3631 + FALSE), /* pcrel_offset */
3633 + /* 64-bit in-place addition, for local label subtraction. */
3634 + HOWTO (R_RISCV_ADD64, /* type */
3635 + 0, /* rightshift */
3636 + 4, /* size */
3637 + 64, /* bitsize */
3638 + FALSE, /* pc_relative */
3639 + 0, /* bitpos */
3640 + complain_overflow_dont, /* complain_on_overflow */
3641 + bfd_elf_generic_reloc, /* special_function */
3642 + "R_RISCV_ADD64", /* name */
3643 + FALSE, /* partial_inplace */
3644 + 0, /* src_mask */
3645 + MINUS_ONE, /* dst_mask */
3646 + FALSE), /* pcrel_offset */
3648 + /* 8-bit in-place addition, for local label subtraction. */
3649 + HOWTO (R_RISCV_SUB8, /* type */
3650 + 0, /* rightshift */
3651 + 0, /* size */
3652 + 8, /* bitsize */
3653 + FALSE, /* pc_relative */
3654 + 0, /* bitpos */
3655 + complain_overflow_dont, /* complain_on_overflow */
3656 + bfd_elf_generic_reloc, /* special_function */
3657 + "R_RISCV_SUB8", /* name */
3658 + FALSE, /* partial_inplace */
3659 + 0, /* src_mask */
3660 + MINUS_ONE, /* dst_mask */
3661 + FALSE), /* pcrel_offset */
3663 + /* 16-bit in-place addition, for local label subtraction. */
3664 + HOWTO (R_RISCV_SUB16, /* type */
3665 + 0, /* rightshift */
3666 + 1, /* size */
3667 + 16, /* bitsize */
3668 + FALSE, /* pc_relative */
3669 + 0, /* bitpos */
3670 + complain_overflow_dont, /* complain_on_overflow */
3671 + bfd_elf_generic_reloc, /* special_function */
3672 + "R_RISCV_SUB16", /* name */
3673 + FALSE, /* partial_inplace */
3674 + 0, /* src_mask */
3675 + MINUS_ONE, /* dst_mask */
3676 + FALSE), /* pcrel_offset */
3678 + /* 32-bit in-place addition, for local label subtraction. */
3679 + HOWTO (R_RISCV_SUB32, /* type */
3680 + 0, /* rightshift */
3681 + 2, /* size */
3682 + 32, /* bitsize */
3683 + FALSE, /* pc_relative */
3684 + 0, /* bitpos */
3685 + complain_overflow_dont, /* complain_on_overflow */
3686 + bfd_elf_generic_reloc, /* special_function */
3687 + "R_RISCV_SUB32", /* name */
3688 + FALSE, /* partial_inplace */
3689 + 0, /* src_mask */
3690 + MINUS_ONE, /* dst_mask */
3691 + FALSE), /* pcrel_offset */
3693 + /* 64-bit in-place addition, for local label subtraction. */
3694 + HOWTO (R_RISCV_SUB64, /* type */
3695 + 0, /* rightshift */
3696 + 4, /* size */
3697 + 64, /* bitsize */
3698 + FALSE, /* pc_relative */
3699 + 0, /* bitpos */
3700 + complain_overflow_dont, /* complain_on_overflow */
3701 + bfd_elf_generic_reloc, /* special_function */
3702 + "R_RISCV_SUB64", /* name */
3703 + FALSE, /* partial_inplace */
3704 + 0, /* src_mask */
3705 + MINUS_ONE, /* dst_mask */
3706 + FALSE), /* pcrel_offset */
3708 + /* GNU extension to record C++ vtable hierarchy */
3709 + HOWTO (R_RISCV_GNU_VTINHERIT, /* type */
3710 + 0, /* rightshift */
3711 + 4, /* size */
3712 + 0, /* bitsize */
3713 + FALSE, /* pc_relative */
3714 + 0, /* bitpos */
3715 + complain_overflow_dont, /* complain_on_overflow */
3716 + NULL, /* special_function */
3717 + "R_RISCV_GNU_VTINHERIT", /* name */
3718 + FALSE, /* partial_inplace */
3719 + 0, /* src_mask */
3720 + 0, /* dst_mask */
3721 + FALSE), /* pcrel_offset */
3723 + /* GNU extension to record C++ vtable member usage */
3724 + HOWTO (R_RISCV_GNU_VTENTRY, /* type */
3725 + 0, /* rightshift */
3726 + 4, /* size */
3727 + 0, /* bitsize */
3728 + FALSE, /* pc_relative */
3729 + 0, /* bitpos */
3730 + complain_overflow_dont, /* complain_on_overflow */
3731 + _bfd_elf_rel_vtable_reloc_fn, /* special_function */
3732 + "R_RISCV_GNU_VTENTRY", /* name */
3733 + FALSE, /* partial_inplace */
3734 + 0, /* src_mask */
3735 + 0, /* dst_mask */
3736 + FALSE), /* pcrel_offset */
3738 + /* Indicates an alignment statement. The addend field encodes how many
3739 + bytes of NOPs follow the statement. The desired alignment is the
3740 + addend rounded up to the next power of two. */
3741 + HOWTO (R_RISCV_ALIGN, /* type */
3742 + 0, /* rightshift */
3743 + 2, /* size */
3744 + 0, /* bitsize */
3745 + FALSE, /* pc_relative */
3746 + 0, /* bitpos */
3747 + complain_overflow_dont, /* complain_on_overflow */
3748 + bfd_elf_generic_reloc, /* special_function */
3749 + "R_RISCV_ALIGN", /* name */
3750 + FALSE, /* partial_inplace */
3751 + 0, /* src_mask */
3752 + 0, /* dst_mask */
3753 + TRUE), /* pcrel_offset */
3755 + /* 8-bit PC-relative branch offset. */
3756 + HOWTO (R_RISCV_RVC_BRANCH, /* type */
3757 + 0, /* rightshift */
3758 + 2, /* size */
3759 + 32, /* bitsize */
3760 + TRUE, /* pc_relative */
3761 + 0, /* bitpos */
3762 + complain_overflow_signed, /* complain_on_overflow */
3763 + bfd_elf_generic_reloc, /* special_function */
3764 + "R_RISCV_RVC_BRANCH", /* name */
3765 + FALSE, /* partial_inplace */
3766 + 0, /* src_mask */
3767 + ENCODE_RVC_B_IMM (-1U), /* dst_mask */
3768 + TRUE), /* pcrel_offset */
3770 + /* 11-bit PC-relative jump offset. */
3771 + HOWTO (R_RISCV_RVC_JUMP, /* type */
3772 + 0, /* rightshift */
3773 + 2, /* size */
3774 + 32, /* bitsize */
3775 + TRUE, /* pc_relative */
3776 + 0, /* bitpos */
3777 + complain_overflow_dont, /* complain_on_overflow */
3778 + /* This needs complex overflow
3779 + detection, because the upper 36
3780 + bits must match the PC + 4. */
3781 + bfd_elf_generic_reloc, /* special_function */
3782 + "R_RISCV_RVC_JUMP", /* name */
3783 + FALSE, /* partial_inplace */
3784 + 0, /* src_mask */
3785 + ENCODE_RVC_J_IMM (-1U), /* dst_mask */
3786 + TRUE), /* pcrel_offset */
3788 + /* High 6 bits of 18-bit absolute address. */
3789 + HOWTO (R_RISCV_RVC_LUI, /* type */
3790 + 0, /* rightshift */
3791 + 2, /* size */
3792 + 32, /* bitsize */
3793 + FALSE, /* pc_relative */
3794 + 0, /* bitpos */
3795 + complain_overflow_dont, /* complain_on_overflow */
3796 + bfd_elf_generic_reloc, /* special_function */
3797 + "R_RISCV_RVC_LUI", /* name */
3798 + FALSE, /* partial_inplace */
3799 + 0, /* src_mask */
3800 + ENCODE_RVC_IMM (-1U), /* dst_mask */
3801 + FALSE), /* pcrel_offset */
3803 + /* High 12 bits of 32-bit load or add. */
3804 + HOWTO (R_RISCV_GPREL_I, /* type */
3805 + 0, /* rightshift */
3806 + 2, /* size */
3807 + 32, /* bitsize */
3808 + FALSE, /* pc_relative */
3809 + 0, /* bitpos */
3810 + complain_overflow_dont, /* complain_on_overflow */
3811 + bfd_elf_generic_reloc, /* special_function */
3812 + "R_RISCV_GPREL_I", /* name */
3813 + FALSE, /* partial_inplace */
3814 + 0, /* src_mask */
3815 + ENCODE_ITYPE_IMM (-1U), /* dst_mask */
3816 + FALSE), /* pcrel_offset */
3818 + /* High 12 bits of 32-bit store. */
3819 + HOWTO (R_RISCV_GPREL_S, /* type */
3820 + 0, /* rightshift */
3821 + 2, /* size */
3822 + 32, /* bitsize */
3823 + FALSE, /* pc_relative */
3824 + 0, /* bitpos */
3825 + complain_overflow_dont, /* complain_on_overflow */
3826 + bfd_elf_generic_reloc, /* special_function */
3827 + "R_RISCV_GPREL_S", /* name */
3828 + FALSE, /* partial_inplace */
3829 + 0, /* src_mask */
3830 + ENCODE_STYPE_IMM (-1U), /* dst_mask */
3831 + FALSE), /* pcrel_offset */
3834 +/* A mapping from BFD reloc types to RISC-V ELF reloc types. */
3836 +struct elf_reloc_map {
3837 + bfd_reloc_code_real_type bfd_val;
3838 + enum elf_riscv_reloc_type elf_val;
3841 +static const struct elf_reloc_map riscv_reloc_map[] =
3843 + { BFD_RELOC_NONE, R_RISCV_NONE },
3844 + { BFD_RELOC_32, R_RISCV_32 },
3845 + { BFD_RELOC_64, R_RISCV_64 },
3846 + { BFD_RELOC_RISCV_ADD8, R_RISCV_ADD8 },
3847 + { BFD_RELOC_RISCV_ADD16, R_RISCV_ADD16 },
3848 + { BFD_RELOC_RISCV_ADD32, R_RISCV_ADD32 },
3849 + { BFD_RELOC_RISCV_ADD64, R_RISCV_ADD64 },
3850 + { BFD_RELOC_RISCV_SUB8, R_RISCV_SUB8 },
3851 + { BFD_RELOC_RISCV_SUB16, R_RISCV_SUB16 },
3852 + { BFD_RELOC_RISCV_SUB32, R_RISCV_SUB32 },
3853 + { BFD_RELOC_RISCV_SUB64, R_RISCV_SUB64 },
3854 + { BFD_RELOC_CTOR, R_RISCV_64 },
3855 + { BFD_RELOC_12_PCREL, R_RISCV_BRANCH },
3856 + { BFD_RELOC_RISCV_HI20, R_RISCV_HI20 },
3857 + { BFD_RELOC_RISCV_LO12_I, R_RISCV_LO12_I },
3858 + { BFD_RELOC_RISCV_LO12_S, R_RISCV_LO12_S },
3859 + { BFD_RELOC_RISCV_PCREL_LO12_I, R_RISCV_PCREL_LO12_I },
3860 + { BFD_RELOC_RISCV_PCREL_LO12_S, R_RISCV_PCREL_LO12_S },
3861 + { BFD_RELOC_RISCV_CALL, R_RISCV_CALL },
3862 + { BFD_RELOC_RISCV_CALL_PLT, R_RISCV_CALL_PLT },
3863 + { BFD_RELOC_RISCV_PCREL_HI20, R_RISCV_PCREL_HI20 },
3864 + { BFD_RELOC_RISCV_JMP, R_RISCV_JAL },
3865 + { BFD_RELOC_RISCV_GOT_HI20, R_RISCV_GOT_HI20 },
3866 + { BFD_RELOC_RISCV_TLS_DTPMOD32, R_RISCV_TLS_DTPMOD32 },
3867 + { BFD_RELOC_RISCV_TLS_DTPREL32, R_RISCV_TLS_DTPREL32 },
3868 + { BFD_RELOC_RISCV_TLS_DTPMOD64, R_RISCV_TLS_DTPMOD64 },
3869 + { BFD_RELOC_RISCV_TLS_DTPREL64, R_RISCV_TLS_DTPREL64 },
3870 + { BFD_RELOC_RISCV_TLS_TPREL32, R_RISCV_TLS_TPREL32 },
3871 + { BFD_RELOC_RISCV_TLS_TPREL64, R_RISCV_TLS_TPREL64 },
3872 + { BFD_RELOC_RISCV_TPREL_HI20, R_RISCV_TPREL_HI20 },
3873 + { BFD_RELOC_RISCV_TPREL_ADD, R_RISCV_TPREL_ADD },
3874 + { BFD_RELOC_RISCV_TPREL_LO12_S, R_RISCV_TPREL_LO12_S },
3875 + { BFD_RELOC_RISCV_TPREL_LO12_I, R_RISCV_TPREL_LO12_I },
3876 + { BFD_RELOC_RISCV_TLS_GOT_HI20, R_RISCV_TLS_GOT_HI20 },
3877 + { BFD_RELOC_RISCV_TLS_GD_HI20, R_RISCV_TLS_GD_HI20 },
3878 + { BFD_RELOC_RISCV_ALIGN, R_RISCV_ALIGN },
3879 + { BFD_RELOC_RISCV_RVC_BRANCH, R_RISCV_RVC_BRANCH },
3880 + { BFD_RELOC_RISCV_RVC_JUMP, R_RISCV_RVC_JUMP },
3881 + { BFD_RELOC_RISCV_RVC_LUI, R_RISCV_RVC_LUI },
3882 + { BFD_RELOC_RISCV_GPREL_I, R_RISCV_GPREL_I },
3883 + { BFD_RELOC_RISCV_GPREL_S, R_RISCV_GPREL_S },
3886 +/* Given a BFD reloc type, return a howto structure. */
3888 +reloc_howto_type *
3889 +riscv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3890 + bfd_reloc_code_real_type code)
3892 + unsigned int i;
3894 + for (i = 0; i < ARRAY_SIZE (riscv_reloc_map); i++)
3895 + if (riscv_reloc_map[i].bfd_val == code)
3896 + return &howto_table[(int) riscv_reloc_map[i].elf_val];
3898 + bfd_set_error (bfd_error_bad_value);
3899 + return NULL;
3902 +reloc_howto_type *
3903 +riscv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
3905 + unsigned int i;
3907 + for (i = 0; i < ARRAY_SIZE (howto_table); i++)
3908 + if (howto_table[i].name && strcasecmp (howto_table[i].name, r_name) == 0)
3909 + return &howto_table[i];
3911 + return NULL;
3914 +reloc_howto_type *
3915 +riscv_elf_rtype_to_howto (unsigned int r_type)
3917 + if (r_type >= ARRAY_SIZE (howto_table))
3919 + (*_bfd_error_handler) (_("unrecognized relocation (0x%x)"), r_type);
3920 + bfd_set_error (bfd_error_bad_value);
3921 + return NULL;
3923 + return &howto_table[r_type];
3925 diff -urN empty/bfd/elfxx-riscv.h binutils-2.26.1/bfd/elfxx-riscv.h
3926 --- empty/bfd/elfxx-riscv.h 1970-01-01 08:00:00.000000000 +0800
3927 +++ binutils-2.26.1/bfd/elfxx-riscv.h 2016-04-03 10:12:57.122276559 +0800
3928 @@ -0,0 +1,33 @@
3929 +/* RISC-V ELF specific backend routines.
3930 + Copyright 2011-2015 Free Software Foundation, Inc.
3932 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
3933 + Based on MIPS target.
3935 + This file is part of BFD, the Binary File Descriptor library.
3937 + This program is free software; you can redistribute it and/or modify
3938 + it under the terms of the GNU General Public License as published by
3939 + the Free Software Foundation; either version 3 of the License, or
3940 + (at your option) any later version.
3942 + This program is distributed in the hope that it will be useful,
3943 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3944 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3945 + GNU General Public License for more details.
3947 + You should have received a copy of the GNU General Public License
3948 + along with this program; see the file COPYING3. If not,
3949 + see <http://www.gnu.org/licenses/>. */
3951 +#include "elf/common.h"
3952 +#include "elf/internal.h"
3954 +extern reloc_howto_type *
3955 +riscv_reloc_name_lookup (bfd *, const char *);
3957 +extern reloc_howto_type *
3958 +riscv_reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
3960 +extern reloc_howto_type *
3961 +riscv_elf_rtype_to_howto (unsigned int r_type);
3962 diff -urN empty/gas/config/tc-riscv.c binutils-2.26.1/gas/config/tc-riscv.c
3963 --- empty/gas/config/tc-riscv.c 1970-01-01 08:00:00.000000000 +0800
3964 +++ binutils-2.26.1/gas/config/tc-riscv.c 2016-04-09 10:50:33.576657106 +0800
3965 @@ -0,0 +1,2434 @@
3966 +/* tc-riscv.c -- RISC-V assembler
3967 + Copyright 2011-2015 Free Software Foundation, Inc.
3969 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
3970 + Based on MIPS target.
3972 + This file is part of GAS.
3974 + GAS is free software; you can redistribute it and/or modify
3975 + it under the terms of the GNU General Public License as published by
3976 + the Free Software Foundation; either version 3, or (at your option)
3977 + any later version.
3979 + GAS is distributed in the hope that it will be useful,
3980 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3981 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3982 + GNU General Public License for more details.
3984 + You should have received a copy of the GNU General Public License
3985 + along with this program; see the file COPYING3. If not,
3986 + see <http://www.gnu.org/licenses/>. */
3988 +#include "as.h"
3989 +#include "config.h"
3990 +#include "subsegs.h"
3991 +#include "safe-ctype.h"
3993 +#include "itbl-ops.h"
3994 +#include "dwarf2dbg.h"
3995 +#include "dw2gencfi.h"
3997 +#include "elf/riscv.h"
3998 +#include "opcode/riscv.h"
4000 +#include <execinfo.h>
4001 +#include <stdint.h>
4003 +/* Information about an instruction, including its format, operands
4004 + and fixups. */
4005 +struct riscv_cl_insn
4007 + /* The opcode's entry in riscv_opcodes. */
4008 + const struct riscv_opcode *insn_mo;
4010 + /* The encoded instruction bits. */
4011 + insn_t insn_opcode;
4013 + /* The frag that contains the instruction. */
4014 + struct frag *frag;
4016 + /* The offset into FRAG of the first instruction byte. */
4017 + long where;
4019 + /* The relocs associated with the instruction, if any. */
4020 + fixS *fixp;
4023 +/* The default architecture. */
4024 +#ifndef DEFAULT_ARCH
4025 +#define DEFAULT_ARCH "riscv64"
4026 +#endif
4027 +static const char default_arch[] = DEFAULT_ARCH;
4029 +unsigned xlen = 0; /* width of an x-register */
4030 +#define LOAD_ADDRESS_INSN (xlen == 64 ? "ld" : "lw")
4031 +#define ADD32_INSN (xlen == 64 ? "addiw" : "addi")
4033 +static unsigned elf_flags = 0;
4035 +/* This is the set of options which the .option pseudo-op may modify. */
4037 +struct riscv_set_options
4039 + int pic; /* Generate position-independent code. */
4040 + int rvc; /* Generate RVC code. */
4043 +static struct riscv_set_options riscv_opts =
4045 + 0, /* pic */
4046 + 0, /* rvc */
4049 +static void
4050 +riscv_set_rvc (bfd_boolean rvc_value)
4052 + if (rvc_value)
4053 + elf_flags |= EF_RISCV_RVC;
4055 + riscv_opts.rvc = rvc_value;
4058 +struct riscv_subset
4060 + const char *name;
4061 + int version_major;
4062 + int version_minor;
4064 + struct riscv_subset *next;
4067 +static struct riscv_subset *riscv_subsets;
4069 +static bfd_boolean
4070 +riscv_subset_supports (const char *feature)
4072 + struct riscv_subset *s;
4073 + char *p;
4074 + unsigned xlen_required = strtoul (feature, &p, 10);
4076 + if (xlen_required && xlen != xlen_required)
4077 + return FALSE;
4079 + for (s = riscv_subsets; s != NULL; s = s->next)
4080 + if (strcasecmp (s->name, p) == 0)
4081 + /* FIXME: once we support version numbers:
4082 + return major == s->version_major && minor <= s->version_minor; */
4083 + return TRUE;
4085 + return FALSE;
4088 +static void
4089 +riscv_add_subset (const char *subset)
4091 + struct riscv_subset *s = xmalloc (sizeof *s);
4092 + s->name = xstrdup (subset);
4093 + s->version_major = 2;
4094 + s->version_minor = 0;
4095 + s->next = riscv_subsets;
4096 + riscv_subsets = s;
4099 +/* Set which ISA and extensions are available. Formally, ISA strings must
4100 + begin with RV32 or RV64, but we allow the prefix to be omitted.
4102 + FIXME: Version numbers are not supported yet. */
4103 +static void
4104 +riscv_set_arch (const char *arg)
4106 + char *uppercase = xstrdup (arg);
4107 + char *p = uppercase;
4108 + const char *all_subsets = "IMAFDC";
4109 + const char *extension = NULL;
4110 + int rvc = 0;
4111 + int i;
4113 + for (i = 0; uppercase[i]; i++)
4114 + uppercase[i] = TOUPPER (uppercase[i]);
4116 + if (strncmp (p, "RV32", 4) == 0)
4118 + xlen = 32;
4119 + p += 4;
4121 + else if (strncmp (p, "RV64", 4) == 0)
4123 + xlen = 64;
4124 + p += 4;
4126 + else if (strncmp (p, "RV", 2) == 0)
4127 + p += 2;
4129 + switch (*p)
4131 + case 'I':
4132 + break;
4134 + case 'G':
4135 + p++;
4136 + /* Fall through. */
4138 + case '\0':
4139 + for (i = 0; all_subsets[i] != '\0'; i++)
4141 + const char subset[] = {all_subsets[i], '\0'};
4142 + riscv_add_subset (subset);
4144 + break;
4146 + default:
4147 + as_fatal ("`I' must be the first ISA subset name specified (got %c)",
4148 + *p);
4151 + while (*p)
4153 + if (*p == 'X')
4155 + char *subset = xstrdup (p), *q = subset;
4157 + while (*++q != '\0' && *q != '_')
4159 + *q = '\0';
4161 + if (extension)
4162 + as_fatal ("only one eXtension is supported (found %s and %s)",
4163 + extension, subset);
4164 + extension = subset;
4165 + riscv_add_subset (subset);
4166 + p += strlen (subset);
4167 + free (subset);
4169 + else if (*p == '_')
4170 + p++;
4171 + else if ((all_subsets = strchr (all_subsets, *p)) != NULL)
4173 + const char subset[] = {*p, 0};
4174 + riscv_add_subset (subset);
4175 + if (*p == 'C')
4176 + rvc = 1;
4177 + all_subsets++;
4178 + p++;
4180 + else
4181 + as_fatal ("unsupported ISA subset %c", *p);
4184 + if (rvc)
4185 + /* Override -m[no-]rvc setting if C was explicitly listed. */
4186 + riscv_set_rvc (TRUE);
4187 + else
4188 + /* Add RVC anyway. -m[no-]rvc toggles its availability. */
4189 + riscv_add_subset ("C");
4191 + free (uppercase);
4194 +/* handle of the OPCODE hash table */
4195 +static struct hash_control *op_hash = NULL;
4197 +/* This array holds the chars that always start a comment. If the
4198 + pre-processor is disabled, these aren't very useful */
4199 +const char comment_chars[] = "#";
4201 +/* This array holds the chars that only start a comment at the beginning of
4202 + a line. If the line seems to have the form '# 123 filename'
4203 + .line and .file directives will appear in the pre-processed output */
4204 +/* Note that input_file.c hand checks for '#' at the beginning of the
4205 + first line of the input file. This is because the compiler outputs
4206 + #NO_APP at the beginning of its output. */
4207 +/* Also note that C style comments are always supported. */
4208 +const char line_comment_chars[] = "#";
4210 +/* This array holds machine specific line separator characters. */
4211 +const char line_separator_chars[] = ";";
4213 +/* Chars that can be used to separate mant from exp in floating point nums */
4214 +const char EXP_CHARS[] = "eE";
4216 +/* Chars that mean this number is a floating point constant */
4217 +/* As in 0f12.456 */
4218 +/* or 0d1.2345e12 */
4219 +const char FLT_CHARS[] = "rRsSfFdDxXpP";
4221 +/* Macros for encoding relaxation state for RVC branches and far jumps. */
4222 +#define RELAX_BRANCH_ENCODE(uncond, rvc, length) \
4223 + ((relax_substateT) \
4224 + (0xc0000000 \
4225 + | ((uncond) ? 1 : 0) \
4226 + | ((rvc) ? 2 : 0) \
4227 + | ((length) << 2)))
4228 +#define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
4229 +#define RELAX_BRANCH_LENGTH(i) (((i) >> 2) & 0xF)
4230 +#define RELAX_BRANCH_RVC(i) (((i) & 2) != 0)
4231 +#define RELAX_BRANCH_UNCOND(i) (((i) & 1) != 0)
4233 +/* Is the given value a sign-extended 32-bit value? */
4234 +#define IS_SEXT_32BIT_NUM(x) \
4235 + (((x) &~ (offsetT) 0x7fffffff) == 0 \
4236 + || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
4238 +/* Is the given value a zero-extended 32-bit value? Or a negated one? */
4239 +#define IS_ZEXT_32BIT_NUM(x) \
4240 + (((x) &~ (offsetT) 0xffffffff) == 0 \
4241 + || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
4243 +/* Change INSN's opcode so that the operand given by FIELD has value VALUE.
4244 + INSN is a riscv_cl_insn structure and VALUE is evaluated exactly once. */
4245 +#define INSERT_OPERAND(FIELD, INSN, VALUE) \
4246 + INSERT_BITS ((INSN).insn_opcode, VALUE, OP_MASK_##FIELD, OP_SH_##FIELD)
4248 +/* Determine if an instruction matches an opcode. */
4249 +#define OPCODE_MATCHES(OPCODE, OP) \
4250 + (((OPCODE) & MASK_##OP) == MATCH_##OP)
4252 +static char *expr_end;
4254 +/* The default target format to use. */
4256 +const char *
4257 +riscv_target_format (void)
4259 + return xlen == 64 ? "elf64-littleriscv" : "elf32-littleriscv";
4262 +/* Return the length of instruction INSN. */
4264 +static inline unsigned int
4265 +insn_length (const struct riscv_cl_insn *insn)
4267 + return riscv_insn_length (insn->insn_opcode);
4270 +/* Initialise INSN from opcode entry MO. Leave its position unspecified. */
4272 +static void
4273 +create_insn (struct riscv_cl_insn *insn, const struct riscv_opcode *mo)
4275 + insn->insn_mo = mo;
4276 + insn->insn_opcode = mo->match;
4277 + insn->frag = NULL;
4278 + insn->where = 0;
4279 + insn->fixp = NULL;
4282 +/* Install INSN at the location specified by its "frag" and "where" fields. */
4284 +static void
4285 +install_insn (const struct riscv_cl_insn *insn)
4287 + char *f = insn->frag->fr_literal + insn->where;
4288 + md_number_to_chars (f, insn->insn_opcode, insn_length (insn));
4291 +/* Move INSN to offset WHERE in FRAG. Adjust the fixups accordingly
4292 + and install the opcode in the new location. */
4294 +static void
4295 +move_insn (struct riscv_cl_insn *insn, fragS *frag, long where)
4297 + insn->frag = frag;
4298 + insn->where = where;
4299 + if (insn->fixp != NULL)
4301 + insn->fixp->fx_frag = frag;
4302 + insn->fixp->fx_where = where;
4304 + install_insn (insn);
4307 +/* Add INSN to the end of the output. */
4309 +static void
4310 +add_fixed_insn (struct riscv_cl_insn *insn)
4312 + char *f = frag_more (insn_length (insn));
4313 + move_insn (insn, frag_now, f - frag_now->fr_literal);
4316 +static void
4317 +add_relaxed_insn (struct riscv_cl_insn *insn, int max_chars, int var,
4318 + relax_substateT subtype, symbolS *symbol, offsetT offset)
4320 + frag_grow (max_chars);
4321 + move_insn (insn, frag_now, frag_more (0) - frag_now->fr_literal);
4322 + frag_var (rs_machine_dependent, max_chars, var,
4323 + subtype, symbol, offset, NULL);
4326 +/* Compute the length of a branch sequence, and adjust the stored length
4327 + accordingly. If FRAGP is NULL, the worst-case length is returned. */
4329 +static int
4330 +relaxed_branch_length (fragS *fragp, asection *sec, int update)
4332 + int jump, rvc, length = 8;
4334 + if (!fragp)
4335 + return length;
4337 + jump = RELAX_BRANCH_UNCOND (fragp->fr_subtype);
4338 + rvc = RELAX_BRANCH_RVC (fragp->fr_subtype);
4339 + length = RELAX_BRANCH_LENGTH (fragp->fr_subtype);
4341 + /* Assume jumps are in range; the linker will catch any that aren't. */
4342 + length = jump ? 4 : 8;
4344 + if (fragp->fr_symbol != NULL
4345 + && S_IS_DEFINED (fragp->fr_symbol)
4346 + && sec == S_GET_SEGMENT (fragp->fr_symbol))
4348 + offsetT val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset;
4349 + bfd_vma rvc_range = jump ? RVC_JUMP_REACH : RVC_BRANCH_REACH;
4350 + val -= fragp->fr_address + fragp->fr_fix;
4352 + if (rvc && (bfd_vma)(val + rvc_range/2) < rvc_range)
4353 + length = 2;
4354 + else if ((bfd_vma)(val + RISCV_BRANCH_REACH/2) < RISCV_BRANCH_REACH)
4355 + length = 4;
4356 + else if (!jump && rvc)
4357 + length = 6;
4360 + if (update)
4361 + fragp->fr_subtype = RELAX_BRANCH_ENCODE (jump, rvc, length);
4363 + return length;
4366 +struct regname {
4367 + const char *name;
4368 + unsigned int num;
4371 +enum reg_class {
4372 + RCLASS_GPR,
4373 + RCLASS_FPR,
4374 + RCLASS_CSR,
4375 + RCLASS_MAX
4378 +static struct hash_control *reg_names_hash = NULL;
4380 +#define ENCODE_REG_HASH(cls, n) (void *)(uintptr_t)((n) * RCLASS_MAX + (cls) + 1)
4381 +#define DECODE_REG_CLASS(hash) (((uintptr_t)(hash) - 1) % RCLASS_MAX)
4382 +#define DECODE_REG_NUM(hash) (((uintptr_t)(hash) - 1) / RCLASS_MAX)
4384 +static void
4385 +hash_reg_name (enum reg_class class, const char *name, unsigned n)
4387 + void *hash = ENCODE_REG_HASH (class, n);
4388 + const char *retval = hash_insert (reg_names_hash, name, hash);
4390 + if (retval != NULL)
4391 + as_fatal (_("internal error: can't hash `%s': %s"), name, retval);
4394 +static void
4395 +hash_reg_names (enum reg_class class, const char * const names[], unsigned n)
4397 + unsigned i;
4399 + for (i = 0; i < n; i++)
4400 + hash_reg_name (class, names[i], i);
4403 +static unsigned int
4404 +reg_lookup_internal (const char *s, enum reg_class class)
4406 + struct regname *r = (struct regname *) hash_find (reg_names_hash, s);
4407 + if (r == NULL || DECODE_REG_CLASS (r) != class)
4408 + return -1;
4409 + return DECODE_REG_NUM (r);
4412 +static int
4413 +reg_lookup (char **s, enum reg_class class, unsigned int *regnop)
4415 + char *e;
4416 + char save_c;
4417 + int reg = -1;
4419 + /* Find end of name. */
4420 + e = *s;
4421 + if (is_name_beginner (*e))
4422 + ++e;
4423 + while (is_part_of_name (*e))
4424 + ++e;
4426 + /* Terminate name. */
4427 + save_c = *e;
4428 + *e = '\0';
4430 + /* Look for the register. Advance to next token if one was recognized. */
4431 + if ((reg = reg_lookup_internal (*s, class)) >= 0)
4432 + *s = e;
4434 + *e = save_c;
4435 + if (regnop)
4436 + *regnop = reg;
4437 + return reg >= 0;
4440 +static int
4441 +arg_lookup (char **s, const char *const *array, size_t size, unsigned *regnop)
4443 + const char *p = strchr (*s, ',');
4444 + size_t i, len = p ? (size_t)(p - *s) : strlen (*s);
4446 + for (i = 0; i < size; i++)
4447 + if (array[i] != NULL && strncmp (array[i], *s, len) == 0)
4449 + *regnop = i;
4450 + *s += len;
4451 + return 1;
4454 + return 0;
4457 +/* For consistency checking, verify that all bits are specified either
4458 + by the match/mask part of the instruction definition, or by the
4459 + operand list. */
4460 +static int
4461 +validate_riscv_insn (const struct riscv_opcode *opc)
4463 + const char *p = opc->args;
4464 + char c;
4465 + insn_t used_bits = opc->mask;
4466 + int insn_width = 8 * riscv_insn_length (opc->match);
4467 + insn_t required_bits = ~0ULL >> (64 - insn_width);
4469 + if ((used_bits & opc->match) != (opc->match & required_bits))
4471 + as_bad (_("internal: bad RISC-V opcode (mask error): %s %s"),
4472 + opc->name, opc->args);
4473 + return 0;
4476 +#define USE_BITS(mask,shift) (used_bits |= ((insn_t)(mask) << (shift)))
4477 + while (*p)
4478 + switch (c = *p++)
4480 + /* Xcustom */
4481 + case '^':
4482 + switch (c = *p++)
4484 + case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
4485 + case 's': USE_BITS (OP_MASK_RS1, OP_SH_RS1); break;
4486 + case 't': USE_BITS (OP_MASK_RS2, OP_SH_RS2); break;
4487 + case 'j': USE_BITS (OP_MASK_CUSTOM_IMM, OP_SH_CUSTOM_IMM); break;
4489 + break;
4490 + case 'C': /* RVC */
4491 + switch (c = *p++)
4493 + case 'a': used_bits |= ENCODE_RVC_J_IMM(-1U); break;
4494 + case 'c': break; /* RS1, constrained to equal sp */
4495 + case 'i': used_bits |= ENCODE_RVC_SIMM3(-1U); break;
4496 + case 'j': used_bits |= ENCODE_RVC_IMM(-1U); break;
4497 + case 'k': used_bits |= ENCODE_RVC_LW_IMM(-1U); break;
4498 + case 'l': used_bits |= ENCODE_RVC_LD_IMM(-1U); break;
4499 + case 'm': used_bits |= ENCODE_RVC_LWSP_IMM(-1U); break;
4500 + case 'n': used_bits |= ENCODE_RVC_LDSP_IMM(-1U); break;
4501 + case 'p': used_bits |= ENCODE_RVC_B_IMM(-1U); break;
4502 + case 's': USE_BITS (OP_MASK_CRS1S, OP_SH_CRS1S); break;
4503 + case 't': USE_BITS (OP_MASK_CRS2S, OP_SH_CRS2S); break;
4504 + case 'u': used_bits |= ENCODE_RVC_IMM(-1U); break;
4505 + case 'v': used_bits |= ENCODE_RVC_IMM(-1U); break;
4506 + case 'w': break; /* RS1S, constrained to equal RD */
4507 + case 'x': break; /* RS2S, constrained to equal RD */
4508 + case 'K': used_bits |= ENCODE_RVC_ADDI4SPN_IMM(-1U); break;
4509 + case 'L': used_bits |= ENCODE_RVC_ADDI16SP_IMM(-1U); break;
4510 + case 'M': used_bits |= ENCODE_RVC_SWSP_IMM(-1U); break;
4511 + case 'N': used_bits |= ENCODE_RVC_SDSP_IMM(-1U); break;
4512 + case 'U': break; /* RS1, constrained to equal RD */
4513 + case 'V': USE_BITS (OP_MASK_CRS2, OP_SH_CRS2); break;
4514 + case '<': used_bits |= ENCODE_RVC_IMM(-1U); break;
4515 + case '>': used_bits |= ENCODE_RVC_IMM(-1U); break;
4516 + case 'T': USE_BITS (OP_MASK_CRS2, OP_SH_CRS2); break;
4517 + case 'D': USE_BITS (OP_MASK_CRS2S, OP_SH_CRS2S); break;
4518 + default:
4519 + as_bad (_("internal: bad RISC-V opcode (unknown operand type `C%c'): %s %s"),
4520 + c, opc->name, opc->args);
4521 + return 0;
4523 + break;
4524 + case ',': break;
4525 + case '(': break;
4526 + case ')': break;
4527 + case '<': USE_BITS (OP_MASK_SHAMTW, OP_SH_SHAMTW); break;
4528 + case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
4529 + case 'A': break;
4530 + case 'D': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
4531 + case 'Z': USE_BITS (OP_MASK_RS1, OP_SH_RS1); break;
4532 + case 'E': USE_BITS (OP_MASK_CSR, OP_SH_CSR); break;
4533 + case 'I': break;
4534 + case 'R': USE_BITS (OP_MASK_RS3, OP_SH_RS3); break;
4535 + case 'S': USE_BITS (OP_MASK_RS1, OP_SH_RS1); break;
4536 + case 'U': USE_BITS (OP_MASK_RS1, OP_SH_RS1); /* fallthru */
4537 + case 'T': USE_BITS (OP_MASK_RS2, OP_SH_RS2); break;
4538 + case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
4539 + case 'm': USE_BITS (OP_MASK_RM, OP_SH_RM); break;
4540 + case 's': USE_BITS (OP_MASK_RS1, OP_SH_RS1); break;
4541 + case 't': USE_BITS (OP_MASK_RS2, OP_SH_RS2); break;
4542 + case 'P': USE_BITS (OP_MASK_PRED, OP_SH_PRED); break;
4543 + case 'Q': USE_BITS (OP_MASK_SUCC, OP_SH_SUCC); break;
4544 + case 'o':
4545 + case 'j': used_bits |= ENCODE_ITYPE_IMM(-1U); break;
4546 + case 'a': used_bits |= ENCODE_UJTYPE_IMM(-1U); break;
4547 + case 'p': used_bits |= ENCODE_SBTYPE_IMM(-1U); break;
4548 + case 'q': used_bits |= ENCODE_STYPE_IMM(-1U); break;
4549 + case 'u': used_bits |= ENCODE_UTYPE_IMM(-1U); break;
4550 + case '[': break;
4551 + case ']': break;
4552 + case '0': break;
4553 + default:
4554 + as_bad (_("internal: bad RISC-V opcode (unknown operand type `%c'): %s %s"),
4555 + c, opc->name, opc->args);
4556 + return 0;
4558 +#undef USE_BITS
4559 + if (used_bits != required_bits)
4561 + as_bad (_("internal: bad RISC-V opcode (bits 0x%lx undefined): %s %s"),
4562 + ~(long)(used_bits & required_bits), opc->name, opc->args);
4563 + return 0;
4565 + return 1;
4568 +struct percent_op_match
4570 + const char *str;
4571 + bfd_reloc_code_real_type reloc;
4574 +/* This function is called once, at assembler startup time. It should set up
4575 + all the tables, etc. that the MD part of the assembler will need. */
4577 +void
4578 +md_begin (void)
4580 + const char *retval = NULL;
4581 + int i = 0;
4583 + if (! bfd_set_arch_mach (stdoutput, bfd_arch_riscv, 0))
4584 + as_warn (_("Could not set architecture and machine"));
4586 + op_hash = hash_new ();
4588 + for (i = 0; i < NUMOPCODES;)
4590 + const char *name = riscv_opcodes[i].name;
4592 + retval = hash_insert (op_hash, name, (void *) &riscv_opcodes[i]);
4594 + if (retval != NULL)
4596 + fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
4597 + riscv_opcodes[i].name, retval);
4598 + /* Probably a memory allocation problem? Give up now. */
4599 + as_fatal (_("Broken assembler. No assembly attempted."));
4601 + do
4603 + if (riscv_opcodes[i].pinfo != INSN_MACRO)
4605 + if (!validate_riscv_insn (&riscv_opcodes[i]))
4606 + as_fatal (_("Broken assembler. No assembly attempted."));
4608 + ++i;
4610 + while ((i < NUMOPCODES) && !strcmp (riscv_opcodes[i].name, name));
4613 + reg_names_hash = hash_new ();
4614 + hash_reg_names (RCLASS_GPR, riscv_gpr_names_numeric, NGPR);
4615 + hash_reg_names (RCLASS_GPR, riscv_gpr_names_abi, NGPR);
4616 + hash_reg_names (RCLASS_FPR, riscv_fpr_names_numeric, NFPR);
4617 + hash_reg_names (RCLASS_FPR, riscv_fpr_names_abi, NFPR);
4619 +#define DECLARE_CSR(name, num) hash_reg_name (RCLASS_CSR, #name, num);
4620 +#include "opcode/riscv-opc.h"
4621 +#undef DECLARE_CSR
4623 + /* Set the default alignment for the text section. */
4624 + record_alignment (text_section, riscv_opts.rvc ? 1 : 2);
4627 +/* Output an instruction. IP is the instruction information.
4628 + ADDRESS_EXPR is an operand of the instruction to be used with
4629 + RELOC_TYPE. */
4631 +static void
4632 +append_insn (struct riscv_cl_insn *ip, expressionS *address_expr,
4633 + bfd_reloc_code_real_type reloc_type)
4635 +#ifdef OBJ_ELF
4636 + dwarf2_emit_insn (0);
4637 +#endif
4639 + if (reloc_type != BFD_RELOC_UNUSED)
4641 + reloc_howto_type *howto;
4643 + gas_assert(address_expr);
4644 + if (reloc_type == BFD_RELOC_12_PCREL
4645 + || reloc_type == BFD_RELOC_RISCV_JMP)
4647 + int j = reloc_type == BFD_RELOC_RISCV_JMP;
4648 + int best_case = riscv_insn_length (ip->insn_opcode);
4649 + int worst_case = relaxed_branch_length (NULL, NULL, 0);
4650 + add_relaxed_insn (ip, worst_case, best_case,
4651 + RELAX_BRANCH_ENCODE (j, best_case == 2, worst_case),
4652 + address_expr->X_add_symbol,
4653 + address_expr->X_add_number);
4654 + return;
4656 + else if (address_expr->X_op == O_constant)
4658 + switch (reloc_type)
4660 + case BFD_RELOC_32:
4661 + ip->insn_opcode |= address_expr->X_add_number;
4662 + goto append;
4664 + case BFD_RELOC_RISCV_HI20:
4666 + insn_t imm = RISCV_CONST_HIGH_PART (address_expr->X_add_number);
4667 + ip->insn_opcode |= ENCODE_UTYPE_IMM (imm);
4668 + goto append;
4671 + case BFD_RELOC_RISCV_LO12_S:
4672 + ip->insn_opcode |= ENCODE_STYPE_IMM (address_expr->X_add_number);
4673 + goto append;
4675 + case BFD_RELOC_RISCV_LO12_I:
4676 + ip->insn_opcode |= ENCODE_ITYPE_IMM (address_expr->X_add_number);
4677 + goto append;
4679 + default:
4680 + break;
4684 + howto = bfd_reloc_type_lookup (stdoutput, reloc_type);
4685 + if (howto == NULL)
4686 + as_bad (_("Unsupported RISC-V relocation number %d"), reloc_type);
4688 + ip->fixp = fix_new_exp (ip->frag, ip->where,
4689 + bfd_get_reloc_size (howto),
4690 + address_expr, FALSE, reloc_type);
4693 +append:
4694 + add_fixed_insn (ip);
4695 + install_insn (ip);
4698 +/* Build an instruction created by a macro expansion. This is passed
4699 + a pointer to the count of instructions created so far, an
4700 + expression, the name of the instruction to build, an operand format
4701 + string, and corresponding arguments. */
4703 +static void
4704 +macro_build (expressionS *ep, const char *name, const char *fmt, ...)
4706 + const struct riscv_opcode *mo;
4707 + struct riscv_cl_insn insn;
4708 + bfd_reloc_code_real_type r;
4709 + va_list args;
4711 + va_start (args, fmt);
4713 + r = BFD_RELOC_UNUSED;
4714 + mo = (struct riscv_opcode *) hash_find (op_hash, name);
4715 + gas_assert (mo);
4717 + /* Find a non-RVC variant of the instruction. */
4718 + while (riscv_insn_length (mo->match) < 4)
4719 + mo++;
4720 + gas_assert (strcmp (name, mo->name) == 0);
4722 + create_insn (&insn, mo);
4723 + for (;;)
4725 + switch (*fmt++)
4727 + case 'd':
4728 + INSERT_OPERAND (RD, insn, va_arg (args, int));
4729 + continue;
4731 + case 's':
4732 + INSERT_OPERAND (RS1, insn, va_arg (args, int));
4733 + continue;
4735 + case 't':
4736 + INSERT_OPERAND (RS2, insn, va_arg (args, int));
4737 + continue;
4739 + case '>':
4740 + INSERT_OPERAND (SHAMT, insn, va_arg (args, int));
4741 + continue;
4743 + case 'j':
4744 + case 'u':
4745 + case 'q':
4746 + gas_assert (ep != NULL);
4747 + r = va_arg (args, int);
4748 + continue;
4750 + case '\0':
4751 + break;
4752 + case ',':
4753 + continue;
4754 + default:
4755 + as_fatal (_("internal error: invalid macro"));
4757 + break;
4759 + va_end (args);
4760 + gas_assert (r == BFD_RELOC_UNUSED ? ep == NULL : ep != NULL);
4762 + append_insn (&insn, ep, r);
4765 +/* Sign-extend 32-bit mode constants that have bit 31 set and all higher bits
4766 + unset. */
4767 +static void
4768 +normalize_constant_expr (expressionS *ex)
4770 + if (xlen > 32)
4771 + return;
4772 + if ((ex->X_op == O_constant || ex->X_op == O_symbol)
4773 + && IS_ZEXT_32BIT_NUM (ex->X_add_number))
4774 + ex->X_add_number = (((ex->X_add_number & 0xffffffff) ^ 0x80000000)
4775 + - 0x80000000);
4778 +/* Warn if an expression is not a constant. */
4780 +static void
4781 +check_absolute_expr (struct riscv_cl_insn *ip, expressionS *ex)
4783 + if (ex->X_op == O_big)
4784 + as_bad (_("unsupported large constant"));
4785 + else if (ex->X_op != O_constant)
4786 + as_bad (_("Instruction %s requires absolute expression"),
4787 + ip->insn_mo->name);
4788 + normalize_constant_expr (ex);
4791 +static symbolS *
4792 +make_internal_label (void)
4794 + return (symbolS *) local_symbol_make (FAKE_LABEL_NAME, now_seg,
4795 + (valueT) frag_now_fix(), frag_now);
4798 +/* Load an entry from the GOT. */
4799 +static void
4800 +pcrel_access (int destreg, int tempreg, expressionS *ep,
4801 + const char *lo_insn, const char *lo_pattern,
4802 + bfd_reloc_code_real_type hi_reloc,
4803 + bfd_reloc_code_real_type lo_reloc)
4805 + expressionS ep2;
4806 + ep2.X_op = O_symbol;
4807 + ep2.X_add_symbol = make_internal_label ();
4808 + ep2.X_add_number = 0;
4810 + macro_build (ep, "auipc", "d,u", tempreg, hi_reloc);
4811 + macro_build (&ep2, lo_insn, lo_pattern, destreg, tempreg, lo_reloc);
4814 +static void
4815 +pcrel_load (int destreg, int tempreg, expressionS *ep, const char *lo_insn,
4816 + bfd_reloc_code_real_type hi_reloc,
4817 + bfd_reloc_code_real_type lo_reloc)
4819 + pcrel_access (destreg, tempreg, ep, lo_insn, "d,s,j", hi_reloc, lo_reloc);
4822 +static void
4823 +pcrel_store (int srcreg, int tempreg, expressionS *ep, const char *lo_insn,
4824 + bfd_reloc_code_real_type hi_reloc,
4825 + bfd_reloc_code_real_type lo_reloc)
4827 + pcrel_access (srcreg, tempreg, ep, lo_insn, "t,s,q", hi_reloc, lo_reloc);
4830 +/* PC-relative function call using AUIPC/JALR, relaxed to JAL. */
4831 +static void
4832 +riscv_call (int destreg, int tempreg, expressionS *ep,
4833 + bfd_reloc_code_real_type reloc)
4835 + macro_build (ep, "auipc", "d,u", tempreg, reloc);
4836 + macro_build (NULL, "jalr", "d,s", destreg, tempreg);
4839 +/* Load an integer constant into a register. */
4841 +static void
4842 +load_const (int reg, expressionS *ep)
4844 + int shift = RISCV_IMM_BITS;
4845 + expressionS upper = *ep, lower = *ep;
4846 + lower.X_add_number = (int32_t) ep->X_add_number << (32-shift) >> (32-shift);
4847 + upper.X_add_number -= lower.X_add_number;
4849 + if (ep->X_op != O_constant)
4851 + as_bad (_("unsupported large constant"));
4852 + return;
4855 + if (xlen > 32 && !IS_SEXT_32BIT_NUM(ep->X_add_number))
4857 + /* Reduce to a signed 32-bit constant using SLLI and ADDI, which
4858 + is not optimal but also not so bad. */
4859 + while (((upper.X_add_number >> shift) & 1) == 0)
4860 + shift++;
4862 + upper.X_add_number = (int64_t) upper.X_add_number >> shift;
4863 + load_const(reg, &upper);
4865 + macro_build (NULL, "slli", "d,s,>", reg, reg, shift);
4866 + if (lower.X_add_number != 0)
4867 + macro_build (&lower, "addi", "d,s,j", reg, reg, BFD_RELOC_RISCV_LO12_I);
4869 + else
4871 + int hi_reg = 0;
4873 + if (upper.X_add_number != 0)
4875 + macro_build (ep, "lui", "d,u", reg, BFD_RELOC_RISCV_HI20);
4876 + hi_reg = reg;
4879 + if (lower.X_add_number != 0 || hi_reg == 0)
4880 + macro_build (ep, ADD32_INSN, "d,s,j", reg, hi_reg,
4881 + BFD_RELOC_RISCV_LO12_I);
4885 +/* Expand RISC-V assembly macros into one or more instructions. */
4886 +static void
4887 +macro (struct riscv_cl_insn *ip, expressionS *imm_expr,
4888 + bfd_reloc_code_real_type *imm_reloc)
4890 + int rd = (ip->insn_opcode >> OP_SH_RD) & OP_MASK_RD;
4891 + int rs1 = (ip->insn_opcode >> OP_SH_RS1) & OP_MASK_RS1;
4892 + int rs2 = (ip->insn_opcode >> OP_SH_RS2) & OP_MASK_RS2;
4893 + int mask = ip->insn_mo->mask;
4895 + switch (mask)
4897 + case M_LI:
4898 + load_const (rd, imm_expr);
4899 + break;
4901 + case M_LA:
4902 + case M_LLA:
4903 + /* Load the address of a symbol into a register. */
4904 + if (!IS_SEXT_32BIT_NUM (imm_expr->X_add_number))
4905 + as_bad(_("offset too large"));
4907 + if (imm_expr->X_op == O_constant)
4908 + load_const (rd, imm_expr);
4909 + else if (riscv_opts.pic && mask == M_LA) /* Global PIC symbol */
4910 + pcrel_load (rd, rd, imm_expr, LOAD_ADDRESS_INSN,
4911 + BFD_RELOC_RISCV_GOT_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4912 + else /* Local PIC symbol, or any non-PIC symbol */
4913 + pcrel_load (rd, rd, imm_expr, "addi",
4914 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4915 + break;
4917 + case M_LA_TLS_GD:
4918 + pcrel_load (rd, rd, imm_expr, "addi",
4919 + BFD_RELOC_RISCV_TLS_GD_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4920 + break;
4922 + case M_LA_TLS_IE:
4923 + pcrel_load (rd, rd, imm_expr, LOAD_ADDRESS_INSN,
4924 + BFD_RELOC_RISCV_TLS_GOT_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4925 + break;
4927 + case M_LB:
4928 + pcrel_load (rd, rd, imm_expr, "lb",
4929 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4930 + break;
4932 + case M_LBU:
4933 + pcrel_load (rd, rd, imm_expr, "lbu",
4934 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4935 + break;
4937 + case M_LH:
4938 + pcrel_load (rd, rd, imm_expr, "lh",
4939 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4940 + break;
4942 + case M_LHU:
4943 + pcrel_load (rd, rd, imm_expr, "lhu",
4944 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4945 + break;
4947 + case M_LW:
4948 + pcrel_load (rd, rd, imm_expr, "lw",
4949 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4950 + break;
4952 + case M_LWU:
4953 + pcrel_load (rd, rd, imm_expr, "lwu",
4954 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4955 + break;
4957 + case M_LD:
4958 + pcrel_load (rd, rd, imm_expr, "ld",
4959 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4960 + break;
4962 + case M_FLW:
4963 + pcrel_load (rd, rs1, imm_expr, "flw",
4964 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4965 + break;
4967 + case M_FLD:
4968 + pcrel_load (rd, rs1, imm_expr, "fld",
4969 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
4970 + break;
4972 + case M_SB:
4973 + pcrel_store (rs2, rs1, imm_expr, "sb",
4974 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_S);
4975 + break;
4977 + case M_SH:
4978 + pcrel_store (rs2, rs1, imm_expr, "sh",
4979 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_S);
4980 + break;
4982 + case M_SW:
4983 + pcrel_store (rs2, rs1, imm_expr, "sw",
4984 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_S);
4985 + break;
4987 + case M_SD:
4988 + pcrel_store (rs2, rs1, imm_expr, "sd",
4989 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_S);
4990 + break;
4992 + case M_FSW:
4993 + pcrel_store (rs2, rs1, imm_expr, "fsw",
4994 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_S);
4995 + break;
4997 + case M_FSD:
4998 + pcrel_store (rs2, rs1, imm_expr, "fsd",
4999 + BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_S);
5000 + break;
5002 + case M_CALL:
5003 + riscv_call (rd, rs1, imm_expr, *imm_reloc);
5004 + break;
5006 + default:
5007 + as_bad (_("Macro %s not implemented"), ip->insn_mo->name);
5008 + break;
5012 +static const struct percent_op_match percent_op_utype[] =
5014 + {"%tprel_hi", BFD_RELOC_RISCV_TPREL_HI20},
5015 + {"%pcrel_hi", BFD_RELOC_RISCV_PCREL_HI20},
5016 + {"%tls_ie_pcrel_hi", BFD_RELOC_RISCV_TLS_GOT_HI20},
5017 + {"%tls_gd_pcrel_hi", BFD_RELOC_RISCV_TLS_GD_HI20},
5018 + {"%hi", BFD_RELOC_RISCV_HI20},
5019 + {0, 0}
5022 +static const struct percent_op_match percent_op_itype[] =
5024 + {"%lo", BFD_RELOC_RISCV_LO12_I},
5025 + {"%tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_I},
5026 + {"%pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_I},
5027 + {0, 0}
5030 +static const struct percent_op_match percent_op_stype[] =
5032 + {"%lo", BFD_RELOC_RISCV_LO12_S},
5033 + {"%tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_S},
5034 + {"%pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_S},
5035 + {0, 0}
5038 +static const struct percent_op_match percent_op_rtype[] =
5040 + {"%tprel_add", BFD_RELOC_RISCV_TPREL_ADD},
5041 + {0, 0}
5044 +/* Return true if *STR points to a relocation operator. When returning true,
5045 + move *STR over the operator and store its relocation code in *RELOC.
5046 + Leave both *STR and *RELOC alone when returning false. */
5048 +static bfd_boolean
5049 +parse_relocation (char **str, bfd_reloc_code_real_type *reloc,
5050 + const struct percent_op_match *percent_op)
5052 + for ( ; percent_op->str; percent_op++)
5053 + if (strncasecmp (*str, percent_op->str, strlen (percent_op->str)) == 0)
5055 + int len = strlen (percent_op->str);
5057 + if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
5058 + continue;
5060 + *str += strlen (percent_op->str);
5061 + *reloc = percent_op->reloc;
5063 + /* Check whether the output BFD supports this relocation.
5064 + If not, issue an error and fall back on something safe. */
5065 + if (!bfd_reloc_type_lookup (stdoutput, percent_op->reloc))
5067 + as_bad ("relocation %s isn't supported by the current ABI",
5068 + percent_op->str);
5069 + *reloc = BFD_RELOC_UNUSED;
5071 + return TRUE;
5073 + return FALSE;
5076 +static void
5077 +my_getExpression (expressionS *ep, char *str)
5079 + char *save_in;
5081 + save_in = input_line_pointer;
5082 + input_line_pointer = str;
5083 + expression (ep);
5084 + expr_end = input_line_pointer;
5085 + input_line_pointer = save_in;
5088 +/* Parse string STR as a 16-bit relocatable operand. Store the
5089 + expression in *EP and the relocation, if any, in RELOC.
5090 + Return the number of relocation operators used (0 or 1).
5092 + On exit, EXPR_END points to the first character after the expression. */
5094 +static size_t
5095 +my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc,
5096 + char *str, const struct percent_op_match *percent_op)
5098 + size_t reloc_index;
5099 + unsigned crux_depth, str_depth, regno;
5100 + char *crux;
5102 + /* First, check for integer registers. */
5103 + if (reg_lookup (&str, RCLASS_GPR, &regno))
5105 + ep->X_op = O_register;
5106 + ep->X_add_number = regno;
5107 + return 0;
5110 + /* Search for the start of the main expression.
5111 + End the loop with CRUX pointing to the start
5112 + of the main expression and with CRUX_DEPTH containing the number
5113 + of open brackets at that point. */
5114 + reloc_index = -1;
5115 + str_depth = 0;
5116 + do
5118 + reloc_index++;
5119 + crux = str;
5120 + crux_depth = str_depth;
5122 + /* Skip over whitespace and brackets, keeping count of the number
5123 + of brackets. */
5124 + while (*str == ' ' || *str == '\t' || *str == '(')
5125 + if (*str++ == '(')
5126 + str_depth++;
5128 + while (*str == '%'
5129 + && reloc_index < 1
5130 + && parse_relocation (&str, reloc, percent_op));
5132 + my_getExpression (ep, crux);
5133 + str = expr_end;
5135 + /* Match every open bracket. */
5136 + while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t'))
5137 + if (*str++ == ')')
5138 + crux_depth--;
5140 + if (crux_depth > 0)
5141 + as_bad ("unclosed '('");
5143 + expr_end = str;
5145 + return reloc_index;
5148 +/* This routine assembles an instruction into its binary format. As a
5149 + side effect, it sets the global variable imm_reloc to the type of
5150 + relocation to do if one of the operands is an address expression. */
5152 +static const char *
5153 +riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
5154 + bfd_reloc_code_real_type *imm_reloc)
5156 + char *s;
5157 + const char *args;
5158 + char c = 0;
5159 + struct riscv_opcode *insn, *end = &riscv_opcodes[NUMOPCODES];
5160 + char *argsStart;
5161 + unsigned int regno;
5162 + char save_c = 0;
5163 + int argnum;
5164 + const struct percent_op_match *p;
5165 + const char *error = "unrecognized opcode";
5167 + /* Parse the name of the instruction. Terminate the string if whitespace
5168 + is found so that hash_find only sees the name part of the string. */
5169 + for (s = str; *s != '\0'; ++s)
5170 + if (ISSPACE (*s))
5172 + save_c = *s;
5173 + *s++ = '\0';
5174 + break;
5177 + insn = (struct riscv_opcode *) hash_find (op_hash, str);
5179 + argsStart = s;
5180 + for ( ; insn && insn < end && strcmp (insn->name, str) == 0; insn++)
5182 + if (!riscv_subset_supports (insn->subset))
5183 + continue;
5185 + create_insn (ip, insn);
5186 + argnum = 1;
5188 + imm_expr->X_op = O_absent;
5189 + *imm_reloc = BFD_RELOC_UNUSED;
5190 + p = percent_op_itype;
5192 + for (args = insn->args;; ++args)
5194 + s += strspn (s, " \t");
5195 + switch (*args)
5197 + case '\0': /* end of args */
5198 + if (insn->pinfo != INSN_MACRO)
5200 + if (!insn->match_func (insn, ip->insn_opcode))
5201 + break;
5202 + if (riscv_insn_length (insn->match) == 2 && !riscv_opts.rvc)
5203 + break;
5205 + if (*s != '\0')
5206 + break;
5207 + /* Successful assembly. */
5208 + error = NULL;
5209 + goto out;
5210 + /* Xcustom */
5211 + case '^':
5213 + unsigned long max = OP_MASK_RD;
5214 + my_getExpression (imm_expr, s);
5215 + check_absolute_expr (ip, imm_expr);
5216 + switch (*++args)
5218 + case 'j':
5219 + max = OP_MASK_CUSTOM_IMM;
5220 + INSERT_OPERAND (CUSTOM_IMM, *ip, imm_expr->X_add_number);
5221 + break;
5222 + case 'd':
5223 + INSERT_OPERAND (RD, *ip, imm_expr->X_add_number);
5224 + break;
5225 + case 's':
5226 + INSERT_OPERAND (RS1, *ip, imm_expr->X_add_number);
5227 + break;
5228 + case 't':
5229 + INSERT_OPERAND (RS2, *ip, imm_expr->X_add_number);
5230 + break;
5232 + imm_expr->X_op = O_absent;
5233 + s = expr_end;
5234 + if ((unsigned long) imm_expr->X_add_number > max)
5235 + as_warn ("Bad custom immediate (%lu), must be at most %lu",
5236 + (unsigned long)imm_expr->X_add_number, max);
5237 + continue;
5240 + case 'C': /* RVC */
5241 + switch (*++args)
5243 + case 's': /* RS1 x8-x15 */
5244 + if (!reg_lookup (&s, RCLASS_GPR, &regno)
5245 + || !(regno >= 8 && regno <= 15))
5246 + break;
5247 + INSERT_OPERAND (CRS1S, *ip, regno % 8);
5248 + continue;
5249 + case 'w': /* RS1 x8-x15, constrained to equal RD x8-x15 */
5250 + if (!reg_lookup (&s, RCLASS_GPR, &regno)
5251 + || EXTRACT_OPERAND (CRS1S, ip->insn_opcode) + 8 != regno)
5252 + break;
5253 + continue;
5254 + case 't': /* RS2 x8-x15 */
5255 + if (!reg_lookup (&s, RCLASS_GPR, &regno)
5256 + || !(regno >= 8 && regno <= 15))
5257 + break;
5258 + INSERT_OPERAND (CRS2S, *ip, regno % 8);
5259 + continue;
5260 + case 'x': /* RS2 x8-x15, constrained to equal RD x8-x15 */
5261 + if (!reg_lookup (&s, RCLASS_GPR, &regno)
5262 + || EXTRACT_OPERAND (CRS2S, ip->insn_opcode) + 8 != regno)
5263 + break;
5264 + continue;
5265 + case 'U': /* RS1, constrained to equal RD */
5266 + if (!reg_lookup (&s, RCLASS_GPR, &regno)
5267 + || EXTRACT_OPERAND (RD, ip->insn_opcode) != regno)
5268 + break;
5269 + continue;
5270 + case 'V': /* RS2 */
5271 + if (!reg_lookup (&s, RCLASS_GPR, &regno))
5272 + break;
5273 + INSERT_OPERAND (CRS2, *ip, regno);
5274 + continue;
5275 + case 'c': /* RS1, constrained to equal sp */
5276 + if (!reg_lookup (&s, RCLASS_GPR, &regno)
5277 + || regno != X_SP)
5278 + break;
5279 + continue;
5280 + case '>':
5281 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5282 + || imm_expr->X_op != O_constant
5283 + || imm_expr->X_add_number <= 0
5284 + || imm_expr->X_add_number >= 64)
5285 + break;
5286 + ip->insn_opcode |= ENCODE_RVC_IMM (imm_expr->X_add_number);
5287 +rvc_imm_done:
5288 + s = expr_end;
5289 + imm_expr->X_op = O_absent;
5290 + continue;
5291 + case '<':
5292 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5293 + || imm_expr->X_op != O_constant
5294 + || !VALID_RVC_IMM (imm_expr->X_add_number)
5295 + || imm_expr->X_add_number <= 0
5296 + || imm_expr->X_add_number >= 32)
5297 + break;
5298 + ip->insn_opcode |= ENCODE_RVC_IMM (imm_expr->X_add_number);
5299 + goto rvc_imm_done;
5300 + case 'i':
5301 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5302 + || imm_expr->X_op != O_constant
5303 + || imm_expr->X_add_number == 0
5304 + || !VALID_RVC_SIMM3 (imm_expr->X_add_number))
5305 + break;
5306 + ip->insn_opcode |= ENCODE_RVC_SIMM3 (imm_expr->X_add_number);
5307 + goto rvc_imm_done;
5308 + case 'j':
5309 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5310 + || imm_expr->X_op != O_constant
5311 + || imm_expr->X_add_number == 0
5312 + || !VALID_RVC_IMM (imm_expr->X_add_number))
5313 + break;
5314 + ip->insn_opcode |= ENCODE_RVC_IMM (imm_expr->X_add_number);
5315 + goto rvc_imm_done;
5316 + case 'k':
5317 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5318 + || imm_expr->X_op != O_constant
5319 + || !VALID_RVC_LW_IMM (imm_expr->X_add_number))
5320 + break;
5321 + ip->insn_opcode |= ENCODE_RVC_LW_IMM (imm_expr->X_add_number);
5322 + goto rvc_imm_done;
5323 + case 'l':
5324 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5325 + || imm_expr->X_op != O_constant
5326 + || !VALID_RVC_LD_IMM (imm_expr->X_add_number))
5327 + break;
5328 + ip->insn_opcode |= ENCODE_RVC_LD_IMM (imm_expr->X_add_number);
5329 + goto rvc_imm_done;
5330 + case 'm':
5331 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5332 + || imm_expr->X_op != O_constant
5333 + || !VALID_RVC_LWSP_IMM (imm_expr->X_add_number))
5334 + break;
5335 + ip->insn_opcode |=
5336 + ENCODE_RVC_LWSP_IMM (imm_expr->X_add_number);
5337 + goto rvc_imm_done;
5338 + case 'n':
5339 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5340 + || imm_expr->X_op != O_constant
5341 + || !VALID_RVC_LDSP_IMM (imm_expr->X_add_number))
5342 + break;
5343 + ip->insn_opcode |=
5344 + ENCODE_RVC_LDSP_IMM (imm_expr->X_add_number);
5345 + goto rvc_imm_done;
5346 + case 'K':
5347 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5348 + || imm_expr->X_op != O_constant
5349 + || !VALID_RVC_ADDI4SPN_IMM (imm_expr->X_add_number)
5350 + || imm_expr->X_add_number == 0)
5351 + break;
5352 + ip->insn_opcode |=
5353 + ENCODE_RVC_ADDI4SPN_IMM (imm_expr->X_add_number);
5354 + goto rvc_imm_done;
5355 + case 'L':
5356 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5357 + || imm_expr->X_op != O_constant
5358 + || !VALID_RVC_ADDI16SP_IMM (imm_expr->X_add_number)
5359 + || imm_expr->X_add_number == 0)
5360 + break;
5361 + ip->insn_opcode |=
5362 + ENCODE_RVC_ADDI16SP_IMM (imm_expr->X_add_number);
5363 + goto rvc_imm_done;
5364 + case 'M':
5365 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5366 + || imm_expr->X_op != O_constant
5367 + || !VALID_RVC_SWSP_IMM (imm_expr->X_add_number))
5368 + break;
5369 + ip->insn_opcode |=
5370 + ENCODE_RVC_SWSP_IMM (imm_expr->X_add_number);
5371 + goto rvc_imm_done;
5372 + case 'N':
5373 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5374 + || imm_expr->X_op != O_constant
5375 + || !VALID_RVC_SDSP_IMM (imm_expr->X_add_number))
5376 + break;
5377 + ip->insn_opcode |=
5378 + ENCODE_RVC_SDSP_IMM (imm_expr->X_add_number);
5379 + goto rvc_imm_done;
5380 + case 'u':
5381 + p = percent_op_utype;
5382 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p))
5383 + break;
5384 +rvc_lui:
5385 + if (imm_expr->X_op != O_constant
5386 + || imm_expr->X_add_number <= 0
5387 + || imm_expr->X_add_number >= RISCV_BIGIMM_REACH
5388 + || (imm_expr->X_add_number >= RISCV_RVC_IMM_REACH / 2
5389 + && imm_expr->X_add_number <
5390 + RISCV_BIGIMM_REACH - RISCV_RVC_IMM_REACH / 2))
5391 + break;
5392 + ip->insn_opcode |= ENCODE_RVC_IMM (imm_expr->X_add_number);
5393 + goto rvc_imm_done;
5394 + case 'v':
5395 + if (my_getSmallExpression (imm_expr, imm_reloc, s, p)
5396 + || (imm_expr->X_add_number & (RISCV_IMM_REACH - 1))
5397 + || (int32_t)imm_expr->X_add_number
5398 + != imm_expr->X_add_number)
5399 + break;
5400 + imm_expr->X_add_number =
5401 + ((uint32_t) imm_expr->X_add_number) >> RISCV_IMM_BITS;
5402 + goto rvc_lui;
5403 + case 'p':
5404 + goto branch;
5405 + case 'a':
5406 + goto jump;
5407 + case 'D': /* floating-point RS2 x8-x15 */
5408 + if (!reg_lookup (&s, RCLASS_FPR, &regno)
5409 + || !(regno >= 8 && regno <= 15))
5410 + break;
5411 + INSERT_OPERAND (CRS2S, *ip, regno % 8);
5412 + continue;
5413 + case 'T': /* floating-point RS2 */
5414 + if (!reg_lookup (&s, RCLASS_FPR, &regno))
5415 + break;
5416 + INSERT_OPERAND (CRS2, *ip, regno);
5417 + continue;
5418 + default:
5419 + as_bad (_("bad RVC field specifier 'C%c'\n"), *args);
5421 + break;
5423 + case ',':
5424 + ++argnum;
5425 + if (*s++ == *args)
5426 + continue;
5427 + s--;
5428 + break;
5430 + case '(':
5431 + case ')':
5432 + case '[':
5433 + case ']':
5434 + if (*s++ == *args)
5435 + continue;
5436 + break;
5438 + case '<': /* shift amount, 0 - 31 */
5439 + my_getExpression (imm_expr, s);
5440 + check_absolute_expr (ip, imm_expr);
5441 + if ((unsigned long) imm_expr->X_add_number > 31)
5442 + as_warn (_("Improper shift amount (%lu)"),
5443 + (unsigned long) imm_expr->X_add_number);
5444 + INSERT_OPERAND (SHAMTW, *ip, imm_expr->X_add_number);
5445 + imm_expr->X_op = O_absent;
5446 + s = expr_end;
5447 + continue;
5449 + case '>': /* shift amount, 0 - (XLEN-1) */
5450 + my_getExpression (imm_expr, s);
5451 + check_absolute_expr (ip, imm_expr);
5452 + if ((unsigned long) imm_expr->X_add_number >= xlen)
5453 + as_warn (_("Improper shift amount (%lu)"),
5454 + (unsigned long) imm_expr->X_add_number);
5455 + INSERT_OPERAND (SHAMT, *ip, imm_expr->X_add_number);
5456 + imm_expr->X_op = O_absent;
5457 + s = expr_end;
5458 + continue;
5460 + case 'Z': /* CSRRxI immediate */
5461 + my_getExpression (imm_expr, s);
5462 + check_absolute_expr (ip, imm_expr);
5463 + if ((unsigned long) imm_expr->X_add_number > 31)
5464 + as_warn (_("Improper CSRxI immediate (%lu)"),
5465 + (unsigned long) imm_expr->X_add_number);
5466 + INSERT_OPERAND (RS1, *ip, imm_expr->X_add_number);
5467 + imm_expr->X_op = O_absent;
5468 + s = expr_end;
5469 + continue;
5471 + case 'E': /* Control register. */
5472 + if (reg_lookup (&s, RCLASS_CSR, &regno))
5473 + INSERT_OPERAND (CSR, *ip, regno);
5474 + else
5476 + my_getExpression (imm_expr, s);
5477 + check_absolute_expr (ip, imm_expr);
5478 + if ((unsigned long) imm_expr->X_add_number > 0xfff)
5479 + as_warn(_("Improper CSR address (%lu)"),
5480 + (unsigned long) imm_expr->X_add_number);
5481 + INSERT_OPERAND (CSR, *ip, imm_expr->X_add_number);
5482 + imm_expr->X_op = O_absent;
5483 + s = expr_end;
5485 + continue;
5487 + case 'm': /* rounding mode */
5488 + if (arg_lookup (&s, riscv_rm, ARRAY_SIZE (riscv_rm), &regno))
5490 + INSERT_OPERAND (RM, *ip, regno);
5491 + continue;
5493 + break;
5495 + case 'P':
5496 + case 'Q': /* fence predecessor/successor */
5497 + if (arg_lookup (&s, riscv_pred_succ, ARRAY_SIZE (riscv_pred_succ),
5498 + &regno))
5500 + if (*args == 'P')
5501 + INSERT_OPERAND (PRED, *ip, regno);
5502 + else
5503 + INSERT_OPERAND (SUCC, *ip, regno);
5504 + continue;
5506 + break;
5508 + case 'd': /* destination register */
5509 + case 's': /* source register */
5510 + case 't': /* target register */
5511 + if (reg_lookup (&s, RCLASS_GPR, &regno))
5513 + c = *args;
5514 + if (*s == ' ')
5515 + ++s;
5517 + /* Now that we have assembled one operand, we use the args
5518 + string to figure out where it goes in the instruction. */
5519 + switch (c)
5521 + case 's':
5522 + INSERT_OPERAND (RS1, *ip, regno);
5523 + break;
5524 + case 'd':
5525 + INSERT_OPERAND (RD, *ip, regno);
5526 + break;
5527 + case 't':
5528 + INSERT_OPERAND (RS2, *ip, regno);
5529 + break;
5531 + continue;
5533 + break;
5535 + case 'D': /* floating point rd */
5536 + case 'S': /* floating point rs1 */
5537 + case 'T': /* floating point rs2 */
5538 + case 'U': /* floating point rs1 and rs2 */
5539 + case 'R': /* floating point rs3 */
5540 + if (reg_lookup (&s, RCLASS_FPR, &regno))
5542 + c = *args;
5543 + if (*s == ' ')
5544 + ++s;
5545 + switch (c)
5547 + case 'D':
5548 + INSERT_OPERAND (RD, *ip, regno);
5549 + break;
5550 + case 'S':
5551 + INSERT_OPERAND (RS1, *ip, regno);
5552 + break;
5553 + case 'U':
5554 + INSERT_OPERAND (RS1, *ip, regno);
5555 + /* fallthru */
5556 + case 'T':
5557 + INSERT_OPERAND (RS2, *ip, regno);
5558 + break;
5559 + case 'R':
5560 + INSERT_OPERAND (RS3, *ip, regno);
5561 + break;
5563 + continue;
5566 + break;
5568 + case 'I':
5569 + my_getExpression (imm_expr, s);
5570 + if (imm_expr->X_op != O_big
5571 + && imm_expr->X_op != O_constant)
5572 + break;
5573 + normalize_constant_expr (imm_expr);
5574 + s = expr_end;
5575 + continue;
5577 + case 'A':
5578 + my_getExpression (imm_expr, s);
5579 + normalize_constant_expr (imm_expr);
5580 + /* The 'A' format specifier must be a symbol. */
5581 + if (imm_expr->X_op != O_symbol)
5582 + break;
5583 + *imm_reloc = BFD_RELOC_32;
5584 + s = expr_end;
5585 + continue;
5587 + case 'j': /* sign-extended immediate */
5588 + *imm_reloc = BFD_RELOC_RISCV_LO12_I;
5589 + p = percent_op_itype;
5590 + goto alu_op;
5591 + case 'q': /* store displacement */
5592 + p = percent_op_stype;
5593 + *imm_reloc = BFD_RELOC_RISCV_LO12_S;
5594 + goto load_store;
5595 + case 'o': /* load displacement */
5596 + p = percent_op_itype;
5597 + *imm_reloc = BFD_RELOC_RISCV_LO12_I;
5598 + goto load_store;
5599 + case '0': /* AMO "displacement," which must be zero */
5600 + p = percent_op_rtype;
5601 + *imm_reloc = BFD_RELOC_UNUSED;
5602 +load_store:
5603 + /* Check whether there is only a single bracketed expression
5604 + left. If so, it must be the base register and the
5605 + constant must be zero. */
5606 + imm_expr->X_op = O_constant;
5607 + imm_expr->X_add_number = 0;
5608 + if (*s == '(' && strchr (s + 1, '(') == 0)
5609 + continue;
5610 +alu_op:
5611 + /* If this value won't fit into a 16 bit offset, then go
5612 + find a macro that will generate the 32 bit offset
5613 + code pattern. */
5614 + if (!my_getSmallExpression (imm_expr, imm_reloc, s, p))
5616 + normalize_constant_expr (imm_expr);
5617 + if (imm_expr->X_op != O_constant
5618 + || (*args == '0' && imm_expr->X_add_number != 0)
5619 + || imm_expr->X_add_number >= (signed)RISCV_IMM_REACH/2
5620 + || imm_expr->X_add_number < -(signed)RISCV_IMM_REACH/2)
5621 + break;
5624 + s = expr_end;
5625 + continue;
5627 + case 'p': /* pc relative offset */
5628 +branch:
5629 + *imm_reloc = BFD_RELOC_12_PCREL;
5630 + my_getExpression (imm_expr, s);
5631 + s = expr_end;
5632 + continue;
5634 + case 'u': /* upper 20 bits */
5635 + p = percent_op_utype;
5636 + if (!my_getSmallExpression (imm_expr, imm_reloc, s, p)
5637 + && imm_expr->X_op == O_constant)
5639 + if (imm_expr->X_add_number < 0
5640 + || imm_expr->X_add_number >= (signed)RISCV_BIGIMM_REACH)
5641 + as_bad (_("lui expression not in range 0..1048575"));
5643 + *imm_reloc = BFD_RELOC_RISCV_HI20;
5644 + imm_expr->X_add_number <<= RISCV_IMM_BITS;
5646 + s = expr_end;
5647 + continue;
5649 + case 'a': /* 26 bit address */
5650 +jump:
5651 + my_getExpression (imm_expr, s);
5652 + s = expr_end;
5653 + *imm_reloc = BFD_RELOC_RISCV_JMP;
5654 + continue;
5656 + case 'c':
5657 + my_getExpression (imm_expr, s);
5658 + s = expr_end;
5659 + *imm_reloc = BFD_RELOC_RISCV_CALL;
5660 + if (*s == '@')
5661 + *imm_reloc = BFD_RELOC_RISCV_CALL_PLT, s++;
5662 + continue;
5664 + default:
5665 + as_fatal (_("internal error: bad argument type %c"), *args);
5667 + break;
5669 + s = argsStart;
5670 + error = _("illegal operands");
5673 +out:
5674 + /* Restore the character we might have clobbered above. */
5675 + if (save_c)
5676 + *(argsStart - 1) = save_c;
5678 + return error;
5681 +void
5682 +md_assemble (char *str)
5684 + struct riscv_cl_insn insn;
5685 + expressionS imm_expr;
5686 + bfd_reloc_code_real_type imm_reloc = BFD_RELOC_UNUSED;
5688 + const char *error = riscv_ip (str, &insn, &imm_expr, &imm_reloc);
5690 + if (error)
5692 + as_bad ("%s `%s'", error, str);
5693 + return;
5696 + if (insn.insn_mo->pinfo == INSN_MACRO)
5697 + macro (&insn, &imm_expr, &imm_reloc);
5698 + else
5699 + append_insn (&insn, &imm_expr, imm_reloc);
5702 +char *
5703 +md_atof (int type, char *litP, int *sizeP)
5705 + return ieee_md_atof (type, litP, sizeP, TARGET_BYTES_BIG_ENDIAN);
5708 +void
5709 +md_number_to_chars (char *buf, valueT val, int n)
5711 + number_to_chars_littleendian (buf, val, n);
5714 +const char *md_shortopts = "O::g::G:";
5716 +enum options
5718 + OPTION_M32 = OPTION_MD_BASE,
5719 + OPTION_M64,
5720 + OPTION_MARCH,
5721 + OPTION_PIC,
5722 + OPTION_NO_PIC,
5723 + OPTION_MSOFT_FLOAT,
5724 + OPTION_MHARD_FLOAT,
5725 + OPTION_MRVC,
5726 + OPTION_MNO_RVC,
5727 + OPTION_END_OF_ENUM
5728 + };
5730 +struct option md_longopts[] =
5732 + {"m32", no_argument, NULL, OPTION_M32},
5733 + {"m64", no_argument, NULL, OPTION_M64},
5734 + {"march", required_argument, NULL, OPTION_MARCH},
5735 + {"fPIC", no_argument, NULL, OPTION_PIC},
5736 + {"fpic", no_argument, NULL, OPTION_PIC},
5737 + {"fno-pic", no_argument, NULL, OPTION_NO_PIC},
5738 + {"mrvc", no_argument, NULL, OPTION_MRVC},
5739 + {"mno-rvc", no_argument, NULL, OPTION_MNO_RVC},
5740 + {"msoft-float", no_argument, NULL, OPTION_MSOFT_FLOAT},
5741 + {"mhard-float", no_argument, NULL, OPTION_MHARD_FLOAT},
5743 + {NULL, no_argument, NULL, 0}
5745 +size_t md_longopts_size = sizeof (md_longopts);
5747 +enum float_mode {
5748 + FLOAT_MODE_DEFAULT,
5749 + FLOAT_MODE_SOFT,
5750 + FLOAT_MODE_HARD
5752 +static enum float_mode marg_float_mode = FLOAT_MODE_DEFAULT;
5754 +int
5755 +md_parse_option (int c, char *arg)
5757 + switch (c)
5759 + case OPTION_MRVC:
5760 + riscv_set_rvc (TRUE);
5761 + break;
5763 + case OPTION_MNO_RVC:
5764 + riscv_set_rvc (FALSE);
5765 + break;
5767 + case OPTION_MSOFT_FLOAT:
5768 + marg_float_mode = FLOAT_MODE_SOFT;
5769 + break;
5771 + case OPTION_MHARD_FLOAT:
5772 + marg_float_mode = FLOAT_MODE_HARD;
5773 + break;
5775 + case OPTION_M32:
5776 + xlen = 32;
5777 + break;
5779 + case OPTION_M64:
5780 + xlen = 64;
5781 + break;
5783 + case OPTION_MARCH:
5784 + riscv_set_arch (arg);
5785 + break;
5787 + case OPTION_NO_PIC:
5788 + riscv_opts.pic = FALSE;
5789 + break;
5791 + case OPTION_PIC:
5792 + riscv_opts.pic = TRUE;
5793 + break;
5795 + default:
5796 + return 0;
5799 + return 1;
5802 +void
5803 +riscv_after_parse_args (void)
5805 + struct riscv_subset *subset;
5806 + enum float_mode isa_float_mode, elf_float_mode;
5808 + if (riscv_subsets == NULL)
5809 + riscv_set_arch ("RVIMAFDXcustom");
5811 + if (xlen == 0)
5813 + if (strcmp (default_arch, "riscv32") == 0)
5814 + xlen = 32;
5815 + else if (strcmp (default_arch, "riscv64") == 0)
5816 + xlen = 64;
5817 + else
5818 + as_bad ("unknown default architecture `%s'", default_arch);
5821 + isa_float_mode = FLOAT_MODE_SOFT;
5822 + for (subset = riscv_subsets; subset != NULL; subset = subset->next)
5824 + if (strcasecmp(subset->name, "F") == 0)
5825 + isa_float_mode = FLOAT_MODE_HARD;
5826 + if (strcasecmp(subset->name, "D") == 0)
5827 + isa_float_mode = FLOAT_MODE_HARD;
5830 + if (marg_float_mode == FLOAT_MODE_HARD && isa_float_mode == FLOAT_MODE_SOFT)
5831 + as_bad ("Architecture doesn't allow hardfloat ABI");
5833 + elf_float_mode = (marg_float_mode == FLOAT_MODE_DEFAULT) ? isa_float_mode
5834 + : marg_float_mode;
5836 + switch (elf_float_mode) {
5837 + case FLOAT_MODE_DEFAULT:
5838 + as_bad("a specific float mode must be specified for an ELF");
5839 + break;
5841 + case FLOAT_MODE_SOFT:
5842 + elf_flags |= EF_RISCV_SOFT_FLOAT;
5843 + break;
5845 + case FLOAT_MODE_HARD:
5846 + elf_flags &= ~EF_RISCV_SOFT_FLOAT;
5847 + break;
5851 +void
5852 +riscv_init_after_args (void)
5854 + /* initialize opcodes */
5855 + bfd_riscv_num_opcodes = bfd_riscv_num_builtin_opcodes;
5856 + riscv_opcodes = (struct riscv_opcode *) riscv_builtin_opcodes;
5859 +long
5860 +md_pcrel_from (fixS *fixP)
5862 + return fixP->fx_where + fixP->fx_frag->fr_address;
5865 +/* Apply a fixup to the object file. */
5867 +void
5868 +md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
5870 + bfd_byte *buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
5872 + /* Remember value for tc_gen_reloc. */
5873 + fixP->fx_addnumber = *valP;
5875 + switch (fixP->fx_r_type)
5877 + case BFD_RELOC_RISCV_TLS_GOT_HI20:
5878 + case BFD_RELOC_RISCV_TLS_GD_HI20:
5879 + case BFD_RELOC_RISCV_TLS_DTPREL32:
5880 + case BFD_RELOC_RISCV_TLS_DTPREL64:
5881 + case BFD_RELOC_RISCV_TPREL_HI20:
5882 + case BFD_RELOC_RISCV_TPREL_LO12_I:
5883 + case BFD_RELOC_RISCV_TPREL_LO12_S:
5884 + case BFD_RELOC_RISCV_TPREL_ADD:
5885 + S_SET_THREAD_LOCAL (fixP->fx_addsy);
5886 + /* fall through */
5888 + case BFD_RELOC_RISCV_GOT_HI20:
5889 + case BFD_RELOC_RISCV_PCREL_HI20:
5890 + case BFD_RELOC_RISCV_HI20:
5891 + case BFD_RELOC_RISCV_LO12_I:
5892 + case BFD_RELOC_RISCV_LO12_S:
5893 + case BFD_RELOC_RISCV_ADD8:
5894 + case BFD_RELOC_RISCV_ADD16:
5895 + case BFD_RELOC_RISCV_ADD32:
5896 + case BFD_RELOC_RISCV_ADD64:
5897 + case BFD_RELOC_RISCV_SUB8:
5898 + case BFD_RELOC_RISCV_SUB16:
5899 + case BFD_RELOC_RISCV_SUB32:
5900 + case BFD_RELOC_RISCV_SUB64:
5901 + gas_assert (fixP->fx_addsy != NULL);
5902 + /* Nothing needed to do. The value comes from the reloc entry. */
5903 + break;
5905 + case BFD_RELOC_64:
5906 + case BFD_RELOC_32:
5907 + case BFD_RELOC_16:
5908 + case BFD_RELOC_8:
5909 + if (fixP->fx_addsy && fixP->fx_subsy)
5911 + fixP->fx_next = xmemdup (fixP, sizeof (*fixP), sizeof (*fixP));
5912 + fixP->fx_next->fx_addsy = fixP->fx_subsy;
5913 + fixP->fx_next->fx_subsy = NULL;
5914 + fixP->fx_next->fx_offset = 0;
5915 + fixP->fx_subsy = NULL;
5917 + if (fixP->fx_r_type == BFD_RELOC_64)
5919 + fixP->fx_r_type = BFD_RELOC_RISCV_ADD64;
5920 + fixP->fx_next->fx_r_type = BFD_RELOC_RISCV_SUB64;
5922 + else if (fixP->fx_r_type == BFD_RELOC_32)
5924 + fixP->fx_r_type = BFD_RELOC_RISCV_ADD32;
5925 + fixP->fx_next->fx_r_type = BFD_RELOC_RISCV_SUB32;
5927 + else if (fixP->fx_r_type == BFD_RELOC_16)
5929 + fixP->fx_r_type = BFD_RELOC_RISCV_ADD16;
5930 + fixP->fx_next->fx_r_type = BFD_RELOC_RISCV_SUB16;
5932 + else
5934 + fixP->fx_r_type = BFD_RELOC_RISCV_ADD8;
5935 + fixP->fx_next->fx_r_type = BFD_RELOC_RISCV_SUB8;
5938 + /* fall through */
5940 + case BFD_RELOC_RVA:
5941 + /* If we are deleting this reloc entry, we must fill in the
5942 + value now. This can happen if we have a .word which is not
5943 + resolved when it appears but is later defined. */
5944 + if (fixP->fx_addsy == NULL)
5946 + gas_assert (fixP->fx_size <= sizeof (valueT));
5947 + md_number_to_chars ((char *) buf, *valP, fixP->fx_size);
5948 + fixP->fx_done = 1;
5950 + break;
5952 + case BFD_RELOC_RISCV_JMP:
5953 + if (fixP->fx_addsy)
5955 + /* Fill in a tentative value to improve objdump readability. */
5956 + bfd_vma target = S_GET_VALUE (fixP->fx_addsy) + *valP;
5957 + bfd_vma delta = target - md_pcrel_from (fixP);
5958 + bfd_putl32 (bfd_getl32 (buf) | ENCODE_UJTYPE_IMM (delta), buf);
5960 + break;
5962 + case BFD_RELOC_12_PCREL:
5963 + if (fixP->fx_addsy)
5965 + /* Fill in a tentative value to improve objdump readability. */
5966 + bfd_vma target = S_GET_VALUE (fixP->fx_addsy) + *valP;
5967 + bfd_vma delta = target - md_pcrel_from (fixP);
5968 + bfd_putl32 (bfd_getl32 (buf) | ENCODE_SBTYPE_IMM (delta), buf);
5970 + break;
5972 + case BFD_RELOC_RISCV_RVC_BRANCH:
5973 + if (fixP->fx_addsy)
5975 + /* Fill in a tentative value to improve objdump readability. */
5976 + bfd_vma target = S_GET_VALUE (fixP->fx_addsy) + *valP;
5977 + bfd_vma delta = target - md_pcrel_from (fixP);
5978 + bfd_putl16 (bfd_getl16 (buf) | ENCODE_RVC_B_IMM (delta), buf);
5980 + break;
5982 + case BFD_RELOC_RISCV_RVC_JUMP:
5983 + if (fixP->fx_addsy)
5985 + /* Fill in a tentative value to improve objdump readability. */
5986 + bfd_vma target = S_GET_VALUE (fixP->fx_addsy) + *valP;
5987 + bfd_vma delta = target - md_pcrel_from (fixP);
5988 + bfd_putl16 (bfd_getl16 (buf) | ENCODE_RVC_J_IMM (delta), buf);
5990 + break;
5992 + case BFD_RELOC_RISCV_PCREL_LO12_S:
5993 + case BFD_RELOC_RISCV_PCREL_LO12_I:
5994 + case BFD_RELOC_RISCV_CALL:
5995 + case BFD_RELOC_RISCV_CALL_PLT:
5996 + case BFD_RELOC_RISCV_ALIGN:
5997 + break;
5999 + default:
6000 + /* We ignore generic BFD relocations we don't know about. */
6001 + if (bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type) != NULL)
6002 + as_fatal (_("internal error: bad relocation #%d"), fixP->fx_r_type);
6006 +/* This structure is used to hold a stack of .option values. */
6008 +struct riscv_option_stack
6010 + struct riscv_option_stack *next;
6011 + struct riscv_set_options options;
6014 +static struct riscv_option_stack *riscv_opts_stack;
6016 +/* Handle the .option pseudo-op. */
6018 +static void
6019 +s_riscv_option (int x ATTRIBUTE_UNUSED)
6021 + char *name = input_line_pointer, ch;
6023 + while (!is_end_of_line[(unsigned char) *input_line_pointer])
6024 + ++input_line_pointer;
6025 + ch = *input_line_pointer;
6026 + *input_line_pointer = '\0';
6028 + if (strcmp (name, "rvc") == 0)
6029 + riscv_set_rvc (TRUE);
6030 + else if (strcmp (name, "norvc") == 0)
6031 + riscv_set_rvc (FALSE);
6032 + else if (strcmp (name, "push") == 0)
6034 + struct riscv_option_stack *s;
6036 + s = (struct riscv_option_stack *) xmalloc (sizeof *s);
6037 + s->next = riscv_opts_stack;
6038 + s->options = riscv_opts;
6039 + riscv_opts_stack = s;
6041 + else if (strcmp (name, "pop") == 0)
6043 + struct riscv_option_stack *s;
6045 + s = riscv_opts_stack;
6046 + if (s == NULL)
6047 + as_bad (_(".option pop with no .option push"));
6048 + else
6050 + riscv_opts = s->options;
6051 + riscv_opts_stack = s->next;
6052 + free (s);
6055 + else
6057 + as_warn (_("Unrecognized .option directive: %s\n"), name);
6059 + *input_line_pointer = ch;
6060 + demand_empty_rest_of_line ();
6063 +/* Handle the .dtprelword and .dtpreldword pseudo-ops. They generate
6064 + a 32-bit or 64-bit DTP-relative relocation (BYTES says which) for
6065 + use in DWARF debug information. */
6067 +static void
6068 +s_dtprel (int bytes)
6070 + expressionS ex;
6071 + char *p;
6073 + expression (&ex);
6075 + if (ex.X_op != O_symbol)
6077 + as_bad (_("Unsupported use of %s"), (bytes == 8
6078 + ? ".dtpreldword"
6079 + : ".dtprelword"));
6080 + ignore_rest_of_line ();
6083 + p = frag_more (bytes);
6084 + md_number_to_chars (p, 0, bytes);
6085 + fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE,
6086 + (bytes == 8
6087 + ? BFD_RELOC_RISCV_TLS_DTPREL64
6088 + : BFD_RELOC_RISCV_TLS_DTPREL32));
6090 + demand_empty_rest_of_line ();
6093 +/* Handle the .bss pseudo-op. */
6095 +static void
6096 +s_bss (int ignore ATTRIBUTE_UNUSED)
6098 + subseg_set (bss_section, 0);
6099 + demand_empty_rest_of_line ();
6102 +/* Align to a given power of two. */
6104 +static void
6105 +s_align (int bytes_p)
6107 + int fill_value = 0, fill_value_specified = 0;
6108 + int min_text_alignment = riscv_opts.rvc ? 2 : 4;
6109 + int alignment = get_absolute_expression(), bytes;
6111 + if (bytes_p)
6113 + bytes = alignment;
6114 + if (bytes < 1 || (bytes & (bytes-1)) != 0)
6115 + as_bad (_("alignment not a power of 2: %d"), bytes);
6116 + for (alignment = 0; bytes > 1; bytes >>= 1)
6117 + alignment++;
6120 + bytes = 1 << alignment;
6122 + if (alignment < 0 || alignment > 31)
6123 + as_bad (_("unsatisfiable alignment: %d"), alignment);
6125 + if (*input_line_pointer == ',')
6127 + ++input_line_pointer;
6128 + fill_value = get_absolute_expression ();
6129 + fill_value_specified = 1;
6132 + if (!fill_value_specified
6133 + && subseg_text_p (now_seg)
6134 + && bytes > min_text_alignment)
6136 + /* Emit the worst-case NOP string. The linker will delete any
6137 + unnecessary NOPs. This allows us to support code alignment
6138 + in spite of linker relaxations. */
6139 + bfd_vma i, worst_case_bytes = bytes - min_text_alignment;
6140 + char *nops = frag_more (worst_case_bytes);
6141 + for (i = 0; i < worst_case_bytes - 2; i += 4)
6142 + md_number_to_chars (nops + i, RISCV_NOP, 4);
6143 + if (i < worst_case_bytes)
6144 + md_number_to_chars (nops + i, RVC_NOP, 2);
6146 + expressionS ex;
6147 + ex.X_op = O_constant;
6148 + ex.X_add_number = worst_case_bytes;
6150 + fix_new_exp (frag_now, nops - frag_now->fr_literal, 0,
6151 + &ex, FALSE, BFD_RELOC_RISCV_ALIGN);
6153 + else if (alignment)
6154 + frag_align (alignment, fill_value, 0);
6156 + record_alignment (now_seg, alignment);
6158 + demand_empty_rest_of_line ();
6161 +int
6162 +md_estimate_size_before_relax (fragS *fragp, asection *segtype)
6164 + return (fragp->fr_var = relaxed_branch_length (fragp, segtype, FALSE));
6167 +/* Translate internal representation of relocation info to BFD target
6168 + format. */
6170 +arelent *
6171 +tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
6173 + arelent *reloc = (arelent *) xmalloc (sizeof (arelent));
6175 + reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
6176 + *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
6177 + reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6178 + reloc->addend = fixp->fx_addnumber;
6180 + reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
6181 + if (reloc->howto == NULL)
6183 + if ((fixp->fx_r_type == BFD_RELOC_16 || fixp->fx_r_type == BFD_RELOC_8)
6184 + && fixp->fx_addsy != NULL && fixp->fx_subsy != NULL)
6186 + /* We don't have R_RISCV_8/16, but for this special case,
6187 + we can use R_RISCV_ADD8/16 with R_RISCV_SUB8/16. */
6188 + return reloc;
6191 + as_bad_where (fixp->fx_file, fixp->fx_line,
6192 + _("cannot represent %s relocation in object file"),
6193 + bfd_get_reloc_code_name (fixp->fx_r_type));
6194 + return NULL;
6197 + return reloc;
6200 +int
6201 +riscv_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
6203 + if (RELAX_BRANCH_P (fragp->fr_subtype))
6205 + offsetT old_var = fragp->fr_var;
6206 + fragp->fr_var = relaxed_branch_length (fragp, sec, TRUE);
6207 + return fragp->fr_var - old_var;
6210 + return 0;
6213 +/* Expand far branches to multi-instruction sequences. */
6215 +static void
6216 +md_convert_frag_branch (fragS *fragp)
6218 + bfd_byte *buf;
6219 + expressionS exp;
6220 + fixS *fixp;
6221 + insn_t insn;
6222 + int rs1, reloc;
6224 + buf = (bfd_byte *)fragp->fr_literal + fragp->fr_fix;
6226 + exp.X_op = O_symbol;
6227 + exp.X_add_symbol = fragp->fr_symbol;
6228 + exp.X_add_number = fragp->fr_offset;
6230 + gas_assert (fragp->fr_var == RELAX_BRANCH_LENGTH (fragp->fr_subtype));
6232 + if (RELAX_BRANCH_RVC (fragp->fr_subtype))
6234 + switch (RELAX_BRANCH_LENGTH (fragp->fr_subtype))
6236 + case 8:
6237 + case 4:
6238 + /* Expand the RVC branch into a RISC-V one. */
6239 + insn = bfd_getl16 (buf);
6240 + rs1 = 8 + ((insn >> OP_SH_CRS1S) & OP_MASK_CRS1S);
6241 + if ((insn & MASK_C_J) == MATCH_C_J)
6242 + insn = MATCH_JAL;
6243 + else if ((insn & MASK_C_JAL) == MATCH_C_JAL)
6244 + insn = MATCH_JAL | (X_RA << OP_SH_RD);
6245 + else if ((insn & MASK_C_BEQZ) == MATCH_C_BEQZ)
6246 + insn = MATCH_BEQ | (rs1 << OP_SH_RS1);
6247 + else if ((insn & MASK_C_BNEZ) == MATCH_C_BNEZ)
6248 + insn = MATCH_BNE | (rs1 << OP_SH_RS1);
6249 + else
6250 + abort ();
6251 + bfd_putl32 (insn, buf);
6252 + break;
6254 + case 6:
6255 + /* Invert the branch condition. Branch over the jump. */
6256 + insn = bfd_getl16 (buf);
6257 + insn ^= MATCH_C_BEQZ ^ MATCH_C_BNEZ;
6258 + insn |= ENCODE_RVC_B_IMM (6);
6259 + bfd_putl16 (insn, buf);
6260 + buf += 2;
6261 + goto jump;
6263 + case 2:
6264 + /* Just keep the RVC branch. */
6265 + reloc = RELAX_BRANCH_UNCOND (fragp->fr_subtype)
6266 + ? BFD_RELOC_RISCV_RVC_JUMP : BFD_RELOC_RISCV_RVC_BRANCH;
6267 + fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
6268 + 2, &exp, FALSE, reloc);
6269 + buf += 2;
6270 + goto done;
6272 + default:
6273 + abort();
6277 + switch (RELAX_BRANCH_LENGTH (fragp->fr_subtype))
6279 + case 8:
6280 + gas_assert (!RELAX_BRANCH_UNCOND (fragp->fr_subtype));
6282 + /* Invert the branch condition. Branch over the jump. */
6283 + insn = bfd_getl32 (buf);
6284 + insn ^= MATCH_BEQ ^ MATCH_BNE;
6285 + insn |= ENCODE_SBTYPE_IMM (8);
6286 + md_number_to_chars ((char *) buf, insn, 4);
6287 + buf += 4;
6289 +jump:
6290 + /* Jump to the target. */
6291 + fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
6292 + 4, &exp, FALSE, BFD_RELOC_RISCV_JMP);
6293 + md_number_to_chars ((char *) buf, MATCH_JAL, 4);
6294 + buf += 4;
6295 + break;
6297 + case 4:
6298 + reloc = RELAX_BRANCH_UNCOND (fragp->fr_subtype)
6299 + ? BFD_RELOC_RISCV_JMP : BFD_RELOC_12_PCREL;
6300 + fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
6301 + 4, &exp, FALSE, reloc);
6302 + buf += 4;
6303 + break;
6305 + default:
6306 + abort ();
6309 +done:
6310 + fixp->fx_file = fragp->fr_file;
6311 + fixp->fx_line = fragp->fr_line;
6313 + gas_assert (buf == (bfd_byte *)fragp->fr_literal
6314 + + fragp->fr_fix + fragp->fr_var);
6316 + fragp->fr_fix += fragp->fr_var;
6319 +/* Relax a machine dependent frag. This returns the amount by which
6320 + the current size of the frag should change. */
6322 +void
6323 +md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec ATTRIBUTE_UNUSED,
6324 + fragS *fragp)
6326 + gas_assert (RELAX_BRANCH_P (fragp->fr_subtype));
6327 + md_convert_frag_branch (fragp);
6330 +void
6331 +md_show_usage (FILE *stream)
6333 + fprintf (stream, _("\
6334 +RISC-V options:\n\
6335 + -m32 assemble RV32 code\n\
6336 + -m64 assemble RV64 code (default)\n\
6337 + -fpic generate position-independent code\n\
6338 + -fno-pic don't generate position-independent code (default)\n\
6339 +"));
6342 +/* Standard calling conventions leave the CFA at SP on entry. */
6343 +void
6344 +riscv_cfi_frame_initial_instructions (void)
6346 + cfi_add_CFA_def_cfa_register (X_SP);
6349 +int
6350 +tc_riscv_regname_to_dw2regnum (char *regname)
6352 + int reg;
6354 + if ((reg = reg_lookup_internal (regname, RCLASS_GPR)) >= 0)
6355 + return reg;
6357 + if ((reg = reg_lookup_internal (regname, RCLASS_FPR)) >= 0)
6358 + return reg + 32;
6360 + as_bad (_("unknown register `%s'"), regname);
6361 + return -1;
6364 +void
6365 +riscv_elf_final_processing (void)
6367 + elf_elfheader (stdoutput)->e_flags |= elf_flags;
6370 +/* Pseudo-op table. */
6372 +static const pseudo_typeS riscv_pseudo_table[] =
6374 + /* RISC-V-specific pseudo-ops. */
6375 + {"option", s_riscv_option, 0},
6376 + {"half", cons, 2},
6377 + {"word", cons, 4},
6378 + {"dword", cons, 8},
6379 + {"dtprelword", s_dtprel, 4},
6380 + {"dtpreldword", s_dtprel, 8},
6381 + {"bss", s_bss, 0},
6382 + {"align", s_align, 0},
6383 + {"p2align", s_align, 0},
6384 + {"balign", s_align, 1},
6386 + /* leb128 doesn't work with relaxation; disallow it */
6387 + {"uleb128", s_err, 0},
6388 + {"sleb128", s_err, 0},
6390 + { NULL, NULL, 0 },
6393 +void
6394 +riscv_pop_insert (void)
6396 + extern void pop_insert (const pseudo_typeS *);
6398 + pop_insert (riscv_pseudo_table);
6400 diff -urN empty/gas/config/tc-riscv.h binutils-2.26.1/gas/config/tc-riscv.h
6401 --- empty/gas/config/tc-riscv.h 1970-01-01 08:00:00.000000000 +0800
6402 +++ binutils-2.26.1/gas/config/tc-riscv.h 2016-04-03 10:33:12.065459702 +0800
6403 @@ -0,0 +1,102 @@
6404 +/* tc-riscv.h -- header file for tc-riscv.c.
6405 + Copyright 2011-2015 Free Software Foundation, Inc.
6407 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
6408 + Based on MIPS target.
6410 + This file is part of GAS.
6412 + GAS is free software; you can redistribute it and/or modify
6413 + it under the terms of the GNU General Public License as published by
6414 + the Free Software Foundation; either version 3, or (at your option)
6415 + any later version.
6417 + GAS is distributed in the hope that it will be useful,
6418 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6419 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6420 + GNU General Public License for more details.
6422 + You should have received a copy of the GNU General Public License
6423 + along with this program; see the file COPYING3. If not,
6424 + see <http://www.gnu.org/licenses/>. */
6426 +#ifndef TC_RISCV
6427 +#define TC_RISCV
6429 +#include "opcode/riscv.h"
6431 +struct frag;
6432 +struct expressionS;
6434 +#define TARGET_BYTES_BIG_ENDIAN 0
6436 +#define TARGET_ARCH bfd_arch_riscv
6438 +#define WORKING_DOT_WORD 1
6439 +#define LOCAL_LABELS_FB 1
6441 +/* Symbols named FAKE_LABEL_NAME are emitted when generating DWARF, so make
6442 + sure FAKE_LABEL_NAME is printable. It still must be distinct from any
6443 + real label name. So, append a space, which other labels can't contain. */
6444 +#define FAKE_LABEL_NAME ".L0 "
6446 +#define md_relax_frag(segment, fragp, stretch) \
6447 + riscv_relax_frag(segment, fragp, stretch)
6448 +extern int riscv_relax_frag (asection *, struct frag *, long);
6450 +#define md_section_align(seg,size) (size)
6451 +#define md_undefined_symbol(name) (0)
6452 +#define md_operand(x)
6454 +/* FIXME: it is unclear if this is used, or if it is even correct. */
6455 +#define MAX_MEM_FOR_RS_ALIGN_CODE (1 + 2)
6457 +/* The ISA of the target may change based on command-line arguments. */
6458 +#define TARGET_FORMAT riscv_target_format()
6459 +extern const char *riscv_target_format (void);
6461 +#define md_after_parse_args() riscv_after_parse_args()
6462 +extern void riscv_after_parse_args (void);
6464 +#define tc_init_after_args() riscv_init_after_args()
6465 +extern void riscv_init_after_args (void);
6467 +#define md_parse_long_option(arg) riscv_parse_long_option (arg)
6468 +extern int riscv_parse_long_option (const char *);
6470 +/* Let the linker resolve all the relocs due to relaxation. */
6471 +#define tc_fix_adjustable(fixp) 0
6472 +#define md_allow_local_subtract(l,r,s) 0
6474 +/* Values passed to md_apply_fix don't include symbol values. */
6475 +#define MD_APPLY_SYM_VALUE(FIX) 0
6477 +/* Global syms must not be resolved, to support ELF shared libraries. */
6478 +#define EXTERN_FORCE_RELOC \
6479 + (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6481 +#define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG) ((SEG)->flags & SEC_CODE)
6482 +#define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) 1
6483 +#define TC_VALIDATE_FIX_SUB(FIX, SEG) 1
6484 +#define TC_FORCE_RELOCATION_LOCAL(FIX) 1
6485 +#define DIFF_EXPR_OK 1
6487 +extern void riscv_pop_insert (void);
6488 +#define md_pop_insert() riscv_pop_insert()
6490 +#define TARGET_USE_CFIPOP 1
6492 +#define tc_cfi_frame_initial_instructions riscv_cfi_frame_initial_instructions
6493 +extern void riscv_cfi_frame_initial_instructions (void);
6495 +#define tc_regname_to_dw2regnum tc_riscv_regname_to_dw2regnum
6496 +extern int tc_riscv_regname_to_dw2regnum (char *regname);
6498 +extern unsigned xlen;
6499 +#define DWARF2_DEFAULT_RETURN_COLUMN X_RA
6500 +#define DWARF2_CIE_DATA_ALIGNMENT (-(int) (xlen / 8))
6502 +#define elf_tc_final_processing riscv_elf_final_processing
6503 +extern void riscv_elf_final_processing (void);
6505 +#endif /* TC_RISCV */
6506 diff -urN empty/include/elf/riscv.h binutils-2.26.1/include/elf/riscv.h
6507 --- empty/include/elf/riscv.h 1970-01-01 08:00:00.000000000 +0800
6508 +++ binutils-2.26.1/include/elf/riscv.h 2016-04-03 10:33:12.065459702 +0800
6509 @@ -0,0 +1,92 @@
6510 +/* RISC-V ELF support for BFD.
6511 + Copyright 2011-2015 Free Software Foundation, Inc.
6513 + Contributed by Andrw Waterman <waterman@cs.berkeley.edu> at UC Berkeley.
6514 + Based on MIPS ELF support for BFD, by Ian Lance Taylor.
6516 + This file is part of BFD, the Binary File Descriptor library.
6518 + This program is free software; you can redistribute it and/or modify
6519 + it under the terms of the GNU General Public License as published by
6520 + the Free Software Foundation; either version 3 of the License, or
6521 + (at your option) any later version.
6523 + This program is distributed in the hope that it will be useful,
6524 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6525 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6526 + GNU General Public License for more details.
6528 + You should have received a copy of the GNU General Public License
6529 + along with this program; see the file COPYING3. If not,
6530 + see <http://www.gnu.org/licenses/>. */
6532 +/* This file holds definitions specific to the RISCV ELF ABI. Note
6533 + that most of this is not actually implemented by BFD. */
6535 +#ifndef _ELF_RISCV_H
6536 +#define _ELF_RISCV_H
6538 +#include "elf/reloc-macros.h"
6539 +#include "libiberty.h"
6541 +/* Relocation types. */
6542 +START_RELOC_NUMBERS (elf_riscv_reloc_type)
6543 + /* Relocation types used by the dynamic linker. */
6544 + RELOC_NUMBER (R_RISCV_NONE, 0)
6545 + RELOC_NUMBER (R_RISCV_32, 1)
6546 + RELOC_NUMBER (R_RISCV_64, 2)
6547 + RELOC_NUMBER (R_RISCV_RELATIVE, 3)
6548 + RELOC_NUMBER (R_RISCV_COPY, 4)
6549 + RELOC_NUMBER (R_RISCV_JUMP_SLOT, 5)
6550 + RELOC_NUMBER (R_RISCV_TLS_DTPMOD32, 6)
6551 + RELOC_NUMBER (R_RISCV_TLS_DTPMOD64, 7)
6552 + RELOC_NUMBER (R_RISCV_TLS_DTPREL32, 8)
6553 + RELOC_NUMBER (R_RISCV_TLS_DTPREL64, 9)
6554 + RELOC_NUMBER (R_RISCV_TLS_TPREL32, 10)
6555 + RELOC_NUMBER (R_RISCV_TLS_TPREL64, 11)
6557 + /* Relocation types not used by the dynamic linker. */
6558 + RELOC_NUMBER (R_RISCV_BRANCH, 16)
6559 + RELOC_NUMBER (R_RISCV_JAL, 17)
6560 + RELOC_NUMBER (R_RISCV_CALL, 18)
6561 + RELOC_NUMBER (R_RISCV_CALL_PLT, 19)
6562 + RELOC_NUMBER (R_RISCV_GOT_HI20, 20)
6563 + RELOC_NUMBER (R_RISCV_TLS_GOT_HI20, 21)
6564 + RELOC_NUMBER (R_RISCV_TLS_GD_HI20, 22)
6565 + RELOC_NUMBER (R_RISCV_PCREL_HI20, 23)
6566 + RELOC_NUMBER (R_RISCV_PCREL_LO12_I, 24)
6567 + RELOC_NUMBER (R_RISCV_PCREL_LO12_S, 25)
6568 + RELOC_NUMBER (R_RISCV_HI20, 26)
6569 + RELOC_NUMBER (R_RISCV_LO12_I, 27)
6570 + RELOC_NUMBER (R_RISCV_LO12_S, 28)
6571 + RELOC_NUMBER (R_RISCV_TPREL_HI20, 29)
6572 + RELOC_NUMBER (R_RISCV_TPREL_LO12_I, 30)
6573 + RELOC_NUMBER (R_RISCV_TPREL_LO12_S, 31)
6574 + RELOC_NUMBER (R_RISCV_TPREL_ADD, 32)
6575 + RELOC_NUMBER (R_RISCV_ADD8, 33)
6576 + RELOC_NUMBER (R_RISCV_ADD16, 34)
6577 + RELOC_NUMBER (R_RISCV_ADD32, 35)
6578 + RELOC_NUMBER (R_RISCV_ADD64, 36)
6579 + RELOC_NUMBER (R_RISCV_SUB8, 37)
6580 + RELOC_NUMBER (R_RISCV_SUB16, 38)
6581 + RELOC_NUMBER (R_RISCV_SUB32, 39)
6582 + RELOC_NUMBER (R_RISCV_SUB64, 40)
6583 + RELOC_NUMBER (R_RISCV_GNU_VTINHERIT, 41)
6584 + RELOC_NUMBER (R_RISCV_GNU_VTENTRY, 42)
6585 + RELOC_NUMBER (R_RISCV_ALIGN, 43)
6586 + RELOC_NUMBER (R_RISCV_RVC_BRANCH, 44)
6587 + RELOC_NUMBER (R_RISCV_RVC_JUMP, 45)
6588 + RELOC_NUMBER (R_RISCV_RVC_LUI, 46)
6589 + RELOC_NUMBER (R_RISCV_GPREL_I, 47)
6590 + RELOC_NUMBER (R_RISCV_GPREL_S, 48)
6591 +END_RELOC_NUMBERS (R_RISCV_max)
6593 +/* Processor specific flags for the ELF header e_flags field. */
6595 +/* File may contain compressed instructions. */
6596 +#define EF_RISCV_RVC 0x0001
6598 +/* File uses the soft-float calling convention. */
6599 +#define EF_RISCV_SOFT_FLOAT 0x0002
6601 +#endif /* _ELF_RISCV_H */
6602 diff -urN empty/include/opcode/riscv.h binutils-2.26.1/include/opcode/riscv.h
6603 --- empty/include/opcode/riscv.h 1970-01-01 08:00:00.000000000 +0800
6604 +++ binutils-2.26.1/include/opcode/riscv.h 2016-04-03 10:33:12.065459702 +0800
6605 @@ -0,0 +1,344 @@
6606 +/* riscv.h. RISC-V opcode list for GDB, the GNU debugger.
6607 + Copyright 2011
6608 + Free Software Foundation, Inc.
6609 + Contributed by Andrew Waterman
6611 +This file is part of GDB, GAS, and the GNU binutils.
6613 +GDB, GAS, and the GNU binutils are free software; you can redistribute
6614 +them and/or modify them under the terms of the GNU General Public
6615 +License as published by the Free Software Foundation; either version
6616 +1, or (at your option) any later version.
6618 +GDB, GAS, and the GNU binutils are distributed in the hope that they
6619 +will be useful, but WITHOUT ANY WARRANTY; without even the implied
6620 +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
6621 +the GNU General Public License for more details.
6623 +You should have received a copy of the GNU General Public License
6624 +along with this file; see the file COPYING. If not, write to the Free
6625 +Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
6627 +#ifndef _RISCV_H_
6628 +#define _RISCV_H_
6630 +#include "riscv-opc.h"
6631 +#include <stdlib.h>
6632 +#include <stdint.h>
6634 +typedef uint64_t insn_t;
6636 +static inline unsigned int riscv_insn_length (insn_t insn)
6638 + if ((insn & 0x3) != 0x3) /* RVC. */
6639 + return 2;
6640 + if ((insn & 0x1f) != 0x1f) /* Base ISA and extensions in 32-bit space. */
6641 + return 4;
6642 + if ((insn & 0x3f) == 0x1f) /* 48-bit extensions. */
6643 + return 6;
6644 + if ((insn & 0x7f) == 0x3f) /* 64-bit extensions. */
6645 + return 8;
6646 + /* Longer instructions not supported at the moment. */
6647 + return 2;
6650 +static const char * const riscv_rm[8] = {
6651 + "rne", "rtz", "rdn", "rup", "rmm", 0, 0, "dyn"
6653 +static const char * const riscv_pred_succ[16] = {
6654 + 0, "w", "r", "rw", "o", "ow", "or", "orw",
6655 + "i", "iw", "ir", "irw", "io", "iow", "ior", "iorw",
6658 +#define RVC_JUMP_BITS 11
6659 +#define RVC_JUMP_REACH ((1ULL << RVC_JUMP_BITS) * RISCV_JUMP_ALIGN)
6661 +#define RVC_BRANCH_BITS 8
6662 +#define RVC_BRANCH_REACH ((1ULL << RVC_BRANCH_BITS) * RISCV_BRANCH_ALIGN)
6664 +#define RV_X(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
6665 +#define RV_IMM_SIGN(x) (-(((x) >> 31) & 1))
6667 +#define EXTRACT_ITYPE_IMM(x) \
6668 + (RV_X(x, 20, 12) | (RV_IMM_SIGN(x) << 12))
6669 +#define EXTRACT_STYPE_IMM(x) \
6670 + (RV_X(x, 7, 5) | (RV_X(x, 25, 7) << 5) | (RV_IMM_SIGN(x) << 12))
6671 +#define EXTRACT_SBTYPE_IMM(x) \
6672 + ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_IMM_SIGN(x) << 12))
6673 +#define EXTRACT_UTYPE_IMM(x) \
6674 + ((RV_X(x, 12, 20) << 12) | (RV_IMM_SIGN(x) << 32))
6675 +#define EXTRACT_UJTYPE_IMM(x) \
6676 + ((RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 12, 8) << 12) | (RV_IMM_SIGN(x) << 20))
6677 +#define EXTRACT_RVC_IMM(x) \
6678 + (RV_X(x, 2, 5) | (-RV_X(x, 12, 1) << 5))
6679 +#define EXTRACT_RVC_LUI_IMM(x) \
6680 + (EXTRACT_RVC_IMM (x) << RISCV_IMM_BITS)
6681 +#define EXTRACT_RVC_SIMM3(x) \
6682 + (RV_X(x, 10, 2) | (-RV_X(x, 12, 1) << 2))
6683 +#define EXTRACT_RVC_ADDI4SPN_IMM(x) \
6684 + ((RV_X(x, 6, 1) << 2) | (RV_X(x, 5, 1) << 3) | (RV_X(x, 11, 2) << 4) | (RV_X(x, 7, 4) << 6))
6685 +#define EXTRACT_RVC_ADDI16SP_IMM(x) \
6686 + ((RV_X(x, 6, 1) << 4) | (RV_X(x, 2, 1) << 5) | (RV_X(x, 5, 1) << 6) | (RV_X(x, 3, 2) << 7) | (-RV_X(x, 12, 1) << 9))
6687 +#define EXTRACT_RVC_LW_IMM(x) \
6688 + ((RV_X(x, 6, 1) << 2) | (RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 1) << 6))
6689 +#define EXTRACT_RVC_LD_IMM(x) \
6690 + ((RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 2) << 6))
6691 +#define EXTRACT_RVC_LWSP_IMM(x) \
6692 + ((RV_X(x, 4, 3) << 2) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 2) << 6))
6693 +#define EXTRACT_RVC_LDSP_IMM(x) \
6694 + ((RV_X(x, 5, 2) << 3) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 3) << 6))
6695 +#define EXTRACT_RVC_SWSP_IMM(x) \
6696 + ((RV_X(x, 9, 4) << 2) | (RV_X(x, 7, 2) << 6))
6697 +#define EXTRACT_RVC_SDSP_IMM(x) \
6698 + ((RV_X(x, 10, 3) << 3) | (RV_X(x, 7, 3) << 6))
6699 +#define EXTRACT_RVC_B_IMM(x) \
6700 + ((RV_X(x, 3, 2) << 1) | (RV_X(x, 10, 2) << 3) | (RV_X(x, 2, 1) << 5) | (RV_X(x, 5, 2) << 6) | (-RV_X(x, 12, 1) << 8))
6701 +#define EXTRACT_RVC_J_IMM(x) \
6702 + ((RV_X(x, 3, 3) << 1) | (RV_X(x, 11, 1) << 4) | (RV_X(x, 2, 1) << 5) | (RV_X(x, 7, 1) << 6) | (RV_X(x, 6, 1) << 7) | (RV_X(x, 9, 2) << 8) | (RV_X(x, 8, 1) << 10) | (-RV_X(x, 12, 1) << 11))
6704 +#define ENCODE_ITYPE_IMM(x) \
6705 + (RV_X(x, 0, 12) << 20)
6706 +#define ENCODE_STYPE_IMM(x) \
6707 + ((RV_X(x, 0, 5) << 7) | (RV_X(x, 5, 7) << 25))
6708 +#define ENCODE_SBTYPE_IMM(x) \
6709 + ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 1) << 31))
6710 +#define ENCODE_UTYPE_IMM(x) \
6711 + (RV_X(x, 12, 20) << 12)
6712 +#define ENCODE_UJTYPE_IMM(x) \
6713 + ((RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 8) << 12) | (RV_X(x, 20, 1) << 31))
6714 +#define ENCODE_RVC_IMM(x) \
6715 + ((RV_X(x, 0, 5) << 2) | (RV_X(x, 5, 1) << 12))
6716 +#define ENCODE_RVC_LUI_IMM(x) \
6717 + ENCODE_RVC_IMM ((x) >> RISCV_IMM_BITS)
6718 +#define ENCODE_RVC_SIMM3(x) \
6719 + (RV_X(x, 0, 3) << 10)
6720 +#define ENCODE_RVC_ADDI4SPN_IMM(x) \
6721 + ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 1) << 5) | (RV_X(x, 4, 2) << 11) | (RV_X(x, 6, 4) << 7))
6722 +#define ENCODE_RVC_ADDI16SP_IMM(x) \
6723 + ((RV_X(x, 4, 1) << 6) | (RV_X(x, 5, 1) << 2) | (RV_X(x, 6, 1) << 5) | (RV_X(x, 7, 2) << 3) | (RV_X(x, 9, 1) << 12))
6724 +#define ENCODE_RVC_LW_IMM(x) \
6725 + ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 1) << 5))
6726 +#define ENCODE_RVC_LD_IMM(x) \
6727 + ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 2) << 5))
6728 +#define ENCODE_RVC_LWSP_IMM(x) \
6729 + ((RV_X(x, 2, 3) << 4) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 2) << 2))
6730 +#define ENCODE_RVC_LDSP_IMM(x) \
6731 + ((RV_X(x, 3, 2) << 5) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 3) << 2))
6732 +#define ENCODE_RVC_SWSP_IMM(x) \
6733 + ((RV_X(x, 2, 4) << 9) | (RV_X(x, 6, 2) << 7))
6734 +#define ENCODE_RVC_SDSP_IMM(x) \
6735 + ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 3) << 7))
6736 +#define ENCODE_RVC_B_IMM(x) \
6737 + ((RV_X(x, 1, 2) << 3) | (RV_X(x, 3, 2) << 10) | (RV_X(x, 5, 1) << 2) | (RV_X(x, 6, 2) << 5) | (RV_X(x, 8, 1) << 12))
6738 +#define ENCODE_RVC_J_IMM(x) \
6739 + ((RV_X(x, 1, 3) << 3) | (RV_X(x, 4, 1) << 11) | (RV_X(x, 5, 1) << 2) | (RV_X(x, 6, 1) << 7) | (RV_X(x, 7, 1) << 6) | (RV_X(x, 8, 2) << 9) | (RV_X(x, 10, 1) << 8) | (RV_X(x, 11, 1) << 12))
6741 +#define VALID_ITYPE_IMM(x) (EXTRACT_ITYPE_IMM(ENCODE_ITYPE_IMM(x)) == (x))
6742 +#define VALID_STYPE_IMM(x) (EXTRACT_STYPE_IMM(ENCODE_STYPE_IMM(x)) == (x))
6743 +#define VALID_SBTYPE_IMM(x) (EXTRACT_SBTYPE_IMM(ENCODE_SBTYPE_IMM(x)) == (x))
6744 +#define VALID_UTYPE_IMM(x) (EXTRACT_UTYPE_IMM(ENCODE_UTYPE_IMM(x)) == (x))
6745 +#define VALID_UJTYPE_IMM(x) (EXTRACT_UJTYPE_IMM(ENCODE_UJTYPE_IMM(x)) == (x))
6746 +#define VALID_RVC_IMM(x) (EXTRACT_RVC_IMM(ENCODE_RVC_IMM(x)) == (x))
6747 +#define VALID_RVC_LUI_IMM(x) (EXTRACT_RVC_LUI_IMM(ENCODE_RVC_LUI_IMM(x)) == (x))
6748 +#define VALID_RVC_SIMM3(x) (EXTRACT_RVC_SIMM3(ENCODE_RVC_SIMM3(x)) == (x))
6749 +#define VALID_RVC_ADDI4SPN_IMM(x) (EXTRACT_RVC_ADDI4SPN_IMM(ENCODE_RVC_ADDI4SPN_IMM(x)) == (x))
6750 +#define VALID_RVC_ADDI16SP_IMM(x) (EXTRACT_RVC_ADDI16SP_IMM(ENCODE_RVC_ADDI16SP_IMM(x)) == (x))
6751 +#define VALID_RVC_LW_IMM(x) (EXTRACT_RVC_LW_IMM(ENCODE_RVC_LW_IMM(x)) == (x))
6752 +#define VALID_RVC_LD_IMM(x) (EXTRACT_RVC_LD_IMM(ENCODE_RVC_LD_IMM(x)) == (x))
6753 +#define VALID_RVC_LWSP_IMM(x) (EXTRACT_RVC_LWSP_IMM(ENCODE_RVC_LWSP_IMM(x)) == (x))
6754 +#define VALID_RVC_LDSP_IMM(x) (EXTRACT_RVC_LDSP_IMM(ENCODE_RVC_LDSP_IMM(x)) == (x))
6755 +#define VALID_RVC_SWSP_IMM(x) (EXTRACT_RVC_SWSP_IMM(ENCODE_RVC_SWSP_IMM(x)) == (x))
6756 +#define VALID_RVC_SDSP_IMM(x) (EXTRACT_RVC_SDSP_IMM(ENCODE_RVC_SDSP_IMM(x)) == (x))
6757 +#define VALID_RVC_B_IMM(x) (EXTRACT_RVC_B_IMM(ENCODE_RVC_B_IMM(x)) == (x))
6758 +#define VALID_RVC_J_IMM(x) (EXTRACT_RVC_J_IMM(ENCODE_RVC_J_IMM(x)) == (x))
6760 +#define RISCV_RTYPE(insn, rd, rs1, rs2) \
6761 + ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2))
6762 +#define RISCV_ITYPE(insn, rd, rs1, imm) \
6763 + ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ENCODE_ITYPE_IMM(imm))
6764 +#define RISCV_STYPE(insn, rs1, rs2, imm) \
6765 + ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_STYPE_IMM(imm))
6766 +#define RISCV_SBTYPE(insn, rs1, rs2, target) \
6767 + ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_SBTYPE_IMM(target))
6768 +#define RISCV_UTYPE(insn, rd, bigimm) \
6769 + ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UTYPE_IMM(bigimm))
6770 +#define RISCV_UJTYPE(insn, rd, target) \
6771 + ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UJTYPE_IMM(target))
6773 +#define RISCV_NOP RISCV_ITYPE(ADDI, 0, 0, 0)
6774 +#define RVC_NOP MATCH_C_ADDI
6776 +#define RISCV_CONST_HIGH_PART(VALUE) \
6777 + (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
6778 +#define RISCV_CONST_LOW_PART(VALUE) ((VALUE) - RISCV_CONST_HIGH_PART (VALUE))
6779 +#define RISCV_PCREL_HIGH_PART(VALUE, PC) RISCV_CONST_HIGH_PART((VALUE) - (PC))
6780 +#define RISCV_PCREL_LOW_PART(VALUE, PC) RISCV_CONST_LOW_PART((VALUE) - (PC))
6782 +#define RISCV_JUMP_BITS RISCV_BIGIMM_BITS
6783 +#define RISCV_JUMP_ALIGN_BITS 1
6784 +#define RISCV_JUMP_ALIGN (1 << RISCV_JUMP_ALIGN_BITS)
6785 +#define RISCV_JUMP_REACH ((1ULL << RISCV_JUMP_BITS) * RISCV_JUMP_ALIGN)
6787 +#define RISCV_IMM_BITS 12
6788 +#define RISCV_BIGIMM_BITS (32 - RISCV_IMM_BITS)
6789 +#define RISCV_IMM_REACH (1LL << RISCV_IMM_BITS)
6790 +#define RISCV_BIGIMM_REACH (1LL << RISCV_BIGIMM_BITS)
6791 +#define RISCV_RVC_IMM_REACH (1LL << 6)
6792 +#define RISCV_BRANCH_BITS RISCV_IMM_BITS
6793 +#define RISCV_BRANCH_ALIGN_BITS RISCV_JUMP_ALIGN_BITS
6794 +#define RISCV_BRANCH_ALIGN (1 << RISCV_BRANCH_ALIGN_BITS)
6795 +#define RISCV_BRANCH_REACH (RISCV_IMM_REACH * RISCV_BRANCH_ALIGN)
6797 +/* RV fields. */
6799 +#define OP_MASK_OP 0x7f
6800 +#define OP_SH_OP 0
6801 +#define OP_MASK_RS2 0x1f
6802 +#define OP_SH_RS2 20
6803 +#define OP_MASK_RS1 0x1f
6804 +#define OP_SH_RS1 15
6805 +#define OP_MASK_RS3 0x1f
6806 +#define OP_SH_RS3 27
6807 +#define OP_MASK_RD 0x1f
6808 +#define OP_SH_RD 7
6809 +#define OP_MASK_SHAMT 0x3f
6810 +#define OP_SH_SHAMT 20
6811 +#define OP_MASK_SHAMTW 0x1f
6812 +#define OP_SH_SHAMTW 20
6813 +#define OP_MASK_RM 0x7
6814 +#define OP_SH_RM 12
6815 +#define OP_MASK_PRED 0xf
6816 +#define OP_SH_PRED 24
6817 +#define OP_MASK_SUCC 0xf
6818 +#define OP_SH_SUCC 20
6819 +#define OP_MASK_AQ 0x1
6820 +#define OP_SH_AQ 26
6821 +#define OP_MASK_RL 0x1
6822 +#define OP_SH_RL 25
6824 +#define OP_MASK_CUSTOM_IMM 0x7f
6825 +#define OP_SH_CUSTOM_IMM 25
6826 +#define OP_MASK_CSR 0xfff
6827 +#define OP_SH_CSR 20
6829 +/* RVC fields. */
6831 +#define OP_MASK_CRS2 0x1f
6832 +#define OP_SH_CRS2 2
6833 +#define OP_MASK_CRS1S 0x7
6834 +#define OP_SH_CRS1S 7
6835 +#define OP_MASK_CRS2S 0x7
6836 +#define OP_SH_CRS2S 2
6838 +/* ABI names for selected x-registers. */
6840 +#define X_RA 1
6841 +#define X_SP 2
6842 +#define X_GP 3
6843 +#define X_TP 4
6844 +#define X_T0 5
6845 +#define X_T1 6
6846 +#define X_T2 7
6847 +#define X_T3 28
6849 +#define NGPR 32
6850 +#define NFPR 32
6852 +/* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
6853 + VALUE << SHIFT. VALUE is evaluated exactly once. */
6854 +#define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
6855 + (STRUCT) = (((STRUCT) & ~((insn_t)(MASK) << (SHIFT))) \
6856 + | ((insn_t)((VALUE) & (MASK)) << (SHIFT)))
6858 +/* Extract bits MASK << SHIFT from STRUCT and shift them right
6859 + SHIFT places. */
6860 +#define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
6861 + (((STRUCT) >> (SHIFT)) & (MASK))
6863 +/* Extract the operand given by FIELD from integer INSN. */
6864 +#define EXTRACT_OPERAND(FIELD, INSN) \
6865 + EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD)
6867 +/* This structure holds information for a particular instruction. */
6869 +struct riscv_opcode
6871 + /* The name of the instruction. */
6872 + const char *name;
6873 + /* The ISA subset name (I, M, A, F, D, Xextension). */
6874 + const char *subset;
6875 + /* A string describing the arguments for this instruction. */
6876 + const char *args;
6877 + /* The basic opcode for the instruction. When assembling, this
6878 + opcode is modified by the arguments to produce the actual opcode
6879 + that is used. If pinfo is INSN_MACRO, then this is 0. */
6880 + insn_t match;
6881 + /* If pinfo is not INSN_MACRO, then this is a bit mask for the
6882 + relevant portions of the opcode when disassembling. If the
6883 + actual opcode anded with the match field equals the opcode field,
6884 + then we have found the correct instruction. If pinfo is
6885 + INSN_MACRO, then this field is the macro identifier. */
6886 + insn_t mask;
6887 + /* A function to determine if a word corresponds to this instruction.
6888 + Usually, this computes ((word & mask) == match). */
6889 + int (*match_func) (const struct riscv_opcode *op, insn_t word);
6890 + /* For a macro, this is INSN_MACRO. Otherwise, it is a collection
6891 + of bits describing the instruction, notably any relevant hazard
6892 + information. */
6893 + unsigned long pinfo;
6896 +/* Instruction is a simple alias (e.g. "mv" for "addi"). */
6897 +#define INSN_ALIAS 0x00000001
6898 +/* Instruction is actually a macro. It should be ignored by the
6899 + disassembler, and requires special treatment by the assembler. */
6900 +#define INSN_MACRO 0xffffffff
6902 +/* This is a list of macro expanded instructions.
6904 + _I appended means immediate
6905 + _A appended means address
6906 + _AB appended means address with base register
6907 + _D appended means 64 bit floating point constant
6908 + _S appended means 32 bit floating point constant. */
6910 +enum
6912 + M_LA,
6913 + M_LLA,
6914 + M_LA_TLS_GD,
6915 + M_LA_TLS_IE,
6916 + M_LB,
6917 + M_LBU,
6918 + M_LH,
6919 + M_LHU,
6920 + M_LW,
6921 + M_LWU,
6922 + M_LD,
6923 + M_SB,
6924 + M_SH,
6925 + M_SW,
6926 + M_SD,
6927 + M_FLW,
6928 + M_FLD,
6929 + M_FSW,
6930 + M_FSD,
6931 + M_CALL,
6932 + M_J,
6933 + M_LI,
6934 + M_NUM_MACROS
6938 +extern const char * const riscv_gpr_names_numeric[NGPR];
6939 +extern const char * const riscv_gpr_names_abi[NGPR];
6940 +extern const char * const riscv_fpr_names_numeric[NFPR];
6941 +extern const char * const riscv_fpr_names_abi[NFPR];
6943 +extern const struct riscv_opcode riscv_builtin_opcodes[];
6944 +extern const int bfd_riscv_num_builtin_opcodes;
6945 +extern struct riscv_opcode *riscv_opcodes;
6946 +extern int bfd_riscv_num_opcodes;
6947 +#define NUMOPCODES bfd_riscv_num_opcodes
6949 +#endif /* _RISCV_H_ */
6950 diff -urN empty/include/opcode/riscv-opc.h binutils-2.26.1/include/opcode/riscv-opc.h
6951 --- empty/include/opcode/riscv-opc.h 1970-01-01 08:00:00.000000000 +0800
6952 +++ binutils-2.26.1/include/opcode/riscv-opc.h 2016-04-03 10:33:12.065459702 +0800
6953 @@ -0,0 +1,931 @@
6954 +/* Automatically generated by parse-opcodes */
6955 +#ifndef RISCV_ENCODING_H
6956 +#define RISCV_ENCODING_H
6957 +#define MATCH_SLLI_RV32 0x1013
6958 +#define MASK_SLLI_RV32 0xfe00707f
6959 +#define MATCH_SRLI_RV32 0x5013
6960 +#define MASK_SRLI_RV32 0xfe00707f
6961 +#define MATCH_SRAI_RV32 0x40005013
6962 +#define MASK_SRAI_RV32 0xfe00707f
6963 +#define MATCH_FRFLAGS 0x102073
6964 +#define MASK_FRFLAGS 0xfffff07f
6965 +#define MATCH_FSFLAGS 0x101073
6966 +#define MASK_FSFLAGS 0xfff0707f
6967 +#define MATCH_FSFLAGSI 0x105073
6968 +#define MASK_FSFLAGSI 0xfff0707f
6969 +#define MATCH_FRRM 0x202073
6970 +#define MASK_FRRM 0xfffff07f
6971 +#define MATCH_FSRM 0x201073
6972 +#define MASK_FSRM 0xfff0707f
6973 +#define MATCH_FSRMI 0x205073
6974 +#define MASK_FSRMI 0xfff0707f
6975 +#define MATCH_FSCSR 0x301073
6976 +#define MASK_FSCSR 0xfff0707f
6977 +#define MATCH_FRCSR 0x302073
6978 +#define MASK_FRCSR 0xfffff07f
6979 +#define MATCH_RDCYCLE 0xc0002073
6980 +#define MASK_RDCYCLE 0xfffff07f
6981 +#define MATCH_RDTIME 0xc0102073
6982 +#define MASK_RDTIME 0xfffff07f
6983 +#define MATCH_RDINSTRET 0xc0202073
6984 +#define MASK_RDINSTRET 0xfffff07f
6985 +#define MATCH_RDCYCLEH 0xc8002073
6986 +#define MASK_RDCYCLEH 0xfffff07f
6987 +#define MATCH_RDTIMEH 0xc8102073
6988 +#define MASK_RDTIMEH 0xfffff07f
6989 +#define MATCH_RDINSTRETH 0xc8202073
6990 +#define MASK_RDINSTRETH 0xfffff07f
6991 +#define MATCH_ECALL 0x73
6992 +#define MASK_ECALL 0xffffffff
6993 +#define MATCH_EBREAK 0x100073
6994 +#define MASK_EBREAK 0xffffffff
6995 +#define MATCH_ERET 0x10000073
6996 +#define MASK_ERET 0xffffffff
6997 +#define MATCH_BEQ 0x63
6998 +#define MASK_BEQ 0x707f
6999 +#define MATCH_BNE 0x1063
7000 +#define MASK_BNE 0x707f
7001 +#define MATCH_BLT 0x4063
7002 +#define MASK_BLT 0x707f
7003 +#define MATCH_BGE 0x5063
7004 +#define MASK_BGE 0x707f
7005 +#define MATCH_BLTU 0x6063
7006 +#define MASK_BLTU 0x707f
7007 +#define MATCH_BGEU 0x7063
7008 +#define MASK_BGEU 0x707f
7009 +#define MATCH_JALR 0x67
7010 +#define MASK_JALR 0x707f
7011 +#define MATCH_JAL 0x6f
7012 +#define MASK_JAL 0x7f
7013 +#define MATCH_LUI 0x37
7014 +#define MASK_LUI 0x7f
7015 +#define MATCH_AUIPC 0x17
7016 +#define MASK_AUIPC 0x7f
7017 +#define MATCH_ADDI 0x13
7018 +#define MASK_ADDI 0x707f
7019 +#define MATCH_SLLI 0x1013
7020 +#define MASK_SLLI 0xfc00707f
7021 +#define MATCH_SLTI 0x2013
7022 +#define MASK_SLTI 0x707f
7023 +#define MATCH_SLTIU 0x3013
7024 +#define MASK_SLTIU 0x707f
7025 +#define MATCH_XORI 0x4013
7026 +#define MASK_XORI 0x707f
7027 +#define MATCH_SRLI 0x5013
7028 +#define MASK_SRLI 0xfc00707f
7029 +#define MATCH_SRAI 0x40005013
7030 +#define MASK_SRAI 0xfc00707f
7031 +#define MATCH_ORI 0x6013
7032 +#define MASK_ORI 0x707f
7033 +#define MATCH_ANDI 0x7013
7034 +#define MASK_ANDI 0x707f
7035 +#define MATCH_ADD 0x33
7036 +#define MASK_ADD 0xfe00707f
7037 +#define MATCH_SUB 0x40000033
7038 +#define MASK_SUB 0xfe00707f
7039 +#define MATCH_SLL 0x1033
7040 +#define MASK_SLL 0xfe00707f
7041 +#define MATCH_SLT 0x2033
7042 +#define MASK_SLT 0xfe00707f
7043 +#define MATCH_SLTU 0x3033
7044 +#define MASK_SLTU 0xfe00707f
7045 +#define MATCH_XOR 0x4033
7046 +#define MASK_XOR 0xfe00707f
7047 +#define MATCH_SRL 0x5033
7048 +#define MASK_SRL 0xfe00707f
7049 +#define MATCH_SRA 0x40005033
7050 +#define MASK_SRA 0xfe00707f
7051 +#define MATCH_OR 0x6033
7052 +#define MASK_OR 0xfe00707f
7053 +#define MATCH_AND 0x7033
7054 +#define MASK_AND 0xfe00707f
7055 +#define MATCH_ADDIW 0x1b
7056 +#define MASK_ADDIW 0x707f
7057 +#define MATCH_SLLIW 0x101b
7058 +#define MASK_SLLIW 0xfe00707f
7059 +#define MATCH_SRLIW 0x501b
7060 +#define MASK_SRLIW 0xfe00707f
7061 +#define MATCH_SRAIW 0x4000501b
7062 +#define MASK_SRAIW 0xfe00707f
7063 +#define MATCH_ADDW 0x3b
7064 +#define MASK_ADDW 0xfe00707f
7065 +#define MATCH_SUBW 0x4000003b
7066 +#define MASK_SUBW 0xfe00707f
7067 +#define MATCH_SLLW 0x103b
7068 +#define MASK_SLLW 0xfe00707f
7069 +#define MATCH_SRLW 0x503b
7070 +#define MASK_SRLW 0xfe00707f
7071 +#define MATCH_SRAW 0x4000503b
7072 +#define MASK_SRAW 0xfe00707f
7073 +#define MATCH_LB 0x3
7074 +#define MASK_LB 0x707f
7075 +#define MATCH_LH 0x1003
7076 +#define MASK_LH 0x707f
7077 +#define MATCH_LW 0x2003
7078 +#define MASK_LW 0x707f
7079 +#define MATCH_LD 0x3003
7080 +#define MASK_LD 0x707f
7081 +#define MATCH_LBU 0x4003
7082 +#define MASK_LBU 0x707f
7083 +#define MATCH_LHU 0x5003
7084 +#define MASK_LHU 0x707f
7085 +#define MATCH_LWU 0x6003
7086 +#define MASK_LWU 0x707f
7087 +#define MATCH_SB 0x23
7088 +#define MASK_SB 0x707f
7089 +#define MATCH_SH 0x1023
7090 +#define MASK_SH 0x707f
7091 +#define MATCH_SW 0x2023
7092 +#define MASK_SW 0x707f
7093 +#define MATCH_SD 0x3023
7094 +#define MASK_SD 0x707f
7095 +#define MATCH_FENCE 0xf
7096 +#define MASK_FENCE 0x707f
7097 +#define MATCH_FENCE_I 0x100f
7098 +#define MASK_FENCE_I 0x707f
7099 +#define MATCH_MUL 0x2000033
7100 +#define MASK_MUL 0xfe00707f
7101 +#define MATCH_MULH 0x2001033
7102 +#define MASK_MULH 0xfe00707f
7103 +#define MATCH_MULHSU 0x2002033
7104 +#define MASK_MULHSU 0xfe00707f
7105 +#define MATCH_MULHU 0x2003033
7106 +#define MASK_MULHU 0xfe00707f
7107 +#define MATCH_DIV 0x2004033
7108 +#define MASK_DIV 0xfe00707f
7109 +#define MATCH_DIVU 0x2005033
7110 +#define MASK_DIVU 0xfe00707f
7111 +#define MATCH_REM 0x2006033
7112 +#define MASK_REM 0xfe00707f
7113 +#define MATCH_REMU 0x2007033
7114 +#define MASK_REMU 0xfe00707f
7115 +#define MATCH_MULW 0x200003b
7116 +#define MASK_MULW 0xfe00707f
7117 +#define MATCH_DIVW 0x200403b
7118 +#define MASK_DIVW 0xfe00707f
7119 +#define MATCH_DIVUW 0x200503b
7120 +#define MASK_DIVUW 0xfe00707f
7121 +#define MATCH_REMW 0x200603b
7122 +#define MASK_REMW 0xfe00707f
7123 +#define MATCH_REMUW 0x200703b
7124 +#define MASK_REMUW 0xfe00707f
7125 +#define MATCH_AMOADD_W 0x202f
7126 +#define MASK_AMOADD_W 0xf800707f
7127 +#define MATCH_AMOXOR_W 0x2000202f
7128 +#define MASK_AMOXOR_W 0xf800707f
7129 +#define MATCH_AMOOR_W 0x4000202f
7130 +#define MASK_AMOOR_W 0xf800707f
7131 +#define MATCH_AMOAND_W 0x6000202f
7132 +#define MASK_AMOAND_W 0xf800707f
7133 +#define MATCH_AMOMIN_W 0x8000202f
7134 +#define MASK_AMOMIN_W 0xf800707f
7135 +#define MATCH_AMOMAX_W 0xa000202f
7136 +#define MASK_AMOMAX_W 0xf800707f
7137 +#define MATCH_AMOMINU_W 0xc000202f
7138 +#define MASK_AMOMINU_W 0xf800707f
7139 +#define MATCH_AMOMAXU_W 0xe000202f
7140 +#define MASK_AMOMAXU_W 0xf800707f
7141 +#define MATCH_AMOSWAP_W 0x800202f
7142 +#define MASK_AMOSWAP_W 0xf800707f
7143 +#define MATCH_LR_W 0x1000202f
7144 +#define MASK_LR_W 0xf9f0707f
7145 +#define MATCH_SC_W 0x1800202f
7146 +#define MASK_SC_W 0xf800707f
7147 +#define MATCH_AMOADD_D 0x302f
7148 +#define MASK_AMOADD_D 0xf800707f
7149 +#define MATCH_AMOXOR_D 0x2000302f
7150 +#define MASK_AMOXOR_D 0xf800707f
7151 +#define MATCH_AMOOR_D 0x4000302f
7152 +#define MASK_AMOOR_D 0xf800707f
7153 +#define MATCH_AMOAND_D 0x6000302f
7154 +#define MASK_AMOAND_D 0xf800707f
7155 +#define MATCH_AMOMIN_D 0x8000302f
7156 +#define MASK_AMOMIN_D 0xf800707f
7157 +#define MATCH_AMOMAX_D 0xa000302f
7158 +#define MASK_AMOMAX_D 0xf800707f
7159 +#define MATCH_AMOMINU_D 0xc000302f
7160 +#define MASK_AMOMINU_D 0xf800707f
7161 +#define MATCH_AMOMAXU_D 0xe000302f
7162 +#define MASK_AMOMAXU_D 0xf800707f
7163 +#define MATCH_AMOSWAP_D 0x800302f
7164 +#define MASK_AMOSWAP_D 0xf800707f
7165 +#define MATCH_LR_D 0x1000302f
7166 +#define MASK_LR_D 0xf9f0707f
7167 +#define MATCH_SC_D 0x1800302f
7168 +#define MASK_SC_D 0xf800707f
7169 +#define MATCH_SCALL 0x73
7170 +#define MASK_SCALL 0xffffffff
7171 +#define MATCH_SBREAK 0x100073
7172 +#define MASK_SBREAK 0xffffffff
7173 +#define MATCH_SRET 0x10200073
7174 +#define MASK_SRET 0xffffffff
7175 +#define MATCH_SFENCE_VM 0x10400073
7176 +#define MASK_SFENCE_VM 0xfff07fff
7177 +#define MATCH_WFI 0x10500073
7178 +#define MASK_WFI 0xffffffff
7179 +#define MATCH_CSRRW 0x1073
7180 +#define MASK_CSRRW 0x707f
7181 +#define MATCH_CSRRS 0x2073
7182 +#define MASK_CSRRS 0x707f
7183 +#define MATCH_CSRRC 0x3073
7184 +#define MASK_CSRRC 0x707f
7185 +#define MATCH_CSRRWI 0x5073
7186 +#define MASK_CSRRWI 0x707f
7187 +#define MATCH_CSRRSI 0x6073
7188 +#define MASK_CSRRSI 0x707f
7189 +#define MATCH_CSRRCI 0x7073
7190 +#define MASK_CSRRCI 0x707f
7191 +#define MATCH_FADD_S 0x53
7192 +#define MASK_FADD_S 0xfe00007f
7193 +#define MATCH_FSUB_S 0x8000053
7194 +#define MASK_FSUB_S 0xfe00007f
7195 +#define MATCH_FMUL_S 0x10000053
7196 +#define MASK_FMUL_S 0xfe00007f
7197 +#define MATCH_FDIV_S 0x18000053
7198 +#define MASK_FDIV_S 0xfe00007f
7199 +#define MATCH_FSGNJ_S 0x20000053
7200 +#define MASK_FSGNJ_S 0xfe00707f
7201 +#define MATCH_FSGNJN_S 0x20001053
7202 +#define MASK_FSGNJN_S 0xfe00707f
7203 +#define MATCH_FSGNJX_S 0x20002053
7204 +#define MASK_FSGNJX_S 0xfe00707f
7205 +#define MATCH_FMIN_S 0x28000053
7206 +#define MASK_FMIN_S 0xfe00707f
7207 +#define MATCH_FMAX_S 0x28001053
7208 +#define MASK_FMAX_S 0xfe00707f
7209 +#define MATCH_FSQRT_S 0x58000053
7210 +#define MASK_FSQRT_S 0xfff0007f
7211 +#define MATCH_FADD_D 0x2000053
7212 +#define MASK_FADD_D 0xfe00007f
7213 +#define MATCH_FSUB_D 0xa000053
7214 +#define MASK_FSUB_D 0xfe00007f
7215 +#define MATCH_FMUL_D 0x12000053
7216 +#define MASK_FMUL_D 0xfe00007f
7217 +#define MATCH_FDIV_D 0x1a000053
7218 +#define MASK_FDIV_D 0xfe00007f
7219 +#define MATCH_FSGNJ_D 0x22000053
7220 +#define MASK_FSGNJ_D 0xfe00707f
7221 +#define MATCH_FSGNJN_D 0x22001053
7222 +#define MASK_FSGNJN_D 0xfe00707f
7223 +#define MATCH_FSGNJX_D 0x22002053
7224 +#define MASK_FSGNJX_D 0xfe00707f
7225 +#define MATCH_FMIN_D 0x2a000053
7226 +#define MASK_FMIN_D 0xfe00707f
7227 +#define MATCH_FMAX_D 0x2a001053
7228 +#define MASK_FMAX_D 0xfe00707f
7229 +#define MATCH_FCVT_S_D 0x40100053
7230 +#define MASK_FCVT_S_D 0xfff0007f
7231 +#define MATCH_FCVT_D_S 0x42000053
7232 +#define MASK_FCVT_D_S 0xfff0007f
7233 +#define MATCH_FSQRT_D 0x5a000053
7234 +#define MASK_FSQRT_D 0xfff0007f
7235 +#define MATCH_FLE_S 0xa0000053
7236 +#define MASK_FLE_S 0xfe00707f
7237 +#define MATCH_FLT_S 0xa0001053
7238 +#define MASK_FLT_S 0xfe00707f
7239 +#define MATCH_FEQ_S 0xa0002053
7240 +#define MASK_FEQ_S 0xfe00707f
7241 +#define MATCH_FLE_D 0xa2000053
7242 +#define MASK_FLE_D 0xfe00707f
7243 +#define MATCH_FLT_D 0xa2001053
7244 +#define MASK_FLT_D 0xfe00707f
7245 +#define MATCH_FEQ_D 0xa2002053
7246 +#define MASK_FEQ_D 0xfe00707f
7247 +#define MATCH_FCVT_W_S 0xc0000053
7248 +#define MASK_FCVT_W_S 0xfff0007f
7249 +#define MATCH_FCVT_WU_S 0xc0100053
7250 +#define MASK_FCVT_WU_S 0xfff0007f
7251 +#define MATCH_FCVT_L_S 0xc0200053
7252 +#define MASK_FCVT_L_S 0xfff0007f
7253 +#define MATCH_FCVT_LU_S 0xc0300053
7254 +#define MASK_FCVT_LU_S 0xfff0007f
7255 +#define MATCH_FMV_X_S 0xe0000053
7256 +#define MASK_FMV_X_S 0xfff0707f
7257 +#define MATCH_FCLASS_S 0xe0001053
7258 +#define MASK_FCLASS_S 0xfff0707f
7259 +#define MATCH_FCVT_W_D 0xc2000053
7260 +#define MASK_FCVT_W_D 0xfff0007f
7261 +#define MATCH_FCVT_WU_D 0xc2100053
7262 +#define MASK_FCVT_WU_D 0xfff0007f
7263 +#define MATCH_FCVT_L_D 0xc2200053
7264 +#define MASK_FCVT_L_D 0xfff0007f
7265 +#define MATCH_FCVT_LU_D 0xc2300053
7266 +#define MASK_FCVT_LU_D 0xfff0007f
7267 +#define MATCH_FMV_X_D 0xe2000053
7268 +#define MASK_FMV_X_D 0xfff0707f
7269 +#define MATCH_FCLASS_D 0xe2001053
7270 +#define MASK_FCLASS_D 0xfff0707f
7271 +#define MATCH_FCVT_S_W 0xd0000053
7272 +#define MASK_FCVT_S_W 0xfff0007f
7273 +#define MATCH_FCVT_S_WU 0xd0100053
7274 +#define MASK_FCVT_S_WU 0xfff0007f
7275 +#define MATCH_FCVT_S_L 0xd0200053
7276 +#define MASK_FCVT_S_L 0xfff0007f
7277 +#define MATCH_FCVT_S_LU 0xd0300053
7278 +#define MASK_FCVT_S_LU 0xfff0007f
7279 +#define MATCH_FMV_S_X 0xf0000053
7280 +#define MASK_FMV_S_X 0xfff0707f
7281 +#define MATCH_FCVT_D_W 0xd2000053
7282 +#define MASK_FCVT_D_W 0xfff0007f
7283 +#define MATCH_FCVT_D_WU 0xd2100053
7284 +#define MASK_FCVT_D_WU 0xfff0007f
7285 +#define MATCH_FCVT_D_L 0xd2200053
7286 +#define MASK_FCVT_D_L 0xfff0007f
7287 +#define MATCH_FCVT_D_LU 0xd2300053
7288 +#define MASK_FCVT_D_LU 0xfff0007f
7289 +#define MATCH_FMV_D_X 0xf2000053
7290 +#define MASK_FMV_D_X 0xfff0707f
7291 +#define MATCH_FLW 0x2007
7292 +#define MASK_FLW 0x707f
7293 +#define MATCH_FLD 0x3007
7294 +#define MASK_FLD 0x707f
7295 +#define MATCH_FSW 0x2027
7296 +#define MASK_FSW 0x707f
7297 +#define MATCH_FSD 0x3027
7298 +#define MASK_FSD 0x707f
7299 +#define MATCH_FMADD_S 0x43
7300 +#define MASK_FMADD_S 0x600007f
7301 +#define MATCH_FMSUB_S 0x47
7302 +#define MASK_FMSUB_S 0x600007f
7303 +#define MATCH_FNMSUB_S 0x4b
7304 +#define MASK_FNMSUB_S 0x600007f
7305 +#define MATCH_FNMADD_S 0x4f
7306 +#define MASK_FNMADD_S 0x600007f
7307 +#define MATCH_FMADD_D 0x2000043
7308 +#define MASK_FMADD_D 0x600007f
7309 +#define MATCH_FMSUB_D 0x2000047
7310 +#define MASK_FMSUB_D 0x600007f
7311 +#define MATCH_FNMSUB_D 0x200004b
7312 +#define MASK_FNMSUB_D 0x600007f
7313 +#define MATCH_FNMADD_D 0x200004f
7314 +#define MASK_FNMADD_D 0x600007f
7315 +#define MATCH_C_ADDI4SPN 0x0
7316 +#define MASK_C_ADDI4SPN 0xe003
7317 +#define MATCH_C_FLD 0x2000
7318 +#define MASK_C_FLD 0xe003
7319 +#define MATCH_C_LW 0x4000
7320 +#define MASK_C_LW 0xe003
7321 +#define MATCH_C_FLW 0x6000
7322 +#define MASK_C_FLW 0xe003
7323 +#define MATCH_C_FSD 0xa000
7324 +#define MASK_C_FSD 0xe003
7325 +#define MATCH_C_SW 0xc000
7326 +#define MASK_C_SW 0xe003
7327 +#define MATCH_C_FSW 0xe000
7328 +#define MASK_C_FSW 0xe003
7329 +#define MATCH_C_ADDI 0x1
7330 +#define MASK_C_ADDI 0xe003
7331 +#define MATCH_C_JAL 0x2001
7332 +#define MASK_C_JAL 0xe003
7333 +#define MATCH_C_LI 0x4001
7334 +#define MASK_C_LI 0xe003
7335 +#define MATCH_C_LUI 0x6001
7336 +#define MASK_C_LUI 0xe003
7337 +#define MATCH_C_SRLI 0x8001
7338 +#define MASK_C_SRLI 0xec03
7339 +#define MATCH_C_SRAI 0x8401
7340 +#define MASK_C_SRAI 0xec03
7341 +#define MATCH_C_ANDI 0x8801
7342 +#define MASK_C_ANDI 0xec03
7343 +#define MATCH_C_SUB 0x8c01
7344 +#define MASK_C_SUB 0xfc63
7345 +#define MATCH_C_XOR 0x8c21
7346 +#define MASK_C_XOR 0xfc63
7347 +#define MATCH_C_OR 0x8c41
7348 +#define MASK_C_OR 0xfc63
7349 +#define MATCH_C_AND 0x8c61
7350 +#define MASK_C_AND 0xfc63
7351 +#define MATCH_C_SUBW 0x9c01
7352 +#define MASK_C_SUBW 0xfc63
7353 +#define MATCH_C_ADDW 0x9c21
7354 +#define MASK_C_ADDW 0xfc63
7355 +#define MATCH_C_J 0xa001
7356 +#define MASK_C_J 0xe003
7357 +#define MATCH_C_BEQZ 0xc001
7358 +#define MASK_C_BEQZ 0xe003
7359 +#define MATCH_C_BNEZ 0xe001
7360 +#define MASK_C_BNEZ 0xe003
7361 +#define MATCH_C_SLLI 0x2
7362 +#define MASK_C_SLLI 0xe003
7363 +#define MATCH_C_FLDSP 0x2002
7364 +#define MASK_C_FLDSP 0xe003
7365 +#define MATCH_C_LWSP 0x4002
7366 +#define MASK_C_LWSP 0xe003
7367 +#define MATCH_C_FLWSP 0x6002
7368 +#define MASK_C_FLWSP 0xe003
7369 +#define MATCH_C_MV 0x8002
7370 +#define MASK_C_MV 0xf003
7371 +#define MATCH_C_ADD 0x9002
7372 +#define MASK_C_ADD 0xf003
7373 +#define MATCH_C_FSDSP 0xa002
7374 +#define MASK_C_FSDSP 0xe003
7375 +#define MATCH_C_SWSP 0xc002
7376 +#define MASK_C_SWSP 0xe003
7377 +#define MATCH_C_FSWSP 0xe002
7378 +#define MASK_C_FSWSP 0xe003
7379 +#define MATCH_C_NOP 0x1
7380 +#define MASK_C_NOP 0xffff
7381 +#define MATCH_C_ADDI16SP 0x6101
7382 +#define MASK_C_ADDI16SP 0xef83
7383 +#define MATCH_C_JR 0x8002
7384 +#define MASK_C_JR 0xf07f
7385 +#define MATCH_C_JALR 0x9002
7386 +#define MASK_C_JALR 0xf07f
7387 +#define MATCH_C_EBREAK 0x9002
7388 +#define MASK_C_EBREAK 0xffff
7389 +#define MATCH_C_LD 0x6000
7390 +#define MASK_C_LD 0xe003
7391 +#define MATCH_C_SD 0xe000
7392 +#define MASK_C_SD 0xe003
7393 +#define MATCH_C_ADDIW 0x2001
7394 +#define MASK_C_ADDIW 0xe003
7395 +#define MATCH_C_LDSP 0x6002
7396 +#define MASK_C_LDSP 0xe003
7397 +#define MATCH_C_SDSP 0xe002
7398 +#define MASK_C_SDSP 0xe003
7399 +#define MATCH_CUSTOM0 0xb
7400 +#define MASK_CUSTOM0 0x707f
7401 +#define MATCH_CUSTOM0_RS1 0x200b
7402 +#define MASK_CUSTOM0_RS1 0x707f
7403 +#define MATCH_CUSTOM0_RS1_RS2 0x300b
7404 +#define MASK_CUSTOM0_RS1_RS2 0x707f
7405 +#define MATCH_CUSTOM0_RD 0x400b
7406 +#define MASK_CUSTOM0_RD 0x707f
7407 +#define MATCH_CUSTOM0_RD_RS1 0x600b
7408 +#define MASK_CUSTOM0_RD_RS1 0x707f
7409 +#define MATCH_CUSTOM0_RD_RS1_RS2 0x700b
7410 +#define MASK_CUSTOM0_RD_RS1_RS2 0x707f
7411 +#define MATCH_CUSTOM1 0x2b
7412 +#define MASK_CUSTOM1 0x707f
7413 +#define MATCH_CUSTOM1_RS1 0x202b
7414 +#define MASK_CUSTOM1_RS1 0x707f
7415 +#define MATCH_CUSTOM1_RS1_RS2 0x302b
7416 +#define MASK_CUSTOM1_RS1_RS2 0x707f
7417 +#define MATCH_CUSTOM1_RD 0x402b
7418 +#define MASK_CUSTOM1_RD 0x707f
7419 +#define MATCH_CUSTOM1_RD_RS1 0x602b
7420 +#define MASK_CUSTOM1_RD_RS1 0x707f
7421 +#define MATCH_CUSTOM1_RD_RS1_RS2 0x702b
7422 +#define MASK_CUSTOM1_RD_RS1_RS2 0x707f
7423 +#define MATCH_CUSTOM2 0x5b
7424 +#define MASK_CUSTOM2 0x707f
7425 +#define MATCH_CUSTOM2_RS1 0x205b
7426 +#define MASK_CUSTOM2_RS1 0x707f
7427 +#define MATCH_CUSTOM2_RS1_RS2 0x305b
7428 +#define MASK_CUSTOM2_RS1_RS2 0x707f
7429 +#define MATCH_CUSTOM2_RD 0x405b
7430 +#define MASK_CUSTOM2_RD 0x707f
7431 +#define MATCH_CUSTOM2_RD_RS1 0x605b
7432 +#define MASK_CUSTOM2_RD_RS1 0x707f
7433 +#define MATCH_CUSTOM2_RD_RS1_RS2 0x705b
7434 +#define MASK_CUSTOM2_RD_RS1_RS2 0x707f
7435 +#define MATCH_CUSTOM3 0x7b
7436 +#define MASK_CUSTOM3 0x707f
7437 +#define MATCH_CUSTOM3_RS1 0x207b
7438 +#define MASK_CUSTOM3_RS1 0x707f
7439 +#define MATCH_CUSTOM3_RS1_RS2 0x307b
7440 +#define MASK_CUSTOM3_RS1_RS2 0x707f
7441 +#define MATCH_CUSTOM3_RD 0x407b
7442 +#define MASK_CUSTOM3_RD 0x707f
7443 +#define MATCH_CUSTOM3_RD_RS1 0x607b
7444 +#define MASK_CUSTOM3_RD_RS1 0x707f
7445 +#define MATCH_CUSTOM3_RD_RS1_RS2 0x707b
7446 +#define MASK_CUSTOM3_RD_RS1_RS2 0x707f
7447 +#define CSR_FFLAGS 0x1
7448 +#define CSR_FRM 0x2
7449 +#define CSR_FCSR 0x3
7450 +#define CSR_CYCLE 0xc00
7451 +#define CSR_TIME 0xc01
7452 +#define CSR_INSTRET 0xc02
7453 +#define CSR_STATS 0xc0
7454 +#define CSR_UARCH0 0xcc0
7455 +#define CSR_UARCH1 0xcc1
7456 +#define CSR_UARCH2 0xcc2
7457 +#define CSR_UARCH3 0xcc3
7458 +#define CSR_UARCH4 0xcc4
7459 +#define CSR_UARCH5 0xcc5
7460 +#define CSR_UARCH6 0xcc6
7461 +#define CSR_UARCH7 0xcc7
7462 +#define CSR_UARCH8 0xcc8
7463 +#define CSR_UARCH9 0xcc9
7464 +#define CSR_UARCH10 0xcca
7465 +#define CSR_UARCH11 0xccb
7466 +#define CSR_UARCH12 0xccc
7467 +#define CSR_UARCH13 0xccd
7468 +#define CSR_UARCH14 0xcce
7469 +#define CSR_UARCH15 0xccf
7470 +#define CSR_SSTATUS 0x100
7471 +#define CSR_SIE 0x104
7472 +#define CSR_STVEC 0x105
7473 +#define CSR_SSCRATCH 0x140
7474 +#define CSR_SEPC 0x141
7475 +#define CSR_SCAUSE 0x142
7476 +#define CSR_SBADADDR 0x143
7477 +#define CSR_SIP 0x144
7478 +#define CSR_SPTBR 0x180
7479 +#define CSR_SASID 0x181
7480 +#define CSR_SCYCLE 0xd00
7481 +#define CSR_STIME 0xd01
7482 +#define CSR_SINSTRET 0xd02
7483 +#define CSR_MSTATUS 0x300
7484 +#define CSR_MEDELEG 0x302
7485 +#define CSR_MIDELEG 0x303
7486 +#define CSR_MIE 0x304
7487 +#define CSR_MTVEC 0x305
7488 +#define CSR_MTIMECMP 0x321
7489 +#define CSR_MSCRATCH 0x340
7490 +#define CSR_MEPC 0x341
7491 +#define CSR_MCAUSE 0x342
7492 +#define CSR_MBADADDR 0x343
7493 +#define CSR_MIP 0x344
7494 +#define CSR_MIPI 0x345
7495 +#define CSR_MUCOUNTEREN 0x310
7496 +#define CSR_MSCOUNTEREN 0x311
7497 +#define CSR_MUCYCLE_DELTA 0x700
7498 +#define CSR_MUTIME_DELTA 0x701
7499 +#define CSR_MUINSTRET_DELTA 0x702
7500 +#define CSR_MSCYCLE_DELTA 0x704
7501 +#define CSR_MSTIME_DELTA 0x705
7502 +#define CSR_MSINSTRET_DELTA 0x706
7503 +#define CSR_MCYCLE 0xf00
7504 +#define CSR_MTIME 0xf01
7505 +#define CSR_MINSTRET 0xf02
7506 +#define CSR_MISA 0xf10
7507 +#define CSR_MVENDORID 0xf11
7508 +#define CSR_MARCHID 0xf12
7509 +#define CSR_MIMPID 0xf13
7510 +#define CSR_MCFGADDR 0xf14
7511 +#define CSR_MHARTID 0xf15
7512 +#define CSR_MTOHOST 0x7c0
7513 +#define CSR_MFROMHOST 0x7c1
7514 +#define CSR_MRESET 0x7c2
7515 +#define CSR_CYCLEH 0xc80
7516 +#define CSR_TIMEH 0xc81
7517 +#define CSR_INSTRETH 0xc82
7518 +#define CSR_MTIMECMPH 0x361
7519 +#define CSR_MUCYCLE_DELTAH 0x780
7520 +#define CSR_MUTIME_DELTAH 0x781
7521 +#define CSR_MUINSTRET_DELTAH 0x782
7522 +#define CSR_MSCYCLE_DELTAH 0x784
7523 +#define CSR_MSTIME_DELTAH 0x785
7524 +#define CSR_MSINSTRET_DELTAH 0x786
7525 +#define CSR_MCYCLEH 0xf80
7526 +#define CSR_MTIMEH 0xf81
7527 +#define CSR_MINSTRETH 0xf82
7528 +#define CAUSE_MISALIGNED_FETCH 0x0
7529 +#define CAUSE_FAULT_FETCH 0x1
7530 +#define CAUSE_ILLEGAL_INSTRUCTION 0x2
7531 +#define CAUSE_BREAKPOINT 0x3
7532 +#define CAUSE_MISALIGNED_LOAD 0x4
7533 +#define CAUSE_FAULT_LOAD 0x5
7534 +#define CAUSE_MISALIGNED_STORE 0x6
7535 +#define CAUSE_FAULT_STORE 0x7
7536 +#define CAUSE_USER_ECALL 0x8
7537 +#define CAUSE_SUPERVISOR_ECALL 0x9
7538 +#define CAUSE_HYPERVISOR_ECALL 0xa
7539 +#define CAUSE_MACHINE_ECALL 0xb
7540 +#endif
7541 +#ifdef DECLARE_INSN
7542 +DECLARE_INSN(slli_rv32, MATCH_SLLI_RV32, MASK_SLLI_RV32)
7543 +DECLARE_INSN(srli_rv32, MATCH_SRLI_RV32, MASK_SRLI_RV32)
7544 +DECLARE_INSN(srai_rv32, MATCH_SRAI_RV32, MASK_SRAI_RV32)
7545 +DECLARE_INSN(frflags, MATCH_FRFLAGS, MASK_FRFLAGS)
7546 +DECLARE_INSN(fsflags, MATCH_FSFLAGS, MASK_FSFLAGS)
7547 +DECLARE_INSN(fsflagsi, MATCH_FSFLAGSI, MASK_FSFLAGSI)
7548 +DECLARE_INSN(frrm, MATCH_FRRM, MASK_FRRM)
7549 +DECLARE_INSN(fsrm, MATCH_FSRM, MASK_FSRM)
7550 +DECLARE_INSN(fsrmi, MATCH_FSRMI, MASK_FSRMI)
7551 +DECLARE_INSN(fscsr, MATCH_FSCSR, MASK_FSCSR)
7552 +DECLARE_INSN(frcsr, MATCH_FRCSR, MASK_FRCSR)
7553 +DECLARE_INSN(rdcycle, MATCH_RDCYCLE, MASK_RDCYCLE)
7554 +DECLARE_INSN(rdtime, MATCH_RDTIME, MASK_RDTIME)
7555 +DECLARE_INSN(rdinstret, MATCH_RDINSTRET, MASK_RDINSTRET)
7556 +DECLARE_INSN(rdcycleh, MATCH_RDCYCLEH, MASK_RDCYCLEH)
7557 +DECLARE_INSN(rdtimeh, MATCH_RDTIMEH, MASK_RDTIMEH)
7558 +DECLARE_INSN(rdinstreth, MATCH_RDINSTRETH, MASK_RDINSTRETH)
7559 +DECLARE_INSN(ecall, MATCH_ECALL, MASK_ECALL)
7560 +DECLARE_INSN(ebreak, MATCH_EBREAK, MASK_EBREAK)
7561 +DECLARE_INSN(eret, MATCH_ERET, MASK_ERET)
7562 +DECLARE_INSN(beq, MATCH_BEQ, MASK_BEQ)
7563 +DECLARE_INSN(bne, MATCH_BNE, MASK_BNE)
7564 +DECLARE_INSN(blt, MATCH_BLT, MASK_BLT)
7565 +DECLARE_INSN(bge, MATCH_BGE, MASK_BGE)
7566 +DECLARE_INSN(bltu, MATCH_BLTU, MASK_BLTU)
7567 +DECLARE_INSN(bgeu, MATCH_BGEU, MASK_BGEU)
7568 +DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR)
7569 +DECLARE_INSN(jal, MATCH_JAL, MASK_JAL)
7570 +DECLARE_INSN(lui, MATCH_LUI, MASK_LUI)
7571 +DECLARE_INSN(auipc, MATCH_AUIPC, MASK_AUIPC)
7572 +DECLARE_INSN(addi, MATCH_ADDI, MASK_ADDI)
7573 +DECLARE_INSN(slli, MATCH_SLLI, MASK_SLLI)
7574 +DECLARE_INSN(slti, MATCH_SLTI, MASK_SLTI)
7575 +DECLARE_INSN(sltiu, MATCH_SLTIU, MASK_SLTIU)
7576 +DECLARE_INSN(xori, MATCH_XORI, MASK_XORI)
7577 +DECLARE_INSN(srli, MATCH_SRLI, MASK_SRLI)
7578 +DECLARE_INSN(srai, MATCH_SRAI, MASK_SRAI)
7579 +DECLARE_INSN(ori, MATCH_ORI, MASK_ORI)
7580 +DECLARE_INSN(andi, MATCH_ANDI, MASK_ANDI)
7581 +DECLARE_INSN(add, MATCH_ADD, MASK_ADD)
7582 +DECLARE_INSN(sub, MATCH_SUB, MASK_SUB)
7583 +DECLARE_INSN(sll, MATCH_SLL, MASK_SLL)
7584 +DECLARE_INSN(slt, MATCH_SLT, MASK_SLT)
7585 +DECLARE_INSN(sltu, MATCH_SLTU, MASK_SLTU)
7586 +DECLARE_INSN(xor, MATCH_XOR, MASK_XOR)
7587 +DECLARE_INSN(srl, MATCH_SRL, MASK_SRL)
7588 +DECLARE_INSN(sra, MATCH_SRA, MASK_SRA)
7589 +DECLARE_INSN(or, MATCH_OR, MASK_OR)
7590 +DECLARE_INSN(and, MATCH_AND, MASK_AND)
7591 +DECLARE_INSN(addiw, MATCH_ADDIW, MASK_ADDIW)
7592 +DECLARE_INSN(slliw, MATCH_SLLIW, MASK_SLLIW)
7593 +DECLARE_INSN(srliw, MATCH_SRLIW, MASK_SRLIW)
7594 +DECLARE_INSN(sraiw, MATCH_SRAIW, MASK_SRAIW)
7595 +DECLARE_INSN(addw, MATCH_ADDW, MASK_ADDW)
7596 +DECLARE_INSN(subw, MATCH_SUBW, MASK_SUBW)
7597 +DECLARE_INSN(sllw, MATCH_SLLW, MASK_SLLW)
7598 +DECLARE_INSN(srlw, MATCH_SRLW, MASK_SRLW)
7599 +DECLARE_INSN(sraw, MATCH_SRAW, MASK_SRAW)
7600 +DECLARE_INSN(lb, MATCH_LB, MASK_LB)
7601 +DECLARE_INSN(lh, MATCH_LH, MASK_LH)
7602 +DECLARE_INSN(lw, MATCH_LW, MASK_LW)
7603 +DECLARE_INSN(ld, MATCH_LD, MASK_LD)
7604 +DECLARE_INSN(lbu, MATCH_LBU, MASK_LBU)
7605 +DECLARE_INSN(lhu, MATCH_LHU, MASK_LHU)
7606 +DECLARE_INSN(lwu, MATCH_LWU, MASK_LWU)
7607 +DECLARE_INSN(sb, MATCH_SB, MASK_SB)
7608 +DECLARE_INSN(sh, MATCH_SH, MASK_SH)
7609 +DECLARE_INSN(sw, MATCH_SW, MASK_SW)
7610 +DECLARE_INSN(sd, MATCH_SD, MASK_SD)
7611 +DECLARE_INSN(fence, MATCH_FENCE, MASK_FENCE)
7612 +DECLARE_INSN(fence_i, MATCH_FENCE_I, MASK_FENCE_I)
7613 +DECLARE_INSN(mul, MATCH_MUL, MASK_MUL)
7614 +DECLARE_INSN(mulh, MATCH_MULH, MASK_MULH)
7615 +DECLARE_INSN(mulhsu, MATCH_MULHSU, MASK_MULHSU)
7616 +DECLARE_INSN(mulhu, MATCH_MULHU, MASK_MULHU)
7617 +DECLARE_INSN(div, MATCH_DIV, MASK_DIV)
7618 +DECLARE_INSN(divu, MATCH_DIVU, MASK_DIVU)
7619 +DECLARE_INSN(rem, MATCH_REM, MASK_REM)
7620 +DECLARE_INSN(remu, MATCH_REMU, MASK_REMU)
7621 +DECLARE_INSN(mulw, MATCH_MULW, MASK_MULW)
7622 +DECLARE_INSN(divw, MATCH_DIVW, MASK_DIVW)
7623 +DECLARE_INSN(divuw, MATCH_DIVUW, MASK_DIVUW)
7624 +DECLARE_INSN(remw, MATCH_REMW, MASK_REMW)
7625 +DECLARE_INSN(remuw, MATCH_REMUW, MASK_REMUW)
7626 +DECLARE_INSN(amoadd_w, MATCH_AMOADD_W, MASK_AMOADD_W)
7627 +DECLARE_INSN(amoxor_w, MATCH_AMOXOR_W, MASK_AMOXOR_W)
7628 +DECLARE_INSN(amoor_w, MATCH_AMOOR_W, MASK_AMOOR_W)
7629 +DECLARE_INSN(amoand_w, MATCH_AMOAND_W, MASK_AMOAND_W)
7630 +DECLARE_INSN(amomin_w, MATCH_AMOMIN_W, MASK_AMOMIN_W)
7631 +DECLARE_INSN(amomax_w, MATCH_AMOMAX_W, MASK_AMOMAX_W)
7632 +DECLARE_INSN(amominu_w, MATCH_AMOMINU_W, MASK_AMOMINU_W)
7633 +DECLARE_INSN(amomaxu_w, MATCH_AMOMAXU_W, MASK_AMOMAXU_W)
7634 +DECLARE_INSN(amoswap_w, MATCH_AMOSWAP_W, MASK_AMOSWAP_W)
7635 +DECLARE_INSN(lr_w, MATCH_LR_W, MASK_LR_W)
7636 +DECLARE_INSN(sc_w, MATCH_SC_W, MASK_SC_W)
7637 +DECLARE_INSN(amoadd_d, MATCH_AMOADD_D, MASK_AMOADD_D)
7638 +DECLARE_INSN(amoxor_d, MATCH_AMOXOR_D, MASK_AMOXOR_D)
7639 +DECLARE_INSN(amoor_d, MATCH_AMOOR_D, MASK_AMOOR_D)
7640 +DECLARE_INSN(amoand_d, MATCH_AMOAND_D, MASK_AMOAND_D)
7641 +DECLARE_INSN(amomin_d, MATCH_AMOMIN_D, MASK_AMOMIN_D)
7642 +DECLARE_INSN(amomax_d, MATCH_AMOMAX_D, MASK_AMOMAX_D)
7643 +DECLARE_INSN(amominu_d, MATCH_AMOMINU_D, MASK_AMOMINU_D)
7644 +DECLARE_INSN(amomaxu_d, MATCH_AMOMAXU_D, MASK_AMOMAXU_D)
7645 +DECLARE_INSN(amoswap_d, MATCH_AMOSWAP_D, MASK_AMOSWAP_D)
7646 +DECLARE_INSN(lr_d, MATCH_LR_D, MASK_LR_D)
7647 +DECLARE_INSN(sc_d, MATCH_SC_D, MASK_SC_D)
7648 +DECLARE_INSN(scall, MATCH_SCALL, MASK_SCALL)
7649 +DECLARE_INSN(sbreak, MATCH_SBREAK, MASK_SBREAK)
7650 +DECLARE_INSN(sret, MATCH_SRET, MASK_SRET)
7651 +DECLARE_INSN(sfence_vm, MATCH_SFENCE_VM, MASK_SFENCE_VM)
7652 +DECLARE_INSN(wfi, MATCH_WFI, MASK_WFI)
7653 +DECLARE_INSN(csrrw, MATCH_CSRRW, MASK_CSRRW)
7654 +DECLARE_INSN(csrrs, MATCH_CSRRS, MASK_CSRRS)
7655 +DECLARE_INSN(csrrc, MATCH_CSRRC, MASK_CSRRC)
7656 +DECLARE_INSN(csrrwi, MATCH_CSRRWI, MASK_CSRRWI)
7657 +DECLARE_INSN(csrrsi, MATCH_CSRRSI, MASK_CSRRSI)
7658 +DECLARE_INSN(csrrci, MATCH_CSRRCI, MASK_CSRRCI)
7659 +DECLARE_INSN(fadd_s, MATCH_FADD_S, MASK_FADD_S)
7660 +DECLARE_INSN(fsub_s, MATCH_FSUB_S, MASK_FSUB_S)
7661 +DECLARE_INSN(fmul_s, MATCH_FMUL_S, MASK_FMUL_S)
7662 +DECLARE_INSN(fdiv_s, MATCH_FDIV_S, MASK_FDIV_S)
7663 +DECLARE_INSN(fsgnj_s, MATCH_FSGNJ_S, MASK_FSGNJ_S)
7664 +DECLARE_INSN(fsgnjn_s, MATCH_FSGNJN_S, MASK_FSGNJN_S)
7665 +DECLARE_INSN(fsgnjx_s, MATCH_FSGNJX_S, MASK_FSGNJX_S)
7666 +DECLARE_INSN(fmin_s, MATCH_FMIN_S, MASK_FMIN_S)
7667 +DECLARE_INSN(fmax_s, MATCH_FMAX_S, MASK_FMAX_S)
7668 +DECLARE_INSN(fsqrt_s, MATCH_FSQRT_S, MASK_FSQRT_S)
7669 +DECLARE_INSN(fadd_d, MATCH_FADD_D, MASK_FADD_D)
7670 +DECLARE_INSN(fsub_d, MATCH_FSUB_D, MASK_FSUB_D)
7671 +DECLARE_INSN(fmul_d, MATCH_FMUL_D, MASK_FMUL_D)
7672 +DECLARE_INSN(fdiv_d, MATCH_FDIV_D, MASK_FDIV_D)
7673 +DECLARE_INSN(fsgnj_d, MATCH_FSGNJ_D, MASK_FSGNJ_D)
7674 +DECLARE_INSN(fsgnjn_d, MATCH_FSGNJN_D, MASK_FSGNJN_D)
7675 +DECLARE_INSN(fsgnjx_d, MATCH_FSGNJX_D, MASK_FSGNJX_D)
7676 +DECLARE_INSN(fmin_d, MATCH_FMIN_D, MASK_FMIN_D)
7677 +DECLARE_INSN(fmax_d, MATCH_FMAX_D, MASK_FMAX_D)
7678 +DECLARE_INSN(fcvt_s_d, MATCH_FCVT_S_D, MASK_FCVT_S_D)
7679 +DECLARE_INSN(fcvt_d_s, MATCH_FCVT_D_S, MASK_FCVT_D_S)
7680 +DECLARE_INSN(fsqrt_d, MATCH_FSQRT_D, MASK_FSQRT_D)
7681 +DECLARE_INSN(fle_s, MATCH_FLE_S, MASK_FLE_S)
7682 +DECLARE_INSN(flt_s, MATCH_FLT_S, MASK_FLT_S)
7683 +DECLARE_INSN(feq_s, MATCH_FEQ_S, MASK_FEQ_S)
7684 +DECLARE_INSN(fle_d, MATCH_FLE_D, MASK_FLE_D)
7685 +DECLARE_INSN(flt_d, MATCH_FLT_D, MASK_FLT_D)
7686 +DECLARE_INSN(feq_d, MATCH_FEQ_D, MASK_FEQ_D)
7687 +DECLARE_INSN(fcvt_w_s, MATCH_FCVT_W_S, MASK_FCVT_W_S)
7688 +DECLARE_INSN(fcvt_wu_s, MATCH_FCVT_WU_S, MASK_FCVT_WU_S)
7689 +DECLARE_INSN(fcvt_l_s, MATCH_FCVT_L_S, MASK_FCVT_L_S)
7690 +DECLARE_INSN(fcvt_lu_s, MATCH_FCVT_LU_S, MASK_FCVT_LU_S)
7691 +DECLARE_INSN(fmv_x_s, MATCH_FMV_X_S, MASK_FMV_X_S)
7692 +DECLARE_INSN(fclass_s, MATCH_FCLASS_S, MASK_FCLASS_S)
7693 +DECLARE_INSN(fcvt_w_d, MATCH_FCVT_W_D, MASK_FCVT_W_D)
7694 +DECLARE_INSN(fcvt_wu_d, MATCH_FCVT_WU_D, MASK_FCVT_WU_D)
7695 +DECLARE_INSN(fcvt_l_d, MATCH_FCVT_L_D, MASK_FCVT_L_D)
7696 +DECLARE_INSN(fcvt_lu_d, MATCH_FCVT_LU_D, MASK_FCVT_LU_D)
7697 +DECLARE_INSN(fmv_x_d, MATCH_FMV_X_D, MASK_FMV_X_D)
7698 +DECLARE_INSN(fclass_d, MATCH_FCLASS_D, MASK_FCLASS_D)
7699 +DECLARE_INSN(fcvt_s_w, MATCH_FCVT_S_W, MASK_FCVT_S_W)
7700 +DECLARE_INSN(fcvt_s_wu, MATCH_FCVT_S_WU, MASK_FCVT_S_WU)
7701 +DECLARE_INSN(fcvt_s_l, MATCH_FCVT_S_L, MASK_FCVT_S_L)
7702 +DECLARE_INSN(fcvt_s_lu, MATCH_FCVT_S_LU, MASK_FCVT_S_LU)
7703 +DECLARE_INSN(fmv_s_x, MATCH_FMV_S_X, MASK_FMV_S_X)
7704 +DECLARE_INSN(fcvt_d_w, MATCH_FCVT_D_W, MASK_FCVT_D_W)
7705 +DECLARE_INSN(fcvt_d_wu, MATCH_FCVT_D_WU, MASK_FCVT_D_WU)
7706 +DECLARE_INSN(fcvt_d_l, MATCH_FCVT_D_L, MASK_FCVT_D_L)
7707 +DECLARE_INSN(fcvt_d_lu, MATCH_FCVT_D_LU, MASK_FCVT_D_LU)
7708 +DECLARE_INSN(fmv_d_x, MATCH_FMV_D_X, MASK_FMV_D_X)
7709 +DECLARE_INSN(flw, MATCH_FLW, MASK_FLW)
7710 +DECLARE_INSN(fld, MATCH_FLD, MASK_FLD)
7711 +DECLARE_INSN(fsw, MATCH_FSW, MASK_FSW)
7712 +DECLARE_INSN(fsd, MATCH_FSD, MASK_FSD)
7713 +DECLARE_INSN(fmadd_s, MATCH_FMADD_S, MASK_FMADD_S)
7714 +DECLARE_INSN(fmsub_s, MATCH_FMSUB_S, MASK_FMSUB_S)
7715 +DECLARE_INSN(fnmsub_s, MATCH_FNMSUB_S, MASK_FNMSUB_S)
7716 +DECLARE_INSN(fnmadd_s, MATCH_FNMADD_S, MASK_FNMADD_S)
7717 +DECLARE_INSN(fmadd_d, MATCH_FMADD_D, MASK_FMADD_D)
7718 +DECLARE_INSN(fmsub_d, MATCH_FMSUB_D, MASK_FMSUB_D)
7719 +DECLARE_INSN(fnmsub_d, MATCH_FNMSUB_D, MASK_FNMSUB_D)
7720 +DECLARE_INSN(fnmadd_d, MATCH_FNMADD_D, MASK_FNMADD_D)
7721 +DECLARE_INSN(c_addi4spn, MATCH_C_ADDI4SPN, MASK_C_ADDI4SPN)
7722 +DECLARE_INSN(c_fld, MATCH_C_FLD, MASK_C_FLD)
7723 +DECLARE_INSN(c_lw, MATCH_C_LW, MASK_C_LW)
7724 +DECLARE_INSN(c_flw, MATCH_C_FLW, MASK_C_FLW)
7725 +DECLARE_INSN(c_fsd, MATCH_C_FSD, MASK_C_FSD)
7726 +DECLARE_INSN(c_sw, MATCH_C_SW, MASK_C_SW)
7727 +DECLARE_INSN(c_fsw, MATCH_C_FSW, MASK_C_FSW)
7728 +DECLARE_INSN(c_addi, MATCH_C_ADDI, MASK_C_ADDI)
7729 +DECLARE_INSN(c_jal, MATCH_C_JAL, MASK_C_JAL)
7730 +DECLARE_INSN(c_li, MATCH_C_LI, MASK_C_LI)
7731 +DECLARE_INSN(c_lui, MATCH_C_LUI, MASK_C_LUI)
7732 +DECLARE_INSN(c_srli, MATCH_C_SRLI, MASK_C_SRLI)
7733 +DECLARE_INSN(c_srai, MATCH_C_SRAI, MASK_C_SRAI)
7734 +DECLARE_INSN(c_andi, MATCH_C_ANDI, MASK_C_ANDI)
7735 +DECLARE_INSN(c_sub, MATCH_C_SUB, MASK_C_SUB)
7736 +DECLARE_INSN(c_xor, MATCH_C_XOR, MASK_C_XOR)
7737 +DECLARE_INSN(c_or, MATCH_C_OR, MASK_C_OR)
7738 +DECLARE_INSN(c_and, MATCH_C_AND, MASK_C_AND)
7739 +DECLARE_INSN(c_subw, MATCH_C_SUBW, MASK_C_SUBW)
7740 +DECLARE_INSN(c_addw, MATCH_C_ADDW, MASK_C_ADDW)
7741 +DECLARE_INSN(c_j, MATCH_C_J, MASK_C_J)
7742 +DECLARE_INSN(c_beqz, MATCH_C_BEQZ, MASK_C_BEQZ)
7743 +DECLARE_INSN(c_bnez, MATCH_C_BNEZ, MASK_C_BNEZ)
7744 +DECLARE_INSN(c_slli, MATCH_C_SLLI, MASK_C_SLLI)
7745 +DECLARE_INSN(c_fldsp, MATCH_C_FLDSP, MASK_C_FLDSP)
7746 +DECLARE_INSN(c_lwsp, MATCH_C_LWSP, MASK_C_LWSP)
7747 +DECLARE_INSN(c_flwsp, MATCH_C_FLWSP, MASK_C_FLWSP)
7748 +DECLARE_INSN(c_mv, MATCH_C_MV, MASK_C_MV)
7749 +DECLARE_INSN(c_add, MATCH_C_ADD, MASK_C_ADD)
7750 +DECLARE_INSN(c_fsdsp, MATCH_C_FSDSP, MASK_C_FSDSP)
7751 +DECLARE_INSN(c_swsp, MATCH_C_SWSP, MASK_C_SWSP)
7752 +DECLARE_INSN(c_fswsp, MATCH_C_FSWSP, MASK_C_FSWSP)
7753 +DECLARE_INSN(c_nop, MATCH_C_NOP, MASK_C_NOP)
7754 +DECLARE_INSN(c_addi16sp, MATCH_C_ADDI16SP, MASK_C_ADDI16SP)
7755 +DECLARE_INSN(c_jr, MATCH_C_JR, MASK_C_JR)
7756 +DECLARE_INSN(c_jalr, MATCH_C_JALR, MASK_C_JALR)
7757 +DECLARE_INSN(c_ebreak, MATCH_C_EBREAK, MASK_C_EBREAK)
7758 +DECLARE_INSN(c_ld, MATCH_C_LD, MASK_C_LD)
7759 +DECLARE_INSN(c_sd, MATCH_C_SD, MASK_C_SD)
7760 +DECLARE_INSN(c_addiw, MATCH_C_ADDIW, MASK_C_ADDIW)
7761 +DECLARE_INSN(c_ldsp, MATCH_C_LDSP, MASK_C_LDSP)
7762 +DECLARE_INSN(c_sdsp, MATCH_C_SDSP, MASK_C_SDSP)
7763 +DECLARE_INSN(custom0, MATCH_CUSTOM0, MASK_CUSTOM0)
7764 +DECLARE_INSN(custom0_rs1, MATCH_CUSTOM0_RS1, MASK_CUSTOM0_RS1)
7765 +DECLARE_INSN(custom0_rs1_rs2, MATCH_CUSTOM0_RS1_RS2, MASK_CUSTOM0_RS1_RS2)
7766 +DECLARE_INSN(custom0_rd, MATCH_CUSTOM0_RD, MASK_CUSTOM0_RD)
7767 +DECLARE_INSN(custom0_rd_rs1, MATCH_CUSTOM0_RD_RS1, MASK_CUSTOM0_RD_RS1)
7768 +DECLARE_INSN(custom0_rd_rs1_rs2, MATCH_CUSTOM0_RD_RS1_RS2, MASK_CUSTOM0_RD_RS1_RS2)
7769 +DECLARE_INSN(custom1, MATCH_CUSTOM1, MASK_CUSTOM1)
7770 +DECLARE_INSN(custom1_rs1, MATCH_CUSTOM1_RS1, MASK_CUSTOM1_RS1)
7771 +DECLARE_INSN(custom1_rs1_rs2, MATCH_CUSTOM1_RS1_RS2, MASK_CUSTOM1_RS1_RS2)
7772 +DECLARE_INSN(custom1_rd, MATCH_CUSTOM1_RD, MASK_CUSTOM1_RD)
7773 +DECLARE_INSN(custom1_rd_rs1, MATCH_CUSTOM1_RD_RS1, MASK_CUSTOM1_RD_RS1)
7774 +DECLARE_INSN(custom1_rd_rs1_rs2, MATCH_CUSTOM1_RD_RS1_RS2, MASK_CUSTOM1_RD_RS1_RS2)
7775 +DECLARE_INSN(custom2, MATCH_CUSTOM2, MASK_CUSTOM2)
7776 +DECLARE_INSN(custom2_rs1, MATCH_CUSTOM2_RS1, MASK_CUSTOM2_RS1)
7777 +DECLARE_INSN(custom2_rs1_rs2, MATCH_CUSTOM2_RS1_RS2, MASK_CUSTOM2_RS1_RS2)
7778 +DECLARE_INSN(custom2_rd, MATCH_CUSTOM2_RD, MASK_CUSTOM2_RD)
7779 +DECLARE_INSN(custom2_rd_rs1, MATCH_CUSTOM2_RD_RS1, MASK_CUSTOM2_RD_RS1)
7780 +DECLARE_INSN(custom2_rd_rs1_rs2, MATCH_CUSTOM2_RD_RS1_RS2, MASK_CUSTOM2_RD_RS1_RS2)
7781 +DECLARE_INSN(custom3, MATCH_CUSTOM3, MASK_CUSTOM3)
7782 +DECLARE_INSN(custom3_rs1, MATCH_CUSTOM3_RS1, MASK_CUSTOM3_RS1)
7783 +DECLARE_INSN(custom3_rs1_rs2, MATCH_CUSTOM3_RS1_RS2, MASK_CUSTOM3_RS1_RS2)
7784 +DECLARE_INSN(custom3_rd, MATCH_CUSTOM3_RD, MASK_CUSTOM3_RD)
7785 +DECLARE_INSN(custom3_rd_rs1, MATCH_CUSTOM3_RD_RS1, MASK_CUSTOM3_RD_RS1)
7786 +DECLARE_INSN(custom3_rd_rs1_rs2, MATCH_CUSTOM3_RD_RS1_RS2, MASK_CUSTOM3_RD_RS1_RS2)
7787 +#endif
7788 +#ifdef DECLARE_CSR
7789 +DECLARE_CSR(fflags, CSR_FFLAGS)
7790 +DECLARE_CSR(frm, CSR_FRM)
7791 +DECLARE_CSR(fcsr, CSR_FCSR)
7792 +DECLARE_CSR(cycle, CSR_CYCLE)
7793 +DECLARE_CSR(time, CSR_TIME)
7794 +DECLARE_CSR(instret, CSR_INSTRET)
7795 +DECLARE_CSR(stats, CSR_STATS)
7796 +DECLARE_CSR(uarch0, CSR_UARCH0)
7797 +DECLARE_CSR(uarch1, CSR_UARCH1)
7798 +DECLARE_CSR(uarch2, CSR_UARCH2)
7799 +DECLARE_CSR(uarch3, CSR_UARCH3)
7800 +DECLARE_CSR(uarch4, CSR_UARCH4)
7801 +DECLARE_CSR(uarch5, CSR_UARCH5)
7802 +DECLARE_CSR(uarch6, CSR_UARCH6)
7803 +DECLARE_CSR(uarch7, CSR_UARCH7)
7804 +DECLARE_CSR(uarch8, CSR_UARCH8)
7805 +DECLARE_CSR(uarch9, CSR_UARCH9)
7806 +DECLARE_CSR(uarch10, CSR_UARCH10)
7807 +DECLARE_CSR(uarch11, CSR_UARCH11)
7808 +DECLARE_CSR(uarch12, CSR_UARCH12)
7809 +DECLARE_CSR(uarch13, CSR_UARCH13)
7810 +DECLARE_CSR(uarch14, CSR_UARCH14)
7811 +DECLARE_CSR(uarch15, CSR_UARCH15)
7812 +DECLARE_CSR(sstatus, CSR_SSTATUS)
7813 +DECLARE_CSR(sie, CSR_SIE)
7814 +DECLARE_CSR(stvec, CSR_STVEC)
7815 +DECLARE_CSR(sscratch, CSR_SSCRATCH)
7816 +DECLARE_CSR(sepc, CSR_SEPC)
7817 +DECLARE_CSR(scause, CSR_SCAUSE)
7818 +DECLARE_CSR(sbadaddr, CSR_SBADADDR)
7819 +DECLARE_CSR(sip, CSR_SIP)
7820 +DECLARE_CSR(sptbr, CSR_SPTBR)
7821 +DECLARE_CSR(sasid, CSR_SASID)
7822 +DECLARE_CSR(scycle, CSR_SCYCLE)
7823 +DECLARE_CSR(stime, CSR_STIME)
7824 +DECLARE_CSR(sinstret, CSR_SINSTRET)
7825 +DECLARE_CSR(mstatus, CSR_MSTATUS)
7826 +DECLARE_CSR(medeleg, CSR_MEDELEG)
7827 +DECLARE_CSR(mideleg, CSR_MIDELEG)
7828 +DECLARE_CSR(mie, CSR_MIE)
7829 +DECLARE_CSR(mtvec, CSR_MTVEC)
7830 +DECLARE_CSR(mtimecmp, CSR_MTIMECMP)
7831 +DECLARE_CSR(mscratch, CSR_MSCRATCH)
7832 +DECLARE_CSR(mepc, CSR_MEPC)
7833 +DECLARE_CSR(mcause, CSR_MCAUSE)
7834 +DECLARE_CSR(mbadaddr, CSR_MBADADDR)
7835 +DECLARE_CSR(mip, CSR_MIP)
7836 +DECLARE_CSR(mipi, CSR_MIPI)
7837 +DECLARE_CSR(mucounteren, CSR_MUCOUNTEREN)
7838 +DECLARE_CSR(mscounteren, CSR_MSCOUNTEREN)
7839 +DECLARE_CSR(mucycle_delta, CSR_MUCYCLE_DELTA)
7840 +DECLARE_CSR(mutime_delta, CSR_MUTIME_DELTA)
7841 +DECLARE_CSR(muinstret_delta, CSR_MUINSTRET_DELTA)
7842 +DECLARE_CSR(mscycle_delta, CSR_MSCYCLE_DELTA)
7843 +DECLARE_CSR(mstime_delta, CSR_MSTIME_DELTA)
7844 +DECLARE_CSR(msinstret_delta, CSR_MSINSTRET_DELTA)
7845 +DECLARE_CSR(mcycle, CSR_MCYCLE)
7846 +DECLARE_CSR(mtime, CSR_MTIME)
7847 +DECLARE_CSR(minstret, CSR_MINSTRET)
7848 +DECLARE_CSR(misa, CSR_MISA)
7849 +DECLARE_CSR(mvendorid, CSR_MVENDORID)
7850 +DECLARE_CSR(marchid, CSR_MARCHID)
7851 +DECLARE_CSR(mimpid, CSR_MIMPID)
7852 +DECLARE_CSR(mcfgaddr, CSR_MCFGADDR)
7853 +DECLARE_CSR(mhartid, CSR_MHARTID)
7854 +DECLARE_CSR(mtohost, CSR_MTOHOST)
7855 +DECLARE_CSR(mfromhost, CSR_MFROMHOST)
7856 +DECLARE_CSR(mreset, CSR_MRESET)
7857 +DECLARE_CSR(cycleh, CSR_CYCLEH)
7858 +DECLARE_CSR(timeh, CSR_TIMEH)
7859 +DECLARE_CSR(instreth, CSR_INSTRETH)
7860 +DECLARE_CSR(mtimecmph, CSR_MTIMECMPH)
7861 +DECLARE_CSR(mucycle_deltah, CSR_MUCYCLE_DELTAH)
7862 +DECLARE_CSR(mutime_deltah, CSR_MUTIME_DELTAH)
7863 +DECLARE_CSR(muinstret_deltah, CSR_MUINSTRET_DELTAH)
7864 +DECLARE_CSR(mscycle_deltah, CSR_MSCYCLE_DELTAH)
7865 +DECLARE_CSR(mstime_deltah, CSR_MSTIME_DELTAH)
7866 +DECLARE_CSR(msinstret_deltah, CSR_MSINSTRET_DELTAH)
7867 +DECLARE_CSR(mcycleh, CSR_MCYCLEH)
7868 +DECLARE_CSR(mtimeh, CSR_MTIMEH)
7869 +DECLARE_CSR(minstreth, CSR_MINSTRETH)
7870 +#endif
7871 +#ifdef DECLARE_CAUSE
7872 +DECLARE_CAUSE("misaligned fetch", CAUSE_MISALIGNED_FETCH)
7873 +DECLARE_CAUSE("fault fetch", CAUSE_FAULT_FETCH)
7874 +DECLARE_CAUSE("illegal instruction", CAUSE_ILLEGAL_INSTRUCTION)
7875 +DECLARE_CAUSE("breakpoint", CAUSE_BREAKPOINT)
7876 +DECLARE_CAUSE("misaligned load", CAUSE_MISALIGNED_LOAD)
7877 +DECLARE_CAUSE("fault load", CAUSE_FAULT_LOAD)
7878 +DECLARE_CAUSE("misaligned store", CAUSE_MISALIGNED_STORE)
7879 +DECLARE_CAUSE("fault store", CAUSE_FAULT_STORE)
7880 +DECLARE_CAUSE("user_ecall", CAUSE_USER_ECALL)
7881 +DECLARE_CAUSE("supervisor_ecall", CAUSE_SUPERVISOR_ECALL)
7882 +DECLARE_CAUSE("hypervisor_ecall", CAUSE_HYPERVISOR_ECALL)
7883 +DECLARE_CAUSE("machine_ecall", CAUSE_MACHINE_ECALL)
7884 +#endif
7885 diff -urN empty/ld/emulparams/elf32lriscv-defs.sh binutils-2.26.1/ld/emulparams/elf32lriscv-defs.sh
7886 --- empty/ld/emulparams/elf32lriscv-defs.sh 1970-01-01 08:00:00.000000000 +0800
7887 +++ binutils-2.26.1/ld/emulparams/elf32lriscv-defs.sh 2016-04-03 10:33:12.065459702 +0800
7888 @@ -0,0 +1,48 @@
7889 +# This is an ELF platform.
7890 +SCRIPT_NAME=elf
7891 +ARCH=riscv
7892 +OUTPUT_FORMAT="elf32-littleriscv"
7893 +NO_REL_RELOCS=yes
7895 +TEMPLATE_NAME=elf32
7896 +EXTRA_EM_FILE=riscvelf
7898 +case x"$EMULATION_NAME" in
7899 +xelf32*) ELFSIZE=32; LIBPATH_SUFFIX=32 ;;
7900 +xelf64*) ELFSIZE=64; LIBPATH_SUFFIX= ;;
7901 +x) ;;
7902 +*) echo $0: unhandled emulation $EMULATION_NAME >&2; exit 1 ;;
7903 +esac
7905 +if test `echo "$host" | sed -e s/64//` = `echo "$target" | sed -e s/64//`; then
7906 + case " $EMULATION_LIBPATH " in
7907 + *" ${EMULATION_NAME} "*)
7908 + NATIVE=yes
7909 + ;;
7910 + esac
7913 +GENERATE_SHLIB_SCRIPT=yes
7914 +GENERATE_PIE_SCRIPT=yes
7916 +TEXT_START_ADDR=0x10000
7917 +MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
7918 +COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
7920 +SDATA_START_SYMBOLS="_gp = . + 0x800;
7921 + *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*)"
7923 +# Place the data section before text section. This enables more compact
7924 +# global variable access for RVC code via linker relaxation.
7925 +INITIAL_READONLY_SECTIONS="
7926 + .data : { *(.data) *(.data.*) *(.gnu.linkonce.d.*) }
7927 + .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r.*) }
7928 + .srodata : { ${SDATA_START_SYMBOLS} }
7929 + .sdata : { *(.sdata .sdata.* .gnu.linkonce.s.*) }
7930 + .sbss : { *(.dynsbss) *(.sbss .sbss.* .gnu.linkonce.sb.*) }
7931 + .bss : { *(.dynbss) *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) }
7932 + . = ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1));"
7933 +INITIAL_READONLY_SECTIONS=".interp : { *(.interp) } ${CREATE_PIE-${INITIAL_READONLY_SECTIONS}}"
7934 +INITIAL_READONLY_SECTIONS="${RELOCATING+${CREATE_SHLIB-${INITIAL_READONLY_SECTIONS}}}"
7936 +SDATA_START_SYMBOLS="${CREATE_PIE+${SDATA_START_SYMBOLS}}"
7937 diff -urN empty/ld/emulparams/elf32lriscv.sh binutils-2.26.1/ld/emulparams/elf32lriscv.sh
7938 --- empty/ld/emulparams/elf32lriscv.sh 1970-01-01 08:00:00.000000000 +0800
7939 +++ binutils-2.26.1/ld/emulparams/elf32lriscv.sh 2016-04-02 14:07:12.469104719 +0800
7940 @@ -0,0 +1,2 @@
7941 +. ${srcdir}/emulparams/elf32lriscv-defs.sh
7942 +OUTPUT_FORMAT="elf32-littleriscv"
7943 diff -urN empty/ld/emulparams/elf64lriscv-defs.sh binutils-2.26.1/ld/emulparams/elf64lriscv-defs.sh
7944 --- empty/ld/emulparams/elf64lriscv-defs.sh 1970-01-01 08:00:00.000000000 +0800
7945 +++ binutils-2.26.1/ld/emulparams/elf64lriscv-defs.sh 2016-04-02 14:07:12.469104719 +0800
7946 @@ -0,0 +1 @@
7947 +. ${srcdir}/emulparams/elf32lriscv-defs.sh
7948 diff -urN empty/ld/emulparams/elf64lriscv.sh binutils-2.26.1/ld/emulparams/elf64lriscv.sh
7949 --- empty/ld/emulparams/elf64lriscv.sh 1970-01-01 08:00:00.000000000 +0800
7950 +++ binutils-2.26.1/ld/emulparams/elf64lriscv.sh 2016-04-02 14:07:12.469104719 +0800
7951 @@ -0,0 +1,2 @@
7952 +. ${srcdir}/emulparams/elf64lriscv-defs.sh
7953 +OUTPUT_FORMAT="elf64-littleriscv"
7954 diff -urN empty/ld/emultempl/riscvelf.em binutils-2.26.1/ld/emultempl/riscvelf.em
7955 --- empty/ld/emultempl/riscvelf.em 1970-01-01 08:00:00.000000000 +0800
7956 +++ binutils-2.26.1/ld/emultempl/riscvelf.em 2016-04-03 10:33:12.065459702 +0800
7957 @@ -0,0 +1,68 @@
7958 +# This shell script emits a C file. -*- C -*-
7959 +# Copyright 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
7961 +# This file is part of the GNU Binutils.
7963 +# This program is free software; you can redistribute it and/or modify
7964 +# it under the terms of the GNU General Public License as published by
7965 +# the Free Software Foundation; either version 3 of the License, or
7966 +# (at your option) any later version.
7968 +# This program is distributed in the hope that it will be useful,
7969 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7970 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7971 +# GNU General Public License for more details.
7973 +# You should have received a copy of the GNU General Public License
7974 +# along with this program; if not, write to the Free Software
7975 +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
7976 +# MA 02110-1301, USA.
7978 +fragment <<EOF
7980 +#include "ldmain.h"
7981 +#include "ldctor.h"
7982 +#include "elf/riscv.h"
7983 +#include "elfxx-riscv.h"
7985 +static void
7986 +riscv_elf_before_allocation (void)
7988 + gld${EMULATION_NAME}_before_allocation ();
7990 + if (link_info.discard == discard_sec_merge)
7991 + link_info.discard = discard_l;
7993 + /* We always need at least some relaxation to handle code alignment. */
7994 + if (RELAXATION_DISABLED_BY_USER)
7995 + TARGET_ENABLE_RELAXATION;
7996 + else
7997 + ENABLE_RELAXATION;
7999 + link_info.relax_pass = 2;
8002 +static void
8003 +gld${EMULATION_NAME}_after_allocation (void)
8005 + int need_layout = 0;
8007 + /* Don't attempt to discard unused .eh_frame sections until the final link,
8008 + as we can't reliably tell if they're used until after relaxation. */
8009 + if (!bfd_link_relocatable (&link_info))
8011 + need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
8012 + if (need_layout < 0)
8014 + einfo ("%X%P: .eh_frame/.stab edit: %E\n");
8015 + return;
8019 + gld${EMULATION_NAME}_map_segments (need_layout);
8022 +EOF
8024 +LDEMUL_BEFORE_ALLOCATION=riscv_elf_before_allocation
8025 +LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
8026 diff -urN empty/opcodes/riscv-dis.c binutils-2.26.1/opcodes/riscv-dis.c
8027 --- empty/opcodes/riscv-dis.c 1970-01-01 08:00:00.000000000 +0800
8028 +++ binutils-2.26.1/opcodes/riscv-dis.c 2016-04-03 10:33:12.065459702 +0800
8029 @@ -0,0 +1,521 @@
8030 +/* RISC-V disassembler
8031 + Copyright 2011-2015 Free Software Foundation, Inc.
8033 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
8034 + Based on MIPS target.
8036 + This file is part of the GNU opcodes library.
8038 + This library is free software; you can redistribute it and/or modify
8039 + it under the terms of the GNU General Public License as published by
8040 + the Free Software Foundation; either version 3, or (at your option)
8041 + any later version.
8043 + It is distributed in the hope that it will be useful, but WITHOUT
8044 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8045 + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
8046 + License for more details.
8048 + You should have received a copy of the GNU General Public License
8049 + along with this program; see the file COPYING3. If not,
8050 + see <http://www.gnu.org/licenses/>. */
8052 +#include "sysdep.h"
8053 +#include "dis-asm.h"
8054 +#include "libiberty.h"
8055 +#include "opcode/riscv.h"
8056 +#include "opintl.h"
8057 +#include "elf-bfd.h"
8058 +#include "elf/riscv.h"
8060 +#include <stdint.h>
8061 +#include <ctype.h>
8063 +struct riscv_private_data
8065 + bfd_vma gp;
8066 + bfd_vma print_addr;
8067 + bfd_vma hi_addr[OP_MASK_RD + 1];
8070 +static const char * const *riscv_gpr_names;
8071 +static const char * const *riscv_fpr_names;
8073 +/* Other options */
8074 +static int no_aliases; /* If set disassemble as most general inst. */
8076 +static void
8077 +set_default_riscv_dis_options (void)
8079 + riscv_gpr_names = riscv_gpr_names_abi;
8080 + riscv_fpr_names = riscv_fpr_names_abi;
8081 + no_aliases = 0;
8084 +static void
8085 +parse_riscv_dis_option (const char *option)
8087 + if (CONST_STRNEQ (option, "no-aliases"))
8088 + no_aliases = 1;
8089 + else if (CONST_STRNEQ (option, "numeric"))
8091 + riscv_gpr_names = riscv_gpr_names_numeric;
8092 + riscv_fpr_names = riscv_fpr_names_numeric;
8094 + else
8096 + /* Invalid option. */
8097 + fprintf (stderr, _("Unrecognized disassembler option: %s\n"), option);
8101 +static void
8102 +parse_riscv_dis_options (const char *opts_in)
8104 + char *opts = xstrdup (opts_in), *opt = opts, *opt_end = opts;
8106 + set_default_riscv_dis_options ();
8108 + for ( ; opt_end != NULL; opt = opt_end + 1)
8110 + if ((opt_end = strchr (opt, ',')) != NULL)
8111 + *opt_end = 0;
8112 + parse_riscv_dis_option (opt);
8115 + free (opts);
8118 +/* Print one argument from an array. */
8120 +static void
8121 +arg_print (struct disassemble_info *info, unsigned long val,
8122 + const char* const* array, size_t size)
8124 + const char *s = val >= size || array[val] == NULL ? "unknown" : array[val];
8125 + (*info->fprintf_func) (info->stream, "%s", s);
8128 +static void
8129 +maybe_print_address (struct riscv_private_data *pd, int base_reg, int offset)
8131 + if (pd->hi_addr[base_reg] != (bfd_vma)-1)
8133 + pd->print_addr = pd->hi_addr[base_reg] + offset;
8134 + pd->hi_addr[base_reg] = -1;
8136 + else if (base_reg == X_GP && pd->gp != (bfd_vma)-1)
8137 + pd->print_addr = pd->gp + offset;
8138 + else if (base_reg == X_TP || base_reg == 0)
8139 + pd->print_addr = offset;
8142 +/* Print insn arguments for 32/64-bit code. */
8144 +static void
8145 +print_insn_args (const char *d, insn_t l, bfd_vma pc, disassemble_info *info)
8147 + struct riscv_private_data *pd = info->private_data;
8148 + int rs1 = (l >> OP_SH_RS1) & OP_MASK_RS1;
8149 + int rd = (l >> OP_SH_RD) & OP_MASK_RD;
8150 + fprintf_ftype print = info->fprintf_func;
8152 + if (*d != '\0')
8153 + print (info->stream, "\t");
8155 + for (; *d != '\0'; d++)
8157 + switch (*d)
8159 + /* Xcustom */
8160 + case '^':
8161 + switch (*++d)
8163 + case 'd':
8164 + print (info->stream, "%d", rd);
8165 + break;
8166 + case 's':
8167 + print (info->stream, "%d", rs1);
8168 + break;
8169 + case 't':
8170 + print (info->stream, "%d", (int) EXTRACT_OPERAND (RS2, l));
8171 + break;
8172 + case 'j':
8173 + print (info->stream, "%d", (int) EXTRACT_OPERAND (CUSTOM_IMM, l));
8174 + break;
8176 + break;
8178 + case 'C': /* RVC */
8179 + switch (*++d)
8181 + case 's': /* RS1 x8-x15 */
8182 + case 'w': /* RS1 x8-x15 */
8183 + print (info->stream, "%s",
8184 + riscv_gpr_names[EXTRACT_OPERAND (CRS1S, l) + 8]);
8185 + break;
8186 + case 't': /* RS2 x8-x15 */
8187 + case 'x': /* RS2 x8-x15 */
8188 + print (info->stream, "%s",
8189 + riscv_gpr_names[EXTRACT_OPERAND (CRS2S, l) + 8]);
8190 + break;
8191 + case 'U': /* RS1, constrained to equal RD */
8192 + print (info->stream, "%s", riscv_gpr_names[rd]);
8193 + break;
8194 + case 'c': /* RS1, constrained to equal sp */
8195 + print (info->stream, "%s", riscv_gpr_names[X_SP]);
8196 + break;
8197 + case 'V': /* RS2 */
8198 + print (info->stream, "%s",
8199 + riscv_gpr_names[EXTRACT_OPERAND (CRS2, l)]);
8200 + break;
8201 + case 'i':
8202 + print (info->stream, "%d", (int)EXTRACT_RVC_SIMM3 (l));
8203 + break;
8204 + case 'j':
8205 + print (info->stream, "%d", (int)EXTRACT_RVC_IMM (l));
8206 + break;
8207 + case 'k':
8208 + print (info->stream, "%d", (int)EXTRACT_RVC_LW_IMM (l));
8209 + break;
8210 + case 'l':
8211 + print (info->stream, "%d", (int)EXTRACT_RVC_LD_IMM (l));
8212 + break;
8213 + case 'm':
8214 + print (info->stream, "%d", (int)EXTRACT_RVC_LWSP_IMM (l));
8215 + break;
8216 + case 'n':
8217 + print (info->stream, "%d", (int)EXTRACT_RVC_LDSP_IMM (l));
8218 + break;
8219 + case 'K':
8220 + print (info->stream, "%d", (int)EXTRACT_RVC_ADDI4SPN_IMM (l));
8221 + break;
8222 + case 'L':
8223 + print (info->stream, "%d", (int)EXTRACT_RVC_ADDI16SP_IMM (l));
8224 + break;
8225 + case 'M':
8226 + print (info->stream, "%d", (int)EXTRACT_RVC_SWSP_IMM (l));
8227 + break;
8228 + case 'N':
8229 + print (info->stream, "%d", (int)EXTRACT_RVC_SDSP_IMM (l));
8230 + break;
8231 + case 'p':
8232 + info->target = EXTRACT_RVC_B_IMM (l) + pc;
8233 + (*info->print_address_func) (info->target, info);
8234 + break;
8235 + case 'a':
8236 + info->target = EXTRACT_RVC_J_IMM (l) + pc;
8237 + (*info->print_address_func) (info->target, info);
8238 + break;
8239 + case 'u':
8240 + print (info->stream, "0x%x",
8241 + (int) (EXTRACT_RVC_IMM (l) & (RISCV_BIGIMM_REACH-1)));
8242 + break;
8243 + case '>':
8244 + print (info->stream, "0x%x", (int) EXTRACT_RVC_IMM (l) & 0x3f);
8245 + break;
8246 + case '<':
8247 + print (info->stream, "0x%x", (int) EXTRACT_RVC_IMM (l) & 0x1f);
8248 + break;
8249 + case 'T': /* floating-point RS2 */
8250 + print (info->stream, "%s",
8251 + riscv_fpr_names[EXTRACT_OPERAND (CRS2, l)]);
8252 + break;
8253 + case 'D': /* floating-point RS2 x8-x15 */
8254 + print (info->stream, "%s",
8255 + riscv_fpr_names[EXTRACT_OPERAND (CRS2S, l) + 8]);
8256 + break;
8258 + break;
8260 + case ',':
8261 + case '(':
8262 + case ')':
8263 + case '[':
8264 + case ']':
8265 + print (info->stream, "%c", *d);
8266 + break;
8268 + case '0':
8269 + /* Only print constant 0 if it is the last argument */
8270 + if (!d[1])
8271 + print (info->stream, "0");
8272 + break;
8274 + case 'b':
8275 + case 's':
8276 + print (info->stream, "%s", riscv_gpr_names[rs1]);
8277 + break;
8279 + case 't':
8280 + print (info->stream, "%s",
8281 + riscv_gpr_names[EXTRACT_OPERAND (RS2, l)]);
8282 + break;
8284 + case 'u':
8285 + print (info->stream, "0x%x",
8286 + (unsigned) EXTRACT_UTYPE_IMM (l) >> RISCV_IMM_BITS);
8287 + break;
8289 + case 'm':
8290 + arg_print (info, EXTRACT_OPERAND (RM, l),
8291 + riscv_rm, ARRAY_SIZE (riscv_rm));
8292 + break;
8294 + case 'P':
8295 + arg_print (info, EXTRACT_OPERAND (PRED, l),
8296 + riscv_pred_succ, ARRAY_SIZE (riscv_pred_succ));
8297 + break;
8299 + case 'Q':
8300 + arg_print (info, EXTRACT_OPERAND (SUCC, l),
8301 + riscv_pred_succ, ARRAY_SIZE (riscv_pred_succ));
8302 + break;
8304 + case 'o':
8305 + maybe_print_address (pd, rs1, EXTRACT_ITYPE_IMM (l));
8306 + case 'j':
8307 + if (((l & MASK_ADDI) == MATCH_ADDI && rs1 != 0)
8308 + || (l & MASK_JALR) == MATCH_JALR)
8309 + maybe_print_address (pd, rs1, EXTRACT_ITYPE_IMM (l));
8310 + print (info->stream, "%d", (int) EXTRACT_ITYPE_IMM (l));
8311 + break;
8313 + case 'q':
8314 + maybe_print_address (pd, rs1, EXTRACT_STYPE_IMM (l));
8315 + print (info->stream, "%d", (int) EXTRACT_STYPE_IMM (l));
8316 + break;
8318 + case 'a':
8319 + info->target = EXTRACT_UJTYPE_IMM (l) + pc;
8320 + (*info->print_address_func) (info->target, info);
8321 + break;
8323 + case 'p':
8324 + info->target = EXTRACT_SBTYPE_IMM (l) + pc;
8325 + (*info->print_address_func) (info->target, info);
8326 + break;
8328 + case 'd':
8329 + if ((l & MASK_AUIPC) == MATCH_AUIPC)
8330 + pd->hi_addr[rd] = pc + EXTRACT_UTYPE_IMM (l);
8331 + else if ((l & MASK_LUI) == MATCH_LUI)
8332 + pd->hi_addr[rd] = EXTRACT_UTYPE_IMM (l);
8333 + else if ((l & MASK_C_LUI) == MATCH_C_LUI)
8334 + pd->hi_addr[rd] = EXTRACT_RVC_LUI_IMM (l);
8335 + print (info->stream, "%s", riscv_gpr_names[rd]);
8336 + break;
8338 + case 'z':
8339 + print (info->stream, "%s", riscv_gpr_names[0]);
8340 + break;
8342 + case '>':
8343 + print (info->stream, "0x%x", (int) EXTRACT_OPERAND (SHAMT, l));
8344 + break;
8346 + case '<':
8347 + print (info->stream, "0x%x", (int) EXTRACT_OPERAND (SHAMTW, l));
8348 + break;
8350 + case 'S':
8351 + case 'U':
8352 + print (info->stream, "%s", riscv_fpr_names[rs1]);
8353 + break;
8355 + case 'T':
8356 + print (info->stream, "%s", riscv_fpr_names[EXTRACT_OPERAND (RS2, l)]);
8357 + break;
8359 + case 'D':
8360 + print (info->stream, "%s", riscv_fpr_names[rd]);
8361 + break;
8363 + case 'R':
8364 + print (info->stream, "%s", riscv_fpr_names[EXTRACT_OPERAND (RS3, l)]);
8365 + break;
8367 + case 'E':
8369 + const char* csr_name = NULL;
8370 + unsigned int csr = EXTRACT_OPERAND (CSR, l);
8371 + switch (csr)
8373 + #define DECLARE_CSR(name, num) case num: csr_name = #name; break;
8374 + #include "opcode/riscv-opc.h"
8375 + #undef DECLARE_CSR
8377 + if (csr_name)
8378 + print (info->stream, "%s", csr_name);
8379 + else
8380 + print (info->stream, "0x%x", csr);
8381 + break;
8384 + case 'Z':
8385 + print (info->stream, "%d", rs1);
8386 + break;
8388 + default:
8389 + /* xgettext:c-format */
8390 + print (info->stream, _("# internal error, undefined modifier (%c)"),
8391 + *d);
8392 + return;
8397 +/* Print the RISC-V instruction at address MEMADDR in debugged memory,
8398 + on using INFO. Returns length of the instruction, in bytes.
8399 + BIGENDIAN must be 1 if this is big-endian code, 0 if
8400 + this is little-endian code. */
8402 +static int
8403 +riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info)
8405 + const struct riscv_opcode *op;
8406 + static bfd_boolean init = 0;
8407 + static const struct riscv_opcode *riscv_hash[OP_MASK_OP + 1];
8408 + struct riscv_private_data *pd;
8409 + int insnlen;
8411 +#define OP_HASH_IDX(i) ((i) & (riscv_insn_length (i) == 2 ? 0x3 : OP_MASK_OP))
8413 + /* Build a hash table to shorten the search time. */
8414 + if (! init)
8416 + for (op = riscv_opcodes; op < &riscv_opcodes[NUMOPCODES]; op++)
8417 + if (!riscv_hash[OP_HASH_IDX (op->match)])
8418 + riscv_hash[OP_HASH_IDX (op->match)] = op;
8420 + init = 1;
8423 + if (info->private_data == NULL)
8425 + int i;
8427 + pd = info->private_data = xcalloc (1, sizeof (struct riscv_private_data));
8428 + pd->gp = -1;
8429 + pd->print_addr = -1;
8430 + for (i = 0; i < (int) ARRAY_SIZE (pd->hi_addr); i++)
8431 + pd->hi_addr[i] = -1;
8433 + for (i = 0; i < info->symtab_size; i++)
8434 + if (strcmp (bfd_asymbol_name (info->symtab[i]), "_gp") == 0)
8435 + pd->gp = bfd_asymbol_value (info->symtab[i]);
8437 + else
8438 + pd = info->private_data;
8440 + insnlen = riscv_insn_length (word);
8442 + info->bytes_per_chunk = insnlen % 4 == 0 ? 4 : 2;
8443 + info->bytes_per_line = 8;
8444 + info->display_endian = info->endian;
8445 + info->insn_info_valid = 1;
8446 + info->branch_delay_insns = 0;
8447 + info->data_size = 0;
8448 + info->insn_type = dis_nonbranch;
8449 + info->target = 0;
8450 + info->target2 = 0;
8452 + op = riscv_hash[OP_HASH_IDX (word)];
8453 + if (op != NULL)
8455 + int xlen = 0;
8457 + /* The incoming section might not always be complete. */
8458 + if (info->section != NULL)
8460 + Elf_Internal_Ehdr *ehdr = elf_elfheader (info->section->owner);
8461 + xlen = ehdr->e_ident[EI_CLASS] == ELFCLASS64 ? 64 : 32;
8464 + for (; op < &riscv_opcodes[NUMOPCODES]; op++)
8466 + /* Does the opcode match? */
8467 + if (! (op->match_func) (op, word))
8468 + continue;
8469 + /* Is this a pseudo-instruction and may we print it as such? */
8470 + if (no_aliases && (op->pinfo & INSN_ALIAS))
8471 + continue;
8472 + /* Is this instruction restricted to a certain value of XLEN? */
8473 + if (isdigit (op->subset[0]) && atoi (op->subset) != xlen)
8474 + continue;
8476 + /* It's a match. */
8477 + (*info->fprintf_func) (info->stream, "%s", op->name);
8478 + print_insn_args (op->args, word, memaddr, info);
8480 + /* Try to disassemble multi-instruction addressing sequences. */
8481 + if (pd->print_addr != (bfd_vma)-1)
8483 + info->target = pd->print_addr;
8484 + (*info->fprintf_func) (info->stream, " # ");
8485 + (*info->print_address_func) (info->target, info);
8486 + pd->print_addr = -1;
8489 + return insnlen;
8493 + /* We did not find a match, so just print the instruction bits. */
8494 + info->insn_type = dis_noninsn;
8495 + (*info->fprintf_func) (info->stream, "0x%llx", (unsigned long long)word);
8496 + return insnlen;
8499 +int
8500 +print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
8502 + bfd_byte packet[2];
8503 + insn_t insn = 0;
8504 + bfd_vma n;
8505 + int status;
8507 + if (info->disassembler_options != NULL)
8509 + parse_riscv_dis_options (info->disassembler_options);
8510 + /* Avoid repeatedly parsing the options. */
8511 + info->disassembler_options = NULL;
8513 + else if (riscv_gpr_names == NULL)
8514 + set_default_riscv_dis_options ();
8516 + /* Instructions are a sequence of 2-byte packets in little-endian order. */
8517 + for (n = 0; n < sizeof (insn) && n < riscv_insn_length (insn); n += 2)
8519 + status = (*info->read_memory_func) (memaddr + n, packet, 2, info);
8520 + if (status != 0)
8522 + /* Don't fail just because we fell off the end. */
8523 + if (n > 0)
8524 + break;
8525 + (*info->memory_error_func) (status, memaddr, info);
8526 + return status;
8529 + insn |= ((insn_t) bfd_getl16 (packet)) << (8 * n);
8532 + return riscv_disassemble_insn (memaddr, insn, info);
8535 +void
8536 +print_riscv_disassembler_options (FILE *stream)
8538 + fprintf (stream, _("\n\
8539 +The following RISC-V-specific disassembler options are supported for use\n\
8540 +with the -M switch (multiple options should be separated by commas):\n"));
8542 + fprintf (stream, _("\n\
8543 + numeric Print numeric reigster names, rather than ABI names.\n"));
8545 + fprintf (stream, _("\n\
8546 + no-aliases Disassemble only into canonical instructions, rather\n\
8547 + than into pseudoinstructions.\n"));
8549 + fprintf (stream, _("\n"));
8551 diff -urN empty/opcodes/riscv-opc.c binutils-2.26.1/opcodes/riscv-opc.c
8552 --- empty/opcodes/riscv-opc.c 1970-01-01 08:00:00.000000000 +0800
8553 +++ binutils-2.26.1/opcodes/riscv-opc.c 2016-04-16 11:38:25.314563423 +0800
8554 @@ -0,0 +1,647 @@
8555 +/* RISC-V opcode list
8556 + Copyright 2011-2015 Free Software Foundation, Inc.
8558 + Contributed by Andrew Waterman (waterman@cs.berkeley.edu) at UC Berkeley.
8559 + Based on MIPS target.
8561 + This file is part of the GNU opcodes library.
8563 + This library is free software; you can redistribute it and/or modify
8564 + it under the terms of the GNU General Public License as published by
8565 + the Free Software Foundation; either version 3, or (at your option)
8566 + any later version.
8568 + It is distributed in the hope that it will be useful, but WITHOUT
8569 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8570 + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
8571 + License for more details.
8573 + You should have received a copy of the GNU General Public License
8574 + along with this program; see the file COPYING3. If not,
8575 + see <http://www.gnu.org/licenses/>. */
8577 +#include "sysdep.h"
8578 +#include "opcode/riscv.h"
8579 +#include <stdio.h>
8581 +/* Register names used by gas and objdump. */
8583 +const char * const riscv_gpr_names_numeric[32] =
8585 + "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8586 + "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8587 + "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8588 + "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31"
8591 +const char * const riscv_gpr_names_abi[32] = {
8592 + "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
8593 + "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
8594 + "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
8595 + "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"
8598 +const char * const riscv_fpr_names_numeric[32] =
8600 + "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
8601 + "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
8602 + "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
8603 + "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
8606 +const char * const riscv_fpr_names_abi[32] = {
8607 + "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7",
8608 + "fs0", "fs1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5",
8609 + "fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
8610 + "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"
8613 +/* The order of overloaded instructions matters. Label arguments and
8614 + register arguments look the same. Instructions that can have either
8615 + for arguments must apear in the correct order in this table for the
8616 + assembler to pick the right one. In other words, entries with
8617 + immediate operands must apear after the same instruction with
8618 + registers.
8620 + Because of the lookup algorithm used, entries with the same opcode
8621 + name must be contiguous. */
8623 +#define MASK_RS1 (OP_MASK_RS1 << OP_SH_RS1)
8624 +#define MASK_RS2 (OP_MASK_RS2 << OP_SH_RS2)
8625 +#define MASK_RD (OP_MASK_RD << OP_SH_RD)
8626 +#define MASK_CRS2 (OP_MASK_CRS2 << OP_SH_CRS2)
8627 +#define MASK_IMM ENCODE_ITYPE_IMM(-1U)
8628 +#define MASK_RVC_IMM ENCODE_RVC_IMM(-1U)
8629 +#define MASK_UIMM ENCODE_UTYPE_IMM(-1U)
8630 +#define MASK_RM (OP_MASK_RM << OP_SH_RM)
8631 +#define MASK_PRED (OP_MASK_PRED << OP_SH_PRED)
8632 +#define MASK_SUCC (OP_MASK_SUCC << OP_SH_SUCC)
8633 +#define MASK_AQ (OP_MASK_AQ << OP_SH_AQ)
8634 +#define MASK_RL (OP_MASK_RL << OP_SH_RL)
8635 +#define MASK_AQRL (MASK_AQ | MASK_RL)
8637 +static int match_opcode(const struct riscv_opcode *op, insn_t insn)
8639 + return ((insn ^ op->match) & op->mask) == 0;
8642 +static int match_never(const struct riscv_opcode *op ATTRIBUTE_UNUSED,
8643 + insn_t insn ATTRIBUTE_UNUSED)
8645 + return 0;
8648 +static int match_rs1_eq_rs2(const struct riscv_opcode *op, insn_t insn)
8650 + int rs1 = (insn & MASK_RS1) >> OP_SH_RS1;
8651 + int rs2 = (insn & MASK_RS2) >> OP_SH_RS2;
8652 + return match_opcode (op, insn) && rs1 == rs2;
8655 +static int match_rd_nonzero(const struct riscv_opcode *op, insn_t insn)
8657 + return match_opcode (op, insn) && ((insn & MASK_RD) != 0);
8660 +static int match_c_add(const struct riscv_opcode *op, insn_t insn)
8662 + return match_rd_nonzero (op, insn) && ((insn & MASK_CRS2) != 0);
8665 +static int match_c_lui(const struct riscv_opcode *op, insn_t insn)
8667 + return match_rd_nonzero (op, insn) && (((insn & MASK_RD) >> OP_SH_RD) != 2);
8670 +const struct riscv_opcode riscv_builtin_opcodes[] =
8672 +/* name, isa, operands, match, mask, match_func, pinfo */
8673 +{"unimp", "C", "", 0, 0xffffU, match_opcode, 0 },
8674 +{"unimp", "I", "", MATCH_CSRRW | (CSR_CYCLE << OP_SH_CSR), 0xffffffffU, match_opcode, 0 }, /* csrw cycle, x0 */
8675 +{"ebreak", "C", "", MATCH_C_EBREAK, MASK_C_EBREAK, match_opcode, INSN_ALIAS },
8676 +{"ebreak", "I", "", MATCH_EBREAK, MASK_EBREAK, match_opcode, 0 },
8677 +{"sbreak", "C", "", MATCH_C_EBREAK, MASK_C_EBREAK, match_opcode, INSN_ALIAS },
8678 +{"sbreak", "I", "", MATCH_EBREAK, MASK_EBREAK, match_opcode, INSN_ALIAS },
8679 +{"ret", "C", "", MATCH_C_JR | (X_RA << OP_SH_RD), MASK_C_JR | MASK_RD, match_opcode, INSN_ALIAS },
8680 +{"ret", "I", "", MATCH_JALR | (X_RA << OP_SH_RS1), MASK_JALR | MASK_RD | MASK_RS1 | MASK_IMM, match_opcode, INSN_ALIAS },
8681 +{"jr", "C", "d", MATCH_C_JR, MASK_C_JR, match_rd_nonzero, INSN_ALIAS },
8682 +{"jr", "I", "s", MATCH_JALR, MASK_JALR | MASK_RD | MASK_IMM, match_opcode, INSN_ALIAS },
8683 +{"jr", "I", "s,j", MATCH_JALR, MASK_JALR | MASK_RD, match_opcode, INSN_ALIAS },
8684 +{"jalr", "C", "d", MATCH_C_JALR, MASK_C_JALR, match_rd_nonzero, INSN_ALIAS },
8685 +{"jalr", "I", "s", MATCH_JALR | (X_RA << OP_SH_RD), MASK_JALR | MASK_RD | MASK_IMM, match_opcode, INSN_ALIAS },
8686 +{"jalr", "I", "s,j", MATCH_JALR | (X_RA << OP_SH_RD), MASK_JALR | MASK_RD, match_opcode, INSN_ALIAS },
8687 +{"jalr", "I", "d,s", MATCH_JALR, MASK_JALR | MASK_IMM, match_opcode, INSN_ALIAS },
8688 +{"jalr", "I", "d,s,j", MATCH_JALR, MASK_JALR, match_opcode, 0 },
8689 +{"j", "C", "Ca", MATCH_C_J, MASK_C_J, match_opcode, INSN_ALIAS },
8690 +{"j", "I", "a", MATCH_JAL, MASK_JAL | MASK_RD, match_opcode, INSN_ALIAS },
8691 +{"jal", "32C", "Ca", MATCH_C_JAL, MASK_C_JAL, match_opcode, INSN_ALIAS },
8692 +{"jal", "I", "a", MATCH_JAL | (X_RA << OP_SH_RD), MASK_JAL | MASK_RD, match_opcode, INSN_ALIAS },
8693 +{"jal", "I", "d,a", MATCH_JAL, MASK_JAL, match_opcode, 0 },
8694 +{"call", "I", "c", (X_T1 << OP_SH_RS1) | (X_RA << OP_SH_RD), (int) M_CALL, match_never, INSN_MACRO },
8695 +{"call", "I", "d,c", (X_T1 << OP_SH_RS1), (int) M_CALL, match_never, INSN_MACRO },
8696 +{"tail", "I", "c", (X_T1 << OP_SH_RS1), (int) M_CALL, match_never, INSN_MACRO },
8697 +{"jump", "I", "c,s", 0, (int) M_CALL, match_never, INSN_MACRO },
8698 +{"nop", "C", "", MATCH_C_ADDI, 0xffff, match_opcode, INSN_ALIAS },
8699 +{"nop", "I", "", MATCH_ADDI, MASK_ADDI | MASK_RD | MASK_RS1 | MASK_IMM, match_opcode, INSN_ALIAS },
8700 +{"lui", "C", "d,Cu", MATCH_C_LUI, MASK_C_LUI, match_c_lui, INSN_ALIAS },
8701 +{"lui", "I", "d,u", MATCH_LUI, MASK_LUI, match_opcode, 0 },
8702 +{"li", "C", "d,Cv", MATCH_C_LUI, MASK_C_LUI, match_c_lui, INSN_ALIAS },
8703 +{"li", "C", "d,Cj", MATCH_C_LI, MASK_C_LI, match_rd_nonzero, INSN_ALIAS },
8704 +{"li", "C", "d,0", MATCH_C_LI, MASK_C_LI | MASK_RVC_IMM, match_rd_nonzero, INSN_ALIAS },
8705 +{"li", "I", "d,j", MATCH_ADDI, MASK_ADDI | MASK_RS1, match_opcode, INSN_ALIAS }, /* addi */
8706 +{"li", "I", "d,I", 0, (int) M_LI, match_never, INSN_MACRO },
8707 +{"mv", "C", "d,CV", MATCH_C_MV, MASK_C_MV, match_c_add, INSN_ALIAS },
8708 +{"mv", "I", "d,s", MATCH_ADDI, MASK_ADDI | MASK_IMM, match_opcode, INSN_ALIAS },
8709 +{"move", "C", "d,CV", MATCH_C_MV, MASK_C_MV, match_c_add, INSN_ALIAS },
8710 +{"move", "I", "d,s", MATCH_ADDI, MASK_ADDI | MASK_IMM, match_opcode, INSN_ALIAS },
8711 +{"andi", "C", "Cs,Cw,Cj", MATCH_C_ANDI, MASK_C_ANDI, match_opcode, INSN_ALIAS },
8712 +{"andi", "I", "d,s,j", MATCH_ANDI, MASK_ANDI, match_opcode, 0 },
8713 +{"and", "C", "Cs,Cw,Ct", MATCH_C_AND, MASK_C_AND, match_opcode, INSN_ALIAS },
8714 +{"and", "C", "Cs,Ct,Cw", MATCH_C_AND, MASK_C_AND, match_opcode, INSN_ALIAS },
8715 +{"and", "C", "Cs,Cw,Cj", MATCH_C_ANDI, MASK_C_ANDI, match_opcode, INSN_ALIAS },
8716 +{"and", "I", "d,s,t", MATCH_AND, MASK_AND, match_opcode, 0 },
8717 +{"and", "I", "d,s,j", MATCH_ANDI, MASK_ANDI, match_opcode, INSN_ALIAS },
8718 +{"beqz", "C", "Cs,Cp", MATCH_C_BEQZ, MASK_C_BEQZ, match_opcode, INSN_ALIAS },
8719 +{"beqz", "I", "s,p", MATCH_BEQ, MASK_BEQ | MASK_RS2, match_opcode, INSN_ALIAS },
8720 +{"beq", "I", "s,t,p", MATCH_BEQ, MASK_BEQ, match_opcode, 0 },
8721 +{"blez", "I", "t,p", MATCH_BGE, MASK_BGE | MASK_RS1, match_opcode, INSN_ALIAS },
8722 +{"bgez", "I", "s,p", MATCH_BGE, MASK_BGE | MASK_RS2, match_opcode, INSN_ALIAS },
8723 +{"ble", "I", "t,s,p", MATCH_BGE, MASK_BGE, match_opcode, INSN_ALIAS },
8724 +{"bleu", "I", "t,s,p", MATCH_BGEU, MASK_BGEU, match_opcode, INSN_ALIAS },
8725 +{"bge", "I", "s,t,p", MATCH_BGE, MASK_BGE, match_opcode, 0 },
8726 +{"bgeu", "I", "s,t,p", MATCH_BGEU, MASK_BGEU, match_opcode, 0 },
8727 +{"bltz", "I", "s,p", MATCH_BLT, MASK_BLT | MASK_RS2, match_opcode, INSN_ALIAS },
8728 +{"bgtz", "I", "t,p", MATCH_BLT, MASK_BLT | MASK_RS1, match_opcode, INSN_ALIAS },
8729 +{"blt", "I", "s,t,p", MATCH_BLT, MASK_BLT, match_opcode, 0 },
8730 +{"bltu", "I", "s,t,p", MATCH_BLTU, MASK_BLTU, match_opcode, 0 },
8731 +{"bgt", "I", "t,s,p", MATCH_BLT, MASK_BLT, match_opcode, INSN_ALIAS },
8732 +{"bgtu", "I", "t,s,p", MATCH_BLTU, MASK_BLTU, match_opcode, INSN_ALIAS },
8733 +{"bnez", "C", "Cs,Cp", MATCH_C_BNEZ, MASK_C_BNEZ, match_opcode, INSN_ALIAS },
8734 +{"bnez", "I", "s,p", MATCH_BNE, MASK_BNE | MASK_RS2, match_opcode, INSN_ALIAS },
8735 +{"bne", "I", "s,t,p", MATCH_BNE, MASK_BNE, match_opcode, 0 },
8736 +{"addi", "C", "Ct,Cc,CK", MATCH_C_ADDI4SPN, MASK_C_ADDI4SPN, match_opcode, INSN_ALIAS },
8737 +{"addi", "C", "d,CU,Cj", MATCH_C_ADDI, MASK_C_ADDI, match_rd_nonzero, INSN_ALIAS },
8738 +{"addi", "C", "Cc,Cc,CL", MATCH_C_ADDI16SP, MASK_C_ADDI16SP, match_opcode, INSN_ALIAS },
8739 +{"addi", "I", "d,s,j", MATCH_ADDI, MASK_ADDI, match_opcode, 0 },
8740 +{"add", "C", "d,CU,CV", MATCH_C_ADD, MASK_C_ADD, match_c_add, INSN_ALIAS },
8741 +{"add", "C", "d,CV,CU", MATCH_C_ADD, MASK_C_ADD, match_c_add, INSN_ALIAS },
8742 +{"add", "C", "d,CU,Cj", MATCH_C_ADDI, MASK_C_ADDI, match_rd_nonzero, INSN_ALIAS },
8743 +{"add", "C", "Ct,Cc,CK", MATCH_C_ADDI4SPN, MASK_C_ADDI4SPN, match_opcode, INSN_ALIAS },
8744 +{"add", "C", "Cc,Cc,CL", MATCH_C_ADDI16SP, MASK_C_ADDI16SP, match_opcode, INSN_ALIAS },
8745 +{"add", "I", "d,s,t", MATCH_ADD, MASK_ADD, match_opcode, 0 },
8746 +{"add", "I", "d,s,t,0",MATCH_ADD, MASK_ADD, match_opcode, 0 },
8747 +{"add", "I", "d,s,j", MATCH_ADDI, MASK_ADDI, match_opcode, INSN_ALIAS },
8748 +{"la", "I", "d,A", 0, (int) M_LA, match_never, INSN_MACRO },
8749 +{"lla", "I", "d,A", 0, (int) M_LLA, match_never, INSN_MACRO },
8750 +{"la.tls.gd", "I", "d,A", 0, (int) M_LA_TLS_GD, match_never, INSN_MACRO },
8751 +{"la.tls.ie", "I", "d,A", 0, (int) M_LA_TLS_IE, match_never, INSN_MACRO },
8752 +{"neg", "I", "d,t", MATCH_SUB, MASK_SUB | MASK_RS1, match_opcode, INSN_ALIAS }, /* sub 0 */
8753 +{"slli", "C", "d,CU,C>", MATCH_C_SLLI, MASK_C_SLLI, match_rd_nonzero, INSN_ALIAS },
8754 +{"slli", "I", "d,s,>", MATCH_SLLI, MASK_SLLI, match_opcode, 0 },
8755 +{"sll", "C", "d,CU,C>", MATCH_C_SLLI, MASK_C_SLLI, match_rd_nonzero, INSN_ALIAS },
8756 +{"sll", "I", "d,s,t", MATCH_SLL, MASK_SLL, match_opcode, 0 },
8757 +{"sll", "I", "d,s,>", MATCH_SLLI, MASK_SLLI, match_opcode, INSN_ALIAS },
8758 +{"srli", "C", "Cs,Cw,C>", MATCH_C_SRLI, MASK_C_SRLI, match_rd_nonzero, INSN_ALIAS },
8759 +{"srli", "I", "d,s,>", MATCH_SRLI, MASK_SRLI, match_opcode, 0 },
8760 +{"srl", "C", "Cs,Cw,C>", MATCH_C_SRLI, MASK_C_SRLI, match_rd_nonzero, INSN_ALIAS },
8761 +{"srl", "I", "d,s,t", MATCH_SRL, MASK_SRL, match_opcode, 0 },
8762 +{"srl", "I", "d,s,>", MATCH_SRLI, MASK_SRLI, match_opcode, INSN_ALIAS },
8763 +{"srai", "C", "Cs,Cw,C>", MATCH_C_SRAI, MASK_C_SRAI, match_rd_nonzero, INSN_ALIAS },
8764 +{"srai", "I", "d,s,>", MATCH_SRAI, MASK_SRAI, match_opcode, 0 },
8765 +{"sra", "C", "Cs,Cw,C>", MATCH_C_SRAI, MASK_C_SRAI, match_rd_nonzero, INSN_ALIAS },
8766 +{"sra", "I", "d,s,t", MATCH_SRA, MASK_SRA, match_opcode, 0 },
8767 +{"sra", "I", "d,s,>", MATCH_SRAI, MASK_SRAI, match_opcode, INSN_ALIAS },
8768 +{"sub", "C", "Cs,Cw,Ct", MATCH_C_SUB, MASK_C_SUB, match_opcode, INSN_ALIAS },
8769 +{"sub", "I", "d,s,t", MATCH_SUB, MASK_SUB, match_opcode, 0 },
8770 +{"lb", "I", "d,o(s)", MATCH_LB, MASK_LB, match_opcode, 0 },
8771 +{"lb", "I", "d,A", 0, (int) M_LB, match_never, INSN_MACRO },
8772 +{"lbu", "I", "d,o(s)", MATCH_LBU, MASK_LBU, match_opcode, 0 },
8773 +{"lbu", "I", "d,A", 0, (int) M_LBU, match_never, INSN_MACRO },
8774 +{"lh", "I", "d,o(s)", MATCH_LH, MASK_LH, match_opcode, 0 },
8775 +{"lh", "I", "d,A", 0, (int) M_LH, match_never, INSN_MACRO },
8776 +{"lhu", "I", "d,o(s)", MATCH_LHU, MASK_LHU, match_opcode, 0 },
8777 +{"lhu", "I", "d,A", 0, (int) M_LHU, match_never, INSN_MACRO },
8778 +{"lw", "C", "d,Cm(Cc)", MATCH_C_LWSP, MASK_C_LWSP, match_rd_nonzero, INSN_ALIAS },
8779 +{"lw", "C", "Ct,Ck(Cs)", MATCH_C_LW, MASK_C_LW, match_opcode, INSN_ALIAS },
8780 +{"lw", "I", "d,o(s)", MATCH_LW, MASK_LW, match_opcode, 0 },
8781 +{"lw", "I", "d,A", 0, (int) M_LW, match_never, INSN_MACRO },
8782 +{"not", "I", "d,s", MATCH_XORI | MASK_IMM, MASK_XORI | MASK_IMM, match_opcode, INSN_ALIAS },
8783 +{"ori", "I", "d,s,j", MATCH_ORI, MASK_ORI, match_opcode, 0 },
8784 +{"or", "C", "Cs,Cw,Ct", MATCH_C_OR, MASK_C_OR, match_opcode, INSN_ALIAS },
8785 +{"or", "C", "Cs,Ct,Cw", MATCH_C_OR, MASK_C_OR, match_opcode, INSN_ALIAS },
8786 +{"or", "I", "d,s,t", MATCH_OR, MASK_OR, match_opcode, 0 },
8787 +{"or", "I", "d,s,j", MATCH_ORI, MASK_ORI, match_opcode, INSN_ALIAS },
8788 +{"auipc", "I", "d,u", MATCH_AUIPC, MASK_AUIPC, match_opcode, 0 },
8789 +{"seqz", "I", "d,s", MATCH_SLTIU | ENCODE_ITYPE_IMM(1), MASK_SLTIU | MASK_IMM, match_opcode, INSN_ALIAS },
8790 +{"snez", "I", "d,t", MATCH_SLTU, MASK_SLTU | MASK_RS1, match_opcode, INSN_ALIAS },
8791 +{"sltz", "I", "d,s", MATCH_SLT, MASK_SLT | MASK_RS2, match_opcode, INSN_ALIAS },
8792 +{"sgtz", "I", "d,t", MATCH_SLT, MASK_SLT | MASK_RS1, match_opcode, INSN_ALIAS },
8793 +{"slti", "I", "d,s,j", MATCH_SLTI, MASK_SLTI, match_opcode, INSN_ALIAS },
8794 +{"slt", "I", "d,s,t", MATCH_SLT, MASK_SLT, match_opcode, 0 },
8795 +{"slt", "I", "d,s,j", MATCH_SLTI, MASK_SLTI, match_opcode, 0 },
8796 +{"sltiu", "I", "d,s,j", MATCH_SLTIU, MASK_SLTIU, match_opcode, 0 },
8797 +{"sltu", "I", "d,s,t", MATCH_SLTU, MASK_SLTU, match_opcode, 0 },
8798 +{"sltu", "I", "d,s,j", MATCH_SLTIU, MASK_SLTIU, match_opcode, INSN_ALIAS },
8799 +{"sgt", "I", "d,t,s", MATCH_SLT, MASK_SLT, match_opcode, INSN_ALIAS },
8800 +{"sgtu", "I", "d,t,s", MATCH_SLTU, MASK_SLTU, match_opcode, INSN_ALIAS },
8801 +{"sb", "I", "t,q(s)", MATCH_SB, MASK_SB, match_opcode, 0 },
8802 +{"sb", "I", "t,A,s", 0, (int) M_SB, match_never, INSN_MACRO },
8803 +{"sh", "I", "t,q(s)", MATCH_SH, MASK_SH, match_opcode, 0 },
8804 +{"sh", "I", "t,A,s", 0, (int) M_SH, match_never, INSN_MACRO },
8805 +{"sw", "C", "CV,CM(Cc)", MATCH_C_SWSP, MASK_C_SWSP, match_opcode, INSN_ALIAS },
8806 +{"sw", "C", "Ct,Ck(Cs)", MATCH_C_SW, MASK_C_SW, match_opcode, INSN_ALIAS },
8807 +{"sw", "I", "t,q(s)", MATCH_SW, MASK_SW, match_opcode, 0 },
8808 +{"sw", "I", "t,A,s", 0, (int) M_SW, match_never, INSN_MACRO },
8809 +{"fence", "I", "", MATCH_FENCE | MASK_PRED | MASK_SUCC, MASK_FENCE | MASK_RD | MASK_RS1 | MASK_IMM, match_opcode, INSN_ALIAS },
8810 +{"fence", "I", "P,Q", MATCH_FENCE, MASK_FENCE | MASK_RD | MASK_RS1 | (MASK_IMM & ~MASK_PRED & ~MASK_SUCC), match_opcode, 0 },
8811 +{"fence.i", "I", "", MATCH_FENCE_I, MASK_FENCE | MASK_RD | MASK_RS1 | MASK_IMM, match_opcode, 0 },
8812 +{"rdcycle", "I", "d", MATCH_RDCYCLE, MASK_RDCYCLE, match_opcode, 0 },
8813 +{"rdinstret", "I", "d", MATCH_RDINSTRET, MASK_RDINSTRET, match_opcode, 0 },
8814 +{"rdtime", "I", "d", MATCH_RDTIME, MASK_RDTIME, match_opcode, 0 },
8815 +{"rdcycleh", "32I", "d", MATCH_RDCYCLEH, MASK_RDCYCLEH, match_opcode, 0 },
8816 +{"rdinstreth","32I", "d", MATCH_RDINSTRETH, MASK_RDINSTRETH, match_opcode, 0 },
8817 +{"rdtimeh", "32I", "d", MATCH_RDTIMEH, MASK_RDTIMEH, match_opcode, 0 },
8818 +{"ecall", "I", "", MATCH_SCALL, MASK_SCALL, match_opcode, 0 },
8819 +{"scall", "I", "", MATCH_SCALL, MASK_SCALL, match_opcode, 0 },
8820 +{"xori", "I", "d,s,j", MATCH_XORI, MASK_XORI, match_opcode, 0 },
8821 +{"xor", "C", "Cs,Cw,Ct", MATCH_C_XOR, MASK_C_XOR, match_opcode, INSN_ALIAS },
8822 +{"xor", "C", "Cs,Ct,Cw", MATCH_C_XOR, MASK_C_XOR, match_opcode, INSN_ALIAS },
8823 +{"xor", "I", "d,s,t", MATCH_XOR, MASK_XOR, match_opcode, 0 },
8824 +{"xor", "I", "d,s,j", MATCH_XORI, MASK_XORI, match_opcode, INSN_ALIAS },
8825 +{"lwu", "64I", "d,o(s)", MATCH_LWU, MASK_LWU, match_opcode, 0 },
8826 +{"lwu", "64I", "d,A", 0, (int) M_LWU, match_never, INSN_MACRO },
8827 +{"ld", "64C", "d,Cn(Cc)", MATCH_C_LDSP, MASK_C_LDSP, match_rd_nonzero, INSN_ALIAS },
8828 +{"ld", "64C", "Ct,Cl(Cs)", MATCH_C_LD, MASK_C_LD, match_opcode, INSN_ALIAS },
8829 +{"ld", "64I", "d,o(s)", MATCH_LD, MASK_LD, match_opcode, 0 },
8830 +{"ld", "64I", "d,A", 0, (int) M_LD, match_never, INSN_MACRO },
8831 +{"sd", "64C", "CV,CN(Cc)", MATCH_C_SDSP, MASK_C_SDSP, match_opcode, INSN_ALIAS },
8832 +{"sd", "64C", "Ct,Cl(Cs)", MATCH_C_SD, MASK_C_SD, match_opcode, INSN_ALIAS },
8833 +{"sd", "64I", "t,q(s)", MATCH_SD, MASK_SD, match_opcode, 0 },
8834 +{"sd", "64I", "t,A,s", 0, (int) M_SD, match_never, INSN_MACRO },
8835 +{"sext.w", "64C", "d,CU", MATCH_C_ADDIW, MASK_C_ADDIW | MASK_RVC_IMM, match_rd_nonzero, INSN_ALIAS },
8836 +{"sext.w", "64I", "d,s", MATCH_ADDIW, MASK_ADDIW | MASK_IMM, match_opcode, INSN_ALIAS },
8837 +{"addiw", "64C", "d,CU,Cj", MATCH_C_ADDIW, MASK_C_ADDIW, match_rd_nonzero, INSN_ALIAS },
8838 +{"addiw", "64I", "d,s,j", MATCH_ADDIW, MASK_ADDIW, match_opcode, 0 },
8839 +{"addw", "64C", "Cs,Cw,Ct", MATCH_C_ADDW, MASK_C_ADDW, match_opcode, INSN_ALIAS },
8840 +{"addw", "64C", "Cs,Ct,Cw", MATCH_C_ADDW, MASK_C_ADDW, match_opcode, INSN_ALIAS },
8841 +{"addw", "64C", "d,CU,Cj", MATCH_C_ADDIW, MASK_C_ADDIW, match_rd_nonzero, INSN_ALIAS },
8842 +{"addw", "64I", "d,s,t", MATCH_ADDW, MASK_ADDW, match_opcode, 0 },
8843 +{"addw", "64I", "d,s,j", MATCH_ADDIW, MASK_ADDIW, match_opcode, INSN_ALIAS },
8844 +{"negw", "64I", "d,t", MATCH_SUBW, MASK_SUBW | MASK_RS1, match_opcode, INSN_ALIAS }, /* sub 0 */
8845 +{"slliw", "64I", "d,s,<", MATCH_SLLIW, MASK_SLLIW, match_opcode, 0 },
8846 +{"sllw", "64I", "d,s,t", MATCH_SLLW, MASK_SLLW, match_opcode, 0 },
8847 +{"sllw", "64I", "d,s,<", MATCH_SLLIW, MASK_SLLIW, match_opcode, INSN_ALIAS },
8848 +{"srliw", "64I", "d,s,<", MATCH_SRLIW, MASK_SRLIW, match_opcode, 0 },
8849 +{"srlw", "64I", "d,s,t", MATCH_SRLW, MASK_SRLW, match_opcode, 0 },
8850 +{"srlw", "64I", "d,s,<", MATCH_SRLIW, MASK_SRLIW, match_opcode, INSN_ALIAS },
8851 +{"sraiw", "64I", "d,s,<", MATCH_SRAIW, MASK_SRAIW, match_opcode, 0 },
8852 +{"sraw", "64I", "d,s,t", MATCH_SRAW, MASK_SRAW, match_opcode, 0 },
8853 +{"sraw", "64I", "d,s,<", MATCH_SRAIW, MASK_SRAIW, match_opcode, INSN_ALIAS },
8854 +{"subw", "64C", "Cs,Cw,Ct", MATCH_C_SUBW, MASK_C_SUBW, match_opcode, INSN_ALIAS },
8855 +{"subw", "64I", "d,s,t", MATCH_SUBW, MASK_SUBW, match_opcode, 0 },
8857 +/* Atomic memory operation instruction subset */
8858 +{"lr.w", "A", "d,0(s)", MATCH_LR_W, MASK_LR_W | MASK_AQRL, match_opcode, 0 },
8859 +{"sc.w", "A", "d,t,0(s)", MATCH_SC_W, MASK_SC_W | MASK_AQRL, match_opcode, 0 },
8860 +{"amoadd.w", "A", "d,t,0(s)", MATCH_AMOADD_W, MASK_AMOADD_W | MASK_AQRL, match_opcode, 0 },
8861 +{"amoswap.w", "A", "d,t,0(s)", MATCH_AMOSWAP_W, MASK_AMOSWAP_W | MASK_AQRL, match_opcode, 0 },
8862 +{"amoand.w", "A", "d,t,0(s)", MATCH_AMOAND_W, MASK_AMOAND_W | MASK_AQRL, match_opcode, 0 },
8863 +{"amoor.w", "A", "d,t,0(s)", MATCH_AMOOR_W, MASK_AMOOR_W | MASK_AQRL, match_opcode, 0 },
8864 +{"amoxor.w", "A", "d,t,0(s)", MATCH_AMOXOR_W, MASK_AMOXOR_W | MASK_AQRL, match_opcode, 0 },
8865 +{"amomax.w", "A", "d,t,0(s)", MATCH_AMOMAX_W, MASK_AMOMAX_W | MASK_AQRL, match_opcode, 0 },
8866 +{"amomaxu.w", "A", "d,t,0(s)", MATCH_AMOMAXU_W, MASK_AMOMAXU_W | MASK_AQRL, match_opcode, 0 },
8867 +{"amomin.w", "A", "d,t,0(s)", MATCH_AMOMIN_W, MASK_AMOMIN_W | MASK_AQRL, match_opcode, 0 },
8868 +{"amominu.w", "A", "d,t,0(s)", MATCH_AMOMINU_W, MASK_AMOMINU_W | MASK_AQRL, match_opcode, 0 },
8869 +{"lr.w.aq", "A", "d,0(s)", MATCH_LR_W | MASK_AQ, MASK_LR_W | MASK_AQRL, match_opcode, 0 },
8870 +{"sc.w.aq", "A", "d,t,0(s)", MATCH_SC_W | MASK_AQ, MASK_SC_W | MASK_AQRL, match_opcode, 0 },
8871 +{"amoadd.w.aq", "A", "d,t,0(s)", MATCH_AMOADD_W | MASK_AQ, MASK_AMOADD_W | MASK_AQRL, match_opcode, 0 },
8872 +{"amoswap.w.aq", "A", "d,t,0(s)", MATCH_AMOSWAP_W | MASK_AQ, MASK_AMOSWAP_W | MASK_AQRL, match_opcode, 0 },
8873 +{"amoand.w.aq", "A", "d,t,0(s)", MATCH_AMOAND_W | MASK_AQ, MASK_AMOAND_W | MASK_AQRL, match_opcode, 0 },
8874 +{"amoor.w.aq", "A", "d,t,0(s)", MATCH_AMOOR_W | MASK_AQ, MASK_AMOOR_W | MASK_AQRL, match_opcode, 0 },
8875 +{"amoxor.w.aq", "A", "d,t,0(s)", MATCH_AMOXOR_W | MASK_AQ, MASK_AMOXOR_W | MASK_AQRL, match_opcode, 0 },
8876 +{"amomax.w.aq", "A", "d,t,0(s)", MATCH_AMOMAX_W | MASK_AQ, MASK_AMOMAX_W | MASK_AQRL, match_opcode, 0 },
8877 +{"amomaxu.w.aq", "A", "d,t,0(s)", MATCH_AMOMAXU_W | MASK_AQ, MASK_AMOMAXU_W | MASK_AQRL, match_opcode, 0 },
8878 +{"amomin.w.aq", "A", "d,t,0(s)", MATCH_AMOMIN_W | MASK_AQ, MASK_AMOMIN_W | MASK_AQRL, match_opcode, 0 },
8879 +{"amominu.w.aq", "A", "d,t,0(s)", MATCH_AMOMINU_W | MASK_AQ, MASK_AMOMINU_W | MASK_AQRL, match_opcode, 0 },
8880 +{"lr.w.rl", "A", "d,0(s)", MATCH_LR_W | MASK_RL, MASK_LR_W | MASK_AQRL, match_opcode, 0 },
8881 +{"sc.w.rl", "A", "d,t,0(s)", MATCH_SC_W | MASK_RL, MASK_SC_W | MASK_AQRL, match_opcode, 0 },
8882 +{"amoadd.w.rl", "A", "d,t,0(s)", MATCH_AMOADD_W | MASK_RL, MASK_AMOADD_W | MASK_AQRL, match_opcode, 0 },
8883 +{"amoswap.w.rl", "A", "d,t,0(s)", MATCH_AMOSWAP_W | MASK_RL, MASK_AMOSWAP_W | MASK_AQRL, match_opcode, 0 },
8884 +{"amoand.w.rl", "A", "d,t,0(s)", MATCH_AMOAND_W | MASK_RL, MASK_AMOAND_W | MASK_AQRL, match_opcode, 0 },
8885 +{"amoor.w.rl", "A", "d,t,0(s)", MATCH_AMOOR_W | MASK_RL, MASK_AMOOR_W | MASK_AQRL, match_opcode, 0 },
8886 +{"amoxor.w.rl", "A", "d,t,0(s)", MATCH_AMOXOR_W | MASK_RL, MASK_AMOXOR_W | MASK_AQRL, match_opcode, 0 },
8887 +{"amomax.w.rl", "A", "d,t,0(s)", MATCH_AMOMAX_W | MASK_RL, MASK_AMOMAX_W | MASK_AQRL, match_opcode, 0 },
8888 +{"amomaxu.w.rl", "A", "d,t,0(s)", MATCH_AMOMAXU_W | MASK_RL, MASK_AMOMAXU_W | MASK_AQRL, match_opcode, 0 },
8889 +{"amomin.w.rl", "A", "d,t,0(s)", MATCH_AMOMIN_W | MASK_RL, MASK_AMOMIN_W | MASK_AQRL, match_opcode, 0 },
8890 +{"amominu.w.rl", "A", "d,t,0(s)", MATCH_AMOMINU_W | MASK_RL, MASK_AMOMINU_W | MASK_AQRL, match_opcode, 0 },
8891 +{"lr.w.sc", "A", "d,0(s)", MATCH_LR_W | MASK_AQRL, MASK_LR_W | MASK_AQRL, match_opcode, 0 },
8892 +{"sc.w.sc", "A", "d,t,0(s)", MATCH_SC_W | MASK_AQRL, MASK_SC_W | MASK_AQRL, match_opcode, 0 },
8893 +{"amoadd.w.sc", "A", "d,t,0(s)", MATCH_AMOADD_W | MASK_AQRL, MASK_AMOADD_W | MASK_AQRL, match_opcode, 0 },
8894 +{"amoswap.w.sc", "A", "d,t,0(s)", MATCH_AMOSWAP_W | MASK_AQRL, MASK_AMOSWAP_W | MASK_AQRL, match_opcode, 0 },
8895 +{"amoand.w.sc", "A", "d,t,0(s)", MATCH_AMOAND_W | MASK_AQRL, MASK_AMOAND_W | MASK_AQRL, match_opcode, 0 },
8896 +{"amoor.w.sc", "A", "d,t,0(s)", MATCH_AMOOR_W | MASK_AQRL, MASK_AMOOR_W | MASK_AQRL, match_opcode, 0 },
8897 +{"amoxor.w.sc", "A", "d,t,0(s)", MATCH_AMOXOR_W | MASK_AQRL, MASK_AMOXOR_W | MASK_AQRL, match_opcode, 0 },
8898 +{"amomax.w.sc", "A", "d,t,0(s)", MATCH_AMOMAX_W | MASK_AQRL, MASK_AMOMAX_W | MASK_AQRL, match_opcode, 0 },
8899 +{"amomaxu.w.sc", "A", "d,t,0(s)", MATCH_AMOMAXU_W | MASK_AQRL, MASK_AMOMAXU_W | MASK_AQRL, match_opcode, 0 },
8900 +{"amomin.w.sc", "A", "d,t,0(s)", MATCH_AMOMIN_W | MASK_AQRL, MASK_AMOMIN_W | MASK_AQRL, match_opcode, 0 },
8901 +{"amominu.w.sc", "A", "d,t,0(s)", MATCH_AMOMINU_W | MASK_AQRL, MASK_AMOMINU_W | MASK_AQRL, match_opcode, 0 },
8902 +{"lr.d", "64A", "d,0(s)", MATCH_LR_D, MASK_LR_D | MASK_AQRL, match_opcode, 0 },
8903 +{"sc.d", "64A", "d,t,0(s)", MATCH_SC_D, MASK_SC_D | MASK_AQRL, match_opcode, 0 },
8904 +{"amoadd.d", "64A", "d,t,0(s)", MATCH_AMOADD_D, MASK_AMOADD_D | MASK_AQRL, match_opcode, 0 },
8905 +{"amoswap.d", "64A", "d,t,0(s)", MATCH_AMOSWAP_D, MASK_AMOSWAP_D | MASK_AQRL, match_opcode, 0 },
8906 +{"amoand.d", "64A", "d,t,0(s)", MATCH_AMOAND_D, MASK_AMOAND_D | MASK_AQRL, match_opcode, 0 },
8907 +{"amoor.d", "64A", "d,t,0(s)", MATCH_AMOOR_D, MASK_AMOOR_D | MASK_AQRL, match_opcode, 0 },
8908 +{"amoxor.d", "64A", "d,t,0(s)", MATCH_AMOXOR_D, MASK_AMOXOR_D | MASK_AQRL, match_opcode, 0 },
8909 +{"amomax.d", "64A", "d,t,0(s)", MATCH_AMOMAX_D, MASK_AMOMAX_D | MASK_AQRL, match_opcode, 0 },
8910 +{"amomaxu.d", "64A", "d,t,0(s)", MATCH_AMOMAXU_D, MASK_AMOMAXU_D | MASK_AQRL, match_opcode, 0 },
8911 +{"amomin.d", "64A", "d,t,0(s)", MATCH_AMOMIN_D, MASK_AMOMIN_D | MASK_AQRL, match_opcode, 0 },
8912 +{"amominu.d", "64A", "d,t,0(s)", MATCH_AMOMINU_D, MASK_AMOMINU_D | MASK_AQRL, match_opcode, 0 },
8913 +{"lr.d.aq", "64A", "d,0(s)", MATCH_LR_D | MASK_AQ, MASK_LR_D | MASK_AQRL, match_opcode, 0 },
8914 +{"sc.d.aq", "64A", "d,t,0(s)", MATCH_SC_D | MASK_AQ, MASK_SC_D | MASK_AQRL, match_opcode, 0 },
8915 +{"amoadd.d.aq", "64A", "d,t,0(s)", MATCH_AMOADD_D | MASK_AQ, MASK_AMOADD_D | MASK_AQRL, match_opcode, 0 },
8916 +{"amoswap.d.aq", "64A", "d,t,0(s)", MATCH_AMOSWAP_D | MASK_AQ, MASK_AMOSWAP_D | MASK_AQRL, match_opcode, 0 },
8917 +{"amoand.d.aq", "64A", "d,t,0(s)", MATCH_AMOAND_D | MASK_AQ, MASK_AMOAND_D | MASK_AQRL, match_opcode, 0 },
8918 +{"amoor.d.aq", "64A", "d,t,0(s)", MATCH_AMOOR_D | MASK_AQ, MASK_AMOOR_D | MASK_AQRL, match_opcode, 0 },
8919 +{"amoxor.d.aq", "64A", "d,t,0(s)", MATCH_AMOXOR_D | MASK_AQ, MASK_AMOXOR_D | MASK_AQRL, match_opcode, 0 },
8920 +{"amomax.d.aq", "64A", "d,t,0(s)", MATCH_AMOMAX_D | MASK_AQ, MASK_AMOMAX_D | MASK_AQRL, match_opcode, 0 },
8921 +{"amomaxu.d.aq", "64A", "d,t,0(s)", MATCH_AMOMAXU_D | MASK_AQ, MASK_AMOMAXU_D | MASK_AQRL, match_opcode, 0 },
8922 +{"amomin.d.aq", "64A", "d,t,0(s)", MATCH_AMOMIN_D | MASK_AQ, MASK_AMOMIN_D | MASK_AQRL, match_opcode, 0 },
8923 +{"amominu.d.aq", "64A", "d,t,0(s)", MATCH_AMOMINU_D | MASK_AQ, MASK_AMOMINU_D | MASK_AQRL, match_opcode, 0 },
8924 +{"lr.d.rl", "64A", "d,0(s)", MATCH_LR_D | MASK_RL, MASK_LR_D | MASK_AQRL, match_opcode, 0 },
8925 +{"sc.d.rl", "64A", "d,t,0(s)", MATCH_SC_D | MASK_RL, MASK_SC_D | MASK_AQRL, match_opcode, 0 },
8926 +{"amoadd.d.rl", "64A", "d,t,0(s)", MATCH_AMOADD_D | MASK_RL, MASK_AMOADD_D | MASK_AQRL, match_opcode, 0 },
8927 +{"amoswap.d.rl", "64A", "d,t,0(s)", MATCH_AMOSWAP_D | MASK_RL, MASK_AMOSWAP_D | MASK_AQRL, match_opcode, 0 },
8928 +{"amoand.d.rl", "64A", "d,t,0(s)", MATCH_AMOAND_D | MASK_RL, MASK_AMOAND_D | MASK_AQRL, match_opcode, 0 },
8929 +{"amoor.d.rl", "64A", "d,t,0(s)", MATCH_AMOOR_D | MASK_RL, MASK_AMOOR_D | MASK_AQRL, match_opcode, 0 },
8930 +{"amoxor.d.rl", "64A", "d,t,0(s)", MATCH_AMOXOR_D | MASK_RL, MASK_AMOXOR_D | MASK_AQRL, match_opcode, 0 },
8931 +{"amomax.d.rl", "64A", "d,t,0(s)", MATCH_AMOMAX_D | MASK_RL, MASK_AMOMAX_D | MASK_AQRL, match_opcode, 0 },
8932 +{"amomaxu.d.rl", "64A", "d,t,0(s)", MATCH_AMOMAXU_D | MASK_RL, MASK_AMOMAXU_D | MASK_AQRL, match_opcode, 0 },
8933 +{"amomin.d.rl", "64A", "d,t,0(s)", MATCH_AMOMIN_D | MASK_RL, MASK_AMOMIN_D | MASK_AQRL, match_opcode, 0 },
8934 +{"amominu.d.rl", "64A", "d,t,0(s)", MATCH_AMOMINU_D | MASK_RL, MASK_AMOMINU_D | MASK_AQRL, match_opcode, 0 },
8935 +{"lr.d.sc", "64A", "d,0(s)", MATCH_LR_D | MASK_AQRL, MASK_LR_D | MASK_AQRL, match_opcode, 0 },
8936 +{"sc.d.sc", "64A", "d,t,0(s)", MATCH_SC_D | MASK_AQRL, MASK_SC_D | MASK_AQRL, match_opcode, 0 },
8937 +{"amoadd.d.sc", "64A", "d,t,0(s)", MATCH_AMOADD_D | MASK_AQRL, MASK_AMOADD_D | MASK_AQRL, match_opcode, 0 },
8938 +{"amoswap.d.sc", "64A", "d,t,0(s)", MATCH_AMOSWAP_D | MASK_AQRL, MASK_AMOSWAP_D | MASK_AQRL, match_opcode, 0 },
8939 +{"amoand.d.sc", "64A", "d,t,0(s)", MATCH_AMOAND_D | MASK_AQRL, MASK_AMOAND_D | MASK_AQRL, match_opcode, 0 },
8940 +{"amoor.d.sc", "64A", "d,t,0(s)", MATCH_AMOOR_D | MASK_AQRL, MASK_AMOOR_D | MASK_AQRL, match_opcode, 0 },
8941 +{"amoxor.d.sc", "64A", "d,t,0(s)", MATCH_AMOXOR_D | MASK_AQRL, MASK_AMOXOR_D | MASK_AQRL, match_opcode, 0 },
8942 +{"amomax.d.sc", "64A", "d,t,0(s)", MATCH_AMOMAX_D | MASK_AQRL, MASK_AMOMAX_D | MASK_AQRL, match_opcode, 0 },
8943 +{"amomaxu.d.sc", "64A", "d,t,0(s)", MATCH_AMOMAXU_D | MASK_AQRL, MASK_AMOMAXU_D | MASK_AQRL, match_opcode, 0 },
8944 +{"amomin.d.sc", "64A", "d,t,0(s)", MATCH_AMOMIN_D | MASK_AQRL, MASK_AMOMIN_D | MASK_AQRL, match_opcode, 0 },
8945 +{"amominu.d.sc", "64A", "d,t,0(s)", MATCH_AMOMINU_D | MASK_AQRL, MASK_AMOMINU_D | MASK_AQRL, match_opcode, 0 },
8947 +/* Multiply/Divide instruction subset */
8948 +{"mul", "M", "d,s,t", MATCH_MUL, MASK_MUL, match_opcode, 0 },
8949 +{"mulh", "M", "d,s,t", MATCH_MULH, MASK_MULH, match_opcode, 0 },
8950 +{"mulhu", "M", "d,s,t", MATCH_MULHU, MASK_MULHU, match_opcode, 0 },
8951 +{"mulhsu", "M", "d,s,t", MATCH_MULHSU, MASK_MULHSU, match_opcode, 0 },
8952 +{"div", "M", "d,s,t", MATCH_DIV, MASK_DIV, match_opcode, 0 },
8953 +{"divu", "M", "d,s,t", MATCH_DIVU, MASK_DIVU, match_opcode, 0 },
8954 +{"rem", "M", "d,s,t", MATCH_REM, MASK_REM, match_opcode, 0 },
8955 +{"remu", "M", "d,s,t", MATCH_REMU, MASK_REMU, match_opcode, 0 },
8956 +{"mulw", "64M", "d,s,t", MATCH_MULW, MASK_MULW, match_opcode, 0 },
8957 +{"divw", "64M", "d,s,t", MATCH_DIVW, MASK_DIVW, match_opcode, 0 },
8958 +{"divuw", "64M", "d,s,t", MATCH_DIVUW, MASK_DIVUW, match_opcode, 0 },
8959 +{"remw", "64M", "d,s,t", MATCH_REMW, MASK_REMW, match_opcode, 0 },
8960 +{"remuw", "64M", "d,s,t", MATCH_REMUW, MASK_REMUW, match_opcode, 0 },
8962 +/* Single-precision floating-point instruction subset */
8963 +{"frsr", "F", "d", MATCH_FRCSR, MASK_FRCSR, match_opcode, 0 },
8964 +{"fssr", "F", "s", MATCH_FSCSR, MASK_FSCSR | MASK_RD, match_opcode, 0 },
8965 +{"fssr", "F", "d,s", MATCH_FSCSR, MASK_FSCSR, match_opcode, 0 },
8966 +{"frcsr", "F", "d", MATCH_FRCSR, MASK_FRCSR, match_opcode, 0 },
8967 +{"fscsr", "F", "s", MATCH_FSCSR, MASK_FSCSR | MASK_RD, match_opcode, 0 },
8968 +{"fscsr", "F", "d,s", MATCH_FSCSR, MASK_FSCSR, match_opcode, 0 },
8969 +{"frrm", "F", "d", MATCH_FRRM, MASK_FRRM, match_opcode, 0 },
8970 +{"fsrm", "F", "s", MATCH_FSRM, MASK_FSRM | MASK_RD, match_opcode, 0 },
8971 +{"fsrm", "F", "d,s", MATCH_FSRM, MASK_FSRM, match_opcode, 0 },
8972 +{"frflags", "F", "d", MATCH_FRFLAGS, MASK_FRFLAGS, match_opcode, 0 },
8973 +{"fsflags", "F", "s", MATCH_FSFLAGS, MASK_FSFLAGS | MASK_RD, match_opcode, 0 },
8974 +{"fsflags", "F", "d,s", MATCH_FSFLAGS, MASK_FSFLAGS, match_opcode, 0 },
8975 +{"flw", "32C", "D,Cm(Cc)", MATCH_C_FLWSP, MASK_C_FLWSP, match_opcode, INSN_ALIAS },
8976 +{"flw", "32C", "CD,Ck(Cs)", MATCH_C_FLW, MASK_C_FLW, match_opcode, INSN_ALIAS },
8977 +{"flw", "F", "D,o(s)", MATCH_FLW, MASK_FLW, match_opcode, 0 },
8978 +{"flw", "F", "D,A,s", 0, (int) M_FLW, match_never, INSN_MACRO },
8979 +{"fsw", "32C", "CT,CM(Cc)", MATCH_C_FSWSP, MASK_C_FSWSP, match_opcode, INSN_ALIAS },
8980 +{"fsw", "32C", "CD,Ck(Cs)", MATCH_C_FSW, MASK_C_FSW, match_opcode, INSN_ALIAS },
8981 +{"fsw", "F", "T,q(s)", MATCH_FSW, MASK_FSW, match_opcode, 0 },
8982 +{"fsw", "F", "T,A,s", 0, (int) M_FSW, match_never, INSN_MACRO },
8983 +{"fmv.x.s", "F", "d,S", MATCH_FMV_X_S, MASK_FMV_X_S, match_opcode, 0 },
8984 +{"fmv.s.x", "F", "D,s", MATCH_FMV_S_X, MASK_FMV_S_X, match_opcode, 0 },
8985 +{"fmv.s", "F", "D,U", MATCH_FSGNJ_S, MASK_FSGNJ_S, match_rs1_eq_rs2, INSN_ALIAS },
8986 +{"fneg.s", "F", "D,U", MATCH_FSGNJN_S, MASK_FSGNJN_S, match_rs1_eq_rs2, INSN_ALIAS },
8987 +{"fabs.s", "F", "D,U", MATCH_FSGNJX_S, MASK_FSGNJX_S, match_rs1_eq_rs2, INSN_ALIAS },
8988 +{"fsgnj.s", "F", "D,S,T", MATCH_FSGNJ_S, MASK_FSGNJ_S, match_opcode, 0 },
8989 +{"fsgnjn.s", "F", "D,S,T", MATCH_FSGNJN_S, MASK_FSGNJN_S, match_opcode, 0 },
8990 +{"fsgnjx.s", "F", "D,S,T", MATCH_FSGNJX_S, MASK_FSGNJX_S, match_opcode, 0 },
8991 +{"fadd.s", "F", "D,S,T", MATCH_FADD_S | MASK_RM, MASK_FADD_S | MASK_RM, match_opcode, 0 },
8992 +{"fadd.s", "F", "D,S,T,m", MATCH_FADD_S, MASK_FADD_S, match_opcode, 0 },
8993 +{"fsub.s", "F", "D,S,T", MATCH_FSUB_S | MASK_RM, MASK_FSUB_S | MASK_RM, match_opcode, 0 },
8994 +{"fsub.s", "F", "D,S,T,m", MATCH_FSUB_S, MASK_FSUB_S, match_opcode, 0 },
8995 +{"fmul.s", "F", "D,S,T", MATCH_FMUL_S | MASK_RM, MASK_FMUL_S | MASK_RM, match_opcode, 0 },
8996 +{"fmul.s", "F", "D,S,T,m", MATCH_FMUL_S, MASK_FMUL_S, match_opcode, 0 },
8997 +{"fdiv.s", "F", "D,S,T", MATCH_FDIV_S | MASK_RM, MASK_FDIV_S | MASK_RM, match_opcode, 0 },
8998 +{"fdiv.s", "F", "D,S,T,m", MATCH_FDIV_S, MASK_FDIV_S, match_opcode, 0 },
8999 +{"fsqrt.s", "F", "D,S", MATCH_FSQRT_S | MASK_RM, MASK_FSQRT_S | MASK_RM, match_opcode, 0 },
9000 +{"fsqrt.s", "F", "D,S,m", MATCH_FSQRT_S, MASK_FSQRT_S, match_opcode, 0 },
9001 +{"fmin.s", "F", "D,S,T", MATCH_FMIN_S, MASK_FMIN_S, match_opcode, 0 },
9002 +{"fmax.s", "F", "D,S,T", MATCH_FMAX_S, MASK_FMAX_S, match_opcode, 0 },
9003 +{"fmadd.s", "F", "D,S,T,R", MATCH_FMADD_S | MASK_RM, MASK_FMADD_S | MASK_RM, match_opcode, 0 },
9004 +{"fmadd.s", "F", "D,S,T,R,m", MATCH_FMADD_S, MASK_FMADD_S, match_opcode, 0 },
9005 +{"fnmadd.s", "F", "D,S,T,R", MATCH_FNMADD_S | MASK_RM, MASK_FNMADD_S | MASK_RM, match_opcode, 0 },
9006 +{"fnmadd.s", "F", "D,S,T,R,m", MATCH_FNMADD_S, MASK_FNMADD_S, match_opcode, 0 },
9007 +{"fmsub.s", "F", "D,S,T,R", MATCH_FMSUB_S | MASK_RM, MASK_FMSUB_S | MASK_RM, match_opcode, 0 },
9008 +{"fmsub.s", "F", "D,S,T,R,m", MATCH_FMSUB_S, MASK_FMSUB_S, match_opcode, 0 },
9009 +{"fnmsub.s", "F", "D,S,T,R", MATCH_FNMSUB_S | MASK_RM, MASK_FNMSUB_S | MASK_RM, match_opcode, 0 },
9010 +{"fnmsub.s", "F", "D,S,T,R,m", MATCH_FNMSUB_S, MASK_FNMSUB_S, match_opcode, 0 },
9011 +{"fcvt.w.s", "F", "d,S", MATCH_FCVT_W_S | MASK_RM, MASK_FCVT_W_S | MASK_RM, match_opcode, 0 },
9012 +{"fcvt.w.s", "F", "d,S,m", MATCH_FCVT_W_S, MASK_FCVT_W_S, match_opcode, 0 },
9013 +{"fcvt.wu.s", "F", "d,S", MATCH_FCVT_WU_S | MASK_RM, MASK_FCVT_WU_S | MASK_RM, match_opcode, 0 },
9014 +{"fcvt.wu.s", "F", "d,S,m", MATCH_FCVT_WU_S, MASK_FCVT_WU_S, match_opcode, 0 },
9015 +{"fcvt.s.w", "F", "D,s", MATCH_FCVT_S_W | MASK_RM, MASK_FCVT_S_W | MASK_RM, match_opcode, 0 },
9016 +{"fcvt.s.w", "F", "D,s,m", MATCH_FCVT_S_W, MASK_FCVT_S_W, match_opcode, 0 },
9017 +{"fcvt.s.wu", "F", "D,s", MATCH_FCVT_S_WU | MASK_RM, MASK_FCVT_S_W | MASK_RM, match_opcode, 0 },
9018 +{"fcvt.s.wu", "F", "D,s,m", MATCH_FCVT_S_WU, MASK_FCVT_S_WU, match_opcode, 0 },
9019 +{"fclass.s", "F", "d,S", MATCH_FCLASS_S, MASK_FCLASS_S, match_opcode, 0 },
9020 +{"feq.s", "F", "d,S,T", MATCH_FEQ_S, MASK_FEQ_S, match_opcode, 0 },
9021 +{"flt.s", "F", "d,S,T", MATCH_FLT_S, MASK_FLT_S, match_opcode, 0 },
9022 +{"fle.s", "F", "d,S,T", MATCH_FLE_S, MASK_FLE_S, match_opcode, 0 },
9023 +{"fgt.s", "F", "d,T,S", MATCH_FLT_S, MASK_FLT_S, match_opcode, 0 },
9024 +{"fge.s", "F", "d,T,S", MATCH_FLE_S, MASK_FLE_S, match_opcode, 0 },
9025 +{"fcvt.l.s", "64F", "d,S", MATCH_FCVT_L_S | MASK_RM, MASK_FCVT_L_S | MASK_RM, match_opcode, 0 },
9026 +{"fcvt.l.s", "64F", "d,S,m", MATCH_FCVT_L_S, MASK_FCVT_L_S, match_opcode, 0 },
9027 +{"fcvt.lu.s", "64F", "d,S", MATCH_FCVT_LU_S | MASK_RM, MASK_FCVT_LU_S | MASK_RM, match_opcode, 0 },
9028 +{"fcvt.lu.s", "64F", "d,S,m", MATCH_FCVT_LU_S, MASK_FCVT_LU_S, match_opcode, 0 },
9029 +{"fcvt.s.l", "64F", "D,s", MATCH_FCVT_S_L | MASK_RM, MASK_FCVT_S_L | MASK_RM, match_opcode, 0 },
9030 +{"fcvt.s.l", "64F", "D,s,m", MATCH_FCVT_S_L, MASK_FCVT_S_L, match_opcode, 0 },
9031 +{"fcvt.s.lu", "64F", "D,s", MATCH_FCVT_S_LU | MASK_RM, MASK_FCVT_S_L | MASK_RM, match_opcode, 0 },
9032 +{"fcvt.s.lu", "64F", "D,s,m", MATCH_FCVT_S_LU, MASK_FCVT_S_LU, match_opcode, 0 },
9034 +/* Double-precision floating-point instruction subset */
9035 +{"fld", "C", "D,Cn(Cc)", MATCH_C_FLDSP, MASK_C_FLDSP, match_opcode, INSN_ALIAS },
9036 +{"fld", "C", "CD,Cl(Cs)", MATCH_C_FLD, MASK_C_FLD, match_opcode, INSN_ALIAS },
9037 +{"fld", "D", "D,o(s)", MATCH_FLD, MASK_FLD, match_opcode, 0 },
9038 +{"fld", "D", "D,A,s", 0, (int) M_FLD, match_never, INSN_MACRO },
9039 +{"fsd", "C", "CT,CN(Cc)", MATCH_C_FSDSP, MASK_C_FSDSP, match_opcode, INSN_ALIAS },
9040 +{"fsd", "C", "CD,Cl(Cs)", MATCH_C_FSD, MASK_C_FSD, match_opcode, INSN_ALIAS },
9041 +{"fsd", "D", "T,q(s)", MATCH_FSD, MASK_FSD, match_opcode, 0 },
9042 +{"fsd", "D", "T,A,s", 0, (int) M_FSD, match_never, INSN_MACRO },
9043 +{"fmv.d", "D", "D,U", MATCH_FSGNJ_D, MASK_FSGNJ_D, match_rs1_eq_rs2, INSN_ALIAS },
9044 +{"fneg.d", "D", "D,U", MATCH_FSGNJN_D, MASK_FSGNJN_D, match_rs1_eq_rs2, INSN_ALIAS },
9045 +{"fabs.d", "D", "D,U", MATCH_FSGNJX_D, MASK_FSGNJX_D, match_rs1_eq_rs2, INSN_ALIAS },
9046 +{"fsgnj.d", "D", "D,S,T", MATCH_FSGNJ_D, MASK_FSGNJ_D, match_opcode, 0 },
9047 +{"fsgnjn.d", "D", "D,S,T", MATCH_FSGNJN_D, MASK_FSGNJN_D, match_opcode, 0 },
9048 +{"fsgnjx.d", "D", "D,S,T", MATCH_FSGNJX_D, MASK_FSGNJX_D, match_opcode, 0 },
9049 +{"fadd.d", "D", "D,S,T", MATCH_FADD_D | MASK_RM, MASK_FADD_D | MASK_RM, match_opcode, 0 },
9050 +{"fadd.d", "D", "D,S,T,m", MATCH_FADD_D, MASK_FADD_D, match_opcode, 0 },
9051 +{"fsub.d", "D", "D,S,T", MATCH_FSUB_D | MASK_RM, MASK_FSUB_D | MASK_RM, match_opcode, 0 },
9052 +{"fsub.d", "D", "D,S,T,m", MATCH_FSUB_D, MASK_FSUB_D, match_opcode, 0 },
9053 +{"fmul.d", "D", "D,S,T", MATCH_FMUL_D | MASK_RM, MASK_FMUL_D | MASK_RM, match_opcode, 0 },
9054 +{"fmul.d", "D", "D,S,T,m", MATCH_FMUL_D, MASK_FMUL_D, match_opcode, 0 },
9055 +{"fdiv.d", "D", "D,S,T", MATCH_FDIV_D | MASK_RM, MASK_FDIV_D | MASK_RM, match_opcode, 0 },
9056 +{"fdiv.d", "D", "D,S,T,m", MATCH_FDIV_D, MASK_FDIV_D, match_opcode, 0 },
9057 +{"fsqrt.d", "D", "D,S", MATCH_FSQRT_D | MASK_RM, MASK_FSQRT_D | MASK_RM, match_opcode, 0 },
9058 +{"fsqrt.d", "D", "D,S,m", MATCH_FSQRT_D, MASK_FSQRT_D, match_opcode, 0 },
9059 +{"fmin.d", "D", "D,S,T", MATCH_FMIN_D, MASK_FMIN_D, match_opcode, 0 },
9060 +{"fmax.d", "D", "D,S,T", MATCH_FMAX_D, MASK_FMAX_D, match_opcode, 0 },
9061 +{"fmadd.d", "D", "D,S,T,R", MATCH_FMADD_D | MASK_RM, MASK_FMADD_D | MASK_RM, match_opcode, 0 },
9062 +{"fmadd.d", "D", "D,S,T,R,m", MATCH_FMADD_D, MASK_FMADD_D, match_opcode, 0 },
9063 +{"fnmadd.d", "D", "D,S,T,R", MATCH_FNMADD_D | MASK_RM, MASK_FNMADD_D | MASK_RM, match_opcode, 0 },
9064 +{"fnmadd.d", "D", "D,S,T,R,m", MATCH_FNMADD_D, MASK_FNMADD_D, match_opcode, 0 },
9065 +{"fmsub.d", "D", "D,S,T,R", MATCH_FMSUB_D | MASK_RM, MASK_FMSUB_D | MASK_RM, match_opcode, 0 },
9066 +{"fmsub.d", "D", "D,S,T,R,m", MATCH_FMSUB_D, MASK_FMSUB_D, match_opcode, 0 },
9067 +{"fnmsub.d", "D", "D,S,T,R", MATCH_FNMSUB_D | MASK_RM, MASK_FNMSUB_D | MASK_RM, match_opcode, 0 },
9068 +{"fnmsub.d", "D", "D,S,T,R,m", MATCH_FNMSUB_D, MASK_FNMSUB_D, match_opcode, 0 },
9069 +{"fcvt.w.d", "D", "d,S", MATCH_FCVT_W_D | MASK_RM, MASK_FCVT_W_D | MASK_RM, match_opcode, 0 },
9070 +{"fcvt.w.d", "D", "d,S,m", MATCH_FCVT_W_D, MASK_FCVT_W_D, match_opcode, 0 },
9071 +{"fcvt.wu.d", "D", "d,S", MATCH_FCVT_WU_D | MASK_RM, MASK_FCVT_WU_D | MASK_RM, match_opcode, 0 },
9072 +{"fcvt.wu.d", "D", "d,S,m", MATCH_FCVT_WU_D, MASK_FCVT_WU_D, match_opcode, 0 },
9073 +{"fcvt.d.w", "D", "D,s", MATCH_FCVT_D_W, MASK_FCVT_D_W | MASK_RM, match_opcode, 0 },
9074 +{"fcvt.d.wu", "D", "D,s", MATCH_FCVT_D_WU, MASK_FCVT_D_WU | MASK_RM, match_opcode, 0 },
9075 +{"fcvt.d.s", "D", "D,S", MATCH_FCVT_D_S, MASK_FCVT_D_S | MASK_RM, match_opcode, 0 },
9076 +{"fcvt.s.d", "D", "D,S", MATCH_FCVT_S_D | MASK_RM, MASK_FCVT_S_D | MASK_RM, match_opcode, 0 },
9077 +{"fcvt.s.d", "D", "D,S,m", MATCH_FCVT_S_D, MASK_FCVT_S_D, match_opcode, 0 },
9078 +{"fclass.d", "D", "d,S", MATCH_FCLASS_D, MASK_FCLASS_D, match_opcode, 0 },
9079 +{"feq.d", "D", "d,S,T", MATCH_FEQ_D, MASK_FEQ_D, match_opcode, 0 },
9080 +{"flt.d", "D", "d,S,T", MATCH_FLT_D, MASK_FLT_D, match_opcode, 0 },
9081 +{"fle.d", "D", "d,S,T", MATCH_FLE_D, MASK_FLE_D, match_opcode, 0 },
9082 +{"fgt.d", "D", "d,T,S", MATCH_FLT_D, MASK_FLT_D, match_opcode, 0 },
9083 +{"fge.d", "D", "d,T,S", MATCH_FLE_D, MASK_FLE_D, match_opcode, 0 },
9084 +{"fmv.x.d", "64D", "d,S", MATCH_FMV_X_D, MASK_FMV_X_D, match_opcode, 0 },
9085 +{"fmv.d.x", "64D", "D,s", MATCH_FMV_D_X, MASK_FMV_D_X, match_opcode, 0 },
9086 +{"fcvt.l.d", "64D", "d,S", MATCH_FCVT_L_D | MASK_RM, MASK_FCVT_L_D | MASK_RM, match_opcode, 0 },
9087 +{"fcvt.l.d", "64D", "d,S,m", MATCH_FCVT_L_D, MASK_FCVT_L_D, match_opcode, 0 },
9088 +{"fcvt.lu.d", "64D", "d,S", MATCH_FCVT_LU_D | MASK_RM, MASK_FCVT_LU_D | MASK_RM, match_opcode, 0 },
9089 +{"fcvt.lu.d", "64D", "d,S,m", MATCH_FCVT_LU_D, MASK_FCVT_LU_D, match_opcode, 0 },
9090 +{"fcvt.d.l", "64D", "D,s", MATCH_FCVT_D_L | MASK_RM, MASK_FCVT_D_L | MASK_RM, match_opcode, 0 },
9091 +{"fcvt.d.l", "64D", "D,s,m", MATCH_FCVT_D_L, MASK_FCVT_D_L, match_opcode, 0 },
9092 +{"fcvt.d.lu", "64D", "D,s", MATCH_FCVT_D_LU | MASK_RM, MASK_FCVT_D_L | MASK_RM, match_opcode, 0 },
9093 +{"fcvt.d.lu", "64D", "D,s,m", MATCH_FCVT_D_LU, MASK_FCVT_D_LU, match_opcode, 0 },
9095 +/* Compressed instructions */
9096 +{"c.ebreak", "C", "", MATCH_C_EBREAK, MASK_C_EBREAK, match_opcode, 0 },
9097 +{"c.jr", "C", "d", MATCH_C_JR, MASK_C_JR, match_rd_nonzero, 0 },
9098 +{"c.jalr", "C", "d", MATCH_C_JALR, MASK_C_JALR, match_rd_nonzero, 0 },
9099 +{"c.j", "C", "Ca", MATCH_C_J, MASK_C_J, match_opcode, 0 },
9100 +{"c.jal", "32C", "Ca", MATCH_C_JAL, MASK_C_JAL, match_opcode, 0 },
9101 +{"c.beqz", "C", "Cs,Cp", MATCH_C_BEQZ, MASK_C_BEQZ, match_opcode, 0 },
9102 +{"c.bnez", "C", "Cs,Cp", MATCH_C_BNEZ, MASK_C_BNEZ, match_opcode, 0 },
9103 +{"c.lwsp", "C", "d,Cm(Cc)", MATCH_C_LWSP, MASK_C_LWSP, match_rd_nonzero, 0 },
9104 +{"c.lw", "C", "Ct,Ck(Cs)", MATCH_C_LW, MASK_C_LW, match_opcode, 0 },
9105 +{"c.swsp", "C", "CV,CM(Cc)", MATCH_C_SWSP, MASK_C_SWSP, match_opcode, 0 },
9106 +{"c.sw", "C", "Ct,Ck(Cs)", MATCH_C_SW, MASK_C_SW, match_opcode, 0 },
9107 +{"c.nop", "C", "", MATCH_C_ADDI, 0xffff, match_opcode, 0 },
9108 +{"c.mv", "C", "d,CV", MATCH_C_MV, MASK_C_MV, match_c_add, 0 },
9109 +{"c.lui", "C", "d,Cu", MATCH_C_LUI, MASK_C_LUI, match_c_lui, 0 },
9110 +{"c.li", "C", "d,Cj", MATCH_C_LI, MASK_C_LI, match_rd_nonzero, 0 },
9111 +{"c.addi4spn","C", "Ct,Cc,CK", MATCH_C_ADDI4SPN, MASK_C_ADDI4SPN, match_opcode, 0 },
9112 +{"c.addi16sp","C", "Cc,CL", MATCH_C_ADDI16SP, MASK_C_ADDI16SP, match_opcode, 0 },
9113 +{"c.addi", "C", "d,Cj", MATCH_C_ADDI, MASK_C_ADDI, match_rd_nonzero, 0 },
9114 +{"c.add", "C", "d,CV", MATCH_C_ADD, MASK_C_ADD, match_c_add, 0 },
9115 +{"c.sub", "C", "Cs,Ct", MATCH_C_SUB, MASK_C_SUB, match_opcode, 0 },
9116 +{"c.and", "C", "Cs,Ct", MATCH_C_AND, MASK_C_AND, match_opcode, 0 },
9117 +{"c.or", "C", "Cs,Ct", MATCH_C_OR, MASK_C_OR, match_opcode, 0 },
9118 +{"c.xor", "C", "Cs,Ct", MATCH_C_XOR, MASK_C_XOR, match_opcode, 0 },
9119 +{"c.slli", "C", "d,C>", MATCH_C_SLLI, MASK_C_SLLI, match_rd_nonzero, 0 },
9120 +{"c.srli", "C", "Cs,C>", MATCH_C_SRLI, MASK_C_SRLI, match_opcode, 0 },
9121 +{"c.srai", "C", "Cs,C>", MATCH_C_SRAI, MASK_C_SRAI, match_opcode, 0 },
9122 +{"c.andi", "C", "Cs,Cj", MATCH_C_ANDI, MASK_C_ANDI, match_opcode, 0 },
9123 +{"c.addiw", "64C", "d,Cj", MATCH_C_ADDIW, MASK_C_ADDIW, match_rd_nonzero, 0 },
9124 +{"c.addw", "64C", "Cs,Ct", MATCH_C_ADDW, MASK_C_ADDW, match_opcode, 0 },
9125 +{"c.subw", "64C", "Cs,Ct", MATCH_C_SUBW, MASK_C_SUBW, match_opcode, 0 },
9126 +{"c.ldsp", "64C", "d,Cn(Cc)", MATCH_C_LDSP, MASK_C_LDSP, match_rd_nonzero, 0 },
9127 +{"c.ld", "64C", "Ct,Cl(Cs)", MATCH_C_LD, MASK_C_LD, match_opcode, 0 },
9128 +{"c.sdsp", "64C", "CV,CN(Cc)", MATCH_C_SDSP, MASK_C_SDSP, match_opcode, 0 },
9129 +{"c.sd", "64C", "Ct,Cl(Cs)", MATCH_C_SD, MASK_C_SD, match_opcode, 0 },
9130 +{"c.fldsp", "C", "D,Cn(Cc)", MATCH_C_FLDSP, MASK_C_FLDSP, match_opcode, 0 },
9131 +{"c.fld", "C", "CD,Cl(Cs)", MATCH_C_FLD, MASK_C_FLD, match_opcode, 0 },
9132 +{"c.fsdsp", "C", "CT,CN(Cc)", MATCH_C_FSDSP, MASK_C_FSDSP, match_opcode, 0 },
9133 +{"c.fsd", "C", "CD,Cl(Cs)", MATCH_C_FSD, MASK_C_FSD, match_opcode, 0 },
9134 +{"c.flwsp", "32C", "D,Cm(Cc)", MATCH_C_FLWSP, MASK_C_FLWSP, match_opcode, 0 },
9135 +{"c.flw", "32C", "CD,Ck(Cs)", MATCH_C_FLW, MASK_C_FLW, match_opcode, 0 },
9136 +{"c.fswsp", "32C", "CT,CM(Cc)", MATCH_C_FSWSP, MASK_C_FSWSP, match_opcode, 0 },
9137 +{"c.fsw", "32C", "CD,Ck(Cs)", MATCH_C_FSW, MASK_C_FSW, match_opcode, 0 },
9139 +/* Supervisor instructions */
9140 +{"csrr", "I", "d,E", MATCH_CSRRS, MASK_CSRRS | MASK_RS1, match_opcode, 0 },
9141 +{"csrwi", "I", "E,Z", MATCH_CSRRWI, MASK_CSRRWI | MASK_RD, match_opcode, 0 },
9142 +{"csrw", "I", "E,s", MATCH_CSRRW, MASK_CSRRW | MASK_RD, match_opcode, 0 },
9143 +{"csrw", "I", "E,Z", MATCH_CSRRWI, MASK_CSRRWI | MASK_RD, match_opcode, 0 },
9144 +{"csrsi", "I", "E,Z", MATCH_CSRRSI, MASK_CSRRSI | MASK_RD, match_opcode, 0 },
9145 +{"csrs", "I", "E,s", MATCH_CSRRS, MASK_CSRRS | MASK_RD, match_opcode, 0 },
9146 +{"csrs", "I", "E,Z", MATCH_CSRRSI, MASK_CSRRSI | MASK_RD, match_opcode, 0 },
9147 +{"csrci", "I", "E,Z", MATCH_CSRRCI, MASK_CSRRCI | MASK_RD, match_opcode, 0 },
9148 +{"csrc", "I", "E,s", MATCH_CSRRC, MASK_CSRRC | MASK_RD, match_opcode, 0 },
9149 +{"csrc", "I", "E,Z", MATCH_CSRRCI, MASK_CSRRCI | MASK_RD, match_opcode, 0 },
9150 +{"csrrw", "I", "d,E,s", MATCH_CSRRW, MASK_CSRRW, match_opcode, 0 },
9151 +{"csrrw", "I", "d,E,Z", MATCH_CSRRWI, MASK_CSRRWI, match_opcode, 0 },
9152 +{"csrrs", "I", "d,E,s", MATCH_CSRRS, MASK_CSRRS, match_opcode, 0 },
9153 +{"csrrs", "I", "d,E,Z", MATCH_CSRRSI, MASK_CSRRSI, match_opcode, 0 },
9154 +{"csrrc", "I", "d,E,s", MATCH_CSRRC, MASK_CSRRC, match_opcode, 0 },
9155 +{"csrrc", "I", "d,E,Z", MATCH_CSRRCI, MASK_CSRRCI, match_opcode, 0 },
9156 +{"csrrwi", "I", "d,E,Z", MATCH_CSRRWI, MASK_CSRRWI, match_opcode, 0 },
9157 +{"csrrsi", "I", "d,E,Z", MATCH_CSRRSI, MASK_CSRRSI, match_opcode, 0 },
9158 +{"csrrci", "I", "d,E,Z", MATCH_CSRRCI, MASK_CSRRCI, match_opcode, 0 },
9159 +{"eret", "I", "", MATCH_SRET, MASK_SRET, match_opcode, 0 },
9160 +{"sret", "I", "", MATCH_SRET, MASK_SRET, match_opcode, 0 },
9161 +{"sfence.vm", "I", "", MATCH_SFENCE_VM, MASK_SFENCE_VM | MASK_RS1, match_opcode, 0 },
9162 +{"sfence.vm", "I", "s", MATCH_SFENCE_VM, MASK_SFENCE_VM, match_opcode, 0 },
9163 +{"wfi", "I", "", MATCH_WFI, MASK_WFI, match_opcode, 0 },
9165 +/* Rocket Custom Coprocessor extension */
9166 +{"custom0", "Xcustom", "d,s,t,^j", MATCH_CUSTOM0_RD_RS1_RS2, MASK_CUSTOM0_RD_RS1_RS2, match_opcode, 0},
9167 +{"custom0", "Xcustom", "d,s,^t,^j", MATCH_CUSTOM0_RD_RS1, MASK_CUSTOM0_RD_RS1, match_opcode, 0},
9168 +{"custom0", "Xcustom", "d,^s,^t,^j", MATCH_CUSTOM0_RD, MASK_CUSTOM0_RD, match_opcode, 0},
9169 +{"custom0", "Xcustom", "^d,s,t,^j", MATCH_CUSTOM0_RS1_RS2, MASK_CUSTOM0_RS1_RS2, match_opcode, 0},
9170 +{"custom0", "Xcustom", "^d,s,^t,^j", MATCH_CUSTOM0_RS1, MASK_CUSTOM0_RS1, match_opcode, 0},
9171 +{"custom0", "Xcustom", "^d,^s,^t,^j", MATCH_CUSTOM0, MASK_CUSTOM0, match_opcode, 0},
9172 +{"custom1", "Xcustom", "d,s,t,^j", MATCH_CUSTOM1_RD_RS1_RS2, MASK_CUSTOM1_RD_RS1_RS2, match_opcode, 0},
9173 +{"custom1", "Xcustom", "d,s,^t,^j", MATCH_CUSTOM1_RD_RS1, MASK_CUSTOM1_RD_RS1, match_opcode, 0},
9174 +{"custom1", "Xcustom", "d,^s,^t,^j", MATCH_CUSTOM1_RD, MASK_CUSTOM1_RD, match_opcode, 0},
9175 +{"custom1", "Xcustom", "^d,s,t,^j", MATCH_CUSTOM1_RS1_RS2, MASK_CUSTOM1_RS1_RS2, match_opcode, 0},
9176 +{"custom1", "Xcustom", "^d,s,^t,^j", MATCH_CUSTOM1_RS1, MASK_CUSTOM1_RS1, match_opcode, 0},
9177 +{"custom1", "Xcustom", "^d,^s,^t,^j", MATCH_CUSTOM1, MASK_CUSTOM1, match_opcode, 0},
9178 +{"custom2", "Xcustom", "d,s,t,^j", MATCH_CUSTOM2_RD_RS1_RS2, MASK_CUSTOM2_RD_RS1_RS2, match_opcode, 0},
9179 +{"custom2", "Xcustom", "d,s,^t,^j", MATCH_CUSTOM2_RD_RS1, MASK_CUSTOM2_RD_RS1, match_opcode, 0},
9180 +{"custom2", "Xcustom", "d,^s,^t,^j", MATCH_CUSTOM2_RD, MASK_CUSTOM2_RD, match_opcode, 0},
9181 +{"custom2", "Xcustom", "^d,s,t,^j", MATCH_CUSTOM2_RS1_RS2, MASK_CUSTOM2_RS1_RS2, match_opcode, 0},
9182 +{"custom2", "Xcustom", "^d,s,^t,^j", MATCH_CUSTOM2_RS1, MASK_CUSTOM2_RS1, match_opcode, 0},
9183 +{"custom2", "Xcustom", "^d,^s,^t,^j", MATCH_CUSTOM2, MASK_CUSTOM2, match_opcode, 0},
9184 +{"custom3", "Xcustom", "d,s,t,^j", MATCH_CUSTOM3_RD_RS1_RS2, MASK_CUSTOM3_RD_RS1_RS2, match_opcode, 0},
9185 +{"custom3", "Xcustom", "d,s,^t,^j", MATCH_CUSTOM3_RD_RS1, MASK_CUSTOM3_RD_RS1, match_opcode, 0},
9186 +{"custom3", "Xcustom", "d,^s,^t,^j", MATCH_CUSTOM3_RD, MASK_CUSTOM3_RD, match_opcode, 0},
9187 +{"custom3", "Xcustom", "^d,s,t,^j", MATCH_CUSTOM3_RS1_RS2, MASK_CUSTOM3_RS1_RS2, match_opcode, 0},
9188 +{"custom3", "Xcustom", "^d,s,^t,^j", MATCH_CUSTOM3_RS1, MASK_CUSTOM3_RS1, match_opcode, 0},
9189 +{"custom3", "Xcustom", "^d,^s,^t,^j", MATCH_CUSTOM3, MASK_CUSTOM3, match_opcode, 0},
9192 +#define RISCV_NUM_OPCODES \
9193 + ((sizeof riscv_builtin_opcodes) / (sizeof (riscv_builtin_opcodes[0])))
9194 +const int bfd_riscv_num_builtin_opcodes = RISCV_NUM_OPCODES;
9196 +/* Removed const from the following to allow for dynamic extensions to the
9197 + built-in instruction set. */
9198 +struct riscv_opcode *riscv_opcodes =
9199 + (struct riscv_opcode *) riscv_builtin_opcodes;
9200 +int bfd_riscv_num_opcodes = RISCV_NUM_OPCODES;
9201 +#undef RISCV_NUM_OPCODES
9202 --- original-binutils/bfd/archures.c
9203 +++ binutils-2.26.1/bfd/archures.c
9204 @@ -612,6 +612,7 @@ extern const bfd_arch_info_type bfd_pj_a
9205 extern const bfd_arch_info_type bfd_plugin_arch;
9206 extern const bfd_arch_info_type bfd_powerpc_archs[];
9207 #define bfd_powerpc_arch bfd_powerpc_archs[0]
9208 +extern const bfd_arch_info_type bfd_riscv_arch;
9209 extern const bfd_arch_info_type bfd_rs6000_arch;
9210 extern const bfd_arch_info_type bfd_rl78_arch;
9211 extern const bfd_arch_info_type bfd_rx_arch;
9212 @@ -701,6 +702,7 @@ static const bfd_arch_info_type * const
9213 &bfd_or1k_arch,
9214 &bfd_pdp11_arch,
9215 &bfd_powerpc_arch,
9216 + &bfd_riscv_arch,
9217 &bfd_rs6000_arch,
9218 &bfd_rl78_arch,
9219 &bfd_rx_arch,
9220 --- original-binutils/bfd/bfd-in2.h
9221 +++ binutils-2.26.1/bfd/bfd-in2.h
9222 @@ -2073,6 +2073,9 @@ enum bfd_architecture
9223 #define bfd_mach_ppc_e6500 5007
9224 #define bfd_mach_ppc_titan 83
9225 #define bfd_mach_ppc_vle 84
9226 + bfd_arch_riscv, /* RISC-V */
9227 +#define bfd_mach_riscv32 132
9228 +#define bfd_mach_riscv64 164
9229 bfd_arch_rs6000, /* IBM RS/6000 */
9230 #define bfd_mach_rs6k 6000
9231 #define bfd_mach_rs6k_rs1 6001
9232 @@ -5652,6 +5655,46 @@ relative offset from _GLOBAL_OFFSET_TABL
9233 value in a word. The relocation is relative offset from */
9234 BFD_RELOC_MICROBLAZE_32_GOTOFF,
9236 +/* RISC-V relocations. */
9237 + BFD_RELOC_RISCV_HI20,
9238 + BFD_RELOC_RISCV_PCREL_HI20,
9239 + BFD_RELOC_RISCV_PCREL_LO12_I,
9240 + BFD_RELOC_RISCV_PCREL_LO12_S,
9241 + BFD_RELOC_RISCV_LO12_I,
9242 + BFD_RELOC_RISCV_LO12_S,
9243 + BFD_RELOC_RISCV_GPREL12_I,
9244 + BFD_RELOC_RISCV_GPREL12_S,
9245 + BFD_RELOC_RISCV_TPREL_HI20,
9246 + BFD_RELOC_RISCV_TPREL_LO12_I,
9247 + BFD_RELOC_RISCV_TPREL_LO12_S,
9248 + BFD_RELOC_RISCV_TPREL_ADD,
9249 + BFD_RELOC_RISCV_CALL,
9250 + BFD_RELOC_RISCV_CALL_PLT,
9251 + BFD_RELOC_RISCV_ADD8,
9252 + BFD_RELOC_RISCV_ADD16,
9253 + BFD_RELOC_RISCV_ADD32,
9254 + BFD_RELOC_RISCV_ADD64,
9255 + BFD_RELOC_RISCV_SUB8,
9256 + BFD_RELOC_RISCV_SUB16,
9257 + BFD_RELOC_RISCV_SUB32,
9258 + BFD_RELOC_RISCV_SUB64,
9259 + BFD_RELOC_RISCV_GOT_HI20,
9260 + BFD_RELOC_RISCV_TLS_GOT_HI20,
9261 + BFD_RELOC_RISCV_TLS_GD_HI20,
9262 + BFD_RELOC_RISCV_JMP,
9263 + BFD_RELOC_RISCV_TLS_DTPMOD32,
9264 + BFD_RELOC_RISCV_TLS_DTPREL32,
9265 + BFD_RELOC_RISCV_TLS_DTPMOD64,
9266 + BFD_RELOC_RISCV_TLS_DTPREL64,
9267 + BFD_RELOC_RISCV_TLS_TPREL32,
9268 + BFD_RELOC_RISCV_TLS_TPREL64,
9269 + BFD_RELOC_RISCV_ALIGN,
9270 + BFD_RELOC_RISCV_RVC_BRANCH,
9271 + BFD_RELOC_RISCV_RVC_JUMP,
9272 + BFD_RELOC_RISCV_RVC_LUI,
9273 + BFD_RELOC_RISCV_GPREL_I,
9274 + BFD_RELOC_RISCV_GPREL_S,
9276 /* This is used to tell the dynamic linker to copy the value out of
9277 the dynamic object into the runtime process image. */
9278 BFD_RELOC_MICROBLAZE_COPY,
9279 --- original-binutils/bfd/config.bfd
9280 +++ binutils-2.26.1/bfd/config.bfd
9281 @@ -120,6 +120,7 @@ or1k*|or1knd*) targ_archs=bfd_or1k_arch
9282 pdp11*) targ_archs=bfd_pdp11_arch ;;
9283 pj*) targ_archs="bfd_pj_arch bfd_i386_arch";;
9284 powerpc*) targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
9285 +riscv*) targ_archs=bfd_riscv_arch ;;
9286 rs6000) targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
9287 s390*) targ_archs=bfd_s390_arch ;;
9288 sh*) targ_archs=bfd_sh_arch ;;
9289 @@ -1344,6 +1345,18 @@ case "${targ}" in
9290 targ_defvec=rl78_elf32_vec
9293 + riscv32-*-*)
9294 + targ_defvec=riscv_elf32_vec
9295 + targ_selvecs="riscv_elf32_vec"
9296 + want64=true
9297 + ;;
9299 + riscv64-*-*)
9300 + targ_defvec=riscv_elf64_vec
9301 + targ_selvecs="riscv_elf32_vec riscv_elf64_vec"
9302 + want64=true
9303 + ;;
9305 rx-*-elf)
9306 targ_defvec=rx_elf32_le_vec
9307 targ_selvecs="rx_elf32_be_vec rx_elf32_le_vec rx_elf32_be_ns_vec"
9308 --- original-binutils/bfd/configure
9309 +++ binutils-2.26.1/bfd/configure
9310 @@ -15472,6 +15472,8 @@ do
9311 powerpc_pei_vec) tb="$tb pei-ppc.lo peigen.lo $coff" ;;
9312 powerpc_pei_le_vec) tb="$tb pei-ppc.lo peigen.lo $coff" ;;
9313 powerpc_xcoff_vec) tb="$tb coff-rs6000.lo $xcoff" ;;
9314 + riscv_elf32_vec) tb="$tb elf32-riscv.lo elfxx-riscv.lo elf32.lo $elf" ;;
9315 + riscv_elf64_vec) tb="$tb elf64-riscv.lo elf64.lo elfxx-riscv.lo elf32.lo $elf"; target_size=64 ;;
9316 rl78_elf32_vec) tb="$tb elf32-rl78.lo elf32.lo $elf" ;;
9317 rs6000_xcoff64_vec) tb="$tb coff64-rs6000.lo aix5ppc-core.lo $xcoff"; target_size=64 ;;
9318 rs6000_xcoff64_aix_vec) tb="$tb coff64-rs6000.lo aix5ppc-core.lo $xcoff"; target_size=64 ;;
9319 --- original-binutils/bfd/configure.ac
9320 +++ binutils-2.26.1/bfd/configure.ac
9321 @@ -918,6 +918,8 @@ do
9322 powerpc_pei_vec) tb="$tb pei-ppc.lo peigen.lo $coff" ;;
9323 powerpc_pei_le_vec) tb="$tb pei-ppc.lo peigen.lo $coff" ;;
9324 powerpc_xcoff_vec) tb="$tb coff-rs6000.lo $xcoff" ;;
9325 + riscv_elf32_vec) tb="$tb elf32-riscv.lo elfxx-riscv.lo elf32.lo $elf" ;;
9326 + riscv_elf64_vec) tb="$tb elf64-riscv.lo elf64.lo elfxx-riscv.lo elf32.lo $elf"; target_size=64 ;;
9327 rl78_elf32_vec) tb="$tb elf32-rl78.lo elf32.lo $elf" ;;
9328 rs6000_xcoff64_vec) tb="$tb coff64-rs6000.lo aix5ppc-core.lo $xcoff"; target_size=64 ;;
9329 rs6000_xcoff64_aix_vec) tb="$tb coff64-rs6000.lo aix5ppc-core.lo $xcoff"; target_size=64 ;;
9330 --- original-binutils/bfd/elf-bfd.h
9331 +++ binutils-2.26.1/bfd/elf-bfd.h
9332 @@ -475,6 +475,7 @@ enum elf_target_id
9333 XGATE_ELF_DATA,
9334 TILEGX_ELF_DATA,
9335 TILEPRO_ELF_DATA,
9336 + RISCV_ELF_DATA,
9337 GENERIC_ELF_DATA
9340 --- original-binutils/bfd/Makefile.am
9341 +++ binutils-2.26.1/bfd/Makefile.am
9342 @@ -949,6 +949,18 @@ elf64-ia64.c : elfnn-ia64.c
9343 $(SED) -e s/NN/64/g < $(srcdir)/elfnn-ia64.c > elf64-ia64.new
9344 mv -f elf64-ia64.new elf64-ia64.c
9346 +elf32-riscv.c : elfnn-riscv.c
9347 + rm -f elf32-riscv.c
9348 + echo "#line 1 \"$(srcdir)/elfnn-riscv.c\"" > elf32-riscv.new
9349 + sed -e s/NN/32/g < $(srcdir)/elfnn-riscv.c >> elf32-riscv.new
9350 + mv -f elf32-riscv.new elf32-riscv.c
9352 +elf64-riscv.c : elfnn-riscv.c
9353 + rm -f elf64-riscv.c
9354 + echo "#line 1 \"$(srcdir)/elfnn-riscv.c\"" > elf64-riscv.new
9355 + sed -e s/NN/64/g < $(srcdir)/elfnn-riscv.c >> elf64-riscv.new
9356 + mv -f elf64-riscv.new elf64-riscv.c
9358 peigen.c : peXXigen.c
9359 rm -f peigen.c
9360 $(SED) -e s/XX/pe/g < $(srcdir)/peXXigen.c > peigen.new
9361 --- original-binutils/bfd/Makefile.in
9362 +++ binutils-2.26.1/bfd/Makefile.in
9363 @@ -450,6 +450,7 @@ ALL_MACHINES = \
9364 cpu-pj.lo \
9365 cpu-plugin.lo \
9366 cpu-powerpc.lo \
9367 + cpu-riscv.lo \
9368 cpu-rs6000.lo \
9369 cpu-rl78.lo \
9370 cpu-rx.lo \
9371 @@ -537,6 +538,7 @@ ALL_MACHINES_CFILES = \
9372 cpu-pj.c \
9373 cpu-plugin.c \
9374 cpu-powerpc.c \
9375 + cpu-riscv.c \
9376 cpu-rs6000.c \
9377 cpu-rl78.c \
9378 cpu-rx.c \
9379 @@ -2035,6 +2037,18 @@ elf64-ia64.c : elfnn-ia64.c
9380 $(SED) -e s/NN/64/g < $(srcdir)/elfnn-ia64.c > elf64-ia64.new
9381 mv -f elf64-ia64.new elf64-ia64.c
9383 +elf32-riscv.c : elfnn-riscv.c
9384 + rm -f elf32-riscv.c
9385 + echo "#line 1 \"$(srcdir)/elfnn-riscv.c\"" > elf32-riscv.new
9386 + sed -e s/NN/32/g < $(srcdir)/elfnn-riscv.c >> elf32-riscv.new
9387 + mv -f elf32-riscv.new elf32-riscv.c
9389 +elf64-riscv.c : elfnn-riscv.c
9390 + rm -f elf64-riscv.c
9391 + echo "#line 1 \"$(srcdir)/elfnn-riscv.c\"" > elf64-riscv.new
9392 + sed -e s/NN/64/g < $(srcdir)/elfnn-riscv.c >> elf64-riscv.new
9393 + mv -f elf64-riscv.new elf64-riscv.c
9395 peigen.c : peXXigen.c
9396 rm -f peigen.c
9397 $(SED) -e s/XX/pe/g < $(srcdir)/peXXigen.c > peigen.new
9398 --- original-binutils/bfd/targets.c
9399 +++ binutils-2.26.1/bfd/targets.c
9400 @@ -793,6 +793,8 @@ extern const bfd_target powerpc_pe_le_ve
9401 extern const bfd_target powerpc_pei_vec;
9402 extern const bfd_target powerpc_pei_le_vec;
9403 extern const bfd_target powerpc_xcoff_vec;
9404 +extern const bfd_target riscv_elf32_vec;
9405 +extern const bfd_target riscv_elf64_vec;
9406 extern const bfd_target rl78_elf32_vec;
9407 extern const bfd_target rs6000_xcoff64_vec;
9408 extern const bfd_target rs6000_xcoff64_aix_vec;
9409 --- original-binutils/binutils/readelf.c
9410 +++ binutils-2.26.1/binutils/readelf.c
9411 @@ -124,6 +124,7 @@
9412 #include "elf/metag.h"
9413 #include "elf/microblaze.h"
9414 #include "elf/mips.h"
9415 +#include "elf/riscv.h"
9416 #include "elf/mmix.h"
9417 #include "elf/mn10200.h"
9418 #include "elf/mn10300.h"
9419 @@ -771,6 +772,7 @@ guess_is_rela (unsigned int e_machine)
9420 case EM_OR1K:
9421 case EM_PPC64:
9422 case EM_PPC:
9423 + case EM_RISCV:
9424 case EM_RL78:
9425 case EM_RX:
9426 case EM_S390:
9427 @@ -1309,6 +1311,10 @@ dump_relocations (FILE * file,
9428 rtype = elf_mips_reloc_type (type);
9429 break;
9431 + case EM_RISCV:
9432 + rtype = elf_riscv_reloc_type (type);
9433 + break;
9435 case EM_ALPHA:
9436 rtype = elf_alpha_reloc_type (type);
9437 break;
9438 @@ -2250,6 +2256,7 @@ get_machine_name (unsigned e_machine)
9439 case EM_CR16:
9440 case EM_MICROBLAZE:
9441 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
9442 + case EM_RISCV: return "RISC-V";
9443 case EM_RL78: return "Renesas RL78";
9444 case EM_RX: return "Renesas RX";
9445 case EM_METAG: return "Imagination Technologies Meta processor architecture";
9446 @@ -3193,6 +3200,13 @@ get_machine_flags (unsigned e_flags, uns
9447 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
9448 break;
9450 + case EM_RISCV:
9451 + if (e_flags & EF_RISCV_RVC)
9452 + strcat (buf, ", RVC");
9453 + if (e_flags & EF_RISCV_SOFT_FLOAT)
9454 + strcat (buf, ", soft-float ABI");
9455 + break;
9457 case EM_SH:
9458 switch ((e_flags & EF_SH_MACH_MASK))
9460 @@ -11430,6 +11444,8 @@ is_32bit_abs_reloc (unsigned int reloc_t
9461 return reloc_type == 1; /* R_PPC64_ADDR32. */
9462 case EM_PPC:
9463 return reloc_type == 1; /* R_PPC_ADDR32. */
9464 + case EM_RISCV:
9465 + return reloc_type == 1; /* R_RISCV_32. */
9466 case EM_RL78:
9467 return reloc_type == 1; /* R_RL78_DIR32. */
9468 case EM_RX:
9469 @@ -11576,6 +11592,8 @@ is_64bit_abs_reloc (unsigned int reloc_t
9470 return reloc_type == 80; /* R_PARISC_DIR64. */
9471 case EM_PPC64:
9472 return reloc_type == 38; /* R_PPC64_ADDR64. */
9473 + case EM_RISCV:
9474 + return reloc_type == 2; /* R_RISCV_64. */
9475 case EM_SPARC32PLUS:
9476 case EM_SPARCV9:
9477 case EM_SPARC:
9478 @@ -11730,6 +11748,7 @@ is_none_reloc (unsigned int reloc_type)
9479 case EM_ADAPTEVA_EPIPHANY:
9480 case EM_PPC: /* R_PPC_NONE. */
9481 case EM_PPC64: /* R_PPC64_NONE. */
9482 + case EM_RISCV: /* R_RISCV_NONE. */
9483 case EM_ARC: /* R_ARC_NONE. */
9484 case EM_ARC_COMPACT: /* R_ARC_NONE. */
9485 case EM_ARC_COMPACT2: /* R_ARC_NONE. */
9486 --- original-binutils/gas/configure
9487 +++ binutils-2.26.1/gas/configure
9488 @@ -12418,7 +12418,7 @@ $as_echo "#define NDS32_DEFAULT_AUDIO_EX
9489 $as_echo "$enable_audio_ext" >&6; }
9492 - i386 | s390 | sparc)
9493 + i386 | riscv | s390 | sparc)
9494 if test $this_target = $target ; then
9496 cat >>confdefs.h <<_ACEOF
9497 --- original-binutils/gas/configure.ac
9498 +++ binutils-2.26.1/gas/configure.ac
9499 @@ -466,7 +466,7 @@ changequote([,])dnl
9500 AC_MSG_RESULT($enable_audio_ext)
9503 - i386 | s390 | sparc)
9504 + i386 | riscv | s390 | sparc)
9505 if test $this_target = $target ; then
9506 AC_DEFINE_UNQUOTED(DEFAULT_ARCH, "${arch}", [Default architecture.])
9508 --- original-binutils/gas/configure.tgt
9509 +++ binutils-2.26.1/gas/configure.tgt
9510 @@ -87,6 +87,8 @@ case ${cpu} in
9511 pj*) cpu_type=pj endian=big ;;
9512 powerpc*le*) cpu_type=ppc endian=little ;;
9513 powerpc*) cpu_type=ppc endian=big ;;
9514 + riscv32*) cpu_type=riscv endian=little arch=riscv32 ;;
9515 + riscv64*) cpu_type=riscv endian=little arch=riscv64 ;;
9516 rs6000*) cpu_type=ppc ;;
9517 rl78*) cpu_type=rl78 ;;
9518 rx) cpu_type=rx ;;
9519 @@ -391,6 +393,8 @@ case ${generic_target} in
9520 ppc-*-kaos*) fmt=elf ;;
9521 ppc-*-lynxos*) fmt=elf em=lynx ;;
9523 + riscv*-*-*) fmt=elf endian=little em=linux ;;
9525 s390-*-linux-*) fmt=elf em=linux ;;
9526 s390-*-tpf*) fmt=elf ;;
9528 @@ -488,7 +492,7 @@ case ${generic_target} in
9529 esac
9531 case ${cpu_type} in
9532 - aarch64 | alpha | arm | i386 | ia64 | microblaze | mips | ns32k | or1k | or1knd | pdp11 | ppc | sparc | z80 | z8k)
9533 + aarch64 | alpha | arm | i386 | ia64 | microblaze | mips | ns32k | or1k | or1knd | pdp11 | ppc | riscv | sparc | z80 | z8k)
9534 bfd_gas=yes
9536 esac
9537 --- original-binutils/gas/Makefile.am
9538 +++ binutils-2.26.1/gas/Makefile.am
9539 @@ -177,6 +177,7 @@ TARGET_CPU_CFILES = \
9540 config/tc-pdp11.c \
9541 config/tc-pj.c \
9542 config/tc-ppc.c \
9543 + config/tc-riscv.c \
9544 config/tc-rl78.c \
9545 config/tc-rx.c \
9546 config/tc-s390.c \
9547 @@ -250,6 +251,7 @@ TARGET_CPU_HFILES = \
9548 config/tc-pdp11.h \
9549 config/tc-pj.h \
9550 config/tc-ppc.h \
9551 + config/tc-riscv.h \
9552 config/tc-rl78.h \
9553 config/tc-rx.h \
9554 config/tc-s390.h \
9555 --- original-binutils/gas/Makefile.in
9556 +++ binutils-2.26.1/gas/Makefile.in
9557 @@ -448,6 +448,7 @@ TARGET_CPU_CFILES = \
9558 config/tc-pdp11.c \
9559 config/tc-pj.c \
9560 config/tc-ppc.c \
9561 + config/tc-riscv.c \
9562 config/tc-rl78.c \
9563 config/tc-rx.c \
9564 config/tc-s390.c \
9565 @@ -521,6 +522,7 @@ TARGET_CPU_HFILES = \
9566 config/tc-pdp11.h \
9567 config/tc-pj.h \
9568 config/tc-ppc.h \
9569 + config/tc-riscv.h \
9570 config/tc-rl78.h \
9571 config/tc-rx.h \
9572 config/tc-s390.h \
9573 @@ -878,6 +880,7 @@ distclean-compile:
9574 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-pdp11.Po@am__quote@
9575 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-pj.Po@am__quote@
9576 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-ppc.Po@am__quote@
9577 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-riscv.Po@am__quote@
9578 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-rl78.Po@am__quote@
9579 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-rx.Po@am__quote@
9580 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-s390.Po@am__quote@
9581 @@ -1598,6 +1601,20 @@ tc-ppc.obj: config/tc-ppc.c
9582 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
9583 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tc-ppc.obj `if test -f 'config/tc-ppc.c'; then $(CYGPATH_W) 'config/tc-ppc.c'; else $(CYGPATH_W) '$(srcdir)/config/tc-ppc.c'; fi`
9585 +tc-riscv.o: config/tc-riscv.c
9586 +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tc-riscv.o -MD -MP -MF $(DEPDIR)/tc-riscv.Tpo -c -o tc-riscv.o `test -f 'config/tc-riscv.c' || echo '$(srcdir)/'`config/tc-riscv.c
9587 +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/tc-riscv.Tpo $(DEPDIR)/tc-riscv.Po
9588 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='config/tc-riscv.c' object='tc-riscv.o' libtool=no @AMDEPBACKSLASH@
9589 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
9590 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tc-riscv.o `test -f 'config/tc-riscv.c' || echo '$(srcdir)/'`config/tc-riscv.c
9592 +tc-riscv.obj: config/tc-riscv.c
9593 +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tc-riscv.obj -MD -MP -MF $(DEPDIR)/tc-riscv.Tpo -c -o tc-riscv.obj `if test -f 'config/tc-riscv.c'; then $(CYGPATH_W) 'config/tc-riscv.c'; else $(CYGPATH_W) '$(srcdir)/config/tc-riscv.c'; fi`
9594 +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/tc-riscv.Tpo $(DEPDIR)/tc-riscv.Po
9595 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='config/tc-riscv.c' object='tc-riscv.obj' libtool=no @AMDEPBACKSLASH@
9596 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
9597 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tc-riscv.obj `if test -f 'config/tc-riscv.c'; then $(CYGPATH_W) 'config/tc-riscv.c'; else $(CYGPATH_W) '$(srcdir)/config/tc-riscv.c'; fi`
9599 tc-rl78.o: config/tc-rl78.c
9600 @am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tc-rl78.o -MD -MP -MF $(DEPDIR)/tc-rl78.Tpo -c -o tc-rl78.o `test -f 'config/tc-rl78.c' || echo '$(srcdir)/'`config/tc-rl78.c
9601 @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/tc-rl78.Tpo $(DEPDIR)/tc-rl78.Po
9602 --- original-binutils/include/dis-asm.h
9603 +++ binutils-2.26.1/include/dis-asm.h
9604 @@ -263,6 +263,7 @@ extern int print_insn_little_arm (bfd_vm
9605 extern int print_insn_little_mips (bfd_vma, disassemble_info *);
9606 extern int print_insn_little_nios2 (bfd_vma, disassemble_info *);
9607 extern int print_insn_little_powerpc (bfd_vma, disassemble_info *);
9608 +extern int print_insn_riscv (bfd_vma, disassemble_info *);
9609 extern int print_insn_little_score (bfd_vma, disassemble_info *);
9610 extern int print_insn_lm32 (bfd_vma, disassemble_info *);
9611 extern int print_insn_m32c (bfd_vma, disassemble_info *);
9612 @@ -327,6 +328,7 @@ extern void print_aarch64_disassembler_o
9613 extern void print_i386_disassembler_options (FILE *);
9614 extern void print_mips_disassembler_options (FILE *);
9615 extern void print_ppc_disassembler_options (FILE *);
9616 +extern void print_riscv_disassembler_options (FILE *);
9617 extern void print_arm_disassembler_options (FILE *);
9618 extern void parse_arm_disassembler_option (char *);
9619 extern void print_s390_disassembler_options (FILE *);
9620 --- original-binutils/include/elf/common.h
9621 +++ binutils-2.26.1/include/elf/common.h
9622 @@ -306,6 +306,7 @@
9623 #define EM_VISIUM 221 /* Controls and Data Services VISIUMcore processor */
9624 #define EM_FT32 222 /* FTDI Chip FT32 high performance 32-bit RISC architecture */
9625 #define EM_MOXIE 223 /* Moxie processor family */
9626 +#define EM_RISCV 243 /* RISC-V */
9628 /* If it is necessary to assign new unofficial EM_* values, please pick large
9629 random numbers (0x8523, 0xa7f2, etc.) to minimize the chances of collision
9630 --- original-binutils/ld/configure.tgt
9631 +++ binutils-2.26.1/ld/configure.tgt
9632 @@ -638,6 +638,12 @@ powerpc-*-aix*) targ_emul=aixppc ;;
9633 powerpc-*-beos*) targ_emul=aixppc ;;
9634 powerpc-*-windiss*) targ_emul=elf32ppcwindiss ;;
9635 powerpc-*-lynxos*) targ_emul=ppclynx ;;
9636 +riscv32*-*-*) targ_emul=elf32lriscv
9637 + targ_extra_emuls="elf64lriscv"
9638 + targ_extra_libpath=$targ_extra_emuls ;;
9639 +riscv64*-*-*) targ_emul=elf64lriscv
9640 + targ_extra_emuls="elf32lriscv"
9641 + targ_extra_libpath=$targ_extra_emuls ;;
9642 rs6000-*-aix[5-9]*) targ_emul=aix5rs6 ;;
9643 rs6000-*-aix*) targ_emul=aixrs6
9645 --- original-binutils/ld/Makefile.am
9646 +++ binutils-2.26.1/ld/Makefile.am
9647 @@ -267,6 +267,7 @@ ALL_EMULATION_SOURCES = \
9648 eelf32ppcsim.c \
9649 eelf32ppcvxworks.c \
9650 eelf32ppcwindiss.c \
9651 + eelf32lriscv.c \
9652 eelf32rl78.c \
9653 eelf32rx.c \
9654 eelf32tilegx.c \
9655 @@ -483,6 +484,7 @@ ALL_64_EMULATION_SOURCES = \
9656 eelf64btsmip_fbsd.c \
9657 eelf64hppa.c \
9658 eelf64lppc.c \
9659 + eelf64lriscv.c \
9660 eelf64ltsmip.c \
9661 eelf64ltsmip_fbsd.c \
9662 eelf64mmix.c \
9663 @@ -1144,6 +1146,11 @@ eelf32lppcsim.c: $(srcdir)/emulparams/el
9664 $(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
9665 $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
9667 +eelf32lriscv.c: $(srcdir)/emulparams/elf32lriscv.sh \
9668 + $(srcdir)/emulparams/elf32lriscv-defs.sh $(ELF_DEPS) \
9669 + $(srcdir)/emultempl/riscvelf.em $(srcdir)/scripttempl/elf.sc \
9670 + ${GEN_DEPENDS}
9672 eelf32lsmip.c: $(srcdir)/emulparams/elf32lsmip.sh \
9673 $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
9674 $(ELF_DEPS) $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc \
9675 @@ -1937,6 +1944,12 @@ eelf64lppc.c: $(srcdir)/emulparams/elf64
9676 ldemul-list.h \
9677 $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
9679 +eelf64lriscv.c: $(srcdir)/emulparams/elf64lriscv.sh \
9680 + $(srcdir)/emulparams/elf64lriscv-defs.sh \
9681 + $(srcdir)/emulparams/elf32lriscv-defs.sh $(ELF_DEPS) \
9682 + $(srcdir)/emultempl/riscvelf.em $(srcdir)/scripttempl/elf.sc \
9683 + ${GEN_DEPENDS}
9685 eelf64ltsmip.c: $(srcdir)/emulparams/elf64ltsmip.sh \
9686 $(srcdir)/emulparams/elf64btsmip.sh $(srcdir)/emulparams/elf64bmip-defs.sh \
9687 $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
9688 --- original-binutils/ld/Makefile.in
9689 +++ binutils-2.26.1/ld/Makefile.in
9690 @@ -577,6 +577,7 @@ ALL_EMULATION_SOURCES = \
9691 eelf32lppclinux.c \
9692 eelf32lppcnto.c \
9693 eelf32lppcsim.c \
9694 + eelf32lriscv.c \
9695 eelf32m32c.c \
9696 eelf32mb_linux.c \
9697 eelf32mbel_linux.c \
9698 @@ -812,6 +813,7 @@ ALL_64_EMULATION_SOURCES = \
9699 eelf64btsmip_fbsd.c \
9700 eelf64hppa.c \
9701 eelf64lppc.c \
9702 + eelf64lriscv.c \
9703 eelf64ltsmip.c \
9704 eelf64ltsmip_fbsd.c \
9705 eelf64mmix.c \
9706 @@ -1219,6 +1221,7 @@ distclean-compile:
9707 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lppclinux.Po@am__quote@
9708 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lppcnto.Po@am__quote@
9709 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lppcsim.Po@am__quote@
9710 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lriscv.Po@am__quote@
9711 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lr5900.Po@am__quote@
9712 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lr5900n32.Po@am__quote@
9713 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32lsmip.Po@am__quote@
9714 @@ -1274,6 +1277,7 @@ distclean-compile:
9715 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64btsmip_fbsd.Po@am__quote@
9716 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64hppa.Po@am__quote@
9717 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lppc.Po@am__quote@
9718 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv.Po@am__quote@
9719 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip.Po@am__quote@
9720 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip_fbsd.Po@am__quote@
9721 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64mmix.Po@am__quote@
9722 @@ -2650,6 +2654,11 @@ eelf32lppcsim.c: $(srcdir)/emulparams/el
9723 $(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
9724 $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
9726 +eelf32lriscv.c: $(srcdir)/emulparams/elf32lriscv.sh \
9727 + $(srcdir)/emulparams/elf32lriscv-defs.sh $(ELF_DEPS) \
9728 + $(srcdir)/emultempl/riscvelf.em $(srcdir)/scripttempl/elf.sc \
9729 + ${GEN_DEPENDS}
9731 eelf32lsmip.c: $(srcdir)/emulparams/elf32lsmip.sh \
9732 $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
9733 $(ELF_DEPS) $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc \
9734 @@ -3443,6 +3452,12 @@ eelf64lppc.c: $(srcdir)/emulparams/elf64
9735 ldemul-list.h \
9736 $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
9738 +eelf64lriscv.c: $(srcdir)/emulparams/elf64lriscv.sh \
9739 + $(srcdir)/emulparams/elf64lriscv-defs.sh \
9740 + $(srcdir)/emulparams/elf32lriscv-defs.sh $(ELF_DEPS) \
9741 + $(srcdir)/emultempl/riscvelf.em $(srcdir)/scripttempl/elf.sc \
9742 + ${GEN_DEPENDS}
9744 eelf64ltsmip.c: $(srcdir)/emulparams/elf64ltsmip.sh \
9745 $(srcdir)/emulparams/elf64btsmip.sh $(srcdir)/emulparams/elf64bmip-defs.sh \
9746 $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
9747 --- original-binutils/opcodes/configure
9748 +++ binutils-2.26.1/opcodes/configure
9749 @@ -12603,6 +12603,7 @@ if test x${all_targets} = xfalse ; then
9750 bfd_powerpc_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;;
9751 bfd_powerpc_64_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;;
9752 bfd_pyramid_arch) ;;
9753 + bfd_riscv_arch) ta="$ta riscv-dis.lo riscv-opc.lo" ;;
9754 bfd_romp_arch) ;;
9755 bfd_rs6000_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;;
9756 bfd_rl78_arch) ta="$ta rl78-dis.lo rl78-decode.lo";;
9757 --- original-binutils/opcodes/disassemble.c
9758 +++ binutils-2.26.1/opcodes/disassemble.c
9759 @@ -376,6 +376,11 @@ disassembler (abfd)
9760 disassemble = print_insn_little_powerpc;
9761 break;
9762 #endif
9763 +#ifdef ARCH_riscv
9764 + case bfd_arch_riscv:
9765 + disassemble = print_insn_riscv;
9766 + break;
9767 +#endif
9768 #ifdef ARCH_rs6000
9769 case bfd_arch_rs6000:
9770 if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
9771 @@ -558,6 +563,9 @@ disassembler_usage (stream)
9772 #ifdef ARCH_powerpc
9773 print_ppc_disassembler_options (stream);
9774 #endif
9775 +#ifdef ARCH_riscv
9776 + print_riscv_disassembler_options (stream);
9777 +#endif
9778 #ifdef ARCH_i386
9779 print_i386_disassembler_options (stream);
9780 #endif