esp_cpu_utils.h 757 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ESP_CPU_UTILS_H
  7. #define _ESP_CPU_UTILS_H
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * @brief Fetch the PC value of the previous instruction
  13. *
  14. * @param pc PC value of the current backtrace frame
  15. *
  16. */
  17. static inline uint32_t esp_cpu_process_stack_pc(uint32_t pc)
  18. {
  19. if (pc & 0x80000000) {
  20. //Top two bits of a0 (return address) specify window increment. Overwrite to map to address space.
  21. pc = (pc & 0x3fffffff) | 0x40000000;
  22. }
  23. //Minus 3 to get PC of previous instruction (i.e. instruction executed before return address)
  24. return pc - 3;
  25. }
  26. #ifdef __cplusplus
  27. }
  28. #endif
  29. #endif // _ESP_CPU_UTILS_H