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 .{
|
return .{
|
||||||
.ptr = obj,
|
.ptr = obj,
|
||||||
.vtable = &.{
|
.vtab = &.{
|
||||||
.read8 = impl.read8,
|
.read8 = impl.read8,
|
||||||
.read16 = impl.read16,
|
.read16 = impl.read16,
|
||||||
.read32 = impl.read32,
|
.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" {
|
test "create ARMv4T interface" {
|
||||||
var bus_impl = ExampleBus{};
|
var bus: Bus = .{ .ptr = undefined, .vtable = undefined };
|
||||||
var scheduler_impl = ExampleScheduler{};
|
var scheduler: Scheduler = .{ .ptr = undefined, .nowFn = undefined };
|
||||||
|
|
||||||
const bus_interface = Bus.init(&bus_impl);
|
|
||||||
const scheduler_interface = Scheduler.init(&scheduler_impl);
|
|
||||||
|
|
||||||
var arm7tdmi = Arm7tdmi{
|
var arm7tdmi = Arm7tdmi{
|
||||||
.sched = scheduler_interface,
|
.sched = scheduler,
|
||||||
.bus = bus_interface,
|
.bus = bus,
|
||||||
.cpsr = .{ .raw = 0x0000_001F },
|
.cpsr = .{ .raw = 0x0000_001F },
|
||||||
.spsr = .{ .raw = 0x0000_0000 },
|
.spsr = .{ .raw = 0x0000_0000 },
|
||||||
};
|
};
|
||||||
|
@ -213,15 +182,12 @@ test "create ARMv4T interface" {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "create ARMv5TE interface" {
|
test "create ARMv5TE interface" {
|
||||||
var bus_impl = ExampleBus{};
|
var bus: Bus = .{ .ptr = undefined, .vtable = undefined };
|
||||||
var scheduler_impl = ExampleScheduler{};
|
var scheduler: Scheduler = .{ .ptr = undefined, .nowFn = undefined };
|
||||||
|
|
||||||
const bus_interface = Bus.init(&bus_impl);
|
var arm946es = Arm7tdmi{
|
||||||
const scheduler_interface = Scheduler.init(&scheduler_impl);
|
.sched = scheduler,
|
||||||
|
.bus = bus,
|
||||||
var arm946es = Arm946es{
|
|
||||||
.sched = scheduler_interface,
|
|
||||||
.bus = bus_interface,
|
|
||||||
.cpsr = .{ .raw = 0x0000_001F },
|
.cpsr = .{ .raw = 0x0000_001F },
|
||||||
.spsr = .{ .raw = 0x0000_0000 },
|
.spsr = .{ .raw = 0x0000_0000 },
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue