summaryrefslogtreecommitdiff
path: root/libcpu/nios/nios_ii/stack.c
blob: 6eecfe6d6c3cb913a040a95048e1d4c4ed69ec0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2011-02-14     aozima       first implementation for Nios II.
 */

#include <rtthread.h>

/**
 * @addtogroup NIOS_II
 */
/*@{*/

/**
 * 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)
{
    unsigned long *stk;

    stk      = (unsigned long *)stack_addr;
    *(stk)   = 0x01;                        /* status  */
    *(--stk) = (unsigned long)texit;        /* ra  */
    *(--stk) = 0xdeadbeef;                  /* fp  */
    *(--stk) = 0xdeadbeef;                  /* r23 */
    *(--stk) = 0xdeadbeef;                  /* r22 */
    *(--stk) = 0xdeadbeef;                  /* r21 */
    *(--stk) = 0xdeadbeef;                  /* r20 */
    *(--stk) = 0xdeadbeef;                  /* r19 */
    *(--stk) = 0xdeadbeef;                  /* r18 */
    *(--stk) = 0xdeadbeef;                  /* r17 */
    *(--stk) = 0xdeadbeef;                  /* r16 */
//  *(--stk) = 0xdeadbeef;                  /* r15 */
//  *(--stk) = 0xdeadbeef;                  /* r14 */
//  *(--stk) = 0xdeadbeef;                  /* r13 */
//  *(--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) = (unsigned long)parameter;    /* r4 argument */
    *(--stk) = 0xdeadbeef;                  /* r3  */
    *(--stk) = 0xdeadbeef;                  /* r2  */
    *(--stk) = (unsigned long)tentry;       /* pc  */

//  *(stk)   = (unsigned long)tentry;       /* thread entry (ra) */
//  *(--stk) = (unsigned long)parameter;    /* thread argument, r4 */

    /* return task's current stack address */
    return (rt_uint8_t *)stk;
}

/*@}*/