feat: implement debug i/o in Bus Interface

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-06-29 23:12:08 -05:00
parent 3c8a87c14d
commit 90d5c19e01
1 changed files with 102 additions and 7 deletions

View File

@ -45,6 +45,14 @@ pub const Bus = struct {
write16: *const fn (ptr: *anyopaque, address: u32, value: u16) void, write16: *const fn (ptr: *anyopaque, address: u32, value: u16) void,
write32: *const fn (ptr: *anyopaque, address: u32, value: u32) void, write32: *const fn (ptr: *anyopaque, address: u32, value: u32) void,
dbg_read8: *const fn (ptr: *anyopaque, address: u32) u8,
dbg_read16: *const fn (ptr: *anyopaque, address: u32) u16,
dbg_read32: *const fn (ptr: *anyopaque, address: u32) u32,
dbg_write8: *const fn (ptr: *anyopaque, address: u32, value: u8) void,
dbg_write16: *const fn (ptr: *anyopaque, address: u32, value: u16) void,
dbg_write32: *const fn (ptr: *anyopaque, address: u32, value: u32) void,
reset: *const fn (ptr: *anyopaque) void, reset: *const fn (ptr: *anyopaque) void,
}; };
@ -89,6 +97,36 @@ pub const Bus = struct {
self.write(u32, address, value); self.write(u32, address, value);
} }
fn dbgRead8(ptr: *anyopaque, address: u32) u8 {
const self = @ptrCast(P, @alignCast(alignment, ptr));
return self.dbgRead(u8, address);
}
fn dbgRead16(ptr: *anyopaque, address: u32) u16 {
const self = @ptrCast(P, @alignCast(alignment, ptr));
return self.dbgRead(u16, address);
}
fn dbgRead32(ptr: *anyopaque, address: u32) u32 {
const self = @ptrCast(P, @alignCast(alignment, ptr));
return self.dbgRead(u32, address);
}
fn dbgWrite8(ptr: *anyopaque, address: u32, value: u8) void {
const self = @ptrCast(P, @alignCast(alignment, ptr));
self.dbgWrite(u8, address, value);
}
fn dbgWrite16(ptr: *anyopaque, address: u32, value: u16) void {
const self = @ptrCast(P, @alignCast(alignment, ptr));
self.dbgWrite(u16, address, value);
}
fn dbgWrite32(ptr: *anyopaque, address: u32, value: u32) void {
const self = @ptrCast(P, @alignCast(alignment, ptr));
self.dbgWrite(u32, address, value);
}
fn reset(ptr: *anyopaque) void { fn reset(ptr: *anyopaque) void {
const self = @ptrCast(P, @alignCast(alignment, ptr)); const self = @ptrCast(P, @alignCast(alignment, ptr));
self.reset(); self.reset();
@ -106,6 +144,14 @@ pub const Bus = struct {
.write16 = impl.write16, .write16 = impl.write16,
.write32 = impl.write32, .write32 = impl.write32,
.dbg_read8 = impl.dbgRead8,
.dbg_read16 = impl.dbgRead16,
.dbg_read32 = impl.dbgRead32,
.dbg_write8 = impl.dbgWrite8,
.dbg_write16 = impl.dbgWrite16,
.dbg_write32 = impl.dbgWrite32,
.reset = impl.reset, .reset = impl.reset,
}, },
}; };
@ -130,16 +176,21 @@ pub const Bus = struct {
} }
pub fn dbgRead(self: @This(), comptime T: type, address: u32) T { pub fn dbgRead(self: @This(), comptime T: type, address: u32) T {
_ = address; return switch (T) {
_ = self; u32 => self.vtable.dbg_read32(self.ptr, address),
@panic("TODO: Implement Debug Reads via Bus Interface"); u16 => self.vtable.dbg_read16(self.ptr, address),
u8 => self.vtable.dbg_read8(self.ptr, address),
else => @compileError("TODO: Fill this in"),
};
} }
pub fn dbgWrite(self: @This(), comptime T: type, address: u32, value: T) void { pub fn dbgWrite(self: @This(), comptime T: type, address: u32, value: T) void {
_ = self; switch (T) {
_ = value; u32 => self.vtable.dbg_write32(self.ptr, address, value),
_ = address; u16 => self.vtable.dbg_write16(self.ptr, address, value),
@panic("TODO: Implement Debug Writes via Bus Interface"); u8 => self.vtable.dbg_write8(self.ptr, address, value),
else => @compileError("TODO: Fill this in"),
}
} }
pub fn reset(self: @This()) void { pub fn reset(self: @This()) void {
@ -206,6 +257,17 @@ const ExampleBus = struct {
_ = value; _ = value;
_ = address; _ = address;
} }
pub fn dbgRead(self: *@This(), comptime T: type, address: u32) T {
_ = self;
_ = address;
return 0;
}
pub fn dbgWrite(self: *@This(), comptime T: type, address: u32, value: T) void {
_ = self;
_ = value;
_ = address;
}
pub fn reset(self: *@This()) void { pub fn reset(self: *@This()) void {
self._ = 0; self._ = 0;
@ -224,6 +286,38 @@ const ExampleScheduler = struct {
} }
}; };
test "create IBus" {
var bus_impl = ExampleBus{};
const iface = Bus.init(&bus_impl);
_ = iface;
}
test "call IBus reads" {
var bus_impl = ExampleBus{};
const iface = Bus.init(&bus_impl);
_ = iface.read(u32, 0x0000_0000);
_ = iface.read(u16, 0x0000_0000);
_ = iface.read(u8, 0x0000_0000);
_ = iface.dbgRead(u32, 0x0000_0000);
_ = iface.dbgRead(u16, 0x0000_0000);
_ = iface.dbgRead(u8, 0x0000_0000);
}
test "call IBus writes" {
var bus_impl = ExampleBus{};
const iface = Bus.init(&bus_impl);
_ = iface.write(u32, 0x0000_0000, 0x0000_0000);
_ = iface.write(u16, 0x0000_0000, 0x0000);
_ = iface.write(u8, 0x0000_0000, 0x00);
_ = iface.dbgWrite(u32, 0x0000_0000, 0x0000_0000);
_ = iface.dbgWrite(u16, 0x0000_0000, 0x0000);
_ = iface.dbgWrite(u8, 0x0000_0000, 0x00);
}
test "create ARMv4T interface" { test "create ARMv4T interface" {
var bus_impl = ExampleBus{}; var bus_impl = ExampleBus{};
var scheduler_impl = ExampleScheduler{}; var scheduler_impl = ExampleScheduler{};
@ -242,6 +336,7 @@ test "create ARMv4T interface" {
icpu.reset(); icpu.reset();
icpu.step(); icpu.step();
// TODO: call icpu.panic()
} }
test "create ARMv5TE interface" { test "create ARMv5TE interface" {