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). You can also use "pausing"
10 * versions of the single-IO instructions (inb_p/inw_p/..).
12 #if defined(__ROMCC__)
13 static inline void outb(uint8_t value, uint16_t port)
15 __builtin_outb(value, port);
18 static inline void outw(uint16_t value, uint16_t port)
20 __builtin_outw(value, port);
23 static inline void outl(uint32_t value, uint16_t port)
25 __builtin_outl(value, port);
29 static inline uint8_t inb(uint16_t port)
31 return __builtin_inb(port);
35 static inline uint16_t inw(uint16_t port)
37 return __builtin_inw(port);
40 static inline uint32_t inl(uint16_t port)
42 return __builtin_inl(port);
45 static inline void outb(uint8_t value, uint16_t port)
47 __asm__ __volatile__ ("outb %b0, %w1" : : "a" (value), "Nd" (port));
50 static inline void outw(uint16_t value, uint16_t port)
52 __asm__ __volatile__ ("outw %w0, %w1" : : "a" (value), "Nd" (port));
55 static inline void outl(uint32_t value, uint16_t port)
57 __asm__ __volatile__ ("outl %0, %w1" : : "a" (value), "Nd" (port));
60 static inline uint8_t inb(uint16_t port)
63 __asm__ __volatile__ ("inb %w1, %b0" : "=a"(value) : "Nd" (port));
67 static inline uint16_t inw(uint16_t port)
70 __asm__ __volatile__ ("inw %w1, %w0" : "=a"(value) : "Nd" (port));
74 static inline uint32_t inl(uint16_t port)
77 __asm__ __volatile__ ("inl %w1, %0" : "=a"(value) : "Nd" (port));
80 #endif /* __ROMCC__ */
82 static inline void outsb(uint16_t port, const void *addr, unsigned long count)
84 __asm__ __volatile__ (
86 : "=S" (addr), "=c" (count)
87 : "d"(port), "0"(addr), "1" (count)
91 static inline void outsw(uint16_t port, const void *addr, unsigned long count)
93 __asm__ __volatile__ (
95 : "=S" (addr), "=c" (count)
96 : "d"(port), "0"(addr), "1" (count)
100 static inline void outsl(uint16_t port, const void *addr, unsigned long count)
102 __asm__ __volatile__ (
104 : "=S" (addr), "=c" (count)
105 : "d"(port), "0"(addr), "1" (count)
110 static inline void insb(uint16_t port, void *addr, unsigned long count)
112 __asm__ __volatile__ (
114 : "=D" (addr), "=c" (count)
115 : "d"(port), "0"(addr), "1" (count)
119 static inline void insw(uint16_t port, void *addr, unsigned long count)
121 __asm__ __volatile__ (
123 : "=D" (addr), "=c" (count)
124 : "d"(port), "0"(addr), "1" (count)
128 static inline void insl(uint16_t port, void *addr, unsigned long count)
130 __asm__ __volatile__ (
132 : "=D" (addr), "=c" (count)
133 : "d"(port), "0"(addr), "1" (count)
137 static inline __attribute__((always_inline)) uint8_t read8(unsigned long addr)
139 return *((volatile uint8_t *)(addr));
142 static inline __attribute__((always_inline)) uint16_t read16(unsigned long addr)
144 return *((volatile uint16_t *)(addr));
147 static inline __attribute__((always_inline)) uint32_t read32(unsigned long addr)
149 return *((volatile uint32_t *)(addr));
152 static inline __attribute__((always_inline)) void write8(unsigned long addr, uint8_t value)
154 *((volatile uint8_t *)(addr)) = value;
157 static inline __attribute__((always_inline)) void write16(unsigned long addr, uint16_t value)
159 *((volatile uint16_t *)(addr)) = value;
162 static inline __attribute__((always_inline)) void write32(unsigned long addr, uint32_t value)
164 *((volatile uint32_t *)(addr)) = value;