arm-swi.S 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2008 by Duane Ellis
  3. *
  4. * All rights reserved.
  5. *
  6. * The original code had been released as part of the LoastARM Project
  7. * under GPL Version 2 and is published here under the following license
  8. * with kind permission from the author:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the copyright holders nor the names of
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  33. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * For additional information see http://lostarm.sourceforge.net/
  37. */
  38. /*!
  39. * \file arch/arm/debug/arm-swi.S
  40. *
  41. * \verbatim
  42. * $Id: arm-swi.S 2399 2009-01-16 19:39:07Z haraldkipp $
  43. * \endverbatim
  44. */
  45. #include <arch/arm.h>
  46. #include <arch/arm/ptrace.h>
  47. #include <arch/arm/exception_asm.h>
  48. .section .text,"ax","progbits"
  49. nop /* put this here so we can see the symbol below */
  50. .global __swi
  51. .type __swi, function
  52. __swi:
  53. exception_enter ARM_SVC_MODE, PTRACE_FRAMETYPE_swi
  54. /* We need the SVC sp, not something else! */
  55. /* pass frame in R0 */
  56. mov r0,sp
  57. /* Switch to supervisor mode */
  58. /* We use r5 here - cause it is saved!*/
  59. /* fetch cpsr - need T bit for thumb test */
  60. ldr r2,[r0,#(PTRACE_CPSR_idx*4)]
  61. /* fetch PC */
  62. ldr r1,[r0,#(PTRACE_R15_idx*4)]
  63. /* TBit Test */
  64. tst r2,#0x20
  65. /* Thumb condition */
  66. ldrneh r1,[r1,#-2]
  67. bicne r1,r1,#0xff00
  68. /* ARM condition */
  69. ldreq r1,[r1,#-4]
  70. biceq r1,r1,#0xff000000
  71. /* Save SWI code */
  72. str r1,[r0,#(PTRACE_SWICODE_idx*4)]
  73. mov r1,#PTRACE_FRAMETYPE_swi
  74. str r1,[r0,#(PTRACE_FRAMETYPE_idx*4)]
  75. ldr r1,=ARM_SWI_Handler
  76. mov lr,pc
  77. bx r1
  78. exception_exit ARM_SVC_MODE
  79. nop
  80. .size __swi, (. - __swi)