asm.S 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  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. /* context switch frame is as follows:
  25. * ulr
  26. * usp
  27. * lr
  28. * r11
  29. * r10
  30. * r9
  31. * r8
  32. * r7
  33. * r6
  34. * r5
  35. * r4
  36. */
  37. /* arm_context_switch(addr_t *old_sp, addr_t new_sp) */
  38. FUNCTION(arm_context_switch)
  39. /* save all the usual registers + user regs */
  40. /* the spsr is saved and restored in the iframe by exceptions.S */
  41. sub r3, sp, #(11*4) /* can't use sp in user mode stm */
  42. mov r12, lr
  43. stmia r3, { r4-r11, r12, r13, r14 }^
  44. /* save old sp */
  45. str r3, [r0]
  46. /* clear any exlusive locks that the old thread holds */
  47. #if ARM_ISA_ARMV7
  48. /* can clear it directly */
  49. .word 0xf57ff01f // clrex
  50. #elif ARM_ISA_ARMV6
  51. /* have to do a fake strex to clear it */
  52. ldr r0, =strex_spot
  53. strex r3, r2, [r0]
  54. #endif
  55. /* load new regs */
  56. ldmia r1, { r4-r11, r12, r13, r14 }^
  57. mov lr, r12 /* restore lr */
  58. add sp, r1, #(11*4) /* restore sp */
  59. bx lr
  60. .ltorg
  61. FUNCTION(arm_save_mode_regs)
  62. mrs r1, cpsr
  63. cps #0x11 /* fiq */
  64. str r13, [r0], #4
  65. str r14, [r0], #4
  66. cps #0x12 /* irq */
  67. str r13, [r0], #4
  68. str r14, [r0], #4
  69. cps #0x13 /* svc */
  70. str r13, [r0], #4
  71. str r14, [r0], #4
  72. cps #0x17 /* abt */
  73. str r13, [r0], #4
  74. str r14, [r0], #4
  75. cps #0x1b /* und */
  76. str r13, [r0], #4
  77. str r14, [r0], #4
  78. cps #0x1f /* sys */
  79. str r13, [r0], #4
  80. str r14, [r0], #4
  81. msr cpsr_c, r1
  82. bx lr
  83. .data
  84. strex_spot:
  85. .word 0