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