81 lines
3.0 KiB
C++

#pragma once
#if !defined(BAD_APPLE_OS_PORT_HPP_INCLUDED)
#define BAD_APPLE_OS_PORT_HPP_INCLUDED
#include <cstdint>
#define writePort8(port, value) \
{ \
__asm__ __volatile__( \
"outb %0, %1" \
: \
: "a"(static_cast<std::uint8_t>(value)), \
"Nd"(static_cast<std::uint16_t>(port)) \
); \
}
#define readPort8(port) \
[&]() \
{ \
std::uint8_t value = 0; \
__asm__ __volatile__( \
"inb %1, %0" \
: "=a"(value) \
: "Nd"(static_cast<std::uint16_t>(port)) \
); \
return value; \
}()
#define writePort16(port, value) \
{ \
__asm__ __volatile__( \
"outw %0, %1" \
: \
: "a"(static_cast<std::uint16_t>(value)), \
"Nd"(static_cast<std::uint16_t>(port)) \
); \
}
#define readPort16(port) \
[&]() \
{ \
std::uint16_t value = 0; \
__asm__ __volatile__( \
"inw %1, %0" \
: "=a"(value) \
: "Nd"(static_cast<std::uint16_t>(port)) \
); \
return value; \
}()
#define writePort32(port, value) \
{ \
__asm__ __volatile__( \
"outl %0, %1" \
: \
: "a"(static_cast<std::uint32_t>(value)), \
"Nd"(static_cast<std::uint16_t>(port)) \
); \
}
#define readPort32(port) \
[&]() \
{ \
std::uint32_t value = 0; \
__asm__ __volatile__( \
"inl %1, %0" \
: "=a"(value) \
: "Nd"(static_cast<std::uint32_t>(port)) \
); \
return value; \
}()
inline void ioWait() noexcept
{
writePort8(0x80, 0);
}
#endif // !defined(BAD_APPLE_OS_PORT_HPP_INCLUDED)