Debian Codegraph @

arch/BPF/BPFConstants.h

raw symbols SCIP
1 /* Capstone Disassembly Engine */
2 /* BPF Backend by david942j <[email protected]>, 2019 */
3
4 /* This file defines constants and macros used for parsing a BPF instruction */
5
6 #ifndef CS_BPF_CONSTANTS_H
7 #define CS_BPF_CONSTANTS_H
8
9 #define BPF_CLASS(code) ((code) & 0x7)
10
11 ///< Instruction classes
12 #define BPF_CLASS_LD 0x00
13 #define BPF_CLASS_LDX 0x01
14 #define BPF_CLASS_ST 0x02
15 #define BPF_CLASS_STX 0x03
16 #define BPF_CLASS_ALU 0x04
17 #define BPF_CLASS_JMP 0x05
18 #define BPF_CLASS_RET 0x06 ///< cBPF only
19 #define BPF_CLASS_MISC 0x07 ///< cBPF only
20 #define BPF_CLASS_ALU64 0x07 ///< eBPF only
21
22 #define BPF_OP(code) ((code) & 0xf0)
23
24 ///< Types of ALU instruction
25 #define BPF_ALU_ADD 0x00
26 #define BPF_ALU_SUB 0x10
27 #define BPF_ALU_MUL 0x20
28 #define BPF_ALU_DIV 0x30
29 #define BPF_ALU_OR 0x40
30 #define BPF_ALU_AND 0x50
31 #define BPF_ALU_LSH 0x60
32 #define BPF_ALU_RSH 0x70
33 #define BPF_ALU_NEG 0x80
34 #define BPF_ALU_MOD 0x90
35 #define BPF_ALU_XOR 0xa0
36 #define BPF_ALU_MOV 0xb0 ///< eBPF only: mov reg to reg
37 #define BPF_ALU_ARSH 0xc0 ///< eBPF only: sign extending shift right
38 #define BPF_ALU_END 0xd0 ///< eBPF only: endianness conversion
39
40 ///< Types of jmp instruction
41 #define BPF_JUMP_JA 0x00 ///< goto
42 #define BPF_JUMP_JEQ 0x10 ///< '=='
43 #define BPF_JUMP_JGT 0x20 ///< unsigned '>'
44 #define BPF_JUMP_JGE 0x30 ///< unsigned '>='
45 #define BPF_JUMP_JSET 0x40 ///< '&'
46 #define BPF_JUMP_JNE 0x50 ///< eBPF only: '!=' */
47 #define BPF_JUMP_JSGT 0x60 ///< eBPF only: signed '>'
48 #define BPF_JUMP_JSGE 0x70 ///< eBPF only: signed '>='
49 #define BPF_JUMP_CALL 0x80 ///< eBPF only: function call
50 #define BPF_JUMP_EXIT 0x90 ///< eBPF only: exit
51 #define BPF_JUMP_JLT 0xa0 ///< eBPF only: unsigned '<'
52 #define BPF_JUMP_JLE 0xb0 ///< eBPF only: unsigned '<='
53 #define BPF_JUMP_JSLT 0xc0 ///< eBPF only: signed '<'
54 #define BPF_JUMP_JSLE 0xd0 ///< eBPF only: signed '<='
55
56 #define BPF_SRC(code) ((code) & 0x08)
57 #define BPF_RVAL(code) ((code) & 0x18) /* cBPF only: for return types */
58 ///< Source operand
59 #define BPF_SRC_K 0x00
60 #define BPF_SRC_X 0x08
61 #define BPF_SRC_A 0x10 /* cBPF only */
62
63 #define BPF_SRC_LITTLE BPF_SRC_K
64 #define BPF_SRC_BIG BPF_SRC_X
65
66 #define BPF_SIZE(code) ((code) & 0x18)
67 ///< Size modifier
68 #define BPF_SIZE_W 0x00 ///< word
69 #define BPF_SIZE_H 0x08 ///< half word
70 #define BPF_SIZE_B 0x10 ///< byte
71 #define BPF_SIZE_DW 0x18 ///< eBPF only: double word
72
73 #define BPF_MODE(code) ((code) & 0xe0)
74 ///< Mode modifier
75 #define BPF_MODE_IMM 0x00 ///< used for 32-bit mov in cBPF and 64-bit in eBPF
76 #define BPF_MODE_ABS 0x20
77 #define BPF_MODE_IND 0x40
78 #define BPF_MODE_MEM 0x60
79 #define BPF_MODE_LEN 0x80 ///< cBPF only, reserved in eBPF
80 #define BPF_MODE_MSH 0xa0 ///< cBPF only, reserved in eBPF
81 #define BPF_MODE_XADD 0xc0 ///< eBPF only: exclusive add
82
83 #define BPF_MISCOP(code) ((code) & 0x80)
84 ///< Operation of misc
85 #define BPF_MISCOP_TAX 0x00
86 #define BPF_MISCOP_TXA 0x80
87
88 #endif