start_gcc.S 3.3 KB

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