x86/atom: use correct names in asm, improve docs

main
anna 3 years ago
parent 7af90dc798
commit ea89961ed2
Signed by: fef
GPG Key ID: EC22E476DC2D3D84

@ -32,10 +32,10 @@ inline int atom_write(atom_t *atom, int val)
int eax;
__asm__ volatile(
" mov (%2), %0 \n"
" mov (%2), %0 \n" /* eax = atom->_value */
"1: lock \n"
" cmpxchgl %1, (%2) \n"
" jne 1b \n"
" cmpxchgl %1, (%2) \n" /* if (atom->_value == eax) atom->_value = val */
" jne 1b \n" /* else goto 1 (eax updated to new atom->_value) */
: "=a"(eax)
: "r"(val), "r"(&atom->_value)
: "cc", "memory"
@ -109,9 +109,9 @@ inline bool atom_dec(atom_t *atom)
bool nonzero = false;
__asm__ volatile(
" lock \n"
" decl (%1) \n"
" setne %0 \n"
" lock \n"
" decl (%1) \n"
" setne %0 \n"
: "+r"(nonzero) /* read+write to ensure the initial value isn't optimized out */
: "r"(&atom->_value)
: "cc", "memory"
@ -136,7 +136,7 @@ inline int atom_and(atom_t *atom, int val)
"1: andl %0, %1 \n" /* val &= eax */
" lock \n"
" 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)
: "r"(&atom->_value)
: "cc", "memory"
@ -161,7 +161,7 @@ inline int atom_or(atom_t *atom, int val)
"1: orl %0, %1 \n" /* eax |= eax */
" lock \n"
" 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)
: "r"(&atom->_value)
: "cc", "memory"
@ -183,10 +183,10 @@ inline int atom_xor(atom_t *atom, int val)
__asm__ volatile(
" movl (%2), %0 \n" /* eax = atom->_value */
"1: xorl %0, %1 \n" /* eax ^= eax */
"1: xorl %0, %1 \n" /* val ^= eax */
" lock \n"
" 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)
: "r"(&atom->_value)
: "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)
* @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 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)
* @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 oldval = atom_and(atom, ~mask);

@ -2,8 +2,16 @@
#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
mov %esp, %ebp
@ -12,10 +20,10 @@ ASM_ENTRY(arch_atom_read)
pop %ebp
ret
ASM_END(arch_atom_read)
ASM_END(atom_read)
/* int arch_atom_write(atom_t *atom, int val) */
ASM_ENTRY(arch_atom_write)
/* int atom_write(atom_t *atom, int val) */
ASM_ENTRY(atom_write)
push %ebp
mov %esp, %ebp
@ -28,10 +36,10 @@ ASM_ENTRY(arch_atom_write)
pop %ebp
ret
ASM_END(arch_atom_write)
ASM_END(atom_write)
/* bool arch_atom_inc(atom_t *atom) */
ASM_ENTRY(arch_atom_inc)
/* bool atom_inc(atom_t *atom) */
ASM_ENTRY(atom_inc)
push %ebp
mov %esp, %ebp
@ -43,10 +51,10 @@ ASM_ENTRY(arch_atom_inc)
pop %ebp
ret
ASM_END(arch_atom_inc)
ASM_END(atom_inc)
/* bool arch_atom_dec(atom_t *atom) */
ASM_ENTRY(arch_atom_dec)
/* bool atom_dec(atom_t *atom) */
ASM_ENTRY(atom_dec)
push %ebp
mov %esp, %ebp
@ -58,10 +66,10 @@ ASM_ENTRY(arch_atom_dec)
pop %ebp
ret
ASM_END(arch_atom_dec)
ASM_END(atom_dec)
/* int arch_atom_add(atom_t *atom, int val) */
ASM_ENTRY(arch_atom_add)
/* int atom_add(atom_t *atom, int val) */
ASM_ENTRY(atom_add)
push %ebp
mov %esp, %ebp
@ -72,10 +80,10 @@ ASM_ENTRY(arch_atom_add)
pop %ebp
ret
ASM_END(arch_atom_add)
ASM_END(atom_add)
/* int arch_atom_sub(atom_t *atom, int val) */
ASM_ENTRY(arch_atom_sub)
/* int atom_sub(atom_t *atom, int val) */
ASM_ENTRY(atom_sub)
push %ebp
mov %esp, %ebp
@ -89,10 +97,10 @@ ASM_ENTRY(arch_atom_sub)
pop %ebp
ret
ASM_END(arch_atom_sub)
ASM_END(atom_sub)
/* int arch_atom_and(atom_t *atom, int val) */
ASM_ENTRY(arch_atom_and)
/* int atom_and(atom_t *atom, int val) */
ASM_ENTRY(atom_and)
push %ebp
mov %esp, %ebp
@ -107,10 +115,10 @@ ASM_ENTRY(arch_atom_and)
pop %ebp
ret
ASM_END(arch_atom_and)
ASM_END(atom_and)
/* int arch_atom_or(atom_t *atom, int val) */
ASM_ENTRY(arch_atom_or)
/* int atom_or(atom_t *atom, int val) */
ASM_ENTRY(atom_or)
push %ebp
mov %esp, %ebp
@ -125,10 +133,10 @@ ASM_ENTRY(arch_atom_or)
pop %ebp
ret
ASM_END(arch_atom_or)
ASM_END(atom_or)
/* int arch_atom_xor(atom_t *atom, int val) */
ASM_ENTRY(arch_atom_xor)
/* int atom_xor(atom_t *atom, int val) */
ASM_ENTRY(atom_xor)
push %ebp
mov %esp, %ebp
@ -143,10 +151,10 @@ ASM_ENTRY(arch_atom_xor)
pop %ebp
ret
ASM_END(arch_atom_xor)
ASM_END(atom_xor)
/* bool arch_atom_set_bit(atom_t *atom, int bit) */
ASM_ENTRY(arch_atom_set_bit)
/* bool atom_set_bit(atom_t *atom, int bit) */
ASM_ENTRY(atom_set_bit)
push %ebp
mov %esp, %ebp
push %ebx
@ -171,10 +179,10 @@ ASM_ENTRY(arch_atom_set_bit)
pop %ebx
pop %ebp
ret
ASM_END(arch_atom_set_bit)
ASM_END(atom_set_bit)
/* bool arch_atom_clr_bit(atom_t *atom, int bit) */
ASM_ENTRY(arch_atom_clr_bit)
/* bool atom_clr_bit(atom_t *atom, int bit) */
ASM_ENTRY(atom_clr_bit)
push %ebp
mov %esp, %ebp
push %ebx
@ -199,7 +207,7 @@ ASM_ENTRY(arch_atom_clr_bit)
pop %ebx
pop %ebp
ret
ASM_END(arch_atom_clr_bit)
ASM_END(atom_clr_bit)
/*
* This file is part of GayBSD.

@ -12,7 +12,7 @@ typedef struct {
} spin_t;
#define SPIN(name) struct spin name = { \
.lock = { ._value = 0 }, \
.lock = ATOM_DEFINE(0), \
}
void spin_init(spin_t *spin);

Loading…
Cancel
Save