head-common.S 7.1 KB

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