2 * linux/arch/armnommu/boot/compressed/head-p2001.S
4 * Copyright (C) 2004 Tobias Lorenz
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.
10 #include <linux/linkage.h>
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.
21 mov \rb, #0x00140000 @ Adr_UART_OLD_BASE
25 str \rb, [r3, #0x00] @ REL_Adr_Uart_TX1
40 .macro debug_reloc_start
43 kphex r6, 8 /* processor id */
45 kphex r7, 8 /* architecture id */
47 kphex r5, 8 /* decompressed kernel start */
49 kphex r8, 8 /* decompressed kernel end */
51 kphex r4, 8 /* kernel execution address */
56 .macro debug_reloc_end
58 kphex r5, 8 /* end of kernel */
61 bl memdump /* dump 256 bytes at start of kernel */
66 .section ".start", #alloc, #execinstr
68 * sort out different calling conventions
78 .word 0x016f2818 @ Magic numbers to help the loader
79 .word start @ absolute load/run zImage address
80 .word _edata @ zImage end address
81 1: mov r7, r1 @ save architecture ID
85 * Booting from P2001 - need to enter SVC mode and disable
86 * FIQs/IRQs (numeric definitions from angel arm.h source).
87 * We only do this if we were in user mode on entry.
89 mrs r2, cpsr @ get current mode
90 orr r2, r2, #0xc0 @ turn off interrupts
94 * Note that some cache flushing and other stuff may
95 * be needed here - is there an Angel SWI call for this?
99 * some architecture specific code can be inserted
100 * by the linker here, but it should preserve r7 and r8.
105 ldmia r0, {r1, r2, r3, r4, r5, r6, ip, sp}
106 subs r0, r0, r1 @ calculate the delta offset
108 @ if delta is zero, we're
109 beq not_relocated @ running at the address we
113 * We're running at a different address. We need to fix
114 * up various pointers:
115 * r5 - zImage base address
123 #ifndef CONFIG_ZBOOT_ROM
125 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
126 * we need to fix up pointers into the BSS region.
136 * Relocate all entries in the GOT table.
138 1: ldr r1, [r6, #0] @ relocate entries in the GOT
139 add r1, r1, r0 @ table. This fixes up the
140 str r1, [r6], #4 @ C references.
146 * Relocate entries in the GOT table. We only relocate
147 * the entries that are outside the (relocated) BSS region.
149 1: ldr r1, [r6, #0] @ relocate entries in the GOT
150 cmp r1, r2 @ entry < bss_start ||
151 cmphs r3, r1 @ _end < entry
152 addlo r1, r1, r0 @ table. This fixes up the
153 str r1, [r6], #4 @ C references.
158 not_relocated: mov r0, #0
159 1: str r0, [r2], #4 @ clear bss
167 * The C runtime environment should now be setup
168 * sufficiently. Set up some pointers, and start decompressing.
170 mov r1, sp @ malloc space above stack
171 add r2, sp, #0x10000 @ 64k max
174 * Check to see if we will overwrite ourselves.
175 * r4 = final kernel address
176 * r5 = start of this image
177 * r2 = end of malloc space (and therefore this image)
180 * r4 + image length <= r5 -> OK
184 add r0, r4, #4096*1024 @ 4MB largest kernel size
188 mov r5, r2 @ decompress after malloc space
194 bic r0, r0, #127 @ align the kernel length
196 * r0 = decompressed kernel length
198 * r4 = kernel execution address
199 * r5 = decompressed kernel start
201 * r7 = architecture ID
204 add r1, r5, r0 @ end of decompressed kernel
208 1: ldmia r2!, {r8 - r13} @ copy relocation code
209 stmia r1!, {r8 - r13}
210 ldmia r2!, {r8 - r13}
211 stmia r1!, {r8 - r13}
215 add pc, r5, r0 @ call relocation code
218 * We're not in danger of overwriting ourselves. Do this the simple way.
220 * r4 = kernel execution address
221 * r7 = architecture ID
223 wont_overwrite: mov r0, r4
230 .word __bss_start @ r2
232 .word _load_addr @ r4
234 .word _got_start @ r6
236 .word user_stack+4096 @ sp
237 LC1: .word reloc_end - reloc_start
241 * Initialise the page tables, turning on the cacheable and bufferable
242 * bits for the RAM area only.
246 mov r8, r8, lsl #18 @ start of RAM
247 add r9, r8, #0x10000000 @ a reasonable RAM size
251 1: cmp r1, r8 @ if virt > start of RAM
252 orrhs r1, r1, #0x0c @ set cacheable, bufferable
253 cmp r1, r9 @ if virt > end of RAM
254 bichs r1, r1, #0x0c @ clear cacheable, bufferable
255 str r1, [r0], #4 @ 1:1 mapping
260 * If ever we are running from Flash, then we surely want the cache
261 * to be enabled also for our execution instance... We map 2MB of it
262 * so there is no map overlap problem for up to 1 MB compressed kernel.
263 * If the execution is in RAM then we would only be duplicating the above.
268 orr r1, r1, r2, lsl #20
269 add r0, r3, r2, lsl #2
276 * All code following this line is relocatable. It is relocated by
277 * the above code to the end of the decompressed kernel image and
278 * executed there. During this time, we have no stacks.
280 * r0 = decompressed kernel length
282 * r4 = kernel execution address
283 * r5 = decompressed kernel start
285 * r7 = architecture ID
289 reloc_start: add r8, r5, r0
294 ldmia r5!, {r0, r2, r3, r9 - r13} @ relocate kernel
295 stmia r1!, {r0, r2, r3, r9 - r13}
302 call_kernel: mov r0, #0
303 mov r1, r7 @ restore architecture number
304 mov pc, r4 @ call kernel
307 * Various debugging routines for printing hex characters and
308 * memory, which again must be relocatable.
311 .type phexbuf,#object
313 .size phexbuf, . - phexbuf
315 phex: adr r3, phexbuf
352 2: mov r0, r11, lsl #2
360 ldr r0, [r12, r11, lsl #2]
381 .section ".stack", "w"
382 user_stack: .space 4096