head.S 19 KB

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