JLINKDCC_HandleDataAbort.s 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH *
  3. * The Embedded Experts *
  4. **********************************************************************
  5. * *
  6. * (c) 2006 - 2019 SEGGER Microcontroller GmbH *
  7. * *
  8. * www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. * *
  12. * All rights reserved. *
  13. * *
  14. * Redistribution and use in source and binary forms, with or *
  15. * without modification, are permitted provided that the following *
  16. * condition is met: *
  17. * *
  18. * o Redistributions of source code must retain the above copyright *
  19. * notice, this condition and the following disclaimer. *
  20. * *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  22. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
  23. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
  25. * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
  26. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
  28. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
  29. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
  32. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
  33. * DAMAGE. *
  34. * *
  35. **********************************************************************
  36. -------------------------- END-OF-HEADER -----------------------------
  37. File : JLINKDCC_HandleDataAbort.s
  38. Purpose : Data abort handler for ARM J-Link type communication via DCC
  39. Notes : (1) How to use
  40. In order to use the DCC abort handler, 3 things need to be done:
  41. * Place a branch to DCC_Abort at address 0x10 ("vector" used for data aborts)
  42. * Initialize the Abort-mode stack pointer to an area of at least 8 bytes of stack
  43. memory required by the handler
  44. * Add the DCC abort handler assembly file to the application
  45. (2) Compatibility
  46. The J-Link ARM DCC handler is compatible to the DCC communication
  47. protocol used by IAR in the embedded workbench for ARM and allows
  48. using the live data window in C-Spy
  49. */
  50. /*********************************************************************
  51. *
  52. * GNU ARM
  53. *
  54. */
  55. .text
  56. .extern JLINKDCC_IsInHandler
  57. .extern JLINKDCC_AbortOccurred
  58. .global JLINKDCC_HandleDataAbort
  59. .arm
  60. .section .text, "ax"
  61. /*********************************************************************
  62. *
  63. * Public code
  64. *
  65. **********************************************************************
  66. */
  67. /*********************************************************************
  68. *
  69. * JLINKDCC_HandleDataAbort
  70. *
  71. * Function description
  72. * Data abort handler for J-Link ARM type DCC communication.
  73. *
  74. * Notes
  75. * (1) Abort mode
  76. * This handler is supposed to be executed in abort mode by simply placing a
  77. * jump to the handler at address 0x10.
  78. * Just like an interrupt service routine, it needs to restore all registers
  79. * for other modes and may only permanently modify registers of abort mode (SPSR_ABT, R14_ABT)
  80. */
  81. JLINKDCC_HandleDataAbort:
  82. @
  83. @ Check if exception stemmed from JLINKARM DCC communication. Otherwise, user abort handler is called
  84. @
  85. STMDB SP!, {R0,R1} @ Save registers on stack
  86. LDR R1, =JLINKDCC_IsInHandler
  87. LDRB R0, [R1, #0]
  88. TST R0, R0 @ Check if abort occurred during execution of DCC handler
  89. LDMEQIA SP!, {R0,R1} @ Restore registers
  90. BEQ UserAbortHandler
  91. @
  92. @ Set JLINKDCC_AbortOccurred so PC (via J-Link) has a chance to find out that memory operation was aborted
  93. @
  94. LDR R1, =JLINKDCC_AbortOccurred
  95. STRB R0, [R1, #0] @ Set abort occurred state
  96. @
  97. @ Continue code execution right after the instruction which caused the abort.
  98. @
  99. MRS R0, SPSR
  100. TST R0, #0x20 @ Check thumb bit
  101. LDMIA SP!, {R0,R1} @ Restore registers
  102. SUBEQS PC, R14, #4 @ Return after the aborted instruction (ARM mode)
  103. SUBS PC, R14, #6 @ Return after the aborted instruction (Thumb mode)
  104. /*********************************************************************
  105. *
  106. * UserAbortHandler
  107. *
  108. * Function description
  109. * User defined abort handler.
  110. * This function is called if a data abort occurs for other reasons than JLINK DCC comunication.
  111. * Feel free to modify and jump to your own handler as required.
  112. */
  113. UserAbortHandler:
  114. B UserAbortHandler @ Modify this line to jump to your own handler if desired
  115. .end
  116. /*************************** end of file ****************************/