MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / arm / boot / compressed / head-s3c44b0.S
blobe4137c80372b36e0e4332b3a0d755e53d7bd4cc3
1 /*
2  *  linux/arch/armnommu/boot/compressed/head.S
3  *
4  *  Copyright (C) 1996-2002 Russell King
5  *  Copyright (C) 2004 Hyok S. Choi (MPU support)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #include <linux/linkage.h>
12 #include <asm/mach-types.h>
15  * Debugging stuff
16  *
17  * Note that these macros must not contain any code which is not
18  * 100% relocatable.  Any attempt to do so will result in a crash.
19  * Please select one of the following when turning on debugging.
20  */
22                 .macro  kputc,val
23                 mov     r0, \val
24                 bl      putc
25                 .endm
27                 .macro  kphex,val,len
28                 mov     r0, \val
29                 mov     r1, #\len
30                 bl      phex
31                 .endm
33                 .macro  debug_reloc_start
34 #ifdef DEBUG
35                 kputc   #'\n'
36                 kphex   r6, 8           /* processor id */
37                 kputc   #':'
38                 kphex   r7, 8           /* architecture id */
39                 kputc   #':'
40                 mrc     p15, 0, r0, c1, c0
41                 kphex   r0, 8           /* control reg */
42                 kputc   #'\n'
43                 kphex   r5, 8           /* decompressed kernel start */
44                 kputc   #'-'
45                 kphex   r8, 8           /* decompressed kernel end  */
46                 kputc   #'>'
47                 kphex   r4, 8           /* kernel execution address */
48                 kputc   #'\n'
49 #endif
50                 .endm
52                 .macro  debug_reloc_end
53 #ifdef DEBUG
54                 kphex   r5, 8           /* end of kernel */
55                 kputc   #'\n'
56                 mov     r0, r4
57                 bl      memdump         /* dump 256 bytes at start of kernel */
58 #endif
59                 .endm
61                 .section ".start", #alloc, #execinstr
63  * sort out different calling conventions
64  */
65                 .align
66 start:
67                 .type   start,#function
68                 .rept   8
69                 mov     r0, r0
70                 .endr
72                 b       1f
73                 .word   0x016f2818              @ Magic numbers to help the loader
74                 .word   start                   @ absolute load/run zImage address
75                 .word   _edata                  @ zImage end address
76 1:              mov     r7, r1                  @ save architecture ID
77                 mov     r8, #0                  @ save r0
79 #ifndef __ARM_ARCH_2__
80                 /*
81                  * Booting from Angel - need to enter SVC mode and disable
82                  * FIQs/IRQs (numeric definitions from angel arm.h source).
83                  * We only do this if we were in user mode on entry.
84                  */
85                 mrs     r2, cpsr                @ get current mode
86                 tst     r2, #3                  @ not user?
87                 bne     not_angel
88                 mov     r0, #0x17               @ angel_SWIreason_EnterSVC
89                 swi     0x123456                @ angel_SWI_ARM
90 not_angel:
91                 mrs     r2, cpsr                @ turn off interrupts to
92                 orr     r2, r2, #0xc0           @ prevent angel from running
93                 msr     cpsr_c, r2
94 #else
95                 teqp    pc, #0x0c000003         @ turn off interrupts
96 #endif
98                 /*
99                  * Note that some cache flushing and other stuff may
100                  * be needed here - is there an Angel SWI call for this?
101                  */
103                 /*
104                  * some architecture specific code can be inserted
105                  * by the linker here, but it should preserve r7 and r8.
106                  */
108                 .text
109                 adr     r0, LC0
110                 ldmia   r0, {r1, r2, r3, r4, r5, r6, ip, sp}
111                 subs    r0, r0, r1              @ calculate the delta offset
113                                                 @ if delta is zero, we're
114                 beq     not_relocated           @ running at the address we
115                                                 @ were linked at.
117                 /*
118                  * We're running at a different address.  We need to fix
119                  * up various pointers:
120                  *   r5 - zImage base address
121                  *   r6 - GOT start
122                  *   ip - GOT end
123                  */
124                 add     r5, r5, r0
125                 add     r6, r6, r0
126                 add     ip, ip, r0
128 #ifndef CONFIG_ZBOOT_ROM
129                 /*
130                  * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
131                  * we need to fix up pointers into the BSS region.
132                  *   r2 - BSS start
133                  *   r3 - BSS end
134                  *   sp - stack pointer
135                  */
136                 add     r2, r2, r0
137                 add     r3, r3, r0
138                 add     sp, sp, r0
140                 /*
141                  * Relocate all entries in the GOT table.
142                  */
143 1:              ldr     r1, [r6, #0]            @ relocate entries in the GOT
144                 add     r1, r1, r0              @ table.  This fixes up the
145                 str     r1, [r6], #4            @ C references.
146                 cmp     r6, ip
147                 blo     1b
148 #else
150                 /*
151                  * Relocate entries in the GOT table.  We only relocate
152                  * the entries that are outside the (relocated) BSS region.
153                  */
154 1:              ldr     r1, [r6, #0]            @ relocate entries in the GOT
155                 cmp     r1, r2                  @ entry < bss_start ||
156                 cmphs   r3, r1                  @ _end < entry
157                 addlo   r1, r1, r0              @ table.  This fixes up the
158                 str     r1, [r6], #4            @ C references.
159                 cmp     r6, ip
160                 blo     1b
161 #endif
163 not_relocated:  mov     r0, #0
164 1:              str     r0, [r2], #4            @ clear bss
165                 str     r0, [r2], #4
166                 str     r0, [r2], #4
167                 str     r0, [r2], #4
168                 cmp     r2, r3
169                 blo     1b
171                 /*
172                  * The C runtime environment should now be setup
173                  * sufficiently.  Turn the cache on, set up some
174                  * pointers, and start decompressing.
175                  */
177                 mov     r1, sp                  @ malloc space above stack
178                 add     r2, sp, #0x10000        @ 64k max
181  * Check to see if we will overwrite ourselves.
182  *   r4 = final kernel address
183  *   r5 = start of this image
184  *   r2 = end of malloc space (and therefore this image)
185  * We basically want:
186  *   r4 >= r2 -> OK
187  *   r4 + image length <= r5 -> OK
188  */
189                 cmp     r4, r2
190                 bhs     wont_overwrite
191                 add     r0, r4, #4096*1024      @ 4MB largest kernel size
192                 cmp     r0, r5
193                 bls     wont_overwrite
195                 mov     r5, r2                  @ decompress after malloc space
196                 mov     r0, r5
197                 mov     r3, r7
198                 bl      decompress_kernel
200                 add     r0, r0, #127
201                 bic     r0, r0, #127            @ align the kernel length
203  * r0     = decompressed kernel length
204  * r1-r3  = unused
205  * r4     = kernel execution address
206  * r5     = decompressed kernel start
207  * r6     = processor ID
208  * r7     = architecture ID
209  * r8-r14 = unused
210  */
211                 add     r1, r5, r0              @ end of decompressed kernel
212                 adr     r2, reloc_start
213                 ldr     r3, LC1
214                 add     r3, r2, r3
215 1:              ldmia   r2!, {r8 - r13}         @ copy relocation code
216                 stmia   r1!, {r8 - r13}
217                 ldmia   r2!, {r8 - r13}
218                 stmia   r1!, {r8 - r13}
219                 cmp     r2, r3
220                 blo     1b
222                 add     pc, r5, r0              @ call relocation code
225  * We're not in danger of overwriting ourselves.  Do this the simple way.
227  * r4     = kernel execution address
228  * r7     = architecture ID
229  */
230 wont_overwrite: mov     r0, r4
231                 mov     r3, r7
232                 bl      decompress_kernel
233                 b       call_kernel
235                 .type   LC0, #object
236 LC0:            .word   LC0                     @ r1
237                 .word   __bss_start             @ r2
238                 .word   _end                    @ r3
239                 .word   _load_addr              @ r4
240                 .word   _start                  @ r5
241                 .word   _got_start              @ r6
242                 .word   _got_end                @ ip
243                 .word   user_stack+4096         @ sp
244 LC1:            .word   reloc_end - reloc_start
245                 .size   LC0, . - LC0
248  * All code following this line is relocatable.  It is relocated by
249  * the above code to the end of the decompressed kernel image and
250  * executed there.  During this time, we have no stacks.
252  * r0     = decompressed kernel length
253  * r1-r3  = unused
254  * r4     = kernel execution address
255  * r5     = decompressed kernel start
256  * r6     = processor ID
257  * r7     = architecture ID
258  * r8-r14 = unused
259  */
260                 .align  5
261 reloc_start:    add     r8, r5, r0
262                 debug_reloc_start
263                 mov     r1, r4
265                 .rept   4
266                 ldmia   r5!, {r0, r2, r3, r9 - r13}     @ relocate kernel
267                 stmia   r1!, {r0, r2, r3, r9 - r13}
268                 .endr
270                 cmp     r5, r8
271                 blo     1b
272                 debug_reloc_end
274 call_kernel:    
276 #ifdef CONFIG_ARCH_S3C44B0
277                 ldr     r2, S3C44B0_PROCESSOR_TYPE
278                 str     r2, [r6]
279                 ldr     r2, S3C44B0_MACH_TYPE
280                 str     r2, [r9]
281                 mov     fp, #0
282                 b       1f
283 S3C44B0_PROCESSOR_TYPE:
284         .long   0x44b07700
285 S3C44B0_MACH_TYPE:
286         .long   MACH_TYPE_S3C44B0
289 #endif
291                 mov     r0, #0
292                 mov     r1, r7                  @ restore architecture number
293                 mov     pc, r4                  @ call kernel
296  * Various debugging routines for printing hex characters and
297  * memory, which again must be relocatable.
298  */
299 #ifdef DEBUG
300                 .type   phexbuf,#object
301 phexbuf:        .space  12
302                 .size   phexbuf, . - phexbuf
304 phex:           adr     r3, phexbuf
305                 mov     r2, #0
306                 strb    r2, [r3, r1]
307 1:              subs    r1, r1, #1
308                 movmi   r0, r3
309                 bmi     puts
310                 and     r2, r0, #15
311                 mov     r0, r0, lsr #4
312                 cmp     r2, #10
313                 addge   r2, r2, #7
314                 add     r2, r2, #'0'
315                 strb    r2, [r3, r1]
316                 b       1b
318 puts:           loadsp  r3
319 1:              ldrb    r2, [r0], #1
320                 teq     r2, #0
321                 moveq   pc, lr
322 2:              writeb  r2
323                 mov     r1, #0x00020000
324 3:              subs    r1, r1, #1
325                 bne     3b
326                 teq     r2, #'\n'
327                 moveq   r2, #'\r'
328                 beq     2b
329                 teq     r0, #0
330                 bne     1b
331                 mov     pc, lr
332 putc:
333                 mov     r2, r0
334                 mov     r0, #0
335                 loadsp  r3
336                 b       2b
338 memdump:        mov     r12, r0
339                 mov     r10, lr
340                 mov     r11, #0
341 2:              mov     r0, r11, lsl #2
342                 add     r0, r0, r12
343                 mov     r1, #8
344                 bl      phex
345                 mov     r0, #':'
346                 bl      putc
347 1:              mov     r0, #' '
348                 bl      putc
349                 ldr     r0, [r12, r11, lsl #2]
350                 mov     r1, #8
351                 bl      phex
352                 and     r0, r11, #7
353                 teq     r0, #3
354                 moveq   r0, #' '
355                 bleq    putc
356                 and     r0, r11, #7
357                 add     r11, r11, #1
358                 teq     r0, #7
359                 bne     1b
360                 mov     r0, #'\n'
361                 bl      putc
362                 cmp     r11, #64
363                 blt     2b
364                 mov     pc, r10
365 #endif
367 reloc_end:
369                 .align
370                 .section ".stack", "w"
371 user_stack:     .space  4096