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