216 lines
3.5 KiB
ArmAsm
216 lines
3.5 KiB
ArmAsm
/* See the end of this file for copyright and license terms. */
|
|
|
|
#include <asm/common.h>
|
|
|
|
/* int arch_atom_read(const atom_t *atom) */
|
|
ASM_ENTRY(arch_atom_read)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %ecx
|
|
mov (%ecx), %eax
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_read)
|
|
|
|
/* int arch_atom_write(atom_t *atom, int val) */
|
|
ASM_ENTRY(arch_atom_write)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
mov 12(%ebp), %ecx
|
|
mov (%edx), %eax
|
|
1: lock
|
|
cmpxchgl %ecx, (%edx)
|
|
jne 1b
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_write)
|
|
|
|
/* bool arch_atom_inc(atom_t *atom) */
|
|
ASM_ENTRY(arch_atom_inc)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
lock
|
|
incl (%edx)
|
|
xor %eax, %eax
|
|
setne %al
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_inc)
|
|
|
|
/* bool arch_atom_dec(atom_t *atom) */
|
|
ASM_ENTRY(arch_atom_dec)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
lock
|
|
decl (%edx)
|
|
xor %eax, %eax
|
|
setne %al
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_dec)
|
|
|
|
/* int arch_atom_add(atom_t *atom, int val) */
|
|
ASM_ENTRY(arch_atom_add)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
mov 12(%ebp), %eax
|
|
lock
|
|
xaddl %eax, (%edx)
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_add)
|
|
|
|
/* int arch_atom_sub(atom_t *atom, int val) */
|
|
ASM_ENTRY(arch_atom_sub)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
mov 12(%ebp), %eax
|
|
/* there is no xsubl, so we add the two's complement */
|
|
not %eax
|
|
inc %eax
|
|
lock
|
|
xaddl %eax, (%edx)
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_sub)
|
|
|
|
/* int arch_atom_and(atom_t *atom, int val) */
|
|
ASM_ENTRY(arch_atom_and)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
and 12(%ebp), %ecx
|
|
lock
|
|
cmpxchgl %ecx, (%edx)
|
|
jne 1b
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_and)
|
|
|
|
/* int arch_atom_or(atom_t *atom, int val) */
|
|
ASM_ENTRY(arch_atom_or)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
and 12(%ebp), %ecx
|
|
lock
|
|
cmpxchgl %ecx, (%edx)
|
|
jne 1b
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_or)
|
|
|
|
/* int arch_atom_xor(atom_t *atom, int val) */
|
|
ASM_ENTRY(arch_atom_xor)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
|
|
mov 8(%ebp), %edx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
xor 12(%ebp), %ecx
|
|
lock
|
|
cmpxchgl %ecx, (%edx)
|
|
jne 1b
|
|
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_xor)
|
|
|
|
/* bool arch_atom_set_bit(atom_t *atom, int bit) */
|
|
ASM_ENTRY(arch_atom_set_bit)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
push %ebx
|
|
|
|
mov 8(%ebp), %edx
|
|
mov 12(%ebp), %ecx
|
|
mov $1, %ebx
|
|
shl %cl, %ebx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
or %ebx, %ecx
|
|
lock
|
|
cmpxchgl %ecx, (%edx)
|
|
jne 1b
|
|
|
|
/* return true if bit was clear before */
|
|
not %eax
|
|
and %ebx, %eax
|
|
shr %cl, %eax
|
|
|
|
pop %ebx
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_set_bit)
|
|
|
|
/* bool arch_atom_clr_bit(atom_t *atom, int bit) */
|
|
ASM_ENTRY(arch_atom_clr_bit)
|
|
push %ebp
|
|
mov %esp, %ebp
|
|
push %ebx
|
|
|
|
mov 8(%ebp), %edx
|
|
mov 12(%ebp), %ecx
|
|
mov $0xfffffffe, %ebx
|
|
rol %cl, %ebx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
and %ebx, %ecx
|
|
lock
|
|
cmpxchgl %ecx, (%edx)
|
|
jne 1b
|
|
|
|
/* return true if bit was set before */
|
|
not %ebx
|
|
and %ebx, %eax
|
|
shr %cl, %eax
|
|
|
|
pop %ebx
|
|
pop %ebp
|
|
ret
|
|
ASM_END(arch_atom_clr_bit)
|
|
|
|
/*
|
|
* This file is part of GayBSD.
|
|
* Copyright (c) 2021 fef <owo@fef.moe>.
|
|
*
|
|
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
|
* modify it under the terms of the Cooperative Nonviolent Public License
|
|
* (CNPL) as found in the LICENSE file in the source code root directory
|
|
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
|
* of the license, or (at your option) any later version.
|
|
*
|
|
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
|
* permitted by applicable law. See the CNPL for details.
|
|
*/
|