head.S 19 KB

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