startup_gcc.S 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018/10/01 Bernard The first version
  9. * 2018/12/27 Jesven Add SMP support
  10. * 2020/6/12 Xim Port to QEMU and remove SMP support
  11. */
  12. #define XSTATUS_FS (3 << 13) /* initial state of FPU, clear to disable */
  13. #define XSTATUS_PUM (1 << 18)
  14. #include <cpuport.h>
  15. .global _start
  16. .section ".start", "ax"
  17. _start:
  18. #ifndef RISCV_S_MODE
  19. # setup stacks per hart
  20. csrr t0, mhartid # read current hart id
  21. slli t0, t0, 10 # shift left the hart id by 1024
  22. # park harts with id != 0
  23. csrr a0, mhartid # read current hart id
  24. bnez a0, park # if we're not on the hart 0
  25. #endif
  26. csrw SRC_XIE, 0 # clear Interrupt Registers
  27. csrw SRC_XIP, 0
  28. la t0, trap_entry
  29. csrw SRC_XTVEC, t0 # set Trap Vector Base Address Register
  30. /* set to disable FPU */
  31. li t0, XSTATUS_FS # close fpu
  32. csrc SRC_XSTATUS, t0
  33. #ifdef RISCV_S_MODE
  34. li t0, XSTATUS_PUM # PUM has no effect
  35. csrs SRC_XSTATUS, t0
  36. #endif
  37. .option push
  38. .option norelax
  39. la gp, __global_pointer$
  40. .option pop
  41. la sp, __stack_start__
  42. li t0, __STACKSIZE__
  43. add sp, sp, t0
  44. csrw SRC_XSCRATCH, sp
  45. j primary_cpu_entry
  46. park:
  47. wfi
  48. j park