blob: 32a098c1ac7c0c3f6e131b147577737b53607edf [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2009 Corey Tabaka
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <asm.h>
24
25.text
26
27/* int _atomic_and(int *ptr, int val); */
28FUNCTION(_atomic_and)
29 movl 4(%esp), %edx
30 movl (%edx), %eax
310:
32 movl %eax, %ecx
33 andl 8(%esp), %ecx
34 lock
35 cmpxchgl %ecx, (%edx)
36 jnz 1f /* static prediction: branch forward not taken */
37 ret
381:
39 jmp 0b
40
41
42/* int _atomic_or(int *ptr, int val); */
43FUNCTION(_atomic_or)
44movl 4(%esp), %edx
45 movl (%edx), %eax
460:
47 movl %eax, %ecx
48 orl 8(%esp), %ecx
49 lock
50 cmpxchgl %ecx, (%edx)
51 jnz 1f /* static prediction: branch forward not taken */
52 ret
531:
54 jmp 0b
55
56/* void arch_idle(); */
57FUNCTION(arch_idle)
58 pushf
59 popl %eax
60 andl $0x200, %eax
61 test %eax, %eax
62 je 1f /* don't halt if local interrupts are disabled */
63 hlt
641:
65 ret
66