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