head.S 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  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. #include <asm/assembler.h>
  13. .arch armv7-a
  14. /*
  15. * Debugging stuff
  16. *
  17. * Note that these macros must not contain any code which is not
  18. * 100% relocatable. Any attempt to do so will result in a crash.
  19. * Please select one of the following when turning on debugging.
  20. */
  21. #ifdef DEBUG
  22. #if defined(CONFIG_DEBUG_ICEDCC)
  23. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
  24. .macro loadsp, rb, tmp
  25. .endm
  26. .macro writeb, ch, rb
  27. mcr p14, 0, \ch, c0, c5, 0
  28. .endm
  29. #elif defined(CONFIG_CPU_XSCALE)
  30. .macro loadsp, rb, tmp
  31. .endm
  32. .macro writeb, ch, rb
  33. mcr p14, 0, \ch, c8, c0, 0
  34. .endm
  35. #else
  36. .macro loadsp, rb, tmp
  37. .endm
  38. .macro writeb, ch, rb
  39. mcr p14, 0, \ch, c1, c0, 0
  40. .endm
  41. #endif
  42. #else
  43. #include CONFIG_DEBUG_LL_INCLUDE
  44. .macro writeb, ch, rb
  45. senduart \ch, \rb
  46. .endm
  47. #if defined(CONFIG_ARCH_SA1100)
  48. .macro loadsp, rb, tmp
  49. mov \rb, #0x80000000 @ physical base address
  50. #ifdef CONFIG_DEBUG_LL_SER3
  51. add \rb, \rb, #0x00050000 @ Ser3
  52. #else
  53. add \rb, \rb, #0x00010000 @ Ser1
  54. #endif
  55. .endm
  56. #else
  57. .macro loadsp, rb, tmp
  58. addruart \rb, \tmp
  59. .endm
  60. #endif
  61. #endif
  62. #endif
  63. .macro kputc,val
  64. mov r0, \val
  65. bl putc
  66. .endm
  67. .macro kphex,val,len
  68. mov r0, \val
  69. mov r1, #\len
  70. bl phex
  71. .endm
  72. .macro debug_reloc_start
  73. #ifdef DEBUG
  74. kputc #'\n'
  75. kphex r6, 8 /* processor id */
  76. kputc #':'
  77. kphex r7, 8 /* architecture id */
  78. #ifdef CONFIG_CPU_CP15
  79. kputc #':'
  80. mrc p15, 0, r0, c1, c0
  81. kphex r0, 8 /* control reg */
  82. #endif
  83. kputc #'\n'
  84. kphex r5, 8 /* decompressed kernel start */
  85. kputc #'-'
  86. kphex r9, 8 /* decompressed kernel end */
  87. kputc #'>'
  88. kphex r4, 8 /* kernel execution address */
  89. kputc #'\n'
  90. #endif
  91. .endm
  92. .macro debug_reloc_end
  93. #ifdef DEBUG
  94. kphex r5, 8 /* end of kernel */
  95. kputc #'\n'
  96. mov r0, r4
  97. bl memdump /* dump 256 bytes at start of kernel */
  98. #endif
  99. .endm
  100. .section ".start", #alloc, #execinstr
  101. /*
  102. * sort out different calling conventions
  103. */
  104. .align
  105. .arm @ Always enter in ARM state
  106. start:
  107. .type start,#function
  108. .rept 7
  109. mov r0, r0
  110. .endr
  111. ARM( mov r0, r0 )
  112. ARM( b 1f )
  113. THUMB( adr r12, BSYM(1f) )
  114. THUMB( bx r12 )
  115. .word 0x016f2818 @ Magic numbers to help the loader
  116. .word start @ absolute load/run zImage address
  117. .word _edata @ zImage end address
  118. THUMB( .thumb )
  119. 1:
  120. ARM_BE8( setend be ) @ go BE8 if compiled for BE8
  121. mrs r9, cpsr
  122. #ifdef CONFIG_ARM_VIRT_EXT
  123. bl __hyp_stub_install @ get into SVC mode, reversibly
  124. #endif
  125. mov r7, r1 @ save architecture ID
  126. mov r8, r2 @ save atags pointer
  127. /*
  128. * Booting from Angel - need to enter SVC mode and disable
  129. * FIQs/IRQs (numeric definitions from angel arm.h source).
  130. * We only do this if we were in user mode on entry.
  131. */
  132. mrs r2, cpsr @ get current mode
  133. tst r2, #3 @ not user?
  134. bne not_angel
  135. mov r0, #0x17 @ angel_SWIreason_EnterSVC
  136. ARM( swi 0x123456 ) @ angel_SWI_ARM
  137. THUMB( svc 0xab ) @ angel_SWI_THUMB
  138. not_angel:
  139. safe_svcmode_maskall r0
  140. msr spsr_cxsf, r9 @ Save the CPU boot mode in
  141. @ SPSR
  142. /*
  143. * Note that some cache flushing and other stuff may
  144. * be needed here - is there an Angel SWI call for this?
  145. */
  146. /*
  147. * some architecture specific code can be inserted
  148. * by the linker here, but it should preserve r7, r8, and r9.
  149. */
  150. .text
  151. #ifdef CONFIG_AUTO_ZRELADDR
  152. @ determine final kernel image address
  153. mov r4, pc
  154. and r4, r4, #0xf8000000
  155. add r4, r4, #TEXT_OFFSET
  156. #else
  157. ldr r4, =zreladdr
  158. #endif
  159. /*
  160. * Set up a page table only if it won't overwrite ourself.
  161. * That means r4 < pc && r4 - 16k page directory > &_end.
  162. * Given that r4 > &_end is most unfrequent, we add a rough
  163. * additional 1MB of room for a possible appended DTB.
  164. */
  165. mov r0, pc
  166. cmp r0, r4
  167. ldrcc r0, LC0+32
  168. addcc r0, r0, pc
  169. cmpcc r4, r0
  170. orrcc r4, r4, #1 @ remember we skipped cache_on
  171. blcs cache_on
  172. restart: adr r0, LC0
  173. ldmia r0, {r1, r2, r3, r6, r10, r11, r12}
  174. ldr sp, [r0, #28]
  175. /*
  176. * We might be running at a different address. We need
  177. * to fix up various pointers.
  178. */
  179. sub r0, r0, r1 @ calculate the delta offset
  180. add r6, r6, r0 @ _edata
  181. add r10, r10, r0 @ inflated kernel size location
  182. /*
  183. * The kernel build system appends the size of the
  184. * decompressed kernel at the end of the compressed data
  185. * in little-endian form.
  186. */
  187. ldrb r9, [r10, #0]
  188. ldrb lr, [r10, #1]
  189. orr r9, r9, lr, lsl #8
  190. ldrb lr, [r10, #2]
  191. ldrb r10, [r10, #3]
  192. orr r9, r9, lr, lsl #16
  193. orr r9, r9, r10, lsl #24
  194. #ifndef CONFIG_ZBOOT_ROM
  195. /* malloc space is above the relocated stack (64k max) */
  196. add sp, sp, r0
  197. add r10, sp, #0x10000
  198. #else
  199. /*
  200. * With ZBOOT_ROM the bss/stack is non relocatable,
  201. * but someone could still run this code from RAM,
  202. * in which case our reference is _edata.
  203. */
  204. mov r10, r6
  205. #endif
  206. mov r5, #0 @ init dtb size to 0
  207. #ifdef CONFIG_ARM_APPENDED_DTB
  208. /*
  209. * r0 = delta
  210. * r2 = BSS start
  211. * r3 = BSS end
  212. * r4 = final kernel address (possibly with LSB set)
  213. * r5 = appended dtb size (still unknown)
  214. * r6 = _edata
  215. * r7 = architecture ID
  216. * r8 = atags/device tree pointer
  217. * r9 = size of decompressed image
  218. * r10 = end of this image, including bss/stack/malloc space if non XIP
  219. * r11 = GOT start
  220. * r12 = GOT end
  221. * sp = stack pointer
  222. *
  223. * if there are device trees (dtb) appended to zImage, advance r10 so that the
  224. * dtb data will get relocated along with the kernel if necessary.
  225. */
  226. ldr lr, [r6, #0]
  227. #ifndef __ARMEB__
  228. ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
  229. #else
  230. ldr r1, =0xd00dfeed
  231. #endif
  232. cmp lr, r1
  233. bne dtb_check_done @ not found
  234. #ifdef CONFIG_ARM_ATAG_DTB_COMPAT
  235. /*
  236. * OK... Let's do some funky business here.
  237. * If we do have a DTB appended to zImage, and we do have
  238. * an ATAG list around, we want the later to be translated
  239. * and folded into the former here. To be on the safe side,
  240. * let's temporarily move the stack away into the malloc
  241. * area. No GOT fixup has occurred yet, but none of the
  242. * code we're about to call uses any global variable.
  243. */
  244. add sp, sp, #0x10000
  245. stmfd sp!, {r0-r3, ip, lr}
  246. mov r0, r8
  247. mov r1, r6
  248. sub r2, sp, r6
  249. bl atags_to_fdt
  250. /*
  251. * If returned value is 1, there is no ATAG at the location
  252. * pointed by r8. Try the typical 0x100 offset from start
  253. * of RAM and hope for the best.
  254. */
  255. cmp r0, #1
  256. sub r0, r4, #TEXT_OFFSET
  257. bic r0, r0, #1
  258. add r0, r0, #0x100
  259. mov r1, r6
  260. sub r2, sp, r6
  261. bleq atags_to_fdt
  262. ldmfd sp!, {r0-r3, ip, lr}
  263. sub sp, sp, #0x10000
  264. #endif
  265. mov r8, r6 @ use the appended device tree
  266. /*
  267. * Make sure that the DTB doesn't end up in the final
  268. * kernel's .bss area. To do so, we adjust the decompressed
  269. * kernel size to compensate if that .bss size is larger
  270. * than the relocated code.
  271. */
  272. ldr r5, =_kernel_bss_size
  273. adr r1, wont_overwrite
  274. sub r1, r6, r1
  275. subs r1, r5, r1
  276. addhi r9, r9, r1
  277. /* Get the dtb's size */
  278. ldr r5, [r6, #4]
  279. #ifndef __ARMEB__
  280. /* convert r5 (dtb size) to little endian */
  281. eor r1, r5, r5, ror #16
  282. bic r1, r1, #0x00ff0000
  283. mov r5, r5, ror #8
  284. eor r5, r5, r1, lsr #8
  285. #endif
  286. /* preserve 64-bit alignment */
  287. add r5, r5, #7
  288. bic r5, r5, #7
  289. /* relocate some pointers past the appended dtb */
  290. add r6, r6, r5
  291. add r10, r10, r5
  292. add sp, sp, r5
  293. dtb_check_done:
  294. #endif
  295. /*
  296. * Check to see if we will overwrite ourselves.
  297. * r4 = final kernel address (possibly with LSB set)
  298. * r9 = size of decompressed image
  299. * r10 = end of this image, including bss/stack/malloc space if non XIP
  300. * We basically want:
  301. * r4 - 16k page directory >= r10 -> OK
  302. * r4 + image length <= address of wont_overwrite -> OK
  303. * Note: the possible LSB in r4 is harmless here.
  304. */
  305. add r10, r10, #16384
  306. cmp r4, r10
  307. bhs wont_overwrite
  308. add r10, r4, r9
  309. adr r9, wont_overwrite
  310. cmp r10, r9
  311. bls wont_overwrite
  312. /*
  313. * Relocate ourselves past the end of the decompressed kernel.
  314. * r6 = _edata
  315. * r10 = end of the decompressed kernel
  316. * Because we always copy ahead, we need to do it from the end and go
  317. * backward in case the source and destination overlap.
  318. */
  319. /*
  320. * Bump to the next 256-byte boundary with the size of
  321. * the relocation code added. This avoids overwriting
  322. * ourself when the offset is small.
  323. */
  324. add r10, r10, #((reloc_code_end - restart + 256) & ~255)
  325. bic r10, r10, #255
  326. /* Get start of code we want to copy and align it down. */
  327. adr r5, restart
  328. bic r5, r5, #31
  329. /* Relocate the hyp vector base if necessary */
  330. #ifdef CONFIG_ARM_VIRT_EXT
  331. mrs r0, spsr
  332. and r0, r0, #MODE_MASK
  333. cmp r0, #HYP_MODE
  334. bne 1f
  335. bl __hyp_get_vectors
  336. sub r0, r0, r5
  337. add r0, r0, r10
  338. bl __hyp_set_vectors
  339. 1:
  340. #endif
  341. sub r9, r6, r5 @ size to copy
  342. add r9, r9, #31 @ rounded up to a multiple
  343. bic r9, r9, #31 @ ... of 32 bytes
  344. add r6, r9, r5
  345. add r9, r9, r10
  346. 1: ldmdb r6!, {r0 - r3, r10 - r12, lr}
  347. cmp r6, r5
  348. stmdb r9!, {r0 - r3, r10 - r12, lr}
  349. bhi 1b
  350. /* Preserve offset to relocated code. */
  351. sub r6, r9, r6
  352. #ifndef CONFIG_ZBOOT_ROM
  353. /* cache_clean_flush may use the stack, so relocate it */
  354. add sp, sp, r6
  355. #endif
  356. tst r4, #1
  357. bleq cache_clean_flush
  358. adr r0, BSYM(restart)
  359. add r0, r0, r6
  360. mov pc, r0
  361. wont_overwrite:
  362. /*
  363. * If delta is zero, we are running at the address we were linked at.
  364. * r0 = delta
  365. * r2 = BSS start
  366. * r3 = BSS end
  367. * r4 = kernel execution address (possibly with LSB set)
  368. * r5 = appended dtb size (0 if not present)
  369. * r7 = architecture ID
  370. * r8 = atags pointer
  371. * r11 = GOT start
  372. * r12 = GOT end
  373. * sp = stack pointer
  374. */
  375. orrs r1, r0, r5
  376. beq not_relocated
  377. add r11, r11, r0
  378. add r12, r12, r0
  379. #ifndef CONFIG_ZBOOT_ROM
  380. /*
  381. * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
  382. * we need to fix up pointers into the BSS region.
  383. * Note that the stack pointer has already been fixed up.
  384. */
  385. add r2, r2, r0
  386. add r3, r3, r0
  387. /*
  388. * Relocate all entries in the GOT table.
  389. * Bump bss entries to _edata + dtb size
  390. */
  391. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  392. add r1, r1, r0 @ This fixes up C references
  393. cmp r1, r2 @ if entry >= bss_start &&
  394. cmphs r3, r1 @ bss_end > entry
  395. addhi r1, r1, r5 @ entry += dtb size
  396. str r1, [r11], #4 @ next entry
  397. cmp r11, r12
  398. blo 1b
  399. /* bump our bss pointers too */
  400. add r2, r2, r5
  401. add r3, r3, r5
  402. #else
  403. /*
  404. * Relocate entries in the GOT table. We only relocate
  405. * the entries that are outside the (relocated) BSS region.
  406. */
  407. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  408. cmp r1, r2 @ entry < bss_start ||
  409. cmphs r3, r1 @ _end < entry
  410. addlo r1, r1, r0 @ table. This fixes up the
  411. str r1, [r11], #4 @ C references.
  412. cmp r11, r12
  413. blo 1b
  414. #endif
  415. not_relocated: mov r0, #0
  416. 1: str r0, [r2], #4 @ clear bss
  417. str r0, [r2], #4
  418. str r0, [r2], #4
  419. str r0, [r2], #4
  420. cmp r2, r3
  421. blo 1b
  422. /*
  423. * Did we skip the cache setup earlier?
  424. * That is indicated by the LSB in r4.
  425. * Do it now if so.
  426. */
  427. tst r4, #1
  428. bic r4, r4, #1
  429. blne cache_on
  430. /*
  431. * The C runtime environment should now be setup sufficiently.
  432. * Set up some pointers, and start decompressing.
  433. * r4 = kernel execution address
  434. * r7 = architecture ID
  435. * r8 = atags pointer
  436. */
  437. mov r0, r4
  438. mov r1, sp @ malloc space above stack
  439. add r2, sp, #0x10000 @ 64k max
  440. mov r3, r7
  441. bl decompress_kernel
  442. bl cache_clean_flush
  443. bl cache_off
  444. mov r1, r7 @ restore architecture number
  445. mov r2, r8 @ restore atags pointer
  446. #ifdef CONFIG_ARM_VIRT_EXT
  447. mrs r0, spsr @ Get saved CPU boot mode
  448. and r0, r0, #MODE_MASK
  449. cmp r0, #HYP_MODE @ if not booted in HYP mode...
  450. bne __enter_kernel @ boot kernel directly
  451. adr r12, .L__hyp_reentry_vectors_offset
  452. ldr r0, [r12]
  453. add r0, r0, r12
  454. bl __hyp_set_vectors
  455. __HVC(0) @ otherwise bounce to hyp mode
  456. b . @ should never be reached
  457. .align 2
  458. .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
  459. #else
  460. b __enter_kernel
  461. #endif
  462. .align 2
  463. .type LC0, #object
  464. LC0: .word LC0 @ r1
  465. .word __bss_start @ r2
  466. .word _end @ r3
  467. .word _edata @ r6
  468. .word input_data_end - 4 @ r10 (inflated size location)
  469. .word _got_start @ r11
  470. .word _got_end @ ip
  471. .word .L_user_stack_end @ sp
  472. .word _end - restart + 16384 + 1024*1024
  473. .size LC0, . - LC0
  474. #ifdef CONFIG_ARCH_RPC
  475. .globl params
  476. params: ldr r0, =0x10000100 @ params_phys for RPC
  477. mov pc, lr
  478. .ltorg
  479. .align
  480. #endif
  481. /*
  482. * Turn on the cache. We need to setup some page tables so that we
  483. * can have both the I and D caches on.
  484. *
  485. * We place the page tables 16k down from the kernel execution address,
  486. * and we hope that nothing else is using it. If we're using it, we
  487. * will go pop!
  488. *
  489. * On entry,
  490. * r4 = kernel execution address
  491. * r7 = architecture number
  492. * r8 = atags pointer
  493. * On exit,
  494. * r0, r1, r2, r3, r9, r10, r12 corrupted
  495. * This routine must preserve:
  496. * r4, r7, r8
  497. */
  498. .align 5
  499. cache_on: mov r3, #8 @ cache_on function
  500. b call_cache_fn
  501. /*
  502. * Initialize the highest priority protection region, PR7
  503. * to cover all 32bit address and cacheable and bufferable.
  504. */
  505. __armv4_mpu_cache_on:
  506. mov r0, #0x3f @ 4G, the whole
  507. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  508. mcr p15, 0, r0, c6, c7, 1
  509. mov r0, #0x80 @ PR7
  510. mcr p15, 0, r0, c2, c0, 0 @ D-cache on
  511. mcr p15, 0, r0, c2, c0, 1 @ I-cache on
  512. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  513. mov r0, #0xc000
  514. mcr p15, 0, r0, c5, c0, 1 @ I-access permission
  515. mcr p15, 0, r0, c5, c0, 0 @ D-access permission
  516. mov r0, #0
  517. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  518. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  519. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  520. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  521. @ ...I .... ..D. WC.M
  522. orr r0, r0, #0x002d @ .... .... ..1. 11.1
  523. orr r0, r0, #0x1000 @ ...1 .... .... ....
  524. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  525. mov r0, #0
  526. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  527. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  528. mov pc, lr
  529. __armv3_mpu_cache_on:
  530. mov r0, #0x3f @ 4G, the whole
  531. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  532. mov r0, #0x80 @ PR7
  533. mcr p15, 0, r0, c2, c0, 0 @ cache on
  534. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  535. mov r0, #0xc000
  536. mcr p15, 0, r0, c5, c0, 0 @ access permission
  537. mov r0, #0
  538. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  539. /*
  540. * ?? ARMv3 MMU does not allow reading the control register,
  541. * does this really work on ARMv3 MPU?
  542. */
  543. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  544. @ .... .... .... WC.M
  545. orr r0, r0, #0x000d @ .... .... .... 11.1
  546. /* ?? this overwrites the value constructed above? */
  547. mov r0, #0
  548. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  549. /* ?? invalidate for the second time? */
  550. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  551. mov pc, lr
  552. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  553. #define CB_BITS 0x08
  554. #else
  555. #define CB_BITS 0x0c
  556. #endif
  557. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  558. bic r3, r3, #0xff @ Align the pointer
  559. bic r3, r3, #0x3f00
  560. /*
  561. * Initialise the page tables, turning on the cacheable and bufferable
  562. * bits for the RAM area only.
  563. */
  564. mov r0, r3
  565. mov r9, r0, lsr #18
  566. mov r9, r9, lsl #18 @ start of RAM
  567. add r10, r9, #0x10000000 @ a reasonable RAM size
  568. mov r1, #0x12 @ XN|U + section mapping
  569. orr r1, r1, #3 << 10 @ AP=11
  570. add r2, r3, #16384
  571. 1: cmp r1, r9 @ if virt > start of RAM
  572. cmphs r10, r1 @ && end of RAM > virt
  573. bic r1, r1, #0x1c @ clear XN|U + C + B
  574. orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
  575. orrhs r1, r1, r6 @ set RAM section settings
  576. str r1, [r0], #4 @ 1:1 mapping
  577. add r1, r1, #1048576
  578. teq r0, r2
  579. bne 1b
  580. /*
  581. * If ever we are running from Flash, then we surely want the cache
  582. * to be enabled also for our execution instance... We map 2MB of it
  583. * so there is no map overlap problem for up to 1 MB compressed kernel.
  584. * If the execution is in RAM then we would only be duplicating the above.
  585. */
  586. orr r1, r6, #0x04 @ ensure B is set for this
  587. orr r1, r1, #3 << 10
  588. mov r2, pc
  589. mov r2, r2, lsr #20
  590. orr r1, r1, r2, lsl #20
  591. add r0, r3, r2, lsl #2
  592. str r1, [r0], #4
  593. add r1, r1, #1048576
  594. str r1, [r0]
  595. mov pc, lr
  596. ENDPROC(__setup_mmu)
  597. @ Enable unaligned access on v6, to allow better code generation
  598. @ for the decompressor C code:
  599. __armv6_mmu_cache_on:
  600. mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
  601. bic r0, r0, #2 @ A (no unaligned access fault)
  602. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  603. mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
  604. b __armv4_mmu_cache_on
  605. __arm926ejs_mmu_cache_on:
  606. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  607. mov r0, #4 @ put dcache in WT mode
  608. mcr p15, 7, r0, c15, c0, 0
  609. #endif
  610. __armv4_mmu_cache_on:
  611. mov r12, lr
  612. #ifdef CONFIG_MMU
  613. mov r6, #CB_BITS | 0x12 @ U
  614. bl __setup_mmu
  615. mov r0, #0
  616. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  617. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  618. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  619. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  620. orr r0, r0, #0x0030
  621. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  622. bl __common_mmu_cache_on
  623. mov r0, #0
  624. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  625. #endif
  626. mov pc, r12
  627. __armv7_mmu_cache_on:
  628. mov r12, lr
  629. #ifdef CONFIG_MMU
  630. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  631. tst r11, #0xf @ VMSA
  632. movne r6, #CB_BITS | 0x02 @ !XN
  633. blne __setup_mmu
  634. mov r0, #0
  635. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  636. tst r11, #0xf @ VMSA
  637. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  638. #endif
  639. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  640. bic r0, r0, #1 << 28 @ clear SCTLR.TRE
  641. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  642. orr r0, r0, #0x003c @ write buffer
  643. bic r0, r0, #2 @ A (no unaligned access fault)
  644. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  645. @ (needed for ARM1176)
  646. #ifdef CONFIG_MMU
  647. ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
  648. mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
  649. orrne r0, r0, #1 @ MMU enabled
  650. movne r1, #0xfffffffd @ domain 0 = client
  651. bic r6, r6, #1 << 31 @ 32-bit translation system
  652. bic r6, r6, #3 << 0 @ use only ttbr0
  653. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  654. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  655. mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
  656. #endif
  657. mcr p15, 0, r0, c7, c5, 4 @ ISB
  658. mcr p15, 0, r0, c1, c0, 0 @ load control register
  659. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  660. mov r0, #0
  661. mcr p15, 0, r0, c7, c5, 4 @ ISB
  662. mov pc, r12
  663. __fa526_cache_on:
  664. mov r12, lr
  665. mov r6, #CB_BITS | 0x12 @ U
  666. bl __setup_mmu
  667. mov r0, #0
  668. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  669. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  670. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  671. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  672. orr r0, r0, #0x1000 @ I-cache enable
  673. bl __common_mmu_cache_on
  674. mov r0, #0
  675. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  676. mov pc, r12
  677. __common_mmu_cache_on:
  678. #ifndef CONFIG_THUMB2_KERNEL
  679. #ifndef DEBUG
  680. orr r0, r0, #0x000d @ Write buffer, mmu
  681. #endif
  682. mov r1, #-1
  683. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  684. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  685. b 1f
  686. .align 5 @ cache line aligned
  687. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  688. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  689. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  690. #endif
  691. #define PROC_ENTRY_SIZE (4*5)
  692. /*
  693. * Here follow the relocatable cache support functions for the
  694. * various processors. This is a generic hook for locating an
  695. * entry and jumping to an instruction at the specified offset
  696. * from the start of the block. Please note this is all position
  697. * independent code.
  698. *
  699. * r1 = corrupted
  700. * r2 = corrupted
  701. * r3 = block offset
  702. * r9 = corrupted
  703. * r12 = corrupted
  704. */
  705. call_cache_fn: adr r12, proc_types
  706. #ifdef CONFIG_CPU_CP15
  707. mrc p15, 0, r9, c0, c0 @ get processor ID
  708. #else
  709. ldr r9, =CONFIG_PROCESSOR_ID
  710. #endif
  711. 1: ldr r1, [r12, #0] @ get value
  712. ldr r2, [r12, #4] @ get mask
  713. eor r1, r1, r9 @ (real ^ match)
  714. tst r1, r2 @ & mask
  715. ARM( addeq pc, r12, r3 ) @ call cache function
  716. THUMB( addeq r12, r3 )
  717. THUMB( moveq pc, r12 ) @ call cache function
  718. add r12, r12, #PROC_ENTRY_SIZE
  719. b 1b
  720. /*
  721. * Table for cache operations. This is basically:
  722. * - CPU ID match
  723. * - CPU ID mask
  724. * - 'cache on' method instruction
  725. * - 'cache off' method instruction
  726. * - 'cache flush' method instruction
  727. *
  728. * We match an entry using: ((real_id ^ match) & mask) == 0
  729. *
  730. * Writethrough caches generally only need 'on' and 'off'
  731. * methods. Writeback caches _must_ have the flush method
  732. * defined.
  733. */
  734. .align 2
  735. .type proc_types,#object
  736. proc_types:
  737. .word 0x41000000 @ old ARM ID
  738. .word 0xff00f000
  739. mov pc, lr
  740. THUMB( nop )
  741. mov pc, lr
  742. THUMB( nop )
  743. mov pc, lr
  744. THUMB( nop )
  745. .word 0x41007000 @ ARM7/710
  746. .word 0xfff8fe00
  747. mov pc, lr
  748. THUMB( nop )
  749. mov pc, lr
  750. THUMB( nop )
  751. mov pc, lr
  752. THUMB( nop )
  753. .word 0x41807200 @ ARM720T (writethrough)
  754. .word 0xffffff00
  755. W(b) __armv4_mmu_cache_on
  756. W(b) __armv4_mmu_cache_off
  757. mov pc, lr
  758. THUMB( nop )
  759. .word 0x41007400 @ ARM74x
  760. .word 0xff00ff00
  761. W(b) __armv3_mpu_cache_on
  762. W(b) __armv3_mpu_cache_off
  763. W(b) __armv3_mpu_cache_flush
  764. .word 0x41009400 @ ARM94x
  765. .word 0xff00ff00
  766. W(b) __armv4_mpu_cache_on
  767. W(b) __armv4_mpu_cache_off
  768. W(b) __armv4_mpu_cache_flush
  769. .word 0x41069260 @ ARM926EJ-S (v5TEJ)
  770. .word 0xff0ffff0
  771. W(b) __arm926ejs_mmu_cache_on
  772. W(b) __armv4_mmu_cache_off
  773. W(b) __armv5tej_mmu_cache_flush
  774. .word 0x00007000 @ ARM7 IDs
  775. .word 0x0000f000
  776. mov pc, lr
  777. THUMB( nop )
  778. mov pc, lr
  779. THUMB( nop )
  780. mov pc, lr
  781. THUMB( nop )
  782. @ Everything from here on will be the new ID system.
  783. .word 0x4401a100 @ sa110 / sa1100
  784. .word 0xffffffe0
  785. W(b) __armv4_mmu_cache_on
  786. W(b) __armv4_mmu_cache_off
  787. W(b) __armv4_mmu_cache_flush
  788. .word 0x6901b110 @ sa1110
  789. .word 0xfffffff0
  790. W(b) __armv4_mmu_cache_on
  791. W(b) __armv4_mmu_cache_off
  792. W(b) __armv4_mmu_cache_flush
  793. .word 0x56056900
  794. .word 0xffffff00 @ PXA9xx
  795. W(b) __armv4_mmu_cache_on
  796. W(b) __armv4_mmu_cache_off
  797. W(b) __armv4_mmu_cache_flush
  798. .word 0x56158000 @ PXA168
  799. .word 0xfffff000
  800. W(b) __armv4_mmu_cache_on
  801. W(b) __armv4_mmu_cache_off
  802. W(b) __armv5tej_mmu_cache_flush
  803. .word 0x56050000 @ Feroceon
  804. .word 0xff0f0000
  805. W(b) __armv4_mmu_cache_on
  806. W(b) __armv4_mmu_cache_off
  807. W(b) __armv5tej_mmu_cache_flush
  808. #ifdef CONFIG_CPU_FEROCEON_OLD_ID
  809. /* this conflicts with the standard ARMv5TE entry */
  810. .long 0x41009260 @ Old Feroceon
  811. .long 0xff00fff0
  812. b __armv4_mmu_cache_on
  813. b __armv4_mmu_cache_off
  814. b __armv5tej_mmu_cache_flush
  815. #endif
  816. .word 0x66015261 @ FA526
  817. .word 0xff01fff1
  818. W(b) __fa526_cache_on
  819. W(b) __armv4_mmu_cache_off
  820. W(b) __fa526_cache_flush
  821. @ These match on the architecture ID
  822. .word 0x00020000 @ ARMv4T
  823. .word 0x000f0000
  824. W(b) __armv4_mmu_cache_on
  825. W(b) __armv4_mmu_cache_off
  826. W(b) __armv4_mmu_cache_flush
  827. .word 0x00050000 @ ARMv5TE
  828. .word 0x000f0000
  829. W(b) __armv4_mmu_cache_on
  830. W(b) __armv4_mmu_cache_off
  831. W(b) __armv4_mmu_cache_flush
  832. .word 0x00060000 @ ARMv5TEJ
  833. .word 0x000f0000
  834. W(b) __armv4_mmu_cache_on
  835. W(b) __armv4_mmu_cache_off
  836. W(b) __armv5tej_mmu_cache_flush
  837. .word 0x0007b000 @ ARMv6
  838. .word 0x000ff000
  839. W(b) __armv6_mmu_cache_on
  840. W(b) __armv4_mmu_cache_off
  841. W(b) __armv6_mmu_cache_flush
  842. .word 0x000f0000 @ new CPU Id
  843. .word 0x000f0000
  844. W(b) __armv7_mmu_cache_on
  845. W(b) __armv7_mmu_cache_off
  846. W(b) __armv7_mmu_cache_flush
  847. .word 0 @ unrecognised type
  848. .word 0
  849. mov pc, lr
  850. THUMB( nop )
  851. mov pc, lr
  852. THUMB( nop )
  853. mov pc, lr
  854. THUMB( nop )
  855. .size proc_types, . - proc_types
  856. /*
  857. * If you get a "non-constant expression in ".if" statement"
  858. * error from the assembler on this line, check that you have
  859. * not accidentally written a "b" instruction where you should
  860. * have written W(b).
  861. */
  862. .if (. - proc_types) % PROC_ENTRY_SIZE != 0
  863. .error "The size of one or more proc_types entries is wrong."
  864. .endif
  865. /*
  866. * Turn off the Cache and MMU. ARMv3 does not support
  867. * reading the control register, but ARMv4 does.
  868. *
  869. * On exit,
  870. * r0, r1, r2, r3, r9, r12 corrupted
  871. * This routine must preserve:
  872. * r4, r7, r8
  873. */
  874. .align 5
  875. cache_off: mov r3, #12 @ cache_off function
  876. b call_cache_fn
  877. __armv4_mpu_cache_off:
  878. mrc p15, 0, r0, c1, c0
  879. bic r0, r0, #0x000d
  880. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  881. mov r0, #0
  882. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  883. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  884. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  885. mov pc, lr
  886. __armv3_mpu_cache_off:
  887. mrc p15, 0, r0, c1, c0
  888. bic r0, r0, #0x000d
  889. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  890. mov r0, #0
  891. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  892. mov pc, lr
  893. __armv4_mmu_cache_off:
  894. #ifdef CONFIG_MMU
  895. mrc p15, 0, r0, c1, c0
  896. bic r0, r0, #0x000d
  897. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  898. mov r0, #0
  899. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  900. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  901. #endif
  902. mov pc, lr
  903. __armv7_mmu_cache_off:
  904. mrc p15, 0, r0, c1, c0
  905. #ifdef CONFIG_MMU
  906. bic r0, r0, #0x000d
  907. #else
  908. bic r0, r0, #0x000c
  909. #endif
  910. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  911. mov r12, lr
  912. bl __armv7_mmu_cache_flush
  913. mov r0, #0
  914. #ifdef CONFIG_MMU
  915. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  916. #endif
  917. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  918. mcr p15, 0, r0, c7, c10, 4 @ DSB
  919. mcr p15, 0, r0, c7, c5, 4 @ ISB
  920. mov pc, r12
  921. /*
  922. * Clean and flush the cache to maintain consistency.
  923. *
  924. * On exit,
  925. * r1, r2, r3, r9, r10, r11, r12 corrupted
  926. * This routine must preserve:
  927. * r4, r6, r7, r8
  928. */
  929. .align 5
  930. cache_clean_flush:
  931. mov r3, #16
  932. b call_cache_fn
  933. __armv4_mpu_cache_flush:
  934. mov r2, #1
  935. mov r3, #0
  936. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  937. mov r1, #7 << 5 @ 8 segments
  938. 1: orr r3, r1, #63 << 26 @ 64 entries
  939. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  940. subs r3, r3, #1 << 26
  941. bcs 2b @ entries 63 to 0
  942. subs r1, r1, #1 << 5
  943. bcs 1b @ segments 7 to 0
  944. teq r2, #0
  945. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  946. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  947. mov pc, lr
  948. __fa526_cache_flush:
  949. mov r1, #0
  950. mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
  951. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  952. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  953. mov pc, lr
  954. __armv6_mmu_cache_flush:
  955. mov r1, #0
  956. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  957. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  958. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  959. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  960. mov pc, lr
  961. __armv7_mmu_cache_flush:
  962. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  963. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  964. mov r10, #0
  965. beq hierarchical
  966. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  967. b iflush
  968. hierarchical:
  969. mcr p15, 0, r10, c7, c10, 5 @ DMB
  970. stmfd sp!, {r0-r7, r9-r11}
  971. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  972. ands r3, r0, #0x7000000 @ extract loc from clidr
  973. mov r3, r3, lsr #23 @ left align loc bit field
  974. beq finished @ if loc is 0, then no need to clean
  975. mov r10, #0 @ start clean at cache level 0
  976. loop1:
  977. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  978. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  979. and r1, r1, #7 @ mask of the bits for current cache only
  980. cmp r1, #2 @ see what cache we have at this level
  981. blt skip @ skip if no cache, or just i-cache
  982. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  983. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  984. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  985. and r2, r1, #7 @ extract the length of the cache lines
  986. add r2, r2, #4 @ add 4 (line length offset)
  987. ldr r4, =0x3ff
  988. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  989. clz r5, r4 @ find bit position of way size increment
  990. ldr r7, =0x7fff
  991. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  992. loop2:
  993. mov r9, r4 @ create working copy of max way size
  994. loop3:
  995. ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
  996. ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
  997. THUMB( lsl r6, r9, r5 )
  998. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  999. THUMB( lsl r6, r7, r2 )
  1000. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  1001. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  1002. subs r9, r9, #1 @ decrement the way
  1003. bge loop3
  1004. subs r7, r7, #1 @ decrement the index
  1005. bge loop2
  1006. skip:
  1007. add r10, r10, #2 @ increment cache number
  1008. cmp r3, r10
  1009. bgt loop1
  1010. finished:
  1011. ldmfd sp!, {r0-r7, r9-r11}
  1012. mov r10, #0 @ swith back to cache level 0
  1013. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  1014. iflush:
  1015. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1016. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  1017. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1018. mcr p15, 0, r10, c7, c5, 4 @ ISB
  1019. mov pc, lr
  1020. __armv5tej_mmu_cache_flush:
  1021. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  1022. bne 1b
  1023. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  1024. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  1025. mov pc, lr
  1026. __armv4_mmu_cache_flush:
  1027. mov r2, #64*1024 @ default: 32K dcache size (*2)
  1028. mov r11, #32 @ default: 32 byte line size
  1029. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  1030. teq r3, r9 @ cache ID register present?
  1031. beq no_cache_id
  1032. mov r1, r3, lsr #18
  1033. and r1, r1, #7
  1034. mov r2, #1024
  1035. mov r2, r2, lsl r1 @ base dcache size *2
  1036. tst r3, #1 << 14 @ test M bit
  1037. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  1038. mov r3, r3, lsr #12
  1039. and r3, r3, #3
  1040. mov r11, #8
  1041. mov r11, r11, lsl r3 @ cache line size in bytes
  1042. no_cache_id:
  1043. mov r1, pc
  1044. bic r1, r1, #63 @ align to longest cache line
  1045. add r2, r1, r2
  1046. 1:
  1047. ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
  1048. THUMB( ldr r3, [r1] ) @ s/w flush D cache
  1049. THUMB( add r1, r1, r11 )
  1050. teq r1, r2
  1051. bne 1b
  1052. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  1053. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  1054. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1055. mov pc, lr
  1056. __armv3_mmu_cache_flush:
  1057. __armv3_mpu_cache_flush:
  1058. mov r1, #0
  1059. mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
  1060. mov pc, lr
  1061. /*
  1062. * Various debugging routines for printing hex characters and
  1063. * memory, which again must be relocatable.
  1064. */
  1065. #ifdef DEBUG
  1066. .align 2
  1067. .type phexbuf,#object
  1068. phexbuf: .space 12
  1069. .size phexbuf, . - phexbuf
  1070. @ phex corrupts {r0, r1, r2, r3}
  1071. phex: adr r3, phexbuf
  1072. mov r2, #0
  1073. strb r2, [r3, r1]
  1074. 1: subs r1, r1, #1
  1075. movmi r0, r3
  1076. bmi puts
  1077. and r2, r0, #15
  1078. mov r0, r0, lsr #4
  1079. cmp r2, #10
  1080. addge r2, r2, #7
  1081. add r2, r2, #'0'
  1082. strb r2, [r3, r1]
  1083. b 1b
  1084. @ puts corrupts {r0, r1, r2, r3}
  1085. puts: loadsp r3, r1
  1086. 1: ldrb r2, [r0], #1
  1087. teq r2, #0
  1088. moveq pc, lr
  1089. 2: writeb r2, r3
  1090. mov r1, #0x00020000
  1091. 3: subs r1, r1, #1
  1092. bne 3b
  1093. teq r2, #'\n'
  1094. moveq r2, #'\r'
  1095. beq 2b
  1096. teq r0, #0
  1097. bne 1b
  1098. mov pc, lr
  1099. @ putc corrupts {r0, r1, r2, r3}
  1100. putc:
  1101. mov r2, r0
  1102. mov r0, #0
  1103. loadsp r3, r1
  1104. b 2b
  1105. @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
  1106. memdump: mov r12, r0
  1107. mov r10, lr
  1108. mov r11, #0
  1109. 2: mov r0, r11, lsl #2
  1110. add r0, r0, r12
  1111. mov r1, #8
  1112. bl phex
  1113. mov r0, #':'
  1114. bl putc
  1115. 1: mov r0, #' '
  1116. bl putc
  1117. ldr r0, [r12, r11, lsl #2]
  1118. mov r1, #8
  1119. bl phex
  1120. and r0, r11, #7
  1121. teq r0, #3
  1122. moveq r0, #' '
  1123. bleq putc
  1124. and r0, r11, #7
  1125. add r11, r11, #1
  1126. teq r0, #7
  1127. bne 1b
  1128. mov r0, #'\n'
  1129. bl putc
  1130. cmp r11, #64
  1131. blt 2b
  1132. mov pc, r10
  1133. #endif
  1134. .ltorg
  1135. #ifdef CONFIG_ARM_VIRT_EXT
  1136. .align 5
  1137. __hyp_reentry_vectors:
  1138. W(b) . @ reset
  1139. W(b) . @ undef
  1140. W(b) . @ svc
  1141. W(b) . @ pabort
  1142. W(b) . @ dabort
  1143. W(b) __enter_kernel @ hyp
  1144. W(b) . @ irq
  1145. W(b) . @ fiq
  1146. #endif /* CONFIG_ARM_VIRT_EXT */
  1147. __enter_kernel:
  1148. mov r0, #0 @ must be 0
  1149. ARM( mov pc, r4 ) @ call kernel
  1150. THUMB( bx r4 ) @ entry point is always ARM
  1151. reloc_code_end:
  1152. .align
  1153. .section ".stack", "aw", %nobits
  1154. .L_user_stack: .space 4096
  1155. .L_user_stack_end: