From ffd82e18b5259fab477ad375a7af8550fac526d8 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Thu, 19 Sep 2019 19:01:53 +0200
Subject: Added reboot feature

---
 src/commands/command.c |  2 ++
 src/io/io.asm          |  1 -
 src/io/io.c            | 12 ++++++++++++
 src/io/io.h            |  2 ++
 4 files changed, 16 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/commands/command.c b/src/commands/command.c
index eeac08e..9cbcb07 100644
--- a/src/commands/command.c
+++ b/src/commands/command.c
@@ -19,6 +19,8 @@ void exec_command(char *command) {
         terminal_write_line("pong!");
     else if (starts_with(command, "shutdown"))
         shutdown();
+    else if (starts_with(command, "reboot"))
+        reboot();
     else
         terminal_write_line("Command not found!");
 }
diff --git a/src/io/io.asm b/src/io/io.asm
index 6776c56..6ab3707 100644
--- a/src/io/io.asm
+++ b/src/io/io.asm
@@ -7,5 +7,4 @@ shutdown:
   mov bx, 0x0001
   mov cx, 0x0003
   int 0x15
-
   ret
\ No newline at end of file
diff --git a/src/io/io.c b/src/io/io.c
index 2f42d04..7bddb13 100644
--- a/src/io/io.c
+++ b/src/io/io.c
@@ -1,3 +1,5 @@
+#include <stdint.h>
+
 unsigned char receive(unsigned short port) {
     unsigned char value;
     __asm__ __volatile__ ("inb %1, %0" : "=a" (value) : "dN" (port));
@@ -7,3 +9,13 @@ unsigned char receive(unsigned short port) {
 void send(unsigned short port, unsigned char data) {
     __asm__ __volatile__ ("outb %1, %0" : : "dN" (port), "a" (data));
 }
+
+void reboot() {
+    uint8_t good = 0x02;
+    while (good & 0x02)
+        good = receive(0x64);
+    send(0x64, 0xFE);
+    loop:
+    asm volatile ("hlt");
+    goto loop;
+}
\ No newline at end of file
diff --git a/src/io/io.h b/src/io/io.h
index 41042c3..e00a5f0 100644
--- a/src/io/io.h
+++ b/src/io/io.h
@@ -7,4 +7,6 @@ unsigned char receive(unsigned short port);
 
 void send(unsigned short port, unsigned char data);
 
+void reboot();
+
 #endif
-- 
cgit v1.2.3