some cleanup before the rest of the tutorial
This commit is contained in:
parent
9ec23055bc
commit
e30f016977
9 changed files with 32 additions and 17 deletions
2
qemu.sh
2
qemu.sh
|
|
@ -9,7 +9,7 @@ start() {
|
|||
-gdb tcp::${QEMU_GDB_PORT} \
|
||||
-monitor unix:${QEMU_SOCKET},server,nowait \
|
||||
-enable-kvm \
|
||||
-m 1337M \
|
||||
-m 1341M \
|
||||
-curses \
|
||||
-kernel ${KERNEL}
|
||||
# -drive file=disk.img,if=virtio\
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub fn initialize() void {
|
|||
setupPaging(@ptrToInt(&pageDirectory[0])); //asm routine
|
||||
}
|
||||
|
||||
pub fn introspect() void {
|
||||
pub fn format() void {
|
||||
var i: usize = 1;
|
||||
i = 0;
|
||||
while (i < 1024) : (i += 1) {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,6 @@ pub fn initialize(info: *const kernel.multiboot.MultibootInfo) void {
|
|||
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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ var command_len: usize = 0;
|
|||
|
||||
fn execute(input: []u8) void {
|
||||
const eql = std.mem.eql;
|
||||
if (eql(u8, input, "x86paging")) return x86.paging.introspect();
|
||||
if (eql(u8, input, "x86memory")) return x86.pmem.introspect();
|
||||
if (eql(u8, input, "tasks")) return task.introspect();
|
||||
if (eql(u8, input, "clear")) return vga.clear();
|
||||
if (eql(u8, input, "x86paging")) return x86.paging.format();
|
||||
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, "uptime")) return time.uptime();
|
||||
println("{}: command not found", input);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub fn DeltaQueue(comptime T: type) type {
|
|||
///
|
||||
/// Arguments:
|
||||
/// 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| {
|
||||
std.debug.assert(new_node.counter <= after.counter); //sanity check
|
||||
after.counter -= new_node.counter;
|
||||
|
|
@ -38,6 +38,7 @@ pub fn DeltaQueue(comptime T: type) type {
|
|||
}
|
||||
};
|
||||
|
||||
len: usize = 0,
|
||||
first: ?*Node,
|
||||
|
||||
/// Initialize a delta queue.
|
||||
|
|
@ -56,6 +57,8 @@ pub fn DeltaQueue(comptime T: type) type {
|
|||
/// node: Pointer to a node in the list.
|
||||
/// new_node: Pointer to the new node to insert.
|
||||
pub fn insert(list: *Self, node: *Node) void {
|
||||
list.len += 1;
|
||||
|
||||
var target: ?*Node = null;
|
||||
var next: ?*Node = list.first;
|
||||
while (true) {
|
||||
|
|
@ -108,6 +111,7 @@ pub fn DeltaQueue(comptime T: type) type {
|
|||
const first = list.first orelse return null;
|
||||
if (first.counter != 0) return null;
|
||||
list.first = first.next;
|
||||
list.len -= 1;
|
||||
return first;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,9 +42,12 @@ pub const PciDevice = struct {
|
|||
pub fn format(self: PciDevice) void {
|
||||
print("{}:{}.{}", self.bus, self.slot, self.function);
|
||||
print(" {x},{x:2}", self.class(), self.subclass());
|
||||
print(" 0x{x},0x{x}", self.vendor, self.device());
|
||||
if (self.driver()) |d|
|
||||
print(" 0x{x} 0x{x}", self.vendor, self.device());
|
||||
if (self.driver()) |d| {
|
||||
print(" {}", d.name);
|
||||
} else {
|
||||
print(" (none)");
|
||||
}
|
||||
println("");
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +144,7 @@ pub fn scan() void {
|
|||
|
||||
pub fn lspci() void {
|
||||
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) {
|
||||
if (PciDevice.init(0, slot, 0)) |dev| {
|
||||
var function: u3 = 0;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ pub fn new(entrypoint: usize) !void {
|
|||
ready_tasks.prepend(node);
|
||||
}
|
||||
|
||||
// TODO: make a sleep without malloc
|
||||
pub fn usleep(usec: u64) !void {
|
||||
const node = try vmem.create(SleepNode);
|
||||
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();
|
||||
|
||||
println("{}", current_task.data);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ pub fn increment(value: u32) void {
|
|||
pub fn uptime() void {
|
||||
var offset_ms: u64 = offset_us / 1000;
|
||||
const offset_s: u64 = offset_ms / 1000;
|
||||
offset_ms = @mod(offset_ms, 1000);
|
||||
println("{}.{:.3}", offset_s, offset_ms);
|
||||
offset_ms = @mod(offset_ms / 100, 10);
|
||||
print("{}.{:.3}", offset_s, offset_ms);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,20 +65,21 @@ pub fn clear() void {
|
|||
pub fn topbar() void {
|
||||
const bg = vga.background;
|
||||
while (true) {
|
||||
if (time.offset_us / 1000000 == 4) task.usleep(2 * 1000 * 1000) catch unreachable;
|
||||
const cursor = vga.cursor;
|
||||
vga.cursor = 0;
|
||||
vga.background = Color.Red;
|
||||
vga.cursor = 0;
|
||||
vga.cursor_enabled = false;
|
||||
|
||||
time.uptime();
|
||||
print(" | ");
|
||||
task.format_short();
|
||||
println("");
|
||||
|
||||
vga.cursor_enabled = true;
|
||||
vga.cursor = cursor;
|
||||
vga.background = bg;
|
||||
|
||||
task.lock_scheduler();
|
||||
task.schedule();
|
||||
task.usleep(60 * 1000) catch unreachable; // 60ms
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue