/*1* Copyright (C) 2009 Wind River Systems Inc2* Implemented by [email protected] and [email protected]3* Copyright (C) 2004 Microtronix Datacom Ltd4* Copyright (C) 2001 Vic Phillips, Microtronix Datacom Ltd.5*6* Based on head.S for Altera's Excalibur development board with nios processor7*8* Based on the following from the Excalibur sdk distribution:9* NA_MemoryMap.s, NR_JumpToStart.s, NR_Setup.s, NR_CWPManager.s10*11* This file is subject to the terms and conditions of the GNU General Public12* License. See the file "COPYING" in the main directory of this archive13* for more details.14*/1516#include <linux/init.h>17#include <linux/linkage.h>18#include <asm/thread_info.h>19#include <asm/processor.h>20#include <asm/cache.h>21#include <asm/page.h>22#include <asm/asm-offsets.h>23#include <asm/asm-macros.h>2425/*26* ZERO_PAGE is a special page that is used for zero-initialized27* data and COW.28*/29.data30.global empty_zero_page31.align 1232empty_zero_page:33.space PAGE_SIZE3435/*36* This global variable is used as an extension to the nios'37* STATUS register to emulate a user/supervisor mode.38*/39.data40.align 241.set noat4243.global _current_thread44_current_thread:45.long 046/*47* Input(s): passed from u-boot48* r4 - Optional pointer to a board information structure.49* r5 - Optional pointer to the physical starting address of the init RAM50* disk.51* r6 - Optional pointer to the physical ending address of the init RAM52* disk.53* r7 - Optional pointer to the physical starting address of any kernel54* command-line parameters.55*/5657/*58* First executable code - detected and jumped to by the ROM bootstrap59* if the code resides in flash (looks for "Nios" at offset 0x0c from60* the potential executable image).61*/62__HEAD63ENTRY(_start)64wrctl status, r0 /* Disable interrupts */6566/* Initialize all cache lines within the instruction cache */67movia r1, NIOS2_ICACHE_SIZE68movui r2, NIOS2_ICACHE_LINE_SIZE6970icache_init:71initi r172sub r1, r1, r273bgt r1, r0, icache_init74br 1f7576/*77* This is the default location for the exception handler. Code in jump78* to our handler79*/80ENTRY(exception_handler_hook)81movia r24, inthandler82jmp r248384ENTRY(fast_handler)85nextpc et86helper:87stw r3, r3save - helper(et)8889rdctl r3 , pteaddr90srli r3, r3, 1291slli r3, r3, 292movia et, pgd_current9394ldw et, 0(et)95add r3, et, r396ldw et, 0(r3)9798rdctl r3, pteaddr99andi r3, r3, 0xfff100add et, r3, et101ldw et, 0(et)102wrctl tlbacc, et103nextpc et104helper2:105ldw r3, r3save - helper2(et)106subi ea, ea, 4107eret108r3save:109.word 0x0110ENTRY(fast_handler_end)1111121:113/*114* After the instruction cache is initialized, the data cache must115* also be initialized.116*/117movia r1, NIOS2_DCACHE_SIZE118movui r2, NIOS2_DCACHE_LINE_SIZE119120dcache_init:121initd 0(r1)122sub r1, r1, r2123bgt r1, r0, dcache_init124125nextpc r1 /* Find out where we are */126chkadr:127movia r2, chkadr128beq r1, r2,finish_move /* We are running in RAM done */129addi r1, r1,(_start - chkadr) /* Source */130movia r2, _start /* Destination */131movia r3, __bss_start /* End of copy */132133loop_move: /* r1: src, r2: dest, r3: last dest */134ldw r8, 0(r1) /* load a word from [r1] */135stw r8, 0(r2) /* store a word to dest [r2] */136flushd 0(r2) /* Flush cache for safety */137addi r1, r1, 4 /* inc the src addr */138addi r2, r2, 4 /* inc the dest addr */139blt r2, r3, loop_move140141movia r1, finish_move /* VMA(_start)->l1 */142jmp r1 /* jmp to _start */143144finish_move:145146/* Mask off all possible interrupts */147wrctl ienable, r0148149/* Clear .bss */150movia r2, __bss_start151movia r1, __bss_stop1521:153stb r0, 0(r2)154addi r2, r2, 1155bne r1, r2, 1b156157movia r1, init_thread_union /* set stack at top of the task union */158addi sp, r1, THREAD_SIZE159movia r2, _current_thread /* Remember current thread */160stw r1, 0(r2)161162movia r1, nios2_boot_init /* save args r4-r7 passed from u-boot */163callr r1164165movia r1, start_kernel /* call start_kernel as a subroutine */166callr r1167168/* If we return from start_kernel, break to the oci debugger and169* buggered we are.170*/171break172173/* End of startup code */174.set at175176177