startup.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2020-2020, BLUETRUM Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "ab32vg1.h"
  7. .global _start
  8. .section .reset, "ax"
  9. _start:
  10. la tp, _tp
  11. la gp, _gp
  12. //load comm
  13. la a0, __comm_vma
  14. la a1, __comm_lma
  15. la a2, __comm_size
  16. call _memcpy
  17. //load ram1
  18. la a0, __ram1_vma
  19. la a1, __ram1_lma
  20. la a2, __ram1_size
  21. call _memcpy
  22. la a0, __irq_stack_start //Stack清成0x23
  23. li a1, 0x23
  24. la a2, __irq_stack_size
  25. call rt_memset
  26. la ra, __irq_stack
  27. lui a5, 0x1
  28. sw zero, -1920(a5)
  29. sw zero, -1916(a5)
  30. //clear bss
  31. la a0, __bss_start
  32. li a1, 0
  33. la a2, __bss_size
  34. call rt_memset
  35. call cache_init
  36. la a0, __comm_vma
  37. sw a0, PICADR(zero)
  38. call entry
  39. la ra, __exception
  40. jr ra
  41. .section .vector, "ax"
  42. .org 0x10
  43. __exception:
  44. li sp, 0x10600 //出错后,不破坏错误点的堆栈数据
  45. jal exception_isr
  46. 1: j 1b
  47. mret
  48. .org 0x40
  49. jal x0, low_prio_irq
  50. .org 0x80
  51. #define METHOD 1
  52. #if METHOD == 1
  53. addi sp, sp, -6*4
  54. # lw a0, PICEN(zero)
  55. lw a1, EPC(zero)
  56. lw a2, EPICCON(zero)
  57. # sw a0, 3*4(sp)
  58. sw a1, 4*4(sp)
  59. sw a2, 5*4(sp)
  60. # andi a0, a0, 1
  61. # sw a0, PICEN(zero)
  62. li a2, 0
  63. sw a2, EPICCON(zero)
  64. la a0, 0f
  65. sw a0, EPC(zero)
  66. j isr_cache
  67. 0:
  68. sw a0, 0(sp)
  69. sw a1, 4(sp)
  70. sw a2, 8(sp)
  71. # lw a0, 3*4(sp)
  72. lw a1, 4*4(sp)
  73. lw a2, 5*4(sp)
  74. # sw a0, PICEN(zero)
  75. sw a1, EPC(zero)
  76. sw a2, EPICCON(zero)
  77. lw a0, 0(sp)
  78. lw a1, 4(sp)
  79. lw a2, 8(sp)
  80. addi sp, sp, 6*4
  81. mret
  82. #endif
  83. .org 0x1e0
  84. 1: j 1b
  85. nop
  86. mret
  87. .global cpu_irq_comm
  88. cpu_irq_comm:
  89. la a5, __irq_stack
  90. mv sp, a5
  91. j cpu_irq_comm_do
  92. ret
  93. .global _tp
  94. .set _tp, 0x84800
  95. .set _memcpy, 0x84044