Skip to content

Commit

Permalink
systemz: fix truncated 64bit imm operand in issue capstone-engine#1515
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Jul 10, 2019
1 parent c609731 commit 4304060
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 10 additions & 0 deletions arch/SystemZ/SystemZGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10645,6 +10645,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 0 encoded into 5 bits for 18 unique commands.
// printf("Fragment 0 = %" PRIu64 "\n", (Bits >> 14) & 31);
switch ((Bits >> 14) & 31) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -10752,6 +10753,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 1 encoded into 5 bits for 17 unique commands.
// printf("Fragment 1 = %" PRIu64 "\n", (Bits >> 19) & 31);
switch ((Bits >> 19) & 31) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -10845,6 +10847,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 2 encoded into 6 bits for 34 unique commands.
// printf("Fragment 2 = %" PRIu64 "\n", (Bits >> 24) & 63);
switch ((Bits >> 24) & 63) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -11011,6 +11014,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 3 encoded into 5 bits for 20 unique commands.
// printf("Fragment 3 = %" PRIu64 "\n", (Bits >> 30) & 31);
switch ((Bits >> 30) & 31) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -11116,6 +11120,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 4 encoded into 6 bits for 33 unique commands.
// printf("Fragment 4 = %" PRIu64 "\n", (Bits >> 35) & 63);
switch ((Bits >> 35) & 63) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -11277,6 +11282,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 5 encoded into 4 bits for 9 unique commands.
// printf("Fragment 5 = %" PRIu64 "\n", (Bits >> 41) & 15);
switch ((Bits >> 41) & 15) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -11329,6 +11335,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 6 encoded into 4 bits for 11 unique commands.
// printf("Fragment 6 = %" PRIu64 "\n", (Bits >> 45) & 15);
switch ((Bits >> 45) & 15) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand Down Expand Up @@ -11386,6 +11393,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 7 encoded into 1 bits for 2 unique commands.
// printf("Fragment 7 = %" PRIu64 "\n", (Bits >> 49) & 1);
if ((Bits >> 49) & 1) {
// RISBG, RISBG32, RISBGN, RISBHG, RISBLG, RNSBG, ROSBG, RXSBG, VAC, VACC...
SStream_concat0(O, ", ");
Expand All @@ -11396,6 +11404,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 8 encoded into 2 bits for 3 unique commands.
// printf("Fragment 8 = %" PRIu64 "\n", (Bits >> 50) & 3);
switch ((Bits >> 50) & 3) {
default: // llvm_unreachable("Invalid command number.");
case 0:
Expand All @@ -11416,6 +11425,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 9 encoded into 1 bits for 2 unique commands.
// printf("Fragment 9 = %" PRIu64 "\n", (Bits >> 52) & 1);
if ((Bits >> 52) & 1) {
// VFCE, VFCH, VFCHE, VFMA, VFMAX, VFMIN, VFMS, VFNMA, VFNMS, VMSL, VSTRC
SStream_concat0(O, ", ");
Expand Down
7 changes: 3 additions & 4 deletions arch/SystemZ/SystemZInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,15 @@ static void printU48ImmOperand(MCInst *MI, int OpNum, SStream *O)
static void printPCRelOperand(MCInst *MI, int OpNum, SStream *O)
{
MCOperand *MO = MCInst_getOperand(MI, OpNum);
int32_t imm;

if (MCOperand_isImm(MO)) {
imm = (int32_t)MCOperand_getImm(MO);
int64_t imm = (int64_t)MCOperand_getImm(MO);

printInt32(O, imm);
printInt64(O, imm);

if (MI->csh->detail) {
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].type = SYSZ_OP_IMM;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = (int64_t)imm;
MI->flat_insn->detail->sysz.operands[MI->flat_insn->detail->sysz.op_count].imm = imm;
MI->flat_insn->detail->sysz.op_count++;
}
}
Expand Down

0 comments on commit 4304060

Please sign in to comment.