2 * linux/arch/arm/boot/compressed/head.S
4 * Copyright (C) 1996-2002 Russell King
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/config.h>
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_DC21285_PORT)
28 #elif defined(CONFIG_DEBUG_ICEDCC)
32 mcr p14, 0, \rb, c0, c1, 0
34 #elif defined(CONFIG_FOOTBRIDGE)
39 strb \rb, [r3, #0x3f8]
41 #elif defined(CONFIG_ARCH_RPC)
44 orr \rb, \rb, #0x00010000
47 strb \rb, [r3, #0x3f8 << 2]
49 #elif defined(CONFIG_ARCH_INTEGRATOR)
56 #elif defined(CONFIG_ARCH_PXA) /* Xscale-type */
59 orr \rb, \rb, #0x00100000
64 #elif defined(CONFIG_ARCH_SA1100)
66 mov \rb, #0x80000000 @ physical base address
67 # if defined(CONFIG_DEBUG_LL_SER3)
68 add \rb, \rb, #0x00050000 @ Ser3
70 add \rb, \rb, #0x00010000 @ Ser1
74 str \rb, [r3, #0x14] @ UTDR
76 #elif defined(CONFIG_ARCH_IXP4XX)
82 #elif defined(CONFIG_ARCH_IXP2000)
85 orr \rb, \rb, #0x00030000
90 #elif defined(CONFIG_ARCH_LH7A40X)
92 ldr \rb, =0x80000700 @ UART2 UARTBASE
97 #elif defined(CONFIG_ARCH_OMAP)
99 mov \rb, #0xff000000 @ physical base address
100 add \rb, \rb, #0x00fb0000
101 #if defined(CONFIG_OMAP_LL_DEBUG_UART2) || defined(CONFIG_OMAP_LL_DEBUG_UART3)
102 add \rb, \rb, #0x00000800
104 #ifdef CONFIG_OMAP_LL_DEBUG_UART3
105 add \rb, \rb, #0x00009000
111 #elif defined(CONFIG_ARCH_IOP331)
114 orr \rb, \rb, #0x00ff0000
115 orr \rb, \rb, #0x0000f700 @ location of the UART
121 #error no serial architecture defined
136 .macro debug_reloc_start
139 kphex r6, 8 /* processor id */
141 kphex r7, 8 /* architecture id */
143 mrc p15, 0, r0, c1, c0
144 kphex r0, 8 /* control reg */
146 kphex r5, 8 /* decompressed kernel start */
148 kphex r8, 8 /* decompressed kernel end */
150 kphex r4, 8 /* kernel execution address */
155 .macro debug_reloc_end
157 kphex r5, 8 /* end of kernel */
160 bl memdump /* dump 256 bytes at start of kernel */
164 .section ".start", #alloc, #execinstr
166 * sort out different calling conventions
170 .type start,#function
176 .word 0x016f2818 @ Magic numbers to help the loader
177 .word start @ absolute load/run zImage address
178 .word _edata @ zImage end address
179 1: mov r7, r1 @ save architecture ID
181 // following mask by Victor Yu. 06-08-2005
187 // above mask by Victor Yu. 06-08-2005
189 #ifndef __ARM_ARCH_2__
191 * Booting from Angel - need to enter SVC mode and disable
192 * FIQs/IRQs (numeric definitions from angel arm.h source).
193 * We only do this if we were in user mode on entry.
195 mrs r2, cpsr @ get current mode
196 tst r2, #3 @ not user?
198 mov r0, #0x17 @ angel_SWIreason_EnterSVC
199 swi 0x123456 @ angel_SWI_ARM
201 mrs r2, cpsr @ turn off interrupts to
202 orr r2, r2, #0xc0 @ prevent angel from running
205 teqp pc, #0x0c000003 @ turn off interrupts
209 * Note that some cache flushing and other stuff may
210 * be needed here - is there an Angel SWI call for this?
214 * some architecture specific code can be inserted
215 * by the linker here, but it should preserve r7 and r8.
220 ldmia r0, {r1, r2, r3, r4, r5, r6, ip, sp}
221 subs r0, r0, r1 @ calculate the delta offset
223 @ if delta is zero, we are
224 beq not_relocated @ running at the address we
228 * We're running at a different address. We need to fix
229 * up various pointers:
230 * r5 - zImage base address
238 #ifndef CONFIG_ZBOOT_ROM
240 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
241 * we need to fix up pointers into the BSS region.
251 * Relocate all entries in the GOT table.
253 1: ldr r1, [r6, #0] @ relocate entries in the GOT
254 add r1, r1, r0 @ table. This fixes up the
255 str r1, [r6], #4 @ C references.
261 * Relocate entries in the GOT table. We only relocate
262 * the entries that are outside the (relocated) BSS region.
264 1: ldr r1, [r6, #0] @ relocate entries in the GOT
265 cmp r1, r2 @ entry < bss_start ||
266 cmphs r3, r1 @ _end < entry
267 addlo r1, r1, r0 @ table. This fixes up the
268 str r1, [r6], #4 @ C references.
273 not_relocated: mov r0, #0
274 1: str r0, [r2], #4 @ clear bss
282 * The C runtime environment should now be setup
283 * sufficiently. Turn the cache on, set up some
284 * pointers, and start decompressing.
288 mov r1, sp @ malloc space above stack
289 add r2, sp, #0x10000 @ 64k max
292 * Check to see if we will overwrite ourselves.
293 * r4 = final kernel address
294 * r5 = start of this image
295 * r2 = end of malloc space (and therefore this image)
298 * r4 + image length <= r5 -> OK
302 add r0, r4, #4096*1024 @ 4MB largest kernel size
306 mov r5, r2 @ decompress after malloc space
312 bic r0, r0, #127 @ align the kernel length
314 * r0 = decompressed kernel length
316 * r4 = kernel execution address
317 * r5 = decompressed kernel start
319 * r7 = architecture ID
322 add r1, r5, r0 @ end of decompressed kernel
326 1: ldmia r2!, {r8 - r13} @ copy relocation code
327 stmia r1!, {r8 - r13}
328 ldmia r2!, {r8 - r13}
329 stmia r1!, {r8 - r13}
334 add pc, r5, r0 @ call relocation code
337 * We're not in danger of overwriting ourselves. Do this the simple way.
339 * r4 = kernel execution address
340 * r7 = architecture ID
342 wont_overwrite: mov r0, r4
349 .word __bss_start @ r2
351 .word _load_addr @ r4
353 .word _got_start @ r6
355 .word user_stack+4096 @ sp
356 LC1: .word reloc_end - reloc_start
359 #ifdef CONFIG_ARCH_RPC
361 params: ldr r0, =params_phys
368 * Turn on the cache. We need to setup some page tables so that we
369 * can have both the I and D caches on.
371 * We place the page tables 16k down from the kernel execution address,
372 * and we hope that nothing else is using it. If we're using it, we
376 * r4 = kernel execution address
378 * r7 = architecture number
379 * r8 = run-time address of "start"
381 * r1, r2, r3, r8, r9, r12 corrupted
382 * This routine must preserve:
386 cache_on: mov r3, #8 @ cache_on function
389 __setup_mmu: sub r3, r4, #16384 @ Page directory size
390 bic r3, r3, #0xff @ Align the pointer
393 * Initialise the page tables, turning on the cacheable and bufferable
394 * bits for the RAM area only.
398 mov r8, r8, lsl #18 @ start of RAM
399 add r9, r8, #0x10000000 @ a reasonable RAM size
403 1: cmp r1, r8 @ if virt > start of RAM
404 orrhs r1, r1, #0x0c @ set cacheable, bufferable
405 cmp r1, r9 @ if virt > end of RAM
406 bichs r1, r1, #0x0c @ clear cacheable, bufferable
407 str r1, [r0], #4 @ 1:1 mapping
412 * If ever we are running from Flash, then we surely want the cache
413 * to be enabled also for our execution instance... We map 2MB of it
414 * so there is no map overlap problem for up to 1 MB compressed kernel.
415 * If the execution is in RAM then we would only be duplicating the above.
420 orr r1, r1, r2, lsl #20
421 add r0, r3, r2, lsl #2
431 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
432 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
433 mrc p15, 0, r0, c1, c0, 0 @ read control reg
434 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
438 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
445 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
446 mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
450 mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
455 orr r0, r0, #0x000d @ Write buffer, mmu
458 mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
459 mcr p15, 0, r1, c3, c0, 0 @ load domain access control
460 mcr p15, 0, r0, c1, c0, 0 @ load control register
461 // following add by Victor Yu. 06-08-2005
463 #ifdef CONFIG_ARCH_MOXART
468 // above add by Victor Yu. 06-08-2005
472 * All code following this line is relocatable. It is relocated by
473 * the above code to the end of the decompressed kernel image and
474 * executed there. During this time, we have no stacks.
476 * r0 = decompressed kernel length
478 * r4 = kernel execution address
479 * r5 = decompressed kernel start
481 * r7 = architecture ID
485 reloc_start: add r8, r5, r0
490 ldmia r5!, {r0, r2, r3, r9 - r13} @ relocate kernel
491 stmia r1!, {r0, r2, r3, r9 - r13}
498 call_kernel: bl cache_clean_flush
501 mov r1, r7 @ restore architecture number
502 mov pc, r4 @ call kernel
505 * Here follow the relocatable cache support functions for the
506 * various processors. This is a generic hook for locating an
507 * entry and jumping to an instruction at the specified offset
508 * from the start of the block. Please note this is all position
518 call_cache_fn: adr r12, proc_types
519 mrc p15, 0, r6, c0, c0 @ get processor ID
520 1: ldr r1, [r12, #0] @ get value
521 ldr r2, [r12, #4] @ get mask
522 eor r1, r1, r6 @ (real ^ match)
524 addeq pc, r12, r3 @ call cache function
529 * Table for cache operations. This is basically:
532 * - 'cache on' method instruction
533 * - 'cache off' method instruction
534 * - 'cache flush' method instruction
536 * We match an entry using: ((real_id ^ match) & mask) == 0
538 * Writethrough caches generally only need 'on' and 'off'
539 * methods. Writeback caches _must_ have the flush method
542 .type proc_types,#object
544 .word 0x41560600 @ ARM6/610
546 b __arm6_cache_off @ works, but slow
549 @ b __arm6_cache_on @ untested
551 @ b __armv3_cache_flush
553 .word 0x00000000 @ old ARM ID
559 .word 0x41007000 @ ARM7/710
565 .word 0x41807200 @ ARM720T (writethrough)
571 .word 0x00007000 @ ARM7 IDs
577 @ Everything from here on will be the new ID system.
579 .word 0x4401a100 @ sa110 / sa1100
583 b __armv4_cache_flush
585 .word 0x6901b110 @ sa1110
589 b __armv4_cache_flush
591 @ These match on the architecture ID
593 .word 0x00020000 @ ARMv4T
597 b __armv4_cache_flush
599 // following add by Victor Yu. 06-08-2005
601 #ifdef CONFIG_ARCH_MOXART
606 b __armv4_cache_flush
609 // above add by Victor Yu. 06-08-2005
611 .word 0x00050000 @ ARMv5TE
615 b __armv4_cache_flush
617 .word 0x00060000 @ ARMv5TEJ
621 b __armv4_cache_flush
623 .word 0x00070000 @ ARMv6
627 b __armv6_cache_flush
629 .word 0 @ unrecognised type
635 .size proc_types, . - proc_types
638 * Turn off the Cache and MMU. ARMv3 does not support
639 * reading the control register, but ARMv4 does.
641 * On entry, r6 = processor ID
642 * On exit, r0, r1, r2, r3, r12 corrupted
643 * This routine must preserve: r4, r6, r7
646 cache_off: mov r3, #12 @ cache_off function
650 mrc p15, 0, r0, c1, c0
652 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
654 mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
655 mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
656 // following add by Victor Yu. 06-08-2005
658 #ifdef CONFIG_ARCH_MOXART
663 // above add by Victor Yu. 06-08-2005
667 mov r0, #0x00000030 @ ARM6 control reg.
671 mov r0, #0x00000070 @ ARM7 control reg.
675 mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
677 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
678 mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
682 * Clean and flush the cache to maintain consistency.
687 * r1, r2, r3, r11, r12 corrupted
688 * This routine must preserve:
698 mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
699 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
700 mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
701 mcr p15, 0, r1, c7, c10, 4 @ drain WB
705 mov r2, #64*1024 @ default: 32K dcache size (*2)
706 mov r11, #32 @ default: 32 byte line size
707 mrc p15, 0, r3, c0, c0, 1 @ read cache type
708 teq r3, r6 @ cache ID register present?
713 mov r2, r2, lsl r1 @ base dcache size *2
714 tst r3, #1 << 14 @ test M bit
715 addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
719 mov r11, r11, lsl r3 @ cache line size in bytes
721 // following add by Victor Yu. 06-08-2005
723 #ifdef CONFIG_ARCH_MOXART
725 mcr p15, 0, r1, c7, c10, 0 @ clean D cache
728 // above add by Victor Yu. 06-08-2005
729 bic r1, pc, #63 @ align to longest cache line
731 1: ldr r3, [r1], r11 @ s/w flush D cache
735 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
736 mcr p15, 0, r1, c7, c6, 0 @ flush D cache
737 mcr p15, 0, r1, c7, c10, 4 @ drain WB
742 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
746 * Various debugging routines for printing hex characters and
747 * memory, which again must be relocatable.
750 .type phexbuf,#object
752 .size phexbuf, . - phexbuf
754 phex: adr r3, phexbuf
791 2: mov r0, r11, lsl #2
799 ldr r0, [r12, r11, lsl #2]
820 .section ".stack", "w"
821 user_stack: .space 4096