Compare commits

..

3 Commits

2 changed files with 17 additions and 2 deletions

View File

@ -108,7 +108,8 @@ pub fn Arm32(comptime arch: Architecture) type {
}; };
} }
inline fn regIdx(mode: Mode, kind: Kind) usize { // public so that we can set up fast-boot
pub inline fn regIdx(mode: Mode, kind: Kind) usize {
const idx: usize = switch (mode) { const idx: usize = switch (mode) {
.User, .System => 0, .User, .System => 0,
.Supervisor => 1, .Supervisor => 1,

View File

@ -139,6 +139,7 @@ pub const Scheduler = struct {
// VTable // VTable
nowFn: *const fn (ptr: *anyopaque) u64, nowFn: *const fn (ptr: *anyopaque) u64,
resetFn: *const fn (ptr: *anyopaque) void,
pub fn init(obj: anytype) @This() { pub fn init(obj: anytype) @This() {
const P = @TypeOf(obj); const P = @TypeOf(obj);
@ -155,14 +156,23 @@ pub const Scheduler = struct {
const self = @ptrCast(P, @alignCast(alignment, ptr)); const self = @ptrCast(P, @alignCast(alignment, ptr));
return self.now(); return self.now();
} }
fn reset(ptr: *anyopaque) void {
const self = @ptrCast(P, @alignCast(alignment, ptr));
self.reset();
}
}; };
return .{ .ptr = obj, .nowFn = impl.now }; return .{ .ptr = obj, .nowFn = impl.now, .resetFn = impl.reset };
} }
pub fn now(self: @This()) u64 { pub fn now(self: @This()) u64 {
return self.nowFn(self.ptr); return self.nowFn(self.ptr);
} }
pub fn reset(self: @This()) void {
self.resetFn(self.ptr);
}
}; };
// --- // ---
@ -191,6 +201,10 @@ const ExampleScheduler = struct {
pub fn now(self: *const @This()) u64 { pub fn now(self: *const @This()) u64 {
return self.tick; return self.tick;
} }
pub fn reset(self: *@This()) void {
self.tick = 0;
}
}; };
test "create ARMv4T interface" { test "create ARMv4T interface" {