summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile4
-rw-r--r--kernel/io_ports.asm28
-rw-r--r--kernel/io_ports.h7
-rw-r--r--kernel/kernel.c18
4 files changed, 55 insertions, 2 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 431c01a..ebaf3c5 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -1,7 +1,7 @@
all: kernel.elf
-OBJS=entry.o stdlib.o tty.o
-HEADERS=stdlib.h tty.h
+OBJS=entry.o stdlib.o tty.o io_ports.o
+HEADERS=stdlib.h tty.h io_ports.h
.SUFFIXES: .asm
diff --git a/kernel/io_ports.asm b/kernel/io_ports.asm
new file mode 100644
index 0000000..9ab47d9
--- /dev/null
+++ b/kernel/io_ports.asm
@@ -0,0 +1,28 @@
+SECTION .text
+global outw
+global inw
+
+outw:
+ push ebp;
+ mov ebp,esp
+
+ mov dx, [ebp+8] ; port
+ mov ax, [ebp+12] ; data
+ out dx, ax
+
+ mov esp,ebp
+ pop ebp
+ ret
+
+
+inw:
+ push ebp;
+ mov ebp,esp
+
+ mov dx, [ebp+8] ; port
+ in eax, dx
+
+ mov esp,ebp
+ pop ebp
+ ret
+
diff --git a/kernel/io_ports.h b/kernel/io_ports.h
new file mode 100644
index 0000000..e6ee7d3
--- /dev/null
+++ b/kernel/io_ports.h
@@ -0,0 +1,7 @@
+#ifndef _IO_PORTS_H_
+#define _IO_PORTS_H_
+
+void outw(uint16_t port, uint16_t data);
+uint16_t inw(uint16_t port);
+
+#endif
diff --git a/kernel/kernel.c b/kernel/kernel.c
index d81c8a7..6b7f077 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,5 +1,6 @@
#include "tty.h"
#include "stdlib.h"
+#include "io_ports.h"
/* this only work for the 32-bit ix86 targets. */
#if !defined(__i386__)
@@ -34,5 +35,22 @@ void kernel_main()
test(strncmp("abc", "abc", 8) == 0);
test(strncmp("abca", "abcb", 3) == 0);
+
+ tty_puts("inw : ");
+ while(true) {
+ int ret = inw(0x03F8);
+ if (ret == 97) {
+ tty_puts(" ok\n");
+ break;
+ }
+ }
+ tty_puts("outw :\n");
+ outw(0x03F8, 'h');
+ outw(0x03F8, 'e');
+ outw(0x03F8, 'l');
+ outw(0x03F8, 'l');
+ outw(0x03F8, 'o');
+ outw(0x03F8, '\0');
+
tty_puts("done.\n");
}