crt0.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #define DSB .byte 0x4f, 0xf0, 0x7f, 0xf5
  24. #define ISB .byte 0x6f, 0xf0, 0x7f, 0xf5
  25. .section ".text.boot"
  26. .globl _start
  27. _start:
  28. b reset
  29. b arm_undefined
  30. b arm_syscall
  31. b arm_prefetch_abort
  32. b arm_data_abort
  33. b arm_reserved
  34. b arm_irq
  35. b arm_fiq
  36. /*pre-loader to uboot argument Location*/
  37. .global BOOT_ARGUMENT_LOCATION
  38. BOOT_ARGUMENT_LOCATION:
  39. .word 0x00000000
  40. reset:
  41. ldr r6, =BOOT_ARGUMENT_LOCATION
  42. str r4, [r6]
  43. #ifdef ARM_CPU_CORTEX_A7
  44. /*Enable SMP bit*/
  45. mrc p15, 0, r0, c1, c0, 1
  46. orr r0, r0, #0x40
  47. mcr p15, 0, r0, c1, c0, 1
  48. #endif
  49. #ifdef ENABLE_TRUSTZONE
  50. /*Add reference to TZ symbol so linker includes it in final image */
  51. ldr r7, =_binary_tzbsp_tzbsp_bin_start
  52. #endif
  53. /* do some cpu setup */
  54. #if ARM_WITH_CP15
  55. /* Read SCTLR */
  56. mrc p15, 0, r0, c1, c0, 0
  57. /* XXX this is currently for arm926, revist with armv6 cores */
  58. /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */
  59. bic r0, r0, #(1<<15| 1<<13 | 1<<12)
  60. bic r0, r0, #(1<<2 | 1<<0)
  61. /* enable alignment faults */
  62. orr r0, r0, #(1<<1)
  63. /* Write SCTLR */
  64. mcr p15, 0, r0, c1, c0, 0
  65. #ifdef ENABLE_TRUSTZONE
  66. /*nkazi: not needed ? Setting VBAR to location of new vector table : 0x80000 */
  67. ldr r0, =0x00080000
  68. mcr p15, 0, r0, c12, c0, 0
  69. #endif
  70. #endif
  71. #if WITH_CPU_EARLY_INIT
  72. /* call platform/arch/etc specific init code */
  73. #ifndef ENABLE_TRUSTZONE
  74. /* Not needed when TrustZone is the first bootloader that runs.*/
  75. bl __cpu_early_init
  76. #endif
  77. /* declare return address as global to avoid using stack */
  78. .globl _cpu_early_init_complete
  79. _cpu_early_init_complete:
  80. #endif
  81. #if (!ENABLE_NANDWRITE)
  82. #if WITH_CPU_WARM_BOOT
  83. ldr r0, warm_boot_tag
  84. cmp r0, #1
  85. /* if set, warm boot */
  86. ldreq pc, =BASE_ADDR
  87. mov r0, #1
  88. str r0, warm_boot_tag
  89. #endif
  90. #endif
  91. /* see if we need to relocate */
  92. mov r0, pc
  93. sub r0, r0, #(.Laddr - _start)
  94. .Laddr:
  95. ldr r1, =_start
  96. cmp r0, r1
  97. beq .Lstack_setup
  98. /* we need to relocate ourselves to the proper spot */
  99. ldr r2, =__data_end
  100. .Lrelocate_loop:
  101. ldr r3, [r0], #4
  102. str r3, [r1], #4
  103. cmp r1, r2
  104. bne .Lrelocate_loop
  105. /* we're relocated, jump to the right address */
  106. ldr r0, =.Lstack_setup
  107. bx r0
  108. .ltorg
  109. #if WITH_CPU_WARM_BOOT
  110. warm_boot_tag:
  111. .word 0
  112. #endif
  113. .Lstack_setup:
  114. /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
  115. mrs r0, cpsr
  116. bic r0, r0, #0x1f
  117. ldr r2, =abort_stack_top
  118. orr r1, r0, #0x12 // irq
  119. msr cpsr_c, r1
  120. ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
  121. orr r1, r0, #0x11 // fiq
  122. msr cpsr_c, r1
  123. mov sp, r2
  124. orr r1, r0, #0x17 // abort
  125. msr cpsr_c, r1
  126. mov sp, r2
  127. orr r1, r0, #0x1b // undefined
  128. msr cpsr_c, r1
  129. mov sp, r2
  130. orr r1, r0, #0x1f // system
  131. msr cpsr_c, r1
  132. mov sp, r2
  133. orr r1, r0, #0x13 // supervisor
  134. msr cpsr_c, r1
  135. mov sp, r2
  136. /* copy the initialized data segment out of rom if necessary */
  137. ldr r0, =__data_start_rom
  138. ldr r1, =__data_start
  139. ldr r2, =__data_end
  140. cmp r0, r1
  141. beq .L__do_bss
  142. .L__copy_loop:
  143. cmp r1, r2
  144. ldrlt r3, [r0], #4
  145. strlt r3, [r1], #4
  146. blt .L__copy_loop
  147. .L__do_bss:
  148. /* clear out the bss */
  149. ldr r0, =__bss_start
  150. ldr r1, =_end
  151. mov r2, #0
  152. .L__bss_loop:
  153. cmp r0, r1
  154. strlt r2, [r0], #4
  155. blt .L__bss_loop
  156. #if defined(ARM_CPU_CORTEX_A8) || defined(ARM_CPU_CORTEX_A9)
  157. DSB
  158. ISB
  159. #endif
  160. bl kmain
  161. b .
  162. .ltorg
  163. .bss
  164. .align 2
  165. /* the abort stack is for unrecoverable errors.
  166. * also note the initial working stack is set to here.
  167. * when the threading system starts up it'll switch to a new
  168. * dynamically allocated stack, so we don't need it for very long
  169. */
  170. abort_stack:
  171. .skip 8192
  172. abort_stack_top:
  173. .section ".rodata"
  174. .align 2
  175. /* define the heap end as read-only data containing the end defined in the
  176. * linker script. other archs that use dynamic memory length discovery can make
  177. * this read-write and update it during init.
  178. */
  179. .global _heap_end
  180. _heap_end:
  181. .int _end_of_ram