head.S 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  626. bl __common_mmu_cache_on
  627. mov r0, #0
  628. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  629. #endif
  630. mov pc, r12
  631. __armv7_mmu_cache_on:
  632. mov r12, lr
  633. #ifdef CONFIG_MMU
  634. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  635. tst r11, #0xf @ VMSA
  636. movne r6, #CB_BITS | 0x02 @ !XN
  637. blne __setup_mmu
  638. mov r0, #0
  639. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  640. tst r11, #0xf @ VMSA
  641. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  642. #endif
  643. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  644. bic r0, r0, #1 << 28 @ clear SCTLR.TRE
  645. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  646. orr r0, r0, #0x003c @ write buffer
  647. bic r0, r0, #2 @ A (no unaligned access fault)
  648. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  649. @ (needed for ARM1176)
  650. #ifdef CONFIG_MMU
  651. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  652. mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
  653. orrne r0, r0, #1 @ MMU enabled
  654. movne r1, #0xfffffffd @ domain 0 = client
  655. bic r6, r6, #1 << 31 @ 32-bit translation system
  656. bic r6, r6, #3 << 0 @ use only ttbr0
  657. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  658. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  659. mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
  660. #endif
  661. mcr p15, 0, r0, c7, c5, 4 @ ISB
  662. mcr p15, 0, r0, c1, c0, 0 @ load control register
  663. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  664. mov r0, #0
  665. mcr p15, 0, r0, c7, c5, 4 @ ISB
  666. mov pc, r12
  667. __fa526_cache_on:
  668. mov r12, lr
  669. mov r6, #CB_BITS | 0x12 @ U
  670. bl __setup_mmu
  671. mov r0, #0
  672. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  673. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  674. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  675. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  676. orr r0, r0, #0x1000 @ I-cache enable
  677. bl __common_mmu_cache_on
  678. mov r0, #0
  679. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  680. mov pc, r12
  681. __common_mmu_cache_on:
  682. #ifndef CONFIG_THUMB2_KERNEL
  683. #ifndef DEBUG
  684. orr r0, r0, #0x000d @ Write buffer, mmu
  685. #endif
  686. mov r1, #-1
  687. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  688. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  689. b 1f
  690. .align 5 @ cache line aligned
  691. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  692. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  693. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  694. #endif
  695. #define PROC_ENTRY_SIZE (4*5)
  696. /*
  697. * Here follow the relocatable cache support functions for the
  698. * various processors. This is a generic hook for locating an
  699. * entry and jumping to an instruction at the specified offset
  700. * from the start of the block. Please note this is all position
  701. * independent code.
  702. *
  703. * r1 = corrupted
  704. * r2 = corrupted
  705. * r3 = block offset
  706. * r9 = corrupted
  707. * r12 = corrupted
  708. */
  709. call_cache_fn: adr r12, proc_types
  710. #ifdef CONFIG_CPU_CP15
  711. mrc p15, 0, r9, c0, c0 @ get processor ID
  712. #else
  713. ldr r9, =CONFIG_PROCESSOR_ID
  714. #endif
  715. 1: ldr r1, [r12, #0] @ get value
  716. ldr r2, [r12, #4] @ get mask
  717. eor r1, r1, r9 @ (real ^ match)
  718. tst r1, r2 @ & mask
  719. ARM( addeq pc, r12, r3 ) @ call cache function
  720. THUMB( addeq r12, r3 )
  721. THUMB( moveq pc, r12 ) @ call cache function
  722. add r12, r12, #PROC_ENTRY_SIZE
  723. b 1b
  724. /*
  725. * Table for cache operations. This is basically:
  726. * - CPU ID match
  727. * - CPU ID mask
  728. * - 'cache on' method instruction
  729. * - 'cache off' method instruction
  730. * - 'cache flush' method instruction
  731. *
  732. * We match an entry using: ((real_id ^ match) & mask) == 0
  733. *
  734. * Writethrough caches generally only need 'on' and 'off'
  735. * methods. Writeback caches _must_ have the flush method
  736. * defined.
  737. */
  738. .align 2
  739. .type proc_types,#object
  740. proc_types:
  741. .word 0x41000000 @ old ARM ID
  742. .word 0xff00f000
  743. mov pc, lr
  744. THUMB( nop )
  745. mov pc, lr
  746. THUMB( nop )
  747. mov pc, lr
  748. THUMB( nop )
  749. .word 0x41007000 @ ARM7/710
  750. .word 0xfff8fe00
  751. mov pc, lr
  752. THUMB( nop )
  753. mov pc, lr
  754. THUMB( nop )
  755. mov pc, lr
  756. THUMB( nop )
  757. .word 0x41807200 @ ARM720T (writethrough)
  758. .word 0xffffff00
  759. W(b) __armv4_mmu_cache_on
  760. W(b) __armv4_mmu_cache_off
  761. mov pc, lr
  762. THUMB( nop )
  763. .word 0x41007400 @ ARM74x
  764. .word 0xff00ff00
  765. W(b) __armv3_mpu_cache_on
  766. W(b) __armv3_mpu_cache_off
  767. W(b) __armv3_mpu_cache_flush
  768. .word 0x41009400 @ ARM94x
  769. .word 0xff00ff00
  770. W(b) __armv4_mpu_cache_on
  771. W(b) __armv4_mpu_cache_off
  772. W(b) __armv4_mpu_cache_flush
  773. .word 0x41069260 @ ARM926EJ-S (v5TEJ)
  774. .word 0xff0ffff0
  775. W(b) __arm926ejs_mmu_cache_on
  776. W(b) __armv4_mmu_cache_off
  777. W(b) __armv5tej_mmu_cache_flush
  778. .word 0x00007000 @ ARM7 IDs
  779. .word 0x0000f000
  780. mov pc, lr
  781. THUMB( nop )
  782. mov pc, lr
  783. THUMB( nop )
  784. mov pc, lr
  785. THUMB( nop )
  786. @ Everything from here on will be the new ID system.
  787. .word 0x4401a100 @ sa110 / sa1100
  788. .word 0xffffffe0
  789. W(b) __armv4_mmu_cache_on
  790. W(b) __armv4_mmu_cache_off
  791. W(b) __armv4_mmu_cache_flush
  792. .word 0x6901b110 @ sa1110
  793. .word 0xfffffff0
  794. W(b) __armv4_mmu_cache_on
  795. W(b) __armv4_mmu_cache_off
  796. W(b) __armv4_mmu_cache_flush
  797. .word 0x56056900
  798. .word 0xffffff00 @ PXA9xx
  799. W(b) __armv4_mmu_cache_on
  800. W(b) __armv4_mmu_cache_off
  801. W(b) __armv4_mmu_cache_flush
  802. .word 0x56158000 @ PXA168
  803. .word 0xfffff000
  804. W(b) __armv4_mmu_cache_on
  805. W(b) __armv4_mmu_cache_off
  806. W(b) __armv5tej_mmu_cache_flush
  807. .word 0x56050000 @ Feroceon
  808. .word 0xff0f0000
  809. W(b) __armv4_mmu_cache_on
  810. W(b) __armv4_mmu_cache_off
  811. W(b) __armv5tej_mmu_cache_flush
  812. #ifdef CONFIG_CPU_FEROCEON_OLD_ID
  813. /* this conflicts with the standard ARMv5TE entry */
  814. .long 0x41009260 @ Old Feroceon
  815. .long 0xff00fff0
  816. b __armv4_mmu_cache_on
  817. b __armv4_mmu_cache_off
  818. b __armv5tej_mmu_cache_flush
  819. #endif
  820. .word 0x66015261 @ FA526
  821. .word 0xff01fff1
  822. W(b) __fa526_cache_on
  823. W(b) __armv4_mmu_cache_off
  824. W(b) __fa526_cache_flush
  825. @ These match on the architecture ID
  826. .word 0x00020000 @ ARMv4T
  827. .word 0x000f0000
  828. W(b) __armv4_mmu_cache_on
  829. W(b) __armv4_mmu_cache_off
  830. W(b) __armv4_mmu_cache_flush
  831. .word 0x00050000 @ ARMv5TE
  832. .word 0x000f0000
  833. W(b) __armv4_mmu_cache_on
  834. W(b) __armv4_mmu_cache_off
  835. W(b) __armv4_mmu_cache_flush
  836. .word 0x00060000 @ ARMv5TEJ
  837. .word 0x000f0000
  838. W(b) __armv4_mmu_cache_on
  839. W(b) __armv4_mmu_cache_off
  840. W(b) __armv5tej_mmu_cache_flush
  841. .word 0x0007b000 @ ARMv6
  842. .word 0x000ff000
  843. W(b) __armv6_mmu_cache_on
  844. W(b) __armv4_mmu_cache_off
  845. W(b) __armv6_mmu_cache_flush
  846. .word 0x000f0000 @ new CPU Id
  847. .word 0x000f0000
  848. W(b) __armv7_mmu_cache_on
  849. W(b) __armv7_mmu_cache_off
  850. W(b) __armv7_mmu_cache_flush
  851. .word 0 @ unrecognised type
  852. .word 0
  853. mov pc, lr
  854. THUMB( nop )
  855. mov pc, lr
  856. THUMB( nop )
  857. mov pc, lr
  858. THUMB( nop )
  859. .size proc_types, . - proc_types
  860. /*
  861. * If you get a "non-constant expression in ".if" statement"
  862. * error from the assembler on this line, check that you have
  863. * not accidentally written a "b" instruction where you should
  864. * have written W(b).
  865. */
  866. .if (. - proc_types) % PROC_ENTRY_SIZE != 0
  867. .error "The size of one or more proc_types entries is wrong."
  868. .endif
  869. /*
  870. * Turn off the Cache and MMU. ARMv3 does not support
  871. * reading the control register, but ARMv4 does.
  872. *
  873. * On exit,
  874. * r0, r1, r2, r3, r9, r12 corrupted
  875. * This routine must preserve:
  876. * r4, r7, r8
  877. */
  878. .align 5
  879. cache_off: mov r3, #12 @ cache_off function
  880. b call_cache_fn
  881. __armv4_mpu_cache_off:
  882. mrc p15, 0, r0, c1, c0
  883. bic r0, r0, #0x000d
  884. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  885. mov r0, #0
  886. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  887. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  888. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  889. mov pc, lr
  890. __armv3_mpu_cache_off:
  891. mrc p15, 0, r0, c1, c0
  892. bic r0, r0, #0x000d
  893. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  894. mov r0, #0
  895. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  896. mov pc, lr
  897. __armv4_mmu_cache_off:
  898. #ifdef CONFIG_MMU
  899. mrc p15, 0, r0, c1, c0
  900. bic r0, r0, #0x000d
  901. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  902. mov r0, #0
  903. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  904. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  905. #endif
  906. mov pc, lr
  907. __armv7_mmu_cache_off:
  908. mrc p15, 0, r0, c1, c0
  909. #ifdef CONFIG_MMU
  910. bic r0, r0, #0x000d
  911. #else
  912. bic r0, r0, #0x000c
  913. #endif
  914. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  915. mov r12, lr
  916. bl __armv7_mmu_cache_flush
  917. mov r0, #0
  918. #ifdef CONFIG_MMU
  919. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  920. #endif
  921. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  922. mcr p15, 0, r0, c7, c10, 4 @ DSB
  923. mcr p15, 0, r0, c7, c5, 4 @ ISB
  924. mov pc, r12
  925. /*
  926. * Clean and flush the cache to maintain consistency.
  927. *
  928. * On exit,
  929. * r1, r2, r3, r9, r10, r11, r12 corrupted
  930. * This routine must preserve:
  931. * r4, r6, r7, r8
  932. */
  933. .align 5
  934. cache_clean_flush:
  935. mov r3, #16
  936. b call_cache_fn
  937. __armv4_mpu_cache_flush:
  938. mov r2, #1
  939. mov r3, #0
  940. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  941. mov r1, #7 << 5 @ 8 segments
  942. 1: orr r3, r1, #63 << 26 @ 64 entries
  943. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  944. subs r3, r3, #1 << 26
  945. bcs 2b @ entries 63 to 0
  946. subs r1, r1, #1 << 5
  947. bcs 1b @ segments 7 to 0
  948. teq r2, #0
  949. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  950. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  951. mov pc, lr
  952. __fa526_cache_flush:
  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. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  961. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  962. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  963. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  964. mov pc, lr
  965. __armv7_mmu_cache_flush:
  966. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  967. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  968. mov r10, #0
  969. beq hierarchical
  970. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  971. b iflush
  972. hierarchical:
  973. mcr p15, 0, r10, c7, c10, 5 @ DMB
  974. stmfd sp!, {r0-r7, r9-r11}
  975. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  976. ands r3, r0, #0x7000000 @ extract loc from clidr
  977. mov r3, r3, lsr #23 @ left align loc bit field
  978. beq finished @ if loc is 0, then no need to clean
  979. mov r10, #0 @ start clean at cache level 0
  980. loop1:
  981. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  982. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  983. and r1, r1, #7 @ mask of the bits for current cache only
  984. cmp r1, #2 @ see what cache we have at this level
  985. blt skip @ skip if no cache, or just i-cache
  986. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  987. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  988. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  989. and r2, r1, #7 @ extract the length of the cache lines
  990. add r2, r2, #4 @ add 4 (line length offset)
  991. ldr r4, =0x3ff
  992. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  993. clz r5, r4 @ find bit position of way size increment
  994. ldr r7, =0x7fff
  995. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  996. loop2:
  997. mov r9, r4 @ create working copy of max way size
  998. loop3:
  999. ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
  1000. ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
  1001. THUMB( lsl r6, r9, r5 )
  1002. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  1003. THUMB( lsl r6, r7, r2 )
  1004. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  1005. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  1006. subs r9, r9, #1 @ decrement the way
  1007. bge loop3
  1008. subs r7, r7, #1 @ decrement the index
  1009. bge loop2
  1010. skip:
  1011. add r10, r10, #2 @ increment cache number
  1012. cmp r3, r10
  1013. bgt loop1
  1014. finished:
  1015. ldmfd sp!, {r0-r7, r9-r11}
  1016. mov r10, #0 @ swith back to cache level 0
  1017. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  1018. iflush:
  1019. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1020. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  1021. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1022. mcr p15, 0, r10, c7, c5, 4 @ ISB
  1023. mov pc, lr
  1024. __armv5tej_mmu_cache_flush:
  1025. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  1026. bne 1b
  1027. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  1028. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  1029. mov pc, lr
  1030. __armv4_mmu_cache_flush:
  1031. mov r2, #64*1024 @ default: 32K dcache size (*2)
  1032. mov r11, #32 @ default: 32 byte line size
  1033. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  1034. teq r3, r9 @ cache ID register present?
  1035. beq no_cache_id
  1036. mov r1, r3, lsr #18
  1037. and r1, r1, #7
  1038. mov r2, #1024
  1039. mov r2, r2, lsl r1 @ base dcache size *2
  1040. tst r3, #1 << 14 @ test M bit
  1041. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  1042. mov r3, r3, lsr #12
  1043. and r3, r3, #3
  1044. mov r11, #8
  1045. mov r11, r11, lsl r3 @ cache line size in bytes
  1046. no_cache_id:
  1047. mov r1, pc
  1048. bic r1, r1, #63 @ align to longest cache line
  1049. add r2, r1, r2
  1050. 1:
  1051. ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
  1052. THUMB( ldr r3, [r1] ) @ s/w flush D cache
  1053. THUMB( add r1, r1, r11 )
  1054. teq r1, r2
  1055. bne 1b
  1056. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  1057. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  1058. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1059. mov pc, lr
  1060. __armv3_mmu_cache_flush:
  1061. __armv3_mpu_cache_flush:
  1062. mov r1, #0
  1063. mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
  1064. mov pc, lr
  1065. /*
  1066. * Various debugging routines for printing hex characters and
  1067. * memory, which again must be relocatable.
  1068. */
  1069. #ifdef DEBUG
  1070. .align 2
  1071. .type phexbuf,#object
  1072. phexbuf: .space 12
  1073. .size phexbuf, . - phexbuf
  1074. @ phex corrupts {r0, r1, r2, r3}
  1075. phex: adr r3, phexbuf
  1076. mov r2, #0
  1077. strb r2, [r3, r1]
  1078. 1: subs r1, r1, #1
  1079. movmi r0, r3
  1080. bmi puts
  1081. and r2, r0, #15
  1082. mov r0, r0, lsr #4
  1083. cmp r2, #10
  1084. addge r2, r2, #7
  1085. add r2, r2, #'0'
  1086. strb r2, [r3, r1]
  1087. b 1b
  1088. @ puts corrupts {r0, r1, r2, r3}
  1089. puts: loadsp r3, r1
  1090. 1: ldrb r2, [r0], #1
  1091. teq r2, #0
  1092. moveq pc, lr
  1093. 2: writeb r2, r3
  1094. mov r1, #0x00020000
  1095. 3: subs r1, r1, #1
  1096. bne 3b
  1097. teq r2, #'\n'
  1098. moveq r2, #'\r'
  1099. beq 2b
  1100. teq r0, #0
  1101. bne 1b
  1102. mov pc, lr
  1103. @ putc corrupts {r0, r1, r2, r3}
  1104. putc:
  1105. mov r2, r0
  1106. mov r0, #0
  1107. loadsp r3, r1
  1108. b 2b
  1109. @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
  1110. memdump: mov r12, r0
  1111. mov r10, lr
  1112. mov r11, #0
  1113. 2: mov r0, r11, lsl #2
  1114. add r0, r0, r12
  1115. mov r1, #8
  1116. bl phex
  1117. mov r0, #':'
  1118. bl putc
  1119. 1: mov r0, #' '
  1120. bl putc
  1121. ldr r0, [r12, r11, lsl #2]
  1122. mov r1, #8
  1123. bl phex
  1124. and r0, r11, #7
  1125. teq r0, #3
  1126. moveq r0, #' '
  1127. bleq putc
  1128. and r0, r11, #7
  1129. add r11, r11, #1
  1130. teq r0, #7
  1131. bne 1b
  1132. mov r0, #'\n'
  1133. bl putc
  1134. cmp r11, #64
  1135. blt 2b
  1136. mov pc, r10
  1137. #endif
  1138. .ltorg
  1139. #ifdef CONFIG_ARM_VIRT_EXT
  1140. .align 5
  1141. __hyp_reentry_vectors:
  1142. W(b) . @ reset
  1143. W(b) . @ undef
  1144. W(b) . @ svc
  1145. W(b) . @ pabort
  1146. W(b) . @ dabort
  1147. W(b) __enter_kernel @ hyp
  1148. W(b) . @ irq
  1149. W(b) . @ fiq
  1150. #endif /* CONFIG_ARM_VIRT_EXT */
  1151. __enter_kernel:
  1152. mov r0, #0 @ must be 0
  1153. ARM( mov pc, r4 ) @ call kernel
  1154. THUMB( bx r4 ) @ entry point is always ARM
  1155. reloc_code_end:
  1156. .align
  1157. .section ".stack", "aw", %nobits
  1158. .L_user_stack: .space 4096
  1159. .L_user_stack_end: