x86: inline I/O port functions

main
anna 3 years ago
parent 16b6924beb
commit bc917d8651
Signed by: fef
GPG Key ID: EC22E476DC2D3D84

@ -21,13 +21,29 @@
#ifndef _ASM_SOURCE
#include <gay/cdefs.h>
/** @brief Induce a brief CPU delay by writing zero to I/O port 0x80. */
extern void x86_io_wait(void);
/**
* @brief Read a byte from the I/O bus.
*
* @param port Port number
* @return The byte that was read
*/
extern u8 x86_inb(u16 port);
inline u8 x86_inb(u16 port)
{
u8 data;
__asm__ volatile(
" inb %1, %0 \n"
: "=a"(data)
: "Nd"(port)
);
return data;
}
/**
* @brief Read a word from the I/O bus.
@ -35,7 +51,18 @@ extern u8 x86_inb(u16 port);
* @param port Port number
* @return The word that was read
*/
extern u16 x86_inw(u16 port);
inline u16 x86_inw(u16 port)
{
u16 data;
__asm__ volatile(
" inw %1, %0 \n"
: "=a"(data)
: "Nd"(port)
);
return data;
}
/**
* @brief Read a longword from the I/O bus.
@ -43,7 +70,18 @@ extern u16 x86_inw(u16 port);
* @param port Port number
* @return The longword that was read
*/
extern u32 x86_inl(u16 port);
inline u32 x86_inl(u16 port)
{
u32 data;
__asm__ volatile(
" inl %1, %0 \n"
: "=a"(data)
: "Nd"(port)
);
return data;
}
/**
* @brief Write a byte to the I/O bus.
@ -51,7 +89,14 @@ extern u32 x86_inl(u16 port);
* @param port Port number
* @param data Byte to send through the port
*/
extern void x86_outb(u16 port, u8 data);
inline void x86_outb(u16 port, u8 data)
{
__asm__ volatile(
" outb %0, %1 \n"
:
: "a"(data), "Nd"(port)
);
}
/**
* @brief Write a word to the I/O bus.
@ -59,7 +104,14 @@ extern void x86_outb(u16 port, u8 data);
* @param port Port number
* @param data Word to send through the port
*/
extern void x86_outw(u16 port, u16 data);
inline void x86_outw(u16 port, u16 data)
{
__asm__ volatile(
" outw %0, %1 \n"
:
: "a"(data), "Nd"(port)
);
}
/**
* @brief Write a longword to the I/O bus.
@ -67,7 +119,14 @@ extern void x86_outw(u16 port, u16 data);
* @param port Port number
* @param data Longword to send through the port
*/
extern void x86_outl(u16 port, u32 data);
inline void x86_outl(u16 port, u32 data)
{
__asm__ volatile(
" outl %0, %1 \n"
:
: "a"(data), "Nd"(port)
);
}
#endif /* not _ASM_SOURCE */

@ -4,6 +4,13 @@
.text
/* void x86_io_wait(void); */
ASM_ENTRY(x86_io_wait)
xor %al, %al
outb %al, $0x80
ret
ASM_END(x86_io_wait)
/* u8 x86_inb(u16 port); */
ASM_ENTRY(x86_inb)
mov 4(%esp), %edx

Loading…
Cancel
Save