head.S 30 KB

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