ops.S 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. .text
  25. /* void arch_enable_ints(void); */
  26. FUNCTION(arch_enable_ints)
  27. sti
  28. ret
  29. /* void arch_disable_ints(void); */
  30. FUNCTION(arch_disable_ints)
  31. cli
  32. ret
  33. /* int atomic_swap(int *ptr, int val); */
  34. FUNCTION(atomic_swap)
  35. movl 4(%esp), %edx
  36. movl 8(%esp), %eax
  37. xchgl %eax, (%edx)
  38. ret
  39. /* int atomic_add(int *ptr, int val); */
  40. FUNCTION(atomic_add)
  41. movl 4(%esp), %edx
  42. movl 8(%esp), %eax
  43. lock
  44. xadd %eax, (%edx)
  45. ret
  46. /* int atomic_and(int *ptr, int val); */
  47. FUNCTION(atomic_and)
  48. movl 4(%esp), %edx
  49. movl (%edx), %eax
  50. 0:
  51. movl %eax, %ecx
  52. andl 8(%esp), %ecx
  53. lock
  54. cmpxchgl %ecx, (%edx)
  55. jnz 1f /* static prediction: branch forward not taken */
  56. ret
  57. 1:
  58. jmp 0b
  59. /* int atomic_or(int *ptr, int val); */
  60. FUNCTION(atomic_or)
  61. movl 4(%esp), %edx
  62. movl (%edx), %eax
  63. 0:
  64. movl %eax, %ecx
  65. orl 8(%esp), %ecx
  66. lock
  67. cmpxchgl %ecx, (%edx)
  68. jnz 1f /* static prediction: branch forward not taken */
  69. ret
  70. 1:
  71. jmp 0b
  72. /* void arch_idle(); */
  73. FUNCTION(arch_idle)
  74. pushf
  75. popl %eax
  76. andl $0x200, %eax
  77. test %eax, %eax
  78. je 1f /* don't halt if local interrupts are disabled */
  79. hlt
  80. 1:
  81. ret
  82. /* void arch_switch_stacks_and_call(addr_t call, addr_t stack) */
  83. FUNCTION(arch_switch_stacks_and_call)
  84. movl 4(%esp), %eax
  85. movl 8(%esp), %edx
  86. movl %edx, %esp
  87. call *%eax /* perhaps this should be a jmp? it's not used anywhere so I don't know. */