cpu.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _SOC_CPU_H
  7. #define _SOC_CPU_H
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include <stddef.h>
  11. #include "esp_cpu.h"
  12. #if __XTENSA__
  13. #include "xt_instr_macros.h"
  14. // [refactor-todo] not actually needed in this header now,
  15. // but kept for compatibility
  16. #include "xtensa/corebits.h"
  17. #include "xtensa/config/core.h"
  18. #include "xtensa/config/specreg.h"
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /** @brief Read current stack pointer address.
  24. * Superseded by esp_cpu_get_sp in esp_cpu.h.
  25. */
  26. static inline __attribute__((deprecated)) void *get_sp(void)
  27. {
  28. return esp_cpu_get_sp();
  29. }
  30. static inline uint32_t esp_cpu_process_stack_pc(uint32_t pc)
  31. {
  32. if (pc & 0x80000000) {
  33. //Top two bits of a0 (return address) specify window increment. Overwrite to map to address space.
  34. pc = (pc & 0x3fffffff) | 0x40000000;
  35. }
  36. //Minus 3 to get PC of previous instruction (i.e. instruction executed before return address)
  37. return pc - 3;
  38. }
  39. /**
  40. * @brief Configure CPU to disable access to invalid memory regions
  41. *
  42. */
  43. void esp_cpu_configure_region_protection(void);
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif