1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <stdint.h>
15 #include <string.h>
16
17 #include "esp_system.h"
18
19 #include "soc/soc_caps.h"
20 #include "hal/cpu_hal.h"
21 #include "los_task.h"
22
abort(void)23 void __attribute__((noreturn)) abort(void)
24 {
25 #define ERR_STR1 "abort() was called at PC 0x"
26 #define ERR_STR2 " on core "
27
28 _Static_assert(UINTPTR_MAX == 0xffffffff, "abort() assumes 32-bit addresses");
29 _Static_assert(SOC_CPU_CORES_NUM < 10, "abort() assumes number of cores is 1 to 9");
30
31 char addr_buf[9] = { 0 };
32 char core_buf[2] = { 0 };
33
34 char buf[sizeof(ERR_STR1) + sizeof(addr_buf) + sizeof(core_buf) + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };
35
36 itoa((uint32_t)(__builtin_return_address(0) - 3), addr_buf, 16);
37 itoa(cpu_ll_get_core_id(), core_buf, 10);
38
39 const char *str[] = { ERR_STR1, addr_buf, ERR_STR2, core_buf };
40
41 char *dest = buf;
42
43 for (size_t i = 0; i < sizeof(str) / sizeof(str[0]); i++) {
44 strcat(dest, str[i]);
45 }
46 {
47 char *name = g_losTask.runTask ? g_losTask.runTask->taskName : NULL;
48 esp_rom_printf("taskName=%s\r\n",name ? name : "NULL");
49 }
50 esp_system_abort(buf);
51 }
52