head.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * linux/arch/arm/boot/compressed/head.S
  3. *
  4. * Copyright (C) 1996-2002 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/config.h>
  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. .macro loadsp, rb
  22. .endm
  23. .macro writeb, ch, rb
  24. mcr p14, 0, \ch, c0, c1, 0
  25. .endm
  26. #else
  27. #include <asm/arch/debug-macro.S>
  28. .macro writeb, ch, rb
  29. senduart \ch, \rb
  30. .endm
  31. #if defined(CONFIG_ARCH_SA1100)
  32. .macro loadsp, rb
  33. mov \rb, #0x80000000 @ physical base address
  34. #ifdef CONFIG_DEBUG_LL_SER3
  35. add \rb, \rb, #0x00050000 @ Ser3
  36. #else
  37. add \rb, \rb, #0x00010000 @ Ser1
  38. #endif
  39. .endm
  40. #elif defined(CONFIG_ARCH_IOP331)
  41. .macro loadsp, rb
  42. mov \rb, #0xff000000
  43. orr \rb, \rb, #0x00ff0000
  44. orr \rb, \rb, #0x0000f700 @ location of the UART
  45. .endm
  46. #elif defined(CONFIG_ARCH_S3C2410)
  47. .macro loadsp, rb
  48. mov \rb, #0x50000000
  49. add \rb, \rb, #0x4000 * CONFIG_S3C2410_LOWLEVEL_UART_PORT
  50. .endm
  51. #else
  52. .macro loadsp, rb
  53. addruart \rb
  54. .endm
  55. #endif
  56. #endif
  57. #endif
  58. .macro kputc,val
  59. mov r0, \val
  60. bl putc
  61. .endm
  62. .macro kphex,val,len
  63. mov r0, \val
  64. mov r1, #\len
  65. bl phex
  66. .endm
  67. .macro debug_reloc_start
  68. #ifdef DEBUG
  69. kputc #'\n'
  70. kphex r6, 8 /* processor id */
  71. kputc #':'
  72. kphex r7, 8 /* architecture id */
  73. kputc #':'
  74. mrc p15, 0, r0, c1, c0
  75. kphex r0, 8 /* control reg */
  76. kputc #'\n'
  77. kphex r5, 8 /* decompressed kernel start */
  78. kputc #'-'
  79. kphex r9, 8 /* decompressed kernel end */
  80. kputc #'>'
  81. kphex r4, 8 /* kernel execution address */
  82. kputc #'\n'
  83. #endif
  84. .endm
  85. .macro debug_reloc_end
  86. #ifdef DEBUG
  87. kphex r5, 8 /* end of kernel */
  88. kputc #'\n'
  89. mov r0, r4
  90. bl memdump /* dump 256 bytes at start of kernel */
  91. #endif
  92. .endm
  93. .section ".start", #alloc, #execinstr
  94. /*
  95. * sort out different calling conventions
  96. */
  97. .align
  98. start:
  99. .type start,#function
  100. .rept 8
  101. mov r0, r0
  102. .endr
  103. b 1f
  104. .word 0x016f2818 @ Magic numbers to help the loader
  105. .word start @ absolute load/run zImage address
  106. .word _edata @ zImage end address
  107. 1: mov r7, r1 @ save architecture ID
  108. mov r8, r2 @ save atags pointer
  109. #ifndef __ARM_ARCH_2__
  110. /*
  111. * Booting from Angel - need to enter SVC mode and disable
  112. * FIQs/IRQs (numeric definitions from angel arm.h source).
  113. * We only do this if we were in user mode on entry.
  114. */
  115. mrs r2, cpsr @ get current mode
  116. tst r2, #3 @ not user?
  117. bne not_angel
  118. mov r0, #0x17 @ angel_SWIreason_EnterSVC
  119. swi 0x123456 @ angel_SWI_ARM
  120. not_angel:
  121. mrs r2, cpsr @ turn off interrupts to
  122. orr r2, r2, #0xc0 @ prevent angel from running
  123. msr cpsr_c, r2
  124. #else
  125. teqp pc, #0x0c000003 @ turn off interrupts
  126. #endif
  127. /*
  128. * Note that some cache flushing and other stuff may
  129. * be needed here - is there an Angel SWI call for this?
  130. */
  131. /*
  132. * some architecture specific code can be inserted
  133. * by the linker here, but it should preserve r7, r8, and r9.
  134. */
  135. .text
  136. adr r0, LC0
  137. ldmia r0, {r1, r2, r3, r4, r5, r6, ip, sp}
  138. subs r0, r0, r1 @ calculate the delta offset
  139. @ if delta is zero, we are
  140. beq not_relocated @ running at the address we
  141. @ were linked at.
  142. /*
  143. * We're running at a different address. We need to fix
  144. * up various pointers:
  145. * r5 - zImage base address
  146. * r6 - GOT start
  147. * ip - GOT end
  148. */
  149. add r5, r5, r0
  150. add r6, r6, r0
  151. add ip, ip, r0
  152. #ifndef CONFIG_ZBOOT_ROM
  153. /*
  154. * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
  155. * we need to fix up pointers into the BSS region.
  156. * r2 - BSS start
  157. * r3 - BSS end
  158. * sp - stack pointer
  159. */
  160. add r2, r2, r0
  161. add r3, r3, r0
  162. add sp, sp, r0
  163. /*
  164. * Relocate all entries in the GOT table.
  165. */
  166. 1: ldr r1, [r6, #0] @ relocate entries in the GOT
  167. add r1, r1, r0 @ table. This fixes up the
  168. str r1, [r6], #4 @ C references.
  169. cmp r6, ip
  170. blo 1b
  171. #else
  172. /*
  173. * Relocate entries in the GOT table. We only relocate
  174. * the entries that are outside the (relocated) BSS region.
  175. */
  176. 1: ldr r1, [r6, #0] @ relocate entries in the GOT
  177. cmp r1, r2 @ entry < bss_start ||
  178. cmphs r3, r1 @ _end < entry
  179. addlo r1, r1, r0 @ table. This fixes up the
  180. str r1, [r6], #4 @ C references.
  181. cmp r6, ip
  182. blo 1b
  183. #endif
  184. not_relocated: mov r0, #0
  185. 1: str r0, [r2], #4 @ clear bss
  186. str r0, [r2], #4
  187. str r0, [r2], #4
  188. str r0, [r2], #4
  189. cmp r2, r3
  190. blo 1b
  191. /*
  192. * The C runtime environment should now be setup
  193. * sufficiently. Turn the cache on, set up some
  194. * pointers, and start decompressing.
  195. */
  196. bl cache_on
  197. mov r1, sp @ malloc space above stack
  198. add r2, sp, #0x10000 @ 64k max
  199. /*
  200. * Check to see if we will overwrite ourselves.
  201. * r4 = final kernel address
  202. * r5 = start of this image
  203. * r2 = end of malloc space (and therefore this image)
  204. * We basically want:
  205. * r4 >= r2 -> OK
  206. * r4 + image length <= r5 -> OK
  207. */
  208. cmp r4, r2
  209. bhs wont_overwrite
  210. add r0, r4, #4096*1024 @ 4MB largest kernel size
  211. cmp r0, r5
  212. bls wont_overwrite
  213. mov r5, r2 @ decompress after malloc space
  214. mov r0, r5
  215. mov r3, r7
  216. bl decompress_kernel
  217. add r0, r0, #127
  218. bic r0, r0, #127 @ align the kernel length
  219. /*
  220. * r0 = decompressed kernel length
  221. * r1-r3 = unused
  222. * r4 = kernel execution address
  223. * r5 = decompressed kernel start
  224. * r6 = processor ID
  225. * r7 = architecture ID
  226. * r8 = atags pointer
  227. * r9-r14 = corrupted
  228. */
  229. add r1, r5, r0 @ end of decompressed kernel
  230. adr r2, reloc_start
  231. ldr r3, LC1
  232. add r3, r2, r3
  233. 1: ldmia r2!, {r9 - r14} @ copy relocation code
  234. stmia r1!, {r9 - r14}
  235. ldmia r2!, {r9 - r14}
  236. stmia r1!, {r9 - r14}
  237. cmp r2, r3
  238. blo 1b
  239. bl cache_clean_flush
  240. add pc, r5, r0 @ call relocation code
  241. /*
  242. * We're not in danger of overwriting ourselves. Do this the simple way.
  243. *
  244. * r4 = kernel execution address
  245. * r7 = architecture ID
  246. */
  247. wont_overwrite: mov r0, r4
  248. mov r3, r7
  249. bl decompress_kernel
  250. b call_kernel
  251. .type LC0, #object
  252. LC0: .word LC0 @ r1
  253. .word __bss_start @ r2
  254. .word _end @ r3
  255. .word zreladdr @ r4
  256. .word _start @ r5
  257. .word _got_start @ r6
  258. .word _got_end @ ip
  259. .word user_stack+4096 @ sp
  260. LC1: .word reloc_end - reloc_start
  261. .size LC0, . - LC0
  262. #ifdef CONFIG_ARCH_RPC
  263. .globl params
  264. params: ldr r0, =params_phys
  265. mov pc, lr
  266. .ltorg
  267. .align
  268. #endif
  269. /*
  270. * Turn on the cache. We need to setup some page tables so that we
  271. * can have both the I and D caches on.
  272. *
  273. * We place the page tables 16k down from the kernel execution address,
  274. * and we hope that nothing else is using it. If we're using it, we
  275. * will go pop!
  276. *
  277. * On entry,
  278. * r4 = kernel execution address
  279. * r6 = processor ID
  280. * r7 = architecture number
  281. * r8 = atags pointer
  282. * r9 = run-time address of "start" (???)
  283. * On exit,
  284. * r1, r2, r3, r9, r10, r12 corrupted
  285. * This routine must preserve:
  286. * r4, r5, r6, r7, r8
  287. */
  288. .align 5
  289. cache_on: mov r3, #8 @ cache_on function
  290. b call_cache_fn
  291. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  292. bic r3, r3, #0xff @ Align the pointer
  293. bic r3, r3, #0x3f00
  294. /*
  295. * Initialise the page tables, turning on the cacheable and bufferable
  296. * bits for the RAM area only.
  297. */
  298. mov r0, r3
  299. mov r9, r0, lsr #18
  300. mov r9, r9, lsl #18 @ start of RAM
  301. add r10, r9, #0x10000000 @ a reasonable RAM size
  302. mov r1, #0x12
  303. orr r1, r1, #3 << 10
  304. add r2, r3, #16384
  305. 1: cmp r1, r9 @ if virt > start of RAM
  306. orrhs r1, r1, #0x0c @ set cacheable, bufferable
  307. cmp r1, r10 @ if virt > end of RAM
  308. bichs r1, r1, #0x0c @ clear cacheable, bufferable
  309. str r1, [r0], #4 @ 1:1 mapping
  310. add r1, r1, #1048576
  311. teq r0, r2
  312. bne 1b
  313. /*
  314. * If ever we are running from Flash, then we surely want the cache
  315. * to be enabled also for our execution instance... We map 2MB of it
  316. * so there is no map overlap problem for up to 1 MB compressed kernel.
  317. * If the execution is in RAM then we would only be duplicating the above.
  318. */
  319. mov r1, #0x1e
  320. orr r1, r1, #3 << 10
  321. mov r2, pc, lsr #20
  322. orr r1, r1, r2, lsl #20
  323. add r0, r3, r2, lsl #2
  324. str r1, [r0], #4
  325. add r1, r1, #1048576
  326. str r1, [r0]
  327. mov pc, lr
  328. __armv4_cache_on:
  329. mov r12, lr
  330. bl __setup_mmu
  331. mov r0, #0
  332. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  333. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  334. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  335. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  336. orr r0, r0, #0x0030
  337. bl __common_cache_on
  338. mov r0, #0
  339. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  340. mov pc, r12
  341. __arm6_cache_on:
  342. mov r12, lr
  343. bl __setup_mmu
  344. mov r0, #0
  345. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  346. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  347. mov r0, #0x30
  348. bl __common_cache_on
  349. mov r0, #0
  350. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  351. mov pc, r12
  352. __common_cache_on:
  353. #ifndef DEBUG
  354. orr r0, r0, #0x000d @ Write buffer, mmu
  355. #endif
  356. mov r1, #-1
  357. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  358. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  359. mcr p15, 0, r0, c1, c0, 0 @ load control register
  360. mov pc, lr
  361. /*
  362. * All code following this line is relocatable. It is relocated by
  363. * the above code to the end of the decompressed kernel image and
  364. * executed there. During this time, we have no stacks.
  365. *
  366. * r0 = decompressed kernel length
  367. * r1-r3 = unused
  368. * r4 = kernel execution address
  369. * r5 = decompressed kernel start
  370. * r6 = processor ID
  371. * r7 = architecture ID
  372. * r8 = atags pointer
  373. * r9-r14 = corrupted
  374. */
  375. .align 5
  376. reloc_start: add r9, r5, r0
  377. debug_reloc_start
  378. mov r1, r4
  379. 1:
  380. .rept 4
  381. ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel
  382. stmia r1!, {r0, r2, r3, r10 - r14}
  383. .endr
  384. cmp r5, r9
  385. blo 1b
  386. debug_reloc_end
  387. call_kernel: bl cache_clean_flush
  388. bl cache_off
  389. mov r0, #0 @ must be zero
  390. mov r1, r7 @ restore architecture number
  391. mov r2, r8 @ restore atags pointer
  392. mov pc, r4 @ call kernel
  393. /*
  394. * Here follow the relocatable cache support functions for the
  395. * various processors. This is a generic hook for locating an
  396. * entry and jumping to an instruction at the specified offset
  397. * from the start of the block. Please note this is all position
  398. * independent code.
  399. *
  400. * r1 = corrupted
  401. * r2 = corrupted
  402. * r3 = block offset
  403. * r6 = corrupted
  404. * r12 = corrupted
  405. */
  406. call_cache_fn: adr r12, proc_types
  407. mrc p15, 0, r6, c0, c0 @ get processor ID
  408. 1: ldr r1, [r12, #0] @ get value
  409. ldr r2, [r12, #4] @ get mask
  410. eor r1, r1, r6 @ (real ^ match)
  411. tst r1, r2 @ & mask
  412. addeq pc, r12, r3 @ call cache function
  413. add r12, r12, #4*5
  414. b 1b
  415. /*
  416. * Table for cache operations. This is basically:
  417. * - CPU ID match
  418. * - CPU ID mask
  419. * - 'cache on' method instruction
  420. * - 'cache off' method instruction
  421. * - 'cache flush' method instruction
  422. *
  423. * We match an entry using: ((real_id ^ match) & mask) == 0
  424. *
  425. * Writethrough caches generally only need 'on' and 'off'
  426. * methods. Writeback caches _must_ have the flush method
  427. * defined.
  428. */
  429. .type proc_types,#object
  430. proc_types:
  431. .word 0x41560600 @ ARM6/610
  432. .word 0xffffffe0
  433. b __arm6_cache_off @ works, but slow
  434. b __arm6_cache_off
  435. mov pc, lr
  436. @ b __arm6_cache_on @ untested
  437. @ b __arm6_cache_off
  438. @ b __armv3_cache_flush
  439. .word 0x00000000 @ old ARM ID
  440. .word 0x0000f000
  441. mov pc, lr
  442. mov pc, lr
  443. mov pc, lr
  444. .word 0x41007000 @ ARM7/710
  445. .word 0xfff8fe00
  446. b __arm7_cache_off
  447. b __arm7_cache_off
  448. mov pc, lr
  449. .word 0x41807200 @ ARM720T (writethrough)
  450. .word 0xffffff00
  451. b __armv4_cache_on
  452. b __armv4_cache_off
  453. mov pc, lr
  454. .word 0x00007000 @ ARM7 IDs
  455. .word 0x0000f000
  456. mov pc, lr
  457. mov pc, lr
  458. mov pc, lr
  459. @ Everything from here on will be the new ID system.
  460. .word 0x4401a100 @ sa110 / sa1100
  461. .word 0xffffffe0
  462. b __armv4_cache_on
  463. b __armv4_cache_off
  464. b __armv4_cache_flush
  465. .word 0x6901b110 @ sa1110
  466. .word 0xfffffff0
  467. b __armv4_cache_on
  468. b __armv4_cache_off
  469. b __armv4_cache_flush
  470. @ These match on the architecture ID
  471. .word 0x00020000 @ ARMv4T
  472. .word 0x000f0000
  473. b __armv4_cache_on
  474. b __armv4_cache_off
  475. b __armv4_cache_flush
  476. .word 0x00050000 @ ARMv5TE
  477. .word 0x000f0000
  478. b __armv4_cache_on
  479. b __armv4_cache_off
  480. b __armv4_cache_flush
  481. .word 0x00060000 @ ARMv5TEJ
  482. .word 0x000f0000
  483. b __armv4_cache_on
  484. b __armv4_cache_off
  485. b __armv4_cache_flush
  486. .word 0x00070000 @ ARMv6
  487. .word 0x000f0000
  488. b __armv4_cache_on
  489. b __armv4_cache_off
  490. b __armv6_cache_flush
  491. .word 0 @ unrecognised type
  492. .word 0
  493. mov pc, lr
  494. mov pc, lr
  495. mov pc, lr
  496. .size proc_types, . - proc_types
  497. /*
  498. * Turn off the Cache and MMU. ARMv3 does not support
  499. * reading the control register, but ARMv4 does.
  500. *
  501. * On entry, r6 = processor ID
  502. * On exit, r0, r1, r2, r3, r12 corrupted
  503. * This routine must preserve: r4, r6, r7
  504. */
  505. .align 5
  506. cache_off: mov r3, #12 @ cache_off function
  507. b call_cache_fn
  508. __armv4_cache_off:
  509. mrc p15, 0, r0, c1, c0
  510. bic r0, r0, #0x000d
  511. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  512. mov r0, #0
  513. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  514. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  515. mov pc, lr
  516. __arm6_cache_off:
  517. mov r0, #0x00000030 @ ARM6 control reg.
  518. b __armv3_cache_off
  519. __arm7_cache_off:
  520. mov r0, #0x00000070 @ ARM7 control reg.
  521. b __armv3_cache_off
  522. __armv3_cache_off:
  523. mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
  524. mov r0, #0
  525. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  526. mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
  527. mov pc, lr
  528. /*
  529. * Clean and flush the cache to maintain consistency.
  530. *
  531. * On entry,
  532. * r6 = processor ID
  533. * On exit,
  534. * r1, r2, r3, r11, r12 corrupted
  535. * This routine must preserve:
  536. * r0, r4, r5, r6, r7
  537. */
  538. .align 5
  539. cache_clean_flush:
  540. mov r3, #16
  541. b call_cache_fn
  542. __armv6_cache_flush:
  543. mov r1, #0
  544. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  545. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  546. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  547. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  548. mov pc, lr
  549. __armv4_cache_flush:
  550. mov r2, #64*1024 @ default: 32K dcache size (*2)
  551. mov r11, #32 @ default: 32 byte line size
  552. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  553. teq r3, r6 @ cache ID register present?
  554. beq no_cache_id
  555. mov r1, r3, lsr #18
  556. and r1, r1, #7
  557. mov r2, #1024
  558. mov r2, r2, lsl r1 @ base dcache size *2
  559. tst r3, #1 << 14 @ test M bit
  560. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  561. mov r3, r3, lsr #12
  562. and r3, r3, #3
  563. mov r11, #8
  564. mov r11, r11, lsl r3 @ cache line size in bytes
  565. no_cache_id:
  566. bic r1, pc, #63 @ align to longest cache line
  567. add r2, r1, r2
  568. 1: ldr r3, [r1], r11 @ s/w flush D cache
  569. teq r1, r2
  570. bne 1b
  571. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  572. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  573. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  574. mov pc, lr
  575. __armv3_cache_flush:
  576. mov r1, #0
  577. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  578. mov pc, lr
  579. /*
  580. * Various debugging routines for printing hex characters and
  581. * memory, which again must be relocatable.
  582. */
  583. #ifdef DEBUG
  584. .type phexbuf,#object
  585. phexbuf: .space 12
  586. .size phexbuf, . - phexbuf
  587. phex: adr r3, phexbuf
  588. mov r2, #0
  589. strb r2, [r3, r1]
  590. 1: subs r1, r1, #1
  591. movmi r0, r3
  592. bmi puts
  593. and r2, r0, #15
  594. mov r0, r0, lsr #4
  595. cmp r2, #10
  596. addge r2, r2, #7
  597. add r2, r2, #'0'
  598. strb r2, [r3, r1]
  599. b 1b
  600. puts: loadsp r3
  601. 1: ldrb r2, [r0], #1
  602. teq r2, #0
  603. moveq pc, lr
  604. 2: writeb r2, r3
  605. mov r1, #0x00020000
  606. 3: subs r1, r1, #1
  607. bne 3b
  608. teq r2, #'\n'
  609. moveq r2, #'\r'
  610. beq 2b
  611. teq r0, #0
  612. bne 1b
  613. mov pc, lr
  614. putc:
  615. mov r2, r0
  616. mov r0, #0
  617. loadsp r3
  618. b 2b
  619. memdump: mov r12, r0
  620. mov r10, lr
  621. mov r11, #0
  622. 2: mov r0, r11, lsl #2
  623. add r0, r0, r12
  624. mov r1, #8
  625. bl phex
  626. mov r0, #':'
  627. bl putc
  628. 1: mov r0, #' '
  629. bl putc
  630. ldr r0, [r12, r11, lsl #2]
  631. mov r1, #8
  632. bl phex
  633. and r0, r11, #7
  634. teq r0, #3
  635. moveq r0, #' '
  636. bleq putc
  637. and r0, r11, #7
  638. add r11, r11, #1
  639. teq r0, #7
  640. bne 1b
  641. mov r0, #'\n'
  642. bl putc
  643. cmp r11, #64
  644. blt 2b
  645. mov pc, r10
  646. #endif
  647. reloc_end:
  648. .align
  649. .section ".stack", "w"
  650. user_stack: .space 4096