start_gcc.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // See LICENSE for license details.
  2. #include <sifive/smp.h>
  3. /* This is defined in sifive/platform.h, but that can't be included from
  4. * assembly. */
  5. #define CLINT_CTRL_ADDR 0x02000000
  6. .section .init
  7. .globl _start
  8. .type _start,@function
  9. _start:
  10. .cfi_startproc
  11. .cfi_undefined ra
  12. .option push
  13. .option norelax
  14. la gp, __global_pointer$
  15. .option pop
  16. la sp, _sp
  17. #if defined(ENABLE_SMP)
  18. smp_pause(t0, t1)
  19. #endif
  20. /* Load data section */
  21. la a0, _data_lma
  22. la a1, _data
  23. la a2, _edata
  24. bgeu a1, a2, 2f
  25. 1:
  26. lw t0, (a0)
  27. sw t0, (a1)
  28. addi a0, a0, 4
  29. addi a1, a1, 4
  30. bltu a1, a2, 1b
  31. 2:
  32. /* Clear bss section */
  33. la a0, __bss_start
  34. la a1, _end
  35. bgeu a0, a1, 2f
  36. 1:
  37. sw zero, (a0)
  38. addi a0, a0, 4
  39. bltu a0, a1, 1b
  40. 2:
  41. /* Call global constructors */
  42. la a0, __libc_fini_array
  43. call atexit
  44. call __libc_init_array
  45. #ifndef __riscv_float_abi_soft
  46. /* Enable FPU */
  47. li t0, MSTATUS_FS
  48. csrs mstatus, t0
  49. csrr t1, mstatus
  50. and t1, t1, t0
  51. beqz t1, 1f
  52. fssr x0
  53. 1:
  54. #endif
  55. #if defined(ENABLE_SMP)
  56. smp_resume(t0, t1)
  57. csrr a0, mhartid
  58. bnez a0, 2f
  59. #endif
  60. auipc ra, 0
  61. addi sp, sp, -16
  62. #if __riscv_xlen == 32
  63. sw ra, 8(sp)
  64. #else
  65. sd ra, 8(sp)
  66. #endif
  67. /* argc = argv = 0 */
  68. li a0, 0
  69. li a1, 0
  70. call main
  71. tail exit
  72. 1:
  73. j 1b
  74. #if defined(ENABLE_SMP)
  75. 2:
  76. la t0, trap_entry
  77. csrw mtvec, t0
  78. csrr a0, mhartid
  79. la t1, _sp
  80. slli t0, a0, 10
  81. sub sp, t1, t0
  82. auipc ra, 0
  83. addi sp, sp, -16
  84. #if __riscv_xlen == 32
  85. sw ra, 8(sp)
  86. #else
  87. sd ra, 8(sp)
  88. #endif
  89. call secondary_main
  90. tail exit
  91. 1:
  92. j 1b
  93. #endif
  94. .cfi_endproc