summaryrefslogtreecommitdiff
path: root/kernel/old/include/x86/ops.h
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/old/include/x86/ops.h')
-rw-r--r--kernel/old/include/x86/ops.h266
1 files changed, 157 insertions, 109 deletions
diff --git a/kernel/old/include/x86/ops.h b/kernel/old/include/x86/ops.h
index 81167a1..ad795b9 100644
--- a/kernel/old/include/x86/ops.h
+++ b/kernel/old/include/x86/ops.h
@@ -10,7 +10,7 @@
** MIT's xv6, https://github.com/mit-pdos/xv6-public
**
** Note: normally, GCC doesn't inline unless the optimization level is
-** over 1. This can be forced by adding
+** over 1. This can be forced by adding
**
** __attribute__((always_inline))
**
@@ -27,10 +27,10 @@
// control "forced" inlining
#ifdef FORCE_INLINING
-#define OPSINLINED __attribute__((always_inline))
+#define OPSINLINED __attribute__((always_inline))
#else
-#define OPSINLINED /* no-op */
-#endif /* FORCE_INLINING */
+#define OPSINLINED /* no-op */
+#endif /* FORCE_INLINING */
/****************************
** Data movement
@@ -47,33 +47,36 @@
** @param src Source buffer
** @param len Byte count
*/
-static inline void movsb(void *dst, const void *src, uint32_t len) OPSINLINED
+static inline void
+movsb( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsb"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsb"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
-static inline void movsw(void *dst, const void *src, uint32_t len) OPSINLINED
+
+static inline void
+movsw( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsw"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsw"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
-static inline void movsl(void *dst, const void *src, uint32_t len) OPSINLINED
+
+static inline void
+movsl( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsl"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsl"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
-static inline void movsq(void *dst, const void *src, uint32_t len) OPSINLINED
+
+static inline void
+movsq( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsq"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsq"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
/**
@@ -87,26 +90,31 @@ static inline void movsq(void *dst, const void *src, uint32_t len) OPSINLINED
** @param val Data to copy
** @param len Byte count
*/
-static inline void stosb(void *dst, uint8_t val, uint32_t len) OPSINLINED
+static inline void
+stosb( void *dst, uint8_t val, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep stosb"
- : "=D"(dst), "=c"(len)
- : "0"(dst), "1"(len), "a"(val)
- : "memory", "cc");
+ __asm__ __volatile__( "cld; rep stosb"
+ : "=D" (dst), "=c" (len)
+ : "0" (dst), "1" (len), "a" (val)
+ : "memory", "cc" );
}
-static inline void stosw(void *dst, uint16_t val, uint32_t len) OPSINLINED
+
+static inline void
+stosw( void *dst, uint16_t val, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep stos2"
- : "=D"(dst), "=c"(len)
- : "0"(dst), "1"(len), "a"(val)
- : "memory", "cc");
+ __asm__ __volatile__( "cld; rep stos2"
+ : "=D" (dst), "=c" (len)
+ : "0" (dst), "1" (len), "a" (val)
+ : "memory", "cc" );
}
-static inline void stosl(void *dst, uint32_t val, uint32_t len) OPSINLINED
+
+static inline void
+stosl( void *dst, uint32_t val, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep stosl"
- : "=D"(dst), "=c"(len)
- : "0"(dst), "1"(len), "a"(val)
- : "memory", "cc");
+ __asm__ __volatile__( "cld; rep stosl"
+ : "=D" (dst), "=c" (len)
+ : "0" (dst), "1" (len), "a" (val)
+ : "memory", "cc" );
}
/****************************
@@ -123,46 +131,59 @@ static inline void stosl(void *dst, uint32_t val, uint32_t len) OPSINLINED
**
** @return Contents of the register
*/
-static inline uint32_t r_cr0(void) OPSINLINED
+static inline uint32_t
+r_cr0( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr0,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr0,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_cr2(void) OPSINLINED
+
+static inline uint32_t
+r_cr2( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr2,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr2,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_cr3(void) OPSINLINED
+
+static inline uint32_t
+r_cr3( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr3,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr3,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_cr4(void) OPSINLINED
+
+static inline uint32_t
+r_cr4( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr4,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr4,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_eflags(void) OPSINLINED
+
+static inline uint32_t
+r_eflags(void) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("pushfl; popl %0" : "=r"(val));
+ __asm__ __volatile__( "pushfl; popl %0" : "=r" (val) );
return val;
}
-static inline uint32_t r_ebp(void) OPSINLINED
+
+static inline uint32_t
+r_ebp(void) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%ebp,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%ebp,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_esp(void) OPSINLINED
+
+static inline uint32_t
+r_esp(void) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%esp,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%esp,%0" : "=r" (val) );
return val;
}
@@ -173,25 +194,34 @@ static inline uint32_t r_esp(void) OPSINLINED
**
** Description: Writes a value into the CR indicated by its name
*/
-static inline void w_cr0(uint32_t val) OPSINLINED
+static inline void
+w_cr0( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr0" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr0" : : "r" (val) );
}
-static inline void w_cr2(uint32_t val) OPSINLINED
+
+static inline void
+w_cr2( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr2" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr2" : : "r" (val) );
}
-static inline void w_cr3(uint32_t val) OPSINLINED
+
+static inline void
+w_cr3( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr3" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr3" : : "r" (val) );
}
-static inline void w_cr4(uint32_t val) OPSINLINED
+
+static inline void
+w_cr4( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr4" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr4" : : "r" (val) );
}
-static inline void w_eflags(uint32_t eflags) OPSINLINED
+
+static inline void
+w_eflags(uint32_t eflags) OPSINLINED
{
- __asm__ __volatile__("pushl %0; popfl" : : "r"(eflags));
+ __asm__ __volatile__( "pushl %0; popfl" : : "r" (eflags) );
}
/**
@@ -203,13 +233,16 @@ static inline void w_eflags(uint32_t eflags) OPSINLINED
**
** @param addr The value to be loaded into the register
*/
-static inline void w_gdt(void *addr) OPSINLINED
+static inline void
+w_gdt( void *addr ) OPSINLINED
{
- __asm__ __volatile__("lgdt (%0)" : : "r"(addr));
+ __asm__ __volatile__( "lgdt (%0)" : : "r" (addr) );
}
-static inline void w_idt(void *addr) OPSINLINED
+
+static inline void
+w_idt( void *addr ) OPSINLINED
{
- __asm__ __volatile__("lidt (%0)" : : "r"(addr));
+ __asm__ __volatile__( "lidt (%0)" : : "r" (addr) );
}
/**
@@ -223,21 +256,19 @@ static inline void w_idt(void *addr) OPSINLINED
** @param cp Pointer to where %ecx contents should be saved, or NULL
** @param dp Pointer to where %edx contents should be saved, or NULL
*/
-static inline void cpuid(uint32_t op, uint32_t *ap, uint32_t *bp, uint32_t *cp,
- uint32_t *dp) OPSINLINED
+static inline void
+cpuid( uint32_t op, uint32_t *ap, uint32_t *bp,
+ uint32_t *cp, uint32_t *dp ) OPSINLINED
{
uint32_t eax, ebx, ecx, edx;
- __asm__ __volatile__("cpuid"
- : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
- : "a"(op));
- if (ap)
- *ap = eax;
- if (bp)
- *bp = ebx;
- if (cp)
- *cp = ecx;
- if (dp)
- *dp = edx;
+ __asm__ __volatile__( "cpuid"
+ : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
+ : "a" (op) );
+
+ if( ap ) *ap = eax;
+ if( bp ) *bp = ebx;
+ if( cp ) *cp = ecx;
+ if( dp ) *dp = edx;
}
/****************************
@@ -251,9 +282,10 @@ static inline void cpuid(uint32_t op, uint32_t *ap, uint32_t *bp, uint32_t *cp,
**
** @param addr An address within the page to be flushed
*/
-static inline void invlpg(uint32_t addr) OPSINLINED
+static inline void
+invlpg( uint32_t addr ) OPSINLINED
{
- __asm__ __volatile__("invlpg (%0)" : : "r"(addr) : "memory");
+ __asm__ __volatile__( "invlpg (%0)" : : "r" (addr) : "memory" );
}
/**
@@ -263,11 +295,12 @@ static inline void invlpg(uint32_t addr) OPSINLINED
**
** We do this by changing CR3.
*/
-static inline void flushtlb(void) OPSINLINED
+static inline void
+flushtlb( void ) OPSINLINED
{
uint32_t cr3;
- __asm__ __volatile__("movl %%cr3,%0" : "=r"(cr3));
- __asm__ __volatile__("movl %0,%%cr2" : : "r"(cr3));
+ __asm__ __volatile__( "movl %%cr3,%0" : "=r" (cr3) );
+ __asm__ __volatile__( "movl %0,%%cr2" : : "r" (cr3) );
}
/****************************
@@ -285,22 +318,27 @@ static inline void flushtlb(void) OPSINLINED
**
** @return The data read from the specified port
*/
-static inline uint8_t inb(int port) OPSINLINED
+static inline uint8_t
+inb( int port ) OPSINLINED
{
uint8_t data;
- __asm__ __volatile__("inb %w1,%0" : "=a"(data) : "d"(port));
+ __asm__ __volatile__( "inb %w1,%0" : "=a" (data) : "d" (port) );
return data;
}
-static inline uint16_t inw(int port) OPSINLINED
+
+static inline uint16_t
+inw( int port ) OPSINLINED
{
uint16_t data;
- __asm__ __volatile__("inw %w1,%0" : "=a"(data) : "d"(port));
+ __asm__ __volatile__( "inw %w1,%0" : "=a" (data) : "d" (port) );
return data;
}
-static inline uint32_t inl(int port) OPSINLINED
+
+static inline uint32_t
+inl( int port ) OPSINLINED
{
uint32_t data;
- __asm__ __volatile__("inl %w1,%0" : "=a"(data) : "d"(port));
+ __asm__ __volatile__( "inl %w1,%0" : "=a" (data) : "d" (port) );
return data;
}
@@ -316,17 +354,22 @@ static inline uint32_t inl(int port) OPSINLINED
**
** @return The data read from the specified port
*/
-static inline void outb(int port, uint8_t data) OPSINLINED
+static inline void
+outb( int port, uint8_t data ) OPSINLINED
{
- __asm__ __volatile__("outb %0,%w1" : : "a"(data), "d"(port));
+ __asm__ __volatile__( "outb %0,%w1" : : "a" (data), "d" (port) );
}
-static inline void outw(int port, uint16_t data) OPSINLINED
+
+static inline void
+outw( int port, uint16_t data ) OPSINLINED
{
- __asm__ __volatile__("outw %0,%w1" : : "a"(data), "d"(port));
+ __asm__ __volatile__( "outw %0,%w1" : : "a" (data), "d" (port) );
}
-static inline void outl(int port, uint32_t data) OPSINLINED
+
+static inline void
+outl( int port, uint32_t data ) OPSINLINED
{
- __asm__ __volatile__("outl %0,%w1" : : "a"(data), "d"(port));
+ __asm__ __volatile__( "outl %0,%w1" : : "a" (data), "d" (port) );
}
/****************************
@@ -338,9 +381,10 @@ static inline void outl(int port, uint32_t data) OPSINLINED
**
** Description: Cause a breakpoint interrupt for debugging purposes
*/
-static inline void breakpoint(void) OPSINLINED
+static inline void
+breakpoint( void ) OPSINLINED
{
- __asm__ __volatile__("int3");
+ __asm__ __volatile__( "int3" );
}
/**
@@ -351,10 +395,11 @@ static inline void breakpoint(void) OPSINLINED
**
** @return The address the calling routine will return to as a uint32_t
*/
-static inline uint32_t get_ra(void) OPSINLINED
+static inline uint32_t
+get_ra( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl 4(%%ebp),%0" : "=r"(val));
+ __asm__ __volatile__( "movl 4(%%ebp),%0" : "=r" (val) );
return val;
}
@@ -363,11 +408,13 @@ static inline uint32_t get_ra(void) OPSINLINED
**
** Description: Pause until something happens
*/
-static inline void ev_wait(void) OPSINLINED
+static inline void
+ev_wait( void ) OPSINLINED
{
- __asm__ __volatile__("sti ; hlt");
+ __asm__ __volatile__( "sti ; hlt" );
}
+
/**
** Name: xchgl
**
@@ -378,18 +425,19 @@ static inline void ev_wait(void) OPSINLINED
**
** @return The old contents of the memory location
*/
-static inline uint32_t xchgl(volatile uint32_t *addr, uint32_t data) OPSINLINED
+static inline uint32_t
+xchgl( volatile uint32_t *addr, uint32_t data ) OPSINLINED
{
uint32_t old;
// + indicates a read-modify-write operand
- __asm__ __volatile__("lock; xchgl %0, %1"
- : "+m"(*addr), "=a"(old)
- : "1"(data)
- : "cc");
+ __asm__ __volatile__( "lock; xchgl %0, %1"
+ : "+m" (*addr), "=a" (old)
+ : "1" (data)
+ : "cc");
return old;
}
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif