1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stdbool.h>
7 #include <stdlib.h>
8 #include <string.h>
9 
10 #include "esp_err.h"
11 #include "spi_flash_mmap.h"
12 #include "esp_private/cache_utils.h"
13 
14 #include "esp_rom_sys.h"
15 
16 #ifndef CONFIG_IDF_TARGET_LINUX
17     #include "esp_cpu.h"
18 #else
19     /* esp_cpu.h isn't available when building for Linux */
esp_cpu_get_call_addr(intptr_t return_address)20     static intptr_t esp_cpu_get_call_addr(intptr_t return_address)
21     {
22         /* on x86, there is no hope to get the address of the previous instruction */
23         return return_address;
24     }
25 #endif
26 
esp_error_check_failed_print(const char * msg,esp_err_t rc,const char * file,int line,const char * function,const char * expression,intptr_t addr)27 static void esp_error_check_failed_print(const char *msg, esp_err_t rc, const char *file, int line, const char *function, const char *expression, intptr_t addr)
28 {
29     esp_rom_printf("%s failed: esp_err_t 0x%x", msg, rc);
30 #ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP
31     esp_rom_printf(" (%s)", esp_err_to_name(rc));
32 #endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP
33     esp_rom_printf(" at 0x%08x\n", esp_cpu_get_call_addr(addr));
34 #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
35     if (spi_flash_cache_enabled())  // strings may be in flash cache
36 #endif
37     {
38         esp_rom_printf("file: \"%s\" line %d\nfunc: %s\nexpression: %s\n", file, line, function, expression);
39     }
40 }
41 
_esp_error_check_failed_without_abort(esp_err_t rc,const char * file,int line,const char * function,const char * expression)42 void _esp_error_check_failed_without_abort(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
43 {
44     esp_error_check_failed_print("ESP_ERROR_CHECK_WITHOUT_ABORT", rc, file, line, function, expression, (intptr_t)__builtin_return_address(0));
45 }
46 
_esp_error_check_failed(esp_err_t rc,const char * file,int line,const char * function,const char * expression)47 void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
48 {
49     esp_error_check_failed_print("ESP_ERROR_CHECK", rc, file, line, function, expression, (intptr_t)__builtin_return_address(0));
50     abort();
51 }
52