Compare commits
2 Commits
9643b520c8
...
b8a7c212b2
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | b8a7c212b2 | |
Rekai Nyangadzayi Musuka | e0d67a9e54 |
54
src/lib.zig
54
src/lib.zig
|
@ -89,7 +89,7 @@ pub const Bus = struct {
|
|||
|
||||
return .{
|
||||
.ptr = obj,
|
||||
.vtab = &.{
|
||||
.vtable = &.{
|
||||
.read8 = impl.read8,
|
||||
.read16 = impl.read16,
|
||||
.read32 = impl.read32,
|
||||
|
@ -164,13 +164,44 @@ pub const Scheduler = struct {
|
|||
}
|
||||
};
|
||||
|
||||
// ---
|
||||
// TESTING
|
||||
// ---
|
||||
|
||||
const ExampleBus = struct {
|
||||
_: u32 = 0, // Note: need this field so that the ptr align of *lib.ExampleBus != 0
|
||||
|
||||
pub fn read(self: *@This(), comptime T: type, address: u32) T {
|
||||
_ = self;
|
||||
_ = address;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn write(self: *@This(), comptime T: type, address: u32, value: T) void {
|
||||
_ = self;
|
||||
_ = value;
|
||||
_ = address;
|
||||
}
|
||||
};
|
||||
|
||||
const ExampleScheduler = struct {
|
||||
tick: u64 = 0,
|
||||
|
||||
pub fn now(self: *const @This()) u64 {
|
||||
return self.tick;
|
||||
}
|
||||
};
|
||||
|
||||
test "create ARMv4T interface" {
|
||||
var bus: Bus = .{ .ptr = undefined, .vtable = undefined };
|
||||
var scheduler: Scheduler = .{ .ptr = undefined, .nowFn = undefined };
|
||||
var bus_impl = ExampleBus{};
|
||||
var scheduler_impl = ExampleScheduler{};
|
||||
|
||||
const bus_interface = Bus.init(&bus_impl);
|
||||
const scheduler_interface = Scheduler.init(&scheduler_impl);
|
||||
|
||||
var arm7tdmi = Arm7tdmi{
|
||||
.sched = scheduler,
|
||||
.bus = bus,
|
||||
.sched = scheduler_interface,
|
||||
.bus = bus_interface,
|
||||
.cpsr = .{ .raw = 0x0000_001F },
|
||||
.spsr = .{ .raw = 0x0000_0000 },
|
||||
};
|
||||
|
@ -182,12 +213,15 @@ test "create ARMv4T interface" {
|
|||
}
|
||||
|
||||
test "create ARMv5TE interface" {
|
||||
var bus: Bus = .{ .ptr = undefined, .vtable = undefined };
|
||||
var scheduler: Scheduler = .{ .ptr = undefined, .nowFn = undefined };
|
||||
var bus_impl = ExampleBus{};
|
||||
var scheduler_impl = ExampleScheduler{};
|
||||
|
||||
var arm946es = Arm7tdmi{
|
||||
.sched = scheduler,
|
||||
.bus = bus,
|
||||
const bus_interface = Bus.init(&bus_impl);
|
||||
const scheduler_interface = Scheduler.init(&scheduler_impl);
|
||||
|
||||
var arm946es = Arm946es{
|
||||
.sched = scheduler_interface,
|
||||
.bus = bus_interface,
|
||||
.cpsr = .{ .raw = 0x0000_001F },
|
||||
.spsr = .{ .raw = 0x0000_0000 },
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue