// Copyright 2020-2021 Beken // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include #include #include "boot.h" #include "bk_arch.h" #include "bk_uart.h" #include #include #include #if CONFIG_TRNG_SUPPORT #include #endif #include #define TAG "Stack" #define STACK_DUMP_MEMORY 0 #define STACK_CALLBACK_BUF_SIZE 32 extern char __executable_start; extern char __etext; extern char _itcm_ema_start, _itcm_ema_end; static int addr_is_in_flash_txt(uint32_t addr) { return ((addr > 0x100) && (addr < (uint32_t)&__etext)); } static int addr_is_in_itcm_txt(uint32_t addr) { return ((addr > (uint32_t)&_itcm_ema_start) && (addr < (uint32_t)&_itcm_ema_end)); } static int code_addr_is_valid(uint32_t addr) { return (addr_is_in_flash_txt(addr) || addr_is_in_itcm_txt(addr)); } void stack_mem_dump(uint32_t stack_top, uint32_t stack_bottom) { unsigned char *data = NULL; volatile uint32_t value = 0; uint32_t cnt = 0; uint32_t sp = stack_top; uint32_t fp = stack_bottom; BK_DUMP_OUT(">>>>stack mem dump begin, stack_top=%08x, stack end=%08x\r\n", stack_top, stack_bottom); for (; sp < fp; sp += sizeof(size_t)) { value = os_get_word(sp); data = ((unsigned char *)&value); if ((cnt++ & 0x7) == 0) { BK_DUMP_OUT("\r\n"); } #if CONFIG_DEBUG_FIRMWARE || CONFIG_DUMP_ENABLE #if CONFIG_INT_WDT if((cnt & 0x7f) == 0) { void bk_wdt_force_feed(void); bk_wdt_force_feed(); } #endif // #if CONFIG_INT_WDT #endif //#if CONFIG_DEBUG_FIRMWARE || CONFIG_DUMP_ENABLE BK_DUMP_OUT("%02x %02x %02x %02x ", data[0], data[1], data[2], data[3]); } BK_DUMP_OUT("\r\n"); BK_DUMP_OUT("<<< 0) { int index; BK_DUMP_OUT("%-16s [0x%-6x ~ 0x%-6x] 0x%-6x %-4d %-8d ", str_type, stack_minimum, stack_bottom, init_stack_top, stack_size, init_stack_top < stack_minimum); for (index = 0; index < call_stack_index; index++) BK_DUMP_OUT("%lx ", call_stack_buf[index]); BK_DUMP_OUT("\r\n"); } else if (init_stack_top < stack_minimum) { BK_DUMP_OUT("%-16s [0x%-6x ~ 0x%-6x] 0x%-6x %-4d %-8d ", str_type, stack_minimum, stack_bottom, init_stack_top, stack_size, init_stack_top < stack_minimum); } }