github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/emulator/inst_jsge.go (about)

     1  package emulator
     2  
     3  import (
     4  	"github.com/dylandreimerink/gobpfld/ebpf"
     5  )
     6  
     7  var _ Instruction = (*JumpSignedGreaterThanOrEqual32)(nil)
     8  
     9  type JumpSignedGreaterThanOrEqual32 struct {
    10  	ebpf.JumpSignedGreaterThanOrEqual32
    11  }
    12  
    13  func (i *JumpSignedGreaterThanOrEqual32) Clone() Instruction {
    14  	c := *i
    15  	return &c
    16  }
    17  
    18  func (i *JumpSignedGreaterThanOrEqual32) 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) && int32(dv) >= i.Value {
    25  		vm.Registers.PC += int(i.Offset)
    26  	}
    27  
    28  	return nil
    29  }
    30  
    31  var _ Instruction = (*JumpSignedGreaterThanOrEqual)(nil)
    32  
    33  type JumpSignedGreaterThanOrEqual struct {
    34  	ebpf.JumpSignedGreaterThanOrEqual
    35  }
    36  
    37  func (i *JumpSignedGreaterThanOrEqual) Clone() Instruction {
    38  	c := *i
    39  	return &c
    40  }
    41  
    42  func (i *JumpSignedGreaterThanOrEqual) 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) && dv >= int64(i.Value) {
    49  		vm.Registers.PC += int(i.Offset)
    50  	}
    51  
    52  	return nil
    53  }
    54  
    55  var _ Instruction = (*JumpSignedGreaterThanOrEqualRegister32)(nil)
    56  
    57  type JumpSignedGreaterThanOrEqualRegister32 struct {
    58  	ebpf.JumpSignedGreaterThanOrEqualRegister32
    59  }
    60  
    61  func (i *JumpSignedGreaterThanOrEqualRegister32) Clone() Instruction {
    62  	c := *i
    63  	return &c
    64  }
    65  
    66  func (i *JumpSignedGreaterThanOrEqualRegister32) 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) && int32(dv) >= int32(sv) {
    78  		vm.Registers.PC += int(i.Offset)
    79  	}
    80  
    81  	return nil
    82  }
    83  
    84  var _ Instruction = (*JumpSignedGreaterThanOrEqualRegister)(nil)
    85  
    86  type JumpSignedGreaterThanOrEqualRegister struct {
    87  	ebpf.JumpSignedGreaterThanOrEqualRegister
    88  }
    89  
    90  func (i *JumpSignedGreaterThanOrEqualRegister) Clone() Instruction {
    91  	c := *i
    92  	return &c
    93  }
    94  
    95  func (i *JumpSignedGreaterThanOrEqualRegister) 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) && dv >= sv {
   107  		vm.Registers.PC += int(i.Offset)
   108  	}
   109  
   110  	return nil
   111  }