
Fix TSS Also change to .{} syntax where appropriate. Added the SS segment Fixed spelling Refactoring GDT Multitasking working for now WIP scheduler Refactored Bitmap a bit WIP still Task switching working Handlers return the stack pointer that will be used to restore the tasks stack, normal handlers will return the same stack pointer it was called with where task switching will return the stack pointer of the next task and restore its state using the interrupt stub. Initial scheduler done Created a stage 2 init task Change u32 to usize Move Task to arch specific WIP WIP2 Removed esp from task, replaced with stack_pointer Removed the debug logs Fixed init task stack Change pickNextTask to pointer manipulation This allows less allocations so faster switching Temporary enable interrupts for some runtime tests PIT and RTC need interrupts enabled to run their runtime tests Renamed schedule => pickNextTask, comptime bitmap for pids not task init And some other stuff: No pub for the task anymore Use the leak detector allocator Fmt Fix unit tests And some other stuff :P PR review Moved Task out of arch and have the stack init in the arch file Mocking clean up Removed commented code Renamed createTask to scheduleTask where the user will have to provide a task to schedule Removed redundant pub in log runtime test Removed global allocator for scheduler Cleaner assembly in paging Fmt Added new Scheduler test mode Added new test mode to CI Removed one of the prints Added doc comment, task test for i386 Removed test WIP Runtime tests work Have a global set in one task and reacted to in another. Also test that local variables are preserved after a task switch. Removed new lines Increased line length Move the allocation of the bool above the task creation
138 lines
4.5 KiB
Zig
138 lines
4.5 KiB
Zig
const build_options = @import("build_options");
|
|
const std = @import("std");
|
|
const fmt = std.fmt;
|
|
const Serial = @import("serial.zig").Serial;
|
|
const scheduler = @import("scheduler.zig");
|
|
|
|
/// The errors that can occur when logging
|
|
const LoggingError = error{};
|
|
|
|
/// The OutStream for the format function
|
|
const OutStream = std.io.OutStream(void, LoggingError, logCallback);
|
|
|
|
/// The different levels of logging that can be outputted.
|
|
pub const Level = enum {
|
|
INFO,
|
|
DEBUG,
|
|
WARNING,
|
|
ERROR,
|
|
};
|
|
|
|
var serial: Serial = undefined;
|
|
|
|
///
|
|
/// The call back function for the std library format function.
|
|
///
|
|
/// Arguments:
|
|
/// context: void - The context of the printing. There isn't a need for a context for this
|
|
/// so is void.
|
|
/// str: []const u8 - The string to print to the serial terminal.
|
|
///
|
|
/// Return: usize
|
|
/// The number of bytes written. This will always be the length of the string to print.
|
|
///
|
|
/// Error: LoggingError
|
|
/// {} - No error as LoggingError is empty.
|
|
///
|
|
fn logCallback(context: void, str: []const u8) LoggingError!usize {
|
|
serial.writeBytes(str);
|
|
return str.len;
|
|
}
|
|
|
|
///
|
|
/// Write a message to the log output stream with a certain logging level.
|
|
///
|
|
/// Arguments:
|
|
/// IN comptime level: Level - The logging level to use. Determines the message prefix and
|
|
/// whether it is filtered.
|
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
|
/// options.
|
|
/// IN args: anytype - A struct of the parameters for the format string.
|
|
///
|
|
pub fn log(comptime level: Level, comptime format: []const u8, args: anytype) void {
|
|
scheduler.taskSwitching(false);
|
|
fmt.format(OutStream{ .context = {} }, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable;
|
|
scheduler.taskSwitching(true);
|
|
}
|
|
|
|
///
|
|
/// Write a message to the log output stream with the INFO level.
|
|
///
|
|
/// Arguments:
|
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
|
/// options.
|
|
/// IN args: anytype - A struct of the parameters for the format string.
|
|
///
|
|
pub fn logInfo(comptime format: []const u8, args: anytype) void {
|
|
log(Level.INFO, format, args);
|
|
}
|
|
|
|
///
|
|
/// Write a message to the log output stream with the DEBUG level.
|
|
///
|
|
/// Arguments:
|
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
|
/// options.
|
|
/// IN args: anytype - A struct of the parameters for the format string.
|
|
///
|
|
pub fn logDebug(comptime format: []const u8, args: anytype) void {
|
|
log(Level.DEBUG, format, args);
|
|
}
|
|
|
|
///
|
|
/// Write a message to the log output stream with the WARNING level.
|
|
///
|
|
/// Arguments:
|
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
|
/// options.
|
|
/// IN args: anytype - A struct of the parameters for the format string.
|
|
///
|
|
pub fn logWarning(comptime format: []const u8, args: anytype) void {
|
|
log(Level.WARNING, format, args);
|
|
}
|
|
|
|
///
|
|
/// Write a message to the log output stream with the ERROR level.
|
|
///
|
|
/// Arguments:
|
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
|
/// options.
|
|
/// IN args: anytype - A struct of the parameters for the format string.
|
|
///
|
|
pub fn logError(comptime format: []const u8, args: anytype) void {
|
|
log(Level.ERROR, format, args);
|
|
}
|
|
|
|
///
|
|
/// Initialise the logging stream using the given Serial instance.
|
|
///
|
|
/// Arguments:
|
|
/// IN ser: Serial - The serial instance to use when logging
|
|
///
|
|
pub fn init(ser: Serial) void {
|
|
serial = ser;
|
|
|
|
switch (build_options.test_mode) {
|
|
.Initialisation => runtimeTests(),
|
|
else => {},
|
|
}
|
|
}
|
|
|
|
///
|
|
/// The logging runtime tests that will test all logging levels.
|
|
///
|
|
fn runtimeTests() void {
|
|
inline for (@typeInfo(Level).Enum.fields) |field| {
|
|
const level = @field(Level, field.name);
|
|
log(level, "Test " ++ field.name ++ " level\n", .{});
|
|
log(level, "Test " ++ field.name ++ " level with args {}, {}\n", .{ "a", @as(u32, 1) });
|
|
const logFn = switch (level) {
|
|
.INFO => logInfo,
|
|
.DEBUG => logDebug,
|
|
.WARNING => logWarning,
|
|
.ERROR => logError,
|
|
};
|
|
logFn("Test " ++ field.name ++ " function\n", .{});
|
|
logFn("Test " ++ field.name ++ " function with args {}, {}\n", .{ "a", @as(u32, 1) });
|
|
}
|
|
}
|