head.S 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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, c1, c0, 0
  32. .endm
  33. #endif
  34. #else
  35. #include <mach/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_S3C_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 + 128 @ alignment + stack
  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. add sp, r1, #128 @ relocate the stack
  245. bl cache_clean_flush
  246. add pc, r5, r0 @ call relocation code
  247. /*
  248. * We're not in danger of overwriting ourselves. Do this the simple way.
  249. *
  250. * r4 = kernel execution address
  251. * r7 = architecture ID
  252. */
  253. wont_overwrite: mov r0, r4
  254. mov r3, r7
  255. bl decompress_kernel
  256. b call_kernel
  257. .type LC0, #object
  258. LC0: .word LC0 @ r1
  259. .word __bss_start @ r2
  260. .word _end @ r3
  261. .word zreladdr @ r4
  262. .word _start @ r5
  263. .word _got_start @ r6
  264. .word _got_end @ ip
  265. .word user_stack+4096 @ sp
  266. LC1: .word reloc_end - reloc_start
  267. .size LC0, . - LC0
  268. #ifdef CONFIG_ARCH_RPC
  269. .globl params
  270. params: ldr r0, =params_phys
  271. mov pc, lr
  272. .ltorg
  273. .align
  274. #endif
  275. /*
  276. * Turn on the cache. We need to setup some page tables so that we
  277. * can have both the I and D caches on.
  278. *
  279. * We place the page tables 16k down from the kernel execution address,
  280. * and we hope that nothing else is using it. If we're using it, we
  281. * will go pop!
  282. *
  283. * On entry,
  284. * r4 = kernel execution address
  285. * r6 = processor ID
  286. * r7 = architecture number
  287. * r8 = atags pointer
  288. * r9 = run-time address of "start" (???)
  289. * On exit,
  290. * r1, r2, r3, r9, r10, r12 corrupted
  291. * This routine must preserve:
  292. * r4, r5, r6, r7, r8
  293. */
  294. .align 5
  295. cache_on: mov r3, #8 @ cache_on function
  296. b call_cache_fn
  297. /*
  298. * Initialize the highest priority protection region, PR7
  299. * to cover all 32bit address and cacheable and bufferable.
  300. */
  301. __armv4_mpu_cache_on:
  302. mov r0, #0x3f @ 4G, the whole
  303. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  304. mcr p15, 0, r0, c6, c7, 1
  305. mov r0, #0x80 @ PR7
  306. mcr p15, 0, r0, c2, c0, 0 @ D-cache on
  307. mcr p15, 0, r0, c2, c0, 1 @ I-cache on
  308. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  309. mov r0, #0xc000
  310. mcr p15, 0, r0, c5, c0, 1 @ I-access permission
  311. mcr p15, 0, r0, c5, c0, 0 @ D-access permission
  312. mov r0, #0
  313. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  314. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  315. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  316. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  317. @ ...I .... ..D. WC.M
  318. orr r0, r0, #0x002d @ .... .... ..1. 11.1
  319. orr r0, r0, #0x1000 @ ...1 .... .... ....
  320. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  321. mov r0, #0
  322. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  323. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  324. mov pc, lr
  325. __armv3_mpu_cache_on:
  326. mov r0, #0x3f @ 4G, the whole
  327. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  328. mov r0, #0x80 @ PR7
  329. mcr p15, 0, r0, c2, c0, 0 @ cache on
  330. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  331. mov r0, #0xc000
  332. mcr p15, 0, r0, c5, c0, 0 @ access permission
  333. mov r0, #0
  334. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  335. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  336. @ .... .... .... WC.M
  337. orr r0, r0, #0x000d @ .... .... .... 11.1
  338. mov r0, #0
  339. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  340. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  341. mov pc, lr
  342. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  343. bic r3, r3, #0xff @ Align the pointer
  344. bic r3, r3, #0x3f00
  345. /*
  346. * Initialise the page tables, turning on the cacheable and bufferable
  347. * bits for the RAM area only.
  348. */
  349. mov r0, r3
  350. mov r9, r0, lsr #18
  351. mov r9, r9, lsl #18 @ start of RAM
  352. add r10, r9, #0x10000000 @ a reasonable RAM size
  353. mov r1, #0x12
  354. orr r1, r1, #3 << 10
  355. add r2, r3, #16384
  356. 1: cmp r1, r9 @ if virt > start of RAM
  357. orrhs r1, r1, #0x0c @ set cacheable, bufferable
  358. cmp r1, r10 @ if virt > end of RAM
  359. bichs r1, r1, #0x0c @ clear cacheable, bufferable
  360. str r1, [r0], #4 @ 1:1 mapping
  361. add r1, r1, #1048576
  362. teq r0, r2
  363. bne 1b
  364. /*
  365. * If ever we are running from Flash, then we surely want the cache
  366. * to be enabled also for our execution instance... We map 2MB of it
  367. * so there is no map overlap problem for up to 1 MB compressed kernel.
  368. * If the execution is in RAM then we would only be duplicating the above.
  369. */
  370. mov r1, #0x1e
  371. orr r1, r1, #3 << 10
  372. mov r2, pc, lsr #20
  373. orr r1, r1, r2, lsl #20
  374. add r0, r3, r2, lsl #2
  375. str r1, [r0], #4
  376. add r1, r1, #1048576
  377. str r1, [r0]
  378. mov pc, lr
  379. ENDPROC(__setup_mmu)
  380. __armv4_mmu_cache_on:
  381. mov r12, lr
  382. bl __setup_mmu
  383. mov r0, #0
  384. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  385. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  386. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  387. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  388. orr r0, r0, #0x0030
  389. bl __common_mmu_cache_on
  390. mov r0, #0
  391. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  392. mov pc, r12
  393. __armv7_mmu_cache_on:
  394. mov r12, lr
  395. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  396. tst r11, #0xf @ VMSA
  397. blne __setup_mmu
  398. mov r0, #0
  399. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  400. tst r11, #0xf @ VMSA
  401. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  402. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  403. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  404. orr r0, r0, #0x003c @ write buffer
  405. orrne r0, r0, #1 @ MMU enabled
  406. movne r1, #-1
  407. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  408. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  409. mcr p15, 0, r0, c1, c0, 0 @ load control register
  410. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  411. mov r0, #0
  412. mcr p15, 0, r0, c7, c5, 4 @ ISB
  413. mov pc, r12
  414. __fa526_cache_on:
  415. mov r12, lr
  416. bl __setup_mmu
  417. mov r0, #0
  418. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  419. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  420. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  421. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  422. orr r0, r0, #0x1000 @ I-cache enable
  423. bl __common_mmu_cache_on
  424. mov r0, #0
  425. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  426. mov pc, r12
  427. __arm6_mmu_cache_on:
  428. mov r12, lr
  429. bl __setup_mmu
  430. mov r0, #0
  431. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  432. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  433. mov r0, #0x30
  434. bl __common_mmu_cache_on
  435. mov r0, #0
  436. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  437. mov pc, r12
  438. __common_mmu_cache_on:
  439. #ifndef DEBUG
  440. orr r0, r0, #0x000d @ Write buffer, mmu
  441. #endif
  442. mov r1, #-1
  443. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  444. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  445. b 1f
  446. .align 5 @ cache line aligned
  447. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  448. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  449. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  450. /*
  451. * All code following this line is relocatable. It is relocated by
  452. * the above code to the end of the decompressed kernel image and
  453. * executed there. During this time, we have no stacks.
  454. *
  455. * r0 = decompressed kernel length
  456. * r1-r3 = unused
  457. * r4 = kernel execution address
  458. * r5 = decompressed kernel start
  459. * r6 = processor ID
  460. * r7 = architecture ID
  461. * r8 = atags pointer
  462. * r9-r14 = corrupted
  463. */
  464. .align 5
  465. reloc_start: add r9, r5, r0
  466. sub r9, r9, #128 @ do not copy the stack
  467. debug_reloc_start
  468. mov r1, r4
  469. 1:
  470. .rept 4
  471. ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel
  472. stmia r1!, {r0, r2, r3, r10 - r14}
  473. .endr
  474. cmp r5, r9
  475. blo 1b
  476. add sp, r1, #128 @ relocate the stack
  477. debug_reloc_end
  478. call_kernel: bl cache_clean_flush
  479. bl cache_off
  480. mov r0, #0 @ must be zero
  481. mov r1, r7 @ restore architecture number
  482. mov r2, r8 @ restore atags pointer
  483. mov pc, r4 @ call kernel
  484. /*
  485. * Here follow the relocatable cache support functions for the
  486. * various processors. This is a generic hook for locating an
  487. * entry and jumping to an instruction at the specified offset
  488. * from the start of the block. Please note this is all position
  489. * independent code.
  490. *
  491. * r1 = corrupted
  492. * r2 = corrupted
  493. * r3 = block offset
  494. * r6 = corrupted
  495. * r12 = corrupted
  496. */
  497. call_cache_fn: adr r12, proc_types
  498. #ifdef CONFIG_CPU_CP15
  499. mrc p15, 0, r6, c0, c0 @ get processor ID
  500. #else
  501. ldr r6, =CONFIG_PROCESSOR_ID
  502. #endif
  503. 1: ldr r1, [r12, #0] @ get value
  504. ldr r2, [r12, #4] @ get mask
  505. eor r1, r1, r6 @ (real ^ match)
  506. tst r1, r2 @ & mask
  507. addeq pc, r12, r3 @ call cache function
  508. add r12, r12, #4*5
  509. b 1b
  510. /*
  511. * Table for cache operations. This is basically:
  512. * - CPU ID match
  513. * - CPU ID mask
  514. * - 'cache on' method instruction
  515. * - 'cache off' method instruction
  516. * - 'cache flush' method instruction
  517. *
  518. * We match an entry using: ((real_id ^ match) & mask) == 0
  519. *
  520. * Writethrough caches generally only need 'on' and 'off'
  521. * methods. Writeback caches _must_ have the flush method
  522. * defined.
  523. */
  524. .type proc_types,#object
  525. proc_types:
  526. .word 0x41560600 @ ARM6/610
  527. .word 0xffffffe0
  528. b __arm6_mmu_cache_off @ works, but slow
  529. b __arm6_mmu_cache_off
  530. mov pc, lr
  531. @ b __arm6_mmu_cache_on @ untested
  532. @ b __arm6_mmu_cache_off
  533. @ b __armv3_mmu_cache_flush
  534. .word 0x00000000 @ old ARM ID
  535. .word 0x0000f000
  536. mov pc, lr
  537. mov pc, lr
  538. mov pc, lr
  539. .word 0x41007000 @ ARM7/710
  540. .word 0xfff8fe00
  541. b __arm7_mmu_cache_off
  542. b __arm7_mmu_cache_off
  543. mov pc, lr
  544. .word 0x41807200 @ ARM720T (writethrough)
  545. .word 0xffffff00
  546. b __armv4_mmu_cache_on
  547. b __armv4_mmu_cache_off
  548. mov pc, lr
  549. .word 0x41007400 @ ARM74x
  550. .word 0xff00ff00
  551. b __armv3_mpu_cache_on
  552. b __armv3_mpu_cache_off
  553. b __armv3_mpu_cache_flush
  554. .word 0x41009400 @ ARM94x
  555. .word 0xff00ff00
  556. b __armv4_mpu_cache_on
  557. b __armv4_mpu_cache_off
  558. b __armv4_mpu_cache_flush
  559. .word 0x00007000 @ ARM7 IDs
  560. .word 0x0000f000
  561. mov pc, lr
  562. mov pc, lr
  563. mov pc, lr
  564. @ Everything from here on will be the new ID system.
  565. .word 0x4401a100 @ sa110 / sa1100
  566. .word 0xffffffe0
  567. b __armv4_mmu_cache_on
  568. b __armv4_mmu_cache_off
  569. b __armv4_mmu_cache_flush
  570. .word 0x6901b110 @ sa1110
  571. .word 0xfffffff0
  572. b __armv4_mmu_cache_on
  573. b __armv4_mmu_cache_off
  574. b __armv4_mmu_cache_flush
  575. .word 0x56056930
  576. .word 0xff0ffff0 @ PXA935
  577. b __armv4_mmu_cache_on
  578. b __armv4_mmu_cache_off
  579. b __armv4_mmu_cache_flush
  580. .word 0x56050000 @ Feroceon
  581. .word 0xff0f0000
  582. b __armv4_mmu_cache_on
  583. b __armv4_mmu_cache_off
  584. b __armv5tej_mmu_cache_flush
  585. .word 0x66015261 @ FA526
  586. .word 0xff01fff1
  587. b __fa526_cache_on
  588. b __armv4_mmu_cache_off
  589. b __fa526_cache_flush
  590. @ These match on the architecture ID
  591. .word 0x00020000 @ ARMv4T
  592. .word 0x000f0000
  593. b __armv4_mmu_cache_on
  594. b __armv4_mmu_cache_off
  595. b __armv4_mmu_cache_flush
  596. .word 0x00050000 @ ARMv5TE
  597. .word 0x000f0000
  598. b __armv4_mmu_cache_on
  599. b __armv4_mmu_cache_off
  600. b __armv4_mmu_cache_flush
  601. .word 0x00060000 @ ARMv5TEJ
  602. .word 0x000f0000
  603. b __armv4_mmu_cache_on
  604. b __armv4_mmu_cache_off
  605. b __armv5tej_mmu_cache_flush
  606. .word 0x0007b000 @ ARMv6
  607. .word 0x000ff000
  608. b __armv4_mmu_cache_on
  609. b __armv4_mmu_cache_off
  610. b __armv6_mmu_cache_flush
  611. .word 0x000f0000 @ new CPU Id
  612. .word 0x000f0000
  613. b __armv7_mmu_cache_on
  614. b __armv7_mmu_cache_off
  615. b __armv7_mmu_cache_flush
  616. .word 0 @ unrecognised type
  617. .word 0
  618. mov pc, lr
  619. mov pc, lr
  620. mov pc, lr
  621. .size proc_types, . - proc_types
  622. /*
  623. * Turn off the Cache and MMU. ARMv3 does not support
  624. * reading the control register, but ARMv4 does.
  625. *
  626. * On entry, r6 = processor ID
  627. * On exit, r0, r1, r2, r3, r12 corrupted
  628. * This routine must preserve: r4, r6, r7
  629. */
  630. .align 5
  631. cache_off: mov r3, #12 @ cache_off function
  632. b call_cache_fn
  633. __armv4_mpu_cache_off:
  634. mrc p15, 0, r0, c1, c0
  635. bic r0, r0, #0x000d
  636. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  637. mov r0, #0
  638. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  639. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  640. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  641. mov pc, lr
  642. __armv3_mpu_cache_off:
  643. mrc p15, 0, r0, c1, c0
  644. bic r0, r0, #0x000d
  645. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  646. mov r0, #0
  647. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  648. mov pc, lr
  649. __armv4_mmu_cache_off:
  650. mrc p15, 0, r0, c1, c0
  651. bic r0, r0, #0x000d
  652. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  653. mov r0, #0
  654. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  655. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  656. mov pc, lr
  657. __armv7_mmu_cache_off:
  658. mrc p15, 0, r0, c1, c0
  659. bic r0, r0, #0x000d
  660. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  661. mov r12, lr
  662. bl __armv7_mmu_cache_flush
  663. mov r0, #0
  664. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  665. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  666. mcr p15, 0, r0, c7, c10, 4 @ DSB
  667. mcr p15, 0, r0, c7, c5, 4 @ ISB
  668. mov pc, r12
  669. __arm6_mmu_cache_off:
  670. mov r0, #0x00000030 @ ARM6 control reg.
  671. b __armv3_mmu_cache_off
  672. __arm7_mmu_cache_off:
  673. mov r0, #0x00000070 @ ARM7 control reg.
  674. b __armv3_mmu_cache_off
  675. __armv3_mmu_cache_off:
  676. mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
  677. mov r0, #0
  678. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  679. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  680. mov pc, lr
  681. /*
  682. * Clean and flush the cache to maintain consistency.
  683. *
  684. * On entry,
  685. * r6 = processor ID
  686. * On exit,
  687. * r1, r2, r3, r11, r12 corrupted
  688. * This routine must preserve:
  689. * r0, r4, r5, r6, r7
  690. */
  691. .align 5
  692. cache_clean_flush:
  693. mov r3, #16
  694. b call_cache_fn
  695. __armv4_mpu_cache_flush:
  696. mov r2, #1
  697. mov r3, #0
  698. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  699. mov r1, #7 << 5 @ 8 segments
  700. 1: orr r3, r1, #63 << 26 @ 64 entries
  701. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  702. subs r3, r3, #1 << 26
  703. bcs 2b @ entries 63 to 0
  704. subs r1, r1, #1 << 5
  705. bcs 1b @ segments 7 to 0
  706. teq r2, #0
  707. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  708. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  709. mov pc, lr
  710. __fa526_cache_flush:
  711. mov r1, #0
  712. mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
  713. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  714. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  715. mov pc, lr
  716. __armv6_mmu_cache_flush:
  717. mov r1, #0
  718. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  719. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  720. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  721. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  722. mov pc, lr
  723. __armv7_mmu_cache_flush:
  724. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  725. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  726. mov r10, #0
  727. beq hierarchical
  728. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  729. b iflush
  730. hierarchical:
  731. mcr p15, 0, r10, c7, c10, 5 @ DMB
  732. stmfd sp!, {r0-r5, r7, r9, r11}
  733. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  734. ands r3, r0, #0x7000000 @ extract loc from clidr
  735. mov r3, r3, lsr #23 @ left align loc bit field
  736. beq finished @ if loc is 0, then no need to clean
  737. mov r10, #0 @ start clean at cache level 0
  738. loop1:
  739. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  740. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  741. and r1, r1, #7 @ mask of the bits for current cache only
  742. cmp r1, #2 @ see what cache we have at this level
  743. blt skip @ skip if no cache, or just i-cache
  744. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  745. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  746. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  747. and r2, r1, #7 @ extract the length of the cache lines
  748. add r2, r2, #4 @ add 4 (line length offset)
  749. ldr r4, =0x3ff
  750. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  751. clz r5, r4 @ find bit position of way size increment
  752. ldr r7, =0x7fff
  753. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  754. loop2:
  755. mov r9, r4 @ create working copy of max way size
  756. loop3:
  757. orr r11, r10, r9, lsl r5 @ factor way and cache number into r11
  758. orr r11, r11, r7, lsl r2 @ factor index number into r11
  759. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  760. subs r9, r9, #1 @ decrement the way
  761. bge loop3
  762. subs r7, r7, #1 @ decrement the index
  763. bge loop2
  764. skip:
  765. add r10, r10, #2 @ increment cache number
  766. cmp r3, r10
  767. bgt loop1
  768. finished:
  769. ldmfd sp!, {r0-r5, r7, r9, r11}
  770. mov r10, #0 @ swith back to cache level 0
  771. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  772. iflush:
  773. mcr p15, 0, r10, c7, c10, 4 @ DSB
  774. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  775. mcr p15, 0, r10, c7, c10, 4 @ DSB
  776. mcr p15, 0, r10, c7, c5, 4 @ ISB
  777. mov pc, lr
  778. __armv5tej_mmu_cache_flush:
  779. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  780. bne 1b
  781. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  782. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  783. mov pc, lr
  784. __armv4_mmu_cache_flush:
  785. mov r2, #64*1024 @ default: 32K dcache size (*2)
  786. mov r11, #32 @ default: 32 byte line size
  787. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  788. teq r3, r6 @ cache ID register present?
  789. beq no_cache_id
  790. mov r1, r3, lsr #18
  791. and r1, r1, #7
  792. mov r2, #1024
  793. mov r2, r2, lsl r1 @ base dcache size *2
  794. tst r3, #1 << 14 @ test M bit
  795. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  796. mov r3, r3, lsr #12
  797. and r3, r3, #3
  798. mov r11, #8
  799. mov r11, r11, lsl r3 @ cache line size in bytes
  800. no_cache_id:
  801. bic r1, pc, #63 @ align to longest cache line
  802. add r2, r1, r2
  803. 1: ldr r3, [r1], r11 @ s/w flush D cache
  804. teq r1, r2
  805. bne 1b
  806. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  807. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  808. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  809. mov pc, lr
  810. __armv3_mmu_cache_flush:
  811. __armv3_mpu_cache_flush:
  812. mov r1, #0
  813. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  814. mov pc, lr
  815. /*
  816. * Various debugging routines for printing hex characters and
  817. * memory, which again must be relocatable.
  818. */
  819. #ifdef DEBUG
  820. .type phexbuf,#object
  821. phexbuf: .space 12
  822. .size phexbuf, . - phexbuf
  823. phex: adr r3, phexbuf
  824. mov r2, #0
  825. strb r2, [r3, r1]
  826. 1: subs r1, r1, #1
  827. movmi r0, r3
  828. bmi puts
  829. and r2, r0, #15
  830. mov r0, r0, lsr #4
  831. cmp r2, #10
  832. addge r2, r2, #7
  833. add r2, r2, #'0'
  834. strb r2, [r3, r1]
  835. b 1b
  836. puts: loadsp r3
  837. 1: ldrb r2, [r0], #1
  838. teq r2, #0
  839. moveq pc, lr
  840. 2: writeb r2, r3
  841. mov r1, #0x00020000
  842. 3: subs r1, r1, #1
  843. bne 3b
  844. teq r2, #'\n'
  845. moveq r2, #'\r'
  846. beq 2b
  847. teq r0, #0
  848. bne 1b
  849. mov pc, lr
  850. putc:
  851. mov r2, r0
  852. mov r0, #0
  853. loadsp r3
  854. b 2b
  855. memdump: mov r12, r0
  856. mov r10, lr
  857. mov r11, #0
  858. 2: mov r0, r11, lsl #2
  859. add r0, r0, r12
  860. mov r1, #8
  861. bl phex
  862. mov r0, #':'
  863. bl putc
  864. 1: mov r0, #' '
  865. bl putc
  866. ldr r0, [r12, r11, lsl #2]
  867. mov r1, #8
  868. bl phex
  869. and r0, r11, #7
  870. teq r0, #3
  871. moveq r0, #' '
  872. bleq putc
  873. and r0, r11, #7
  874. add r11, r11, #1
  875. teq r0, #7
  876. bne 1b
  877. mov r0, #'\n'
  878. bl putc
  879. cmp r11, #64
  880. blt 2b
  881. mov pc, r10
  882. #endif
  883. .ltorg
  884. reloc_end:
  885. .align
  886. .section ".stack", "w"
  887. user_stack: .space 4096