diff options
Diffstat (limited to 'include/device/portio.h')
-rw-r--r-- | include/device/portio.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/device/portio.h b/include/device/portio.h new file mode 100644 index 0000000..76b28c4 --- /dev/null +++ b/include/device/portio.h @@ -0,0 +1,26 @@ +#ifndef _JOVE_PORTIO_H +#define _JOVE_PORTIO_H 1 + +#include <stdint.h> + +typedef uint16_t ioport_t; + +static inline uint8_t port_inb(ioport_t port) +{ uint8_t r; __asm__ volatile("inb %w1, %b0": "=a"(r): "Nd"(port): "memory"); return r; } + +static inline uint16_t port_inw(ioport_t port) +{ uint16_t r; __asm__ volatile("inw %w1, %w0": "=a"(r): "Nd"(port): "memory"); return r; } + +static inline uint32_t port_inl(ioport_t port) +{ uint32_t r; __asm__ volatile("inl %d1, %l0": "=a"(r): "Nd"(port): "memory"); return r; } + +static inline void port_outb(ioport_t port, uint8_t v) +{ __asm__ volatile("outb %b0, %w1":: "a"(v), "Nd"(port): "memory"); } + +static inline void port_outw(ioport_t port, uint16_t v) +{ __asm__ volatile("outb %w0, %w1":: "a"(v), "Nd"(port): "memory"); } + +static inline void port_outl(ioport_t port, uint32_t v) +{ __asm__ volatile("outb %d0, %w1":: "a"(v), "Nd"(port): "memory"); } + +#endif |