start.S 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // See LICENSE for license details.
  2. #include "encoding.h"
  3. #include "platform.h"
  4. #include "sys.h"
  5. /* This is defined in sifive/platform.h, but that can't be included from
  6. * assembly. */
  7. .section .init
  8. .globl _start
  9. _start:
  10. la t0, trap_entry
  11. csrw mtvec, t0
  12. csrwi mstatus, 0
  13. csrwi mie, 0
  14. // Allocate 4 KiB stack for each hart
  15. csrr t0, mhartid
  16. slli t0, t0, 12
  17. la sp, _sp
  18. sub sp, sp, t0
  19. li a1, NONSMP_HART;
  20. csrr a0, mhartid;
  21. bne a0, a1, .LbootOtherHart //other hart
  22. // Load data section
  23. la t0, _data_lma
  24. la t1, _data
  25. beq t0, t1, 2f
  26. la t2, _edata
  27. bgeu t1, t2, 2f
  28. 1:
  29. ld t3, 0(t0)
  30. sd t3, 0(t1)
  31. addi t0, t0, 8
  32. addi t1, t1, 8
  33. bltu t1, t2, 1b
  34. 2:
  35. /* Clear bss section */
  36. la t1, _bss_start
  37. la t2, _bss_end
  38. bgeu t1, t2, 4f
  39. 3:
  40. sd x0, 0(t1)
  41. addi t1, t1, 8
  42. blt t1, t2, 3b
  43. 4:
  44. /*only hart 0*/
  45. call BootMain
  46. j .enter_uboot
  47. .LbootOtherHart:
  48. li s1, CLINT_CTRL_ADDR
  49. csrr a0, mhartid
  50. slli s2, a0, 2
  51. add s2, s2, s1
  52. sw zero, 0(s2)
  53. fence
  54. csrw mip, 0
  55. # core 1 jumps to main_other_hart
  56. # Set MSIE bit to receive IPI
  57. li a2, MIP_MSIP
  58. csrw mie, a2
  59. .LwaitOtherHart:
  60. # Wait for an IPI to signal that its safe to boot
  61. // call second_hart
  62. wfi
  63. # Only start if MIP_MSIP is set
  64. csrr a2, mip
  65. andi a2, a2, MIP_MSIP
  66. beqz a2, .LwaitOtherHart
  67. li s1, CLINT_CTRL_ADDR
  68. csrr a0, mhartid
  69. slli s2, a0, 2
  70. add s2, s2, s1
  71. sw zero, 0(s2)
  72. fence
  73. csrw mip, 0
  74. li a2, NUM_CORES
  75. bltu a0, a2, .enter_uboot
  76. j .LwaitOtherHart
  77. .enter_uboot:
  78. li t0, DEFAULT_DDR_ADDR
  79. csrr a0, mhartid
  80. la a1, 0
  81. jr t0