-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsh.go
71 lines (54 loc) · 1.38 KB
/
rsh.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 = (*Rsh32)(nil)
type Rsh32 struct {
Dest Register
Value int32
}
func (a *Rsh32) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU | BPF_K | BPF_RSH, Reg: NewReg(0, a.Dest), Imm: a.Value},
}, nil
}
func (a *Rsh32) String() string {
return fmt.Sprintf("w%s >>= %d", a.Dest, a.Value)
}
var _ Instruction = (*Rsh64)(nil)
type Rsh64 struct {
Dest Register
Value int32
}
func (a *Rsh64) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU64 | BPF_K | BPF_RSH, Reg: NewReg(0, a.Dest), Imm: a.Value},
}, nil
}
func (a *Rsh64) String() string {
return fmt.Sprintf("r%s >>= %d", a.Dest, a.Value)
}
var _ Instruction = (*Rsh32Register)(nil)
type Rsh32Register struct {
Dest Register
Src Register
}
func (a *Rsh32Register) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU | BPF_X | BPF_RSH, Reg: NewReg(a.Src, a.Dest)},
}, nil
}
func (a *Rsh32Register) String() string {
return fmt.Sprintf("w%s >>= w%d", a.Dest, a.Src)
}
var _ Instruction = (*Rsh64Register)(nil)
type Rsh64Register struct {
Dest Register
Src Register
}
func (a *Rsh64Register) Raw() ([]RawInstruction, error) {
return []RawInstruction{
{Op: BPF_ALU64 | BPF_X | BPF_RSH, Reg: NewReg(a.Src, a.Dest)},
}, nil
}
func (a *Rsh64Register) String() string {
return fmt.Sprintf("r%s >>= r%s", a.Dest, a.Src)
}