head.S 31 KB

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