head.S 19 KB

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