aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/arm64/arch-transform-dis.inc.h6
-rw-r--r--test/transform-dis-cases-arm64.S35
-rw-r--r--test/transform-dis-cases-x86_64.S13
3 files changed, 51 insertions, 3 deletions
diff --git a/lib/arm64/arch-transform-dis.inc.h b/lib/arm64/arch-transform-dis.inc.h
index 123c7ae..73fe227 100644
--- a/lib/arm64/arch-transform-dis.inc.h
+++ b/lib/arm64/arch-transform-dis.inc.h
@@ -45,7 +45,7 @@ void transform_dis_branch(struct transform_dis_ctx *ctx, uint_tptr dpc, int cc)
static void transform_dis_pre_dis(UNUSED struct transform_dis_ctx *ctx) {}
static void transform_dis_post_dis(struct transform_dis_ctx *ctx) {
uint32_t op = ctx->base.op;
- ctx->arch.regs_possibly_written |= op & 31;
- ctx->arch.regs_possibly_written |= op >> 10 & 31;
- ctx->arch.regs_possibly_written |= op >> 16 & 31;
+ ctx->arch.regs_possibly_written |= 1 << (op & 31);
+ ctx->arch.regs_possibly_written |= 1 << (op >> 10 & 31);
+ ctx->arch.regs_possibly_written |= 1 << (op >> 16 & 31);
}
diff --git a/test/transform-dis-cases-arm64.S b/test/transform-dis-cases-arm64.S
new file mode 100644
index 0000000..cc3bd4c
--- /dev/null
+++ b/test/transform-dis-cases-arm64.S
@@ -0,0 +1,35 @@
+#define GIVEN .ascii "GIVEN";
+#define EXPECT .ascii "EXPECT";
+#define EXPECT_ERR .ascii "EXPECT_ERR";
+
+/* yay clang, no semicolons allowed */
+
+GIVEN
+ blr x5
+EXPECT
+ blr x5
+
+GIVEN
+ blr x5
+ nop
+EXPECT_ERR
+
+GIVEN
+ cbnz x8, .+0x100
+EXPECT
+ cbz x8, 1f
+ mov x18, #0x0100
+ movk x18, #0xdead, lsl #16
+ br x18
+ 1:
+
+GIVEN
+ 0: mov x18, #0x123
+ cbnz x18, 0b+0x100
+EXPECT
+ mov x18, #0x123
+ cbz x18, 1f
+ mov x17, #0x0100
+ movk x17, #0xdead, lsl #16
+ br x17
+ 1:
diff --git a/test/transform-dis-cases-x86_64.S b/test/transform-dis-cases-x86_64.S
new file mode 100644
index 0000000..7dccf24
--- /dev/null
+++ b/test/transform-dis-cases-x86_64.S
@@ -0,0 +1,13 @@
+#define GIVEN .ascii "GIVEN";
+#define EXPECT .ascii "EXPECT";
+#define EXPECT_ERR .ascii "EXPECT_ERR";
+
+GIVEN nopl (%rip)
+EXPECT push %rcx; mov $0xdead0007, %rcx; nopl (%rcx); pop %rcx
+GIVEN mov (%rip), %rax
+EXPECT push %rcx; mov $0xdead0007, %rcx; mov (%rcx), %rax; pop %rcx
+GIVEN mov (%rip), %rcx
+EXPECT push %rax; mov $0xdead0007, %rax; mov (%rax), %rcx; pop %rax
+GIVEN jmpq *(%rip)
+EXPECT push %rax; mov $0xdead0006, %rax; mov %rax, -8(%rsp); pop %rax;
+ jmp *-0x10(%rsp)