abort.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <stdint.h>
  14. #include <string.h>
  15. #include "esp_system.h"
  16. #include "soc/soc_caps.h"
  17. #include "hal/cpu_hal.h"
  18. void __attribute__((noreturn)) abort(void)
  19. {
  20. #define ERR_STR1 "abort() was called at PC 0x"
  21. #define ERR_STR2 " on core "
  22. _Static_assert(UINTPTR_MAX == 0xffffffff, "abort() assumes 32-bit addresses");
  23. _Static_assert(SOC_CPU_CORES_NUM < 10, "abort() assumes number of cores is 1 to 9");
  24. char addr_buf[9] = { 0 };
  25. char core_buf[2] = { 0 };
  26. char buf[sizeof(ERR_STR1) + sizeof(addr_buf) + sizeof(core_buf) + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };
  27. itoa((uint32_t)(__builtin_return_address(0) - 3), addr_buf, 16);
  28. itoa(cpu_ll_get_core_id(), core_buf, 10);
  29. const char *str[] = { ERR_STR1, addr_buf, ERR_STR2, core_buf };
  30. char *dest = buf;
  31. for (size_t i = 0; i < sizeof(str) / sizeof(str[0]); i++) {
  32. strcat(dest, str[i]);
  33. }
  34. esp_system_abort(buf);
  35. }