head.S 32 KB

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