head-common.S 6.6 KB

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