head.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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. b 1f
  406. .align 5 @ cache line aligned
  407. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  408. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  409. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  410. /*
  411. * All code following this line is relocatable. It is relocated by
  412. * the above code to the end of the decompressed kernel image and
  413. * executed there. During this time, we have no stacks.
  414. *
  415. * r0 = decompressed kernel length
  416. * r1-r3 = unused
  417. * r4 = kernel execution address
  418. * r5 = decompressed kernel start
  419. * r6 = processor ID
  420. * r7 = architecture ID
  421. * r8 = atags pointer
  422. * r9-r14 = corrupted
  423. */
  424. .align 5
  425. reloc_start: add r9, r5, r0
  426. debug_reloc_start
  427. mov r1, r4
  428. 1:
  429. .rept 4
  430. ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel
  431. stmia r1!, {r0, r2, r3, r10 - r14}
  432. .endr
  433. cmp r5, r9
  434. blo 1b
  435. debug_reloc_end
  436. call_kernel: bl cache_clean_flush
  437. bl cache_off
  438. mov r0, #0 @ must be zero
  439. mov r1, r7 @ restore architecture number
  440. mov r2, r8 @ restore atags pointer
  441. mov pc, r4 @ call kernel
  442. /*
  443. * Here follow the relocatable cache support functions for the
  444. * various processors. This is a generic hook for locating an
  445. * entry and jumping to an instruction at the specified offset
  446. * from the start of the block. Please note this is all position
  447. * independent code.
  448. *
  449. * r1 = corrupted
  450. * r2 = corrupted
  451. * r3 = block offset
  452. * r6 = corrupted
  453. * r12 = corrupted
  454. */
  455. call_cache_fn: adr r12, proc_types
  456. mrc p15, 0, r6, c0, c0 @ get processor ID
  457. 1: ldr r1, [r12, #0] @ get value
  458. ldr r2, [r12, #4] @ get mask
  459. eor r1, r1, r6 @ (real ^ match)
  460. tst r1, r2 @ & mask
  461. addeq pc, r12, r3 @ call cache function
  462. add r12, r12, #4*5
  463. b 1b
  464. /*
  465. * Table for cache operations. This is basically:
  466. * - CPU ID match
  467. * - CPU ID mask
  468. * - 'cache on' method instruction
  469. * - 'cache off' method instruction
  470. * - 'cache flush' method instruction
  471. *
  472. * We match an entry using: ((real_id ^ match) & mask) == 0
  473. *
  474. * Writethrough caches generally only need 'on' and 'off'
  475. * methods. Writeback caches _must_ have the flush method
  476. * defined.
  477. */
  478. .type proc_types,#object
  479. proc_types:
  480. .word 0x41560600 @ ARM6/610
  481. .word 0xffffffe0
  482. b __arm6_mmu_cache_off @ works, but slow
  483. b __arm6_mmu_cache_off
  484. mov pc, lr
  485. @ b __arm6_mmu_cache_on @ untested
  486. @ b __arm6_mmu_cache_off
  487. @ b __armv3_mmu_cache_flush
  488. .word 0x00000000 @ old ARM ID
  489. .word 0x0000f000
  490. mov pc, lr
  491. mov pc, lr
  492. mov pc, lr
  493. .word 0x41007000 @ ARM7/710
  494. .word 0xfff8fe00
  495. b __arm7_mmu_cache_off
  496. b __arm7_mmu_cache_off
  497. mov pc, lr
  498. .word 0x41807200 @ ARM720T (writethrough)
  499. .word 0xffffff00
  500. b __armv4_mmu_cache_on
  501. b __armv4_mmu_cache_off
  502. mov pc, lr
  503. .word 0x41007400 @ ARM74x
  504. .word 0xff00ff00
  505. b __armv3_mpu_cache_on
  506. b __armv3_mpu_cache_off
  507. b __armv3_mpu_cache_flush
  508. .word 0x41009400 @ ARM94x
  509. .word 0xff00ff00
  510. b __armv4_mpu_cache_on
  511. b __armv4_mpu_cache_off
  512. b __armv4_mpu_cache_flush
  513. .word 0x00007000 @ ARM7 IDs
  514. .word 0x0000f000
  515. mov pc, lr
  516. mov pc, lr
  517. mov pc, lr
  518. @ Everything from here on will be the new ID system.
  519. .word 0x4401a100 @ sa110 / sa1100
  520. .word 0xffffffe0
  521. b __armv4_mmu_cache_on
  522. b __armv4_mmu_cache_off
  523. b __armv4_mmu_cache_flush
  524. .word 0x6901b110 @ sa1110
  525. .word 0xfffffff0
  526. b __armv4_mmu_cache_on
  527. b __armv4_mmu_cache_off
  528. b __armv4_mmu_cache_flush
  529. @ These match on the architecture ID
  530. .word 0x00020000 @ ARMv4T
  531. .word 0x000f0000
  532. b __armv4_mmu_cache_on
  533. b __armv4_mmu_cache_off
  534. b __armv4_mmu_cache_flush
  535. .word 0x00050000 @ ARMv5TE
  536. .word 0x000f0000
  537. b __armv4_mmu_cache_on
  538. b __armv4_mmu_cache_off
  539. b __armv4_mmu_cache_flush
  540. .word 0x00060000 @ ARMv5TEJ
  541. .word 0x000f0000
  542. b __armv4_mmu_cache_on
  543. b __armv4_mmu_cache_off
  544. b __armv4_mmu_cache_flush
  545. .word 0x0007b000 @ ARMv6
  546. .word 0x0007f000
  547. b __armv4_mmu_cache_on
  548. b __armv4_mmu_cache_off
  549. b __armv6_mmu_cache_flush
  550. .word 0 @ unrecognised type
  551. .word 0
  552. mov pc, lr
  553. mov pc, lr
  554. mov pc, lr
  555. .size proc_types, . - proc_types
  556. /*
  557. * Turn off the Cache and MMU. ARMv3 does not support
  558. * reading the control register, but ARMv4 does.
  559. *
  560. * On entry, r6 = processor ID
  561. * On exit, r0, r1, r2, r3, r12 corrupted
  562. * This routine must preserve: r4, r6, r7
  563. */
  564. .align 5
  565. cache_off: mov r3, #12 @ cache_off function
  566. b call_cache_fn
  567. __armv4_mpu_cache_off:
  568. mrc p15, 0, r0, c1, c0
  569. bic r0, r0, #0x000d
  570. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  571. mov r0, #0
  572. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  573. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  574. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  575. mov pc, lr
  576. __armv3_mpu_cache_off:
  577. mrc p15, 0, r0, c1, c0
  578. bic r0, r0, #0x000d
  579. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  580. mov r0, #0
  581. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  582. mov pc, lr
  583. __armv4_mmu_cache_off:
  584. mrc p15, 0, r0, c1, c0
  585. bic r0, r0, #0x000d
  586. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  587. mov r0, #0
  588. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  589. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  590. mov pc, lr
  591. __arm6_mmu_cache_off:
  592. mov r0, #0x00000030 @ ARM6 control reg.
  593. b __armv3_mmu_cache_off
  594. __arm7_mmu_cache_off:
  595. mov r0, #0x00000070 @ ARM7 control reg.
  596. b __armv3_mmu_cache_off
  597. __armv3_mmu_cache_off:
  598. mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
  599. mov r0, #0
  600. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  601. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  602. mov pc, lr
  603. /*
  604. * Clean and flush the cache to maintain consistency.
  605. *
  606. * On entry,
  607. * r6 = processor ID
  608. * On exit,
  609. * r1, r2, r3, r11, r12 corrupted
  610. * This routine must preserve:
  611. * r0, r4, r5, r6, r7
  612. */
  613. .align 5
  614. cache_clean_flush:
  615. mov r3, #16
  616. b call_cache_fn
  617. __armv4_mpu_cache_flush:
  618. mov r2, #1
  619. mov r3, #0
  620. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  621. mov r1, #7 << 5 @ 8 segments
  622. 1: orr r3, r1, #63 << 26 @ 64 entries
  623. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  624. subs r3, r3, #1 << 26
  625. bcs 2b @ entries 63 to 0
  626. subs r1, r1, #1 << 5
  627. bcs 1b @ segments 7 to 0
  628. teq r2, #0
  629. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  630. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  631. mov pc, lr
  632. __armv6_mmu_cache_flush:
  633. mov r1, #0
  634. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  635. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  636. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  637. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  638. mov pc, lr
  639. __armv4_mmu_cache_flush:
  640. mov r2, #64*1024 @ default: 32K dcache size (*2)
  641. mov r11, #32 @ default: 32 byte line size
  642. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  643. teq r3, r6 @ cache ID register present?
  644. beq no_cache_id
  645. mov r1, r3, lsr #18
  646. and r1, r1, #7
  647. mov r2, #1024
  648. mov r2, r2, lsl r1 @ base dcache size *2
  649. tst r3, #1 << 14 @ test M bit
  650. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  651. mov r3, r3, lsr #12
  652. and r3, r3, #3
  653. mov r11, #8
  654. mov r11, r11, lsl r3 @ cache line size in bytes
  655. no_cache_id:
  656. bic r1, pc, #63 @ align to longest cache line
  657. add r2, r1, r2
  658. 1: ldr r3, [r1], r11 @ s/w flush D cache
  659. teq r1, r2
  660. bne 1b
  661. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  662. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  663. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  664. mov pc, lr
  665. __armv3_mmu_cache_flush:
  666. __armv3_mpu_cache_flush:
  667. mov r1, #0
  668. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  669. mov pc, lr
  670. /*
  671. * Various debugging routines for printing hex characters and
  672. * memory, which again must be relocatable.
  673. */
  674. #ifdef DEBUG
  675. .type phexbuf,#object
  676. phexbuf: .space 12
  677. .size phexbuf, . - phexbuf
  678. phex: adr r3, phexbuf
  679. mov r2, #0
  680. strb r2, [r3, r1]
  681. 1: subs r1, r1, #1
  682. movmi r0, r3
  683. bmi puts
  684. and r2, r0, #15
  685. mov r0, r0, lsr #4
  686. cmp r2, #10
  687. addge r2, r2, #7
  688. add r2, r2, #'0'
  689. strb r2, [r3, r1]
  690. b 1b
  691. puts: loadsp r3
  692. 1: ldrb r2, [r0], #1
  693. teq r2, #0
  694. moveq pc, lr
  695. 2: writeb r2, r3
  696. mov r1, #0x00020000
  697. 3: subs r1, r1, #1
  698. bne 3b
  699. teq r2, #'\n'
  700. moveq r2, #'\r'
  701. beq 2b
  702. teq r0, #0
  703. bne 1b
  704. mov pc, lr
  705. putc:
  706. mov r2, r0
  707. mov r0, #0
  708. loadsp r3
  709. b 2b
  710. memdump: mov r12, r0
  711. mov r10, lr
  712. mov r11, #0
  713. 2: mov r0, r11, lsl #2
  714. add r0, r0, r12
  715. mov r1, #8
  716. bl phex
  717. mov r0, #':'
  718. bl putc
  719. 1: mov r0, #' '
  720. bl putc
  721. ldr r0, [r12, r11, lsl #2]
  722. mov r1, #8
  723. bl phex
  724. and r0, r11, #7
  725. teq r0, #3
  726. moveq r0, #' '
  727. bleq putc
  728. and r0, r11, #7
  729. add r11, r11, #1
  730. teq r0, #7
  731. bne 1b
  732. mov r0, #'\n'
  733. bl putc
  734. cmp r11, #64
  735. blt 2b
  736. mov pc, r10
  737. #endif
  738. reloc_end:
  739. .align
  740. .section ".stack", "w"
  741. user_stack: .space 4096