Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 1 | /* |
| 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); */ |
| 28 | FUNCTION(arch_enable_ints) |
| 29 | sti |
| 30 | ret |
| 31 | |
| 32 | /* void arch_disable_ints(void); */ |
| 33 | FUNCTION(arch_disable_ints) |
| 34 | cli |
| 35 | ret |
| 36 | |
| 37 | /* int atomic_swap(int *ptr, int val); */ |
| 38 | FUNCTION(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); */ |
| 45 | FUNCTION(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); */ |
| 53 | FUNCTION(atomic_and) |
| 54 | movl 4(%esp), %edx |
| 55 | movl (%edx), %eax |
| 56 | 0: |
| 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 |
| 63 | 1: |
| 64 | jmp 0b |
| 65 | |
| 66 | |
| 67 | /* int atomic_or(int *ptr, int val); */ |
| 68 | FUNCTION(atomic_or) |
| 69 | movl 4(%esp), %edx |
| 70 | movl (%edx), %eax |
| 71 | 0: |
| 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 |
| 78 | 1: |
| 79 | jmp 0b |
| 80 | |
| 81 | /* void arch_idle(); */ |
| 82 | FUNCTION(arch_idle) |
Corey Tabaka | ad21b8d | 2009-04-03 15:34:38 -0400 | [diff] [blame] | 83 | pushf |
| 84 | popl %eax |
| 85 | andl $0x200, %eax |
| 86 | test %eax, %eax |
| 87 | je 1f /* don't halt if local interrupts are disabled */ |
Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 88 | hlt |
Corey Tabaka | ad21b8d | 2009-04-03 15:34:38 -0400 | [diff] [blame] | 89 | 1: |
Corey Tabaka | 8469724 | 2009-03-26 02:32:01 -0400 | [diff] [blame] | 90 | ret |
| 91 | |
| 92 | /* void arch_switch_stacks_and_call(addr_t call, addr_t stack) */ |
| 93 | FUNCTION(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. */ |