head.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. /*
  13. * Debugging stuff
  14. *
  15. * Note that these macros must not contain any code which is not
  16. * 100% relocatable. Any attempt to do so will result in a crash.
  17. * Please select one of the following when turning on debugging.
  18. */
  19. #ifdef DEBUG
  20. #if defined(CONFIG_DEBUG_ICEDCC)
  21. .macro loadsp, rb
  22. .endm
  23. .macro writeb, ch, rb
  24. mcr p14, 0, \ch, c0, c1, 0
  25. .endm
  26. #else
  27. #include <asm/arch/debug-macro.S>
  28. .macro writeb, ch, rb
  29. senduart \ch, \rb
  30. .endm
  31. #if defined(CONFIG_ARCH_SA1100)
  32. .macro loadsp, rb
  33. mov \rb, #0x80000000 @ physical base address
  34. #ifdef CONFIG_DEBUG_LL_SER3
  35. add \rb, \rb, #0x00050000 @ Ser3
  36. #else
  37. add \rb, \rb, #0x00010000 @ Ser1
  38. #endif
  39. .endm
  40. #elif defined(CONFIG_ARCH_S3C2410)
  41. .macro loadsp, rb
  42. mov \rb, #0x50000000
  43. add \rb, \rb, #0x4000 * CONFIG_S3C2410_LOWLEVEL_UART_PORT
  44. .endm
  45. #else
  46. .macro loadsp, rb
  47. addruart \rb
  48. .endm
  49. #endif
  50. #endif
  51. #endif
  52. .macro kputc,val
  53. mov r0, \val
  54. bl putc
  55. .endm
  56. .macro kphex,val,len
  57. mov r0, \val
  58. mov r1, #\len
  59. bl phex
  60. .endm
  61. .macro debug_reloc_start
  62. #ifdef DEBUG
  63. kputc #'\n'
  64. kphex r6, 8 /* processor id */
  65. kputc #':'
  66. kphex r7, 8 /* architecture id */
  67. kputc #':'
  68. mrc p15, 0, r0, c1, c0
  69. kphex r0, 8 /* control reg */
  70. kputc #'\n'
  71. kphex r5, 8 /* decompressed kernel start */
  72. kputc #'-'
  73. kphex r9, 8 /* decompressed kernel end */
  74. kputc #'>'
  75. kphex r4, 8 /* kernel execution address */
  76. kputc #'\n'
  77. #endif
  78. .endm
  79. .macro debug_reloc_end
  80. #ifdef DEBUG
  81. kphex r5, 8 /* end of kernel */
  82. kputc #'\n'
  83. mov r0, r4
  84. bl memdump /* dump 256 bytes at start of kernel */
  85. #endif
  86. .endm
  87. .section ".start", #alloc, #execinstr
  88. /*
  89. * sort out different calling conventions
  90. */
  91. .align
  92. start:
  93. .type start,#function
  94. .rept 8
  95. mov r0, r0
  96. .endr
  97. b 1f
  98. .word 0x016f2818 @ Magic numbers to help the loader
  99. .word start @ absolute load/run zImage address
  100. .word _edata @ zImage end address
  101. 1: mov r7, r1 @ save architecture ID
  102. mov r8, r2 @ save atags pointer
  103. #ifndef __ARM_ARCH_2__
  104. /*
  105. * Booting from Angel - need to enter SVC mode and disable
  106. * FIQs/IRQs (numeric definitions from angel arm.h source).
  107. * We only do this if we were in user mode on entry.
  108. */
  109. mrs r2, cpsr @ get current mode
  110. tst r2, #3 @ not user?
  111. bne not_angel
  112. mov r0, #0x17 @ angel_SWIreason_EnterSVC
  113. swi 0x123456 @ angel_SWI_ARM
  114. not_angel:
  115. mrs r2, cpsr @ turn off interrupts to
  116. orr r2, r2, #0xc0 @ prevent angel from running
  117. msr cpsr_c, r2
  118. #else
  119. teqp pc, #0x0c000003 @ turn off interrupts
  120. #endif
  121. /*
  122. * Note that some cache flushing and other stuff may
  123. * be needed here - is there an Angel SWI call for this?
  124. */
  125. /*
  126. * some architecture specific code can be inserted
  127. * by the linker here, but it should preserve r7, r8, and r9.
  128. */
  129. .text
  130. adr r0, LC0
  131. ldmia r0, {r1, r2, r3, r4, r5, r6, ip, sp}
  132. subs r0, r0, r1 @ calculate the delta offset
  133. @ if delta is zero, we are
  134. beq not_relocated @ running at the address we
  135. @ were linked at.
  136. /*
  137. * We're running at a different address. We need to fix
  138. * up various pointers:
  139. * r5 - zImage base address
  140. * r6 - GOT start
  141. * ip - GOT end
  142. */
  143. add r5, r5, r0
  144. add r6, r6, r0
  145. add ip, ip, r0
  146. #ifndef CONFIG_ZBOOT_ROM
  147. /*
  148. * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
  149. * we need to fix up pointers into the BSS region.
  150. * r2 - BSS start
  151. * r3 - BSS end
  152. * sp - stack pointer
  153. */
  154. add r2, r2, r0
  155. add r3, r3, r0
  156. add sp, sp, r0
  157. /*
  158. * Relocate all entries in the GOT table.
  159. */
  160. 1: ldr r1, [r6, #0] @ relocate entries in the GOT
  161. add r1, r1, r0 @ table. This fixes up the
  162. str r1, [r6], #4 @ C references.
  163. cmp r6, ip
  164. blo 1b
  165. #else
  166. /*
  167. * Relocate entries in the GOT table. We only relocate
  168. * the entries that are outside the (relocated) BSS region.
  169. */
  170. 1: ldr r1, [r6, #0] @ relocate entries in the GOT
  171. cmp r1, r2 @ entry < bss_start ||
  172. cmphs r3, r1 @ _end < entry
  173. addlo r1, r1, r0 @ table. This fixes up the
  174. str r1, [r6], #4 @ C references.
  175. cmp r6, ip
  176. blo 1b
  177. #endif
  178. not_relocated: mov r0, #0
  179. 1: str r0, [r2], #4 @ clear bss
  180. str r0, [r2], #4
  181. str r0, [r2], #4
  182. str r0, [r2], #4
  183. cmp r2, r3
  184. blo 1b
  185. /*
  186. * The C runtime environment should now be setup
  187. * sufficiently. Turn the cache on, set up some
  188. * pointers, and start decompressing.
  189. */
  190. bl cache_on
  191. mov r1, sp @ malloc space above stack
  192. add r2, sp, #0x10000 @ 64k max
  193. /*
  194. * Check to see if we will overwrite ourselves.
  195. * r4 = final kernel address
  196. * r5 = start of this image
  197. * r2 = end of malloc space (and therefore this image)
  198. * We basically want:
  199. * r4 >= r2 -> OK
  200. * r4 + image length <= r5 -> OK
  201. */
  202. cmp r4, r2
  203. bhs wont_overwrite
  204. add r0, r4, #4096*1024 @ 4MB largest kernel size
  205. cmp r0, r5
  206. bls wont_overwrite
  207. mov r5, r2 @ decompress after malloc space
  208. mov r0, r5
  209. mov r3, r7
  210. bl decompress_kernel
  211. add r0, r0, #127
  212. bic r0, r0, #127 @ align the kernel length
  213. /*
  214. * r0 = decompressed kernel length
  215. * r1-r3 = unused
  216. * r4 = kernel execution address
  217. * r5 = decompressed kernel start
  218. * r6 = processor ID
  219. * r7 = architecture ID
  220. * r8 = atags pointer
  221. * r9-r14 = corrupted
  222. */
  223. add r1, r5, r0 @ end of decompressed kernel
  224. adr r2, reloc_start
  225. ldr r3, LC1
  226. add r3, r2, r3
  227. 1: ldmia r2!, {r9 - r14} @ copy relocation code
  228. stmia r1!, {r9 - r14}
  229. ldmia r2!, {r9 - r14}
  230. stmia r1!, {r9 - r14}
  231. cmp r2, r3
  232. blo 1b
  233. bl cache_clean_flush
  234. add pc, r5, r0 @ call relocation code
  235. /*
  236. * We're not in danger of overwriting ourselves. Do this the simple way.
  237. *
  238. * r4 = kernel execution address
  239. * r7 = architecture ID
  240. */
  241. wont_overwrite: mov r0, r4
  242. mov r3, r7
  243. bl decompress_kernel
  244. b call_kernel
  245. .type LC0, #object
  246. LC0: .word LC0 @ r1
  247. .word __bss_start @ r2
  248. .word _end @ r3
  249. .word zreladdr @ r4
  250. .word _start @ r5
  251. .word _got_start @ r6
  252. .word _got_end @ ip
  253. .word user_stack+4096 @ sp
  254. LC1: .word reloc_end - reloc_start
  255. .size LC0, . - LC0
  256. #ifdef CONFIG_ARCH_RPC
  257. .globl params
  258. params: ldr r0, =params_phys
  259. mov pc, lr
  260. .ltorg
  261. .align
  262. #endif
  263. /*
  264. * Turn on the cache. We need to setup some page tables so that we
  265. * can have both the I and D caches on.
  266. *
  267. * We place the page tables 16k down from the kernel execution address,
  268. * and we hope that nothing else is using it. If we're using it, we
  269. * will go pop!
  270. *
  271. * On entry,
  272. * r4 = kernel execution address
  273. * r6 = processor ID
  274. * r7 = architecture number
  275. * r8 = atags pointer
  276. * r9 = run-time address of "start" (???)
  277. * On exit,
  278. * r1, r2, r3, r9, r10, r12 corrupted
  279. * This routine must preserve:
  280. * r4, r5, r6, r7, r8
  281. */
  282. .align 5
  283. cache_on: mov r3, #8 @ cache_on function
  284. b call_cache_fn
  285. /*
  286. * Initialize the highest priority protection region, PR7
  287. * to cover all 32bit address and cacheable and bufferable.
  288. */
  289. __armv4_mpu_cache_on:
  290. mov r0, #0x3f @ 4G, the whole
  291. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  292. mcr p15, 0, r0, c6, c7, 1
  293. mov r0, #0x80 @ PR7
  294. mcr p15, 0, r0, c2, c0, 0 @ D-cache on
  295. mcr p15, 0, r0, c2, c0, 1 @ I-cache on
  296. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  297. mov r0, #0xc000
  298. mcr p15, 0, r0, c5, c0, 1 @ I-access permission
  299. mcr p15, 0, r0, c5, c0, 0 @ D-access permission
  300. mov r0, #0
  301. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  302. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  303. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  304. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  305. @ ...I .... ..D. WC.M
  306. orr r0, r0, #0x002d @ .... .... ..1. 11.1
  307. orr r0, r0, #0x1000 @ ...1 .... .... ....
  308. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  309. mov r0, #0
  310. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  311. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  312. mov pc, lr
  313. __armv3_mpu_cache_on:
  314. mov r0, #0x3f @ 4G, the whole
  315. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  316. mov r0, #0x80 @ PR7
  317. mcr p15, 0, r0, c2, c0, 0 @ cache on
  318. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  319. mov r0, #0xc000
  320. mcr p15, 0, r0, c5, c0, 0 @ access permission
  321. mov r0, #0
  322. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  323. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  324. @ .... .... .... WC.M
  325. orr r0, r0, #0x000d @ .... .... .... 11.1
  326. mov r0, #0
  327. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  328. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  329. mov pc, lr
  330. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  331. bic r3, r3, #0xff @ Align the pointer
  332. bic r3, r3, #0x3f00
  333. /*
  334. * Initialise the page tables, turning on the cacheable and bufferable
  335. * bits for the RAM area only.
  336. */
  337. mov r0, r3
  338. mov r9, r0, lsr #18
  339. mov r9, r9, lsl #18 @ start of RAM
  340. add r10, r9, #0x10000000 @ a reasonable RAM size
  341. mov r1, #0x12
  342. orr r1, r1, #3 << 10
  343. add r2, r3, #16384
  344. 1: cmp r1, r9 @ if virt > start of RAM
  345. orrhs r1, r1, #0x0c @ set cacheable, bufferable
  346. cmp r1, r10 @ if virt > end of RAM
  347. bichs r1, r1, #0x0c @ clear cacheable, bufferable
  348. str r1, [r0], #4 @ 1:1 mapping
  349. add r1, r1, #1048576
  350. teq r0, r2
  351. bne 1b
  352. /*
  353. * If ever we are running from Flash, then we surely want the cache
  354. * to be enabled also for our execution instance... We map 2MB of it
  355. * so there is no map overlap problem for up to 1 MB compressed kernel.
  356. * If the execution is in RAM then we would only be duplicating the above.
  357. */
  358. mov r1, #0x1e
  359. orr r1, r1, #3 << 10
  360. mov r2, pc, lsr #20
  361. orr r1, r1, r2, lsl #20
  362. add r0, r3, r2, lsl #2
  363. str r1, [r0], #4
  364. add r1, r1, #1048576
  365. str r1, [r0]
  366. mov pc, lr
  367. __armv4_mmu_cache_on:
  368. mov r12, lr
  369. bl __setup_mmu
  370. mov r0, #0
  371. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  372. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  373. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  374. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  375. orr r0, r0, #0x0030
  376. bl __common_mmu_cache_on
  377. mov r0, #0
  378. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  379. mov pc, r12
  380. __arm6_mmu_cache_on:
  381. mov r12, lr
  382. bl __setup_mmu
  383. mov r0, #0
  384. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  385. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  386. mov r0, #0x30
  387. bl __common_mmu_cache_on
  388. mov r0, #0
  389. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  390. mov pc, r12
  391. __common_mmu_cache_on:
  392. #ifndef DEBUG
  393. orr r0, r0, #0x000d @ Write buffer, mmu
  394. #endif
  395. mov r1, #-1
  396. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  397. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  398. b 1f
  399. .align 5 @ cache line aligned
  400. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  401. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  402. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  403. /*
  404. * All code following this line is relocatable. It is relocated by
  405. * the above code to the end of the decompressed kernel image and
  406. * executed there. During this time, we have no stacks.
  407. *
  408. * r0 = decompressed kernel length
  409. * r1-r3 = unused
  410. * r4 = kernel execution address
  411. * r5 = decompressed kernel start
  412. * r6 = processor ID
  413. * r7 = architecture ID
  414. * r8 = atags pointer
  415. * r9-r14 = corrupted
  416. */
  417. .align 5
  418. reloc_start: add r9, r5, r0
  419. debug_reloc_start
  420. mov r1, r4
  421. 1:
  422. .rept 4
  423. ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel
  424. stmia r1!, {r0, r2, r3, r10 - r14}
  425. .endr
  426. cmp r5, r9
  427. blo 1b
  428. debug_reloc_end
  429. call_kernel: bl cache_clean_flush
  430. bl cache_off
  431. mov r0, #0 @ must be zero
  432. mov r1, r7 @ restore architecture number
  433. mov r2, r8 @ restore atags pointer
  434. mov pc, r4 @ call kernel
  435. /*
  436. * Here follow the relocatable cache support functions for the
  437. * various processors. This is a generic hook for locating an
  438. * entry and jumping to an instruction at the specified offset
  439. * from the start of the block. Please note this is all position
  440. * independent code.
  441. *
  442. * r1 = corrupted
  443. * r2 = corrupted
  444. * r3 = block offset
  445. * r6 = corrupted
  446. * r12 = corrupted
  447. */
  448. call_cache_fn: adr r12, proc_types
  449. mrc p15, 0, r6, c0, c0 @ get processor ID
  450. 1: ldr r1, [r12, #0] @ get value
  451. ldr r2, [r12, #4] @ get mask
  452. eor r1, r1, r6 @ (real ^ match)
  453. tst r1, r2 @ & mask
  454. addeq pc, r12, r3 @ call cache function
  455. add r12, r12, #4*5
  456. b 1b
  457. /*
  458. * Table for cache operations. This is basically:
  459. * - CPU ID match
  460. * - CPU ID mask
  461. * - 'cache on' method instruction
  462. * - 'cache off' method instruction
  463. * - 'cache flush' method instruction
  464. *
  465. * We match an entry using: ((real_id ^ match) & mask) == 0
  466. *
  467. * Writethrough caches generally only need 'on' and 'off'
  468. * methods. Writeback caches _must_ have the flush method
  469. * defined.
  470. */
  471. .type proc_types,#object
  472. proc_types:
  473. .word 0x41560600 @ ARM6/610
  474. .word 0xffffffe0
  475. b __arm6_mmu_cache_off @ works, but slow
  476. b __arm6_mmu_cache_off
  477. mov pc, lr
  478. @ b __arm6_mmu_cache_on @ untested
  479. @ b __arm6_mmu_cache_off
  480. @ b __armv3_mmu_cache_flush
  481. .word 0x00000000 @ old ARM ID
  482. .word 0x0000f000
  483. mov pc, lr
  484. mov pc, lr
  485. mov pc, lr
  486. .word 0x41007000 @ ARM7/710
  487. .word 0xfff8fe00
  488. b __arm7_mmu_cache_off
  489. b __arm7_mmu_cache_off
  490. mov pc, lr
  491. .word 0x41807200 @ ARM720T (writethrough)
  492. .word 0xffffff00
  493. b __armv4_mmu_cache_on
  494. b __armv4_mmu_cache_off
  495. mov pc, lr
  496. .word 0x41007400 @ ARM74x
  497. .word 0xff00ff00
  498. b __armv3_mpu_cache_on
  499. b __armv3_mpu_cache_off
  500. b __armv3_mpu_cache_flush
  501. .word 0x41009400 @ ARM94x
  502. .word 0xff00ff00
  503. b __armv4_mpu_cache_on
  504. b __armv4_mpu_cache_off
  505. b __armv4_mpu_cache_flush
  506. .word 0x00007000 @ ARM7 IDs
  507. .word 0x0000f000
  508. mov pc, lr
  509. mov pc, lr
  510. mov pc, lr
  511. @ Everything from here on will be the new ID system.
  512. .word 0x4401a100 @ sa110 / sa1100
  513. .word 0xffffffe0
  514. b __armv4_mmu_cache_on
  515. b __armv4_mmu_cache_off
  516. b __armv4_mmu_cache_flush
  517. .word 0x6901b110 @ sa1110
  518. .word 0xfffffff0
  519. b __armv4_mmu_cache_on
  520. b __armv4_mmu_cache_off
  521. b __armv4_mmu_cache_flush
  522. @ These match on the architecture ID
  523. .word 0x00020000 @ ARMv4T
  524. .word 0x000f0000
  525. b __armv4_mmu_cache_on
  526. b __armv4_mmu_cache_off
  527. b __armv4_mmu_cache_flush
  528. .word 0x00050000 @ ARMv5TE
  529. .word 0x000f0000
  530. b __armv4_mmu_cache_on
  531. b __armv4_mmu_cache_off
  532. b __armv4_mmu_cache_flush
  533. .word 0x00060000 @ ARMv5TEJ
  534. .word 0x000f0000
  535. b __armv4_mmu_cache_on
  536. b __armv4_mmu_cache_off
  537. b __armv4_mmu_cache_flush
  538. .word 0x0007b000 @ ARMv6
  539. .word 0x0007f000
  540. b __armv4_mmu_cache_on
  541. b __armv4_mmu_cache_off
  542. b __armv6_mmu_cache_flush
  543. .word 0 @ unrecognised type
  544. .word 0
  545. mov pc, lr
  546. mov pc, lr
  547. mov pc, lr
  548. .size proc_types, . - proc_types
  549. /*
  550. * Turn off the Cache and MMU. ARMv3 does not support
  551. * reading the control register, but ARMv4 does.
  552. *
  553. * On entry, r6 = processor ID
  554. * On exit, r0, r1, r2, r3, r12 corrupted
  555. * This routine must preserve: r4, r6, r7
  556. */
  557. .align 5
  558. cache_off: mov r3, #12 @ cache_off function
  559. b call_cache_fn
  560. __armv4_mpu_cache_off:
  561. mrc p15, 0, r0, c1, c0
  562. bic r0, r0, #0x000d
  563. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  564. mov r0, #0
  565. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  566. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  567. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  568. mov pc, lr
  569. __armv3_mpu_cache_off:
  570. mrc p15, 0, r0, c1, c0
  571. bic r0, r0, #0x000d
  572. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  573. mov r0, #0
  574. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  575. mov pc, lr
  576. __armv4_mmu_cache_off:
  577. mrc p15, 0, r0, c1, c0
  578. bic r0, r0, #0x000d
  579. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  580. mov r0, #0
  581. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  582. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  583. mov pc, lr
  584. __arm6_mmu_cache_off:
  585. mov r0, #0x00000030 @ ARM6 control reg.
  586. b __armv3_mmu_cache_off
  587. __arm7_mmu_cache_off:
  588. mov r0, #0x00000070 @ ARM7 control reg.
  589. b __armv3_mmu_cache_off
  590. __armv3_mmu_cache_off:
  591. mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
  592. mov r0, #0
  593. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  594. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  595. mov pc, lr
  596. /*
  597. * Clean and flush the cache to maintain consistency.
  598. *
  599. * On entry,
  600. * r6 = processor ID
  601. * On exit,
  602. * r1, r2, r3, r11, r12 corrupted
  603. * This routine must preserve:
  604. * r0, r4, r5, r6, r7
  605. */
  606. .align 5
  607. cache_clean_flush:
  608. mov r3, #16
  609. b call_cache_fn
  610. __armv4_mpu_cache_flush:
  611. mov r2, #1
  612. mov r3, #0
  613. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  614. mov r1, #7 << 5 @ 8 segments
  615. 1: orr r3, r1, #63 << 26 @ 64 entries
  616. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  617. subs r3, r3, #1 << 26
  618. bcs 2b @ entries 63 to 0
  619. subs r1, r1, #1 << 5
  620. bcs 1b @ segments 7 to 0
  621. teq r2, #0
  622. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  623. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  624. mov pc, lr
  625. __armv6_mmu_cache_flush:
  626. mov r1, #0
  627. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  628. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  629. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  630. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  631. mov pc, lr
  632. __armv4_mmu_cache_flush:
  633. mov r2, #64*1024 @ default: 32K dcache size (*2)
  634. mov r11, #32 @ default: 32 byte line size
  635. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  636. teq r3, r6 @ cache ID register present?
  637. beq no_cache_id
  638. mov r1, r3, lsr #18
  639. and r1, r1, #7
  640. mov r2, #1024
  641. mov r2, r2, lsl r1 @ base dcache size *2
  642. tst r3, #1 << 14 @ test M bit
  643. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  644. mov r3, r3, lsr #12
  645. and r3, r3, #3
  646. mov r11, #8
  647. mov r11, r11, lsl r3 @ cache line size in bytes
  648. no_cache_id:
  649. bic r1, pc, #63 @ align to longest cache line
  650. add r2, r1, r2
  651. 1: ldr r3, [r1], r11 @ s/w flush D cache
  652. teq r1, r2
  653. bne 1b
  654. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  655. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  656. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  657. mov pc, lr
  658. __armv3_mmu_cache_flush:
  659. __armv3_mpu_cache_flush:
  660. mov r1, #0
  661. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  662. mov pc, lr
  663. /*
  664. * Various debugging routines for printing hex characters and
  665. * memory, which again must be relocatable.
  666. */
  667. #ifdef DEBUG
  668. .type phexbuf,#object
  669. phexbuf: .space 12
  670. .size phexbuf, . - phexbuf
  671. phex: adr r3, phexbuf
  672. mov r2, #0
  673. strb r2, [r3, r1]
  674. 1: subs r1, r1, #1
  675. movmi r0, r3
  676. bmi puts
  677. and r2, r0, #15
  678. mov r0, r0, lsr #4
  679. cmp r2, #10
  680. addge r2, r2, #7
  681. add r2, r2, #'0'
  682. strb r2, [r3, r1]
  683. b 1b
  684. puts: loadsp r3
  685. 1: ldrb r2, [r0], #1
  686. teq r2, #0
  687. moveq pc, lr
  688. 2: writeb r2, r3
  689. mov r1, #0x00020000
  690. 3: subs r1, r1, #1
  691. bne 3b
  692. teq r2, #'\n'
  693. moveq r2, #'\r'
  694. beq 2b
  695. teq r0, #0
  696. bne 1b
  697. mov pc, lr
  698. putc:
  699. mov r2, r0
  700. mov r0, #0
  701. loadsp r3
  702. b 2b
  703. memdump: mov r12, r0
  704. mov r10, lr
  705. mov r11, #0
  706. 2: mov r0, r11, lsl #2
  707. add r0, r0, r12
  708. mov r1, #8
  709. bl phex
  710. mov r0, #':'
  711. bl putc
  712. 1: mov r0, #' '
  713. bl putc
  714. ldr r0, [r12, r11, lsl #2]
  715. mov r1, #8
  716. bl phex
  717. and r0, r11, #7
  718. teq r0, #3
  719. moveq r0, #' '
  720. bleq putc
  721. and r0, r11, #7
  722. add r11, r11, #1
  723. teq r0, #7
  724. bne 1b
  725. mov r0, #'\n'
  726. bl putc
  727. cmp r11, #64
  728. blt 2b
  729. mov pc, r10
  730. #endif
  731. reloc_end:
  732. .align
  733. .section ".stack", "w"
  734. user_stack: .space 4096