head-common.S 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. .align 2
  17. .type __switch_data, %object
  18. __switch_data:
  19. .long __mmap_switched
  20. .long __data_loc @ r4
  21. .long _data @ r5
  22. .long __bss_start @ r6
  23. .long _end @ r7
  24. .long processor_id @ r4
  25. .long __machine_arch_type @ r5
  26. .long __atags_pointer @ r6
  27. .long cr_alignment @ r7
  28. .long init_thread_union + THREAD_START_SP @ sp
  29. /*
  30. * The following fragment of code is executed with the MMU on in MMU mode,
  31. * and uses absolute addresses; this is not position independent.
  32. *
  33. * r0 = cp#15 control register
  34. * r1 = machine ID
  35. * r2 = atags pointer
  36. * r9 = processor ID
  37. */
  38. __mmap_switched:
  39. adr r3, __switch_data + 4
  40. ldmia r3!, {r4, r5, r6, r7}
  41. cmp r4, r5 @ Copy data segment if needed
  42. 1: cmpne r5, r6
  43. ldrne fp, [r4], #4
  44. strne fp, [r5], #4
  45. bne 1b
  46. mov fp, #0 @ Clear BSS (and zero fp)
  47. 1: cmp r6, r7
  48. strcc fp, [r6],#4
  49. bcc 1b
  50. ARM( ldmia r3, {r4, r5, r6, r7, sp})
  51. THUMB( ldmia r3, {r4, r5, r6, r7} )
  52. THUMB( ldr sp, [r3, #16] )
  53. str r9, [r4] @ Save processor ID
  54. str r1, [r5] @ Save machine type
  55. str r2, [r6] @ Save atags pointer
  56. bic r4, r0, #CR_A @ Clear 'A' bit
  57. stmia r7, {r0, r4} @ Save control register values
  58. b start_kernel
  59. ENDPROC(__mmap_switched)
  60. /*
  61. * Exception handling. Something went wrong and we can't proceed. We
  62. * ought to tell the user, but since we don't have any guarantee that
  63. * we're even running on the right architecture, we do virtually nothing.
  64. *
  65. * If CONFIG_DEBUG_LL is set we try to print out something about the error
  66. * and hope for the best (useful if bootloader fails to pass a proper
  67. * machine ID for example).
  68. */
  69. __error_p:
  70. #ifdef CONFIG_DEBUG_LL
  71. adr r0, str_p1
  72. bl printascii
  73. mov r0, r9
  74. bl printhex8
  75. adr r0, str_p2
  76. bl printascii
  77. b __error
  78. str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
  79. str_p2: .asciz ").\n"
  80. .align
  81. #endif
  82. ENDPROC(__error_p)
  83. __error_a:
  84. #ifdef CONFIG_DEBUG_LL
  85. mov r4, r1 @ preserve machine ID
  86. adr r0, str_a1
  87. bl printascii
  88. mov r0, r4
  89. bl printhex8
  90. adr r0, str_a2
  91. bl printascii
  92. adr r3, 4f
  93. ldmia r3, {r4, r5, r6} @ get machine desc list
  94. sub r4, r3, r4 @ get offset between virt&phys
  95. add r5, r5, r4 @ convert virt addresses to
  96. add r6, r6, r4 @ physical address space
  97. 1: ldr r0, [r5, #MACHINFO_TYPE] @ get machine type
  98. bl printhex8
  99. mov r0, #'\t'
  100. bl printch
  101. ldr r0, [r5, #MACHINFO_NAME] @ get machine name
  102. add r0, r0, r4
  103. bl printascii
  104. mov r0, #'\n'
  105. bl printch
  106. add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc
  107. cmp r5, r6
  108. blo 1b
  109. adr r0, str_a3
  110. bl printascii
  111. b __error
  112. ENDPROC(__error_a)
  113. str_a1: .asciz "\nError: unrecognized/unsupported machine ID (r1 = 0x"
  114. str_a2: .asciz ").\n\nAvailable machine support:\n\nID (hex)\tNAME\n"
  115. str_a3: .asciz "\nPlease check your kernel config and/or bootloader.\n"
  116. .align
  117. #endif
  118. __error:
  119. #ifdef CONFIG_ARCH_RPC
  120. /*
  121. * Turn the screen red on a error - RiscPC only.
  122. */
  123. mov r0, #0x02000000
  124. mov r3, #0x11
  125. orr r3, r3, r3, lsl #8
  126. orr r3, r3, r3, lsl #16
  127. str r3, [r0], #4
  128. str r3, [r0], #4
  129. str r3, [r0], #4
  130. str r3, [r0], #4
  131. #endif
  132. 1: mov r0, r0
  133. b 1b
  134. ENDPROC(__error)
  135. /*
  136. * Read processor ID register (CP#15, CR0), and look up in the linker-built
  137. * supported processor list. Note that we can't use the absolute addresses
  138. * for the __proc_info lists since we aren't running with the MMU on
  139. * (and therefore, we are not in the correct address space). We have to
  140. * calculate the offset.
  141. *
  142. * r9 = cpuid
  143. * Returns:
  144. * r3, r4, r6 corrupted
  145. * r5 = proc_info pointer in physical address space
  146. * r9 = cpuid (preserved)
  147. */
  148. __lookup_processor_type:
  149. adr r3, 3f
  150. ldmia r3, {r5 - r7}
  151. add r3, r3, #8
  152. sub r3, r3, r7 @ get offset between virt&phys
  153. add r5, r5, r3 @ convert virt addresses to
  154. add r6, r6, r3 @ physical address space
  155. 1: ldmia r5, {r3, r4} @ value, mask
  156. and r4, r4, r9 @ mask wanted bits
  157. teq r3, r4
  158. beq 2f
  159. add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
  160. cmp r5, r6
  161. blo 1b
  162. mov r5, #0 @ unknown processor
  163. 2: mov pc, lr
  164. ENDPROC(__lookup_processor_type)
  165. /*
  166. * This provides a C-API version of the above function.
  167. */
  168. ENTRY(lookup_processor_type)
  169. stmfd sp!, {r4 - r7, r9, lr}
  170. mov r9, r0
  171. bl __lookup_processor_type
  172. mov r0, r5
  173. ldmfd sp!, {r4 - r7, r9, pc}
  174. ENDPROC(lookup_processor_type)
  175. /*
  176. * Look in <asm/procinfo.h> and arch/arm/kernel/arch.[ch] for
  177. * more information about the __proc_info and __arch_info structures.
  178. */
  179. .align 2
  180. 3: .long __proc_info_begin
  181. .long __proc_info_end
  182. 4: .long .
  183. .long __arch_info_begin
  184. .long __arch_info_end
  185. /*
  186. * Lookup machine architecture in the linker-build list of architectures.
  187. * Note that we can't use the absolute addresses for the __arch_info
  188. * lists since we aren't running with the MMU on (and therefore, we are
  189. * not in the correct address space). We have to calculate the offset.
  190. *
  191. * r1 = machine architecture number
  192. * Returns:
  193. * r3, r4, r6 corrupted
  194. * r5 = mach_info pointer in physical address space
  195. */
  196. __lookup_machine_type:
  197. adr r3, 4b
  198. ldmia r3, {r4, r5, r6}
  199. sub r3, r3, r4 @ get offset between virt&phys
  200. add r5, r5, r3 @ convert virt addresses to
  201. add r6, r6, r3 @ physical address space
  202. 1: ldr r3, [r5, #MACHINFO_TYPE] @ get machine type
  203. teq r3, r1 @ matches loader number?
  204. beq 2f @ found
  205. add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc
  206. cmp r5, r6
  207. blo 1b
  208. mov r5, #0 @ unknown machine
  209. 2: mov pc, lr
  210. ENDPROC(__lookup_machine_type)
  211. /*
  212. * This provides a C-API version of the above function.
  213. */
  214. ENTRY(lookup_machine_type)
  215. stmfd sp!, {r4 - r6, lr}
  216. mov r1, r0
  217. bl __lookup_machine_type
  218. mov r0, r5
  219. ldmfd sp!, {r4 - r6, pc}
  220. ENDPROC(lookup_machine_type)
  221. /* Determine validity of the r2 atags pointer. The heuristic requires
  222. * that the pointer be aligned, in the first 16k of physical RAM and
  223. * that the ATAG_CORE marker is first and present. Future revisions
  224. * of this function may be more lenient with the physical address and
  225. * may also be able to move the ATAGS block if necessary.
  226. *
  227. * r8 = machinfo
  228. *
  229. * Returns:
  230. * r2 either valid atags pointer, or zero
  231. * r5, r6 corrupted
  232. */
  233. __vet_atags:
  234. tst r2, #0x3 @ aligned?
  235. bne 1f
  236. ldr r5, [r2, #0] @ is first tag ATAG_CORE?
  237. cmp r5, #ATAG_CORE_SIZE
  238. cmpne r5, #ATAG_CORE_SIZE_EMPTY
  239. bne 1f
  240. ldr r5, [r2, #4]
  241. ldr r6, =ATAG_CORE
  242. cmp r5, r6
  243. bne 1f
  244. mov pc, lr @ atag pointer is ok
  245. 1: mov r2, #0
  246. mov pc, lr
  247. ENDPROC(__vet_atags)