console: refactor to print available commands
This commit is contained in:
parent
c3dcb449cb
commit
b1c76c405b
2 changed files with 25 additions and 15 deletions
|
|
@ -5,24 +5,34 @@ var input_ring: Ring(u8) = undefined;
|
|||
var command: [10]u8 = undefined;
|
||||
var command_len: usize = 0;
|
||||
|
||||
fn sleep_for_2() void {
|
||||
fn sleep2() void {
|
||||
task.usleep(2 * 1000 * 1000) catch unreachable;
|
||||
}
|
||||
|
||||
fn t_sleep2() void {
|
||||
_ = task.new(@ptrToInt(sleep2)) catch unreachable;
|
||||
}
|
||||
|
||||
const Command = struct {
|
||||
name: []const u8,
|
||||
f: fn () void,
|
||||
};
|
||||
|
||||
const commands = [_]Command{
|
||||
Command{ .name = "clear", .f = clear },
|
||||
Command{ .name = "paging", .f = x86.paging.format },
|
||||
Command{ .name = "memory", .f = x86.pmem.format },
|
||||
Command{ .name = "tasks", .f = task.format },
|
||||
Command{ .name = "lspci", .f = pci.lspci },
|
||||
Command{ .name = "sleep2", .f = sleep2 },
|
||||
Command{ .name = "t-sleep2", .f = t_sleep2 },
|
||||
Command{ .name = "uptime", .f = time.uptime },
|
||||
};
|
||||
|
||||
fn execute(input: []u8) void {
|
||||
const eql = std.mem.eql;
|
||||
if (eql(u8, input, "clear")) return vga.clear();
|
||||
if (eql(u8, input, "paging")) return x86.paging.format();
|
||||
if (eql(u8, input, "memory")) return x86.pmem.format();
|
||||
if (eql(u8, input, "tasks")) return task.format();
|
||||
if (eql(u8, input, "lspci")) return pci.lspci();
|
||||
if (eql(u8, input, "sleep2")) return sleep_for_2();
|
||||
if (eql(u8, input, "t-sleep2")) {
|
||||
_ = task.new(@ptrToInt(sleep_for_2)) catch unreachable;
|
||||
return;
|
||||
}
|
||||
if (eql(u8, input, "uptime")) return time.uptime();
|
||||
println("{}: command not found", input);
|
||||
for (commands) |c| if (std.mem.eql(u8, input, c.name)) return c.f();
|
||||
println("{}: command not found, list of available commands:", input);
|
||||
for (commands) |c| println("{}", c.name);
|
||||
}
|
||||
|
||||
pub fn keypress(char: u8) void {
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ const Driver = struct {
|
|||
init: fn (PciDevice) void,
|
||||
};
|
||||
|
||||
pub var Drivers = [_]Driver{
|
||||
const Drivers = [_]Driver{
|
||||
Driver{ .name = "virtio-blk", .class = 0x1, .subclass = 0x0, .vendor = 0x1af4, .subsystem = 0x2, .init = virtio.init },
|
||||
Driver{ .name = "ide-ata", .class = 0x1, .subclass = 0x1, .init = ide.init },
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue