startup_gcc.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2006-2022, 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. boot_hartid: .int
  16. .global boot_hartid
  17. .global _start
  18. .section ".start", "ax"
  19. _start:
  20. #ifdef RISCV_S_MODE
  21. # save hartid
  22. la t0, boot_hartid # global varible rt_boot_hartid
  23. mv t1, a0 # get hartid in S-mode frome a0 register
  24. sw t1, (t0) # store t1 register low 4 bits in memory address which is stored in t0
  25. #else
  26. # setup stacks per hart
  27. csrr t0, mhartid # read current hart id
  28. slli t0, t0, 10 # shift left the hart id by 1024
  29. # park harts with id != 0
  30. csrr a0, mhartid # read current hart id
  31. bnez a0, park # if we're not on the hart 0
  32. #endif
  33. csrw SRC_XIE, 0 # clear Interrupt Registers
  34. csrw SRC_XIP, 0
  35. la t0, trap_entry
  36. csrw SRC_XTVEC, t0 # set Trap Vector Base Address Register
  37. /* set to disable FPU */
  38. li t0, XSTATUS_FS # close fpu
  39. csrc SRC_XSTATUS, t0
  40. #ifdef RISCV_S_MODE
  41. li t0, XSTATUS_PUM # PUM has no effect
  42. csrs SRC_XSTATUS, t0
  43. #endif
  44. .option push
  45. .option norelax
  46. la gp, __global_pointer$
  47. .option pop
  48. la sp, __stack_start__
  49. li t0, __STACKSIZE__
  50. add sp, sp, t0
  51. csrw SRC_XSCRATCH, sp
  52. j primary_cpu_entry
  53. park:
  54. wfi
  55. j park