Lines Matching refs:ins

27 func (ins Instruction) Sym(name string) Instruction {
28 ins.Symbol = name
29 return ins
33 func (ins *Instruction) Unmarshal(r io.Reader, bo binary.ByteOrder) (uint64, error) {
40 ins.OpCode = bi.OpCode
41 ins.Offset = bi.Offset
42 ins.Constant = int64(bi.Constant)
43 ins.Dst, ins.Src, err = bi.Registers.Unmarshal(bo)
60 ins.Constant = int64(uint64(uint32(bi2.Constant))<<32 | uint64(uint32(bi.Constant)))
66 func (ins Instruction) Marshal(w io.Writer, bo binary.ByteOrder) (uint64, error) {
67 if ins.OpCode == InvalidOpCode {
71 isDWordLoad := ins.OpCode.isDWordLoad()
73 cons := int32(ins.Constant)
76 cons = int32(uint32(ins.Constant))
79 regs, err := newBPFRegisters(ins.Dst, ins.Src, bo)
85 ins.OpCode,
87 ins.Offset,
100 Constant: int32(ins.Constant >> 32),
113 func (ins *Instruction) RewriteMapPtr(fd int) error {
114 if !ins.OpCode.isDWordLoad() {
115 return fmt.Errorf("%s is not a 64 bit load", ins.OpCode)
118 if ins.Src != PseudoMapFD && ins.Src != PseudoMapValue {
123 offset := uint64(ins.Constant) & (math.MaxUint32 << 32)
125 ins.Constant = int64(offset | rawFd)
129 func (ins *Instruction) mapPtr() uint32 {
130 return uint32(uint64(ins.Constant) & math.MaxUint32)
136 func (ins *Instruction) RewriteMapOffset(offset uint32) error {
137 if !ins.OpCode.isDWordLoad() {
138 return fmt.Errorf("%s is not a 64 bit load", ins.OpCode)
141 if ins.Src != PseudoMapValue {
145 fd := uint64(ins.Constant) & math.MaxUint32
146 ins.Constant = int64(uint64(offset)<<32 | fd)
150 func (ins *Instruction) mapOffset() uint32 {
151 return uint32(uint64(ins.Constant) >> 32)
154 func (ins *Instruction) isLoadFromMap() bool {
155 return ins.OpCode == LoadImmOp(DWord) && (ins.Src == PseudoMapFD || ins.Src == PseudoMapValue)
159 func (ins Instruction) Format(f fmt.State, c rune) {
165 op := ins.OpCode
178 if ins.isLoadFromMap() {
179 fd := int32(ins.mapPtr())
180 switch ins.Src {
182 fmt.Fprintf(f, "LoadMapPtr dst: %s fd: %d", ins.Dst, fd)
185 fmt.Fprintf(f, "LoadMapValue dst: %s, fd: %d off: %d", ins.Dst, fd, ins.mapOffset())
196 fmt.Fprintf(f, "dst: %s imm: %d", ins.Dst, ins.Constant)
198 fmt.Fprintf(f, "imm: %d", ins.Constant)
200 fmt.Fprintf(f, "dst: %s src: %s imm: %d", ins.Dst, ins.Src, ins.Constant)
202 fmt.Fprintf(f, "dst: %s src: %s off: %d imm: %d", ins.Dst, ins.Src, ins.Offset, ins.Constant)
204 fmt.Fprintf(f, "dst: %s src: %s", ins.Dst, ins.Src)
208 fmt.Fprintf(f, "dst: %s ", ins.Dst)
210 fmt.Fprintf(f, "imm: %d", ins.Constant)
212 fmt.Fprintf(f, "src: %s", ins.Src)
218 if ins.Src == PseudoCall {
220 fmt.Fprint(f, ins.Constant)
222 fmt.Fprint(f, BuiltinFunc(ins.Constant))
226 fmt.Fprintf(f, "dst: %s off: %d ", ins.Dst, ins.Offset)
228 fmt.Fprintf(f, "imm: %d", ins.Constant)
230 fmt.Fprintf(f, "src: %s", ins.Src)
236 if ins.Reference != "" {
237 fmt.Fprintf(f, " <%s>", ins.Reference)
258 ins := &insns[i]
259 if ins.Reference != symbol {
263 if err := ins.RewriteMapPtr(fd); err != nil {
282 for i, ins := range insns {
283 if ins.Symbol == "" {
287 if _, ok := offsets[ins.Symbol]; ok {
288 return nil, fmt.Errorf("duplicate symbol %s", ins.Symbol)
291 offsets[ins.Symbol] = i
302 for i, ins := range insns {
303 if ins.Reference == "" {
307 offsets[ins.Reference] = append(offsets[ins.Reference], i)
317 for _, ins := range insns {
319 marshalledPos += ins.OpCode.marshalledInstructions()
321 if ins.Symbol == "" {
325 if _, ok := symbols[ins.Symbol]; ok {
326 return nil, fmt.Errorf("duplicate symbol %s", ins.Symbol)
329 symbols[ins.Symbol] = currentPos
376 for _, ins := range insns {
377 highestOffset += ins.OpCode.marshalledInstructions()
382 for _, ins := range insns {
383 if ins.Symbol != "" {
384 fmt.Fprintf(f, "%s%s:\n", symIndent, ins.Symbol)
386 fmt.Fprintf(f, "%s%*d: %v\n", indent, offsetWidth, offset, ins)
387 offset += ins.OpCode.marshalledInstructions()
401 for i, ins := range insns {
403 case ins.OpCode.JumpOp() == Call && ins.Src == PseudoCall && ins.Constant == -1:
405 offset, ok := absoluteOffsets[ins.Reference]
407 return fmt.Errorf("instruction %d: reference to missing symbol %s", i, ins.Reference)
410 ins.Constant = int64(offset - num - 1)
412 case ins.OpCode.Class() == JumpClass && ins.Offset == -1:
414 offset, ok := absoluteOffsets[ins.Reference]
416 return fmt.Errorf("instruction %d: reference to missing symbol %s", i, ins.Reference)
419 ins.Offset = int16(offset - num - 1)
422 n, err := ins.Marshal(w, bo)