head-common.S 5.5 KB

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