head-common.S 6.3 KB

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