head.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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/page.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. /* For XIP, kernel_sec_start/kernel_sec_end are currently in RO memory */
  233. #ifndef CONFIG_XIP_KERNEL
  234. adr_l r5, kernel_sec_start @ _pa(kernel_sec_start)
  235. #if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
  236. str r8, [r5, #4] @ Save physical start of kernel (BE)
  237. #else
  238. str r8, [r5] @ Save physical start of kernel (LE)
  239. #endif
  240. #endif
  241. orr r3, r8, r7 @ Add the MMU flags
  242. add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_ORDER)
  243. 1: str r3, [r0], #1 << PMD_ENTRY_ORDER
  244. add r3, r3, #1 << SECTION_SHIFT
  245. cmp r0, r6
  246. bls 1b
  247. #ifndef CONFIG_XIP_KERNEL
  248. eor r3, r3, r7 @ Remove the MMU flags
  249. adr_l r5, kernel_sec_end @ _pa(kernel_sec_end)
  250. #if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
  251. str r3, [r5, #4] @ Save physical end of kernel (BE)
  252. #else
  253. str r3, [r5] @ Save physical end of kernel (LE)
  254. #endif
  255. #else
  256. /*
  257. * Map the kernel image separately as it is not located in RAM.
  258. */
  259. #define XIP_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
  260. mov r3, pc
  261. mov r3, r3, lsr #SECTION_SHIFT
  262. orr r3, r7, r3, lsl #SECTION_SHIFT
  263. add r0, r4, #(XIP_START & 0xff000000) >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  264. str r3, [r0, #((XIP_START & 0x00f00000) >> SECTION_SHIFT) << PMD_ENTRY_ORDER]!
  265. ldr r6, =(_edata_loc - 1)
  266. add r0, r0, #1 << PMD_ENTRY_ORDER
  267. add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_ORDER)
  268. 1: cmp r0, r6
  269. add r3, r3, #1 << SECTION_SHIFT
  270. strls r3, [r0], #1 << PMD_ENTRY_ORDER
  271. bls 1b
  272. #endif
  273. /*
  274. * Then map boot params address in r2 if specified.
  275. * We map 2 sections in case the ATAGs/DTB crosses a section boundary.
  276. */
  277. mov r0, r2, lsr #SECTION_SHIFT
  278. cmp r2, #0
  279. ldrne r3, =FDT_FIXED_BASE >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  280. addne r3, r3, r4
  281. orrne r6, r7, r0, lsl #SECTION_SHIFT
  282. strne r6, [r3], #1 << PMD_ENTRY_ORDER
  283. addne r6, r6, #1 << SECTION_SHIFT
  284. strne r6, [r3]
  285. #if defined(CONFIG_ARM_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
  286. sub r4, r4, #4 @ Fixup page table pointer
  287. @ for 64-bit descriptors
  288. #endif
  289. #ifdef CONFIG_DEBUG_LL
  290. #if !defined(CONFIG_DEBUG_ICEDCC) && !defined(CONFIG_DEBUG_SEMIHOSTING)
  291. /*
  292. * Map in IO space for serial debugging.
  293. * This allows debug messages to be output
  294. * via a serial console before paging_init.
  295. */
  296. addruart r7, r3, r0
  297. mov r3, r3, lsr #SECTION_SHIFT
  298. mov r3, r3, lsl #PMD_ENTRY_ORDER
  299. add r0, r4, r3
  300. mov r3, r7, lsr #SECTION_SHIFT
  301. ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
  302. orr r3, r7, r3, lsl #SECTION_SHIFT
  303. #ifdef CONFIG_ARM_LPAE
  304. mov r7, #1 << (54 - 32) @ XN
  305. #ifdef CONFIG_CPU_ENDIAN_BE8
  306. str r7, [r0], #4
  307. str r3, [r0], #4
  308. #else
  309. str r3, [r0], #4
  310. str r7, [r0], #4
  311. #endif
  312. #else
  313. orr r3, r3, #PMD_SECT_XN
  314. str r3, [r0], #4
  315. #endif
  316. #else /* CONFIG_DEBUG_ICEDCC || CONFIG_DEBUG_SEMIHOSTING */
  317. /* we don't need any serial debugging mappings */
  318. ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
  319. #endif
  320. #if defined(CONFIG_ARCH_NETWINDER)
  321. /*
  322. * If we're using the NetWinder or CATS, we also need to map
  323. * in the 16550-type serial port for the debug messages
  324. */
  325. add r0, r4, #0xff000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  326. orr r3, r7, #0x7c000000
  327. str r3, [r0]
  328. #endif
  329. #ifdef CONFIG_ARCH_RPC
  330. /*
  331. * Map in screen at 0x02000000 & SCREEN2_BASE
  332. * Similar reasons here - for debug. This is
  333. * only for Acorn RiscPC architectures.
  334. */
  335. add r0, r4, #0x02000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  336. orr r3, r7, #0x02000000
  337. str r3, [r0]
  338. add r0, r4, #0xd8000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
  339. str r3, [r0]
  340. #endif
  341. #endif
  342. #ifdef CONFIG_ARM_LPAE
  343. sub r4, r4, #0x1000 @ point to the PGD table
  344. #endif
  345. ret lr
  346. ENDPROC(__create_page_tables)
  347. .ltorg
  348. #if defined(CONFIG_SMP)
  349. .text
  350. .arm
  351. ENTRY(secondary_startup_arm)
  352. THUMB( badr r9, 1f ) @ Kernel is entered in ARM.
  353. THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
  354. THUMB( .thumb ) @ switch to Thumb now.
  355. THUMB(1: )
  356. ENTRY(secondary_startup)
  357. /*
  358. * Common entry point for secondary CPUs.
  359. *
  360. * Ensure that we're in SVC mode, and IRQs are disabled. Lookup
  361. * the processor type - there is no need to check the machine type
  362. * as it has already been validated by the primary processor.
  363. */
  364. ARM_BE8(setend be) @ ensure we are in BE8 mode
  365. #ifdef CONFIG_ARM_VIRT_EXT
  366. bl __hyp_stub_install_secondary
  367. #endif
  368. safe_svcmode_maskall r9
  369. mrc p15, 0, r9, c0, c0 @ get processor id
  370. bl __lookup_processor_type
  371. movs r10, r5 @ invalid processor?
  372. moveq r0, #'p' @ yes, error 'p'
  373. THUMB( it eq ) @ force fixup-able long branch encoding
  374. beq __error_p
  375. /*
  376. * Use the page tables supplied from __cpu_up.
  377. */
  378. #ifdef CONFIG_XIP_KERNEL
  379. ldr r3, =(secondary_data + PLAT_PHYS_OFFSET - PAGE_OFFSET)
  380. #else
  381. adr_l r3, secondary_data
  382. #endif
  383. mov_l r12, __secondary_switched
  384. ldrd r4, r5, [r3, #0] @ get secondary_data.pgdir
  385. ARM_BE8(eor r4, r4, r5) @ Swap r5 and r4 in BE:
  386. ARM_BE8(eor r5, r4, r5) @ it can be done in 3 steps
  387. ARM_BE8(eor r4, r4, r5) @ without using a temp reg.
  388. ldr r8, [r3, #8] @ get secondary_data.swapper_pg_dir
  389. badr lr, __enable_mmu @ return address
  390. mov r13, r12 @ __secondary_switched address
  391. ldr r12, [r10, #PROCINFO_INITFUNC]
  392. add r12, r12, r10 @ initialise processor
  393. @ (return control reg)
  394. ret r12
  395. ENDPROC(secondary_startup)
  396. ENDPROC(secondary_startup_arm)
  397. ENTRY(__secondary_switched)
  398. #if defined(CONFIG_VMAP_STACK) && !defined(CONFIG_ARM_LPAE)
  399. @ Before using the vmap'ed stack, we have to switch to swapper_pg_dir
  400. @ as the ID map does not cover the vmalloc region.
  401. mrc p15, 0, ip, c2, c0, 1 @ read TTBR1
  402. mcr p15, 0, ip, c2, c0, 0 @ set TTBR0
  403. instr_sync
  404. #endif
  405. adr_l r7, secondary_data + 12 @ get secondary_data.stack
  406. ldr sp, [r7]
  407. ldr r0, [r7, #4] @ get secondary_data.task
  408. mov fp, #0
  409. b secondary_start_kernel
  410. ENDPROC(__secondary_switched)
  411. #endif /* defined(CONFIG_SMP) */
  412. /*
  413. * Setup common bits before finally enabling the MMU. Essentially
  414. * this is just loading the page table pointer and domain access
  415. * registers. All these registers need to be preserved by the
  416. * processor setup function (or set in the case of r0)
  417. *
  418. * r0 = cp#15 control register
  419. * r1 = machine ID
  420. * r2 = atags or dtb pointer
  421. * r4 = TTBR pointer (low word)
  422. * r5 = TTBR pointer (high word if LPAE)
  423. * r9 = processor ID
  424. * r13 = *virtual* address to jump to upon completion
  425. */
  426. __enable_mmu:
  427. #if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6
  428. orr r0, r0, #CR_A
  429. #else
  430. bic r0, r0, #CR_A
  431. #endif
  432. #ifdef CONFIG_CPU_DCACHE_DISABLE
  433. bic r0, r0, #CR_C
  434. #endif
  435. #ifdef CONFIG_CPU_BPREDICT_DISABLE
  436. bic r0, r0, #CR_Z
  437. #endif
  438. #ifdef CONFIG_CPU_ICACHE_DISABLE
  439. bic r0, r0, #CR_I
  440. #endif
  441. #ifdef CONFIG_ARM_LPAE
  442. mcrr p15, 0, r4, r5, c2 @ load TTBR0
  443. #else
  444. mov r5, #DACR_INIT
  445. mcr p15, 0, r5, c3, c0, 0 @ load domain access register
  446. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  447. #endif
  448. b __turn_mmu_on
  449. ENDPROC(__enable_mmu)
  450. /*
  451. * Enable the MMU. This completely changes the structure of the visible
  452. * memory space. You will not be able to trace execution through this.
  453. * If you have an enquiry about this, *please* check the linux-arm-kernel
  454. * mailing list archives BEFORE sending another post to the list.
  455. *
  456. * r0 = cp#15 control register
  457. * r1 = machine ID
  458. * r2 = atags or dtb pointer
  459. * r9 = processor ID
  460. * r13 = *virtual* address to jump to upon completion
  461. *
  462. * other registers depend on the function called upon completion
  463. */
  464. .align 5
  465. .pushsection .idmap.text, "ax"
  466. ENTRY(__turn_mmu_on)
  467. mov r0, r0
  468. instr_sync
  469. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  470. mrc p15, 0, r3, c0, c0, 0 @ read id reg
  471. instr_sync
  472. mov r3, r3
  473. mov r3, r13
  474. ret r3
  475. __turn_mmu_on_end:
  476. ENDPROC(__turn_mmu_on)
  477. .popsection
  478. #ifdef CONFIG_SMP_ON_UP
  479. __HEAD
  480. __fixup_smp:
  481. and r3, r9, #0x000f0000 @ architecture version
  482. teq r3, #0x000f0000 @ CPU ID supported?
  483. bne __fixup_smp_on_up @ no, assume UP
  484. bic r3, r9, #0x00ff0000
  485. bic r3, r3, #0x0000000f @ mask 0xff00fff0
  486. mov r4, #0x41000000
  487. orr r4, r4, #0x0000b000
  488. orr r4, r4, #0x00000020 @ val 0x4100b020
  489. teq r3, r4 @ ARM 11MPCore?
  490. reteq lr @ yes, assume SMP
  491. mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
  492. and r0, r0, #0xc0000000 @ multiprocessing extensions and
  493. teq r0, #0x80000000 @ not part of a uniprocessor system?
  494. bne __fixup_smp_on_up @ no, assume UP
  495. @ Core indicates it is SMP. Check for Aegis SOC where a single
  496. @ Cortex-A9 CPU is present but SMP operations fault.
  497. mov r4, #0x41000000
  498. orr r4, r4, #0x0000c000
  499. orr r4, r4, #0x00000090
  500. teq r3, r4 @ Check for ARM Cortex-A9
  501. retne lr @ Not ARM Cortex-A9,
  502. @ If a future SoC *does* use 0x0 as the PERIPH_BASE, then the
  503. @ below address check will need to be #ifdef'd or equivalent
  504. @ for the Aegis platform.
  505. mrc p15, 4, r0, c15, c0 @ get SCU base address
  506. teq r0, #0x0 @ '0' on actual UP A9 hardware
  507. beq __fixup_smp_on_up @ So its an A9 UP
  508. ldr r0, [r0, #4] @ read SCU Config
  509. ARM_BE8(rev r0, r0) @ byteswap if big endian
  510. and r0, r0, #0x3 @ number of CPUs
  511. teq r0, #0x0 @ is 1?
  512. retne lr
  513. __fixup_smp_on_up:
  514. adr_l r4, __smpalt_begin
  515. adr_l r5, __smpalt_end
  516. b __do_fixup_smp_on_up
  517. ENDPROC(__fixup_smp)
  518. .pushsection .data
  519. .align 2
  520. .globl smp_on_up
  521. smp_on_up:
  522. ALT_SMP(.long 1)
  523. ALT_UP(.long 0)
  524. .popsection
  525. #endif
  526. .text
  527. __do_fixup_smp_on_up:
  528. cmp r4, r5
  529. reths lr
  530. ldmia r4, {r0, r6}
  531. ARM( str r6, [r0, r4] )
  532. THUMB( add r0, r0, r4 )
  533. add r4, r4, #8
  534. #ifdef __ARMEB__
  535. THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian.
  536. #endif
  537. THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords
  538. THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r0.
  539. THUMB( strh r6, [r0] )
  540. b __do_fixup_smp_on_up
  541. ENDPROC(__do_fixup_smp_on_up)
  542. ENTRY(fixup_smp)
  543. stmfd sp!, {r4 - r6, lr}
  544. mov r4, r0
  545. add r5, r0, r1
  546. bl __do_fixup_smp_on_up
  547. ldmfd sp!, {r4 - r6, pc}
  548. ENDPROC(fixup_smp)
  549. #include "head-common.S"