head.S 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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. bl __common_mmu_cache_on
  396. mov r0, #0
  397. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  398. mov pc, r12
  399. __armv7_mmu_cache_on:
  400. mov r12, lr
  401. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  402. tst r11, #0xf @ VMSA
  403. blne __setup_mmu
  404. mov r0, #0
  405. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  406. tst r11, #0xf @ VMSA
  407. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  408. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  409. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  410. orr r0, r0, #0x003c @ write buffer
  411. orrne r0, r0, #1 @ MMU enabled
  412. movne r1, #-1
  413. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  414. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  415. mcr p15, 0, r0, c1, c0, 0 @ load control register
  416. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  417. mov r0, #0
  418. mcr p15, 0, r0, c7, c5, 4 @ ISB
  419. mov pc, r12
  420. __fa526_cache_on:
  421. mov r12, lr
  422. bl __setup_mmu
  423. mov r0, #0
  424. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  425. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  426. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  427. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  428. orr r0, r0, #0x1000 @ I-cache enable
  429. bl __common_mmu_cache_on
  430. mov r0, #0
  431. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  432. mov pc, r12
  433. __arm6_mmu_cache_on:
  434. mov r12, lr
  435. bl __setup_mmu
  436. mov r0, #0
  437. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  438. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  439. mov r0, #0x30
  440. bl __common_mmu_cache_on
  441. mov r0, #0
  442. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  443. mov pc, r12
  444. __common_mmu_cache_on:
  445. #ifndef DEBUG
  446. orr r0, r0, #0x000d @ Write buffer, mmu
  447. #endif
  448. mov r1, #-1
  449. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  450. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  451. b 1f
  452. .align 5 @ cache line aligned
  453. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  454. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  455. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  456. /*
  457. * All code following this line is relocatable. It is relocated by
  458. * the above code to the end of the decompressed kernel image and
  459. * executed there. During this time, we have no stacks.
  460. *
  461. * r0 = decompressed kernel length
  462. * r1-r3 = unused
  463. * r4 = kernel execution address
  464. * r5 = decompressed kernel start
  465. * r6 = processor ID
  466. * r7 = architecture ID
  467. * r8 = atags pointer
  468. * r9-r14 = corrupted
  469. */
  470. .align 5
  471. reloc_start: add r9, r5, r0
  472. sub r9, r9, #128 @ do not copy the stack
  473. debug_reloc_start
  474. mov r1, r4
  475. 1:
  476. .rept 4
  477. ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel
  478. stmia r1!, {r0, r2, r3, r10 - r14}
  479. .endr
  480. cmp r5, r9
  481. blo 1b
  482. add sp, r1, #128 @ relocate the stack
  483. debug_reloc_end
  484. call_kernel: bl cache_clean_flush
  485. bl cache_off
  486. mov r0, #0 @ must be zero
  487. mov r1, r7 @ restore architecture number
  488. mov r2, r8 @ restore atags pointer
  489. mov pc, r4 @ call kernel
  490. /*
  491. * Here follow the relocatable cache support functions for the
  492. * various processors. This is a generic hook for locating an
  493. * entry and jumping to an instruction at the specified offset
  494. * from the start of the block. Please note this is all position
  495. * independent code.
  496. *
  497. * r1 = corrupted
  498. * r2 = corrupted
  499. * r3 = block offset
  500. * r6 = corrupted
  501. * r12 = corrupted
  502. */
  503. call_cache_fn: adr r12, proc_types
  504. #ifdef CONFIG_CPU_CP15
  505. mrc p15, 0, r6, c0, c0 @ get processor ID
  506. #else
  507. ldr r6, =CONFIG_PROCESSOR_ID
  508. #endif
  509. 1: ldr r1, [r12, #0] @ get value
  510. ldr r2, [r12, #4] @ get mask
  511. eor r1, r1, r6 @ (real ^ match)
  512. tst r1, r2 @ & mask
  513. addeq pc, r12, r3 @ call cache function
  514. add r12, r12, #4*5
  515. b 1b
  516. /*
  517. * Table for cache operations. This is basically:
  518. * - CPU ID match
  519. * - CPU ID mask
  520. * - 'cache on' method instruction
  521. * - 'cache off' method instruction
  522. * - 'cache flush' method instruction
  523. *
  524. * We match an entry using: ((real_id ^ match) & mask) == 0
  525. *
  526. * Writethrough caches generally only need 'on' and 'off'
  527. * methods. Writeback caches _must_ have the flush method
  528. * defined.
  529. */
  530. .type proc_types,#object
  531. proc_types:
  532. .word 0x41560600 @ ARM6/610
  533. .word 0xffffffe0
  534. b __arm6_mmu_cache_off @ works, but slow
  535. b __arm6_mmu_cache_off
  536. mov pc, lr
  537. @ b __arm6_mmu_cache_on @ untested
  538. @ b __arm6_mmu_cache_off
  539. @ b __armv3_mmu_cache_flush
  540. .word 0x00000000 @ old ARM ID
  541. .word 0x0000f000
  542. mov pc, lr
  543. mov pc, lr
  544. mov pc, lr
  545. .word 0x41007000 @ ARM7/710
  546. .word 0xfff8fe00
  547. b __arm7_mmu_cache_off
  548. b __arm7_mmu_cache_off
  549. mov pc, lr
  550. .word 0x41807200 @ ARM720T (writethrough)
  551. .word 0xffffff00
  552. b __armv4_mmu_cache_on
  553. b __armv4_mmu_cache_off
  554. mov pc, lr
  555. .word 0x41007400 @ ARM74x
  556. .word 0xff00ff00
  557. b __armv3_mpu_cache_on
  558. b __armv3_mpu_cache_off
  559. b __armv3_mpu_cache_flush
  560. .word 0x41009400 @ ARM94x
  561. .word 0xff00ff00
  562. b __armv4_mpu_cache_on
  563. b __armv4_mpu_cache_off
  564. b __armv4_mpu_cache_flush
  565. .word 0x00007000 @ ARM7 IDs
  566. .word 0x0000f000
  567. mov pc, lr
  568. mov pc, lr
  569. mov pc, lr
  570. @ Everything from here on will be the new ID system.
  571. .word 0x4401a100 @ sa110 / sa1100
  572. .word 0xffffffe0
  573. b __armv4_mmu_cache_on
  574. b __armv4_mmu_cache_off
  575. b __armv4_mmu_cache_flush
  576. .word 0x6901b110 @ sa1110
  577. .word 0xfffffff0
  578. b __armv4_mmu_cache_on
  579. b __armv4_mmu_cache_off
  580. b __armv4_mmu_cache_flush
  581. .word 0x56056930
  582. .word 0xff0ffff0 @ PXA935
  583. b __armv4_mmu_cache_on
  584. b __armv4_mmu_cache_off
  585. b __armv4_mmu_cache_flush
  586. .word 0x56158000 @ PXA168
  587. .word 0xfffff000
  588. b __armv4_mmu_cache_on
  589. b __armv4_mmu_cache_off
  590. b __armv5tej_mmu_cache_flush
  591. .word 0x56056930
  592. .word 0xff0ffff0 @ PXA935
  593. b __armv4_mmu_cache_on
  594. b __armv4_mmu_cache_off
  595. b __armv4_mmu_cache_flush
  596. .word 0x56050000 @ Feroceon
  597. .word 0xff0f0000
  598. b __armv4_mmu_cache_on
  599. b __armv4_mmu_cache_off
  600. b __armv5tej_mmu_cache_flush
  601. .word 0x66015261 @ FA526
  602. .word 0xff01fff1
  603. b __fa526_cache_on
  604. b __armv4_mmu_cache_off
  605. b __fa526_cache_flush
  606. @ These match on the architecture ID
  607. .word 0x00020000 @ ARMv4T
  608. .word 0x000f0000
  609. b __armv4_mmu_cache_on
  610. b __armv4_mmu_cache_off
  611. b __armv4_mmu_cache_flush
  612. .word 0x00050000 @ ARMv5TE
  613. .word 0x000f0000
  614. b __armv4_mmu_cache_on
  615. b __armv4_mmu_cache_off
  616. b __armv4_mmu_cache_flush
  617. .word 0x00060000 @ ARMv5TEJ
  618. .word 0x000f0000
  619. b __armv4_mmu_cache_on
  620. b __armv4_mmu_cache_off
  621. b __armv5tej_mmu_cache_flush
  622. .word 0x0007b000 @ ARMv6
  623. .word 0x000ff000
  624. b __armv4_mmu_cache_on
  625. b __armv4_mmu_cache_off
  626. b __armv6_mmu_cache_flush
  627. .word 0x000f0000 @ new CPU Id
  628. .word 0x000f0000
  629. b __armv7_mmu_cache_on
  630. b __armv7_mmu_cache_off
  631. b __armv7_mmu_cache_flush
  632. .word 0 @ unrecognised type
  633. .word 0
  634. mov pc, lr
  635. mov pc, lr
  636. mov pc, lr
  637. .size proc_types, . - proc_types
  638. /*
  639. * Turn off the Cache and MMU. ARMv3 does not support
  640. * reading the control register, but ARMv4 does.
  641. *
  642. * On entry, r6 = processor ID
  643. * On exit, r0, r1, r2, r3, r12 corrupted
  644. * This routine must preserve: r4, r6, r7
  645. */
  646. .align 5
  647. cache_off: mov r3, #12 @ cache_off function
  648. b call_cache_fn
  649. __armv4_mpu_cache_off:
  650. mrc p15, 0, r0, c1, c0
  651. bic r0, r0, #0x000d
  652. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  653. mov r0, #0
  654. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  655. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  656. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  657. mov pc, lr
  658. __armv3_mpu_cache_off:
  659. mrc p15, 0, r0, c1, c0
  660. bic r0, r0, #0x000d
  661. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  662. mov r0, #0
  663. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  664. mov pc, lr
  665. __armv4_mmu_cache_off:
  666. mrc p15, 0, r0, c1, c0
  667. bic r0, r0, #0x000d
  668. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  669. mov r0, #0
  670. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  671. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  672. mov pc, lr
  673. __armv7_mmu_cache_off:
  674. mrc p15, 0, r0, c1, c0
  675. bic r0, r0, #0x000d
  676. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  677. mov r12, lr
  678. bl __armv7_mmu_cache_flush
  679. mov r0, #0
  680. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  681. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  682. mcr p15, 0, r0, c7, c10, 4 @ DSB
  683. mcr p15, 0, r0, c7, c5, 4 @ ISB
  684. mov pc, r12
  685. __arm6_mmu_cache_off:
  686. mov r0, #0x00000030 @ ARM6 control reg.
  687. b __armv3_mmu_cache_off
  688. __arm7_mmu_cache_off:
  689. mov r0, #0x00000070 @ ARM7 control reg.
  690. b __armv3_mmu_cache_off
  691. __armv3_mmu_cache_off:
  692. mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
  693. mov r0, #0
  694. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  695. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  696. mov pc, lr
  697. /*
  698. * Clean and flush the cache to maintain consistency.
  699. *
  700. * On entry,
  701. * r6 = processor ID
  702. * On exit,
  703. * r1, r2, r3, r11, r12 corrupted
  704. * This routine must preserve:
  705. * r0, r4, r5, r6, r7
  706. */
  707. .align 5
  708. cache_clean_flush:
  709. mov r3, #16
  710. b call_cache_fn
  711. __armv4_mpu_cache_flush:
  712. mov r2, #1
  713. mov r3, #0
  714. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  715. mov r1, #7 << 5 @ 8 segments
  716. 1: orr r3, r1, #63 << 26 @ 64 entries
  717. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  718. subs r3, r3, #1 << 26
  719. bcs 2b @ entries 63 to 0
  720. subs r1, r1, #1 << 5
  721. bcs 1b @ segments 7 to 0
  722. teq r2, #0
  723. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  724. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  725. mov pc, lr
  726. __fa526_cache_flush:
  727. mov r1, #0
  728. mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
  729. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  730. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  731. mov pc, lr
  732. __armv6_mmu_cache_flush:
  733. mov r1, #0
  734. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  735. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  736. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  737. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  738. mov pc, lr
  739. __armv7_mmu_cache_flush:
  740. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  741. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  742. mov r10, #0
  743. beq hierarchical
  744. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  745. b iflush
  746. hierarchical:
  747. mcr p15, 0, r10, c7, c10, 5 @ DMB
  748. stmfd sp!, {r0-r5, r7, r9, r11}
  749. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  750. ands r3, r0, #0x7000000 @ extract loc from clidr
  751. mov r3, r3, lsr #23 @ left align loc bit field
  752. beq finished @ if loc is 0, then no need to clean
  753. mov r10, #0 @ start clean at cache level 0
  754. loop1:
  755. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  756. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  757. and r1, r1, #7 @ mask of the bits for current cache only
  758. cmp r1, #2 @ see what cache we have at this level
  759. blt skip @ skip if no cache, or just i-cache
  760. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  761. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  762. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  763. and r2, r1, #7 @ extract the length of the cache lines
  764. add r2, r2, #4 @ add 4 (line length offset)
  765. ldr r4, =0x3ff
  766. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  767. clz r5, r4 @ find bit position of way size increment
  768. ldr r7, =0x7fff
  769. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  770. loop2:
  771. mov r9, r4 @ create working copy of max way size
  772. loop3:
  773. orr r11, r10, r9, lsl r5 @ factor way and cache number into r11
  774. orr r11, r11, r7, lsl r2 @ factor index number into r11
  775. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  776. subs r9, r9, #1 @ decrement the way
  777. bge loop3
  778. subs r7, r7, #1 @ decrement the index
  779. bge loop2
  780. skip:
  781. add r10, r10, #2 @ increment cache number
  782. cmp r3, r10
  783. bgt loop1
  784. finished:
  785. ldmfd sp!, {r0-r5, r7, r9, r11}
  786. mov r10, #0 @ swith back to cache level 0
  787. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  788. iflush:
  789. mcr p15, 0, r10, c7, c10, 4 @ DSB
  790. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  791. mcr p15, 0, r10, c7, c10, 4 @ DSB
  792. mcr p15, 0, r10, c7, c5, 4 @ ISB
  793. mov pc, lr
  794. __armv5tej_mmu_cache_flush:
  795. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  796. bne 1b
  797. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  798. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  799. mov pc, lr
  800. __armv4_mmu_cache_flush:
  801. mov r2, #64*1024 @ default: 32K dcache size (*2)
  802. mov r11, #32 @ default: 32 byte line size
  803. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  804. teq r3, r6 @ cache ID register present?
  805. beq no_cache_id
  806. mov r1, r3, lsr #18
  807. and r1, r1, #7
  808. mov r2, #1024
  809. mov r2, r2, lsl r1 @ base dcache size *2
  810. tst r3, #1 << 14 @ test M bit
  811. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  812. mov r3, r3, lsr #12
  813. and r3, r3, #3
  814. mov r11, #8
  815. mov r11, r11, lsl r3 @ cache line size in bytes
  816. no_cache_id:
  817. bic r1, pc, #63 @ align to longest cache line
  818. add r2, r1, r2
  819. 1: ldr r3, [r1], r11 @ s/w flush D cache
  820. teq r1, r2
  821. bne 1b
  822. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  823. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  824. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  825. mov pc, lr
  826. __armv3_mmu_cache_flush:
  827. __armv3_mpu_cache_flush:
  828. mov r1, #0
  829. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  830. mov pc, lr
  831. /*
  832. * Various debugging routines for printing hex characters and
  833. * memory, which again must be relocatable.
  834. */
  835. #ifdef DEBUG
  836. .type phexbuf,#object
  837. phexbuf: .space 12
  838. .size phexbuf, . - phexbuf
  839. phex: adr r3, phexbuf
  840. mov r2, #0
  841. strb r2, [r3, r1]
  842. 1: subs r1, r1, #1
  843. movmi r0, r3
  844. bmi puts
  845. and r2, r0, #15
  846. mov r0, r0, lsr #4
  847. cmp r2, #10
  848. addge r2, r2, #7
  849. add r2, r2, #'0'
  850. strb r2, [r3, r1]
  851. b 1b
  852. puts: loadsp r3
  853. 1: ldrb r2, [r0], #1
  854. teq r2, #0
  855. moveq pc, lr
  856. 2: writeb r2, r3
  857. mov r1, #0x00020000
  858. 3: subs r1, r1, #1
  859. bne 3b
  860. teq r2, #'\n'
  861. moveq r2, #'\r'
  862. beq 2b
  863. teq r0, #0
  864. bne 1b
  865. mov pc, lr
  866. putc:
  867. mov r2, r0
  868. mov r0, #0
  869. loadsp r3
  870. b 2b
  871. memdump: mov r12, r0
  872. mov r10, lr
  873. mov r11, #0
  874. 2: mov r0, r11, lsl #2
  875. add r0, r0, r12
  876. mov r1, #8
  877. bl phex
  878. mov r0, #':'
  879. bl putc
  880. 1: mov r0, #' '
  881. bl putc
  882. ldr r0, [r12, r11, lsl #2]
  883. mov r1, #8
  884. bl phex
  885. and r0, r11, #7
  886. teq r0, #3
  887. moveq r0, #' '
  888. bleq putc
  889. and r0, r11, #7
  890. add r11, r11, #1
  891. teq r0, #7
  892. bne 1b
  893. mov r0, #'\n'
  894. bl putc
  895. cmp r11, #64
  896. blt 2b
  897. mov pc, r10
  898. #endif
  899. .ltorg
  900. reloc_end:
  901. .align
  902. .section ".stack", "w"
  903. user_stack: .space 4096