mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-02-17 13:10:12 +08:00
This patch adds support to the GNU assembler for an alternative assembly syntax used in BPF. This syntax is C-like and very unconventional for an assembly language, but it is generated by clang/llvm and is also used in inline asm templates in kernel code, so we ought to support it. After this patch, the assembler is able to parse instructions in both supported syntax: the normal assembly-like syntax and the pseudo-C syntax. Instruction formats can be mixed in the source program: the assembler recognizes the right syntax to use. gas/ChangeLog: 2023-04-20 Guillermo E. Martinez <guillermo.e.martinez@oracle.com> PR gas/29728 * config/tc-bpf.h (TC_EQUAL_IN_INSN): Define. * config/tc-bpf.c (LEX_IS_SYMBOL_COMPONENT): Define. (LEX_IS_WHITESPACE): Likewise. (LEX_IS_NEWLINE): Likewise. (LEX_IS_ARITHM_OP): Likewise. (LEX_IS_STAR): Likewise. (LEX_IS_CLSE_BR): Likewise. (LEX_IS_OPEN_BR): Likewise. (LEX_IS_EQUAL): Likewise. (LEX_IS_EXCLA): Likewise. (ST_EOI): Likewise. (MAX_TOKEN_SZ): Likewise. (init_pseudoc_lex): New function. (md_begin): Call init_pseudoc_lex. (valid_expr): New function. (build_bpf_non_generic_load): Likewise. (build_bpf_atomic_insn): Likewise. (build_bpf_jmp_insn): Likewise. (build_bpf_arithm_insn): Likewise. (build_bpf_endianness): Likewise. (build_bpf_load_store_insn): Likewise. (look_for_reserved_word): Likewise. (is_register): Likewise. (is_cast): Likewise. (get_token): Likewise. (bpf_pseudoc_to_normal_syntax): Likewise. (md_assemble): Try pseudo-C syntax if an instruction cannot be parsed.
56 lines
1.9 KiB
C
56 lines
1.9 KiB
C
/* tc-bpf.h -- Header file for tc-ebpf.c.
|
|
Copyright (C) 2019-2023 Free Software Foundation, Inc.
|
|
Contributed by Oracle, Inc.
|
|
|
|
This file is part of GAS, the GNU Assembler.
|
|
|
|
GAS is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GAS is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GAS; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
|
|
02110-1301, USA. */
|
|
|
|
#define TC_BPF
|
|
|
|
#define LISTING_HEADER "BPF GAS "
|
|
|
|
/* The target BFD architecture. */
|
|
#define TARGET_ARCH bfd_arch_bpf
|
|
#define TARGET_MACH 0 /* The default. */
|
|
|
|
#define TARGET_FORMAT \
|
|
(target_big_endian ? "elf64-bpfbe" : "elf64-bpfle")
|
|
|
|
/* This is used to set the default value for `target_big_endian'. */
|
|
#ifndef TARGET_BYTES_BIG_ENDIAN
|
|
#define TARGET_BYTES_BIG_ENDIAN 0
|
|
#endif
|
|
|
|
/* .-foo gets turned into PC relative relocs. */
|
|
#define DIFF_EXPR_OK 1
|
|
#define GAS_CGEN_PCREL_R_TYPE(R_TYPE) gas_cgen_pcrel_r_type (R_TYPE)
|
|
|
|
/* Call md_pcrel_from_section(), not md_pcrel_from(). */
|
|
#define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from_section (FIXP, SEC)
|
|
|
|
/* We don't need to handle .word strangely. */
|
|
#define WORKING_DOT_WORD
|
|
|
|
/* Values passed to md_apply_fix don't include the symbol value. */
|
|
#define MD_APPLY_SYM_VALUE(FIX) 0
|
|
|
|
/* The Linux kernel verifier expects NOPs to be encoded in this way;
|
|
a jump to offset 0 means jump to the next instruction. */
|
|
#define md_single_noop_insn "ja 0"
|
|
|
|
#define TC_EQUAL_IN_INSN(c, s) 1
|