Compare commits
2 Commits
b8a7c212b2
...
9643b520c8
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | 9643b520c8 | |
Rekai Nyangadzayi Musuka | 78cdb10395 |
54
src/lib.zig
54
src/lib.zig
|
@ -89,7 +89,7 @@ pub const Bus = struct {
|
|||
|
||||
return .{
|
||||
.ptr = obj,
|
||||
.vtable = &.{
|
||||
.vtab = &.{
|
||||
.read8 = impl.read8,
|
||||
.read16 = impl.read16,
|
||||
.read32 = impl.read32,
|
||||
|
@ -164,44 +164,13 @@ 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_impl = ExampleBus{};
|
||||
var scheduler_impl = ExampleScheduler{};
|
||||
|
||||
const bus_interface = Bus.init(&bus_impl);
|
||||
const scheduler_interface = Scheduler.init(&scheduler_impl);
|
||||
var bus: Bus = .{ .ptr = undefined, .vtable = undefined };
|
||||
var scheduler: Scheduler = .{ .ptr = undefined, .nowFn = undefined };
|
||||
|
||||
var arm7tdmi = Arm7tdmi{
|
||||
.sched = scheduler_interface,
|
||||
.bus = bus_interface,
|
||||
.sched = scheduler,
|
||||
.bus = bus,
|
||||
.cpsr = .{ .raw = 0x0000_001F },
|
||||
.spsr = .{ .raw = 0x0000_0000 },
|
||||
};
|
||||
|
@ -213,15 +182,12 @@ test "create ARMv4T interface" {
|
|||
}
|
||||
|
||||
test "create ARMv5TE interface" {
|
||||
var bus_impl = ExampleBus{};
|
||||
var scheduler_impl = ExampleScheduler{};
|
||||
var bus: Bus = .{ .ptr = undefined, .vtable = undefined };
|
||||
var scheduler: Scheduler = .{ .ptr = undefined, .nowFn = undefined };
|
||||
|
||||
const bus_interface = Bus.init(&bus_impl);
|
||||
const scheduler_interface = Scheduler.init(&scheduler_impl);
|
||||
|
||||
var arm946es = Arm946es{
|
||||
.sched = scheduler_interface,
|
||||
.bus = bus_interface,
|
||||
var arm946es = Arm7tdmi{
|
||||
.sched = scheduler,
|
||||
.bus = bus,
|
||||
.cpsr = .{ .raw = 0x0000_001F },
|
||||
.spsr = .{ .raw = 0x0000_0000 },
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue