head.S 16 KB

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