head.S 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. /*
  2. * linux/arch/arm/boot/compressed/head.S
  3. *
  4. * Copyright (C) 1996-2002 Russell King
  5. * Copyright (C) 2004 Hyok S. Choi (MPU support)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/assembler.h>
  13. #include <asm/v7m.h>
  14. #include "efi-header.S"
  15. AR_CLASS( .arch armv7-a )
  16. M_CLASS( .arch armv7-m )
  17. /*
  18. * Debugging stuff
  19. *
  20. * Note that these macros must not contain any code which is not
  21. * 100% relocatable. Any attempt to do so will result in a crash.
  22. * Please select one of the following when turning on debugging.
  23. */
  24. #ifdef DEBUG
  25. #if defined(CONFIG_DEBUG_ICEDCC)
  26. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
  27. .macro loadsp, rb, tmp
  28. .endm
  29. .macro writeb, ch, rb
  30. mcr p14, 0, \ch, c0, c5, 0
  31. .endm
  32. #elif defined(CONFIG_CPU_XSCALE)
  33. .macro loadsp, rb, tmp
  34. .endm
  35. .macro writeb, ch, rb
  36. mcr p14, 0, \ch, c8, c0, 0
  37. .endm
  38. #else
  39. .macro loadsp, rb, tmp
  40. .endm
  41. .macro writeb, ch, rb
  42. mcr p14, 0, \ch, c1, c0, 0
  43. .endm
  44. #endif
  45. #else
  46. #include CONFIG_DEBUG_LL_INCLUDE
  47. .macro writeb, ch, rb
  48. senduart \ch, \rb
  49. .endm
  50. #if defined(CONFIG_ARCH_SA1100)
  51. .macro loadsp, rb, tmp
  52. mov \rb, #0x80000000 @ physical base address
  53. #ifdef CONFIG_DEBUG_LL_SER3
  54. add \rb, \rb, #0x00050000 @ Ser3
  55. #else
  56. add \rb, \rb, #0x00010000 @ Ser1
  57. #endif
  58. .endm
  59. #else
  60. .macro loadsp, rb, tmp
  61. addruart \rb, \tmp
  62. .endm
  63. #endif
  64. #endif
  65. #endif
  66. .macro kputc,val
  67. mov r0, \val
  68. bl putc
  69. .endm
  70. .macro kphex,val,len
  71. mov r0, \val
  72. mov r1, #\len
  73. bl phex
  74. .endm
  75. .macro debug_reloc_start
  76. #ifdef DEBUG
  77. kputc #'\n'
  78. kphex r6, 8 /* processor id */
  79. kputc #':'
  80. kphex r7, 8 /* architecture id */
  81. #ifdef CONFIG_CPU_CP15
  82. kputc #':'
  83. mrc p15, 0, r0, c1, c0
  84. kphex r0, 8 /* control reg */
  85. #endif
  86. kputc #'\n'
  87. kphex r5, 8 /* decompressed kernel start */
  88. kputc #'-'
  89. kphex r9, 8 /* decompressed kernel end */
  90. kputc #'>'
  91. kphex r4, 8 /* kernel execution address */
  92. kputc #'\n'
  93. #endif
  94. .endm
  95. .macro debug_reloc_end
  96. #ifdef DEBUG
  97. kphex r5, 8 /* end of kernel */
  98. kputc #'\n'
  99. mov r0, r4
  100. bl memdump /* dump 256 bytes at start of kernel */
  101. #endif
  102. .endm
  103. .section ".start", #alloc, #execinstr
  104. /*
  105. * sort out different calling conventions
  106. */
  107. .align
  108. /*
  109. * Always enter in ARM state for CPUs that support the ARM ISA.
  110. * As of today (2014) that's exactly the members of the A and R
  111. * classes.
  112. */
  113. AR_CLASS( .arm )
  114. start:
  115. .type start,#function
  116. .rept 7
  117. __nop
  118. .endr
  119. ARM( mov r0, r0 )
  120. ARM( b 1f )
  121. THUMB( badr r12, 1f )
  122. THUMB( bx r12 )
  123. .word _magic_sig @ Magic numbers to help the loader
  124. .word _magic_start @ absolute load/run zImage address
  125. .word _magic_end @ zImage end address
  126. .word 0x04030201 @ endianness flag
  127. THUMB( .thumb )
  128. 1: __EFI_HEADER
  129. ARM_BE8( setend be ) @ go BE8 if compiled for BE8
  130. AR_CLASS( mrs r9, cpsr )
  131. #ifdef CONFIG_ARM_VIRT_EXT
  132. bl __hyp_stub_install @ get into SVC mode, reversibly
  133. #endif
  134. mov r7, r1 @ save architecture ID
  135. mov r8, r2 @ save atags pointer
  136. #ifndef CONFIG_CPU_V7M
  137. /*
  138. * Booting from Angel - need to enter SVC mode and disable
  139. * FIQs/IRQs (numeric definitions from angel arm.h source).
  140. * We only do this if we were in user mode on entry.
  141. */
  142. mrs r2, cpsr @ get current mode
  143. tst r2, #3 @ not user?
  144. bne not_angel
  145. mov r0, #0x17 @ angel_SWIreason_EnterSVC
  146. ARM( swi 0x123456 ) @ angel_SWI_ARM
  147. THUMB( svc 0xab ) @ angel_SWI_THUMB
  148. not_angel:
  149. safe_svcmode_maskall r0
  150. msr spsr_cxsf, r9 @ Save the CPU boot mode in
  151. @ SPSR
  152. #endif
  153. /*
  154. * Note that some cache flushing and other stuff may
  155. * be needed here - is there an Angel SWI call for this?
  156. */
  157. /*
  158. * some architecture specific code can be inserted
  159. * by the linker here, but it should preserve r7, r8, and r9.
  160. */
  161. .text
  162. #ifdef CONFIG_AUTO_ZRELADDR
  163. /*
  164. * Find the start of physical memory. As we are executing
  165. * without the MMU on, we are in the physical address space.
  166. * We just need to get rid of any offset by aligning the
  167. * address.
  168. *
  169. * This alignment is a balance between the requirements of
  170. * different platforms - we have chosen 128MB to allow
  171. * platforms which align the start of their physical memory
  172. * to 128MB to use this feature, while allowing the zImage
  173. * to be placed within the first 128MB of memory on other
  174. * platforms. Increasing the alignment means we place
  175. * stricter alignment requirements on the start of physical
  176. * memory, but relaxing it means that we break people who
  177. * are already placing their zImage in (eg) the top 64MB
  178. * of this range.
  179. */
  180. mov r4, pc
  181. and r4, r4, #0xf8000000
  182. /* Determine final kernel image address. */
  183. add r4, r4, #TEXT_OFFSET
  184. #else
  185. ldr r4, =zreladdr
  186. #endif
  187. /*
  188. * Set up a page table only if it won't overwrite ourself.
  189. * That means r4 < pc || r4 - 16k page directory > &_end.
  190. * Given that r4 > &_end is most unfrequent, we add a rough
  191. * additional 1MB of room for a possible appended DTB.
  192. */
  193. mov r0, pc
  194. cmp r0, r4
  195. ldrcc r0, LC0+32
  196. addcc r0, r0, pc
  197. cmpcc r4, r0
  198. orrcc r4, r4, #1 @ remember we skipped cache_on
  199. blcs cache_on
  200. restart: adr r0, LC0
  201. ldmia r0, {r1, r2, r3, r6, r10, r11, r12}
  202. ldr sp, [r0, #28]
  203. /*
  204. * We might be running at a different address. We need
  205. * to fix up various pointers.
  206. */
  207. sub r0, r0, r1 @ calculate the delta offset
  208. add r6, r6, r0 @ _edata
  209. add r10, r10, r0 @ inflated kernel size location
  210. /*
  211. * The kernel build system appends the size of the
  212. * decompressed kernel at the end of the compressed data
  213. * in little-endian form.
  214. */
  215. ldrb r9, [r10, #0]
  216. ldrb lr, [r10, #1]
  217. orr r9, r9, lr, lsl #8
  218. ldrb lr, [r10, #2]
  219. ldrb r10, [r10, #3]
  220. orr r9, r9, lr, lsl #16
  221. orr r9, r9, r10, lsl #24
  222. #ifndef CONFIG_ZBOOT_ROM
  223. /* malloc space is above the relocated stack (64k max) */
  224. add sp, sp, r0
  225. add r10, sp, #0x10000
  226. #else
  227. /*
  228. * With ZBOOT_ROM the bss/stack is non relocatable,
  229. * but someone could still run this code from RAM,
  230. * in which case our reference is _edata.
  231. */
  232. mov r10, r6
  233. #endif
  234. mov r5, #0 @ init dtb size to 0
  235. #ifdef CONFIG_ARM_APPENDED_DTB
  236. /*
  237. * r0 = delta
  238. * r2 = BSS start
  239. * r3 = BSS end
  240. * r4 = final kernel address (possibly with LSB set)
  241. * r5 = appended dtb size (still unknown)
  242. * r6 = _edata
  243. * r7 = architecture ID
  244. * r8 = atags/device tree pointer
  245. * r9 = size of decompressed image
  246. * r10 = end of this image, including bss/stack/malloc space if non XIP
  247. * r11 = GOT start
  248. * r12 = GOT end
  249. * sp = stack pointer
  250. *
  251. * if there are device trees (dtb) appended to zImage, advance r10 so that the
  252. * dtb data will get relocated along with the kernel if necessary.
  253. */
  254. ldr lr, [r6, #0]
  255. #ifndef __ARMEB__
  256. ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
  257. #else
  258. ldr r1, =0xd00dfeed
  259. #endif
  260. cmp lr, r1
  261. bne dtb_check_done @ not found
  262. #ifdef CONFIG_ARM_ATAG_DTB_COMPAT
  263. /*
  264. * OK... Let's do some funky business here.
  265. * If we do have a DTB appended to zImage, and we do have
  266. * an ATAG list around, we want the later to be translated
  267. * and folded into the former here. No GOT fixup has occurred
  268. * yet, but none of the code we're about to call uses any
  269. * global variable.
  270. */
  271. /* Get the initial DTB size */
  272. ldr r5, [r6, #4]
  273. #ifndef __ARMEB__
  274. /* convert to little endian */
  275. eor r1, r5, r5, ror #16
  276. bic r1, r1, #0x00ff0000
  277. mov r5, r5, ror #8
  278. eor r5, r5, r1, lsr #8
  279. #endif
  280. /* 50% DTB growth should be good enough */
  281. add r5, r5, r5, lsr #1
  282. /* preserve 64-bit alignment */
  283. add r5, r5, #7
  284. bic r5, r5, #7
  285. /* clamp to 32KB min and 1MB max */
  286. cmp r5, #(1 << 15)
  287. movlo r5, #(1 << 15)
  288. cmp r5, #(1 << 20)
  289. movhi r5, #(1 << 20)
  290. /* temporarily relocate the stack past the DTB work space */
  291. add sp, sp, r5
  292. stmfd sp!, {r0-r3, ip, lr}
  293. mov r0, r8
  294. mov r1, r6
  295. mov r2, r5
  296. bl atags_to_fdt
  297. /*
  298. * If returned value is 1, there is no ATAG at the location
  299. * pointed by r8. Try the typical 0x100 offset from start
  300. * of RAM and hope for the best.
  301. */
  302. cmp r0, #1
  303. sub r0, r4, #TEXT_OFFSET
  304. bic r0, r0, #1
  305. add r0, r0, #0x100
  306. mov r1, r6
  307. mov r2, r5
  308. bleq atags_to_fdt
  309. ldmfd sp!, {r0-r3, ip, lr}
  310. sub sp, sp, r5
  311. #endif
  312. mov r8, r6 @ use the appended device tree
  313. /*
  314. * Make sure that the DTB doesn't end up in the final
  315. * kernel's .bss area. To do so, we adjust the decompressed
  316. * kernel size to compensate if that .bss size is larger
  317. * than the relocated code.
  318. */
  319. ldr r5, =_kernel_bss_size
  320. adr r1, wont_overwrite
  321. sub r1, r6, r1
  322. subs r1, r5, r1
  323. addhi r9, r9, r1
  324. /* Get the current DTB size */
  325. ldr r5, [r6, #4]
  326. #ifndef __ARMEB__
  327. /* convert r5 (dtb size) to little endian */
  328. eor r1, r5, r5, ror #16
  329. bic r1, r1, #0x00ff0000
  330. mov r5, r5, ror #8
  331. eor r5, r5, r1, lsr #8
  332. #endif
  333. /* preserve 64-bit alignment */
  334. add r5, r5, #7
  335. bic r5, r5, #7
  336. /* relocate some pointers past the appended dtb */
  337. add r6, r6, r5
  338. add r10, r10, r5
  339. add sp, sp, r5
  340. dtb_check_done:
  341. #endif
  342. /*
  343. * Check to see if we will overwrite ourselves.
  344. * r4 = final kernel address (possibly with LSB set)
  345. * r9 = size of decompressed image
  346. * r10 = end of this image, including bss/stack/malloc space if non XIP
  347. * We basically want:
  348. * r4 - 16k page directory >= r10 -> OK
  349. * r4 + image length <= address of wont_overwrite -> OK
  350. * Note: the possible LSB in r4 is harmless here.
  351. */
  352. add r10, r10, #16384
  353. cmp r4, r10
  354. bhs wont_overwrite
  355. add r10, r4, r9
  356. adr r9, wont_overwrite
  357. cmp r10, r9
  358. bls wont_overwrite
  359. /*
  360. * Relocate ourselves past the end of the decompressed kernel.
  361. * r6 = _edata
  362. * r10 = end of the decompressed kernel
  363. * Because we always copy ahead, we need to do it from the end and go
  364. * backward in case the source and destination overlap.
  365. */
  366. /*
  367. * Bump to the next 256-byte boundary with the size of
  368. * the relocation code added. This avoids overwriting
  369. * ourself when the offset is small.
  370. */
  371. add r10, r10, #((reloc_code_end - restart + 256) & ~255)
  372. bic r10, r10, #255
  373. /* Get start of code we want to copy and align it down. */
  374. adr r5, restart
  375. bic r5, r5, #31
  376. /* Relocate the hyp vector base if necessary */
  377. #ifdef CONFIG_ARM_VIRT_EXT
  378. mrs r0, spsr
  379. and r0, r0, #MODE_MASK
  380. cmp r0, #HYP_MODE
  381. bne 1f
  382. bl __hyp_get_vectors
  383. sub r0, r0, r5
  384. add r0, r0, r10
  385. bl __hyp_set_vectors
  386. 1:
  387. #endif
  388. sub r9, r6, r5 @ size to copy
  389. add r9, r9, #31 @ rounded up to a multiple
  390. bic r9, r9, #31 @ ... of 32 bytes
  391. add r6, r9, r5
  392. add r9, r9, r10
  393. 1: ldmdb r6!, {r0 - r3, r10 - r12, lr}
  394. cmp r6, r5
  395. stmdb r9!, {r0 - r3, r10 - r12, lr}
  396. bhi 1b
  397. /* Preserve offset to relocated code. */
  398. sub r6, r9, r6
  399. #ifndef CONFIG_ZBOOT_ROM
  400. /* cache_clean_flush may use the stack, so relocate it */
  401. add sp, sp, r6
  402. #endif
  403. bl cache_clean_flush
  404. badr r0, restart
  405. add r0, r0, r6
  406. mov pc, r0
  407. wont_overwrite:
  408. /*
  409. * If delta is zero, we are running at the address we were linked at.
  410. * r0 = delta
  411. * r2 = BSS start
  412. * r3 = BSS end
  413. * r4 = kernel execution address (possibly with LSB set)
  414. * r5 = appended dtb size (0 if not present)
  415. * r7 = architecture ID
  416. * r8 = atags pointer
  417. * r11 = GOT start
  418. * r12 = GOT end
  419. * sp = stack pointer
  420. */
  421. orrs r1, r0, r5
  422. beq not_relocated
  423. add r11, r11, r0
  424. add r12, r12, r0
  425. #ifndef CONFIG_ZBOOT_ROM
  426. /*
  427. * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
  428. * we need to fix up pointers into the BSS region.
  429. * Note that the stack pointer has already been fixed up.
  430. */
  431. add r2, r2, r0
  432. add r3, r3, r0
  433. /*
  434. * Relocate all entries in the GOT table.
  435. * Bump bss entries to _edata + dtb size
  436. */
  437. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  438. add r1, r1, r0 @ This fixes up C references
  439. cmp r1, r2 @ if entry >= bss_start &&
  440. cmphs r3, r1 @ bss_end > entry
  441. addhi r1, r1, r5 @ entry += dtb size
  442. str r1, [r11], #4 @ next entry
  443. cmp r11, r12
  444. blo 1b
  445. /* bump our bss pointers too */
  446. add r2, r2, r5
  447. add r3, r3, r5
  448. #else
  449. /*
  450. * Relocate entries in the GOT table. We only relocate
  451. * the entries that are outside the (relocated) BSS region.
  452. */
  453. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  454. cmp r1, r2 @ entry < bss_start ||
  455. cmphs r3, r1 @ _end < entry
  456. addlo r1, r1, r0 @ table. This fixes up the
  457. str r1, [r11], #4 @ C references.
  458. cmp r11, r12
  459. blo 1b
  460. #endif
  461. not_relocated: mov r0, #0
  462. 1: str r0, [r2], #4 @ clear bss
  463. str r0, [r2], #4
  464. str r0, [r2], #4
  465. str r0, [r2], #4
  466. cmp r2, r3
  467. blo 1b
  468. /*
  469. * Did we skip the cache setup earlier?
  470. * That is indicated by the LSB in r4.
  471. * Do it now if so.
  472. */
  473. tst r4, #1
  474. bic r4, r4, #1
  475. blne cache_on
  476. /*
  477. * The C runtime environment should now be setup sufficiently.
  478. * Set up some pointers, and start decompressing.
  479. * r4 = kernel execution address
  480. * r7 = architecture ID
  481. * r8 = atags pointer
  482. */
  483. mov r0, r4
  484. mov r1, sp @ malloc space above stack
  485. add r2, sp, #0x10000 @ 64k max
  486. mov r3, r7
  487. bl decompress_kernel
  488. bl cache_clean_flush
  489. bl cache_off
  490. mov r1, r7 @ restore architecture number
  491. mov r2, r8 @ restore atags pointer
  492. #ifdef CONFIG_ARM_VIRT_EXT
  493. mrs r0, spsr @ Get saved CPU boot mode
  494. and r0, r0, #MODE_MASK
  495. cmp r0, #HYP_MODE @ if not booted in HYP mode...
  496. bne __enter_kernel @ boot kernel directly
  497. adr r12, .L__hyp_reentry_vectors_offset
  498. ldr r0, [r12]
  499. add r0, r0, r12
  500. bl __hyp_set_vectors
  501. __HVC(0) @ otherwise bounce to hyp mode
  502. b . @ should never be reached
  503. .align 2
  504. .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
  505. #else
  506. b __enter_kernel
  507. #endif
  508. .align 2
  509. .type LC0, #object
  510. LC0: .word LC0 @ r1
  511. .word __bss_start @ r2
  512. .word _end @ r3
  513. .word _edata @ r6
  514. .word input_data_end - 4 @ r10 (inflated size location)
  515. .word _got_start @ r11
  516. .word _got_end @ ip
  517. .word .L_user_stack_end @ sp
  518. .word _end - restart + 16384 + 1024*1024
  519. .size LC0, . - LC0
  520. #ifdef CONFIG_ARCH_RPC
  521. .globl params
  522. params: ldr r0, =0x10000100 @ params_phys for RPC
  523. mov pc, lr
  524. .ltorg
  525. .align
  526. #endif
  527. /*
  528. * Turn on the cache. We need to setup some page tables so that we
  529. * can have both the I and D caches on.
  530. *
  531. * We place the page tables 16k down from the kernel execution address,
  532. * and we hope that nothing else is using it. If we're using it, we
  533. * will go pop!
  534. *
  535. * On entry,
  536. * r4 = kernel execution address
  537. * r7 = architecture number
  538. * r8 = atags pointer
  539. * On exit,
  540. * r0, r1, r2, r3, r9, r10, r12 corrupted
  541. * This routine must preserve:
  542. * r4, r7, r8
  543. */
  544. .align 5
  545. cache_on: mov r3, #8 @ cache_on function
  546. b call_cache_fn
  547. /*
  548. * Initialize the highest priority protection region, PR7
  549. * to cover all 32bit address and cacheable and bufferable.
  550. */
  551. __armv4_mpu_cache_on:
  552. mov r0, #0x3f @ 4G, the whole
  553. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  554. mcr p15, 0, r0, c6, c7, 1
  555. mov r0, #0x80 @ PR7
  556. mcr p15, 0, r0, c2, c0, 0 @ D-cache on
  557. mcr p15, 0, r0, c2, c0, 1 @ I-cache on
  558. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  559. mov r0, #0xc000
  560. mcr p15, 0, r0, c5, c0, 1 @ I-access permission
  561. mcr p15, 0, r0, c5, c0, 0 @ D-access permission
  562. mov r0, #0
  563. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  564. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  565. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  566. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  567. @ ...I .... ..D. WC.M
  568. orr r0, r0, #0x002d @ .... .... ..1. 11.1
  569. orr r0, r0, #0x1000 @ ...1 .... .... ....
  570. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  571. mov r0, #0
  572. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  573. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  574. mov pc, lr
  575. __armv3_mpu_cache_on:
  576. mov r0, #0x3f @ 4G, the whole
  577. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  578. mov r0, #0x80 @ PR7
  579. mcr p15, 0, r0, c2, c0, 0 @ cache on
  580. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  581. mov r0, #0xc000
  582. mcr p15, 0, r0, c5, c0, 0 @ access permission
  583. mov r0, #0
  584. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  585. /*
  586. * ?? ARMv3 MMU does not allow reading the control register,
  587. * does this really work on ARMv3 MPU?
  588. */
  589. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  590. @ .... .... .... WC.M
  591. orr r0, r0, #0x000d @ .... .... .... 11.1
  592. /* ?? this overwrites the value constructed above? */
  593. mov r0, #0
  594. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  595. /* ?? invalidate for the second time? */
  596. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  597. mov pc, lr
  598. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  599. #define CB_BITS 0x08
  600. #else
  601. #define CB_BITS 0x0c
  602. #endif
  603. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  604. bic r3, r3, #0xff @ Align the pointer
  605. bic r3, r3, #0x3f00
  606. /*
  607. * Initialise the page tables, turning on the cacheable and bufferable
  608. * bits for the RAM area only.
  609. */
  610. mov r0, r3
  611. mov r9, r0, lsr #18
  612. mov r9, r9, lsl #18 @ start of RAM
  613. add r10, r9, #0x10000000 @ a reasonable RAM size
  614. mov r1, #0x12 @ XN|U + section mapping
  615. orr r1, r1, #3 << 10 @ AP=11
  616. add r2, r3, #16384
  617. 1: cmp r1, r9 @ if virt > start of RAM
  618. cmphs r10, r1 @ && end of RAM > virt
  619. bic r1, r1, #0x1c @ clear XN|U + C + B
  620. orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
  621. orrhs r1, r1, r6 @ set RAM section settings
  622. str r1, [r0], #4 @ 1:1 mapping
  623. add r1, r1, #1048576
  624. teq r0, r2
  625. bne 1b
  626. /*
  627. * If ever we are running from Flash, then we surely want the cache
  628. * to be enabled also for our execution instance... We map 2MB of it
  629. * so there is no map overlap problem for up to 1 MB compressed kernel.
  630. * If the execution is in RAM then we would only be duplicating the above.
  631. */
  632. orr r1, r6, #0x04 @ ensure B is set for this
  633. orr r1, r1, #3 << 10
  634. mov r2, pc
  635. mov r2, r2, lsr #20
  636. orr r1, r1, r2, lsl #20
  637. add r0, r3, r2, lsl #2
  638. str r1, [r0], #4
  639. add r1, r1, #1048576
  640. str r1, [r0]
  641. mov pc, lr
  642. ENDPROC(__setup_mmu)
  643. @ Enable unaligned access on v6, to allow better code generation
  644. @ for the decompressor C code:
  645. __armv6_mmu_cache_on:
  646. mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
  647. bic r0, r0, #2 @ A (no unaligned access fault)
  648. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  649. mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
  650. b __armv4_mmu_cache_on
  651. __arm926ejs_mmu_cache_on:
  652. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  653. mov r0, #4 @ put dcache in WT mode
  654. mcr p15, 7, r0, c15, c0, 0
  655. #endif
  656. __armv4_mmu_cache_on:
  657. mov r12, lr
  658. #ifdef CONFIG_MMU
  659. mov r6, #CB_BITS | 0x12 @ U
  660. bl __setup_mmu
  661. mov r0, #0
  662. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  663. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  664. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  665. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  666. orr r0, r0, #0x0030
  667. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  668. bl __common_mmu_cache_on
  669. mov r0, #0
  670. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  671. #endif
  672. mov pc, r12
  673. __armv7_mmu_cache_on:
  674. mov r12, lr
  675. #ifdef CONFIG_MMU
  676. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  677. tst r11, #0xf @ VMSA
  678. movne r6, #CB_BITS | 0x02 @ !XN
  679. blne __setup_mmu
  680. mov r0, #0
  681. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  682. tst r11, #0xf @ VMSA
  683. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  684. #endif
  685. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  686. bic r0, r0, #1 << 28 @ clear SCTLR.TRE
  687. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  688. orr r0, r0, #0x003c @ write buffer
  689. bic r0, r0, #2 @ A (no unaligned access fault)
  690. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  691. @ (needed for ARM1176)
  692. #ifdef CONFIG_MMU
  693. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  694. mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
  695. orrne r0, r0, #1 @ MMU enabled
  696. movne r1, #0xfffffffd @ domain 0 = client
  697. bic r6, r6, #1 << 31 @ 32-bit translation system
  698. bic r6, r6, #(7 << 0) | (1 << 4) @ use only ttbr0
  699. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  700. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  701. mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
  702. #endif
  703. mcr p15, 0, r0, c7, c5, 4 @ ISB
  704. mcr p15, 0, r0, c1, c0, 0 @ load control register
  705. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  706. mov r0, #0
  707. mcr p15, 0, r0, c7, c5, 4 @ ISB
  708. mov pc, r12
  709. __fa526_cache_on:
  710. mov r12, lr
  711. mov r6, #CB_BITS | 0x12 @ U
  712. bl __setup_mmu
  713. mov r0, #0
  714. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  715. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  716. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  717. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  718. orr r0, r0, #0x1000 @ I-cache enable
  719. bl __common_mmu_cache_on
  720. mov r0, #0
  721. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  722. mov pc, r12
  723. __common_mmu_cache_on:
  724. #ifndef CONFIG_THUMB2_KERNEL
  725. #ifndef DEBUG
  726. orr r0, r0, #0x000d @ Write buffer, mmu
  727. #endif
  728. mov r1, #-1
  729. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  730. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  731. b 1f
  732. .align 5 @ cache line aligned
  733. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  734. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  735. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  736. #endif
  737. #define PROC_ENTRY_SIZE (4*5)
  738. /*
  739. * Here follow the relocatable cache support functions for the
  740. * various processors. This is a generic hook for locating an
  741. * entry and jumping to an instruction at the specified offset
  742. * from the start of the block. Please note this is all position
  743. * independent code.
  744. *
  745. * r1 = corrupted
  746. * r2 = corrupted
  747. * r3 = block offset
  748. * r9 = corrupted
  749. * r12 = corrupted
  750. */
  751. call_cache_fn: adr r12, proc_types
  752. #ifdef CONFIG_CPU_CP15
  753. mrc p15, 0, r9, c0, c0 @ get processor ID
  754. #elif defined(CONFIG_CPU_V7M)
  755. /*
  756. * On v7-M the processor id is located in the V7M_SCB_CPUID
  757. * register, but as cache handling is IMPLEMENTATION DEFINED on
  758. * v7-M (if existant at all) we just return early here.
  759. * If V7M_SCB_CPUID were used the cpu ID functions (i.e.
  760. * __armv7_mmu_cache_{on,off,flush}) would be selected which
  761. * use cp15 registers that are not implemented on v7-M.
  762. */
  763. bx lr
  764. #else
  765. ldr r9, =CONFIG_PROCESSOR_ID
  766. #endif
  767. 1: ldr r1, [r12, #0] @ get value
  768. ldr r2, [r12, #4] @ get mask
  769. eor r1, r1, r9 @ (real ^ match)
  770. tst r1, r2 @ & mask
  771. ARM( addeq pc, r12, r3 ) @ call cache function
  772. THUMB( addeq r12, r3 )
  773. THUMB( moveq pc, r12 ) @ call cache function
  774. add r12, r12, #PROC_ENTRY_SIZE
  775. b 1b
  776. /*
  777. * Table for cache operations. This is basically:
  778. * - CPU ID match
  779. * - CPU ID mask
  780. * - 'cache on' method instruction
  781. * - 'cache off' method instruction
  782. * - 'cache flush' method instruction
  783. *
  784. * We match an entry using: ((real_id ^ match) & mask) == 0
  785. *
  786. * Writethrough caches generally only need 'on' and 'off'
  787. * methods. Writeback caches _must_ have the flush method
  788. * defined.
  789. */
  790. .align 2
  791. .type proc_types,#object
  792. proc_types:
  793. .word 0x41000000 @ old ARM ID
  794. .word 0xff00f000
  795. mov pc, lr
  796. THUMB( nop )
  797. mov pc, lr
  798. THUMB( nop )
  799. mov pc, lr
  800. THUMB( nop )
  801. .word 0x41007000 @ ARM7/710
  802. .word 0xfff8fe00
  803. mov pc, lr
  804. THUMB( nop )
  805. mov pc, lr
  806. THUMB( nop )
  807. mov pc, lr
  808. THUMB( nop )
  809. .word 0x41807200 @ ARM720T (writethrough)
  810. .word 0xffffff00
  811. W(b) __armv4_mmu_cache_on
  812. W(b) __armv4_mmu_cache_off
  813. mov pc, lr
  814. THUMB( nop )
  815. .word 0x41007400 @ ARM74x
  816. .word 0xff00ff00
  817. W(b) __armv3_mpu_cache_on
  818. W(b) __armv3_mpu_cache_off
  819. W(b) __armv3_mpu_cache_flush
  820. .word 0x41009400 @ ARM94x
  821. .word 0xff00ff00
  822. W(b) __armv4_mpu_cache_on
  823. W(b) __armv4_mpu_cache_off
  824. W(b) __armv4_mpu_cache_flush
  825. .word 0x41069260 @ ARM926EJ-S (v5TEJ)
  826. .word 0xff0ffff0
  827. W(b) __arm926ejs_mmu_cache_on
  828. W(b) __armv4_mmu_cache_off
  829. W(b) __armv5tej_mmu_cache_flush
  830. .word 0x00007000 @ ARM7 IDs
  831. .word 0x0000f000
  832. mov pc, lr
  833. THUMB( nop )
  834. mov pc, lr
  835. THUMB( nop )
  836. mov pc, lr
  837. THUMB( nop )
  838. @ Everything from here on will be the new ID system.
  839. .word 0x4401a100 @ sa110 / sa1100
  840. .word 0xffffffe0
  841. W(b) __armv4_mmu_cache_on
  842. W(b) __armv4_mmu_cache_off
  843. W(b) __armv4_mmu_cache_flush
  844. .word 0x6901b110 @ sa1110
  845. .word 0xfffffff0
  846. W(b) __armv4_mmu_cache_on
  847. W(b) __armv4_mmu_cache_off
  848. W(b) __armv4_mmu_cache_flush
  849. .word 0x56056900
  850. .word 0xffffff00 @ PXA9xx
  851. W(b) __armv4_mmu_cache_on
  852. W(b) __armv4_mmu_cache_off
  853. W(b) __armv4_mmu_cache_flush
  854. .word 0x56158000 @ PXA168
  855. .word 0xfffff000
  856. W(b) __armv4_mmu_cache_on
  857. W(b) __armv4_mmu_cache_off
  858. W(b) __armv5tej_mmu_cache_flush
  859. .word 0x56050000 @ Feroceon
  860. .word 0xff0f0000
  861. W(b) __armv4_mmu_cache_on
  862. W(b) __armv4_mmu_cache_off
  863. W(b) __armv5tej_mmu_cache_flush
  864. #ifdef CONFIG_CPU_FEROCEON_OLD_ID
  865. /* this conflicts with the standard ARMv5TE entry */
  866. .long 0x41009260 @ Old Feroceon
  867. .long 0xff00fff0
  868. b __armv4_mmu_cache_on
  869. b __armv4_mmu_cache_off
  870. b __armv5tej_mmu_cache_flush
  871. #endif
  872. .word 0x66015261 @ FA526
  873. .word 0xff01fff1
  874. W(b) __fa526_cache_on
  875. W(b) __armv4_mmu_cache_off
  876. W(b) __fa526_cache_flush
  877. @ These match on the architecture ID
  878. .word 0x00020000 @ ARMv4T
  879. .word 0x000f0000
  880. W(b) __armv4_mmu_cache_on
  881. W(b) __armv4_mmu_cache_off
  882. W(b) __armv4_mmu_cache_flush
  883. .word 0x00050000 @ ARMv5TE
  884. .word 0x000f0000
  885. W(b) __armv4_mmu_cache_on
  886. W(b) __armv4_mmu_cache_off
  887. W(b) __armv4_mmu_cache_flush
  888. .word 0x00060000 @ ARMv5TEJ
  889. .word 0x000f0000
  890. W(b) __armv4_mmu_cache_on
  891. W(b) __armv4_mmu_cache_off
  892. W(b) __armv5tej_mmu_cache_flush
  893. .word 0x0007b000 @ ARMv6
  894. .word 0x000ff000
  895. W(b) __armv6_mmu_cache_on
  896. W(b) __armv4_mmu_cache_off
  897. W(b) __armv6_mmu_cache_flush
  898. .word 0x000f0000 @ new CPU Id
  899. .word 0x000f0000
  900. W(b) __armv7_mmu_cache_on
  901. W(b) __armv7_mmu_cache_off
  902. W(b) __armv7_mmu_cache_flush
  903. .word 0 @ unrecognised type
  904. .word 0
  905. mov pc, lr
  906. THUMB( nop )
  907. mov pc, lr
  908. THUMB( nop )
  909. mov pc, lr
  910. THUMB( nop )
  911. .size proc_types, . - proc_types
  912. /*
  913. * If you get a "non-constant expression in ".if" statement"
  914. * error from the assembler on this line, check that you have
  915. * not accidentally written a "b" instruction where you should
  916. * have written W(b).
  917. */
  918. .if (. - proc_types) % PROC_ENTRY_SIZE != 0
  919. .error "The size of one or more proc_types entries is wrong."
  920. .endif
  921. /*
  922. * Turn off the Cache and MMU. ARMv3 does not support
  923. * reading the control register, but ARMv4 does.
  924. *
  925. * On exit,
  926. * r0, r1, r2, r3, r9, r12 corrupted
  927. * This routine must preserve:
  928. * r4, r7, r8
  929. */
  930. .align 5
  931. cache_off: mov r3, #12 @ cache_off function
  932. b call_cache_fn
  933. __armv4_mpu_cache_off:
  934. mrc p15, 0, r0, c1, c0
  935. bic r0, r0, #0x000d
  936. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  937. mov r0, #0
  938. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  939. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  940. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  941. mov pc, lr
  942. __armv3_mpu_cache_off:
  943. mrc p15, 0, r0, c1, c0
  944. bic r0, r0, #0x000d
  945. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  946. mov r0, #0
  947. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  948. mov pc, lr
  949. __armv4_mmu_cache_off:
  950. #ifdef CONFIG_MMU
  951. mrc p15, 0, r0, c1, c0
  952. bic r0, r0, #0x000d
  953. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  954. mov r0, #0
  955. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  956. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  957. #endif
  958. mov pc, lr
  959. __armv7_mmu_cache_off:
  960. mrc p15, 0, r0, c1, c0
  961. #ifdef CONFIG_MMU
  962. bic r0, r0, #0x000d
  963. #else
  964. bic r0, r0, #0x000c
  965. #endif
  966. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  967. mov r12, lr
  968. bl __armv7_mmu_cache_flush
  969. mov r0, #0
  970. #ifdef CONFIG_MMU
  971. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  972. #endif
  973. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  974. mcr p15, 0, r0, c7, c10, 4 @ DSB
  975. mcr p15, 0, r0, c7, c5, 4 @ ISB
  976. mov pc, r12
  977. /*
  978. * Clean and flush the cache to maintain consistency.
  979. *
  980. * On exit,
  981. * r1, r2, r3, r9, r10, r11, r12 corrupted
  982. * This routine must preserve:
  983. * r4, r6, r7, r8
  984. */
  985. .align 5
  986. cache_clean_flush:
  987. mov r3, #16
  988. b call_cache_fn
  989. __armv4_mpu_cache_flush:
  990. tst r4, #1
  991. movne pc, lr
  992. mov r2, #1
  993. mov r3, #0
  994. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  995. mov r1, #7 << 5 @ 8 segments
  996. 1: orr r3, r1, #63 << 26 @ 64 entries
  997. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  998. subs r3, r3, #1 << 26
  999. bcs 2b @ entries 63 to 0
  1000. subs r1, r1, #1 << 5
  1001. bcs 1b @ segments 7 to 0
  1002. teq r2, #0
  1003. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  1004. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  1005. mov pc, lr
  1006. __fa526_cache_flush:
  1007. tst r4, #1
  1008. movne pc, lr
  1009. mov r1, #0
  1010. mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
  1011. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  1012. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1013. mov pc, lr
  1014. __armv6_mmu_cache_flush:
  1015. mov r1, #0
  1016. tst r4, #1
  1017. mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  1018. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  1019. mcreq p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  1020. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1021. mov pc, lr
  1022. __armv7_mmu_cache_flush:
  1023. tst r4, #1
  1024. bne iflush
  1025. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  1026. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  1027. mov r10, #0
  1028. beq hierarchical
  1029. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  1030. b iflush
  1031. hierarchical:
  1032. mcr p15, 0, r10, c7, c10, 5 @ DMB
  1033. stmfd sp!, {r0-r7, r9-r11}
  1034. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  1035. ands r3, r0, #0x7000000 @ extract loc from clidr
  1036. mov r3, r3, lsr #23 @ left align loc bit field
  1037. beq finished @ if loc is 0, then no need to clean
  1038. mov r10, #0 @ start clean at cache level 0
  1039. loop1:
  1040. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  1041. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  1042. and r1, r1, #7 @ mask of the bits for current cache only
  1043. cmp r1, #2 @ see what cache we have at this level
  1044. blt skip @ skip if no cache, or just i-cache
  1045. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  1046. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  1047. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  1048. and r2, r1, #7 @ extract the length of the cache lines
  1049. add r2, r2, #4 @ add 4 (line length offset)
  1050. ldr r4, =0x3ff
  1051. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  1052. clz r5, r4 @ find bit position of way size increment
  1053. ldr r7, =0x7fff
  1054. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  1055. loop2:
  1056. mov r9, r4 @ create working copy of max way size
  1057. loop3:
  1058. ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
  1059. ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
  1060. THUMB( lsl r6, r9, r5 )
  1061. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  1062. THUMB( lsl r6, r7, r2 )
  1063. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  1064. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  1065. subs r9, r9, #1 @ decrement the way
  1066. bge loop3
  1067. subs r7, r7, #1 @ decrement the index
  1068. bge loop2
  1069. skip:
  1070. add r10, r10, #2 @ increment cache number
  1071. cmp r3, r10
  1072. bgt loop1
  1073. finished:
  1074. ldmfd sp!, {r0-r7, r9-r11}
  1075. mov r10, #0 @ swith back to cache level 0
  1076. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  1077. iflush:
  1078. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1079. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  1080. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1081. mcr p15, 0, r10, c7, c5, 4 @ ISB
  1082. mov pc, lr
  1083. __armv5tej_mmu_cache_flush:
  1084. tst r4, #1
  1085. movne pc, lr
  1086. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  1087. bne 1b
  1088. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  1089. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  1090. mov pc, lr
  1091. __armv4_mmu_cache_flush:
  1092. tst r4, #1
  1093. movne pc, lr
  1094. mov r2, #64*1024 @ default: 32K dcache size (*2)
  1095. mov r11, #32 @ default: 32 byte line size
  1096. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  1097. teq r3, r9 @ cache ID register present?
  1098. beq no_cache_id
  1099. mov r1, r3, lsr #18
  1100. and r1, r1, #7
  1101. mov r2, #1024
  1102. mov r2, r2, lsl r1 @ base dcache size *2
  1103. tst r3, #1 << 14 @ test M bit
  1104. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  1105. mov r3, r3, lsr #12
  1106. and r3, r3, #3
  1107. mov r11, #8
  1108. mov r11, r11, lsl r3 @ cache line size in bytes
  1109. no_cache_id:
  1110. mov r1, pc
  1111. bic r1, r1, #63 @ align to longest cache line
  1112. add r2, r1, r2
  1113. 1:
  1114. ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
  1115. THUMB( ldr r3, [r1] ) @ s/w flush D cache
  1116. THUMB( add r1, r1, r11 )
  1117. teq r1, r2
  1118. bne 1b
  1119. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  1120. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  1121. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1122. mov pc, lr
  1123. __armv3_mmu_cache_flush:
  1124. __armv3_mpu_cache_flush:
  1125. tst r4, #1
  1126. movne pc, lr
  1127. mov r1, #0
  1128. mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
  1129. mov pc, lr
  1130. /*
  1131. * Various debugging routines for printing hex characters and
  1132. * memory, which again must be relocatable.
  1133. */
  1134. #ifdef DEBUG
  1135. .align 2
  1136. .type phexbuf,#object
  1137. phexbuf: .space 12
  1138. .size phexbuf, . - phexbuf
  1139. @ phex corrupts {r0, r1, r2, r3}
  1140. phex: adr r3, phexbuf
  1141. mov r2, #0
  1142. strb r2, [r3, r1]
  1143. 1: subs r1, r1, #1
  1144. movmi r0, r3
  1145. bmi puts
  1146. and r2, r0, #15
  1147. mov r0, r0, lsr #4
  1148. cmp r2, #10
  1149. addge r2, r2, #7
  1150. add r2, r2, #'0'
  1151. strb r2, [r3, r1]
  1152. b 1b
  1153. @ puts corrupts {r0, r1, r2, r3}
  1154. puts: loadsp r3, r1
  1155. 1: ldrb r2, [r0], #1
  1156. teq r2, #0
  1157. moveq pc, lr
  1158. 2: writeb r2, r3
  1159. mov r1, #0x00020000
  1160. 3: subs r1, r1, #1
  1161. bne 3b
  1162. teq r2, #'\n'
  1163. moveq r2, #'\r'
  1164. beq 2b
  1165. teq r0, #0
  1166. bne 1b
  1167. mov pc, lr
  1168. @ putc corrupts {r0, r1, r2, r3}
  1169. putc:
  1170. mov r2, r0
  1171. mov r0, #0
  1172. loadsp r3, r1
  1173. b 2b
  1174. @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
  1175. memdump: mov r12, r0
  1176. mov r10, lr
  1177. mov r11, #0
  1178. 2: mov r0, r11, lsl #2
  1179. add r0, r0, r12
  1180. mov r1, #8
  1181. bl phex
  1182. mov r0, #':'
  1183. bl putc
  1184. 1: mov r0, #' '
  1185. bl putc
  1186. ldr r0, [r12, r11, lsl #2]
  1187. mov r1, #8
  1188. bl phex
  1189. and r0, r11, #7
  1190. teq r0, #3
  1191. moveq r0, #' '
  1192. bleq putc
  1193. and r0, r11, #7
  1194. add r11, r11, #1
  1195. teq r0, #7
  1196. bne 1b
  1197. mov r0, #'\n'
  1198. bl putc
  1199. cmp r11, #64
  1200. blt 2b
  1201. mov pc, r10
  1202. #endif
  1203. .ltorg
  1204. #ifdef CONFIG_ARM_VIRT_EXT
  1205. .align 5
  1206. __hyp_reentry_vectors:
  1207. W(b) . @ reset
  1208. W(b) . @ undef
  1209. W(b) . @ svc
  1210. W(b) . @ pabort
  1211. W(b) . @ dabort
  1212. W(b) __enter_kernel @ hyp
  1213. W(b) . @ irq
  1214. W(b) . @ fiq
  1215. #endif /* CONFIG_ARM_VIRT_EXT */
  1216. __enter_kernel:
  1217. mov r0, #0 @ must be 0
  1218. ARM( mov pc, r4 ) @ call kernel
  1219. M_CLASS( add r4, r4, #1 ) @ enter in Thumb mode for M class
  1220. THUMB( bx r4 ) @ entry point is always ARM for A/R classes
  1221. reloc_code_end:
  1222. #ifdef CONFIG_EFI_STUB
  1223. .align 2
  1224. _start: .long start - .
  1225. ENTRY(efi_stub_entry)
  1226. @ allocate space on stack for passing current zImage address
  1227. @ and for the EFI stub to return of new entry point of
  1228. @ zImage, as EFI stub may copy the kernel. Pointer address
  1229. @ is passed in r2. r0 and r1 are passed through from the
  1230. @ EFI firmware to efi_entry
  1231. adr ip, _start
  1232. ldr r3, [ip]
  1233. add r3, r3, ip
  1234. stmfd sp!, {r3, lr}
  1235. mov r2, sp @ pass zImage address in r2
  1236. bl efi_entry
  1237. @ Check for error return from EFI stub. r0 has FDT address
  1238. @ or error code.
  1239. cmn r0, #1
  1240. beq efi_load_fail
  1241. @ Preserve return value of efi_entry() in r4
  1242. mov r4, r0
  1243. bl cache_clean_flush
  1244. bl cache_off
  1245. @ Set parameters for booting zImage according to boot protocol
  1246. @ put FDT address in r2, it was returned by efi_entry()
  1247. @ r1 is the machine type, and r0 needs to be 0
  1248. mov r0, #0
  1249. mov r1, #0xFFFFFFFF
  1250. mov r2, r4
  1251. @ Branch to (possibly) relocated zImage that is in [sp]
  1252. ldr lr, [sp]
  1253. ldr ip, =start_offset
  1254. add lr, lr, ip
  1255. mov pc, lr @ no mode switch
  1256. efi_load_fail:
  1257. @ Return EFI_LOAD_ERROR to EFI firmware on error.
  1258. ldr r0, =0x80000001
  1259. ldmfd sp!, {ip, pc}
  1260. ENDPROC(efi_stub_entry)
  1261. #endif
  1262. .align
  1263. .section ".stack", "aw", %nobits
  1264. .L_user_stack: .space 4096
  1265. .L_user_stack_end: