/*1* Copyright (C) 2009 Thomas Chou <[email protected]>2*3* Based on arch/nios2/kernel/head.S4*5* This file is subject to the terms and conditions of the GNU General Public6* License. See the file "COPYING" in the main directory of this archive7* for more details.8*9*/1011/*12* This code can be loaded anywhere, eg FLASH ROM as reset vector,13* as long as output does not overlap it.14*/1516#include <linux/linkage.h>17#include <asm/cache.h>1819.text20.set noat21ENTRY(_start)22wrctl status, r0 /* disable interrupt */23/* invalidate all instruction cache */24movia r1, NIOS2_ICACHE_SIZE25movui r2, NIOS2_ICACHE_LINE_SIZE261: initi r127sub r1, r1, r228bgt r1, r0, 1b29/* invalidate all data cache */30movia r1, NIOS2_DCACHE_SIZE31movui r2, NIOS2_DCACHE_LINE_SIZE321: initd 0(r1)33sub r1, r1, r234bgt r1, r0, 1b3536nextpc r1 /* Find out where we are */37chkadr:38movia r2, chkadr39beq r1, r2, finish_move /* We are running in correct address,40done */41/* move code, r1: src, r2: dest, r3: last dest */42addi r1, r1, (_start - chkadr) /* Source */43movia r2, _start /* Destination */44movia r3, __bss_start /* End of copy */451: ldw r8, 0(r1) /* load a word from [r1] */46stw r8, 0(r2) /* stort a word to dest [r2] */47addi r1, r1, 4 /* inc the src addr */48addi r2, r2, 4 /* inc the dest addr */49blt r2, r3, 1b50/* flush the data cache after moving */51movia r1, NIOS2_DCACHE_SIZE52movui r2, NIOS2_DCACHE_LINE_SIZE531: flushd 0(r1)54sub r1, r1, r255bgt r1, r0, 1b56movia r1, finish_move57jmp r1 /* jmp to linked address */5859finish_move:60/* zero out the .bss segment (uninitialized common data) */61movia r2, __bss_start /* presume nothing is between */62movia r1, _end /* the .bss and _end. */631: stb r0, 0(r2)64addi r2, r2, 165bne r1, r2, 1b66/*67* set up the stack pointer, some where higher than _end.68* The stack space must be greater than 32K for decompress.69*/70movia sp, 0x1000071add sp, sp, r172/* save args passed from u-boot, maybe */73addi sp, sp, -1674stw r4, 0(sp)75stw r5, 4(sp)76stw r6, 8(sp)77stw r7, 12(sp)78/* decompress the kernel */79call decompress_kernel80/* pass saved args to kernel */81ldw r4, 0(sp)82ldw r5, 4(sp)83ldw r6, 8(sp)84ldw r7, 12(sp)8586/* flush all data cache after decompressing */87movia r1, NIOS2_DCACHE_SIZE88movui r2, NIOS2_DCACHE_LINE_SIZE891: flushd 0(r1)90sub r1, r1, r291bgt r1, r0, 1b92/* flush all instruction cache */93movia r1, NIOS2_ICACHE_SIZE94movui r2, NIOS2_ICACHE_LINE_SIZE951: flushi r196sub r1, r1, r297bgt r1, r0, 1b98flushp99/* jump to start real kernel */100movia r1, (CONFIG_NIOS2_MEM_BASE | CONFIG_NIOS2_KERNEL_REGION_BASE)101jmp r1102103.balign 512104fake_headers_as_bzImage:105.short 0106.ascii "HdrS"107.short 0x0202108.short 0109.short 0110.byte 0x00, 0x10111.short 0112.byte 0113.byte 1114.byte 0x00, 0x80115.long 0116.long 0117118119