head-common.S 5.4 KB

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