bpf: fix neg and neg32 BPF instructions in simulator
This patch fixes the semantics of the neg and neg32 BPF instructions in the simulator, and also updates the corresponding tests accordingly. Tested in target bpf-unknown-none.
This commit is contained in:
parent
04896832b2
commit
4200337219
3 changed files with 7 additions and 7 deletions
|
@ -728,7 +728,7 @@ execute (SIM_CPU *cpu, struct bpf_insn *insn)
|
|||
break;
|
||||
case BPF_INSN_NEGR:
|
||||
BPF_TRACE ("BPF_INSN_NEGR\n");
|
||||
bpf_regs[insn->dst] = - (int64_t) bpf_regs[insn->src];
|
||||
bpf_regs[insn->dst] = - (int64_t) bpf_regs[insn->dst];
|
||||
break;
|
||||
case BPF_INSN_NEGI:
|
||||
BPF_TRACE ("BPF_INSN_NEGI\n");
|
||||
|
@ -865,7 +865,7 @@ execute (SIM_CPU *cpu, struct bpf_insn *insn)
|
|||
break;
|
||||
case BPF_INSN_NEG32R:
|
||||
BPF_TRACE ("BPF_INSN_NEG32R\n");
|
||||
bpf_regs[insn->dst] = (uint32_t) (- (int32_t) bpf_regs[insn->src]);
|
||||
bpf_regs[insn->dst] = (uint32_t) (- (int32_t) bpf_regs[insn->dst]);
|
||||
break;
|
||||
case BPF_INSN_NEG32I:
|
||||
BPF_TRACE ("BPF_INSN_NEG32I\n");
|
||||
|
|
|
@ -112,10 +112,10 @@ main:
|
|||
fail_ne %r1, 0
|
||||
|
||||
;; neg
|
||||
neg %r2, %r2
|
||||
neg %r2
|
||||
fail_ne %r2, -5
|
||||
mov %r1, -1025
|
||||
neg %r1, %r1
|
||||
neg %r1
|
||||
fail_ne %r1, 1025
|
||||
|
||||
pass
|
||||
|
|
|
@ -100,11 +100,11 @@ main:
|
|||
;; neg
|
||||
mov32 %r1, -1
|
||||
mov32 %r2, 0x7fffffff
|
||||
neg32 %r1, %r1
|
||||
neg32 %r2, %r2
|
||||
neg32 %r1
|
||||
neg32 %r2
|
||||
fail_ne32 %r1, 1
|
||||
fail_ne %r2, 0x80000001 ; Note: check for (bad) sign-extend
|
||||
neg32 %r2, %r2
|
||||
neg32 %r2
|
||||
fail_ne32 %r2, 0x7fffffff
|
||||
|
||||
pass
|
||||
|
|
Loading…
Add table
Reference in a new issue