1 //===-- BPFInstrFormats.td - BPF Instruction Formats -------*- tablegen -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 class BPFOpClass<bits<3> val> { 11 bits<3> Value = val; 12 } 13 14 def BPF_LD : BPFOpClass<0x0>; 15 def BPF_LDX : BPFOpClass<0x1>; 16 def BPF_ST : BPFOpClass<0x2>; 17 def BPF_STX : BPFOpClass<0x3>; 18 def BPF_ALU : BPFOpClass<0x4>; 19 def BPF_JMP : BPFOpClass<0x5>; 20 def BPF_ALU64 : BPFOpClass<0x7>; 21 22 class BPFSrcType<bits<1> val> { 23 bits<1> Value = val; 24 } 25 26 def BPF_K : BPFSrcType<0x0>; 27 def BPF_X : BPFSrcType<0x1>; 28 29 class BPFArithOp<bits<4> val> { 30 bits<4> Value = val; 31 } 32 33 def BPF_ADD : BPFArithOp<0x0>; 34 def BPF_SUB : BPFArithOp<0x1>; 35 def BPF_MUL : BPFArithOp<0x2>; 36 def BPF_DIV : BPFArithOp<0x3>; 37 def BPF_OR : BPFArithOp<0x4>; 38 def BPF_AND : BPFArithOp<0x5>; 39 def BPF_LSH : BPFArithOp<0x6>; 40 def BPF_RSH : BPFArithOp<0x7>; 41 def BPF_NEG : BPFArithOp<0x8>; 42 def BPF_XOR : BPFArithOp<0xa>; 43 def BPF_MOV : BPFArithOp<0xb>; 44 def BPF_ARSH : BPFArithOp<0xc>; 45 def BPF_END : BPFArithOp<0xd>; 46 47 class BPFEndDir<bits<1> val> { 48 bits<1> Value = val; 49 } 50 51 def BPF_TO_LE : BPFSrcType<0x0>; 52 def BPF_TO_BE : BPFSrcType<0x1>; 53 54 class BPFJumpOp<bits<4> val> { 55 bits<4> Value = val; 56 } 57 58 def BPF_JA : BPFJumpOp<0x0>; 59 def BPF_JEQ : BPFJumpOp<0x1>; 60 def BPF_JGT : BPFJumpOp<0x2>; 61 def BPF_JGE : BPFJumpOp<0x3>; 62 def BPF_JNE : BPFJumpOp<0x5>; 63 def BPF_JSGT : BPFJumpOp<0x6>; 64 def BPF_JSGE : BPFJumpOp<0x7>; 65 def BPF_CALL : BPFJumpOp<0x8>; 66 def BPF_EXIT : BPFJumpOp<0x9>; 67 def BPF_JLT : BPFJumpOp<0xa>; 68 def BPF_JLE : BPFJumpOp<0xb>; 69 def BPF_JSLT : BPFJumpOp<0xc>; 70 def BPF_JSLE : BPFJumpOp<0xd>; 71 72 class BPFWidthModifer<bits<2> val> { 73 bits<2> Value = val; 74 } 75 76 def BPF_W : BPFWidthModifer<0x0>; 77 def BPF_H : BPFWidthModifer<0x1>; 78 def BPF_B : BPFWidthModifer<0x2>; 79 def BPF_DW : BPFWidthModifer<0x3>; 80 81 class BPFModeModifer<bits<3> val> { 82 bits<3> Value = val; 83 } 84 85 def BPF_IMM : BPFModeModifer<0x0>; 86 def BPF_ABS : BPFModeModifer<0x1>; 87 def BPF_IND : BPFModeModifer<0x2>; 88 def BPF_MEM : BPFModeModifer<0x3>; 89 def BPF_XADD : BPFModeModifer<0x6>; 90 91 class InstBPF<dag outs, dag ins, string asmstr, list<dag> pattern> 92 : Instruction { 93 field bits<64> Inst; 94 field bits<64> SoftFail = 0; 95 let Size = 8; 96 97 let Namespace = "BPF"; 98 let DecoderNamespace = "BPF"; 99 100 BPFOpClass BPFClass; 101 let Inst{58-56} = BPFClass.Value; 102 103 dag OutOperandList = outs; 104 dag InOperandList = ins; 105 let AsmString = asmstr; 106 let Pattern = pattern; 107 } 108 109 // Pseudo instructions 110 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern> 111 : InstBPF<outs, ins, asmstr, pattern> { 112 let Inst{63-0} = 0; 113 let isPseudo = 1; 114 } 115