asm.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Entry point of all programs (_start).
  3. It initializes DWARF call frame information, the stack pointer, the
  4. frame pointer (needed for closures to work in start_rust) and the global
  5. pointer. Then it calls _start_rust.
  6. */
  7. .section .init, "ax"
  8. .global _start
  9. _start:
  10. .cfi_startproc
  11. .cfi_undefined ra
  12. csrw mideleg, 0
  13. csrw medeleg, 0
  14. csrw mie, 0
  15. csrw mip, 0
  16. li x1, 0
  17. li x2, 0
  18. li x3, 0
  19. li x4, 0
  20. li x5, 0
  21. li x6, 0
  22. li x7, 0
  23. li x8, 0
  24. li x9, 0
  25. li x10,0
  26. li x11,0
  27. li x12,0
  28. li x13,0
  29. li x14,0
  30. li x15,0
  31. li x16,0
  32. li x17,0
  33. li x18,0
  34. li x19,0
  35. li x20,0
  36. li x21,0
  37. li x22,0
  38. li x23,0
  39. li x24,0
  40. li x25,0
  41. li x26,0
  42. li x27,0
  43. li x28,0
  44. li x29,0
  45. li x30,0
  46. li x31,0
  47. .option push
  48. .option norelax
  49. la gp, __global_pointer$
  50. .option pop
  51. // Check hart id
  52. csrr a2, mhartid
  53. lui t0, %hi(_max_hart_id)
  54. add t0, t0, %lo(_max_hart_id)
  55. bgtu a2, t0, abort
  56. // Allocate stacks
  57. la sp, _stack_start
  58. lui t0, %hi(_hart_stack_size)
  59. add t0, t0, %lo(_hart_stack_size)
  60. mul t0, a2, t0
  61. sub sp, sp, t0
  62. // Set frame pointer
  63. add s0, sp, zero
  64. // Park non-zero harts
  65. bnez a2, abort
  66. jal zero, _start_rust
  67. .cfi_endproc
  68. /*
  69. Trap entry point (_start_trap)
  70. Saves caller saved registers ra, t0..6, a0..7, calls _start_trap_rust,
  71. restores caller saved registers and then returns.
  72. */
  73. .section .trap, "ax"
  74. .global _start_trap
  75. _start_trap:
  76. addi sp, sp, -16*4
  77. sw ra, 0*4(sp)
  78. sw t0, 1*4(sp)
  79. sw t1, 2*4(sp)
  80. sw t2, 3*4(sp)
  81. sw t3, 4*4(sp)
  82. sw t4, 5*4(sp)
  83. sw t5, 6*4(sp)
  84. sw t6, 7*4(sp)
  85. sw a0, 8*4(sp)
  86. sw a1, 9*4(sp)
  87. sw a2, 10*4(sp)
  88. sw a3, 11*4(sp)
  89. sw a4, 12*4(sp)
  90. sw a5, 13*4(sp)
  91. sw a6, 14*4(sp)
  92. sw a7, 15*4(sp)
  93. jal ra, _start_trap_rust
  94. lw ra, 0*4(sp)
  95. lw t0, 1*4(sp)
  96. lw t1, 2*4(sp)
  97. lw t2, 3*4(sp)
  98. lw t3, 4*4(sp)
  99. lw t4, 5*4(sp)
  100. lw t5, 6*4(sp)
  101. lw t6, 7*4(sp)
  102. lw a0, 8*4(sp)
  103. lw a1, 9*4(sp)
  104. lw a2, 10*4(sp)
  105. lw a3, 11*4(sp)
  106. lw a4, 12*4(sp)
  107. lw a5, 13*4(sp)
  108. lw a6, 14*4(sp)
  109. lw a7, 15*4(sp)
  110. addi sp, sp, 16*4
  111. mret
  112. /* Make sure there is an abort when linking */
  113. .section .init
  114. .globl abort
  115. abort:
  116. j abort