From b46ca321097dfc6c0ecfa67f0eb7cc1ccfcd8981 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 6 Aug 2021 10:42:43 +0200 Subject: [PATCH] lib: add IO port read/write helper functions Add 16bit and 32bit IN helper. Add 32bit OUT helper. Signed-off-by: Pawel Wieczorkiewicz --- include/lib.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/lib.h b/include/lib.h index 7438acb5..782bd0ad 100644 --- a/include/lib.h +++ b/include/lib.h @@ -332,6 +332,22 @@ static inline uint8_t inb(io_port_t port) { return value; } +static inline uint16_t inw(io_port_t port) { + uint16_t value; + + asm volatile("inw %1, %0" : "=a"(value) : "Nd"(port)); + + return value; +} + +static inline uint32_t ind(io_port_t port) { + uint32_t value; + + asm volatile("in %1, %0" : "=a"(value) : "Nd"(port)); + + return value; +} + static inline void outb(io_port_t port, uint8_t value) { asm volatile("outb %0, %1" ::"a"(value), "Nd"(port)); } @@ -340,6 +356,10 @@ static inline void outw(io_port_t port, uint16_t value) { asm volatile("outw %0, %1" ::"a"(value), "Nd"(port)); } +static inline void outd(io_port_t port, uint32_t value) { + asm volatile("out %0, %1" ::"a"(value), "Nd"(port)); +} + static inline void putc(io_port_t port, int c) { outb(port, c); } static inline void puts(io_port_t port, const char *buf, size_t len) {