diff --git a/src/include/io.h b/src/include/io.h index 0fce831..75d5d97 100644 --- a/src/include/io.h +++ b/src/include/io.h @@ -7,6 +7,10 @@ static inline void outb(uint16_t port, uint8_t value) { __asm__ volatile ("outb %0, %1" : : "a"(value), "Nd"(port)); } +static inline void outw(uint16_t port, uint16_t value) { + __asm__ volatile ("outw %0, %1" : : "a"(value), "Nd"(port)); +} + static inline uint8_t inb(uint16_t port) { uint8_t ret; __asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port)); diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 575ab67..fd21df3 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -2,6 +2,7 @@ #include "../include/colors.h" #include "../include/fetch.h" #include "../include/integer.h" +#include "../include/io.h" #include "../include/log.h" #include "../include/memory.h" #include "../include/mm.h" @@ -94,6 +95,8 @@ static void shell_execute(char *cmd) { terminal_writestring("mmap - print current virtual memory mappings\n"); terminal_writestring("peek - read and print memory at a given hex address\n"); terminal_writestring("echo - repeats your input to the console\n"); + terminal_writestring("reboot - restart the machine\n"); + terminal_writestring("exit. - shut the machine down (QEMU/Bochs)\n"); terminal_writestring("crash - make the machine freeze (fun cmd)\n\n"); } else if (strcmp(cmd_name, "clear") == 0) { @@ -144,6 +147,19 @@ static void shell_execute(char *cmd) { for (;;) asm volatile("hlt"); } + else if (strcmp(cmd_name, "reboot") == 0) { + terminal_writestring("Rebooting...\n"); + while (inb(0x64) & 0x02) + ; + outb(0x64, 0xFE); + asm volatile("cli; hlt"); + } + else if (strcmp(cmd_name, "exit") == 0) { + terminal_writestring("Powering off...\n"); + outw(0x604, 0x2000); + outw(0xB004, 0x2000); + asm volatile("cli; hlt"); + } else if (strcmp(cmd_name, "uptime") == 0) { uint32_t ticks = get_tick(); uint32_t total_seconds = ticks / 1000;