114 lines
2.0 KiB
C
114 lines
2.0 KiB
C
#ifndef MINIOS_X86_H
|
|
#define MINIOS_X86_H
|
|
|
|
#include "type.h"
|
|
|
|
static inline u8
|
|
inb(int port)
|
|
{
|
|
u8 data;
|
|
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
|
|
return data;
|
|
}
|
|
|
|
static inline void
|
|
insb(int port, void *addr, int cnt)
|
|
{
|
|
asm volatile("cld\n\trepne\n\tinsb"
|
|
: "=D" (addr), "=c" (cnt)
|
|
: "d" (port), "0" (addr), "1" (cnt)
|
|
: "memory", "cc");
|
|
}
|
|
|
|
static inline u16
|
|
inw(int port)
|
|
{
|
|
u16 data;
|
|
asm volatile("inw %w1,%0" : "=a" (data) : "d" (port));
|
|
return data;
|
|
}
|
|
|
|
static inline void
|
|
insw(int port, void *addr, int cnt)
|
|
{
|
|
asm volatile("cld\n\trepne\n\tinsw"
|
|
: "=D" (addr), "=c" (cnt)
|
|
: "d" (port), "0" (addr), "1" (cnt)
|
|
: "memory", "cc");
|
|
}
|
|
|
|
static inline u32
|
|
inl(int port)
|
|
{
|
|
u32 data;
|
|
asm volatile("inl %w1,%0" : "=a" (data) : "d" (port));
|
|
return data;
|
|
}
|
|
|
|
static inline void
|
|
insl(int port, void *addr, int cnt)
|
|
{
|
|
asm volatile("cld\n\trepne\n\tinsl"
|
|
: "=D" (addr), "=c" (cnt)
|
|
: "d" (port), "0" (addr), "1" (cnt)
|
|
: "memory", "cc");
|
|
}
|
|
|
|
static inline void
|
|
outb(int port, u8 data)
|
|
{
|
|
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
|
|
}
|
|
|
|
static inline void
|
|
outsb(int port, const void *addr, int cnt)
|
|
{
|
|
asm volatile("cld\n\trepne\n\toutsb"
|
|
: "=S" (addr), "=c" (cnt)
|
|
: "d" (port), "0" (addr), "1" (cnt)
|
|
: "cc");
|
|
}
|
|
|
|
static inline void
|
|
outw(int port, u16 data)
|
|
{
|
|
asm volatile("outw %0,%w1" : : "a" (data), "d" (port));
|
|
}
|
|
|
|
static inline void
|
|
outsw(int port, const void *addr, int cnt)
|
|
{
|
|
asm volatile("cld\n\trepne\n\toutsw"
|
|
: "=S" (addr), "=c" (cnt)
|
|
: "d" (port), "0" (addr), "1" (cnt)
|
|
: "cc");
|
|
}
|
|
|
|
static inline void
|
|
outsl(int port, const void *addr, int cnt)
|
|
{
|
|
asm volatile("cld\n\trepne\n\toutsl"
|
|
: "=S" (addr), "=c" (cnt)
|
|
: "d" (port), "0" (addr), "1" (cnt)
|
|
: "cc");
|
|
}
|
|
|
|
static inline void
|
|
outl(int port, u32 data)
|
|
{
|
|
asm volatile("outl %0,%w1" : : "a" (data), "d" (port));
|
|
}
|
|
|
|
static inline void
|
|
disable_int()
|
|
{
|
|
asm volatile("cli");
|
|
}
|
|
|
|
static inline void
|
|
enable_int()
|
|
{
|
|
asm volatile("sti");
|
|
}
|
|
|
|
#endif |