github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/emulator/inst_jge.go (about) 1 package emulator 2 3 import ( 4 "github.com/dylandreimerink/gobpfld/ebpf" 5 ) 6 7 var _ Instruction = (*JumpGreaterThanEqual32)(nil) 8 9 type JumpGreaterThanEqual32 struct { 10 ebpf.JumpGreaterThanEqual32 11 } 12 13 func (i *JumpGreaterThanEqual32) Clone() Instruction { 14 c := *i 15 return &c 16 } 17 18 func (i *JumpGreaterThanEqual32) Execute(vm *VM) error { 19 dv, dr, err := readReg(vm, i.Dest) 20 if err != nil { 21 return err 22 } 23 24 if isIMM(dr) && uint32(dv) >= uint32(i.Value) { 25 vm.Registers.PC += int(i.Offset) 26 } 27 28 return nil 29 } 30 31 var _ Instruction = (*JumpGreaterThanEqual)(nil) 32 33 type JumpGreaterThanEqual struct { 34 ebpf.JumpGreaterThanEqual 35 } 36 37 func (i *JumpGreaterThanEqual) Clone() Instruction { 38 c := *i 39 return &c 40 } 41 42 func (i *JumpGreaterThanEqual) Execute(vm *VM) error { 43 dv, dr, err := readReg(vm, i.Dest) 44 if err != nil { 45 return err 46 } 47 48 if isIMM(dr) && uint64(dv) >= uint64(i.Value) { 49 vm.Registers.PC += int(i.Offset) 50 } 51 52 return nil 53 } 54 55 var _ Instruction = (*JumpGreaterThanEqualRegister32)(nil) 56 57 type JumpGreaterThanEqualRegister32 struct { 58 ebpf.JumpGreaterThanEqualRegister32 59 } 60 61 func (i *JumpGreaterThanEqualRegister32) Clone() Instruction { 62 c := *i 63 return &c 64 } 65 66 func (i *JumpGreaterThanEqualRegister32) Execute(vm *VM) error { 67 dv, dr, err := readReg(vm, i.Dest) 68 if err != nil { 69 return err 70 } 71 72 sv, sr, err := readReg(vm, i.Src) 73 if err != nil { 74 return err 75 } 76 77 if sameRVType(dr, sr) && uint32(dv) >= uint32(sv) { 78 vm.Registers.PC += int(i.Offset) 79 } 80 81 return nil 82 } 83 84 var _ Instruction = (*JumpGreaterThanEqualRegister)(nil) 85 86 type JumpGreaterThanEqualRegister struct { 87 ebpf.JumpGreaterThanEqualRegister 88 } 89 90 func (i *JumpGreaterThanEqualRegister) Clone() Instruction { 91 c := *i 92 return &c 93 } 94 95 func (i *JumpGreaterThanEqualRegister) Execute(vm *VM) error { 96 dv, dr, err := readReg(vm, i.Dest) 97 if err != nil { 98 return err 99 } 100 101 sv, sr, err := readReg(vm, i.Src) 102 if err != nil { 103 return err 104 } 105 106 if sameRVType(dr, sr) && uint64(dv) >= uint64(sv) { 107 vm.Registers.PC += int(i.Offset) 108 } 109 110 return nil 111 }