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