head.S 19 KB

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