head.S 25 KB

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