head.S 32 KB

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