Path: blob/master/arch/unicore32/boot/compressed/head.S
10818 views
/*1* linux/arch/unicore32/boot/compressed/head.S2*3* Code specific to PKUnity SoC and UniCore ISA4*5* Copyright (C) 2001-2010 GUAN Xue-tao6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*/11#include <linux/linkage.h>12#include <mach/memory.h>1314#define csub cmpsub15#define cand cmpand16#define nop8 nop; nop; nop; nop; nop; nop; nop; nop1718.section ".start", #alloc, #execinstr19.text20start:21.type start,#function2223/* Initialize ASR, PRIV mode and INTR off */24mov r0, #0xD325mov.a asr, r02627adr r0, LC028ldm (r1, r2, r3, r5, r6, r7, r8), [r0]+29ldw sp, [r0+], #2830sub.a r0, r0, r1 @ calculate the delta offset3132/*33* if delta is zero, we are running at the address34* we were linked at.35*/36beq not_relocated3738/*39* We're running at a different address. We need to fix40* up various pointers:41* r5 - zImage base address (_start)42* r7 - GOT start43* r8 - GOT end44*/45add r5, r5, r046add r7, r7, r047add r8, r8, r04849/*50* we need to fix up pointers into the BSS region.51* r2 - BSS start52* r3 - BSS end53* sp - stack pointer54*/55add r2, r2, r056add r3, r3, r057add sp, sp, r05859/*60* Relocate all entries in the GOT table.61* This fixes up the C references.62* r7 - GOT start63* r8 - GOT end64*/651001: ldw r1, [r7+], #066add r1, r1, r067stw.w r1, [r7]+, #468csub.a r7, r869bub 1001b7071not_relocated:72/*73* Clear BSS region.74* r2 - BSS start75* r3 - BSS end76*/77mov r0, #0781002: stw.w r0, [r2]+, #479csub.a r2, r380bub 1002b8182/*83* Turn on the cache.84*/85mov r0, #086movc p0.c5, r0, #28 @ cache invalidate all87nop888movc p0.c6, r0, #6 @ tlb invalidate all89nop89091mov r0, #0x1c @ en icache and wb dcache92movc p0.c1, r0, #093nop89495/*96* Set up some pointers, for starting decompressing.97*/9899mov r1, sp @ malloc space above stack100add r2, sp, #0x10000 @ 64k max101102/*103* Check to see if we will overwrite ourselves.104* r4 = final kernel address105* r5 = start of this image106* r6 = size of decompressed image107* r2 = end of malloc space (and therefore this image)108* We basically want:109* r4 >= r2 -> OK110* r4 + image length <= r5 -> OK111*/112ldw r4, =KERNEL_IMAGE_START113csub.a r4, r2114bea wont_overwrite115add r0, r4, r6116csub.a r0, r5117beb wont_overwrite118119/*120* If overwrite, just print error message121*/122b __error_overwrite123124/*125* We're not in danger of overwriting ourselves.126* Do this the simple way.127*/128wont_overwrite:129/*130* decompress_kernel:131* r0: output_start132* r1: free_mem_ptr_p133* r2: free_mem_ptr_end_p134*/135mov r0, r4136b.l decompress_kernel @ C functions137138/*139* Clean and flush the cache to maintain consistency.140*/141mov r0, #0142movc p0.c5, r0, #14 @ flush dcache143nop8144movc p0.c5, r0, #20 @ icache invalidate all145nop8146147/*148* Turn off the Cache and MMU.149*/150mov r0, #0 @ disable i/d cache and MMU151movc p0.c1, r0, #0152nop8153154mov r0, #0 @ must be zero155ldw r4, =KERNEL_IMAGE_START156mov pc, r4 @ call kernel157158159.align 2160.type LC0, #object161LC0: .word LC0 @ r1162.word __bss_start @ r2163.word _end @ r3164.word _start @ r5165.word _image_size @ r6166.word _got_start @ r7167.word _got_end @ r8168.word decompress_stack_end @ sp169.size LC0, . - LC0170171print_string:172#ifdef CONFIG_DEBUG_OCD1732001: ldb.w r1, [r0]+, #1174csub.a r1, #0175bne 2002f176mov pc, lr1772002:178movc r2, p1.c0, #0179cand.a r2, #2180bne 2002b181movc p1.c1, r1, #1182csub.a r1, #'\n'183cmoveq r1, #'\r'184beq 2002b185b 2001b186#else187mov pc, lr188#endif189190__error_overwrite:191adr r0, str_error192b.l print_string1932001: nop8194b 2001b195str_error: .asciz "\nError: Kernel address OVERWRITE\n"196.align197198.ltorg199200.align 4201.section ".stack", "aw", %nobits202decompress_stack: .space 4096203decompress_stack_end:204205206