head.S 32 KB

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