| 1 |
/* BPF-specific code for C family languages. |
| 2 |
Copyright (C) 2024-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Oracle Inc. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#define IN_TARGET_CODE 1 |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include "system.h" |
| 25 |
#include "coretypes.h" |
| 26 |
#include "tm.h" |
| 27 |
#include "c-family/c-common.h" |
| 28 |
#include "cpplib.h" |
| 29 |
|
| 30 |
/* Define target-specific CPP macros. This function in used in the |
| 31 |
definition of TARGET_CPU_CPP_BUILTINS in bpf.h */ |
| 32 |
|
| 33 |
#define builtin_define(TXT) cpp_define (pfile, TXT) |
| 34 |
|
| 35 |
void |
| 36 |
bpf_target_macros (cpp_reader *pfile) |
| 37 |
{ |
| 38 |
builtin_define ("__BPF__"); |
| 39 |
builtin_define ("__bpf__"); |
| 40 |
|
| 41 |
if (TARGET_BIG_ENDIAN) |
| 42 |
builtin_define ("__BPF_BIG_ENDIAN__"); |
| 43 |
else |
| 44 |
builtin_define ("__BPF_LITTLE_ENDIAN__"); |
| 45 |
|
| 46 |
switch (bpf_isa) |
| 47 |
{ |
| 48 |
case ISA_V1: |
| 49 |
builtin_define_with_int_value ("__BPF_CPU_VERSION__", 1); |
| 50 |
break; |
| 51 |
case ISA_V2: |
| 52 |
builtin_define_with_int_value ("__BPF_CPU_VERSION__", 2); |
| 53 |
break; |
| 54 |
case ISA_V3: |
| 55 |
builtin_define_with_int_value ("__BPF_CPU_VERSION__", 3); |
| 56 |
break; |
| 57 |
case ISA_V4: |
| 58 |
builtin_define_with_int_value ("__BPF_CPU_VERSION__", 4); |
| 59 |
break; |
| 60 |
default: |
| 61 |
gcc_unreachable (); |
| 62 |
break; |
| 63 |
} |
| 64 |
|
| 65 |
/* Different BPF CPU versions support different features. Some of |
| 66 |
them can be enabled/disabled explicitly. */ |
| 67 |
if (bpf_has_alu32) |
| 68 |
builtin_define ("__BPF_FEATURE_ALU32"); |
| 69 |
if (bpf_has_jmp32) |
| 70 |
builtin_define ("__BPF_FEATURE_JMP32"); |
| 71 |
if (bpf_has_jmpext) |
| 72 |
builtin_define ("__BPF_FEATURE_JMP_EXT"); |
| 73 |
if (bpf_has_bswap) |
| 74 |
builtin_define ("__BPF_FEATURE_BSWAP"); |
| 75 |
if (bpf_has_sdiv) |
| 76 |
builtin_define ("__BPF_FEATURE_SDIV_SMOD"); |
| 77 |
if (bpf_has_smov) |
| 78 |
builtin_define ("__BPF_FEATURE_MOVSX"); |
| 79 |
|
| 80 |
/* Other CPU features can only be enabled/disabled generically by |
| 81 |
selecting the corresponding CPU version. */ |
| 82 |
if (bpf_isa >= ISA_V4) |
| 83 |
{ |
| 84 |
builtin_define ("__BPF_FEATURE_LDSX"); |
| 85 |
builtin_define ("__BPF_FEATURE_GOTOL"); |
| 86 |
builtin_define ("__BPF_FEATURE_ST"); |
| 87 |
} |
| 88 |
} |