head.S 18 KB

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