mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-07 16:23:38 +03:00
* PoC cache configuration control Expaned boards.txt.py to allow new MMU options and create revised .ld's Updated eboot to pass 48K IRAM segments. Added Cache_Read_Enable intercept to modify call for 16K ICACHE Update platform.txt to pass new mmu options through to compiler and linker preprocessor. Added quick example: esp8266/MMU48K * Style corrections Added MMU_ qualifier to new defines. Moved changes into their own file. Don't know how to fix platformio issue. * Added detailed description for Cache_Read_Enable. Updated tools/sizes.py to report correct IRAM size and indicate ICACHE size. Merged in earlephilhower's work on unaligned exception. Refactored and added support for store operations and changed the name to be more closely aligned with its function. Improved crash reporting path. * Style and MMU_SEC_HEAP corrections. * Improved asm register usage. Added some inline functions to aid in byte and short access to iRAM. * only byte read has been tested Updated .ld file to work better with platform.io; however, I am still missing some steps, so platformio will still fail. * Interesting glitch in boards.txt after github merge. A new board in master was missing new additions added by boards.txt.py in the PR. Which the CI flags when it rebuilds boards.txt. * Support for 2nd Heap, excess IRAM, through umm_malloc. Adapted changes to umm_malloc, Esp.cpp, StackThunk.cpp, WiFiClientSecureBearSSL.cpp, and virtualmem.ino to irammem.ino from @earlephilhower PR #6994. Reworked umm_malloc to use context pointers instead of copy context. umm_malloc now supports allocations from IRAM. Added class HeapSelectIram, ... to aid in selecting alternate heaps, modeled after class InterruptLock. Restrict alloc request from ISRs to DRAM. Never ending improvements to debug printing. Sec Heap option now pulls in free IRAM left over in the 1st 32K block. Managed through umm_malloc with HeapSelectIram. Updated examples. * Post push CI cleanup. * Cleanup part II * Cleanup part III * Updates to support platformio, maybe. * Added exception C wrapper replacement. * CI Cleanup * CI Cleanup II Don't know what to do with platformio it doesn't like my .S file. ifdef out USE_ISR_SAFE_EXC_WRAPPER to block the new assemlby module from building on platformio only. * Changes to exc-c-wrapper-handler.S to assemble under platformio. * For platformio, Correction to toolchain-xtensa include path. @mcspr, Thankyou! * Temporarily added --print-memory-usage to ld parameters for cross-checking IRAM size. * undo change to platform.txt * correct merge conflict. take 1 * Fixed #if... for building umm_get_oom_count. It was not building when UMM_STATS_FULL was used. * Commented out XMC support. Compatibility issues with PoC when using 16K ICACHE. * Corrected size.py, DRAM bracketing changed to not include ICACHE with DRAM total. * Added additional _context for support of use of UMM_INLINE_METRICS. Corrected some UMM_POSION missed edits. * Changes to clear errors and warnings from toolchain 10.1 Several fixes and improvements to example MMU48K. With the improved optimization in toolchain 10.1 The example divide by 0 exception was failing with a HWDT event instead of its exception handler. The compiler saw the obscured divide by 0 and replaced it with a break point. * Isolated incompatable definitions related to _xtos_set_exception_handler. GDBSTUB definitions are different from the BootROM's. * Update tools/platformio-build.py Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com> * Requested changes Changed mmu related usages of ETS_... defines to DBG_MMU_... Cleanup in example MMU48K.ino. Removed stale memory reference macro and mmu_status print statement. Cleanup printf '\n' to be '\r\n'. Improved issolation of development debug prints from the rest of the debug prints. * Corrected comment. And added missing include. * Improve comment. * style and comment correction * Added draft mmu.rst file and updated index. Updated example HeapMetric.ino to also illustrate use of IRAM Improved comments in exc-c-wrapper-handler.S. Added insurance IRQ disable. * Updated mmu.rst Improved function name uniqueness for is_iram, is_dram, and is_icache by adding prefix mmu_. Also, made them available outside of a debug build. Made pointer precision width more specific. Made some of the static inline functions in mmu_irm.h safe for ISRs by setting then for always inline. * Add a default MMU_IRAM_SIZE value for a new CI test to pass. Extended use 'umm_heap_context_t *_context' argument in ..._core functions and expanded its usage to reduce unnecessary repeated calls to umm_info(NULL, false), also removed recursion from umm_info(NULL, true). Fixed stack buffer length in umm_info_safe_printf_P and heap.cpp. Added example for creating an IRAM reserve section. Updated mmu.rst. Grammar and spelling corrections. * CI appeasement * CI appeasement with comment correction. * Ensure SYS always runs with DRAM Heap selected. * Add/move heap stack overflow/underflow check to Esp.cpp where the event was discarded. * Improved comment clarity of purpose for IramReserve.ino. Clean up MMU48K.ino * Added missing #include * Corrected usage of warning * CI appeasement and use #message not #pragma message * Updated git version of eboot.elf to match build version. Good test catch. * Remove conditional build option USE_ISR_SAFE_EXC_WRAPPER, always install. Use the replacement wrapper on non32xfer_exception_handler install. Added comments to code describing some exception handling issues. * Updated mmu.rst * Expanded and clarified comments. Limited access to some detailed typdefs/prototypes to .cpp modules, to avoid future build conflicts. Completed TODO for verifing that the "C" structure struct __exception_frame matches the ASM version. Fixed some typo's, code rot, and added some more cases in examaple irammem.ino. Refactored a little and reordered printing to ease comparison between methods. Corrected `#ifdef __cplusplus` coverage area. Cleaned up `extern "C" ...` usage. Fixes issues with including mmu_iram.h or esp8266_undocumented.h in .c files. * Style fixes and more cleanup * Style fix * Remove unnessasary IRAM_ATTR from install_non32xfer_exception_handler Some comment tuning. In the context of _xtos_set_exception_handler and the functions it registers, changed to type int for exception cause type. This is also the type used by gdbstub and some other Xtensa files I found.
222 lines
6.0 KiB
C
222 lines
6.0 KiB
C
/*
|
|
* Copyright 2020 M Hightower
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef __MMU_IRAM_H
|
|
#define __MMU_IRAM_H
|
|
|
|
#include <stdint.h>
|
|
#include <c_types.h>
|
|
#include <assert.h>
|
|
#include <esp8266_undocumented.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
//C This turns on range checking. Is this the value you want to trigger it?
|
|
#ifdef DEBUG_ESP_CORE
|
|
#define DEBUG_ESP_MMU
|
|
#endif
|
|
|
|
#if defined(CORE_MOCK)
|
|
#define ets_uart_printf(...) do {} while(false)
|
|
#endif
|
|
|
|
/*
|
|
* DEV_DEBUG_PRINT:
|
|
* Debug printing macros for printing before before, during, and after
|
|
* NONOS SDK initializes. May or maynot be safe during NONOS SDK
|
|
* initialization. As in printing from functions called on by the SDK
|
|
* during the SDK initialization.
|
|
*
|
|
#define DEV_DEBUG_PRINT
|
|
*/
|
|
|
|
#if defined(DEV_DEBUG_PRINT) || defined(DEBUG_ESP_MMU)
|
|
#include <esp8266_peri.h>
|
|
|
|
#define DBG_MMU_FLUSH(a) while((USS(a) >> USTXC) & 0xff) {}
|
|
|
|
#if defined(DEV_DEBUG_PRINT)
|
|
extern void set_pll(void);
|
|
extern void dbg_set_pll(void);
|
|
|
|
#define DBG_MMU_PRINTF(fmt, ...) \
|
|
set_pll(); \
|
|
uart_buff_switch(0); \
|
|
ets_uart_printf(fmt, ##__VA_ARGS__); \
|
|
DBG_MMU_FLUSH(0)
|
|
|
|
#else // ! defined(DEV_DEBUG_PRINT)
|
|
#define DBG_MMU_PRINTF(fmt, ...) ets_uart_printf(fmt, ##__VA_ARGS__)
|
|
#endif
|
|
|
|
#else // ! defined(DEV_DEBUG_PRINT) || defined(DEBUG_ESP_MMU)
|
|
#define DBG_MMU_FLUSH(...) do {} while(false)
|
|
#define DBG_MMU_PRINTF(...) do {} while(false)
|
|
#endif // defined(DEV_DEBUG_PRINT) || defined(DEBUG_ESP_MMU)
|
|
|
|
static inline __attribute__((always_inline))
|
|
bool mmu_is_iram(const void *addr) {
|
|
#define IRAM_START 0x40100000UL
|
|
#ifndef MMU_IRAM_SIZE
|
|
#if defined(__GNUC__) && !defined(CORE_MOCK)
|
|
#warning "MMU_IRAM_SIZE was undefined, setting to 0x8000UL!"
|
|
#endif
|
|
#define MMU_IRAM_SIZE 0x8000UL
|
|
#endif
|
|
#define IRAM_END (IRAM_START + MMU_IRAM_SIZE)
|
|
|
|
return (IRAM_START <= (uintptr_t)addr && IRAM_END > (uintptr_t)addr);
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
bool mmu_is_dram(const void *addr) {
|
|
#define DRAM_START 0x3FF80000UL
|
|
#define DRAM_END 0x40000000UL
|
|
|
|
return (DRAM_START <= (uintptr_t)addr && DRAM_END > (uintptr_t)addr);
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
bool mmu_is_icache(const void *addr) {
|
|
#define ICACHE_START 0x40200000UL
|
|
#define ICACHE_END (ICACHE_START + 0x100000UL)
|
|
|
|
return (ICACHE_START <= (uintptr_t)addr && ICACHE_END > (uintptr_t)addr);
|
|
}
|
|
|
|
#ifdef DEBUG_ESP_MMU
|
|
#define ASSERT_RANGE_TEST_WRITE(a) \
|
|
if (mmu_is_iram(a) || mmu_is_dram(a)) { \
|
|
} else { \
|
|
DBG_MMU_PRINTF("\nexcvaddr: %p\n", a); \
|
|
assert(("Outside of Range - Write" && false)); \
|
|
}
|
|
|
|
#define ASSERT_RANGE_TEST_READ(a) \
|
|
if (mmu_is_iram(a) || mmu_is_dram(a) || mmu_is_icache(a)) { \
|
|
} else { \
|
|
DBG_MMU_PRINTF("\nexcvaddr: %p\n", a); \
|
|
assert(("Outside of Range - Read" && false)); \
|
|
}
|
|
|
|
#else
|
|
#define ASSERT_RANGE_TEST_WRITE(a) do {} while(false)
|
|
#define ASSERT_RANGE_TEST_READ(a) do {} while(false)
|
|
#endif
|
|
|
|
/*
|
|
* Some inlines to allow faster random access to non32bit access of iRAM or
|
|
* iCACHE data elements. These remove the extra time and stack space that would
|
|
* have occured by relying on exception processing.
|
|
*/
|
|
static inline __attribute__((always_inline))
|
|
uint8_t mmu_get_uint8(const void *p8) {
|
|
ASSERT_RANGE_TEST_READ(p8);
|
|
uint32_t val = (*(uint32_t *)((uintptr_t)p8 & ~0x3));
|
|
uint32_t pos = ((uintptr_t)p8 & 0x3) * 8;
|
|
val >>= pos;
|
|
return (uint8_t)val;
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
uint16_t mmu_get_uint16(const uint16_t *p16) {
|
|
ASSERT_RANGE_TEST_READ(p16);
|
|
uint32_t val = (*(uint32_t *)((uintptr_t)p16 & ~0x3));
|
|
uint32_t pos = ((uintptr_t)p16 & 0x3) * 8;
|
|
val >>= pos;
|
|
return (uint16_t)val;
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
int16_t mmu_get_int16(const int16_t *p16) {
|
|
ASSERT_RANGE_TEST_READ(p16);
|
|
uint32_t val = (*(uint32_t *)((uintptr_t)p16 & ~0x3));
|
|
uint32_t pos = ((uintptr_t)p16 & 0x3) * 8;
|
|
val >>= pos;
|
|
return (int16_t)val;
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
uint8_t mmu_set_uint8(void *p8, const uint8_t val) {
|
|
ASSERT_RANGE_TEST_WRITE(p8);
|
|
uint32_t pos = ((uintptr_t)p8 & 0x3) * 8;
|
|
uint32_t sval = val << pos;
|
|
uint32_t valmask = 0x0FF << pos;
|
|
|
|
uint32_t *p32 = (uint32_t *)((uintptr_t)p8 & ~0x3);
|
|
uint32_t ival = *p32;
|
|
ival &= (~valmask);
|
|
ival |= sval;
|
|
*p32 = ival;
|
|
return val;
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
uint16_t mmu_set_uint16(uint16_t *p16, const uint16_t val) {
|
|
ASSERT_RANGE_TEST_WRITE(p16);
|
|
uint32_t pos = ((uintptr_t)p16 & 0x3) * 8;
|
|
uint32_t sval = val << pos;
|
|
uint32_t valmask = 0x0FFFF << pos;
|
|
|
|
uint32_t *p32 = (uint32_t *)((uintptr_t)p16 & ~0x3);
|
|
uint32_t ival = *p32;
|
|
ival &= (~valmask);
|
|
ival |= sval;
|
|
*p32 = ival;
|
|
return val;
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
int16_t mmu_set_int16(int16_t *p16, const int16_t val) {
|
|
ASSERT_RANGE_TEST_WRITE(p16);
|
|
uint32_t sval = (uint16_t)val;
|
|
uint32_t pos = ((uintptr_t)p16 & 0x3) * 8;
|
|
sval <<= pos;
|
|
uint32_t valmask = 0x0FFFF << pos;
|
|
|
|
uint32_t *p32 = (uint32_t *)((uintptr_t)p16 & ~0x3);
|
|
uint32_t ival = *p32;
|
|
ival &= (~valmask);
|
|
ival |= sval;
|
|
*p32 = ival;
|
|
return val;
|
|
}
|
|
|
|
#if (MMU_IRAM_SIZE > 32*1024) && !defined(MMU_SEC_HEAP)
|
|
extern void _text_end(void);
|
|
#define MMU_SEC_HEAP mmu_sec_heap()
|
|
#define MMU_SEC_HEAP_SIZE mmu_sec_heap_size()
|
|
|
|
static inline __attribute__((always_inline))
|
|
void *mmu_sec_heap(void) {
|
|
uint32_t sec_heap = (uint32_t)_text_end + 32;
|
|
return (void *)(sec_heap &= ~7);
|
|
}
|
|
|
|
static inline __attribute__((always_inline))
|
|
size_t mmu_sec_heap_size(void) {
|
|
return (size_t)0xC000UL - ((size_t)mmu_sec_heap() - 0x40100000UL);
|
|
}
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|