summaryrefslogtreecommitdiff
path: root/libcpu/arm/cortex-a7/stack.c
diff options
context:
space:
mode:
authorbigmagic <[email protected]>2020-01-10 10:38:21 +0800
committerbigmagic <[email protected]>2020-01-10 10:38:21 +0800
commitfdde8ab1982adabc71ab651e55160993dbdd9365 (patch)
treed7880b24a9bf2c0d2eba1332dda3ecac54cd4dd2 /libcpu/arm/cortex-a7/stack.c
parentd0098acd885e67cc7cf25fb828b7eba82380f6b1 (diff)
add raspi2 and raspi3 BSP
Diffstat (limited to 'libcpu/arm/cortex-a7/stack.c')
-rw-r--r--libcpu/arm/cortex-a7/stack.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/libcpu/arm/cortex-a7/stack.c b/libcpu/arm/cortex-a7/stack.c
new file mode 100644
index 0000000000..e60e8c7170
--- /dev/null
+++ b/libcpu/arm/cortex-a7/stack.c
@@ -0,0 +1,68 @@
+/*
+ * File : stack.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2011, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-09-23 Bernard the first version
+ * 2011-10-05 Bernard add thumb mode
+ */
+#include <rtthread.h>
+#include <board.h>
+#include <armv7.h>
+
+/**
+ * @addtogroup AM33xx
+ */
+/*@{*/
+
+/**
+ * This function will initialize thread stack
+ *
+ * @param tentry the entry of thread
+ * @param parameter the parameter of entry
+ * @param stack_addr the beginning stack address
+ * @param texit the function will be called when thread exit
+ *
+ * @return stack address
+ */
+rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
+ rt_uint8_t *stack_addr, void *texit)
+{
+ rt_uint32_t *stk;
+
+ stack_addr += sizeof(rt_uint32_t);
+ stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
+ stk = (rt_uint32_t *)stack_addr;
+ *(--stk) = (rt_uint32_t)tentry; /* entry point */
+ *(--stk) = (rt_uint32_t)texit; /* lr */
+ *(--stk) = 0xdeadbeef; /* r12 */
+ *(--stk) = 0xdeadbeef; /* r11 */
+ *(--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 */
+
+ /* cpsr */
+ 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;
+}
+
+/*@}*/