head-common.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /* Determine validity of the r2 atags pointer. The heuristic requires
  27. * that the pointer be aligned, in the first 16k of physical RAM and
  28. * that the ATAG_CORE marker is first and present. Future revisions
  29. * of this function may be more lenient with the physical address and
  30. * may also be able to move the ATAGS block if necessary.
  31. *
  32. * Returns:
  33. * r2 either valid atags pointer, or zero
  34. * r5, r6 corrupted
  35. */
  36. __vet_atags:
  37. tst r2, #0x3 @ aligned?
  38. bne 1f
  39. ldr r5, [r2, #0] @ is first tag ATAG_CORE?
  40. cmp r5, #ATAG_CORE_SIZE
  41. cmpne r5, #ATAG_CORE_SIZE_EMPTY
  42. bne 1f
  43. ldr r5, [r2, #4]
  44. ldr r6, =ATAG_CORE
  45. cmp r5, r6
  46. bne 1f
  47. mov pc, lr @ atag pointer is ok
  48. 1: mov r2, #0
  49. mov pc, lr
  50. ENDPROC(__vet_atags)
  51. /*
  52. * The following fragment of code is executed with the MMU on in MMU mode,
  53. * and uses absolute addresses; this is not position independent.
  54. *
  55. * r0 = cp#15 control register
  56. * r1 = machine ID
  57. * r2 = atags pointer
  58. * r9 = processor ID
  59. */
  60. __INIT
  61. __mmap_switched:
  62. adr r3, __mmap_switched_data
  63. ldmia r3!, {r4, r5, r6, r7}
  64. cmp r4, r5 @ Copy data segment if needed
  65. 1: cmpne r5, r6
  66. ldrne fp, [r4], #4
  67. strne fp, [r5], #4
  68. bne 1b
  69. mov fp, #0 @ Clear BSS (and zero fp)
  70. 1: cmp r6, r7
  71. strcc fp, [r6],#4
  72. bcc 1b
  73. ARM( ldmia r3, {r4, r5, r6, r7, sp})
  74. THUMB( ldmia r3, {r4, r5, r6, r7} )
  75. THUMB( ldr sp, [r3, #16] )
  76. str r9, [r4] @ Save processor ID
  77. str r1, [r5] @ Save machine type
  78. str r2, [r6] @ Save atags pointer
  79. bic r4, r0, #CR_A @ Clear 'A' bit
  80. stmia r7, {r0, r4} @ Save control register values
  81. b start_kernel
  82. ENDPROC(__mmap_switched)
  83. .align 2
  84. .type __mmap_switched_data, %object
  85. __mmap_switched_data:
  86. .long __data_loc @ r4
  87. .long _sdata @ r5
  88. .long __bss_start @ r6
  89. .long _end @ r7
  90. .long processor_id @ r4
  91. .long __machine_arch_type @ r5
  92. .long __atags_pointer @ r6
  93. .long cr_alignment @ r7
  94. .long init_thread_union + THREAD_START_SP @ sp
  95. .size __mmap_switched_data, . - __mmap_switched_data
  96. /*
  97. * This provides a C-API version of __lookup_processor_type
  98. */
  99. ENTRY(lookup_processor_type)
  100. stmfd sp!, {r4 - r6, r9, lr}
  101. mov r9, r0
  102. bl __lookup_processor_type
  103. mov r0, r5
  104. ldmfd sp!, {r4 - r6, r9, pc}
  105. ENDPROC(lookup_processor_type)
  106. /*
  107. * Read processor ID register (CP#15, CR0), and look up in the linker-built
  108. * supported processor list. Note that we can't use the absolute addresses
  109. * for the __proc_info lists since we aren't running with the MMU on
  110. * (and therefore, we are not in the correct address space). We have to
  111. * calculate the offset.
  112. *
  113. * r9 = cpuid
  114. * Returns:
  115. * r3, r4, r6 corrupted
  116. * r5 = proc_info pointer in physical address space
  117. * r9 = cpuid (preserved)
  118. */
  119. __CPUINIT
  120. __lookup_processor_type:
  121. adr r3, __lookup_processor_type_data
  122. ldmia r3, {r4 - r6}
  123. sub r3, r3, r4 @ get offset between virt&phys
  124. add r5, r5, r3 @ convert virt addresses to
  125. add r6, r6, r3 @ physical address space
  126. 1: ldmia r5, {r3, r4} @ value, mask
  127. and r4, r4, r9 @ mask wanted bits
  128. teq r3, r4
  129. beq 2f
  130. add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
  131. cmp r5, r6
  132. blo 1b
  133. mov r5, #0 @ unknown processor
  134. 2: mov pc, lr
  135. ENDPROC(__lookup_processor_type)
  136. /*
  137. * Look in <asm/procinfo.h> for information about the __proc_info structure.
  138. */
  139. .align 2
  140. .type __lookup_processor_type_data, %object
  141. __lookup_processor_type_data:
  142. .long .
  143. .long __proc_info_begin
  144. .long __proc_info_end
  145. .size __lookup_processor_type_data, . - __lookup_processor_type_data
  146. __error_p:
  147. #ifdef CONFIG_DEBUG_LL
  148. adr r0, str_p1
  149. bl printascii
  150. mov r0, r9
  151. bl printhex8
  152. adr r0, str_p2
  153. bl printascii
  154. b __error
  155. str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
  156. str_p2: .asciz ").\n"
  157. .align
  158. #endif
  159. ENDPROC(__error_p)
  160. __error:
  161. #ifdef CONFIG_ARCH_RPC
  162. /*
  163. * Turn the screen red on a error - RiscPC only.
  164. */
  165. mov r0, #0x02000000
  166. mov r3, #0x11
  167. orr r3, r3, r3, lsl #8
  168. orr r3, r3, r3, lsl #16
  169. str r3, [r0], #4
  170. str r3, [r0], #4
  171. str r3, [r0], #4
  172. str r3, [r0], #4
  173. #endif
  174. 1: mov r0, r0
  175. b 1b
  176. ENDPROC(__error)