2 * linux/arch/arm/boot/compressed/head-espd_4510b.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>
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.
21 #if defined(CONFIG_DEBUG_ICEDCC)
25 mcr p14, 0, \rb, c0, c1, 0
28 #error no serial architecture defined
43 .macro debug_reloc_start
46 kphex r6, 8 /* processor id */
48 kphex r7, 8 /* architecture id */
50 mrc p15, 0, r0, c1, c0
51 kphex r0, 8 /* control reg */
53 kphex r5, 8 /* decompressed kernel start */
55 kphex r8, 8 /* decompressed kernel end */
57 kphex r4, 8 /* kernel execution address */
62 .macro debug_reloc_end
64 kphex r5, 8 /* end of kernel */
67 bl memdump /* dump 256 bytes at start of kernel */
71 .section ".start", #alloc, #execinstr
73 * sort out different calling conventions
83 .word 0x016f2818 @ Magic numbers to help the loader
84 .word start @ absolute load/run zImage address
85 .word _edata @ zImage end address
86 1: mov r7, r1 @ save architecture ID
89 #ifndef __ARM_ARCH_2__
91 * Booting from Angel - need to enter SVC mode and disable
92 * FIQs/IRQs (numeric definitions from angel arm.h source).
93 * We only do this if we were in user mode on entry.
95 mrs r2, cpsr @ get current mode
96 tst r2, #3 @ not user?
98 mov r0, #0x17 @ angel_SWIreason_EnterSVC
99 swi 0x123456 @ angel_SWI_ARM
101 mrs r2, cpsr @ turn off interrupts to
102 orr r2, r2, #0xc0 @ prevent angel from running
105 teqp pc, #0x0c000003 @ turn off interrupts
109 * Note that some cache flushing and other stuff may
110 * be needed here - is there an Angel SWI call for this?
114 * some architecture specific code can be inserted
115 * by the linker here, but it should preserve r7 and r8.
120 ldmia r0, {r1, r2, r3, r4, r5, r6, ip, sp}
121 subs r0, r0, r1 @ calculate the delta offset
123 @ if delta is zero, we are
124 beq not_relocated @ running at the address we
128 * We're running at a different address. We need to fix
129 * up various pointers:
130 * r5 - zImage base address
138 #ifndef CONFIG_ZBOOT_ROM
140 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
141 * we need to fix up pointers into the BSS region.
151 * Relocate all entries in the GOT table.
153 1: ldr r1, [r6, #0] @ relocate entries in the GOT
154 add r1, r1, r0 @ table. This fixes up the
155 str r1, [r6], #4 @ C references.
161 * Relocate entries in the GOT table. We only relocate
162 * the entries that are outside the (relocated) BSS region.
164 1: ldr r1, [r6, #0] @ relocate entries in the GOT
165 cmp r1, r2 @ entry < bss_start ||
166 cmphs r3, r1 @ _end < entry
167 addlo r1, r1, r0 @ table. This fixes up the
168 str r1, [r6], #4 @ C references.
173 not_relocated: mov r0, #0
174 1: str r0, [r2], #4 @ clear bss
182 * Reset Ethernet BDMA (before cache on)
184 ldr r3, =0x8000 @ BDMA reset
185 ldr r2, =0x3FF9000 @ BDMATXCON
187 ldr r2, =0x3FF9004 @ BDMARXCON
191 * The C runtime environment should now be setup
192 * sufficiently. Turn the cache on, set up some
193 * pointers, and start decompressing.
197 mov r1, sp @ malloc space above stack
198 add r2, sp, #0x10000 @ 64k max
201 * Check to see if we will overwrite ourselves.
202 * r4 = final kernel address
203 * r5 = start of this image
204 * r2 = end of malloc space (and therefore this image)
207 * r4 + image length <= r5 -> OK
211 add r0, r4, #4096*1024 @ 4MB largest kernel size
215 mov r5, r2 @ decompress after malloc space
221 bic r0, r0, #127 @ align the kernel length
223 * r0 = decompressed kernel length
225 * r4 = kernel execution address
226 * r5 = decompressed kernel start
228 * r7 = architecture ID
231 add r1, r5, r0 @ end of decompressed kernel
235 1: ldmia r2!, {r8 - r13} @ copy relocation code
236 stmia r1!, {r8 - r13}
237 ldmia r2!, {r8 - r13}
238 stmia r1!, {r8 - r13}
243 add pc, r5, r0 @ call relocation code
246 * We're not in danger of overwriting ourselves. Do this the simple way.
248 * r4 = kernel execution address
249 * r7 = architecture ID
251 wont_overwrite: mov r0, r4
258 .word __bss_start @ r2
262 .word _got_start @ r6
264 .word user_stack+4096 @ sp
265 LC1: .word reloc_end - reloc_start
269 * Turn on the cache. We need to setup some page tables so that we
270 * can have both the I and D caches on.
272 * We place the page tables 16k down from the kernel execution address,
273 * and we hope that nothing else is using it. If we're using it, we
277 * r4 = kernel execution address
279 * r7 = architecture number
280 * r8 = run-time address of "start"
282 * r1, r2, r3, r8, r9, r12 corrupted
283 * This routine must preserve:
288 /* cache/write buffer on */
289 ldr r0, =0x3FF0000 @ SYSCFG
291 orr r2, r2, #6 @ Cache and write buffer
296 * All code following this line is relocatable. It is relocated by
297 * the above code to the end of the decompressed kernel image and
298 * executed there. During this time, we have no stacks.
300 * r0 = decompressed kernel length
302 * r4 = kernel execution address
303 * r5 = decompressed kernel start
305 * r7 = architecture ID
309 reloc_start: add r8, r5, r0
314 ldmia r5!, {r0, r2, r3, r9 - r13} @ relocate kernel
315 stmia r1!, {r0, r2, r3, r9 - r13}
322 call_kernel: bl cache_clean_flush
325 mov r1, r7 @ restore architecture number
326 mov pc, r4 @ call kernel
330 * Turn off the Cache and MMU. ARMv3 does not support
331 * reading the control register, but ARMv4 does.
333 * On entry, r6 = processor ID
334 * On exit, r0, r1, r2, r3, r12 corrupted
335 * This routine must preserve: r4, r6, r7
339 /* cache/write buffer off */
340 ldr r0, =0x3FF0000 @ SYSCFG
342 bic r2, r2, #6 @ Cache and write buffer
346 * Clean and flush the cache to maintain consistency.
351 * r1, r2, r3, r11, r12 corrupted
352 * This routine must preserve:
358 * cf. Ch-5 of S3C4510 user's manual for
359 * "Cache flush operation"
360 * To clear Tag RAM area.
372 * Various debugging routines for printing hex characters and
373 * memory, which again must be relocatable.
376 .type phexbuf,#object
378 .size phexbuf, . - phexbuf
380 phex: adr r3, phexbuf
417 2: mov r0, r11, lsl #2
425 ldr r0, [r12, r11, lsl #2]
446 .section ".stack", "w"
447 user_stack: .space 4096