github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/ebpf/rsh.go (about) 1 package ebpf 2 3 import "fmt" 4 5 var _ Instruction = (*Rsh32)(nil) 6 7 type Rsh32 struct { 8 Dest Register 9 Value int32 10 } 11 12 func (a *Rsh32) Raw() ([]RawInstruction, error) { 13 return []RawInstruction{ 14 {Op: BPF_ALU | BPF_K | BPF_RSH, Reg: NewReg(0, a.Dest), Imm: a.Value}, 15 }, nil 16 } 17 18 func (a *Rsh32) String() string { 19 return fmt.Sprintf("w%s >>= %d", a.Dest, a.Value) 20 } 21 22 var _ Instruction = (*Rsh64)(nil) 23 24 type Rsh64 struct { 25 Dest Register 26 Value int32 27 } 28 29 func (a *Rsh64) Raw() ([]RawInstruction, error) { 30 return []RawInstruction{ 31 {Op: BPF_ALU64 | BPF_K | BPF_RSH, Reg: NewReg(0, a.Dest), Imm: a.Value}, 32 }, nil 33 } 34 35 func (a *Rsh64) String() string { 36 return fmt.Sprintf("r%s >>= %d", a.Dest, a.Value) 37 } 38 39 var _ Instruction = (*Rsh32Register)(nil) 40 41 type Rsh32Register struct { 42 Dest Register 43 Src Register 44 } 45 46 func (a *Rsh32Register) Raw() ([]RawInstruction, error) { 47 return []RawInstruction{ 48 {Op: BPF_ALU | BPF_X | BPF_RSH, Reg: NewReg(a.Src, a.Dest)}, 49 }, nil 50 } 51 52 func (a *Rsh32Register) String() string { 53 return fmt.Sprintf("w%s >>= w%d", a.Dest, a.Src) 54 } 55 56 var _ Instruction = (*Rsh64Register)(nil) 57 58 type Rsh64Register struct { 59 Dest Register 60 Src Register 61 } 62 63 func (a *Rsh64Register) Raw() ([]RawInstruction, error) { 64 return []RawInstruction{ 65 {Op: BPF_ALU64 | BPF_X | BPF_RSH, Reg: NewReg(a.Src, a.Dest)}, 66 }, nil 67 } 68 69 func (a *Rsh64Register) String() string { 70 return fmt.Sprintf("r%s >>= r%s", a.Dest, a.Src) 71 }