summaryrefslogtreecommitdiff
path: root/anim/src/disasm.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/disasm.zig')
-rw-r--r--anim/src/disasm.zig36
1 files changed, 26 insertions, 10 deletions
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig
index 3748eac..fc6f63d 100644
--- a/anim/src/disasm.zig
+++ b/anim/src/disasm.zig
@@ -1321,13 +1321,18 @@ pub fn liveRow(at: ui.Ui, row: Insn, y: f32, width: f32, moment: Recording.Momen
while (words.next()) |word| {
const reg = full(word) orelse continue;
if (seen) |previous| if (std.mem.eql(u8, reg, previous)) continue;
- const raw = regs.named(reg) orelse continue;
- const value = number(u, if (word.len == 2 and word[1] == 'h') raw >> 8 else raw, registerSize(word) orelse 8);
+ var raw = regs.named(reg) orelse continue;
+ const bytes = registerSize(word) orelse 8;
+ if (word.len == 2 and word[1] == 'h') raw >>= 8;
+ if (bytes < 8) raw &= (@as(u64, 1) << @intCast(bytes * 8)) - 1;
+ const value = number(u, raw, bytes);
const text = u.print("{s} {s}", .{ word, value });
const w = u.width(.mono, size, text);
if (x + w > room) break;
u.text(.mono, size, x, base_y, word, t.dim);
- u.text(.mono, size, x + @as(f32, @floatFromInt(word.len + 1)) * adv, base_y, value, t.primary);
+ const value_x = x + @as(f32, @floatFromInt(word.len + 1)) * adv;
+ u.text(.mono, size, value_x, base_y, value, t.primary);
+ if (rows.regionOf(moment, raw) != .none) u.hitAddress(raw, .{ .x = value_x, .y = y, .w = u.width(.mono, size, value), .h = m.row });
x += w + 2 * adv;
seen = reg;
}
@@ -1492,16 +1497,19 @@ fn written(row: Insn) ?[]const u8 {
/// A register's 64-bit name, from any of its widths.
fn full(name: []const u8) ?[]const u8 {
- const table = [_][2][]const u8{
- .{ "rax", "eax" }, .{ "rbx", "ebx" }, .{ "rcx", "ecx" }, .{ "rdx", "edx" },
- .{ "rsi", "esi" }, .{ "rdi", "edi" }, .{ "rbp", "ebp" }, .{ "rsp", "esp" },
+ const table = [_][]const []const u8{
+ &.{ "rax", "eax", "ax", "al", "ah" }, &.{ "rbx", "ebx", "bx", "bl", "bh" },
+ &.{ "rcx", "ecx", "cx", "cl", "ch" }, &.{ "rdx", "edx", "dx", "dl", "dh" },
+ &.{ "rsi", "esi", "si", "sil" }, &.{ "rdi", "edi", "di", "dil" },
+ &.{ "rbp", "ebp", "bp", "bpl" }, &.{ "rsp", "esp", "sp", "spl" },
+ };
+ for (table) |aliases| for (aliases) |alias| {
+ if (std.mem.eql(u8, name, alias)) return aliases[0];
};
- for (table) |pair| {
- if (std.mem.eql(u8, name, pair[0]) or std.mem.eql(u8, name, pair[1])) return pair[0];
- if (name.len == 2 and pair[0][1] == name[0] and (name[1] == 'x' or name[1] == 'l' or name[1] == 'h' or name[1] == 'i' or name[1] == 'p')) return pair[0];
- }
if (name.len >= 2 and name[0] == 'r' and std.ascii.isDigit(name[1])) {
const digits = if (name.len >= 3 and std.ascii.isDigit(name[2])) name[0..3] else name[0..2];
+ const suffix = name[digits.len..];
+ if (suffix.len != 0 and !(suffix.len == 1 and std.mem.indexOfScalar(u8, "dwb", suffix[0]) != null)) return null;
for ([_][]const u8{ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" }) |r| if (std.mem.eql(u8, r, digits)) return r;
}
return null;
@@ -1610,6 +1618,14 @@ test "a register is known by any of its widths" {
try std.testing.expectEqualStrings("rdi", full("rdi").?);
try std.testing.expectEqualStrings("r10", full("r10d").?);
try std.testing.expectEqualStrings("rax", full("al").?);
+ try std.testing.expectEqualStrings("rdi", full("di").?);
+ try std.testing.expectEqualStrings("rbp", full("bp").?);
+ try std.testing.expectEqualStrings("rsp", full("sp").?);
+ try std.testing.expectEqualStrings("rsi", full("sil").?);
+ try std.testing.expectEqualStrings("rdi", full("dil").?);
+ try std.testing.expectEqualStrings("rbp", full("bpl").?);
+ try std.testing.expectEqualStrings("rsp", full("spl").?);
+ try std.testing.expect(full("r8junk") == null);
try std.testing.expect(full("qword ptr [rbp - 8]") == null);
}