head.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/kernel/head.S
  4. *
  5. * Copyright (C) 1994-2002 Russell King
  6. * Copyright (c) 2003 ARM Limited
  7. * All Rights Reserved
  8. *
  9. * Kernel startup code for all 32-bit CPUs
  10. */
  11. #include <linux/linkage.h>
  12. #include <linux/init.h>
  13. #include <linux/pgtable.h>
  14. #include <asm/assembler.h>
  15. #include <asm/cp15.h>
  16. #include <asm/domain.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/asm-offsets.h>
  19. #include <asm/memory.h>
  20. #include <asm/thread_info.h>
  21. #if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_SEMIHOSTING)
  22. #include CONFIG_DEBUG_LL_INCLUDE
  23. #endif
  24. /*
  25. * swapper_pg_dir is the virtual address of the initial page table.
  26. * We place the page tables 16K below KERNEL_RAM_VADDR. Therefore, we must
  27. * make sure that KERNEL_RAM_VADDR is correctly set. Currently, we expect
  28. * the least significant 16 bits to be 0x8000, but we could probably
  29. * relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000.
  30. */
  31. #define KERNEL_RAM_VADDR (KERNEL_OFFSET + TEXT_OFFSET)
  32. #if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
  33. #error KERNEL_RAM_VADDR must start at 0xXXXX8000
  34. #endif
  35. #ifdef CONFIG_ARM_LPAE
  36. /* LPAE requires an additional page for the PGD */
  37. #define PG_DIR_SIZE 0x5000
  38. #define PMD_ENTRY_ORDER 3 /* PMD entry size is 2^PMD_ENTRY_ORDER */
  39. #else
  40. #define PG_DIR_SIZE 0x4000
  41. #define PMD_ENTRY_ORDER 2
  42. #endif
  43. .globl swapper_pg_dir
  44. .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
  45. /*
  46. * This needs to be assigned at runtime when the linker symbols are
  47. * resolved. These are unsigned 64bit really, but in this assembly code
  48. * We store them as 32bit.
  49. */
  50. .pushsection .data
  51. .align 2
  52. .globl kernel_sec_start
  53. .globl kernel_sec_end
  54. kernel_sec_start:
  55. .long 0
  56. .long 0
  57. kernel_sec_end:
  58. .long 0
  59. .long 0
  60. .popsection
  61. .macro pgtbl, rd, phys
  62. add \rd, \phys, #TEXT_OFFSET
  63. sub \rd, \rd, #PG_DIR_SIZE
  64. .endm
  65. /*
  66. * Kernel startup entry point.
  67. * ---------------------------
  68. *
  69. * This is normally called from the decompressor code. The requirements
  70. * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
  71. * r1 = machine nr, r2 = atags or dtb pointer.
  72. *
  73. * This code is mostly position independent, so if you link the kernel at
  74. * 0xc0008000, you call this at __pa(0xc0008000).
  75. *
  76. * See linux/arch/arm/tools/mach-types for the complete list of machine
  77. * numbers for r1.
  78. *
  79. * We're trying to keep crap to a minimum; DO NOT add any machine specific
  80. * crap here - that's what the boot loader (or in extreme, well justified
  81. * circumstances, zImage) is for.
  82. */
  83. .arm
  84. __HEAD
  85. ENTRY(stext)
  86. ARM_BE8(setend be ) @ ensure we are in BE8 mode
  87. THUMB( badr r9, 1f ) @ Kernel is always entered in ARM.
  88. THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
  89. THUMB( .thumb ) @ switch to Thumb now.
  90. THUMB(1: )
  91. #ifdef CONFIG_ARM_VIRT_EXT
  92. bl __hyp_stub_install
  93. #endif
  94. @ ensure svc mode and all interrupts masked
  95. safe_svcmode_maskall r9
  96. mrc p15, 0, r9, c0, c0 @ get processor id
  97. bl __lookup_processor_type @ r5=procinfo r9=cpuid
  98. movs r10, r5 @ invalid processor (r5=0)?
  99. THUMB( it eq ) @ force fixup-able long branch encoding
  100. beq __error_p @ yes, error 'p'
  101. #ifdef CONFIG_ARM_LPAE
  102. mrc p15, 0, r3, c0, c1, 4 @ read ID_MMFR0
  103. and r3, r3, #0xf @ extract VMSA support
  104. cmp r3, #5 @ long-descriptor translation table format?
  105. THUMB( it lo ) @ force fixup-able long branch encoding
  106. blo __error_lpae @ only classic page table format
  107. #endif
  108. #ifndef CONFIG_XIP_KERNEL
  109. adr_l r8, _text @ __pa(_text)
  110. sub r8, r8, #TEXT_OFFSET @ PHYS_OFFSET
  111. #else
  112. ldr r8, =PLAT_PHYS_OFFSET @ always constant in this case
  113. #endif
  114. /*
  115. * r1 = machine no, r2 = atags or dtb,
  116. * r8 = phys_offset, r9 = cpuid, r10 = procinfo
  117. */
  118. bl __vet_atags
  119. #ifdef CONFIG_SMP_ON_UP
  120. bl __fixup_smp
  121. #endif
  122. #ifdef CONFIG_ARM_PATCH_PHYS_VIRT
  123. bl __fixup_pv_table
  124. #endif
  125. bl __create_page_tables
  126. /*
  127. * The following calls CPU specific code in a position independent
  128. * manner. See arch/arm/mm/proc-*.S for details. r10 = base of
  129. * xxx_proc_info structure selected by __lookup_processor_type
  130. * above.
  131. *
  132. * The processor init function will be called with:
  133. * r1 - machine type
  134. * r2 - boot data (atags/dt) pointer
  135. * r4 - translation table base (low word)
  136. * r5 - translation table base (high word, if LPAE)
  137. * r8 - translation table base 1 (pfn if LPAE)
  138. * r9 - cpuid
  139. * r13 - virtual address for __enable_mmu -> __turn_mmu_on
  140. *
  141. * On return, the CPU will be ready for the MMU to be turned on,
  142. * r0 will hold the CPU control register value, r1, r2, r4, and
  143. * r9 will be preserved. r5 will also be preserved if LPAE.
  144. */
  145. ldr r13, =__mmap_switched @ address to jump to after
  146. @ mmu has been enabled
  147. badr lr, 1f @ return (PIC) address
  148. #ifdef CONFIG_ARM_LPAE
  149. mov r5, #0 @ high TTBR0
  150. mov r8, r4, lsr #12 @ TTBR1 is swapper_pg_dir pfn
  151. #else
  152. mov r8, r4 @ set TTBR1 to swapper_pg_dir
  153. #endif
  154. ldr r12, [r10, #PROCINFO_INITFUNC]
  155. add r12, r12, r10
  156. ret r12
  157. 1: b __enable_mmu
  158. ENDPROC(stext)
  159. .ltorg
  160. /*
  161. * Setup the initial page tables. We only setup the barest
  162. * amount which are required to get the kernel running, which
  163. * generally means mapping in the kernel code.
  164. *
  165. * r8 = phys_offset, r9 = cpuid, r10 = procinfo
  166. *
  167. * Returns:
  168. * r0, r3, r5-r7 corrupted
  169. * r4 = physical page table address
  170. */
  171. __create_page_tables:
  172. pgtbl r4, r8 @ page table address
  173. /*
  174. * Clear the swapper page table
  175. */
  176. mov r0, r4
  177. mov r3, #0
  178. add r6, r0, #PG_DIR_SIZE
  179. 1: str r3, [r0], #4
  180. str r3, [r0], #4
  181. str r3, [r0], #4
  182. str r3, [r0], #4
  183. teq r0, r6
  184. bne 1b
  185. #ifdef CONFIG_ARM_LPAE
  186. /*
  187. * Build the PGD table (first level) to point to the PMD table. A PGD
  188. * entry is 64-bit wide.
  189. */
  190. mov r0, r4
  191. add r3, r4, #0x1000 @ first PMD table address
  192. orr r3, r3, #3 @ PGD block type
  193. mov r6, #4 @ PTRS_PER_PGD
  194. mov r7, #1 << (55 - 32) @ L_PGD_SWAPPER
  195. 1:
  196. #ifdef CONFIG_CPU_ENDIAN_BE8
  197. str r7, [r0], #4 @ set top PGD entry bits
  198. str r3, [r0], #4 @ set bottom PGD entry bits
  199. #else
  200. str r3, [r0], #4 @ set bottom PGD entry bits
  201. str r7, [r0], #4 @ set top PGD entry bits
  202. #endif
  203. add r3, r3, #0x1000 @ next PMD table
  204. subs r6, r6, #1
  205. bne 1b
  206. add r4, r4, #0x1000 @ point to the PMD tables
  207. #ifdef CONFIG_CPU_ENDIAN_BE8
  208. add r4, r4, #4 @ we only write the bottom word
  209. #endif
  210. #endif
  211. ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
  212. /*
  213. * Create identity mapping to cater for __enable_mmu.
  214. * This identity mapping will be removed by paging_init().
  215. */
  216. adr_l r5, __turn_mmu_on @ _pa(__turn_mmu_on)
  217. adr_l r6, __turn_mmu_on_end @ _pa(__turn_mmu_on_end)
  218. mov r5, r5, lsr #SECTION_SHIFT
  219. mov r6, r6, lsr #SECTION_SHIFT
  220. 1: orr r3, r7, r5, lsl #SECTION_SHIFT @ flags + kernel base
  221. str r3, [r4, r5, lsl #PMD_ENTRY_ORDER] @ identity mapping
  222. cmp r5, r6
  223. addlo r5, r5, #1 @ next section
  224. blo 1b
  225. /*
  226. * The main matter: map in the kernel using section mappings, and
  227. * set two variables to indicate the physical start and end of the
  228. * kernel.
  229. */
  230. add r0, r4, #KERNEL_OFFSET >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  231. ldr r6, =(_end - 1)
  232. adr_l r5, kernel_sec_start @ _pa(kernel_sec_start)
  233. #if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
  234. str r8, [r5, #4] @ Save physical start of kernel (BE)
  235. #else
  236. str r8, [r5] @ Save physical start of kernel (LE)
  237. #endif
  238. orr r3, r8, r7 @ Add the MMU flags
  239. add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_ORDER)
  240. 1: str r3, [r0], #1 << PMD_ENTRY_ORDER
  241. add r3, r3, #1 << SECTION_SHIFT
  242. cmp r0, r6
  243. bls 1b
  244. eor r3, r3, r7 @ Remove the MMU flags
  245. adr_l r5, kernel_sec_end @ _pa(kernel_sec_end)
  246. #if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
  247. str r3, [r5, #4] @ Save physical end of kernel (BE)
  248. #else
  249. str r3, [r5] @ Save physical end of kernel (LE)
  250. #endif
  251. #ifdef CONFIG_XIP_KERNEL
  252. /*
  253. * Map the kernel image separately as it is not located in RAM.
  254. */
  255. #define XIP_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
  256. mov r3, pc
  257. mov r3, r3, lsr #SECTION_SHIFT
  258. orr r3, r7, r3, lsl #SECTION_SHIFT
  259. add r0, r4, #(XIP_START & 0xff000000) >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  260. str r3, [r0, #((XIP_START & 0x00f00000) >> SECTION_SHIFT) << PMD_ENTRY_ORDER]!
  261. ldr r6, =(_edata_loc - 1)
  262. add r0, r0, #1 << PMD_ENTRY_ORDER
  263. add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_ORDER)
  264. 1: cmp r0, r6
  265. add r3, r3, #1 << SECTION_SHIFT
  266. strls r3, [r0], #1 << PMD_ENTRY_ORDER
  267. bls 1b
  268. #endif
  269. /*
  270. * Then map boot params address in r2 if specified.
  271. * We map 2 sections in case the ATAGs/DTB crosses a section boundary.
  272. */
  273. mov r0, r2, lsr #SECTION_SHIFT
  274. cmp r2, #0
  275. ldrne r3, =FDT_FIXED_BASE >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  276. addne r3, r3, r4
  277. orrne r6, r7, r0, lsl #SECTION_SHIFT
  278. strne r6, [r3], #1 << PMD_ENTRY_ORDER
  279. addne r6, r6, #1 << SECTION_SHIFT
  280. strne r6, [r3]
  281. #if defined(CONFIG_ARM_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
  282. sub r4, r4, #4 @ Fixup page table pointer
  283. @ for 64-bit descriptors
  284. #endif
  285. #ifdef CONFIG_DEBUG_LL
  286. #if !defined(CONFIG_DEBUG_ICEDCC) && !defined(CONFIG_DEBUG_SEMIHOSTING)
  287. /*
  288. * Map in IO space for serial debugging.
  289. * This allows debug messages to be output
  290. * via a serial console before paging_init.
  291. */
  292. addruart r7, r3, r0
  293. mov r3, r3, lsr #SECTION_SHIFT
  294. mov r3, r3, lsl #PMD_ENTRY_ORDER
  295. add r0, r4, r3
  296. mov r3, r7, lsr #SECTION_SHIFT
  297. ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
  298. orr r3, r7, r3, lsl #SECTION_SHIFT
  299. #ifdef CONFIG_ARM_LPAE
  300. mov r7, #1 << (54 - 32) @ XN
  301. #ifdef CONFIG_CPU_ENDIAN_BE8
  302. str r7, [r0], #4
  303. str r3, [r0], #4
  304. #else
  305. str r3, [r0], #4
  306. str r7, [r0], #4
  307. #endif
  308. #else
  309. orr r3, r3, #PMD_SECT_XN
  310. str r3, [r0], #4
  311. #endif
  312. #else /* CONFIG_DEBUG_ICEDCC || CONFIG_DEBUG_SEMIHOSTING */
  313. /* we don't need any serial debugging mappings */
  314. ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
  315. #endif
  316. #if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS)
  317. /*
  318. * If we're using the NetWinder or CATS, we also need to map
  319. * in the 16550-type serial port for the debug messages
  320. */
  321. add r0, r4, #0xff000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  322. orr r3, r7, #0x7c000000
  323. str r3, [r0]
  324. #endif
  325. #ifdef CONFIG_ARCH_RPC
  326. /*
  327. * Map in screen at 0x02000000 & SCREEN2_BASE
  328. * Similar reasons here - for debug. This is
  329. * only for Acorn RiscPC architectures.
  330. */
  331. add r0, r4, #0x02000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  332. orr r3, r7, #0x02000000
  333. str r3, [r0]
  334. add r0, r4, #0xd8000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  335. str r3, [r0]
  336. #endif
  337. #endif
  338. #ifdef CONFIG_ARM_LPAE
  339. sub r4, r4, #0x1000 @ point to the PGD table
  340. #endif
  341. ret lr
  342. ENDPROC(__create_page_tables)
  343. .ltorg
  344. #if defined(CONFIG_SMP)
  345. .text
  346. .arm
  347. ENTRY(secondary_startup_arm)
  348. THUMB( badr r9, 1f ) @ Kernel is entered in ARM.
  349. THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
  350. THUMB( .thumb ) @ switch to Thumb now.
  351. THUMB(1: )
  352. ENTRY(secondary_startup)
  353. /*
  354. * Common entry point for secondary CPUs.
  355. *
  356. * Ensure that we're in SVC mode, and IRQs are disabled. Lookup
  357. * the processor type - there is no need to check the machine type
  358. * as it has already been validated by the primary processor.
  359. */
  360. ARM_BE8(setend be) @ ensure we are in BE8 mode
  361. #ifdef CONFIG_ARM_VIRT_EXT
  362. bl __hyp_stub_install_secondary
  363. #endif
  364. safe_svcmode_maskall r9
  365. mrc p15, 0, r9, c0, c0 @ get processor id
  366. bl __lookup_processor_type
  367. movs r10, r5 @ invalid processor?
  368. moveq r0, #'p' @ yes, error 'p'
  369. THUMB( it eq ) @ force fixup-able long branch encoding
  370. beq __error_p
  371. /*
  372. * Use the page tables supplied from __cpu_up.
  373. */
  374. adr_l r3, secondary_data
  375. mov_l r12, __secondary_switched
  376. ldrd r4, r5, [r3, #0] @ get secondary_data.pgdir
  377. ARM_BE8(eor r4, r4, r5) @ Swap r5 and r4 in BE:
  378. ARM_BE8(eor r5, r4, r5) @ it can be done in 3 steps
  379. ARM_BE8(eor r4, r4, r5) @ without using a temp reg.
  380. ldr r8, [r3, #8] @ get secondary_data.swapper_pg_dir
  381. badr lr, __enable_mmu @ return address
  382. mov r13, r12 @ __secondary_switched address
  383. ldr r12, [r10, #PROCINFO_INITFUNC]
  384. add r12, r12, r10 @ initialise processor
  385. @ (return control reg)
  386. ret r12
  387. ENDPROC(secondary_startup)
  388. ENDPROC(secondary_startup_arm)
  389. ENTRY(__secondary_switched)
  390. #if defined(CONFIG_VMAP_STACK) && !defined(CONFIG_ARM_LPAE)
  391. @ Before using the vmap'ed stack, we have to switch to swapper_pg_dir
  392. @ as the ID map does not cover the vmalloc region.
  393. mrc p15, 0, ip, c2, c0, 1 @ read TTBR1
  394. mcr p15, 0, ip, c2, c0, 0 @ set TTBR0
  395. instr_sync
  396. #endif
  397. adr_l r7, secondary_data + 12 @ get secondary_data.stack
  398. ldr sp, [r7]
  399. ldr r0, [r7, #4] @ get secondary_data.task
  400. mov fp, #0
  401. b secondary_start_kernel
  402. ENDPROC(__secondary_switched)
  403. #endif /* defined(CONFIG_SMP) */
  404. /*
  405. * Setup common bits before finally enabling the MMU. Essentially
  406. * this is just loading the page table pointer and domain access
  407. * registers. All these registers need to be preserved by the
  408. * processor setup function (or set in the case of r0)
  409. *
  410. * r0 = cp#15 control register
  411. * r1 = machine ID
  412. * r2 = atags or dtb pointer
  413. * r4 = TTBR pointer (low word)
  414. * r5 = TTBR pointer (high word if LPAE)
  415. * r9 = processor ID
  416. * r13 = *virtual* address to jump to upon completion
  417. */
  418. __enable_mmu:
  419. #if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6
  420. orr r0, r0, #CR_A
  421. #else
  422. bic r0, r0, #CR_A
  423. #endif
  424. #ifdef CONFIG_CPU_DCACHE_DISABLE
  425. bic r0, r0, #CR_C
  426. #endif
  427. #ifdef CONFIG_CPU_BPREDICT_DISABLE
  428. bic r0, r0, #CR_Z
  429. #endif
  430. #ifdef CONFIG_CPU_ICACHE_DISABLE
  431. bic r0, r0, #CR_I
  432. #endif
  433. #ifdef CONFIG_ARM_LPAE
  434. mcrr p15, 0, r4, r5, c2 @ load TTBR0
  435. #else
  436. mov r5, #DACR_INIT
  437. mcr p15, 0, r5, c3, c0, 0 @ load domain access register
  438. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  439. #endif
  440. b __turn_mmu_on
  441. ENDPROC(__enable_mmu)
  442. /*
  443. * Enable the MMU. This completely changes the structure of the visible
  444. * memory space. You will not be able to trace execution through this.
  445. * If you have an enquiry about this, *please* check the linux-arm-kernel
  446. * mailing list archives BEFORE sending another post to the list.
  447. *
  448. * r0 = cp#15 control register
  449. * r1 = machine ID
  450. * r2 = atags or dtb pointer
  451. * r9 = processor ID
  452. * r13 = *virtual* address to jump to upon completion
  453. *
  454. * other registers depend on the function called upon completion
  455. */
  456. .align 5
  457. .pushsection .idmap.text, "ax"
  458. ENTRY(__turn_mmu_on)
  459. mov r0, r0
  460. instr_sync
  461. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  462. mrc p15, 0, r3, c0, c0, 0 @ read id reg
  463. instr_sync
  464. mov r3, r3
  465. mov r3, r13
  466. ret r3
  467. __turn_mmu_on_end:
  468. ENDPROC(__turn_mmu_on)
  469. .popsection
  470. #ifdef CONFIG_SMP_ON_UP
  471. __HEAD
  472. __fixup_smp:
  473. and r3, r9, #0x000f0000 @ architecture version
  474. teq r3, #0x000f0000 @ CPU ID supported?
  475. bne __fixup_smp_on_up @ no, assume UP
  476. bic r3, r9, #0x00ff0000
  477. bic r3, r3, #0x0000000f @ mask 0xff00fff0
  478. mov r4, #0x41000000
  479. orr r4, r4, #0x0000b000
  480. orr r4, r4, #0x00000020 @ val 0x4100b020
  481. teq r3, r4 @ ARM 11MPCore?
  482. reteq lr @ yes, assume SMP
  483. mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
  484. and r0, r0, #0xc0000000 @ multiprocessing extensions and
  485. teq r0, #0x80000000 @ not part of a uniprocessor system?
  486. bne __fixup_smp_on_up @ no, assume UP
  487. @ Core indicates it is SMP. Check for Aegis SOC where a single
  488. @ Cortex-A9 CPU is present but SMP operations fault.
  489. mov r4, #0x41000000
  490. orr r4, r4, #0x0000c000
  491. orr r4, r4, #0x00000090
  492. teq r3, r4 @ Check for ARM Cortex-A9
  493. retne lr @ Not ARM Cortex-A9,
  494. @ If a future SoC *does* use 0x0 as the PERIPH_BASE, then the
  495. @ below address check will need to be #ifdef'd or equivalent
  496. @ for the Aegis platform.
  497. mrc p15, 4, r0, c15, c0 @ get SCU base address
  498. teq r0, #0x0 @ '0' on actual UP A9 hardware
  499. beq __fixup_smp_on_up @ So its an A9 UP
  500. ldr r0, [r0, #4] @ read SCU Config
  501. ARM_BE8(rev r0, r0) @ byteswap if big endian
  502. and r0, r0, #0x3 @ number of CPUs
  503. teq r0, #0x0 @ is 1?
  504. retne lr
  505. __fixup_smp_on_up:
  506. adr_l r4, __smpalt_begin
  507. adr_l r5, __smpalt_end
  508. b __do_fixup_smp_on_up
  509. ENDPROC(__fixup_smp)
  510. .pushsection .data
  511. .align 2
  512. .globl smp_on_up
  513. smp_on_up:
  514. ALT_SMP(.long 1)
  515. ALT_UP(.long 0)
  516. .popsection
  517. #endif
  518. .text
  519. __do_fixup_smp_on_up:
  520. cmp r4, r5
  521. reths lr
  522. ldmia r4, {r0, r6}
  523. ARM( str r6, [r0, r4] )
  524. THUMB( add r0, r0, r4 )
  525. add r4, r4, #8
  526. #ifdef __ARMEB__
  527. THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian.
  528. #endif
  529. THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords
  530. THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r0.
  531. THUMB( strh r6, [r0] )
  532. b __do_fixup_smp_on_up
  533. ENDPROC(__do_fixup_smp_on_up)
  534. ENTRY(fixup_smp)
  535. stmfd sp!, {r4 - r6, lr}
  536. mov r4, r0
  537. add r5, r0, r1
  538. bl __do_fixup_smp_on_up
  539. ldmfd sp!, {r4 - r6, pc}
  540. ENDPROC(fixup_smp)
  541. #include "head-common.S"