head.S 32 KB

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