public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: gdb-patches@sourceware.org
Subject: [COMMITTED] bpf: fix neg and neg32 BPF instructions in simulator
Date: Wed, 26 Jul 2023 11:46:31 +0200	[thread overview]
Message-ID: <20230726094631.32356-1-jose.marchesi@oracle.com> (raw)

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.
---
 sim/bpf/bpf-sim.c         | 4 ++--
 sim/testsuite/bpf/alu.s   | 4 ++--
 sim/testsuite/bpf/alu32.s | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sim/bpf/bpf-sim.c b/sim/bpf/bpf-sim.c
index 8d3a28e1940..5e01ddeca9f 100644
--- a/sim/bpf/bpf-sim.c
+++ b/sim/bpf/bpf-sim.c
@@ -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");
diff --git a/sim/testsuite/bpf/alu.s b/sim/testsuite/bpf/alu.s
index c073f67f819..4dc37b1f01a 100644
--- a/sim/testsuite/bpf/alu.s
+++ b/sim/testsuite/bpf/alu.s
@@ -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
diff --git a/sim/testsuite/bpf/alu32.s b/sim/testsuite/bpf/alu32.s
index d797122daf1..e8d5062476c 100644
--- a/sim/testsuite/bpf/alu32.s
+++ b/sim/testsuite/bpf/alu32.s
@@ -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
-- 
2.30.2


                 reply	other threads:[~2023-07-26  9:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230726094631.32356-1-jose.marchesi@oracle.com \
    --to=jose.marchesi@oracle.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).