head.S 26 KB

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