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.

164 lines
2.6 KiB

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