You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
2.9 KiB
ArmAsm
186 lines
2.9 KiB
ArmAsm
/* See the end of this file for copyright and license terms. */
|
|
|
|
#include <asm/common.h>
|
|
|
|
/* int atom_read(const atom_t *atom) */
|
|
ASM_ENTRY(atom_read)
|
|
mov 4(%esp), %ecx
|
|
mov (%ecx), %eax
|
|
|
|
ret
|
|
ASM_END(atom_read)
|
|
|
|
/* int atom_write(atom_t *atom, int val) */
|
|
ASM_ENTRY(atom_write)
|
|
mov 4(%esp), %edx
|
|
mov 8(%esp), %ecx
|
|
mov (%edx), %eax
|
|
|
|
1: lock
|
|
cmpxchg %ecx, (%edx)
|
|
pause
|
|
jne 1b
|
|
|
|
ret
|
|
ASM_END(atom_write)
|
|
|
|
/* bool atom_inc(atom_t *atom) */
|
|
ASM_ENTRY(atom_inc)
|
|
mov 4(%esp), %edx
|
|
|
|
lock
|
|
incl (%edx)
|
|
xor %eax, %eax
|
|
setne %al
|
|
|
|
ret
|
|
ASM_END(atom_inc)
|
|
|
|
/* bool atom_dec(atom_t *atom) */
|
|
ASM_ENTRY(atom_dec)
|
|
mov 4(%esp), %edx
|
|
|
|
lock
|
|
decl (%edx)
|
|
xor %eax, %eax
|
|
setne %al
|
|
|
|
ret
|
|
ASM_END(atom_dec)
|
|
|
|
/* int atom_add(atom_t *atom, int val) */
|
|
ASM_ENTRY(atom_add)
|
|
mov 4(%esp), %edx
|
|
mov 8(%esp), %eax
|
|
|
|
lock
|
|
xadd %eax, (%edx)
|
|
|
|
ret
|
|
ASM_END(atom_add)
|
|
|
|
/* int atom_sub(atom_t *atom, int val) */
|
|
ASM_ENTRY(atom_sub)
|
|
mov 4(%esp), %edx
|
|
mov 8(%esp), %eax
|
|
|
|
/* there is no xsubl, so we add the two's complement */
|
|
neg %eax
|
|
lock
|
|
xadd %eax, (%edx)
|
|
|
|
ret
|
|
ASM_END(atom_sub)
|
|
|
|
/* int atom_and(atom_t *atom, int val) */
|
|
ASM_ENTRY(atom_and)
|
|
mov 4(%esp), %edx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
and 8(%esp), %ecx
|
|
lock
|
|
cmpxchg %ecx, (%edx)
|
|
pause
|
|
jne 1b
|
|
|
|
ret
|
|
ASM_END(atom_and)
|
|
|
|
/* int atom_or(atom_t *atom, int val) */
|
|
ASM_ENTRY(atom_or)
|
|
mov 4(%esp), %edx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
and 8(%esp), %ecx
|
|
lock
|
|
cmpxchg %ecx, (%edx)
|
|
pause
|
|
jne 1b
|
|
|
|
ret
|
|
ASM_END(atom_or)
|
|
|
|
/* int atom_xor(atom_t *atom, int val) */
|
|
ASM_ENTRY(atom_xor)
|
|
mov 4(%esp), %edx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
xor 8(%esp), %ecx
|
|
lock
|
|
cmpxchg %ecx, (%edx)
|
|
pause
|
|
jne 1b
|
|
|
|
ret
|
|
ASM_END(atom_xor)
|
|
|
|
/* bool atom_set_bit(atom_t *atom, int bit) */
|
|
ASM_ENTRY(atom_set_bit)
|
|
mov 4(%esp), %edx
|
|
mov 8(%esp), %ecx
|
|
|
|
push %ebx
|
|
mov $1, %ebx
|
|
shl %cl, %ebx
|
|
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
or %ebx, %ecx
|
|
lock
|
|
cmpxchg %ecx, (%edx)
|
|
pause
|
|
jne 1b
|
|
|
|
/* return true if bit was clear before */
|
|
not %eax
|
|
and %ebx, %eax
|
|
shr %cl, %eax
|
|
|
|
pop %ebx
|
|
ret
|
|
ASM_END(atom_set_bit)
|
|
|
|
/* bool atom_clr_bit(atom_t *atom, int bit) */
|
|
ASM_ENTRY(atom_clr_bit)
|
|
mov 4(%esp), %edx
|
|
mov 8(%esp), %ecx
|
|
|
|
push %ebx
|
|
mov $0xfffffffe, %ebx
|
|
rol %cl, %ebx
|
|
mov (%edx), %eax
|
|
|
|
1: mov %eax, %ecx
|
|
and %ebx, %ecx
|
|
lock
|
|
cmpxchg %ecx, (%edx)
|
|
pause
|
|
jne 1b
|
|
|
|
/* return true if bit was set before */
|
|
not %ebx
|
|
and %ebx, %eax
|
|
shr %cl, %eax
|
|
|
|
pop %ebx
|
|
ret
|
|
ASM_END(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.
|
|
*/
|