You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
2.4 KiB

  1. .section .init
  2. .global _start
  3. .type _start,@function
  4. _start:
  5. #ifndef VEXRISCV_RWMTVEC
  6. j _crtInit
  7. nop
  8. nop
  9. nop
  10. nop
  11. nop
  12. nop
  13. nop
  14. j trap_entry
  15. _crtInit:
  16. #endif
  17. .cfi_startproc
  18. .cfi_undefined ra
  19. .option push
  20. .option norelax
  21. la gp, __global_pointer$
  22. .option pop
  23. la sp, _sp
  24. #ifndef VEXRISCV_VOLATILE
  25. /* Load data section */
  26. la a0, _data_lma
  27. la a1, _data
  28. la a2, _edata
  29. bgeu a1, a2, 2f
  30. 1:
  31. lw t0, (a0)
  32. sw t0, (a1)
  33. addi a0, a0, 4
  34. addi a1, a1, 4
  35. bltu a1, a2, 1b
  36. 2:
  37. #endif
  38. /* Clear bss section */
  39. la a0, __bss_start
  40. la a1, _end
  41. bgeu a0, a1, 2f
  42. 1:
  43. sw zero, (a0)
  44. addi a0, a0, 4
  45. bltu a0, a1, 1b
  46. 2:
  47. /* Call global constructors */
  48. la a0, __libc_fini_array
  49. call atexit
  50. call __libc_init_array
  51. auipc ra, 0
  52. addi sp, sp, -16
  53. sw ra, 8(sp)
  54. /* Enable Interrupts and set trap vector */
  55. #ifndef VEXRISCV_RWMTVEC
  56. la a0, trap_entry
  57. csrw mtvec, a0
  58. #endif
  59. li a0, 0x880 //880 enable timer + external interrupts
  60. csrw mie, a0
  61. li a0, 0x1808 //1808 enable interrupts
  62. csrw mstatus, a0
  63. /* argc = argv = 0 */
  64. li a0, 0
  65. li a1, 0
  66. call main
  67. tail exit
  68. 1:
  69. j 1b
  70. .cfi_endproc
  71. .align 4
  72. .weak trap_entry
  73. .global trap_entry
  74. trap_entry:
  75. addi sp, sp, -32*4
  76. sw x1, 1*4(sp)
  77. sw x2, 2*4(sp)
  78. sw x3, 3*4(sp)
  79. sw x4, 4*4(sp)
  80. sw x5, 5*4(sp)
  81. sw x6, 6*4(sp)
  82. sw x7, 7*4(sp)
  83. sw x8, 8*4(sp)
  84. sw x9, 9*4(sp)
  85. sw x10, 10*4(sp)
  86. sw x11, 11*4(sp)
  87. sw x12, 12*4(sp)
  88. sw x13, 13*4(sp)
  89. sw x14, 14*4(sp)
  90. sw x15, 15*4(sp)
  91. sw x16, 16*4(sp)
  92. sw x17, 17*4(sp)
  93. sw x18, 18*4(sp)
  94. sw x19, 19*4(sp)
  95. sw x20, 20*4(sp)
  96. sw x21, 21*4(sp)
  97. sw x22, 22*4(sp)
  98. sw x23, 23*4(sp)
  99. sw x24, 24*4(sp)
  100. sw x25, 25*4(sp)
  101. sw x26, 26*4(sp)
  102. sw x27, 27*4(sp)
  103. sw x28, 28*4(sp)
  104. sw x29, 29*4(sp)
  105. sw x30, 30*4(sp)
  106. sw x31, 31*4(sp)
  107. call irqCallback
  108. lw x1, 1*4(sp)
  109. lw x2, 2*4(sp)
  110. lw x3, 3*4(sp)
  111. lw x4, 4*4(sp)
  112. lw x5, 5*4(sp)
  113. lw x6, 6*4(sp)
  114. lw x7, 7*4(sp)
  115. lw x8, 8*4(sp)
  116. lw x9, 9*4(sp)
  117. lw x10, 10*4(sp)
  118. lw x11, 11*4(sp)
  119. lw x12, 12*4(sp)
  120. lw x13, 13*4(sp)
  121. lw x14, 14*4(sp)
  122. lw x15, 15*4(sp)
  123. lw x16, 16*4(sp)
  124. lw x17, 17*4(sp)
  125. lw x18, 18*4(sp)
  126. lw x19, 19*4(sp)
  127. lw x20, 20*4(sp)
  128. lw x21, 21*4(sp)
  129. lw x22, 22*4(sp)
  130. lw x23, 23*4(sp)
  131. lw x24, 24*4(sp)
  132. lw x25, 25*4(sp)
  133. lw x26, 26*4(sp)
  134. lw x27, 27*4(sp)
  135. lw x28, 28*4(sp)
  136. lw x29, 29*4(sp)
  137. lw x30, 30*4(sp)
  138. lw x31, 31*4(sp)
  139. addi sp, sp, 32*4
  140. mret
  141. .weak irqCallback
  142. irqCallback:
  143. 1:
  144. j 1b