stack.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-01-13 weety copy from mini2440
  23. */
  24. #include <rtthread.h>
  25. /*****************************/
  26. /* CPU Mode */
  27. /*****************************/
  28. #define USERMODE 0x10
  29. #define FIQMODE 0x11
  30. #define IRQMODE 0x12
  31. #define SVCMODE 0x13
  32. #define ABORTMODE 0x17
  33. #define UNDEFMODE 0x1b
  34. #define MODEMASK 0x1f
  35. #define NOINT 0xc0
  36. /**
  37. * This function will initialize thread stack
  38. *
  39. * @param tentry the entry of thread
  40. * @param parameter the parameter of entry
  41. * @param stack_addr the beginning stack address
  42. * @param texit the function will be called when thread exit
  43. *
  44. * @return stack address
  45. */
  46. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  47. rt_uint8_t *stack_addr, void *texit)
  48. {
  49. rt_uint32_t *stk;
  50. stk = (rt_uint32_t*)stack_addr;
  51. *(stk) = (rt_uint32_t)tentry; /* entry point */
  52. *(--stk) = (rt_uint32_t)texit; /* lr */
  53. *(--stk) = 0; /* r12 */
  54. *(--stk) = 0; /* r11 */
  55. *(--stk) = 0; /* r10 */
  56. *(--stk) = 0; /* r9 */
  57. *(--stk) = 0; /* r8 */
  58. *(--stk) = 0; /* r7 */
  59. *(--stk) = 0; /* r6 */
  60. *(--stk) = 0; /* r5 */
  61. *(--stk) = 0; /* r4 */
  62. *(--stk) = 0; /* r3 */
  63. *(--stk) = 0; /* r2 */
  64. *(--stk) = 0; /* r1 */
  65. *(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
  66. *(--stk) = SVCMODE; /* cpsr */
  67. *(--stk) = SVCMODE; /* spsr */
  68. /* return task's current stack address */
  69. return (rt_uint8_t *)stk;
  70. }