head-common.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/kernel/head-common.S
  4. *
  5. * Copyright (C) 1994-2002 Russell King
  6. * Copyright (c) 2003 ARM Limited
  7. * All Rights Reserved
  8. */
  9. #include <asm/assembler.h>
  10. #define ATAG_CORE 0x54410001
  11. #define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)
  12. #define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2)
  13. #ifdef CONFIG_CPU_BIG_ENDIAN
  14. #define OF_DT_MAGIC 0xd00dfeed
  15. #else
  16. #define OF_DT_MAGIC 0xedfe0dd0 /* 0xd00dfeed in big-endian */
  17. #endif
  18. /*
  19. * Exception handling. Something went wrong and we can't proceed. We
  20. * ought to tell the user, but since we don't have any guarantee that
  21. * we're even running on the right architecture, we do virtually nothing.
  22. *
  23. * If CONFIG_DEBUG_LL is set we try to print out something about the error
  24. * and hope for the best (useful if bootloader fails to pass a proper
  25. * machine ID for example).
  26. */
  27. __HEAD
  28. /* Determine validity of the r2 atags pointer. The heuristic requires
  29. * that the pointer be aligned, in the first 16k of physical RAM and
  30. * that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE
  31. * is selected, then it will also accept a dtb pointer. Future revisions
  32. * of this function may be more lenient with the physical address and
  33. * may also be able to move the ATAGS block if necessary.
  34. *
  35. * Returns:
  36. * r2 either valid atags pointer, valid dtb pointer, or zero
  37. * r5, r6 corrupted
  38. */
  39. __vet_atags:
  40. tst r2, #0x3 @ aligned?
  41. bne 1f
  42. ldr r5, [r2, #0]
  43. #ifdef CONFIG_OF_FLATTREE
  44. ldr r6, =OF_DT_MAGIC @ is it a DTB?
  45. cmp r5, r6
  46. beq 2f
  47. #endif
  48. cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE?
  49. cmpne r5, #ATAG_CORE_SIZE_EMPTY
  50. bne 1f
  51. ldr r5, [r2, #4]
  52. ldr r6, =ATAG_CORE
  53. cmp r5, r6
  54. bne 1f
  55. 2: ret lr @ atag/dtb pointer is ok
  56. 1: mov r2, #0
  57. ret lr
  58. ENDPROC(__vet_atags)
  59. /*
  60. * The following fragment of code is executed with the MMU on in MMU mode,
  61. * and uses absolute addresses; this is not position independent.
  62. *
  63. * r0 = cp#15 control register (exc_ret for M-class)
  64. * r1 = machine ID
  65. * r2 = atags/dtb pointer
  66. * r9 = processor ID
  67. */
  68. __INIT
  69. __mmap_switched:
  70. mov r7, r1
  71. mov r8, r2
  72. mov r10, r0
  73. adr r4, __mmap_switched_data
  74. mov fp, #0
  75. #if defined(CONFIG_XIP_DEFLATED_DATA)
  76. ARM( ldr sp, [r4], #4 )
  77. THUMB( ldr sp, [r4] )
  78. THUMB( add r4, #4 )
  79. bl __inflate_kernel_data @ decompress .data to RAM
  80. teq r0, #0
  81. bne __error
  82. #elif defined(CONFIG_XIP_KERNEL)
  83. ARM( ldmia r4!, {r0, r1, r2, sp} )
  84. THUMB( ldmia r4!, {r0, r1, r2, r3} )
  85. THUMB( mov sp, r3 )
  86. sub r2, r2, r1
  87. bl __memcpy @ copy .data to RAM
  88. #endif
  89. ARM( ldmia r4!, {r0, r1, sp} )
  90. THUMB( ldmia r4!, {r0, r1, r3} )
  91. THUMB( mov sp, r3 )
  92. sub r2, r1, r0
  93. mov r1, #0
  94. bl __memset @ clear .bss
  95. adr_l r0, init_task @ get swapper task_struct
  96. set_current r0, r1
  97. ldmia r4, {r0, r1, r2, r3}
  98. str r9, [r0] @ Save processor ID
  99. str r7, [r1] @ Save machine type
  100. str r8, [r2] @ Save atags pointer
  101. cmp r3, #0
  102. strne r10, [r3] @ Save control register values
  103. #ifdef CONFIG_KASAN
  104. bl kasan_early_init
  105. #endif
  106. mov lr, #0
  107. b start_kernel
  108. ENDPROC(__mmap_switched)
  109. .align 2
  110. .type __mmap_switched_data, %object
  111. __mmap_switched_data:
  112. #ifdef CONFIG_XIP_KERNEL
  113. #ifndef CONFIG_XIP_DEFLATED_DATA
  114. .long _sdata @ r0
  115. .long __data_loc @ r1
  116. .long _edata_loc @ r2
  117. #endif
  118. .long __bss_stop @ sp (temporary stack in .bss)
  119. #endif
  120. .long __bss_start @ r0
  121. .long __bss_stop @ r1
  122. .long init_thread_union + THREAD_START_SP @ sp
  123. .long processor_id @ r0
  124. .long __machine_arch_type @ r1
  125. .long __atags_pointer @ r2
  126. #ifdef CONFIG_CPU_CP15
  127. .long cr_alignment @ r3
  128. #else
  129. M_CLASS(.long exc_ret) @ r3
  130. AR_CLASS(.long 0) @ r3
  131. #endif
  132. .size __mmap_switched_data, . - __mmap_switched_data
  133. __FINIT
  134. .text
  135. /*
  136. * This provides a C-API version of __lookup_processor_type
  137. */
  138. ENTRY(lookup_processor_type)
  139. stmfd sp!, {r4 - r6, r9, lr}
  140. mov r9, r0
  141. bl __lookup_processor_type
  142. mov r0, r5
  143. ldmfd sp!, {r4 - r6, r9, pc}
  144. ENDPROC(lookup_processor_type)
  145. /*
  146. * Read processor ID register (CP#15, CR0), and look up in the linker-built
  147. * supported processor list. Note that we can't use the absolute addresses
  148. * for the __proc_info lists since we aren't running with the MMU on
  149. * (and therefore, we are not in the correct address space). We have to
  150. * calculate the offset.
  151. *
  152. * r9 = cpuid
  153. * Returns:
  154. * r3, r4, r6 corrupted
  155. * r5 = proc_info pointer in physical address space
  156. * r9 = cpuid (preserved)
  157. */
  158. __lookup_processor_type:
  159. /*
  160. * Look in <asm/procinfo.h> for information about the __proc_info
  161. * structure.
  162. */
  163. adr_l r5, __proc_info_begin
  164. adr_l r6, __proc_info_end
  165. 1: ldmia r5, {r3, r4} @ value, mask
  166. and r4, r4, r9 @ mask wanted bits
  167. teq r3, r4
  168. beq 2f
  169. add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
  170. cmp r5, r6
  171. blo 1b
  172. mov r5, #0 @ unknown processor
  173. 2: ret lr
  174. ENDPROC(__lookup_processor_type)
  175. __error_lpae:
  176. #ifdef CONFIG_DEBUG_LL
  177. adr r0, str_lpae
  178. bl printascii
  179. b __error
  180. str_lpae: .asciz "\nError: Kernel with LPAE support, but CPU does not support LPAE.\n"
  181. #else
  182. b __error
  183. #endif
  184. .align
  185. ENDPROC(__error_lpae)
  186. __error_p:
  187. #ifdef CONFIG_DEBUG_LL
  188. adr r0, str_p1
  189. bl printascii
  190. mov r0, r9
  191. bl printhex8
  192. adr r0, str_p2
  193. bl printascii
  194. b __error
  195. str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
  196. str_p2: .asciz ").\n"
  197. .align
  198. #endif
  199. ENDPROC(__error_p)
  200. __error:
  201. #ifdef CONFIG_ARCH_RPC
  202. /*
  203. * Turn the screen red on a error - RiscPC only.
  204. */
  205. mov r0, #0x02000000
  206. mov r3, #0x11
  207. orr r3, r3, r3, lsl #8
  208. orr r3, r3, r3, lsl #16
  209. str r3, [r0], #4
  210. str r3, [r0], #4
  211. str r3, [r0], #4
  212. str r3, [r0], #4
  213. #endif
  214. 1: mov r0, r0
  215. b 1b
  216. ENDPROC(__error)