From 7a07b4a4398e02aead731b0c38af143d6a2fe41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 4 Nov 2015 13:41:10 +0100 Subject: add io_ports --- kernel/Makefile | 4 ++-- kernel/io_ports.asm | 28 ++++++++++++++++++++++++++++ kernel/io_ports.h | 7 +++++++ kernel/kernel.c | 18 ++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 kernel/io_ports.asm create mode 100644 kernel/io_ports.h 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"); } -- cgit v1.1-2-g2b99