debug_helpers_asm.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <xtensa/coreasm.h>
  15. #include <xtensa/corebits.h>
  16. #include <xtensa/config/system.h>
  17. #include <xtensa/hal.h>
  18. /*
  19. * esp_backtrace_get_start(uint32_t *pc, uint32_t *sp, uint32_t *next_pc)
  20. *
  21. * High Addr
  22. * ..................
  23. * | i-3 BS |
  24. * | i-1 locals | Function B
  25. * .................. i-1 SP
  26. * | i-2 BS |
  27. * | i locals | Function A (Start of backtrace)
  28. * ------------------ i SP
  29. * | i-1 BS |
  30. * | i+1 locals | Backtracing function (e.g. esp_backtrace_print())
  31. * ------------------ i+1 SP
  32. * | i BS |
  33. * | i+2 locals | esp_backtrace_get_start() <- This function
  34. * ------------------ i+2 SP
  35. * | i+1 BS |
  36. * | i+3 locals | xthal_window_spill()
  37. * ------------------ i+3 SP
  38. * .................. Low Addr
  39. */
  40. .section .iram1, "ax"
  41. .align 4
  42. .global esp_backtrace_get_start
  43. .type esp_backtrace_get_start, @function
  44. esp_backtrace_get_start:
  45. entry a1, 32
  46. call8 xthal_window_spill //Spill registers onto stack (excluding this function)
  47. //a2, a3, a4 should be out arguments for i SP, i PC, i-1 PC respectively. Use a5 and a6 as scratch
  48. l32e a5, sp, -16 //Get i PC, which is ret addres of i+1
  49. s32i a5, a2, 0 //Store i PC to arg *pc
  50. l32e a6, sp, -12 //Get i+1 SP. Used to access i BS
  51. l32e a5, a6, -12 //Get i SP
  52. s32i a5, a3, 0 //Store i SP to arg *sp
  53. l32e a5, a6, -16 //Get i-1 PC, which is ret address of i
  54. s32i a5, a4, 0 //Store i-1 PC to arg *next_pc
  55. retw