head.S 34 KB

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