feat: implement instruction-granular stepping

This commit is contained in:
2022-12-15 19:31:24 -04:00
parent 21565a9726
commit 460fcec370
3 changed files with 49 additions and 39 deletions

View File

@@ -10,10 +10,11 @@ pub const Emulator = struct {
readFn: *const fn (*anyopaque, u32) u8,
writeFn: *const fn (*anyopaque, u32, u8) void,
// FIXME: Expensive copy
registersFn: *const fn (*anyopaque) [16]u32,
registersFn: *const fn (*anyopaque) *[16]u32,
cpsrFn: *const fn (*anyopaque) u32,
stepFn: *const fn (*anyopaque) void,
pub fn init(ptr: anytype) Self {
const Ptr = @TypeOf(ptr);
const ptr_info = @typeInfo(Ptr);
@@ -36,7 +37,7 @@ pub const Emulator = struct {
return @call(.{ .modifier = .always_inline }, ptr_info.Pointer.child.write, .{ self, addr, value });
}
pub fn registersImpl(pointer: *anyopaque) [16]u32 {
pub fn registersImpl(pointer: *anyopaque) *[16]u32 {
const self = @ptrCast(Ptr, @alignCast(alignment, pointer));
return @call(.{ .modifier = .always_inline }, ptr_info.Pointer.child.registers, .{self});
@@ -47,15 +48,15 @@ pub const Emulator = struct {
return @call(.{ .modifier = .always_inline }, ptr_info.Pointer.child.cpsr, .{self});
}
pub fn stepImpl(pointer: *anyopaque) void {
const self = @ptrCast(Ptr, @alignCast(alignment, pointer));
return @call(.{ .modifier = .always_inline }, ptr_info.Pointer.child.step, .{self});
}
};
return .{
.ptr = ptr,
.readFn = gen.readImpl,
.writeFn = gen.writeImpl,
.registersFn = gen.registersImpl,
.cpsrFn = gen.cpsrImpl,
};
return .{ .ptr = ptr, .readFn = gen.readImpl, .writeFn = gen.writeImpl, .registersFn = gen.registersImpl, .cpsrFn = gen.cpsrImpl, .stepFn = gen.stepImpl };
}
pub inline fn read(self: Self, addr: u32) u8 {
@@ -66,11 +67,15 @@ pub const Emulator = struct {
self.writeFn(self.ptr, addr, value);
}
pub inline fn registers(self: Self) [16]u32 {
pub inline fn registers(self: Self) *[16]u32 {
return self.registersFn(self.ptr);
}
pub inline fn cpsr(self: Self) u32 {
return self.cpsrFn(self.ptr);
}
pub inline fn step(self: Self) void {
self.stepFn(self.ptr);
}
};