7 * This file contains the definitions for the x86 IO instructions
8 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
9 * (insb/insw/insl/outsb/outsw/outsl).
11 #if defined(__ROMCC__)
12 static inline void outb(uint8_t value, uint16_t port)
14 __builtin_outb(value, port);
17 static inline void outw(uint16_t value, uint16_t port)
19 __builtin_outw(value, port);
22 static inline void outl(uint32_t value, uint16_t port)
24 __builtin_outl(value, port);
28 static inline uint8_t inb(uint16_t port)
30 return __builtin_inb(port);
34 static inline uint16_t inw(uint16_t port)
36 return __builtin_inw(port);
39 static inline uint32_t inl(uint16_t port)
41 return __builtin_inl(port);
44 static inline void outb(uint8_t value, uint16_t port)
46 __asm__ __volatile__ ("outb %b0, %w1" : : "a" (value), "Nd" (port));
49 static inline void outw(uint16_t value, uint16_t port)
51 __asm__ __volatile__ ("outw %w0, %w1" : : "a" (value), "Nd" (port));
54 static inline void outl(uint32_t value, uint16_t port)
56 __asm__ __volatile__ ("outl %0, %w1" : : "a" (value), "Nd" (port));
59 static inline uint8_t inb(uint16_t port)
62 __asm__ __volatile__ ("inb %w1, %b0" : "=a"(value) : "Nd" (port));
66 static inline uint16_t inw(uint16_t port)
69 __asm__ __volatile__ ("inw %w1, %w0" : "=a"(value) : "Nd" (port));
73 static inline uint32_t inl(uint16_t port)
76 __asm__ __volatile__ ("inl %w1, %0" : "=a"(value) : "Nd" (port));
79 #endif /* __ROMCC__ */
81 static inline void outsb(uint16_t port, const void *addr, unsigned long count)
83 __asm__ __volatile__ (
85 : "=S" (addr), "=c" (count)
86 : "d"(port), "0"(addr), "1" (count)
90 static inline void outsw(uint16_t port, const void *addr, unsigned long count)
92 __asm__ __volatile__ (
94 : "=S" (addr), "=c" (count)
95 : "d"(port), "0"(addr), "1" (count)
99 static inline void outsl(uint16_t port, const void *addr, unsigned long count)
101 __asm__ __volatile__ (
103 : "=S" (addr), "=c" (count)
104 : "d"(port), "0"(addr), "1" (count)
109 static inline void insb(uint16_t port, void *addr, unsigned long count)
111 __asm__ __volatile__ (
113 : "=D" (addr), "=c" (count)
114 : "d"(port), "0"(addr), "1" (count)
118 static inline void insw(uint16_t port, void *addr, unsigned long count)
120 __asm__ __volatile__ (
122 : "=D" (addr), "=c" (count)
123 : "d"(port), "0"(addr), "1" (count)
127 static inline void insl(uint16_t port, void *addr, unsigned long count)
129 __asm__ __volatile__ (
131 : "=D" (addr), "=c" (count)
132 : "d"(port), "0"(addr), "1" (count)
136 static inline __attribute__((always_inline)) uint8_t read8(unsigned long addr)
138 return *((volatile uint8_t *)(addr));
141 static inline __attribute__((always_inline)) uint16_t read16(unsigned long addr)
143 return *((volatile uint16_t *)(addr));
146 static inline __attribute__((always_inline)) uint32_t read32(unsigned long addr)
148 return *((volatile uint32_t *)(addr));
151 static inline __attribute__((always_inline)) void write8(unsigned long addr, uint8_t value)
153 *((volatile uint8_t *)(addr)) = value;
156 static inline __attribute__((always_inline)) void write16(unsigned long addr, uint16_t value)
158 *((volatile uint16_t *)(addr)) = value;
161 static inline __attribute__((always_inline)) void write32(unsigned long addr, uint32_t value)
163 *((volatile uint32_t *)(addr)) = value;