Add user mode

This commit is contained in:
Sam Tebbs 2020-07-24 00:18:56 +01:00
parent fee4b27f14
commit 307ea7a52e
17 changed files with 612 additions and 126 deletions

View file

@ -49,6 +49,7 @@ const types = .{
.{ "*const IdtPtr", "PTR_CONST_IDTPTR", "idt_mock", "", "IdtPtr" },
.{ "*Task", "PTR_TASK", "task_mock", "", "Task" },
.{ "*Allocator", "PTR_ALLOCATOR", "", "std.mem", "Allocator" },
.{ "*VirtualMemoryManager(u8)", "PTR_VMM", "vmm_mock", "", "VirtualMemoryManager" },
.{ "IdtError!void", "ERROR_IDTERROR_RET_VOID", "idt_mock", "", "IdtError" },
.{ "Allocator.Error!*Task", "ERROR_ALLOCATOR_RET_PTRTASK", "", "", "" },
@ -82,6 +83,7 @@ const types = .{
.{ "fn (*Task, usize) void", "FN_IPTRTASK_IUSIZE_OVOID", "", "", "" },
.{ "fn (*Task, *Allocator) void", "FN_IPTRTASK_IPTRALLOCATOR_OVOID", "", "", "" },
.{ "fn (fn () void, *Allocator) Allocator.Error!*Task", "FN_IFNOVOID_IPTRALLOCATOR_EALLOCATOR_OPTRTASK", "", "", "" },
.{ "fn (usize, *Allocator, bool, *VirtualMemoryManager(u8)) Allocator.Error!*Task", "FN_IUSIZE_IPTRALLOCATOR_IBOOL_IVMM_EALLOCATOR_OVOID", "", "", "" },
.{ "fn (StatusRegister, u8, bool) void", "FN_ISTATUSREGISTER_IU8_IBOOL_OVOID", "", "", "" },
};

View file

@ -11,7 +11,7 @@ const Serial = @import("../../../src/kernel/serial.zig").Serial;
const TTY = @import("../../../src/kernel/tty.zig").TTY;
const Keyboard = @import("../../../src/kernel/keyboard.zig").Keyboard;
pub const task = @import("task_mock.zig");
pub const task = @import("../../../src/kernel/task.zig");
pub const Device = pci.PciDeviceInfo;
@ -141,10 +141,7 @@ pub fn initMem(payload: BootPayload) Allocator.Error!mem.MemProfile {
};
}
pub fn initTaskStack(entry_point: usize, allocator: *Allocator) Allocator.Error!struct { stack: []u32, pointer: usize } {
const ret = .{ .stack = &([_]u32{}), .pointer = 0 };
return ret;
}
pub fn initTask(t: *Task, entry_point: usize, allocator: *Allocator) Allocator.Error!void {}
pub fn initKeyboard(allocator: *Allocator) Allocator.Error!?*Keyboard {
return null;

View file

@ -146,6 +146,7 @@ fn Mock() type {
1 => fn (fields[0].field_type) RetType,
2 => fn (fields[0].field_type, fields[1].field_type) RetType,
3 => fn (fields[0].field_type, fields[1].field_type, fields[2].field_type) RetType,
4 => fn (fields[0].field_type, fields[1].field_type, fields[2].field_type, fields[3].field_type) RetType,
else => @compileError("More than 3 parameters not supported"),
};
}
@ -167,6 +168,7 @@ fn Mock() type {
1 => function_type(params[0]),
2 => function_type(params[0], params[1]),
3 => function_type(params[0], params[1], params[2]),
4 => function_type(params[0], params[1], params[2], params[3]),
// Should get to this as `getFunctionType` will catch this
else => @compileError("More than 3 parameters not supported"),
};

View file

@ -1,4 +1,6 @@
const std = @import("std");
const vmm = @import("vmm_mock.zig");
const arch = @import("arch_mock.zig");
const Allocator = std.mem.Allocator;
const mock_framework = @import("mock_framework.zig");
@ -8,17 +10,20 @@ pub const addTestParams = mock_framework.addTestParams;
pub const addConsumeFunction = mock_framework.addConsumeFunction;
pub const addRepeatFunction = mock_framework.addRepeatFunction;
const EntryPointFn = fn () void;
pub const EntryPoint = usize;
pub const Task = struct {
const Self = @This();
pid: u32,
stack: []u32,
kernel_stack: []u32,
user_stack: []u32,
stack_pointer: usize,
kernel: bool,
vmm: vmm.VirtualMemoryManager(arch.VmmPayload),
pub fn create(entry_point: EntryPointFn, allocator: *Allocator) Allocator.Error!*Task {
return mock_framework.performAction("Task.create", Allocator.Error!*Task, .{ entry_point, allocator });
pub fn create(entry_point: EntryPoint, kernel: bool, task_vmm: *vmm.VirtualMemoryManager(arch.VmmPayload), allocator: *Allocator) Allocator.Error!*Task {
return mock_framework.performAction("Task.create", Allocator.Error!*Task, .{ entry_point, allocator, kernel, task_vmm });
}
pub fn destroy(self: *Self, allocator: *Allocator) void {

View file

@ -3,6 +3,7 @@ const bitmap = @import("../../../src/kernel/bitmap.zig");
const vmm = @import("../../../src/kernel/vmm.zig");
const arch = @import("arch_mock.zig");
const std = @import("std");
const Allocator = std.mem.Allocator;
pub const VmmError = error{
/// A memory region expected to be allocated wasn't
@ -45,9 +46,11 @@ pub fn VirtualMemoryManager(comptime Payload: type) type {
pub fn free(self: *Self, vaddr: usize) (bitmap.Bitmap(u32).BitmapError || VmmError)!void {
return VmmError.NotAllocated;
}
pub fn copyDataToVMM(self: *Self, to: *const Self, data: []const u8, dest: usize) (bitmap.Bitmap(usize).BitmapError || VmmError || Allocator.Error)!void {}
};
}
pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) std.mem.Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {
pub fn init(mem_profile: *const mem.MemProfile, allocator: *Allocator) Allocator.Error!*VirtualMemoryManager(arch.VmmPayload) {
return std.mem.Allocator.Error.OutOfMemory;
}

6
test/user_program.s Normal file
View file

@ -0,0 +1,6 @@
entry:
mov $0xCAFE, %eax
mov $0xBEEF, %ebx
loop:
jmp loop