Skip to content

Commit e014b0f

Browse files
authored
Merge pull request #2522 from svastm/cthunk_cm7
Add CThunk for CM7
2 parents 24e1218 + af0f7e3 commit e014b0f

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

hal/api/CThunk.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,35 @@
3232
#define __CTHUNK_H__
3333

3434
#define CTHUNK_ADDRESS 1
35+
#define CTHUNK_VARIABLES volatile uint32_t code[2]
3536

36-
#if (defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)) && ! defined(__CORTEX_A9)
37-
#define CTHUNK_VARIABLES volatile uint32_t code[1]
37+
#if (defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_M7) || defined(__CORTEX_A9))
3838
/**
39-
* CTHUNK disassembly for Cortex-M3/M4 (thumb2):
40-
* * ldm.w pc,{r0,r1,r2,pc}
39+
* CTHUNK disassembly for Cortex-M3/M4/M7/A9 (thumb2):
40+
* * adr r0, #4
41+
* * ldm r0, {r0, r1, r2, pc}
4142
*
4243
* This instruction loads the arguments for the static thunking function to r0-r2, and
4344
* branches to that function by loading its address into PC.
4445
*
4546
* This is safe for both regular calling and interrupt calling, since it only touches scratch registers
4647
* which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
4748
*/
48-
#define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F
49+
#define CTHUNK_ASSIGMENT do { \
50+
m_thunk.code[0] = 0xE890A001; \
51+
m_thunk.code[1] = 0x00008007; \
52+
} while (0)
4953

50-
#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0) || defined(__CORTEX_A9)
54+
#elif (defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0))
5155
/*
52-
* CTHUNK disassembly for Cortex M0 (thumb):
53-
* * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
54-
* * movs r4,#4 set up address to load arguments from (immediately following this code block) (1)
55-
* * add r4,pc set up address to load arguments from (immediately following this code block) (2)
56-
* * ldm r4!,{r0,r1,r2,r3} load arguments for static thunk function
57-
* * blx r3 call static thunk function
58-
* * pop {r0,r1,r2,r3,r4,pc} restore scratch registers and return from function
56+
* CTHUNK disassembly for Cortex M0/M0+ (thumb):
57+
* * adr r0, #4
58+
* * ldm r0, {r0, r1, r2, r3}
59+
* * bx r3
5960
*/
60-
#define CTHUNK_VARIABLES volatile uint32_t code[3]
6161
#define CTHUNK_ASSIGMENT do { \
62-
m_thunk.code[0] = 0x2404B51F; \
63-
m_thunk.code[1] = 0xCC0F447C; \
64-
m_thunk.code[2] = 0xBD1F4798; \
62+
m_thunk.code[0] = 0xC80FA001; \
63+
m_thunk.code[1] = 0x00004718; \
6564
} while (0)
6665

6766
#else
@@ -225,6 +224,13 @@ class CThunk
225224
__ca9u_inv_tlb_all();
226225
__v7_inv_btac();
227226
}
227+
#endif
228+
#if defined(__CORTEX_M7)
229+
/* Data cache clean and invalid */
230+
SCB_CleanInvalidateDCache();
231+
232+
/* Instruction cache invalid */
233+
SCB_InvalidateICache();
228234
#endif
229235
__ISB();
230236
__DSB();

0 commit comments

Comments
 (0)