275275#include < esp8266_peri.h>
276276#include < uart.h>
277277#include < pgmspace.h>
278+ #include " mmu_iram.h"
278279
279280extern " C" {
280281#include < user_interface.h>
@@ -1007,6 +1008,18 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
10071008#endif
10081009}
10091010
1011+ #if defined(DEBUG_ESP_HWDT_DEV_DEBUG) && !defined(USE_IRAM)
1012+ static void printSanityCheck () {
1013+ ETS_PRINTF (" \n\n sys_stack_first: %p\n " , sys_stack_first);
1014+ ETS_PRINTF ( " CONT_STACK: %p\n " , CONT_STACK);
1015+ ETS_PRINTF ( " g_pcont: %p\n " , g_pcont);
1016+ ETS_PRINTF ( " ROM_STACK: %p\n " , ROM_STACK);
1017+ ETS_PRINTF ( " get_noextra4k_g_pcont(): %p\n " , get_noextra4k_g_pcont ());
1018+ ETS_PRINTF ( " g_rom_stack: %p\n " , g_rom_stack);
1019+ ETS_PRINTF ( " g_rom_stack_A16_sz: 0x%08X\n\n " , g_rom_stack_A16_sz);
1020+ }
1021+ #endif // DEBUG_ESP_HWDT_DEV_DEBUG
1022+
10101023/*
10111024 * Using Cache_Read_Enable/Cache_Read_Disable to reduce IRAM usage. Moved
10121025 * strings and most functions to flash. At this phase of the startup, "C++" has
@@ -1019,34 +1032,11 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
10191032 * https://richard.burtons.org/2015/06/12/esp8266-cache_read_enable/.
10201033 * Additional insight can be gleemed from reviewing the ESP8266_RTOS_SDK.
10211034 * (eg. ../components/bootloader_support/src/bootloader_utility.c)
1035+ *
1036+ * The logic to use Cache_Read_Enable and Cache_Read_Disable has been
1037+ * generalized into a wrapper function, mmu_wrap_irom_fn, and moved to
1038+ * mmu_iram.cpp.
10221039 */
1023- #define ICACHE_SIZE_32 1
1024- #define ICACHE_SIZE_16 0
1025-
1026- extern " C" void Cache_Read_Disable (void );
1027- extern " C" void Cache_Read_Enable (uint8_t map, uint8_t p, uint8_t v);
1028-
1029- #ifndef USE_IRAM
1030- static void IRAM_ATTR __attribute__ ((noinline)) handle_hwdt_icache() __attribute__((used));
1031- void handle_hwdt_icache () {
1032- Cache_Read_Enable (0 , 0 , ICACHE_SIZE_16);
1033- handle_hwdt ();
1034- Cache_Read_Disable ();
1035- }
1036- #endif // USE_IRAM
1037-
1038-
1039- #if defined(DEBUG_ESP_HWDT_DEV_DEBUG) && !defined(USE_IRAM)
1040- static void printSanityCheck () {
1041- ETS_PRINTF (" \n\n sys_stack_first: %p\n " , sys_stack_first);
1042- ETS_PRINTF ( " CONT_STACK: %p\n " , CONT_STACK);
1043- ETS_PRINTF ( " g_pcont: %p\n " , g_pcont);
1044- ETS_PRINTF ( " ROM_STACK: %p\n " , ROM_STACK);
1045- ETS_PRINTF ( " get_noextra4k_g_pcont(): %p\n " , get_noextra4k_g_pcont ());
1046- ETS_PRINTF ( " g_rom_stack: %p\n " , g_rom_stack);
1047- ETS_PRINTF ( " g_rom_stack_A16_sz: 0x%08X\n\n " , g_rom_stack_A16_sz);
1048- }
1049- #endif // DEBUG_ESP_HWDT_DEV_DEBUG
10501040
10511041/*
10521042 hwdt_pre_sdk_init() is the result of a hook for development diagnotics which
@@ -1071,9 +1061,8 @@ void hwdt_pre_sdk_init(void) {
10711061#endif
10721062}
10731063
1074- static void IRAM_ATTR __attribute__ ((noinline)) hwdt_pre_sdk_init_icache(void ) __attribute__((used));
1064+ static void __attribute__ ((noinline)) hwdt_pre_sdk_init_icache(void ) __attribute__((used));
10751065void hwdt_pre_sdk_init_icache (void ) {
1076- Cache_Read_Enable (0 , 0 , ICACHE_SIZE_16);
10771066#ifdef DEBUG_ESP_HWDT_UART_SPEED
10781067 const uint32_t uart_divisor = set_uart_speed (0 , DEBUG_ESP_HWDT_UART_SPEED);
10791068#endif
@@ -1085,7 +1074,6 @@ void hwdt_pre_sdk_init_icache(void) {
10851074 adjust_uart_speed (uart_divisor);
10861075 }
10871076#endif
1088- Cache_Read_Disable ();
10891077}
10901078
10911079/*
@@ -1106,6 +1094,7 @@ asm (
11061094 " .literal .umm_init, umm_init\n\t "
11071095 " .literal .call_user_start, call_user_start\n\t "
11081096 " .literal .get_noextra4k_g_pcont, get_noextra4k_g_pcont\n\t "
1097+ " .literal .mmu_wrap_irom_fn, mmu_wrap_irom_fn\n\t "
11091098 " .align 4\n\t "
11101099 " .global app_entry_redefinable\n\t "
11111100 " .type app_entry_redefinable, @function\n\t "
@@ -1129,7 +1118,9 @@ asm (
11291118#ifdef USE_IRAM
11301119 " call0 handle_hwdt\n\t "
11311120#else
1132- " call0 handle_hwdt_icache\n\t "
1121+ " l32r a0, .mmu_wrap_irom_fn\n\t "
1122+ " movi a2, handle_hwdt\n\t "
1123+ " callx0 a0\n\t "
11331124#endif
11341125 /*
11351126 * Use new calculated SYS stack from top.
@@ -1160,7 +1151,9 @@ asm (
11601151 /*
11611152 * Allow for running additional diagnotics supplied at link time.
11621153 */
1163- " call0 hwdt_pre_sdk_init_icache\n\t "
1154+ " l32r a0, .mmu_wrap_irom_fn\n\t "
1155+ " movi a2, hwdt_pre_sdk_init_icache\n\t "
1156+ " callx0 a0\n\t "
11641157
11651158 // In case somebody cares, leave things as we found them
11661159 // - Restore ROM BSS zeros.
@@ -1174,7 +1167,12 @@ asm (
11741167 * improvements could possibly use hwdt_pre_sdk_init() to run other early
11751168 * diagnostic tools.
11761169 */
1170+ #ifdef UMM_INIT_USE_IRAM
11771171 " l32r a0, .umm_init\n\t "
1172+ #else
1173+ " l32r a0, .mmu_wrap_irom_fn\n\t "
1174+ " l32r a2, .umm_init\n\t "
1175+ #endif
11781176 " callx0 a0\n\t "
11791177
11801178 " l32r a3, .call_user_start\n\t "
0 commit comments