From c71be1bc3735e885fa54d0cbae639cbdda9f3394 Mon Sep 17 00:00:00 2001 From: dingusdev Date: Wed, 19 Feb 2020 19:03:39 -0700 Subject: [PATCH] Fixed compare instructions --- cpu/ppc/ppcdisasm.cpp | 19 +++++++++++++------ cpu/ppc/test/ppcdisasmtest.csv | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cpu/ppc/ppcdisasm.cpp b/cpu/ppc/ppcdisasm.cpp index 3a31a77..da71c90 100644 --- a/cpu/ppc/ppcdisasm.cpp +++ b/cpu/ppc/ppcdisasm.cpp @@ -473,7 +473,7 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) auto ls = (ctx->instr_code >> 21) & 0x1; auto ra = (ctx->instr_code >> 16) & 0x1F; auto crfd = (ctx->instr_code >> 23) & 0x07; - auto imm = ctx->instr_code & 0xFFFF; + int imm = ctx->instr_code & 0xFFFF; if (ctx->simplified) { @@ -481,7 +481,7 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) if ((ctx->instr_code >> 26) & 0x1) ctx->instr_str = my_sprintf("%-8scr%d, r%d, 0x%X", "cmpwi", crfd, ra, imm); else - ctx->instr_str = my_sprintf("%-8scr%d, r%d, 0x%04X", "cmplwi", crfd, ra, imm); + ctx->instr_str = my_sprintf("%-8scr%d, r%d, %s0x%X", "cmplwi", crfd, ra, (imm < 0) ? "-" : "", abs(imm)); return; } @@ -490,7 +490,7 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) if ((ctx->instr_code >> 26) & 0x1) ctx->instr_str = my_sprintf("%-8scr%d, %d, r%d, 0x%X", "cmpi", crfd, ls, ra, imm); else - ctx->instr_str = my_sprintf("%-8scr%d, %d, r%d, 0x%04X", "cmpli", crfd, ls, ra, imm); + ctx->instr_str = my_sprintf("%-8scr%d, %d, r%d, %s0x%X", "cmpli", crfd, ls, ra, (imm < 0) ? "-" : "", abs(imm)); } void opc_bool_im(PPCDisasmContext* ctx) @@ -1067,8 +1067,14 @@ void opc_group31(PPCDisasmContext* ctx) if (ctx->simplified) { if (!(rs & 1)) { - ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmpw", (rs >> 2), ra, rb); - return; + if ((rs >> 2) == 0) { + ctx->instr_str = my_sprintf("%-8sr%d, r%d", "cmpw", ra, rb); + return; + } + else { + ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmpw", (rs >> 2), ra, rb); + return; + } } } @@ -1127,8 +1133,9 @@ void opc_group31(PPCDisasmContext* ctx) } } - else + else { ctx->instr_str = my_sprintf("%-8scr%d, %d, r%d, r%d", "cmpl", (rs >> 2), (rs & 1), ra, rb); + } break; case 83: /* mfmsr */ ctx->instr_str = my_sprintf("%-8sr%d", "mfmsr", diff --git a/cpu/ppc/test/ppcdisasmtest.csv b/cpu/ppc/test/ppcdisasmtest.csv index 791dbb9..ea2bcb0 100644 --- a/cpu/ppc/test/ppcdisasmtest.csv +++ b/cpu/ppc/test/ppcdisasmtest.csv @@ -357,9 +357,9 @@ # compare instructions 0xFFF00100,0x7C15A000,cmpw,r21,r20 0xFFF00100,0x7FBFB800,cmp,cr7,1,r31,r23 -0xFFF00100,0x7FA05840,cmpl,cr7,1,r0,r11 -0xFFF00100,0x2FA90000,cmpi,cr7,1,r9,0x0 -0xFFF00100,0x2AA3FFFF,cmpli,cr5,1,r3,0xFFFF +0xFFF00100,0x7F804840,cmplw,cr7,r0,r9 +0xFFF00100,0x2F800000,cmpwi,cr7,r0,0x0 +0xFFF00100,0x298E0022,cmplwi,cr3,r14,0x22 0xFFF00100,0xFE17C840,fcmpo,cr4,f23,f25 0xFFF00100,0xFF0C6800,fcmpu,cr6,f12,f13