blob: 9a97948afe440d71ec3be3c96adc22a77651b67c [file] [log] [blame]
Corey Tabaka84697242009-03-26 02:32:01 -04001/*
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/* void arch_enable_ints(void); */
28FUNCTION(arch_enable_ints)
29 sti
30 ret
31
32/* void arch_disable_ints(void); */
33FUNCTION(arch_disable_ints)
34 cli
35 ret
36
37/* int atomic_swap(int *ptr, int val); */
38FUNCTION(atomic_swap)
39 movl 4(%esp), %edx
40 movl 8(%esp), %eax
41 xchgl %eax, (%edx)
42 ret
43
44/* int atomic_add(int *ptr, int val); */
45FUNCTION(atomic_add)
46 movl 4(%esp), %edx
47 movl 8(%esp), %eax
48 lock
49 xadd %eax, (%edx)
50 ret
51
52/* int atomic_and(int *ptr, int val); */
53FUNCTION(atomic_and)
54 movl 4(%esp), %edx
55 movl (%edx), %eax
560:
57 movl %eax, %ecx
58 andl 8(%esp), %ecx
59 lock
60 cmpxchgl %ecx, (%edx)
61 jnz 1f /* static prediction: branch forward not taken */
62 ret
631:
64 jmp 0b
65
66
67/* int atomic_or(int *ptr, int val); */
68FUNCTION(atomic_or)
69movl 4(%esp), %edx
70 movl (%edx), %eax
710:
72 movl %eax, %ecx
73 orl 8(%esp), %ecx
74 lock
75 cmpxchgl %ecx, (%edx)
76 jnz 1f /* static prediction: branch forward not taken */
77 ret
781:
79 jmp 0b
80
81/* void arch_idle(); */
82FUNCTION(arch_idle)
Corey Tabakaad21b8d2009-04-03 15:34:38 -040083 pushf
84 popl %eax
85 andl $0x200, %eax
86 test %eax, %eax
87 je 1f /* don't halt if local interrupts are disabled */
Corey Tabaka84697242009-03-26 02:32:01 -040088 hlt
Corey Tabakaad21b8d2009-04-03 15:34:38 -0400891:
Corey Tabaka84697242009-03-26 02:32:01 -040090 ret
91
92/* void arch_switch_stacks_and_call(addr_t call, addr_t stack) */
93FUNCTION(arch_switch_stacks_and_call)
94 movl 4(%esp), %eax
95 movl 8(%esp), %edx
96 movl %edx, %esp
97 call *%eax /* perhaps this should be a jmp? it's not used anywhere so I don't know. */