Skip to contentSkip to conversation

Fix swap.b

Qemu-devel Applied Vladimir Prus 2 participants 2 messages Oct 12, 2008

lore
Share & tools
lore
#0 lore raw

The SH4 manual documents the swap.b instruction as follows:

SWAP.B Rm,Rn
Rm → swap lower 2 bytes → Rn

Current QEMU code, in addition to the above, also clears the high 16 bits. The immediate breakage I saw is that htonl function applied to netmask of 255.255.255.0 gives 0, which breaks all networking. Attached patch fixes the problem.

- Volodya

---
 target-sh4/translate.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
target-sh4/translate.c +4 -1
index 365936f..2ef8c00 100644
@@ -686,7 +686,9 @@ void _decode_opc(DisasContext * ctx)
 	return;
     case 0x6008:		/* swap.b Rm,Rn */
 	{
-	    TCGv high, low;
+	    TCGv highw, high, low;
+	    highw = tcg_temp_new(TCG_TYPE_I32);
+	    tcg_gen_andi_i32(highw, REG(B7_4), 0xffff0000);
 	    high = tcg_temp_new(TCG_TYPE_I32);
 	    tcg_gen_ext8u_i32(high, REG(B7_4));
 	    tcg_gen_shli_i32(high, high, 8);
@@ -694,6 +696,7 @@ void _decode_opc(DisasContext * ctx)
 	    tcg_gen_shri_i32(low, REG(B7_4), 8);
 	    tcg_gen_ext8u_i32(low, low);
 	    tcg_gen_or_i32(REG(B11_8), high, low);
+	    tcg_gen_or_i32(REG(B11_8), REG(B11_8), highw);
 	    tcg_temp_free(low);
 	    tcg_temp_free(high);
 	}
Signature · 1 line
1.5.3.5
#1 lore raw
Quoted 11 lines · Vladimir Prus

The SH4 manual documents the swap.b instruction as follows:

SWAP.B Rm,Rn
Rm → swap lower 2 bytes → Rn

Current QEMU code, in addition to the above, also clears the high 16 bits. The immediate breakage I saw is that htonl function applied to netmask of 255.255.255.0 gives 0, which breaks all networking. Attached patch fixes the problem.

Thanks, applied.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net