stack.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006-2021, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-02-14 aozima first implementation for Nios II.
  13. */
  14. #include <rtthread.h>
  15. /**
  16. * @addtogroup NIOS_II
  17. */
  18. /*@{*/
  19. /**
  20. * This function will initialize thread stack
  21. *
  22. * @param tentry the entry of thread
  23. * @param parameter the parameter of entry
  24. * @param stack_addr the beginning stack address
  25. * @param texit the function will be called when thread exit
  26. *
  27. * @return stack address
  28. */
  29. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  30. rt_uint8_t *stack_addr, void *texit)
  31. {
  32. unsigned long *stk;
  33. stk = (unsigned long *)stack_addr;
  34. *(stk) = 0x01; /* status */
  35. *(--stk) = (unsigned long)texit; /* ra */
  36. *(--stk) = 0xdeadbeef; /* fp */
  37. *(--stk) = 0xdeadbeef; /* r23 */
  38. *(--stk) = 0xdeadbeef; /* r22 */
  39. *(--stk) = 0xdeadbeef; /* r21 */
  40. *(--stk) = 0xdeadbeef; /* r20 */
  41. *(--stk) = 0xdeadbeef; /* r19 */
  42. *(--stk) = 0xdeadbeef; /* r18 */
  43. *(--stk) = 0xdeadbeef; /* r17 */
  44. *(--stk) = 0xdeadbeef; /* r16 */
  45. // *(--stk) = 0xdeadbeef; /* r15 */
  46. // *(--stk) = 0xdeadbeef; /* r14 */
  47. // *(--stk) = 0xdeadbeef; /* r13 */
  48. // *(--stk) = 0xdeadbeef; /* r12 */
  49. // *(--stk) = 0xdeadbeef; /* r11 */
  50. // *(--stk) = 0xdeadbeef; /* r10 */
  51. // *(--stk) = 0xdeadbeef; /* r9 */
  52. // *(--stk) = 0xdeadbeef; /* r8 */
  53. *(--stk) = 0xdeadbeef; /* r7 */
  54. *(--stk) = 0xdeadbeef; /* r6 */
  55. *(--stk) = 0xdeadbeef; /* r5 */
  56. *(--stk) = (unsigned long)parameter; /* r4 argument */
  57. *(--stk) = 0xdeadbeef; /* r3 */
  58. *(--stk) = 0xdeadbeef; /* r2 */
  59. *(--stk) = (unsigned long)tentry; /* pc */
  60. // *(stk) = (unsigned long)tentry; /* thread entry (ra) */
  61. // *(--stk) = (unsigned long)parameter; /* thread argument, r4 */
  62. /* return task's current stack address */
  63. return (rt_uint8_t *)stk;
  64. }
  65. /*@}*/