head-common.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. bic r4, r0, #CR_A @ Clear 'A' bit
  91. stmia r7, {r0, r4} @ 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. .long cr_alignment @ r7
  105. .long init_thread_union + THREAD_START_SP @ sp
  106. .size __mmap_switched_data, . - __mmap_switched_data
  107. /*
  108. * This provides a C-API version of __lookup_processor_type
  109. */
  110. ENTRY(lookup_processor_type)
  111. stmfd sp!, {r4 - r6, r9, lr}
  112. mov r9, r0
  113. bl __lookup_processor_type
  114. mov r0, r5
  115. ldmfd sp!, {r4 - r6, r9, pc}
  116. ENDPROC(lookup_processor_type)
  117. /*
  118. * Read processor ID register (CP#15, CR0), and look up in the linker-built
  119. * supported processor list. Note that we can't use the absolute addresses
  120. * for the __proc_info lists since we aren't running with the MMU on
  121. * (and therefore, we are not in the correct address space). We have to
  122. * calculate the offset.
  123. *
  124. * r9 = cpuid
  125. * Returns:
  126. * r3, r4, r6 corrupted
  127. * r5 = proc_info pointer in physical address space
  128. * r9 = cpuid (preserved)
  129. */
  130. __CPUINIT
  131. __lookup_processor_type:
  132. adr r3, __lookup_processor_type_data
  133. ldmia r3, {r4 - r6}
  134. sub r3, r3, r4 @ get offset between virt&phys
  135. add r5, r5, r3 @ convert virt addresses to
  136. add r6, r6, r3 @ physical address space
  137. 1: ldmia r5, {r3, r4} @ value, mask
  138. and r4, r4, r9 @ mask wanted bits
  139. teq r3, r4
  140. beq 2f
  141. add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
  142. cmp r5, r6
  143. blo 1b
  144. mov r5, #0 @ unknown processor
  145. 2: mov pc, lr
  146. ENDPROC(__lookup_processor_type)
  147. /*
  148. * Look in <asm/procinfo.h> for information about the __proc_info structure.
  149. */
  150. .align 2
  151. .type __lookup_processor_type_data, %object
  152. __lookup_processor_type_data:
  153. .long .
  154. .long __proc_info_begin
  155. .long __proc_info_end
  156. .size __lookup_processor_type_data, . - __lookup_processor_type_data
  157. __error_p:
  158. #ifdef CONFIG_DEBUG_LL
  159. adr r0, str_p1
  160. bl printascii
  161. mov r0, r9
  162. bl printhex8
  163. adr r0, str_p2
  164. bl printascii
  165. b __error
  166. str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
  167. str_p2: .asciz ").\n"
  168. .align
  169. #endif
  170. ENDPROC(__error_p)
  171. __error:
  172. #ifdef CONFIG_ARCH_RPC
  173. /*
  174. * Turn the screen red on a error - RiscPC only.
  175. */
  176. mov r0, #0x02000000
  177. mov r3, #0x11
  178. orr r3, r3, r3, lsl #8
  179. orr r3, r3, r3, lsl #16
  180. str r3, [r0], #4
  181. str r3, [r0], #4
  182. str r3, [r0], #4
  183. str r3, [r0], #4
  184. #endif
  185. 1: mov r0, r0
  186. b 1b
  187. ENDPROC(__error)