Skip to content

Commit c5422ee

Browse files
committed
Change CThunk method for Cortex-A
thumb2 code executes invalid ram space, and it causes crash Add instruction cache clean codes
1 parent 6d3e9e3 commit c5422ee

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libraries/mbed/api/CThunk.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#define CTHUNK_ADDRESS 1
2626

27-
#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_A9) || defined(__thumb2__)
27+
#if (defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)) && ! defined(__CORTEX_A9)
2828
#define CTHUNK_VARIABLES volatile uint32_t code[1]
2929
/**
3030
* CTHUNK disassembly for Cortex-M3/M4 (thumb2):
@@ -38,7 +38,7 @@
3838
*/
3939
#define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F
4040

41-
#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0)
41+
#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0) || defined(__CORTEX_A9)
4242
/*
4343
* CTHUNK disassembly for Cortex M0 (thumb):
4444
* * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
@@ -196,14 +196,20 @@ class CThunk
196196

197197
#if defined(__CORTEX_A9)
198198
/* Data cache clean */
199+
/* Cache control */
199200
{
200201
uint32_t start_addr = (uint32_t)&m_thunk & 0xFFFFFFE0;
201-
uint32_t end_addr = ((uint32_t)&m_thunk + sizeof(m_thunk));
202+
uint32_t end_addr = (uint32_t)&m_thunk + sizeof(m_thunk);
202203
uint32_t addr;
203204

205+
/* Data cache clean and invalid */
204206
for (addr = start_addr; addr < end_addr; addr += 0x20) {
205207
__v7_clean_inv_dcache_mva((void *)addr);
206208
}
209+
/* Instruction cache invalid */
210+
__v7_inv_icache_all();
211+
__ca9u_inv_tlb_all();
212+
__v7_inv_btac();
207213
}
208214
#endif
209215
__ISB();

0 commit comments

Comments
 (0)