feat: implement instruction-granular stepping
This commit is contained in:
27
src/lib.zig
27
src/lib.zig
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user