head.S 19 KB

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