/*1* Copyright (C) 2007-2009 Michal Simek <[email protected]>2* Copyright (C) 2007-2009 PetaLogix3* Copyright (C) 2006 Atmark Techno, Inc.4*5* MMU code derived from arch/ppc/kernel/head_4xx.S:6* Copyright (c) 1995-1996 Gary Thomas <[email protected]>7* Initial PowerPC version.8* Copyright (c) 1996 Cort Dougan <[email protected]>9* Rewritten for PReP10* Copyright (c) 1996 Paul Mackerras <[email protected]>11* Low-level exception handers, MMU support, and rewrite.12* Copyright (c) 1997 Dan Malek <[email protected]>13* PowerPC 8xx modifications.14* Copyright (c) 1998-1999 TiVo, Inc.15* PowerPC 403GCX modifications.16* Copyright (c) 1999 Grant Erickson <[email protected]>17* PowerPC 403GCX/405GP modifications.18* Copyright 2000 MontaVista Software Inc.19* PPC405 modifications20* PowerPC 403GCX/405GP modifications.21* Author: MontaVista Software, Inc.22* [email protected] or [email protected]23* [email protected]24*25* This file is subject to the terms and conditions of the GNU General Public26* License. See the file "COPYING" in the main directory of this archive27* for more details.28*/2930#include <linux/init.h>31#include <linux/linkage.h>32#include <asm/thread_info.h>33#include <asm/page.h>34#include <linux/of_fdt.h> /* for OF_DT_HEADER */3536#ifdef CONFIG_MMU37#include <asm/setup.h> /* COMMAND_LINE_SIZE */38#include <asm/mmu.h>39#include <asm/processor.h>4041.section .data42.global empty_zero_page43.align 1244empty_zero_page:45.space PAGE_SIZE46.global swapper_pg_dir47swapper_pg_dir:48.space PAGE_SIZE4950#endif /* CONFIG_MMU */5152.section .rodata53.align 454endian_check:55.word 15657__HEAD58ENTRY(_start)59#if CONFIG_KERNEL_BASE_ADDR == 060brai TOPHYS(real_start)61.org 0x10062real_start:63#endif6465mfs r1, rmsr66andi r1, r1, ~267mts rmsr, r168/*69* According to Xilinx, msrclr instruction behaves like 'mfs rX,rpc'70* if the msrclr instruction is not enabled. We use this to detect71* if the opcode is available, by issuing msrclr and then testing the result.72* r8 == 0 - msr instructions are implemented73* r8 != 0 - msr instructions are not implemented74*/75msrclr r8, 0 /* clear nothing - just read msr for test */76cmpu r8, r8, r1 /* r1 must contain msr reg content */7778/* r7 may point to an FDT, or there may be one linked in.79if it's in r7, we've got to save it away ASAP.80We ensure r7 points to a valid FDT, just in case the bootloader81is broken or non-existent */82beqi r7, no_fdt_arg /* NULL pointer? don't copy */83/* Does r7 point to a valid FDT? Load HEADER magic number */84/* Run time Big/Little endian platform */85/* Save 1 as word and load byte - 0 - BIG, 1 - LITTLE */86lbui r11, r0, TOPHYS(endian_check)87beqid r11, big_endian /* DO NOT break delay stop dependency */88lw r11, r0, r7 /* Big endian load in delay slot */89lwr r11, r0, r7 /* Little endian load */90big_endian:91rsubi r11, r11, OF_DT_HEADER /* Check FDT header */92beqi r11, _prepare_copy_fdt93or r7, r0, r0 /* clear R7 when not valid DTB */94bnei r11, no_fdt_arg /* No - get out of here */95_prepare_copy_fdt:96or r11, r0, r0 /* incremment */97ori r4, r0, TOPHYS(_fdt_start)98ori r3, r0, (0x4000 - 4)99_copy_fdt:100lw r12, r7, r11 /* r12 = r7 + r11 */101sw r12, r4, r11 /* addr[r4 + r11] = r12 */102addik r11, r11, 4 /* increment counting */103bgtid r3, _copy_fdt /* loop for all entries */104addik r3, r3, -4 /* descrement loop */105no_fdt_arg:106107#ifdef CONFIG_MMU108109#ifndef CONFIG_CMDLINE_BOOL110/*111* handling command line112* copy command line to __init_end. There is space for storing command line.113*/114or r6, r0, r0 /* incremment */115ori r4, r0, __init_end /* load address of command line */116tophys(r4,r4) /* convert to phys address */117ori r3, r0, COMMAND_LINE_SIZE - 1 /* number of loops */118_copy_command_line:119lbu r2, r5, r6 /* r2=r5+r6 - r5 contain pointer to command line */120sb r2, r4, r6 /* addr[r4+r6]= r2*/121addik r6, r6, 1 /* increment counting */122bgtid r3, _copy_command_line /* loop for all entries */123addik r3, r3, -1 /* descrement loop */124addik r5, r4, 0 /* add new space for command line */125tovirt(r5,r5)126#endif /* CONFIG_CMDLINE_BOOL */127128#ifdef NOT_COMPILE129/* save bram context */130or r6, r0, r0 /* incremment */131ori r4, r0, TOPHYS(_bram_load_start) /* save bram context */132ori r3, r0, (LMB_SIZE - 4)133_copy_bram:134lw r7, r0, r6 /* r7 = r0 + r6 */135sw r7, r4, r6 /* addr[r4 + r6] = r7*/136addik r6, r6, 4 /* increment counting */137bgtid r3, _copy_bram /* loop for all entries */138addik r3, r3, -4 /* descrement loop */139#endif140/* We have to turn on the MMU right away. */141142/*143* Set up the initial MMU state so we can do the first level of144* kernel initialization. This maps the first 16 MBytes of memory 1:1145* virtual to physical.146*/147nop148addik r3, r0, MICROBLAZE_TLB_SIZE -1 /* Invalidate all TLB entries */149_invalidate:150mts rtlbx, r3151mts rtlbhi, r0 /* flush: ensure V is clear */152bgtid r3, _invalidate /* loop for all entries */153addik r3, r3, -1154/* sync */155156/* Setup the kernel PID */157mts rpid,r0 /* Load the kernel PID */158nop159bri 4160161/*162* We should still be executing code at physical address area163* RAM_BASEADDR at this point. However, kernel code is at164* a virtual address. So, set up a TLB mapping to cover this once165* translation is enabled.166*/167168addik r3,r0, CONFIG_KERNEL_START /* Load the kernel virtual address */169tophys(r4,r3) /* Load the kernel physical address */170171/*172* Configure and load two entries into TLB slots 0 and 1.173* In case we are pinning TLBs, these are reserved in by the174* other TLB functions. If not reserving, then it doesn't175* matter where they are loaded.176*/177andi r4,r4,0xfffffc00 /* Mask off the real page number */178ori r4,r4,(TLB_WR | TLB_EX) /* Set the write and execute bits */179180andi r3,r3,0xfffffc00 /* Mask off the effective page number */181ori r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_16M))182183mts rtlbx,r0 /* TLB slow 0 */184185mts rtlblo,r4 /* Load the data portion of the entry */186mts rtlbhi,r3 /* Load the tag portion of the entry */187188addik r4, r4, 0x01000000 /* Map next 16 M entries */189addik r3, r3, 0x01000000190191ori r6,r0,1 /* TLB slot 1 */192mts rtlbx,r6193194mts rtlblo,r4 /* Load the data portion of the entry */195mts rtlbhi,r3 /* Load the tag portion of the entry */196197/*198* Load a TLB entry for LMB, since we need access to199* the exception vectors, using a 4k real==virtual mapping.200*/201ori r6,r0,3 /* TLB slot 3 */202mts rtlbx,r6203204ori r4,r0,(TLB_WR | TLB_EX)205ori r3,r0,(TLB_VALID | TLB_PAGESZ(PAGESZ_4K))206207mts rtlblo,r4 /* Load the data portion of the entry */208mts rtlbhi,r3 /* Load the tag portion of the entry */209210/*211* We now have the lower 16 Meg of RAM mapped into TLB entries, and the212* caches ready to work.213*/214turn_on_mmu:215ori r15,r0,start_here216ori r4,r0,MSR_KERNEL_VMS217mts rmsr,r4218nop219rted r15,0 /* enables MMU */220nop221222start_here:223#endif /* CONFIG_MMU */224225/* Initialize small data anchors */226addik r13, r0, _KERNEL_SDA_BASE_227addik r2, r0, _KERNEL_SDA2_BASE_228229/* Initialize stack pointer */230addik r1, r0, init_thread_union + THREAD_SIZE - 4231232/* Initialize r31 with current task address */233addik r31, r0, init_task234235/*236* Call platform dependent initialize function.237* Please see $(ARCH)/mach-$(SUBARCH)/setup.c for238* the function.239*/240addik r9, r0, machine_early_init241brald r15, r9242nop243244#ifndef CONFIG_MMU245addik r15, r0, machine_halt246braid start_kernel247nop248#else249/*250* Initialize the MMU.251*/252bralid r15, mmu_init253nop254255/* Go back to running unmapped so we can load up new values256* and change to using our exception vectors.257* On the MicroBlaze, all we invalidate the used TLB entries to clear258* the old 16M byte TLB mappings.259*/260ori r15,r0,TOPHYS(kernel_load_context)261ori r4,r0,MSR_KERNEL262mts rmsr,r4263nop264bri 4265rted r15,0266nop267268/* Load up the kernel context */269kernel_load_context:270# Keep entry 0 and 1 valid. Entry 3 mapped to LMB can go away.271ori r5,r0,3272mts rtlbx,r5273nop274mts rtlbhi,r0275nop276addi r15, r0, machine_halt277ori r17, r0, start_kernel278ori r4, r0, MSR_KERNEL_VMS279mts rmsr, r4280nop281rted r17, 0 /* enable MMU and jump to start_kernel */282nop283#endif /* CONFIG_MMU */284285286