From 91923430c498110b4e60b750bf9cb5a17726c4d1 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 18 Aug 2021 22:09:04 +0200 Subject: [PATCH] Headers --- kernel/io.c | 18 +++++++++++++++++- kernel/io.h | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/io.c b/kernel/io.c index 9b630ef..4bdffb8 100644 --- a/kernel/io.c +++ b/kernel/io.c @@ -1,3 +1,4 @@ +// Function to read a byte from port unsigned char port_byte_in(unsigned short port) { unsigned char res; __asm__("in %%dx, %%al" : "=a" (res) : "d" (port)); @@ -5,6 +6,21 @@ unsigned char port_byte_in(unsigned short port) { return res; } +// to write a byte to port void port_byte_out(unsigned short port, unsigned char data) { - + __asm__("out %%al, %%dx" : :"a" (data), "d" (port)); +} + + +// Read word from port +unsigned short port_word_in(unsigned short port) { + unsigned short res; + __asm__("in %%dx, %%ax" : "=a" (res) : "d" (port)); + + return res; +} + +// write word to port +void port_word_out(unsigned short port, unsigned short data) { + __asm__("out %%ax, %%dx" : :"a" (data), "d" (port)); } diff --git a/kernel/io.h b/kernel/io.h index e69de29..87c3e5c 100644 --- a/kernel/io.h +++ b/kernel/io.h @@ -0,0 +1,5 @@ +unsigned char port_byte_in(); +void port_byte_out(); + +unsigned short port_word_in(); +void port_word_out();