stack.c 2.3 KB

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