2 * linux/arch/armnommu/boot/compressed/head.S
4 * Copyright (C) 1996-2002 Russell King
5 * Copyright (C) 2004 Hyok S. Choi (MPU support)
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.
11 #include <linux/linkage.h>
12 #include <asm/mach-types.h>
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.
33 .macro debug_reloc_start
36 kphex r6, 8 /* processor id */
38 kphex r7, 8 /* architecture id */
40 mrc p15, 0, r0, c1, c0
41 kphex r0, 8 /* control reg */
43 kphex r5, 8 /* decompressed kernel start */
45 kphex r8, 8 /* decompressed kernel end */
47 kphex r4, 8 /* kernel execution address */
52 .macro debug_reloc_end
54 kphex r5, 8 /* end of kernel */
57 bl memdump /* dump 256 bytes at start of kernel */
61 .section ".start", #alloc, #execinstr
63 * sort out different calling conventions
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
79 #ifndef __ARM_ARCH_2__
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.
85 mrs r2, cpsr @ get current mode
86 tst r2, #3 @ not user?
88 mov r0, #0x17 @ angel_SWIreason_EnterSVC
89 swi 0x123456 @ angel_SWI_ARM
91 mrs r2, cpsr @ turn off interrupts to
92 orr r2, r2, #0xc0 @ prevent angel from running
95 teqp pc, #0x0c000003 @ turn off interrupts
99 * Note that some cache flushing and other stuff may
100 * be needed here - is there an Angel SWI call for this?
104 * some architecture specific code can be inserted
105 * by the linker here, but it should preserve r7 and r8.
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
118 * We're running at a different address. We need to fix
119 * up various pointers:
120 * r5 - zImage base address
128 #ifndef CONFIG_ZBOOT_ROM
130 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
131 * we need to fix up pointers into the BSS region.
141 * Relocate all entries in the GOT table.
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.
151 * Relocate entries in the GOT table. We only relocate
152 * the entries that are outside the (relocated) BSS region.
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.
163 not_relocated: mov r0, #0
164 1: str r0, [r2], #4 @ clear bss
172 * The C runtime environment should now be setup
173 * sufficiently. Turn the cache on, set up some
174 * pointers, and start decompressing.
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)
187 * r4 + image length <= r5 -> OK
191 add r0, r4, #4096*1024 @ 4MB largest kernel size
195 mov r5, r2 @ decompress after malloc space
201 bic r0, r0, #127 @ align the kernel length
203 * r0 = decompressed kernel length
205 * r4 = kernel execution address
206 * r5 = decompressed kernel start
208 * r7 = architecture ID
211 add r1, r5, r0 @ end of decompressed kernel
215 1: ldmia r2!, {r8 - r13} @ copy relocation code
216 stmia r1!, {r8 - r13}
217 ldmia r2!, {r8 - r13}
218 stmia r1!, {r8 - r13}
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
230 wont_overwrite: mov r0, r4
237 .word __bss_start @ r2
239 .word _load_addr @ r4
241 .word _got_start @ r6
243 .word user_stack+4096 @ sp
244 LC1: .word reloc_end - reloc_start
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
254 * r4 = kernel execution address
255 * r5 = decompressed kernel start
257 * r7 = architecture ID
261 reloc_start: add r8, r5, r0
266 ldmia r5!, {r0, r2, r3, r9 - r13} @ relocate kernel
267 stmia r1!, {r0, r2, r3, r9 - r13}
276 #ifdef CONFIG_ARCH_S3C44B0
277 ldr r2, S3C44B0_PROCESSOR_TYPE
279 ldr r2, S3C44B0_MACH_TYPE
283 S3C44B0_PROCESSOR_TYPE:
286 .long MACH_TYPE_S3C44B0
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.
300 .type phexbuf,#object
302 .size phexbuf, . - phexbuf
304 phex: adr r3, phexbuf
341 2: mov r0, r11, lsl #2
349 ldr r0, [r12, r11, lsl #2]
370 .section ".stack", "w"
371 user_stack: .space 4096