head.S 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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. bl cache_clean_flush
  358. adr r0, BSYM(restart)
  359. add r0, r0, r6
  360. mov pc, r0
  361. wont_overwrite:
  362. /*
  363. * If delta is zero, we are running at the address we were linked at.
  364. * r0 = delta
  365. * r2 = BSS start
  366. * r3 = BSS end
  367. * r4 = kernel execution address (possibly with LSB set)
  368. * r5 = appended dtb size (0 if not present)
  369. * r7 = architecture ID
  370. * r8 = atags pointer
  371. * r11 = GOT start
  372. * r12 = GOT end
  373. * sp = stack pointer
  374. */
  375. orrs r1, r0, r5
  376. beq not_relocated
  377. add r11, r11, r0
  378. add r12, r12, r0
  379. #ifndef CONFIG_ZBOOT_ROM
  380. /*
  381. * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
  382. * we need to fix up pointers into the BSS region.
  383. * Note that the stack pointer has already been fixed up.
  384. */
  385. add r2, r2, r0
  386. add r3, r3, r0
  387. /*
  388. * Relocate all entries in the GOT table.
  389. * Bump bss entries to _edata + dtb size
  390. */
  391. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  392. add r1, r1, r0 @ This fixes up C references
  393. cmp r1, r2 @ if entry >= bss_start &&
  394. cmphs r3, r1 @ bss_end > entry
  395. addhi r1, r1, r5 @ entry += dtb size
  396. str r1, [r11], #4 @ next entry
  397. cmp r11, r12
  398. blo 1b
  399. /* bump our bss pointers too */
  400. add r2, r2, r5
  401. add r3, r3, r5
  402. #else
  403. /*
  404. * Relocate entries in the GOT table. We only relocate
  405. * the entries that are outside the (relocated) BSS region.
  406. */
  407. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  408. cmp r1, r2 @ entry < bss_start ||
  409. cmphs r3, r1 @ _end < entry
  410. addlo r1, r1, r0 @ table. This fixes up the
  411. str r1, [r11], #4 @ C references.
  412. cmp r11, r12
  413. blo 1b
  414. #endif
  415. not_relocated: mov r0, #0
  416. 1: str r0, [r2], #4 @ clear bss
  417. str r0, [r2], #4
  418. str r0, [r2], #4
  419. str r0, [r2], #4
  420. cmp r2, r3
  421. blo 1b
  422. /*
  423. * Did we skip the cache setup earlier?
  424. * That is indicated by the LSB in r4.
  425. * Do it now if so.
  426. */
  427. tst r4, #1
  428. bic r4, r4, #1
  429. blne cache_on
  430. /*
  431. * The C runtime environment should now be setup sufficiently.
  432. * Set up some pointers, and start decompressing.
  433. * r4 = kernel execution address
  434. * r7 = architecture ID
  435. * r8 = atags pointer
  436. */
  437. mov r0, r4
  438. mov r1, sp @ malloc space above stack
  439. add r2, sp, #0x10000 @ 64k max
  440. mov r3, r7
  441. bl decompress_kernel
  442. bl cache_clean_flush
  443. bl cache_off
  444. mov r1, r7 @ restore architecture number
  445. mov r2, r8 @ restore atags pointer
  446. #ifdef CONFIG_ARM_VIRT_EXT
  447. mrs r0, spsr @ Get saved CPU boot mode
  448. and r0, r0, #MODE_MASK
  449. cmp r0, #HYP_MODE @ if not booted in HYP mode...
  450. bne __enter_kernel @ boot kernel directly
  451. adr r12, .L__hyp_reentry_vectors_offset
  452. ldr r0, [r12]
  453. add r0, r0, r12
  454. bl __hyp_set_vectors
  455. __HVC(0) @ otherwise bounce to hyp mode
  456. b . @ should never be reached
  457. .align 2
  458. .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
  459. #else
  460. b __enter_kernel
  461. #endif
  462. .align 2
  463. .type LC0, #object
  464. LC0: .word LC0 @ r1
  465. .word __bss_start @ r2
  466. .word _end @ r3
  467. .word _edata @ r6
  468. .word input_data_end - 4 @ r10 (inflated size location)
  469. .word _got_start @ r11
  470. .word _got_end @ ip
  471. .word .L_user_stack_end @ sp
  472. .word _end - restart + 16384 + 1024*1024
  473. .size LC0, . - LC0
  474. #ifdef CONFIG_ARCH_RPC
  475. .globl params
  476. params: ldr r0, =0x10000100 @ params_phys for RPC
  477. mov pc, lr
  478. .ltorg
  479. .align
  480. #endif
  481. /*
  482. * Turn on the cache. We need to setup some page tables so that we
  483. * can have both the I and D caches on.
  484. *
  485. * We place the page tables 16k down from the kernel execution address,
  486. * and we hope that nothing else is using it. If we're using it, we
  487. * will go pop!
  488. *
  489. * On entry,
  490. * r4 = kernel execution address
  491. * r7 = architecture number
  492. * r8 = atags pointer
  493. * On exit,
  494. * r0, r1, r2, r3, r9, r10, r12 corrupted
  495. * This routine must preserve:
  496. * r4, r7, r8
  497. */
  498. .align 5
  499. cache_on: mov r3, #8 @ cache_on function
  500. b call_cache_fn
  501. /*
  502. * Initialize the highest priority protection region, PR7
  503. * to cover all 32bit address and cacheable and bufferable.
  504. */
  505. __armv4_mpu_cache_on:
  506. mov r0, #0x3f @ 4G, the whole
  507. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  508. mcr p15, 0, r0, c6, c7, 1
  509. mov r0, #0x80 @ PR7
  510. mcr p15, 0, r0, c2, c0, 0 @ D-cache on
  511. mcr p15, 0, r0, c2, c0, 1 @ I-cache on
  512. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  513. mov r0, #0xc000
  514. mcr p15, 0, r0, c5, c0, 1 @ I-access permission
  515. mcr p15, 0, r0, c5, c0, 0 @ D-access permission
  516. mov r0, #0
  517. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  518. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  519. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  520. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  521. @ ...I .... ..D. WC.M
  522. orr r0, r0, #0x002d @ .... .... ..1. 11.1
  523. orr r0, r0, #0x1000 @ ...1 .... .... ....
  524. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  525. mov r0, #0
  526. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  527. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  528. mov pc, lr
  529. __armv3_mpu_cache_on:
  530. mov r0, #0x3f @ 4G, the whole
  531. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  532. mov r0, #0x80 @ PR7
  533. mcr p15, 0, r0, c2, c0, 0 @ cache on
  534. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  535. mov r0, #0xc000
  536. mcr p15, 0, r0, c5, c0, 0 @ access permission
  537. mov r0, #0
  538. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  539. /*
  540. * ?? ARMv3 MMU does not allow reading the control register,
  541. * does this really work on ARMv3 MPU?
  542. */
  543. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  544. @ .... .... .... WC.M
  545. orr r0, r0, #0x000d @ .... .... .... 11.1
  546. /* ?? this overwrites the value constructed above? */
  547. mov r0, #0
  548. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  549. /* ?? invalidate for the second time? */
  550. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  551. mov pc, lr
  552. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  553. #define CB_BITS 0x08
  554. #else
  555. #define CB_BITS 0x0c
  556. #endif
  557. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  558. bic r3, r3, #0xff @ Align the pointer
  559. bic r3, r3, #0x3f00
  560. /*
  561. * Initialise the page tables, turning on the cacheable and bufferable
  562. * bits for the RAM area only.
  563. */
  564. mov r0, r3
  565. mov r9, r0, lsr #18
  566. mov r9, r9, lsl #18 @ start of RAM
  567. add r10, r9, #0x10000000 @ a reasonable RAM size
  568. mov r1, #0x12 @ XN|U + section mapping
  569. orr r1, r1, #3 << 10 @ AP=11
  570. add r2, r3, #16384
  571. 1: cmp r1, r9 @ if virt > start of RAM
  572. cmphs r10, r1 @ && end of RAM > virt
  573. bic r1, r1, #0x1c @ clear XN|U + C + B
  574. orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
  575. orrhs r1, r1, r6 @ set RAM section settings
  576. str r1, [r0], #4 @ 1:1 mapping
  577. add r1, r1, #1048576
  578. teq r0, r2
  579. bne 1b
  580. /*
  581. * If ever we are running from Flash, then we surely want the cache
  582. * to be enabled also for our execution instance... We map 2MB of it
  583. * so there is no map overlap problem for up to 1 MB compressed kernel.
  584. * If the execution is in RAM then we would only be duplicating the above.
  585. */
  586. orr r1, r6, #0x04 @ ensure B is set for this
  587. orr r1, r1, #3 << 10
  588. mov r2, pc
  589. mov r2, r2, lsr #20
  590. orr r1, r1, r2, lsl #20
  591. add r0, r3, r2, lsl #2
  592. str r1, [r0], #4
  593. add r1, r1, #1048576
  594. str r1, [r0]
  595. mov pc, lr
  596. ENDPROC(__setup_mmu)
  597. @ Enable unaligned access on v6, to allow better code generation
  598. @ for the decompressor C code:
  599. __armv6_mmu_cache_on:
  600. mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
  601. bic r0, r0, #2 @ A (no unaligned access fault)
  602. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  603. mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
  604. b __armv4_mmu_cache_on
  605. __arm926ejs_mmu_cache_on:
  606. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  607. mov r0, #4 @ put dcache in WT mode
  608. mcr p15, 7, r0, c15, c0, 0
  609. #endif
  610. __armv4_mmu_cache_on:
  611. mov r12, lr
  612. #ifdef CONFIG_MMU
  613. mov r6, #CB_BITS | 0x12 @ U
  614. bl __setup_mmu
  615. mov r0, #0
  616. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  617. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  618. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  619. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  620. orr r0, r0, #0x0030
  621. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  622. bl __common_mmu_cache_on
  623. mov r0, #0
  624. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  625. #endif
  626. mov pc, r12
  627. __armv7_mmu_cache_on:
  628. mov r12, lr
  629. #ifdef CONFIG_MMU
  630. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  631. tst r11, #0xf @ VMSA
  632. movne r6, #CB_BITS | 0x02 @ !XN
  633. blne __setup_mmu
  634. mov r0, #0
  635. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  636. tst r11, #0xf @ VMSA
  637. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  638. #endif
  639. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  640. bic r0, r0, #1 << 28 @ clear SCTLR.TRE
  641. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  642. orr r0, r0, #0x003c @ write buffer
  643. bic r0, r0, #2 @ A (no unaligned access fault)
  644. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  645. @ (needed for ARM1176)
  646. #ifdef CONFIG_MMU
  647. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  648. mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
  649. orrne r0, r0, #1 @ MMU enabled
  650. movne r1, #0xfffffffd @ domain 0 = client
  651. bic r6, r6, #1 << 31 @ 32-bit translation system
  652. bic r6, r6, #3 << 0 @ use only ttbr0
  653. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  654. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  655. mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
  656. #endif
  657. mcr p15, 0, r0, c7, c5, 4 @ ISB
  658. mcr p15, 0, r0, c1, c0, 0 @ load control register
  659. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  660. mov r0, #0
  661. mcr p15, 0, r0, c7, c5, 4 @ ISB
  662. mov pc, r12
  663. __fa526_cache_on:
  664. mov r12, lr
  665. mov r6, #CB_BITS | 0x12 @ U
  666. bl __setup_mmu
  667. mov r0, #0
  668. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  669. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  670. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  671. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  672. orr r0, r0, #0x1000 @ I-cache enable
  673. bl __common_mmu_cache_on
  674. mov r0, #0
  675. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  676. mov pc, r12
  677. __common_mmu_cache_on:
  678. #ifndef CONFIG_THUMB2_KERNEL
  679. #ifndef DEBUG
  680. orr r0, r0, #0x000d @ Write buffer, mmu
  681. #endif
  682. mov r1, #-1
  683. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  684. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  685. b 1f
  686. .align 5 @ cache line aligned
  687. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  688. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  689. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  690. #endif
  691. #define PROC_ENTRY_SIZE (4*5)
  692. /*
  693. * Here follow the relocatable cache support functions for the
  694. * various processors. This is a generic hook for locating an
  695. * entry and jumping to an instruction at the specified offset
  696. * from the start of the block. Please note this is all position
  697. * independent code.
  698. *
  699. * r1 = corrupted
  700. * r2 = corrupted
  701. * r3 = block offset
  702. * r9 = corrupted
  703. * r12 = corrupted
  704. */
  705. call_cache_fn: adr r12, proc_types
  706. #ifdef CONFIG_CPU_CP15
  707. mrc p15, 0, r9, c0, c0 @ get processor ID
  708. #else
  709. ldr r9, =CONFIG_PROCESSOR_ID
  710. #endif
  711. 1: ldr r1, [r12, #0] @ get value
  712. ldr r2, [r12, #4] @ get mask
  713. eor r1, r1, r9 @ (real ^ match)
  714. tst r1, r2 @ & mask
  715. ARM( addeq pc, r12, r3 ) @ call cache function
  716. THUMB( addeq r12, r3 )
  717. THUMB( moveq pc, r12 ) @ call cache function
  718. add r12, r12, #PROC_ENTRY_SIZE
  719. b 1b
  720. /*
  721. * Table for cache operations. This is basically:
  722. * - CPU ID match
  723. * - CPU ID mask
  724. * - 'cache on' method instruction
  725. * - 'cache off' method instruction
  726. * - 'cache flush' method instruction
  727. *
  728. * We match an entry using: ((real_id ^ match) & mask) == 0
  729. *
  730. * Writethrough caches generally only need 'on' and 'off'
  731. * methods. Writeback caches _must_ have the flush method
  732. * defined.
  733. */
  734. .align 2
  735. .type proc_types,#object
  736. proc_types:
  737. .word 0x41000000 @ old ARM ID
  738. .word 0xff00f000
  739. mov pc, lr
  740. THUMB( nop )
  741. mov pc, lr
  742. THUMB( nop )
  743. mov pc, lr
  744. THUMB( nop )
  745. .word 0x41007000 @ ARM7/710
  746. .word 0xfff8fe00
  747. mov pc, lr
  748. THUMB( nop )
  749. mov pc, lr
  750. THUMB( nop )
  751. mov pc, lr
  752. THUMB( nop )
  753. .word 0x41807200 @ ARM720T (writethrough)
  754. .word 0xffffff00
  755. W(b) __armv4_mmu_cache_on
  756. W(b) __armv4_mmu_cache_off
  757. mov pc, lr
  758. THUMB( nop )
  759. .word 0x41007400 @ ARM74x
  760. .word 0xff00ff00
  761. W(b) __armv3_mpu_cache_on
  762. W(b) __armv3_mpu_cache_off
  763. W(b) __armv3_mpu_cache_flush
  764. .word 0x41009400 @ ARM94x
  765. .word 0xff00ff00
  766. W(b) __armv4_mpu_cache_on
  767. W(b) __armv4_mpu_cache_off
  768. W(b) __armv4_mpu_cache_flush
  769. .word 0x41069260 @ ARM926EJ-S (v5TEJ)
  770. .word 0xff0ffff0
  771. W(b) __arm926ejs_mmu_cache_on
  772. W(b) __armv4_mmu_cache_off
  773. W(b) __armv5tej_mmu_cache_flush
  774. .word 0x00007000 @ ARM7 IDs
  775. .word 0x0000f000
  776. mov pc, lr
  777. THUMB( nop )
  778. mov pc, lr
  779. THUMB( nop )
  780. mov pc, lr
  781. THUMB( nop )
  782. @ Everything from here on will be the new ID system.
  783. .word 0x4401a100 @ sa110 / sa1100
  784. .word 0xffffffe0
  785. W(b) __armv4_mmu_cache_on
  786. W(b) __armv4_mmu_cache_off
  787. W(b) __armv4_mmu_cache_flush
  788. .word 0x6901b110 @ sa1110
  789. .word 0xfffffff0
  790. W(b) __armv4_mmu_cache_on
  791. W(b) __armv4_mmu_cache_off
  792. W(b) __armv4_mmu_cache_flush
  793. .word 0x56056900
  794. .word 0xffffff00 @ PXA9xx
  795. W(b) __armv4_mmu_cache_on
  796. W(b) __armv4_mmu_cache_off
  797. W(b) __armv4_mmu_cache_flush
  798. .word 0x56158000 @ PXA168
  799. .word 0xfffff000
  800. W(b) __armv4_mmu_cache_on
  801. W(b) __armv4_mmu_cache_off
  802. W(b) __armv5tej_mmu_cache_flush
  803. .word 0x56050000 @ Feroceon
  804. .word 0xff0f0000
  805. W(b) __armv4_mmu_cache_on
  806. W(b) __armv4_mmu_cache_off
  807. W(b) __armv5tej_mmu_cache_flush
  808. #ifdef CONFIG_CPU_FEROCEON_OLD_ID
  809. /* this conflicts with the standard ARMv5TE entry */
  810. .long 0x41009260 @ Old Feroceon
  811. .long 0xff00fff0
  812. b __armv4_mmu_cache_on
  813. b __armv4_mmu_cache_off
  814. b __armv5tej_mmu_cache_flush
  815. #endif
  816. .word 0x66015261 @ FA526
  817. .word 0xff01fff1
  818. W(b) __fa526_cache_on
  819. W(b) __armv4_mmu_cache_off
  820. W(b) __fa526_cache_flush
  821. @ These match on the architecture ID
  822. .word 0x00020000 @ ARMv4T
  823. .word 0x000f0000
  824. W(b) __armv4_mmu_cache_on
  825. W(b) __armv4_mmu_cache_off
  826. W(b) __armv4_mmu_cache_flush
  827. .word 0x00050000 @ ARMv5TE
  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 0x00060000 @ ARMv5TEJ
  833. .word 0x000f0000
  834. W(b) __armv4_mmu_cache_on
  835. W(b) __armv4_mmu_cache_off
  836. W(b) __armv5tej_mmu_cache_flush
  837. .word 0x0007b000 @ ARMv6
  838. .word 0x000ff000
  839. W(b) __armv6_mmu_cache_on
  840. W(b) __armv4_mmu_cache_off
  841. W(b) __armv6_mmu_cache_flush
  842. .word 0x000f0000 @ new CPU Id
  843. .word 0x000f0000
  844. W(b) __armv7_mmu_cache_on
  845. W(b) __armv7_mmu_cache_off
  846. W(b) __armv7_mmu_cache_flush
  847. .word 0 @ unrecognised type
  848. .word 0
  849. mov pc, lr
  850. THUMB( nop )
  851. mov pc, lr
  852. THUMB( nop )
  853. mov pc, lr
  854. THUMB( nop )
  855. .size proc_types, . - proc_types
  856. /*
  857. * If you get a "non-constant expression in ".if" statement"
  858. * error from the assembler on this line, check that you have
  859. * not accidentally written a "b" instruction where you should
  860. * have written W(b).
  861. */
  862. .if (. - proc_types) % PROC_ENTRY_SIZE != 0
  863. .error "The size of one or more proc_types entries is wrong."
  864. .endif
  865. /*
  866. * Turn off the Cache and MMU. ARMv3 does not support
  867. * reading the control register, but ARMv4 does.
  868. *
  869. * On exit,
  870. * r0, r1, r2, r3, r9, r12 corrupted
  871. * This routine must preserve:
  872. * r4, r7, r8
  873. */
  874. .align 5
  875. cache_off: mov r3, #12 @ cache_off function
  876. b call_cache_fn
  877. __armv4_mpu_cache_off:
  878. mrc p15, 0, r0, c1, c0
  879. bic r0, r0, #0x000d
  880. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  881. mov r0, #0
  882. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  883. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  884. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  885. mov pc, lr
  886. __armv3_mpu_cache_off:
  887. mrc p15, 0, r0, c1, c0
  888. bic r0, r0, #0x000d
  889. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  890. mov r0, #0
  891. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  892. mov pc, lr
  893. __armv4_mmu_cache_off:
  894. #ifdef CONFIG_MMU
  895. mrc p15, 0, r0, c1, c0
  896. bic r0, r0, #0x000d
  897. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  898. mov r0, #0
  899. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  900. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  901. #endif
  902. mov pc, lr
  903. __armv7_mmu_cache_off:
  904. mrc p15, 0, r0, c1, c0
  905. #ifdef CONFIG_MMU
  906. bic r0, r0, #0x000d
  907. #else
  908. bic r0, r0, #0x000c
  909. #endif
  910. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  911. mov r12, lr
  912. bl __armv7_mmu_cache_flush
  913. mov r0, #0
  914. #ifdef CONFIG_MMU
  915. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  916. #endif
  917. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  918. mcr p15, 0, r0, c7, c10, 4 @ DSB
  919. mcr p15, 0, r0, c7, c5, 4 @ ISB
  920. mov pc, r12
  921. /*
  922. * Clean and flush the cache to maintain consistency.
  923. *
  924. * On exit,
  925. * r1, r2, r3, r9, r10, r11, r12 corrupted
  926. * This routine must preserve:
  927. * r4, r6, r7, r8
  928. */
  929. .align 5
  930. cache_clean_flush:
  931. mov r3, #16
  932. b call_cache_fn
  933. __armv4_mpu_cache_flush:
  934. tst r4, #1
  935. movne pc, lr
  936. mov r2, #1
  937. mov r3, #0
  938. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  939. mov r1, #7 << 5 @ 8 segments
  940. 1: orr r3, r1, #63 << 26 @ 64 entries
  941. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  942. subs r3, r3, #1 << 26
  943. bcs 2b @ entries 63 to 0
  944. subs r1, r1, #1 << 5
  945. bcs 1b @ segments 7 to 0
  946. teq r2, #0
  947. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  948. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  949. mov pc, lr
  950. __fa526_cache_flush:
  951. tst r4, #1
  952. movne pc, lr
  953. mov r1, #0
  954. mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
  955. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  956. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  957. mov pc, lr
  958. __armv6_mmu_cache_flush:
  959. mov r1, #0
  960. tst r4, #1
  961. mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  962. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  963. mcreq 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. tst r4, #1
  968. bne iflush
  969. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  970. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  971. mov r10, #0
  972. beq hierarchical
  973. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  974. b iflush
  975. hierarchical:
  976. mcr p15, 0, r10, c7, c10, 5 @ DMB
  977. stmfd sp!, {r0-r7, r9-r11}
  978. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  979. ands r3, r0, #0x7000000 @ extract loc from clidr
  980. mov r3, r3, lsr #23 @ left align loc bit field
  981. beq finished @ if loc is 0, then no need to clean
  982. mov r10, #0 @ start clean at cache level 0
  983. loop1:
  984. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  985. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  986. and r1, r1, #7 @ mask of the bits for current cache only
  987. cmp r1, #2 @ see what cache we have at this level
  988. blt skip @ skip if no cache, or just i-cache
  989. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  990. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  991. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  992. and r2, r1, #7 @ extract the length of the cache lines
  993. add r2, r2, #4 @ add 4 (line length offset)
  994. ldr r4, =0x3ff
  995. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  996. clz r5, r4 @ find bit position of way size increment
  997. ldr r7, =0x7fff
  998. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  999. loop2:
  1000. mov r9, r4 @ create working copy of max way size
  1001. loop3:
  1002. ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
  1003. ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
  1004. THUMB( lsl r6, r9, r5 )
  1005. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  1006. THUMB( lsl r6, r7, r2 )
  1007. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  1008. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  1009. subs r9, r9, #1 @ decrement the way
  1010. bge loop3
  1011. subs r7, r7, #1 @ decrement the index
  1012. bge loop2
  1013. skip:
  1014. add r10, r10, #2 @ increment cache number
  1015. cmp r3, r10
  1016. bgt loop1
  1017. finished:
  1018. ldmfd sp!, {r0-r7, r9-r11}
  1019. mov r10, #0 @ swith back to cache level 0
  1020. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  1021. iflush:
  1022. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1023. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  1024. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1025. mcr p15, 0, r10, c7, c5, 4 @ ISB
  1026. mov pc, lr
  1027. __armv5tej_mmu_cache_flush:
  1028. tst r4, #1
  1029. movne pc, lr
  1030. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  1031. bne 1b
  1032. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  1033. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  1034. mov pc, lr
  1035. __armv4_mmu_cache_flush:
  1036. tst r4, #1
  1037. movne pc, lr
  1038. mov r2, #64*1024 @ default: 32K dcache size (*2)
  1039. mov r11, #32 @ default: 32 byte line size
  1040. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  1041. teq r3, r9 @ cache ID register present?
  1042. beq no_cache_id
  1043. mov r1, r3, lsr #18
  1044. and r1, r1, #7
  1045. mov r2, #1024
  1046. mov r2, r2, lsl r1 @ base dcache size *2
  1047. tst r3, #1 << 14 @ test M bit
  1048. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  1049. mov r3, r3, lsr #12
  1050. and r3, r3, #3
  1051. mov r11, #8
  1052. mov r11, r11, lsl r3 @ cache line size in bytes
  1053. no_cache_id:
  1054. mov r1, pc
  1055. bic r1, r1, #63 @ align to longest cache line
  1056. add r2, r1, r2
  1057. 1:
  1058. ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
  1059. THUMB( ldr r3, [r1] ) @ s/w flush D cache
  1060. THUMB( add r1, r1, r11 )
  1061. teq r1, r2
  1062. bne 1b
  1063. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  1064. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  1065. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1066. mov pc, lr
  1067. __armv3_mmu_cache_flush:
  1068. __armv3_mpu_cache_flush:
  1069. tst r4, #1
  1070. movne pc, lr
  1071. mov r1, #0
  1072. mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
  1073. mov pc, lr
  1074. /*
  1075. * Various debugging routines for printing hex characters and
  1076. * memory, which again must be relocatable.
  1077. */
  1078. #ifdef DEBUG
  1079. .align 2
  1080. .type phexbuf,#object
  1081. phexbuf: .space 12
  1082. .size phexbuf, . - phexbuf
  1083. @ phex corrupts {r0, r1, r2, r3}
  1084. phex: adr r3, phexbuf
  1085. mov r2, #0
  1086. strb r2, [r3, r1]
  1087. 1: subs r1, r1, #1
  1088. movmi r0, r3
  1089. bmi puts
  1090. and r2, r0, #15
  1091. mov r0, r0, lsr #4
  1092. cmp r2, #10
  1093. addge r2, r2, #7
  1094. add r2, r2, #'0'
  1095. strb r2, [r3, r1]
  1096. b 1b
  1097. @ puts corrupts {r0, r1, r2, r3}
  1098. puts: loadsp r3, r1
  1099. 1: ldrb r2, [r0], #1
  1100. teq r2, #0
  1101. moveq pc, lr
  1102. 2: writeb r2, r3
  1103. mov r1, #0x00020000
  1104. 3: subs r1, r1, #1
  1105. bne 3b
  1106. teq r2, #'\n'
  1107. moveq r2, #'\r'
  1108. beq 2b
  1109. teq r0, #0
  1110. bne 1b
  1111. mov pc, lr
  1112. @ putc corrupts {r0, r1, r2, r3}
  1113. putc:
  1114. mov r2, r0
  1115. mov r0, #0
  1116. loadsp r3, r1
  1117. b 2b
  1118. @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
  1119. memdump: mov r12, r0
  1120. mov r10, lr
  1121. mov r11, #0
  1122. 2: mov r0, r11, lsl #2
  1123. add r0, r0, r12
  1124. mov r1, #8
  1125. bl phex
  1126. mov r0, #':'
  1127. bl putc
  1128. 1: mov r0, #' '
  1129. bl putc
  1130. ldr r0, [r12, r11, lsl #2]
  1131. mov r1, #8
  1132. bl phex
  1133. and r0, r11, #7
  1134. teq r0, #3
  1135. moveq r0, #' '
  1136. bleq putc
  1137. and r0, r11, #7
  1138. add r11, r11, #1
  1139. teq r0, #7
  1140. bne 1b
  1141. mov r0, #'\n'
  1142. bl putc
  1143. cmp r11, #64
  1144. blt 2b
  1145. mov pc, r10
  1146. #endif
  1147. .ltorg
  1148. #ifdef CONFIG_ARM_VIRT_EXT
  1149. .align 5
  1150. __hyp_reentry_vectors:
  1151. W(b) . @ reset
  1152. W(b) . @ undef
  1153. W(b) . @ svc
  1154. W(b) . @ pabort
  1155. W(b) . @ dabort
  1156. W(b) __enter_kernel @ hyp
  1157. W(b) . @ irq
  1158. W(b) . @ fiq
  1159. #endif /* CONFIG_ARM_VIRT_EXT */
  1160. __enter_kernel:
  1161. mov r0, #0 @ must be 0
  1162. ARM( mov pc, r4 ) @ call kernel
  1163. THUMB( bx r4 ) @ entry point is always ARM
  1164. reloc_code_end:
  1165. .align
  1166. .section ".stack", "aw", %nobits
  1167. .L_user_stack: .space 4096
  1168. .L_user_stack_end: