aboutsummaryrefslogtreecommitdiff
path: root/src/process.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.zig')
-rw-r--r--src/process.zig21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/process.zig b/src/process.zig
index 9577bc3..a6217c6 100644
--- a/src/process.zig
+++ b/src/process.zig
@@ -5,14 +5,13 @@
const std = @import("std");
const instructions = @import("instructions.zig");
-const interrupts = @import("interrupts.zig");
const paging = @import("paging.zig");
const trap = @import("trap.zig");
const num_stack_pages = 2;
var next_pid: u16 = 1;
-var list = std.mem.zeroInit(std.DoublyLinkedList(*Info));
+var list = std.mem.zeroInit(std.DoublyLinkedList(Info), .{});
pub const State = enum(u8) {
waiting,
@@ -73,16 +72,16 @@ fn new(entry: usize) !Info {
return proc;
}
-pub fn nextScheduled() ?Info {
- if (list.popFirst()) |next| {
- list.append(next);
- return next.data;
+pub fn next() ?*Info {
+ if (list.popFirst()) |info| {
+ list.append(info);
+ return &info.data;
}
return null;
}
-fn switchTo(proc: *const Info) noreturn {
+pub fn switchTo(proc: *const Info) noreturn {
instructions.setSscratch(@intFromPtr(&proc.trap_frame));
asm volatile (
@@ -142,7 +141,7 @@ fn switchTo(proc: *const Info) noreturn {
unreachable;
}
-pub fn demo() !void {
+pub fn demo(allocator: std.mem.Allocator) !void {
const entry: [*]u8 = @alignCast(@ptrCast(try paging.zeroedAlloc(1)));
defer paging.free(@ptrCast(entry)) catch {};
@@ -151,8 +150,10 @@ pub fn demo() !void {
entry[2] = 0x00;
entry[3] = 0x00;
- var proc = try new(@intFromPtr(entry));
- switchTo(&proc);
+ const proc = try new(@intFromPtr(entry));
+ const proc_node = try allocator.create(std.DoublyLinkedList(Info).Node);
+ proc_node.data = proc;
+ list.prepend(proc_node);
while (true) asm volatile ("wfi");
}