head.S 18 KB

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