Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/include/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
16 changes: 16 additions & 0 deletions src/kernel/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Loading