1 /* EBPF opcode support. -*- c -*-
3 Copyright (C) 2019 Free Software Foundation, Inc.
5 Contributed by Oracle, Inc.
7 This file is part of the GNU Binutils and of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 Each section is delimited with start and end markers.
27 <arch>-opc.h additions use: "-- opc.h"
28 <arch>-opc.c additions use: "-- opc.c"
29 <arch>-asm.c additions use: "-- asm.c"
30 <arch>-dis.c additions use: "-- dis.c"
31 <arch>-ibd.h additions use: "-- ibd.h". */
35 #undef CGEN_DIS_HASH_SIZE
36 #define CGEN_DIS_HASH_SIZE 1
39 #define CGEN_DIS_HASH(buffer, value) 0
41 /* Allows reason codes to be output when assembler errors occur. */
42 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
44 #define CGEN_VALIDATE_INSN_SUPPORTED
45 extern int bpf_cgen_insn_supported (CGEN_CPU_DESC, const CGEN_INSN *);
52 /* Parse a signed 64-bit immediate. */
55 parse_imm64 (CGEN_CPU_DESC cd,
61 enum cgen_parse_operand_result result;
64 errmsg = (* cd->parse_operand_fn)
65 (cd, CGEN_PARSE_OPERAND_INTEGER, strp, opindex, BFD_RELOC_NONE,
73 /* Endianness size operands are integer immediates whose values can be
77 parse_endsize (CGEN_CPU_DESC cd,
80 unsigned long *valuep)
84 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
95 return _("expected 16, 32 or 64 in");
101 /* Special check to ensure that the right instruction variant is used
102 for the given endianness induced by the ISA selected in the CPU.
103 See bpf.cpu for a discussion on how eBPF is really two instruction
107 bpf_cgen_insn_supported (CGEN_CPU_DESC cd, const CGEN_INSN *insn)
109 CGEN_BITSET isas = CGEN_INSN_BITSET_ATTR_VALUE (insn, CGEN_INSN_ISA);
111 return cgen_bitset_intersect_p (&isas, cd->isas);
117 /* We need to customize the disassembler a bit:
118 - Use 8 bytes per line by default.
121 #define CGEN_PRINT_INSN bpf_print_insn
124 bpf_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
126 bfd_byte buf[CGEN_MAX_INSN_SIZE];
130 info->bytes_per_chunk = 1;
131 info->bytes_per_line = 8;
133 /* Attempt to read the base part of the insn. */
134 buflen = cd->base_insn_bitsize / 8;
135 status = (*info->read_memory_func) (pc, buf, buflen, info);
137 /* Try again with the minimum part, if min < base. */
138 if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
140 buflen = cd->min_insn_bitsize / 8;
141 status = (*info->read_memory_func) (pc, buf, buflen, info);
146 (*info->memory_error_func) (status, pc, info);
150 return print_insn (cd, pc, info, buf, buflen);
153 /* Signed immediates should be printed in hexadecimal. */
156 print_immediate (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
159 unsigned int attrs ATTRIBUTE_UNUSED,
160 bfd_vma pc ATTRIBUTE_UNUSED,
161 int length ATTRIBUTE_UNUSED)
163 disassemble_info *info = (disassemble_info *) dis_info;
166 (*info->fprintf_func) (info->stream, "%" PRId64, value);
168 (*info->fprintf_func) (info->stream, "%#" PRIx64, value);
170 /* This is to avoid -Wunused-function for print_normal. */
172 print_normal (cd, dis_info, value, attrs, pc, length);
175 /* Endianness bit sizes should be printed in decimal. */
178 print_endsize (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
181 unsigned int attrs ATTRIBUTE_UNUSED,
182 bfd_vma pc ATTRIBUTE_UNUSED,
183 int length ATTRIBUTE_UNUSED)
185 disassemble_info *info = (disassemble_info *) dis_info;
186 (*info->fprintf_func) (info->stream, "%lu", value);