head-common.S 5.3 KB

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