head.S 19 KB

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