start_gcc.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-05-17 swkyer first version
  9. * 2010-09-04 bernard porting to JZ47xx
  10. * 2019-07-19 Zhou Yanjie clean up code
  11. */
  12. #ifndef __ASSEMBLY__
  13. #define __ASSEMBLY__
  14. #endif
  15. #include "../common/mips_def.h"
  16. #include "../common/stackframe.h"
  17. #include "stack.h"
  18. .section ".start", "ax"
  19. .set noreorder
  20. /* the program entry */
  21. .globl _start
  22. _start:
  23. .set noreorder
  24. la ra, _start
  25. li t1, 0x00800000
  26. mtc0 t1, CP0_CAUSE
  27. /* init cp0 registers. */
  28. li t0, 0x0000FC00 /* BEV = 0 and mask all interrupt */
  29. mtc0 t0, CP0_STATUS
  30. /* setup stack pointer */
  31. li sp, SYSTEM_STACK
  32. la gp, _gp
  33. /* init caches, assumes a 4way * 128set * 32byte I/D cache */
  34. mtc0 zero, CP0_TAGLO /* TAGLO reg */
  35. mtc0 zero, CP0_TAGHI /* TAGHI reg */
  36. li t0, 3 /* enable cache for kseg0 accesses */
  37. mtc0 t0, CP0_CONFIG /* CONFIG reg */
  38. la t0, 0x80000000 /* an idx op should use an unmappable address */
  39. ori t1, t0, 0x4000 /* 16kB cache */
  40. _cache_loop:
  41. cache 0x8, 0(t0) /* index store icache tag */
  42. cache 0x9, 0(t0) /* index store dcache tag */
  43. bne t0, t1, _cache_loop
  44. addiu t0, t0, 0x20 /* 32 bytes per cache line */
  45. nop
  46. /* invalidate BTB */
  47. mfc0 t0, CP0_CONFIG
  48. nop
  49. ori t0, 2
  50. mtc0 t0, CP0_CONFIG
  51. nop
  52. /* copy IRAM section */
  53. la t0, _iramcopy
  54. la t1, _iramstart
  55. la t2, _iramend
  56. _iram_loop:
  57. lw t3, 0(t0)
  58. sw t3, 0(t1)
  59. addiu t1, 4
  60. bne t1, t2, _iram_loop
  61. addiu t0, 4
  62. /* clear bss */
  63. la t0, __bss_start
  64. la t1, __bss_end
  65. _clr_bss_loop:
  66. sw zero, 0(t0)
  67. bne t0, t1, _clr_bss_loop
  68. addiu t0, t0, 4
  69. /* jump to RT-Thread RTOS */
  70. jal rtthread_startup
  71. nop
  72. /* restart, never die */
  73. j _start
  74. nop
  75. .set reorder
  76. .globl cp0_get_cause
  77. cp0_get_cause:
  78. mfc0 v0, CP0_CAUSE
  79. jr ra
  80. nop
  81. .globl cp0_get_status
  82. cp0_get_status:
  83. mfc0 v0, CP0_STATUS
  84. jr ra
  85. nop
  86. .globl cp0_get_hi
  87. cp0_get_hi:
  88. mfhi v0
  89. jr ra
  90. nop
  91. .globl cp0_get_lo
  92. cp0_get_lo:
  93. mflo v0
  94. jr ra
  95. nop
  96. .extern tlb_refill_handler
  97. .extern cache_error_handler
  98. /* Exception Handler */
  99. /* 0x0 - TLB refill handler */
  100. .section .vectors.1, "ax", %progbits
  101. j tlb_refill_handler
  102. nop
  103. /* 0x100 - Cache error handler */
  104. .section .vectors.2, "ax", %progbits
  105. j cache_error_handler
  106. nop
  107. /* 0x180 - Exception/Interrupt handler */
  108. .section .vectors.3, "ax", %progbits
  109. j _general_exception_handler
  110. nop
  111. /* 0x200 - Special Exception Interrupt handler (when IV is set in CP0_CAUSE) */
  112. .section .vectors.4, "ax", %progbits
  113. j _irq_handler
  114. nop
  115. .section .vectors, "ax", %progbits
  116. .extern mips_irq_handle
  117. /* general exception handler */
  118. _general_exception_handler:
  119. .set noreorder
  120. mfc0 k1, CP0_CAUSE
  121. andi k1, k1, 0x7c
  122. srl k1, k1, 2
  123. lw k0, sys_exception_handlers(k1)
  124. jr k0
  125. nop
  126. .set reorder
  127. /* interrupt handler */
  128. _irq_handler:
  129. .set noreorder
  130. la k0, mips_irq_handle
  131. jr k0
  132. nop
  133. .set reorder