stack.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-12-04 Jiaxun Yang Initial version
  9. */
  10. #include <rtthread.h>
  11. #include "mips.h"
  12. register rt_uint32_t $GP __asm__ ("$28");
  13. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint8_t *stack_addr, void *texit)
  14. {
  15. static rt_uint32_t wSR=0;
  16. static rt_uint32_t wGP;
  17. rt_uint8_t *stk;
  18. struct pt_regs *pt;
  19. rt_uint32_t i;
  20. /* Get stack aligned */
  21. stk = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
  22. stk -= sizeof(struct pt_regs);
  23. pt = (struct pt_regs*)stk;
  24. for (i = 0; i < 8; ++i)
  25. {
  26. pt->pad0[i] = 0xdeadbeef;
  27. }
  28. /* Fill Stack register numbers */
  29. for (i = 0; i < 32; ++i)
  30. {
  31. pt->regs[i] = 0xdeadbeef;
  32. }
  33. pt->regs[REG_SP] = (rt_uint32_t)stk;
  34. pt->regs[REG_A0] = (rt_uint32_t)parameter;
  35. pt->regs[REG_GP] = (rt_uint32_t)$GP;
  36. pt->regs[REG_FP] = (rt_uint32_t)0x0;
  37. pt->regs[REG_RA] = (rt_uint32_t)texit;
  38. pt->hi = 0x0;
  39. pt->lo = 0x0;
  40. pt->cp0_status = (ST0_IE | ST0_CU0 | ST0_IM);
  41. #ifdef RT_USING_FPU
  42. pt->cp0_status |= (ST0_CU1 | ST0_FR);
  43. #endif
  44. pt->cp0_cause = read_c0_cause();
  45. pt->cp0_epc = (rt_uint32_t)tentry;
  46. pt->cp0_badvaddr = 0x0;
  47. return stk;
  48. }