x86/atom: use correct names in asm, improve docs
This commit is contained in:
parent
7af90dc798
commit
ea89961ed2
3 changed files with 54 additions and 46 deletions
|
@ -32,10 +32,10 @@ inline int atom_write(atom_t *atom, int val)
|
||||||
int eax;
|
int eax;
|
||||||
|
|
||||||
__asm__ volatile(
|
__asm__ volatile(
|
||||||
" mov (%2), %0 \n"
|
" mov (%2), %0 \n" /* eax = atom->_value */
|
||||||
"1: lock \n"
|
"1: lock \n"
|
||||||
" cmpxchgl %1, (%2) \n"
|
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = val */
|
||||||
" jne 1b \n"
|
" jne 1b \n" /* else goto 1 (eax updated to new atom->_value) */
|
||||||
: "=a"(eax)
|
: "=a"(eax)
|
||||||
: "r"(val), "r"(&atom->_value)
|
: "r"(val), "r"(&atom->_value)
|
||||||
: "cc", "memory"
|
: "cc", "memory"
|
||||||
|
@ -109,9 +109,9 @@ inline bool atom_dec(atom_t *atom)
|
||||||
bool nonzero = false;
|
bool nonzero = false;
|
||||||
|
|
||||||
__asm__ volatile(
|
__asm__ volatile(
|
||||||
" lock \n"
|
" lock \n"
|
||||||
" decl (%1) \n"
|
" decl (%1) \n"
|
||||||
" setne %0 \n"
|
" setne %0 \n"
|
||||||
: "+r"(nonzero) /* read+write to ensure the initial value isn't optimized out */
|
: "+r"(nonzero) /* read+write to ensure the initial value isn't optimized out */
|
||||||
: "r"(&atom->_value)
|
: "r"(&atom->_value)
|
||||||
: "cc", "memory"
|
: "cc", "memory"
|
||||||
|
@ -136,7 +136,7 @@ inline int atom_and(atom_t *atom, int val)
|
||||||
"1: andl %0, %1 \n" /* val &= eax */
|
"1: andl %0, %1 \n" /* val &= eax */
|
||||||
" lock \n"
|
" lock \n"
|
||||||
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = val */
|
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = val */
|
||||||
" jne 1b \n" /* else goto 1 */
|
" jne 1b \n" /* else goto 1 (eax updated to new atom->_value) */
|
||||||
: "=a"(eax), "+r"(val)
|
: "=a"(eax), "+r"(val)
|
||||||
: "r"(&atom->_value)
|
: "r"(&atom->_value)
|
||||||
: "cc", "memory"
|
: "cc", "memory"
|
||||||
|
@ -161,7 +161,7 @@ inline int atom_or(atom_t *atom, int val)
|
||||||
"1: orl %0, %1 \n" /* eax |= eax */
|
"1: orl %0, %1 \n" /* eax |= eax */
|
||||||
" lock \n"
|
" lock \n"
|
||||||
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = eax */
|
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = eax */
|
||||||
" jne 1b \n" /* else goto 1 */
|
" jne 1b \n" /* else goto 1 (eax updated to new atom->_value) */
|
||||||
: "=a"(eax), "+r"(val)
|
: "=a"(eax), "+r"(val)
|
||||||
: "r"(&atom->_value)
|
: "r"(&atom->_value)
|
||||||
: "cc", "memory"
|
: "cc", "memory"
|
||||||
|
@ -183,10 +183,10 @@ inline int atom_xor(atom_t *atom, int val)
|
||||||
|
|
||||||
__asm__ volatile(
|
__asm__ volatile(
|
||||||
" movl (%2), %0 \n" /* eax = atom->_value */
|
" movl (%2), %0 \n" /* eax = atom->_value */
|
||||||
"1: xorl %0, %1 \n" /* eax ^= eax */
|
"1: xorl %0, %1 \n" /* val ^= eax */
|
||||||
" lock \n"
|
" lock \n"
|
||||||
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = eax */
|
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = eax */
|
||||||
" jne 1b \n" /* else goto 1 */
|
" jne 1b \n" /* else goto 1 (eax updated to new atom->_value) */
|
||||||
: "=a"(eax), "+r"(val)
|
: "=a"(eax), "+r"(val)
|
||||||
: "r"(&atom->_value)
|
: "r"(&atom->_value)
|
||||||
: "cc", "memory"
|
: "cc", "memory"
|
||||||
|
@ -202,7 +202,7 @@ inline int atom_xor(atom_t *atom, int val)
|
||||||
* @param pos Bit position (starting from 0 for the LSB)
|
* @param pos Bit position (starting from 0 for the LSB)
|
||||||
* @return `true` the bit was clear *before* the operation
|
* @return `true` the bit was clear *before* the operation
|
||||||
*/
|
*/
|
||||||
inline bool arch_atom_set_bit(atom_t *atom, int pos)
|
inline bool atom_set_bit(atom_t *atom, int pos)
|
||||||
{
|
{
|
||||||
int mask = 1 << pos;
|
int mask = 1 << pos;
|
||||||
int oldval = atom_or(atom, mask);
|
int oldval = atom_or(atom, mask);
|
||||||
|
@ -216,7 +216,7 @@ inline bool arch_atom_set_bit(atom_t *atom, int pos)
|
||||||
* @param pos Bit position (starting from 0 for the LSB)
|
* @param pos Bit position (starting from 0 for the LSB)
|
||||||
* @return `true` if the bit was set *before* the operation
|
* @return `true` if the bit was set *before* the operation
|
||||||
*/
|
*/
|
||||||
inline bool arch_atom_clr_bit(atom_t *atom, int pos)
|
inline bool atom_clr_bit(atom_t *atom, int pos)
|
||||||
{
|
{
|
||||||
int mask = 1 << pos;
|
int mask = 1 << pos;
|
||||||
int oldval = atom_and(atom, ~mask);
|
int oldval = atom_and(atom, ~mask);
|
||||||
|
|
|
@ -2,8 +2,16 @@
|
||||||
|
|
||||||
#include <asm/common.h>
|
#include <asm/common.h>
|
||||||
|
|
||||||
/* int arch_atom_read(const atom_t *atom) */
|
/*
|
||||||
ASM_ENTRY(arch_atom_read)
|
* These routines are only really used if debugging is enabled, where everything
|
||||||
|
* is compiled with -O0. Otherwise clang would just take the inline definitions
|
||||||
|
* from the header file (what an elegant way of creating bugs that only appear
|
||||||
|
* in optimized code!). Therefore, we sacrifice a bit of performance for the
|
||||||
|
* sake of being nicer to gdb by creating frame pointers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* int atom_read(const atom_t *atom) */
|
||||||
|
ASM_ENTRY(atom_read)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -12,10 +20,10 @@ ASM_ENTRY(arch_atom_read)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_read)
|
ASM_END(atom_read)
|
||||||
|
|
||||||
/* int arch_atom_write(atom_t *atom, int val) */
|
/* int atom_write(atom_t *atom, int val) */
|
||||||
ASM_ENTRY(arch_atom_write)
|
ASM_ENTRY(atom_write)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -28,10 +36,10 @@ ASM_ENTRY(arch_atom_write)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_write)
|
ASM_END(atom_write)
|
||||||
|
|
||||||
/* bool arch_atom_inc(atom_t *atom) */
|
/* bool atom_inc(atom_t *atom) */
|
||||||
ASM_ENTRY(arch_atom_inc)
|
ASM_ENTRY(atom_inc)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -43,10 +51,10 @@ ASM_ENTRY(arch_atom_inc)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_inc)
|
ASM_END(atom_inc)
|
||||||
|
|
||||||
/* bool arch_atom_dec(atom_t *atom) */
|
/* bool atom_dec(atom_t *atom) */
|
||||||
ASM_ENTRY(arch_atom_dec)
|
ASM_ENTRY(atom_dec)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -58,10 +66,10 @@ ASM_ENTRY(arch_atom_dec)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_dec)
|
ASM_END(atom_dec)
|
||||||
|
|
||||||
/* int arch_atom_add(atom_t *atom, int val) */
|
/* int atom_add(atom_t *atom, int val) */
|
||||||
ASM_ENTRY(arch_atom_add)
|
ASM_ENTRY(atom_add)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -72,10 +80,10 @@ ASM_ENTRY(arch_atom_add)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_add)
|
ASM_END(atom_add)
|
||||||
|
|
||||||
/* int arch_atom_sub(atom_t *atom, int val) */
|
/* int atom_sub(atom_t *atom, int val) */
|
||||||
ASM_ENTRY(arch_atom_sub)
|
ASM_ENTRY(atom_sub)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -89,10 +97,10 @@ ASM_ENTRY(arch_atom_sub)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_sub)
|
ASM_END(atom_sub)
|
||||||
|
|
||||||
/* int arch_atom_and(atom_t *atom, int val) */
|
/* int atom_and(atom_t *atom, int val) */
|
||||||
ASM_ENTRY(arch_atom_and)
|
ASM_ENTRY(atom_and)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -107,10 +115,10 @@ ASM_ENTRY(arch_atom_and)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_and)
|
ASM_END(atom_and)
|
||||||
|
|
||||||
/* int arch_atom_or(atom_t *atom, int val) */
|
/* int atom_or(atom_t *atom, int val) */
|
||||||
ASM_ENTRY(arch_atom_or)
|
ASM_ENTRY(atom_or)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -125,10 +133,10 @@ ASM_ENTRY(arch_atom_or)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_or)
|
ASM_END(atom_or)
|
||||||
|
|
||||||
/* int arch_atom_xor(atom_t *atom, int val) */
|
/* int atom_xor(atom_t *atom, int val) */
|
||||||
ASM_ENTRY(arch_atom_xor)
|
ASM_ENTRY(atom_xor)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
|
|
||||||
|
@ -143,10 +151,10 @@ ASM_ENTRY(arch_atom_xor)
|
||||||
|
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_xor)
|
ASM_END(atom_xor)
|
||||||
|
|
||||||
/* bool arch_atom_set_bit(atom_t *atom, int bit) */
|
/* bool atom_set_bit(atom_t *atom, int bit) */
|
||||||
ASM_ENTRY(arch_atom_set_bit)
|
ASM_ENTRY(atom_set_bit)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
push %ebx
|
push %ebx
|
||||||
|
@ -171,10 +179,10 @@ ASM_ENTRY(arch_atom_set_bit)
|
||||||
pop %ebx
|
pop %ebx
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_set_bit)
|
ASM_END(atom_set_bit)
|
||||||
|
|
||||||
/* bool arch_atom_clr_bit(atom_t *atom, int bit) */
|
/* bool atom_clr_bit(atom_t *atom, int bit) */
|
||||||
ASM_ENTRY(arch_atom_clr_bit)
|
ASM_ENTRY(atom_clr_bit)
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
push %ebx
|
push %ebx
|
||||||
|
@ -199,7 +207,7 @@ ASM_ENTRY(arch_atom_clr_bit)
|
||||||
pop %ebx
|
pop %ebx
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
ASM_END(arch_atom_clr_bit)
|
ASM_END(atom_clr_bit)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of GayBSD.
|
* This file is part of GayBSD.
|
||||||
|
|
|
@ -12,7 +12,7 @@ typedef struct {
|
||||||
} spin_t;
|
} spin_t;
|
||||||
|
|
||||||
#define SPIN(name) struct spin name = { \
|
#define SPIN(name) struct spin name = { \
|
||||||
.lock = { ._value = 0 }, \
|
.lock = ATOM_DEFINE(0), \
|
||||||
}
|
}
|
||||||
|
|
||||||
void spin_init(spin_t *spin);
|
void spin_init(spin_t *spin);
|
||||||
|
|
Loading…
Reference in a new issue