start_gcc.S 3.4 KB

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