aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/io
diff options
context:
space:
mode:
authorMarvin Borner2019-09-19 19:56:59 +0200
committerMarvin Borner2019-09-19 20:05:38 +0200
commit05e1fedcc9cd30d1a34a65e640da45e980b4f859 (patch)
tree9cfb7620907ac126f26cdfe9363cb73ed74ea179 /src/kernel/io
parentffd82e18b5259fab477ad375a7af8550fac526d8 (diff)
Moved source to kernel directory
Diffstat (limited to 'src/kernel/io')
-rw-r--r--src/kernel/io/io.asm10
-rw-r--r--src/kernel/io/io.c21
-rw-r--r--src/kernel/io/io.h12
3 files changed, 43 insertions, 0 deletions
diff --git a/src/kernel/io/io.asm b/src/kernel/io/io.asm
new file mode 100644
index 0000000..6ab3707
--- /dev/null
+++ b/src/kernel/io/io.asm
@@ -0,0 +1,10 @@
+global shutdown
+shutdown:
+ mov ax, 0x1000
+ mov ax, ss
+ mov sp, 0xf000
+ mov ax, 0x5307
+ mov bx, 0x0001
+ mov cx, 0x0003
+ int 0x15
+ ret \ No newline at end of file
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c
new file mode 100644
index 0000000..7bddb13
--- /dev/null
+++ b/src/kernel/io/io.c
@@ -0,0 +1,21 @@
+#include <stdint.h>
+
+unsigned char receive(unsigned short port) {
+ unsigned char value;
+ __asm__ __volatile__ ("inb %1, %0" : "=a" (value) : "dN" (port));
+ return value;
+}
+
+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/kernel/io/io.h b/src/kernel/io/io.h
new file mode 100644
index 0000000..e00a5f0
--- /dev/null
+++ b/src/kernel/io/io.h
@@ -0,0 +1,12 @@
+#ifndef MELVIX_IO_H
+#define MELVIX_IO_H
+
+#include <stdint.h>
+
+unsigned char receive(unsigned short port);
+
+void send(unsigned short port, unsigned char data);
+
+void reboot();
+
+#endif