start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. !********************************************************************************************************
  2. !
  3. ! (c) Copyright 2005-2014, Andes Techonology
  4. ! All Rights Reserved
  5. !
  6. ! NDS32 Generic Port
  7. ! GNU C Compiler
  8. !
  9. !********************************************************************************************************
  10. !********************************************************************************************************
  11. ! INCLUDE ASSEMBLY CONSTANTS
  12. !********************************************************************************************************
  13. #include <nds32_init.inc>
  14. #include "nds32_defs.h"
  15. #include "os_cpu_common.h"
  16. #ifndef VECTOR_NUMINTRS
  17. #define VECTOR_NUMINTRS 32
  18. #endif
  19. .global OS_Init_Nds32
  20. .global OS_Int_Vectors
  21. .global OS_Int_Vectors_End
  22. .macro WEAK_DEFAULT weak_sym, default_handler
  23. .weak \weak_sym
  24. .set \weak_sym ,\default_handler
  25. .endm
  26. ! Define standard NDS32 vector table entry point of
  27. ! exception/interruption vectors
  28. .macro VECTOR handler
  29. WEAK_DEFAULT \handler, OS_Default_Exception
  30. .align 4
  31. __\handler:
  32. #ifdef MPU_SUPPORT
  33. la $p0, \handler
  34. jr5 $p0
  35. #else
  36. pushm $r0, $r5
  37. la $r0, \handler
  38. jr5 $r0
  39. #endif
  40. .endm
  41. .macro INTERRUPT_VECTOR num
  42. WEAK_DEFAULT OS_Trap_Interrupt_HW\num, OS_Default_Interrupt
  43. .align 4
  44. __OS_Trap_Interrupt_HW\num:
  45. #ifdef MPU_SUPPORT
  46. la $p1, OS_Trap_Interrupt_HW\num
  47. li $p0, \num
  48. jr5 $p1
  49. #else
  50. pushm $r0, $r5
  51. la $r1, OS_Trap_Interrupt_HW\num
  52. li $r0, \num
  53. jr5 $r1
  54. #endif
  55. .endm
  56. !********************************************************************************************************
  57. ! Vector Entry Table
  58. !********************************************************************************************************
  59. .section .nds32_init, "ax"
  60. OS_Int_Vectors:
  61. b OS_Init_Nds32 ! (0) Trap Reset/NMI
  62. VECTOR OS_Trap_TLB_Fill ! (1) Trap TLB fill
  63. VECTOR OS_Trap_PTE_Not_Present ! (2) Trap PTE not present
  64. VECTOR OS_Trap_TLB_Misc ! (3) Trap TLB misc
  65. VECTOR OS_Trap_TLB_VLPT_Miss ! (4) Trap TLB VLPT miss
  66. VECTOR OS_Trap_Machine_Error ! (5) Trap Machine error
  67. VECTOR OS_Trap_Debug_Related ! (6) Trap Debug related
  68. VECTOR OS_Trap_General_Exception ! (7) Trap General exception
  69. VECTOR OS_Trap_Syscall ! (8) Syscall
  70. ! Interrupt vectors
  71. .altmacro
  72. .set irqno, 0
  73. .rept VECTOR_NUMINTRS
  74. INTERRUPT_VECTOR %irqno
  75. .set irqno, irqno+1
  76. .endr
  77. .align 4
  78. OS_Int_Vectors_End:
  79. !******************************************************************************************************
  80. ! Start Entry
  81. !******************************************************************************************************
  82. .section .text
  83. .global _start
  84. OS_Init_Nds32:
  85. _start:
  86. !************************** Begin of do-not-modify **************************
  87. ! Please don't modify this code
  88. ! Initialize the registers used by the compiler
  89. nds32_init ! NDS32 startup initial macro in <nds32_init.inc>
  90. !*************************** End of do-not-modify ***************************
  91. #ifdef CONFIG_HWZOL
  92. ! enable AEN
  93. mfsr $r0, $PSW
  94. ori $r0, $r0, (1 << PSW_offAEN)
  95. mtsr $r0, $PSW
  96. #endif
  97. #if (defined(CONFIG_CPU_ICACHE_ENABLE) || defined(CONFIG_CPU_DCACHE_ENABLE))
  98. ! disable cache
  99. mfsr $r0, $CACHE_CTL
  100. li $r1, ~(CACHE_CTL_mskIC_EN | CACHE_CTL_mskDC_EN)
  101. and $r0, $r0, $r1
  102. mtsr $r0, $CACHE_CTL
  103. #endif
  104. ! Do system low level setup. It must be a leaf function.
  105. bal _nds32_init_mem
  106. #if 1 /* Speed prefer */
  107. ! We do this on a word basis.
  108. ! Currently, the default linker script guarantee
  109. ! the __bss_start/_end boundary word-aligned.
  110. ! Clear bss
  111. la $r0, __bss_start
  112. la $r1, _end
  113. sub $r2, $r1, $r0 ! $r2: Size of .bss
  114. beqz $r2, clear_end
  115. andi $r7, $r2, 0x1f ! $r7 = $r2 mod 32
  116. movi $r3, 0
  117. movi $r4, 0
  118. movi $r5, 0
  119. movi $r6, 0
  120. movi $r8, 0
  121. movi $r9, 0
  122. movi $r10, 0
  123. beqz $r7, clear_loop ! if $r7 == 0, bss_size%32 == 0
  124. sub $r2, $r2, $r7
  125. first_clear:
  126. swi.bi $r3, [$r0], #4 ! clear each word
  127. addi $r7, $r7, -4
  128. bnez $r7, first_clear
  129. li $r1, 0xffffffe0
  130. and $r2, $r2, $r1 ! check bss_size/32 == 0 or not
  131. beqz $r2, clear_end ! if bss_size/32 == 0 , needless to clear
  132. clear_loop:
  133. smw.bim $r3, [$r0], $r10 !clear each 8 words
  134. addi $r2, $r2, -32
  135. bgez $r2, clear_loop
  136. clear_end:
  137. #else /* Size prefer */
  138. ! Clear bss
  139. la $r0, _edata
  140. la $r1, _end
  141. beq $r0, $r1, 2f
  142. li $r2, #0
  143. 1:
  144. swi.bi $r2, [$r0], #4
  145. bne $r0, $r1, 1b
  146. 2:
  147. #endif
  148. ! Set-up the stack pointer
  149. la $sp, _stack
  150. ! System reset handler
  151. bal reset
  152. ! Default exceptions / interrupts handler
  153. OS_Default_Exception:
  154. OS_Default_Interrupt:
  155. die:
  156. b die
  157. !********************************************************************************************************
  158. ! Interrupt vector Table
  159. !********************************************************************************************************
  160. .data
  161. .align 2
  162. ! These tables contain the isr pointers used to deliver interrupts
  163. .global OS_CPU_Vector_Table
  164. OS_CPU_Vector_Table:
  165. .rept 32
  166. .long OS_Default_Interrupt
  167. .endr
  168. .end