stack.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-01-13 weety copy from mini2440
  13. */
  14. #include <rtthread.h>
  15. #include "at91sam926x.h"
  16. /**
  17. * @addtogroup AT91SAM926X
  18. */
  19. /*@{*/
  20. /**
  21. * This function will initialize thread stack
  22. *
  23. * @param tentry the entry of thread
  24. * @param parameter the parameter of entry
  25. * @param stack_addr the beginning stack address
  26. * @param texit the function will be called when thread exit
  27. *
  28. * @return stack address
  29. */
  30. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  31. rt_uint8_t *stack_addr, void *texit)
  32. {
  33. rt_uint32_t *stk;
  34. stk = (rt_uint32_t*)stack_addr;
  35. *(stk) = (rt_uint32_t)tentry; /* entry point */
  36. *(--stk) = (rt_uint32_t)texit; /* lr */
  37. *(--stk) = 0; /* r12 */
  38. *(--stk) = 0; /* r11 */
  39. *(--stk) = 0; /* r10 */
  40. *(--stk) = 0; /* r9 */
  41. *(--stk) = 0; /* r8 */
  42. *(--stk) = 0; /* r7 */
  43. *(--stk) = 0; /* r6 */
  44. *(--stk) = 0; /* r5 */
  45. *(--stk) = 0; /* r4 */
  46. *(--stk) = 0; /* r3 */
  47. *(--stk) = 0; /* r2 */
  48. *(--stk) = 0; /* r1 */
  49. *(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
  50. *(--stk) = SVCMODE; /* cpsr */
  51. *(--stk) = SVCMODE; /* spsr */
  52. /* return task's current stack address */
  53. return (rt_uint8_t *)stk;
  54. }
  55. /*@}*/