-
Notifications
You must be signed in to change notification settings - Fork 2
/
mod.go
71 lines (54 loc) · 1.38 KB
/
mod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ebpf
import "fmt"
var _ Instruction = (*Mod32)(nil)
type Mod32 struct {
Dest Register
Value int32
}
func (a *Mod32) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU | BPF_K | BPF_MOD, Reg: NewReg(0, a.Dest), Imm: a.Value},
}, nil
}
func (a *Mod32) String() string {
return fmt.Sprintf("w%s %%= %d", a.Dest, a.Value)
}
var _ Instruction = (*Mod64)(nil)
type Mod64 struct {
Dest Register
Value int32
}
func (a *Mod64) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU64 | BPF_K | BPF_MOD, Reg: NewReg(0, a.Dest), Imm: a.Value},
}, nil
}
func (a *Mod64) String() string {
return fmt.Sprintf("r%s %%= %d", a.Dest, a.Value)
}
var _ Instruction = (*Mod32Register)(nil)
type Mod32Register struct {
Dest Register
Src Register
}
func (a *Mod32Register) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU | BPF_X | BPF_MOD, Reg: NewReg(a.Src, a.Dest)},
}, nil
}
func (a *Mod32Register) String() string {
return fmt.Sprintf("w%s %%= w%d", a.Dest, a.Src)
}
var _ Instruction = (*Mod64Register)(nil)
type Mod64Register struct {
Dest Register
Src Register
}
func (a *Mod64Register) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU64 | BPF_X | BPF_MOD, Reg: NewReg(a.Src, a.Dest)},
}, nil
}
func (a *Mod64Register) String() string {
return fmt.Sprintf("r%s %%= r%s", a.Dest, a.Src)
}