1 /*
2 * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <stdint.h>
7 #include <string.h>
8
9 #include "esp_system.h"
10 #include "esp_cpu.h"
11
12 #include "soc/soc_caps.h"
13
abort(void)14 void __attribute__((noreturn)) abort(void)
15 {
16 #define ERR_STR1 "abort() was called at PC 0x"
17 #define ERR_STR2 " on core "
18
19 _Static_assert(UINTPTR_MAX == 0xffffffff, "abort() assumes 32-bit addresses");
20 _Static_assert(SOC_CPU_CORES_NUM < 10, "abort() assumes number of cores is 1 to 9");
21
22 char addr_buf[9] = { 0 };
23 char core_buf[2] = { 0 };
24
25 char buf[sizeof(ERR_STR1) + sizeof(addr_buf) + sizeof(core_buf) + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };
26
27 itoa((uint32_t)(__builtin_return_address(0) - 3), addr_buf, 16);
28 itoa(esp_cpu_get_core_id(), core_buf, 10);
29
30 const char *str[] = { ERR_STR1, addr_buf, ERR_STR2, core_buf };
31
32 char *dest = buf;
33
34 for (size_t i = 0; i < sizeof(str) / sizeof(str[0]); i++) {
35 strcat(dest, str[i]);
36 }
37
38 esp_system_abort(buf);
39 }
40