275
275
#include < esp8266_peri.h>
276
276
#include < uart.h>
277
277
#include < pgmspace.h>
278
+ #include " mmu_iram.h"
278
279
279
280
extern " C" {
280
281
#include < user_interface.h>
@@ -1007,6 +1008,18 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
1007
1008
#endif
1008
1009
}
1009
1010
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
+
1010
1023
/*
1011
1024
* Using Cache_Read_Enable/Cache_Read_Disable to reduce IRAM usage. Moved
1012
1025
* 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) {
1019
1032
* https://richard.burtons.org/2015/06/12/esp8266-cache_read_enable/.
1020
1033
* Additional insight can be gleemed from reviewing the ESP8266_RTOS_SDK.
1021
1034
* (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.
1022
1039
*/
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
1050
1040
1051
1041
/*
1052
1042
hwdt_pre_sdk_init() is the result of a hook for development diagnotics which
@@ -1071,9 +1061,8 @@ void hwdt_pre_sdk_init(void) {
1071
1061
#endif
1072
1062
}
1073
1063
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));
1075
1065
void hwdt_pre_sdk_init_icache (void ) {
1076
- Cache_Read_Enable (0 , 0 , ICACHE_SIZE_16);
1077
1066
#ifdef DEBUG_ESP_HWDT_UART_SPEED
1078
1067
const uint32_t uart_divisor = set_uart_speed (0 , DEBUG_ESP_HWDT_UART_SPEED);
1079
1068
#endif
@@ -1085,7 +1074,6 @@ void hwdt_pre_sdk_init_icache(void) {
1085
1074
adjust_uart_speed (uart_divisor);
1086
1075
}
1087
1076
#endif
1088
- Cache_Read_Disable ();
1089
1077
}
1090
1078
1091
1079
/*
@@ -1106,6 +1094,7 @@ asm (
1106
1094
" .literal .umm_init, umm_init\n\t "
1107
1095
" .literal .call_user_start, call_user_start\n\t "
1108
1096
" .literal .get_noextra4k_g_pcont, get_noextra4k_g_pcont\n\t "
1097
+ " .literal .mmu_wrap_irom_fn, mmu_wrap_irom_fn\n\t "
1109
1098
" .align 4\n\t "
1110
1099
" .global app_entry_redefinable\n\t "
1111
1100
" .type app_entry_redefinable, @function\n\t "
@@ -1129,7 +1118,9 @@ asm (
1129
1118
#ifdef USE_IRAM
1130
1119
" call0 handle_hwdt\n\t "
1131
1120
#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 "
1133
1124
#endif
1134
1125
/*
1135
1126
* Use new calculated SYS stack from top.
@@ -1160,7 +1151,9 @@ asm (
1160
1151
/*
1161
1152
* Allow for running additional diagnotics supplied at link time.
1162
1153
*/
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 "
1164
1157
1165
1158
// In case somebody cares, leave things as we found them
1166
1159
// - Restore ROM BSS zeros.
@@ -1174,7 +1167,12 @@ asm (
1174
1167
* improvements could possibly use hwdt_pre_sdk_init() to run other early
1175
1168
* diagnostic tools.
1176
1169
*/
1170
+ #ifdef UMM_INIT_USE_IRAM
1177
1171
" 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
1178
1176
" callx0 a0\n\t "
1179
1177
1180
1178
" l32r a3, .call_user_start\n\t "
0 commit comments