Merge pull request #1123 from SummerGGift/8-byte_alignment

[libcpu]: add 8-byte alignment for armv6 architecture
This commit is contained in:
Bernard Xiong 2017-12-21 15:36:21 +08:00 committed by GitHub
commit cc75366fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 34 deletions

View File

@ -26,54 +26,57 @@
/*****************************/ /*****************************/
/* CPU Mode */ /* CPU Mode */
/*****************************/ /*****************************/
#define USERMODE 0x10 #define USERMODE 0x10
#define FIQMODE 0x11 #define FIQMODE 0x11
#define IRQMODE 0x12 #define IRQMODE 0x12
#define SVCMODE 0x13 #define SVCMODE 0x13
#define ABORTMODE 0x17 #define ABORTMODE 0x17
#define UNDEFMODE 0x1b #define UNDEFMODE 0x1b
#define MODEMASK 0x1f #define MODEMASK 0x1f
#define NOINT 0xc0 #define NOINT 0xc0
/** /**
* This function will initialize thread stack * This function will initialize thread stack
* *
* @param tentry the entry of thread * @param tentry the entry of thread
* @param parameter the parameter of entry * @param parameter the parameter of entry
* @param stack_addr the beginning stack address * @param stack_addr the beginning stack address
* @param texit the function will be called when thread exit * @param texit the function will be called when thread exit
* *
* @return stack address * @return stack address
*/ */
rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
rt_uint8_t *stack_addr, void *texit) rt_uint8_t *stack_addr, void *texit)
{ {
rt_uint32_t *stk; rt_uint32_t *stk;
stk = (rt_uint32_t*)stack_addr; stack_addr += sizeof(rt_uint32_t);
*(stk) = (rt_uint32_t)tentry; /* entry point */ stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
*(--stk) = (rt_uint32_t)texit; /* lr */ stk = (rt_uint32_t *)stack_addr;
*(--stk) = 0; /* r12 */
*(--stk) = 0; /* r11 */
*(--stk) = 0; /* r10 */
*(--stk) = 0; /* r9 */
*(--stk) = 0; /* r8 */
*(--stk) = 0; /* r7 */
*(--stk) = 0; /* r6 */
*(--stk) = 0; /* r5 */
*(--stk) = 0; /* r4 */
*(--stk) = 0; /* r3 */
*(--stk) = 0; /* r2 */
*(--stk) = 0; /* r1 */
*(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
/* cpsr */ *(--stk) = (rt_uint32_t)tentry; /* entry point */
if ((rt_uint32_t)tentry & 0x01) *(--stk) = (rt_uint32_t)texit; /* lr */
*(--stk) = SVCMODE | 0x20; /* thumb mode */ *(--stk) = 0xdeadbeef; /* r12 */
else *(--stk) = 0xdeadbeef; /* r11 */
*(--stk) = SVCMODE; /* arm mode */ *(--stk) = 0xdeadbeef; /* r10 */
*(--stk) = 0xdeadbeef; /* r9 */
*(--stk) = 0xdeadbeef; /* r8 */
*(--stk) = 0xdeadbeef; /* r7 */
*(--stk) = 0xdeadbeef; /* r6 */
*(--stk) = 0xdeadbeef; /* r5 */
*(--stk) = 0xdeadbeef; /* r4 */
*(--stk) = 0xdeadbeef; /* r3 */
*(--stk) = 0xdeadbeef; /* r2 */
*(--stk) = 0xdeadbeef; /* r1 */
*(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
/* return task's current stack address */ /* cpsr */
return (rt_uint8_t *)stk; if ((rt_uint32_t)tentry & 0x01)
*(--stk) = SVCMODE | 0x20; /* thumb mode */
else
*(--stk) = SVCMODE; /* arm mode */
/* return task's current stack address */
return (rt_uint8_t *)stk;
} }