d600be874c
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
151 lines
5.8 KiB
Zig
151 lines
5.8 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const rt = @import("test/runtime_test.zig");
|
|
const RuntimeStep = rt.RuntimeStep;
|
|
const Builder = std.build.Builder;
|
|
const Target = std.Target;
|
|
const CrossTarget = std.zig.CrossTarget;
|
|
const fs = std.fs;
|
|
const Mode = builtin.Mode;
|
|
const TestMode = rt.TestMode;
|
|
const ArrayList = std.ArrayList;
|
|
|
|
const x86_i686 = CrossTarget{
|
|
.cpu_arch = .i386,
|
|
.os_tag = .freestanding,
|
|
.cpu_model = .{ .explicit = &Target.x86.cpu._i686 },
|
|
};
|
|
|
|
pub fn build(b: *Builder) !void {
|
|
const target = b.standardTargetOptions(.{ .whitelist = &[_]CrossTarget{x86_i686}, .default_target = x86_i686 });
|
|
const arch = switch (target.getCpuArch()) {
|
|
.i386 => "x86",
|
|
else => unreachable,
|
|
};
|
|
|
|
const fmt_step = b.addFmt(&[_][]const u8{
|
|
"build.zig",
|
|
"src",
|
|
"test",
|
|
});
|
|
b.default_step.dependOn(&fmt_step.step);
|
|
|
|
const main_src = "src/kernel/kmain.zig";
|
|
const arch_root = "src/kernel/arch";
|
|
const constants_path = try fs.path.join(b.allocator, &[_][]const u8{ arch_root, arch, "constants.zig" });
|
|
const linker_script_path = try fs.path.join(b.allocator, &[_][]const u8{ arch_root, arch, "link.ld" });
|
|
const output_iso = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "pluto.iso" });
|
|
const iso_dir_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso" });
|
|
const boot_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "boot" });
|
|
const modules_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "modules" });
|
|
|
|
const build_mode = b.standardReleaseOptions();
|
|
comptime var test_mode_desc: []const u8 = "\n ";
|
|
inline for (@typeInfo(TestMode).Enum.fields) |field| {
|
|
const tm = @field(TestMode, field.name);
|
|
test_mode_desc = test_mode_desc ++ field.name ++ " (" ++ TestMode.getDescription(tm) ++ ")";
|
|
test_mode_desc = test_mode_desc ++ "\n ";
|
|
}
|
|
|
|
const test_mode = b.option(TestMode, "test-mode", "Run a specific runtime test. This option is for the rt-test step. Available options: " ++ test_mode_desc) orelse .None;
|
|
const disable_display = b.option(bool, "disable-display", "Disable the qemu window") orelse false;
|
|
|
|
const exec = b.addExecutable("pluto.elf", main_src);
|
|
exec.addPackagePath("constants", constants_path);
|
|
exec.setOutputDir(b.cache_root);
|
|
exec.addBuildOption(TestMode, "test_mode", test_mode);
|
|
exec.setBuildMode(build_mode);
|
|
exec.setLinkerScriptPath(linker_script_path);
|
|
exec.setTarget(target);
|
|
|
|
const make_iso = switch (target.getCpuArch()) {
|
|
.i386 => b.addSystemCommand(&[_][]const u8{ "./makeiso.sh", boot_path, modules_path, iso_dir_path, exec.getOutputPath(), output_iso }),
|
|
else => unreachable,
|
|
};
|
|
make_iso.step.dependOn(&exec.step);
|
|
|
|
b.default_step.dependOn(&make_iso.step);
|
|
|
|
const test_step = b.step("test", "Run tests");
|
|
const mock_path = "\"../../test/mock/kernel/\"";
|
|
const arch_mock_path = "\"../../../../test/mock/kernel/\"";
|
|
const unit_tests = b.addTest(main_src);
|
|
unit_tests.setBuildMode(build_mode);
|
|
unit_tests.setMainPkgPath(".");
|
|
unit_tests.addPackagePath("constants", constants_path);
|
|
unit_tests.addBuildOption(TestMode, "test_mode", test_mode);
|
|
unit_tests.addBuildOption([]const u8, "mock_path", mock_path);
|
|
unit_tests.addBuildOption([]const u8, "arch_mock_path", arch_mock_path);
|
|
|
|
if (builtin.os.tag != .windows) {
|
|
unit_tests.enable_qemu = true;
|
|
}
|
|
|
|
unit_tests.setTarget(.{ .cpu_arch = target.cpu_arch });
|
|
test_step.dependOn(&unit_tests.step);
|
|
|
|
const rt_test_step = b.step("rt-test", "Run runtime tests");
|
|
const build_mode_str = switch (build_mode) {
|
|
.Debug => "",
|
|
.ReleaseSafe => "-Drelease-safe",
|
|
.ReleaseFast => "-Drelease-fast",
|
|
.ReleaseSmall => "-Drelease-small",
|
|
};
|
|
|
|
var qemu_args_al = ArrayList([]const u8).init(b.allocator);
|
|
defer qemu_args_al.deinit();
|
|
|
|
switch (target.getCpuArch()) {
|
|
.i386 => try qemu_args_al.append("qemu-system-i386"),
|
|
else => unreachable,
|
|
}
|
|
try qemu_args_al.append("-serial");
|
|
try qemu_args_al.append("stdio");
|
|
switch (target.getCpuArch()) {
|
|
.i386 => {
|
|
try qemu_args_al.append("-boot");
|
|
try qemu_args_al.append("d");
|
|
try qemu_args_al.append("-cdrom");
|
|
try qemu_args_al.append(output_iso);
|
|
},
|
|
else => unreachable,
|
|
}
|
|
if (disable_display) {
|
|
try qemu_args_al.append("-display");
|
|
try qemu_args_al.append("none");
|
|
}
|
|
|
|
var qemu_args = qemu_args_al.toOwnedSlice();
|
|
|
|
const rt_step = RuntimeStep.create(b, test_mode, qemu_args);
|
|
rt_step.step.dependOn(&make_iso.step);
|
|
rt_test_step.dependOn(&rt_step.step);
|
|
|
|
const run_step = b.step("run", "Run with qemu");
|
|
const run_debug_step = b.step("debug-run", "Run with qemu and wait for a gdb connection");
|
|
|
|
const qemu_cmd = b.addSystemCommand(qemu_args);
|
|
const qemu_debug_cmd = b.addSystemCommand(qemu_args);
|
|
qemu_debug_cmd.addArgs(&[_][]const u8{ "-s", "-S" });
|
|
|
|
qemu_cmd.step.dependOn(&make_iso.step);
|
|
qemu_debug_cmd.step.dependOn(&make_iso.step);
|
|
|
|
run_step.dependOn(&qemu_cmd.step);
|
|
run_debug_step.dependOn(&qemu_debug_cmd.step);
|
|
|
|
const debug_step = b.step("debug", "Debug with gdb and connect to a running qemu instance");
|
|
const symbol_file_arg = try std.mem.join(b.allocator, " ", &[_][]const u8{ "symbol-file", exec.getOutputPath() });
|
|
const debug_cmd = b.addSystemCommand(&[_][]const u8{
|
|
"gdb-multiarch",
|
|
"-ex",
|
|
symbol_file_arg,
|
|
"-ex",
|
|
"set architecture auto",
|
|
});
|
|
debug_cmd.addArgs(&[_][]const u8{
|
|
"-ex",
|
|
"target remote localhost:1234",
|
|
});
|
|
debug_step.dependOn(&debug_cmd.step);
|
|
}
|