From 19d9a04e36e7fb96eebe89e24311408460c29a70 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 30 Sep 2024 11:08:46 -0400 Subject: reorganize files --- portio.hpp | 72 -------------------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 portio.hpp (limited to 'portio.hpp') diff --git a/portio.hpp b/portio.hpp deleted file mode 100644 index 7636c14..0000000 --- a/portio.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef PORTIO_HPP -#define PORTIO_HPP - -#include - -inline void outb(std::uint16_t port, std::uint8_t val) -{ - asm volatile("out %%al, %%dx" :: "a"(val), "Nd"(port) : "memory"); -} - -inline std::uint8_t inb(std::uint16_t port) -{ - std::uint8_t val; - asm volatile("inb %%dx" : "=a"(val) : "Nd"(port) : "memory"); - return val; -} - -inline void outw(std::uint16_t port, std::uint16_t val) -{ - asm volatile("out %%ax, %%dx" :: "a"(val), "Nd"(port) : "memory"); -} - -inline std::uint16_t inw(std::uint16_t port) -{ - std::uint16_t val; - asm volatile("inw %%dx" : "=a"(val) : "Nd"(port) : "memory"); - return val; -} - -inline void io_wait() -{ - outb(0x80, 0); -} - -template -struct Port -{ - Port() = default; - - template - auto operator=(T val) noexcept { - if constexpr (sizeof(T) == 1) - outb(Addr, val); - else if constexpr (sizeof(T) == 2) - outw(Addr, val); - - return *this; - } - - template - operator T() const noexcept { - if constexpr (sizeof(T) == 1) - return inb(Addr); - else if constexpr (sizeof(T) == 2) - return inw(Addr); - } - - template - bool operator==(T val) const noexcept { - T dat = *this; - return dat == val; - } - - template - auto operator&(T val) const noexcept { - T dat = *this; - return dat & val; - } -}; - -#endif // PORTIO_HPP - -- cgit v1.2.3