stack.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /*****************************/
  16. /* CPU Mode */
  17. /*****************************/
  18. #define USERMODE 0x10
  19. #define FIQMODE 0x11
  20. #define IRQMODE 0x12
  21. #define SVCMODE 0x13
  22. #define ABORTMODE 0x17
  23. #define UNDEFMODE 0x1b
  24. #define MODEMASK 0x1f
  25. #define NOINT 0xc0
  26. /**
  27. * This function will initialize thread stack
  28. *
  29. * @param tentry the entry of thread
  30. * @param parameter the parameter of entry
  31. * @param stack_addr the beginning stack address
  32. * @param texit the function will be called when thread exit
  33. *
  34. * @return stack address
  35. */
  36. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  37. rt_uint8_t *stack_addr, void *texit)
  38. {
  39. rt_uint32_t *stk;
  40. stk = (rt_uint32_t*)stack_addr;
  41. *(stk) = (rt_uint32_t)tentry; /* entry point */
  42. *(--stk) = (rt_uint32_t)texit; /* lr */
  43. *(--stk) = 0; /* r12 */
  44. *(--stk) = 0; /* r11 */
  45. *(--stk) = 0; /* r10 */
  46. *(--stk) = 0; /* r9 */
  47. *(--stk) = 0; /* r8 */
  48. *(--stk) = 0; /* r7 */
  49. *(--stk) = 0; /* r6 */
  50. *(--stk) = 0; /* r5 */
  51. *(--stk) = 0; /* r4 */
  52. *(--stk) = 0; /* r3 */
  53. *(--stk) = 0; /* r2 */
  54. *(--stk) = 0; /* r1 */
  55. *(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
  56. *(--stk) = SVCMODE; /* cpsr */
  57. *(--stk) = SVCMODE; /* spsr */
  58. /* return task's current stack address */
  59. return (rt_uint8_t *)stk;
  60. }