some cleanup before the rest of the tutorial

This commit is contained in:
Jack Halford 2019-12-15 19:25:01 +01:00
parent 9ec23055bc
commit e30f016977
9 changed files with 32 additions and 17 deletions

View file

@ -9,7 +9,7 @@ start() {
-gdb tcp::${QEMU_GDB_PORT} \ -gdb tcp::${QEMU_GDB_PORT} \
-monitor unix:${QEMU_SOCKET},server,nowait \ -monitor unix:${QEMU_SOCKET},server,nowait \
-enable-kvm \ -enable-kvm \
-m 1337M \ -m 1341M \
-curses \ -curses \
-kernel ${KERNEL} -kernel ${KERNEL}
# -drive file=disk.img,if=virtio\ # -drive file=disk.img,if=virtio\

View file

@ -68,7 +68,7 @@ pub fn initialize() void {
setupPaging(@ptrToInt(&pageDirectory[0])); //asm routine setupPaging(@ptrToInt(&pageDirectory[0])); //asm routine
} }
pub fn introspect() void { pub fn format() void {
var i: usize = 1; var i: usize = 1;
i = 0; i = 0;
while (i < 1024) : (i += 1) { while (i < 1024) : (i += 1) {

View file

@ -88,6 +88,6 @@ pub fn initialize(info: *const kernel.multiboot.MultibootInfo) void {
kernel.println("available memory: {d} MiB ", available() / 1024 / 1024); kernel.println("available memory: {d} MiB ", available() / 1024 / 1024);
} }
pub fn introspect() void { pub fn format() void {
kernel.println("physframes left: {d} ({d} MiB)", stack_index, available_MiB()); kernel.println("physframes left: {d} ({d} MiB)", stack_index, available_MiB());
} }

View file

@ -10,9 +10,11 @@ var command_len: usize = 0;
fn execute(input: []u8) void { fn execute(input: []u8) void {
const eql = std.mem.eql; const eql = std.mem.eql;
if (eql(u8, input, "x86paging")) return x86.paging.introspect(); if (eql(u8, input, "clear")) return vga.clear();
if (eql(u8, input, "x86memory")) return x86.pmem.introspect(); if (eql(u8, input, "x86paging")) return x86.paging.format();
if (eql(u8, input, "tasks")) return task.introspect(); if (eql(u8, input, "x86memory")) return x86.pmem.format();
if (eql(u8, input, "tasks")) return task.format();
if (eql(u8, input, "tasks")) return task.format_short();
if (eql(u8, input, "lspci")) return pci.lspci(); if (eql(u8, input, "lspci")) return pci.lspci();
if (eql(u8, input, "uptime")) return time.uptime(); if (eql(u8, input, "uptime")) return time.uptime();
println("{}: command not found", input); println("{}: command not found", input);

View file

@ -28,7 +28,7 @@ pub fn DeltaQueue(comptime T: type) type {
/// ///
/// Arguments: /// Arguments:
/// new_node: Pointer to the new node to insert. /// new_node: Pointer to the new node to insert.
pub fn insertAfter(node: *Node, new_node: *Node) void { fn insertAfter(node: *Node, new_node: *Node) void {
if (node.next) |after| { if (node.next) |after| {
std.debug.assert(new_node.counter <= after.counter); //sanity check std.debug.assert(new_node.counter <= after.counter); //sanity check
after.counter -= new_node.counter; after.counter -= new_node.counter;
@ -38,6 +38,7 @@ pub fn DeltaQueue(comptime T: type) type {
} }
}; };
len: usize = 0,
first: ?*Node, first: ?*Node,
/// Initialize a delta queue. /// Initialize a delta queue.
@ -56,6 +57,8 @@ pub fn DeltaQueue(comptime T: type) type {
/// node: Pointer to a node in the list. /// node: Pointer to a node in the list.
/// new_node: Pointer to the new node to insert. /// new_node: Pointer to the new node to insert.
pub fn insert(list: *Self, node: *Node) void { pub fn insert(list: *Self, node: *Node) void {
list.len += 1;
var target: ?*Node = null; var target: ?*Node = null;
var next: ?*Node = list.first; var next: ?*Node = list.first;
while (true) { while (true) {
@ -108,6 +111,7 @@ pub fn DeltaQueue(comptime T: type) type {
const first = list.first orelse return null; const first = list.first orelse return null;
if (first.counter != 0) return null; if (first.counter != 0) return null;
list.first = first.next; list.first = first.next;
list.len -= 1;
return first; return first;
} }

View file

@ -42,9 +42,12 @@ pub const PciDevice = struct {
pub fn format(self: PciDevice) void { pub fn format(self: PciDevice) void {
print("{}:{}.{}", self.bus, self.slot, self.function); print("{}:{}.{}", self.bus, self.slot, self.function);
print(" {x},{x:2}", self.class(), self.subclass()); print(" {x},{x:2}", self.class(), self.subclass());
print(" 0x{x},0x{x}", self.vendor, self.device()); print(" 0x{x} 0x{x}", self.vendor, self.device());
if (self.driver()) |d| if (self.driver()) |d| {
print(" {}", d.name); print(" {}", d.name);
} else {
print(" (none)");
}
println(""); println("");
} }
@ -141,7 +144,7 @@ pub fn scan() void {
pub fn lspci() void { pub fn lspci() void {
var slot: u5 = 0; var slot: u5 = 0;
println("b:s.f c, s v d drv"); println("b:s.f c, s vendor device driver");
while (slot < 31) : (slot += 1) { while (slot < 31) : (slot += 1) {
if (PciDevice.init(0, slot, 0)) |dev| { if (PciDevice.init(0, slot, 0)) |dev| {
var function: u3 = 0; var function: u3 = 0;

View file

@ -73,6 +73,7 @@ pub fn new(entrypoint: usize) !void {
ready_tasks.prepend(node); ready_tasks.prepend(node);
} }
// TODO: make a sleep without malloc
pub fn usleep(usec: u64) !void { pub fn usleep(usec: u64) !void {
const node = try vmem.create(SleepNode); const node = try vmem.create(SleepNode);
lock_scheduler(); lock_scheduler();
@ -163,7 +164,11 @@ pub fn unlock_scheduler() void {
} }
} }
pub fn introspect() void { pub fn format_short() void {
print("{}R {}B {}S", ready_tasks.len, blocked_tasks.len, sleeping_tasks.len);
}
pub fn format() void {
update_time_used(); update_time_used();
println("{}", current_task.data); println("{}", current_task.data);

View file

@ -8,6 +8,6 @@ pub fn increment(value: u32) void {
pub fn uptime() void { pub fn uptime() void {
var offset_ms: u64 = offset_us / 1000; var offset_ms: u64 = offset_us / 1000;
const offset_s: u64 = offset_ms / 1000; const offset_s: u64 = offset_ms / 1000;
offset_ms = @mod(offset_ms, 1000); offset_ms = @mod(offset_ms / 100, 10);
println("{}.{:.3}", offset_s, offset_ms); print("{}.{:.3}", offset_s, offset_ms);
} }

View file

@ -65,20 +65,21 @@ pub fn clear() void {
pub fn topbar() void { pub fn topbar() void {
const bg = vga.background; const bg = vga.background;
while (true) { while (true) {
if (time.offset_us / 1000000 == 4) task.usleep(2 * 1000 * 1000) catch unreachable;
const cursor = vga.cursor; const cursor = vga.cursor;
vga.cursor = 0;
vga.background = Color.Red; vga.background = Color.Red;
vga.cursor = 0;
vga.cursor_enabled = false; vga.cursor_enabled = false;
time.uptime(); time.uptime();
print(" | ");
task.format_short();
println("");
vga.cursor_enabled = true; vga.cursor_enabled = true;
vga.cursor = cursor; vga.cursor = cursor;
vga.background = bg; vga.background = bg;
task.lock_scheduler(); task.usleep(60 * 1000) catch unreachable; // 60ms
task.schedule();
} }
} }