head-common.S 7.1 KB

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