head-common.S 6.4 KB

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