All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] TriCore instruction bugfixes
@ 2023-01-27 12:03 Bastian Koppelmann
  2023-01-27 12:03 ` [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation Bastian Koppelmann
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Bastian Koppelmann @ 2023-01-27 12:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbastian, anton.kochkov

Hi,

while resolving [1], I noticed a few more bugs in DEXTR and LD_BU_PREINC which
this patch series fixes. 

I also included the solo patch [1] into this series.

Cheers,
Bastian

[1] https://gitlab.com/qemu-project/qemu/-/issues/653
[2] https://lore.kernel.org/qemu-devel/20230113123759.677960-1-kbastian@mail.uni-paderborn.de/


Bastian Koppelmann (5):
  target/tricore: Fix OPC2_32_RCRW_IMASK translation
  target/tricore: Fix OPC2_32_RCRW_INSERT translation
  target/tricore: Fix RRPW_DEXTR
  target/tricore: Fix OPC2_32_RRRR_DEXTR
  target/tricore: Fix OPC2_32_BO_LD_BU_PREINC

 target/tricore/translate.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

-- 
2.39.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation
  2023-01-27 12:03 [PATCH 0/5] TriCore instruction bugfixes Bastian Koppelmann
@ 2023-01-27 12:03 ` Bastian Koppelmann
  2023-01-27 18:11   ` Richard Henderson
  2023-01-27 12:03 ` [PATCH 2/5] target/tricore: Fix OPC2_32_RCRW_INSERT translation Bastian Koppelmann
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Bastian Koppelmann @ 2023-01-27 12:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbastian, anton.kochkov

we were mixing up the "c" and "d" registers. We used "d" as a
destination register und "c" as the source. According to the TriCore ISA
manual 1.6 vol 2 it is the other way round.

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/653
---
 target/tricore/translate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index df9e46c649..8de4e56b1f 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -5794,11 +5794,11 @@ static void decode_rcrw_insert(DisasContext *ctx)
 
     switch (op2) {
     case OPC2_32_RCRW_IMASK:
-        tcg_gen_andi_tl(temp, cpu_gpr_d[r4], 0x1f);
+        tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
         tcg_gen_movi_tl(temp2, (1 << width) - 1);
-        tcg_gen_shl_tl(cpu_gpr_d[r3 + 1], temp2, temp);
+        tcg_gen_shl_tl(cpu_gpr_d[r4 + 1], temp2, temp);
         tcg_gen_movi_tl(temp2, const4);
-        tcg_gen_shl_tl(cpu_gpr_d[r3], temp2, temp);
+        tcg_gen_shl_tl(cpu_gpr_d[r4], temp2, temp);
         break;
     case OPC2_32_RCRW_INSERT:
         temp3 = tcg_temp_new();
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5] target/tricore: Fix OPC2_32_RCRW_INSERT translation
  2023-01-27 12:03 [PATCH 0/5] TriCore instruction bugfixes Bastian Koppelmann
  2023-01-27 12:03 ` [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation Bastian Koppelmann
@ 2023-01-27 12:03 ` Bastian Koppelmann
  2023-01-27 18:13   ` Richard Henderson
  2023-01-27 12:03 ` [PATCH 3/5] target/tricore: Fix RRPW_DEXTR Bastian Koppelmann
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Bastian Koppelmann @ 2023-01-27 12:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbastian, anton.kochkov

we were mixing up the "c" and "d" registers. We used "d" as a
destination register und "c" as the source. According to the TriCore ISA
manual 1.6 vol 2 it is the other way round.

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/653
---
 target/tricore/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index 8de4e56b1f..6149d4f5c0 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -5805,8 +5805,8 @@ static void decode_rcrw_insert(DisasContext *ctx)
 
         tcg_gen_movi_tl(temp, width);
         tcg_gen_movi_tl(temp2, const4);
-        tcg_gen_andi_tl(temp3, cpu_gpr_d[r4], 0x1f);
-        gen_insert(cpu_gpr_d[r3], cpu_gpr_d[r1], temp2, temp, temp3);
+        tcg_gen_andi_tl(temp3, cpu_gpr_d[r3], 0x1f);
+        gen_insert(cpu_gpr_d[r4], cpu_gpr_d[r1], temp2, temp, temp3);
 
         tcg_temp_free(temp3);
         break;
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] target/tricore: Fix RRPW_DEXTR
  2023-01-27 12:03 [PATCH 0/5] TriCore instruction bugfixes Bastian Koppelmann
  2023-01-27 12:03 ` [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation Bastian Koppelmann
  2023-01-27 12:03 ` [PATCH 2/5] target/tricore: Fix OPC2_32_RCRW_INSERT translation Bastian Koppelmann
@ 2023-01-27 12:03 ` Bastian Koppelmann
  2023-01-27 18:21   ` Richard Henderson
  2023-01-27 12:03 ` [PATCH 4/5] target/tricore: Fix OPC2_32_RRRR_DEXTR Bastian Koppelmann
  2023-01-27 12:03 ` [PATCH 5/5] target/tricore: Fix OPC2_32_BO_LD_BU_PREINC Bastian Koppelmann
  4 siblings, 1 reply; 11+ messages in thread
From: Bastian Koppelmann @ 2023-01-27 12:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbastian, anton.kochkov

if we used const16 == 0 we would crash qemu with the error:

../tcg/tcg-op.c:196: tcg_gen_shri_i32: Assertion `arg2 >= 0 && arg2 < 32' failed

This is a special case anyways as we can directly return cpu_gpr_d[r1]
as this is the most significant word an nothing is shifted.

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 target/tricore/translate.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index 6149d4f5c0..62128c6aae 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -8708,6 +8708,8 @@ static void decode_32Bit_opc(DisasContext *ctx)
         const16 = MASK_OP_RRPW_POS(ctx->opcode);
         if (r1 == r2) {
             tcg_gen_rotli_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], const16);
+        } else if (const16 == 0) {
+            tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
         } else {
             temp = tcg_temp_new();
             tcg_gen_shli_tl(temp, cpu_gpr_d[r1], const16);
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] target/tricore: Fix OPC2_32_RRRR_DEXTR
  2023-01-27 12:03 [PATCH 0/5] TriCore instruction bugfixes Bastian Koppelmann
                   ` (2 preceding siblings ...)
  2023-01-27 12:03 ` [PATCH 3/5] target/tricore: Fix RRPW_DEXTR Bastian Koppelmann
@ 2023-01-27 12:03 ` Bastian Koppelmann
  2023-01-27 18:25   ` Richard Henderson
  2023-01-27 12:03 ` [PATCH 5/5] target/tricore: Fix OPC2_32_BO_LD_BU_PREINC Bastian Koppelmann
  4 siblings, 1 reply; 11+ messages in thread
From: Bastian Koppelmann @ 2023-01-27 12:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbastian, anton.kochkov

if cpu_gpr_d[r3] == 0 then we were shifting the lower register to the
right by 32 which is undefined behaviour. In this case the TriCore would
do nothing an just return the higher register cpu_reg_d[r1]. We fixed
that by detecting whether cpu_gpr_d[r3] was zero and cleared the lower
register.

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 target/tricore/translate.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index 62128c6aae..b8e0969079 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -8245,10 +8245,19 @@ static void decode_rrrr_extract_insert(DisasContext *ctx)
         if (r1 == r2) {
             tcg_gen_rotl_tl(cpu_gpr_d[r4], cpu_gpr_d[r1], tmp_pos);
         } else {
+            TCGv msw = tcg_temp_new();
+            TCGv zero = tcg_const_tl(0);
             tcg_gen_shl_tl(tmp_width, cpu_gpr_d[r1], tmp_pos);
-            tcg_gen_subfi_tl(tmp_pos, 32, tmp_pos);
-            tcg_gen_shr_tl(tmp_pos, cpu_gpr_d[r2], tmp_pos);
-            tcg_gen_or_tl(cpu_gpr_d[r4], tmp_width, tmp_pos);
+            tcg_gen_subfi_tl(msw, 32, tmp_pos);
+            tcg_gen_shr_tl(msw, cpu_gpr_d[r2], msw);
+            /* if pos == 0, then we do cpu_gpr_d[r2] << 32, which is undefined
+             * behaviour. So check that case here and set the low bits to zero
+             * which effectivly returns cpu_gpr_d[r1]
+             */
+            tcg_gen_movcond_tl(TCG_COND_EQ, msw, tmp_pos, zero, zero, msw);
+            tcg_gen_or_tl(cpu_gpr_d[r4], tmp_width, msw);
+            tcg_temp_free(zero);
+            tcg_temp_free(msw);
         }
         break;
     case OPC2_32_RRRR_EXTR:
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] target/tricore: Fix OPC2_32_BO_LD_BU_PREINC
  2023-01-27 12:03 [PATCH 0/5] TriCore instruction bugfixes Bastian Koppelmann
                   ` (3 preceding siblings ...)
  2023-01-27 12:03 ` [PATCH 4/5] target/tricore: Fix OPC2_32_RRRR_DEXTR Bastian Koppelmann
@ 2023-01-27 12:03 ` Bastian Koppelmann
  2023-01-27 18:25   ` Richard Henderson
  4 siblings, 1 reply; 11+ messages in thread
From: Bastian Koppelmann @ 2023-01-27 12:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbastian, anton.kochkov

we were sign extending the result of the load, while the instruction
clearly states that the result should be unsigned.

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 target/tricore/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index b8e0969079..c17d19b83e 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -4964,7 +4964,7 @@ static void decode_bo_addrmode_ld_post_pre_base(DisasContext *ctx)
         tcg_gen_addi_tl(cpu_gpr_a[r2], cpu_gpr_a[r2], off10);
         break;
     case OPC2_32_BO_LD_BU_PREINC:
-        gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_SB);
+        gen_ld_preincr(ctx, cpu_gpr_d[r1], cpu_gpr_a[r2], off10, MO_UB);
         break;
     case OPC2_32_BO_LD_D_SHORTOFF:
         CHECK_REG_PAIR(r1);
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation
  2023-01-27 12:03 ` [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation Bastian Koppelmann
@ 2023-01-27 18:11   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2023-01-27 18:11 UTC (permalink / raw)
  To: Bastian Koppelmann, qemu-devel; +Cc: anton.kochkov

On 1/27/23 02:03, Bastian Koppelmann wrote:
> we were mixing up the "c" and "d" registers. We used "d" as a
> destination register und "c" as the source. According to the TriCore ISA
> manual 1.6 vol 2 it is the other way round.
> 
> Signed-off-by: Bastian Koppelmann<kbastian@mail.uni-paderborn.de>
> Resolves:https://gitlab.com/qemu-project/qemu/-/issues/653
> ---
>   target/tricore/translate.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] target/tricore: Fix OPC2_32_RCRW_INSERT translation
  2023-01-27 12:03 ` [PATCH 2/5] target/tricore: Fix OPC2_32_RCRW_INSERT translation Bastian Koppelmann
@ 2023-01-27 18:13   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2023-01-27 18:13 UTC (permalink / raw)
  To: Bastian Koppelmann, qemu-devel; +Cc: anton.kochkov

On 1/27/23 02:03, Bastian Koppelmann wrote:
> we were mixing up the "c" and "d" registers. We used "d" as a
> destination register und "c" as the source. According to the TriCore ISA
> manual 1.6 vol 2 it is the other way round.
> 
> Signed-off-by: Bastian Koppelmann<kbastian@mail.uni-paderborn.de>
> Resolves:https://gitlab.com/qemu-project/qemu/-/issues/653
> ---
>   target/tricore/translate.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/5] target/tricore: Fix RRPW_DEXTR
  2023-01-27 12:03 ` [PATCH 3/5] target/tricore: Fix RRPW_DEXTR Bastian Koppelmann
@ 2023-01-27 18:21   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2023-01-27 18:21 UTC (permalink / raw)
  To: Bastian Koppelmann, qemu-devel; +Cc: anton.kochkov

On 1/27/23 02:03, Bastian Koppelmann wrote:
> if we used const16 == 0 we would crash qemu with the error:
> 
> ../tcg/tcg-op.c:196: tcg_gen_shri_i32: Assertion `arg2 >= 0 && arg2 < 32' failed
> 
> This is a special case anyways as we can directly return cpu_gpr_d[r1]
> as this is the most significant word an nothing is shifted.
> 
> Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
> ---
>   target/tricore/translate.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/target/tricore/translate.c b/target/tricore/translate.c
> index 6149d4f5c0..62128c6aae 100644
> --- a/target/tricore/translate.c
> +++ b/target/tricore/translate.c
> @@ -8708,6 +8708,8 @@ static void decode_32Bit_opc(DisasContext *ctx)
>           const16 = MASK_OP_RRPW_POS(ctx->opcode);
>           if (r1 == r2) {
>               tcg_gen_rotli_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], const16);
> +        } else if (const16 == 0) {
> +            tcg_gen_mov_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
>           } else {
>               temp = tcg_temp_new();
>               tcg_gen_shli_tl(temp, cpu_gpr_d[r1], const16);

While correct, this entire operation is

    tcg_gen_extract2_tl(cpu_gpr_d[r3], cpu_gpr_d[r2], cpu_gpr_d[r1], 32 - const16);

which will take care of your two special cases as well.


r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] target/tricore: Fix OPC2_32_RRRR_DEXTR
  2023-01-27 12:03 ` [PATCH 4/5] target/tricore: Fix OPC2_32_RRRR_DEXTR Bastian Koppelmann
@ 2023-01-27 18:25   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2023-01-27 18:25 UTC (permalink / raw)
  To: Bastian Koppelmann, qemu-devel; +Cc: anton.kochkov

On 1/27/23 02:03, Bastian Koppelmann wrote:
> if cpu_gpr_d[r3] == 0 then we were shifting the lower register to the
> right by 32 which is undefined behaviour. In this case the TriCore would
> do nothing an just return the higher register cpu_reg_d[r1]. We fixed
> that by detecting whether cpu_gpr_d[r3] was zero and cleared the lower
> register.
> 
> Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
> ---
>   target/tricore/translate.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/target/tricore/translate.c b/target/tricore/translate.c
> index 62128c6aae..b8e0969079 100644
> --- a/target/tricore/translate.c
> +++ b/target/tricore/translate.c
> @@ -8245,10 +8245,19 @@ static void decode_rrrr_extract_insert(DisasContext *ctx)
>           if (r1 == r2) {
>               tcg_gen_rotl_tl(cpu_gpr_d[r4], cpu_gpr_d[r1], tmp_pos);
>           } else {
> +            TCGv msw = tcg_temp_new();
> +            TCGv zero = tcg_const_tl(0);

tcg_constant_tl(0), which you then don't need to free at the end.

>               tcg_gen_shl_tl(tmp_width, cpu_gpr_d[r1], tmp_pos);
> +            tcg_gen_subfi_tl(msw, 32, tmp_pos);
> +            tcg_gen_shr_tl(msw, cpu_gpr_d[r2], msw);
> +            /* if pos == 0, then we do cpu_gpr_d[r2] << 32, which is undefined

   /*
    * If ...
    */

> +             * behaviour. So check that case here and set the low bits to zero
> +             * which effectivly returns cpu_gpr_d[r1]
> +             */
> +            tcg_gen_movcond_tl(TCG_COND_EQ, msw, tmp_pos, zero, zero, msw);
> +            tcg_gen_or_tl(cpu_gpr_d[r4], tmp_width, msw);
> +            tcg_temp_free(zero);
> +            tcg_temp_free(msw);

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/5] target/tricore: Fix OPC2_32_BO_LD_BU_PREINC
  2023-01-27 12:03 ` [PATCH 5/5] target/tricore: Fix OPC2_32_BO_LD_BU_PREINC Bastian Koppelmann
@ 2023-01-27 18:25   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2023-01-27 18:25 UTC (permalink / raw)
  To: Bastian Koppelmann, qemu-devel; +Cc: anton.kochkov

On 1/27/23 02:03, Bastian Koppelmann wrote:
> we were sign extending the result of the load, while the instruction
> clearly states that the result should be unsigned.
> 
> Signed-off-by: Bastian Koppelmann<kbastian@mail.uni-paderborn.de>
> ---
>   target/tricore/translate.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-01-27 18:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 12:03 [PATCH 0/5] TriCore instruction bugfixes Bastian Koppelmann
2023-01-27 12:03 ` [PATCH 1/5] target/tricore: Fix OPC2_32_RCRW_IMASK translation Bastian Koppelmann
2023-01-27 18:11   ` Richard Henderson
2023-01-27 12:03 ` [PATCH 2/5] target/tricore: Fix OPC2_32_RCRW_INSERT translation Bastian Koppelmann
2023-01-27 18:13   ` Richard Henderson
2023-01-27 12:03 ` [PATCH 3/5] target/tricore: Fix RRPW_DEXTR Bastian Koppelmann
2023-01-27 18:21   ` Richard Henderson
2023-01-27 12:03 ` [PATCH 4/5] target/tricore: Fix OPC2_32_RRRR_DEXTR Bastian Koppelmann
2023-01-27 18:25   ` Richard Henderson
2023-01-27 12:03 ` [PATCH 5/5] target/tricore: Fix OPC2_32_BO_LD_BU_PREINC Bastian Koppelmann
2023-01-27 18:25   ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.