1*d48c12e9SYatharth Kochar/* 2*d48c12e9SYatharth Kochar * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3*d48c12e9SYatharth Kochar * 4*d48c12e9SYatharth Kochar * Redistribution and use in source and binary forms, with or without 5*d48c12e9SYatharth Kochar * modification, are permitted provided that the following conditions are met: 6*d48c12e9SYatharth Kochar * 7*d48c12e9SYatharth Kochar * Redistributions of source code must retain the above copyright notice, this 8*d48c12e9SYatharth Kochar * list of conditions and the following disclaimer. 9*d48c12e9SYatharth Kochar * 10*d48c12e9SYatharth Kochar * Redistributions in binary form must reproduce the above copyright notice, 11*d48c12e9SYatharth Kochar * this list of conditions and the following disclaimer in the documentation 12*d48c12e9SYatharth Kochar * and/or other materials provided with the distribution. 13*d48c12e9SYatharth Kochar * 14*d48c12e9SYatharth Kochar * Neither the name of ARM nor the names of its contributors may be used 15*d48c12e9SYatharth Kochar * to endorse or promote products derived from this software without specific 16*d48c12e9SYatharth Kochar * prior written permission. 17*d48c12e9SYatharth Kochar * 18*d48c12e9SYatharth Kochar * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*d48c12e9SYatharth Kochar * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*d48c12e9SYatharth Kochar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*d48c12e9SYatharth Kochar * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*d48c12e9SYatharth Kochar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*d48c12e9SYatharth Kochar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*d48c12e9SYatharth Kochar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*d48c12e9SYatharth Kochar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*d48c12e9SYatharth Kochar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*d48c12e9SYatharth Kochar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*d48c12e9SYatharth Kochar * POSSIBILITY OF SUCH DAMAGE. 29*d48c12e9SYatharth Kochar */ 30*d48c12e9SYatharth Kochar 31*d48c12e9SYatharth Kochar#include <arch.h> 32*d48c12e9SYatharth Kochar#include <asm_macros.S> 33*d48c12e9SYatharth Kochar#include <bl_common.h> 34*d48c12e9SYatharth Kochar 35*d48c12e9SYatharth Kochar 36*d48c12e9SYatharth Kochar .globl bl2_vector_table 37*d48c12e9SYatharth Kochar .globl bl2_entrypoint 38*d48c12e9SYatharth Kochar 39*d48c12e9SYatharth Kochar 40*d48c12e9SYatharth Kocharvector_base bl2_vector_table 41*d48c12e9SYatharth Kochar b bl2_entrypoint 42*d48c12e9SYatharth Kochar b report_exception /* Undef */ 43*d48c12e9SYatharth Kochar b report_exception /* SVC call */ 44*d48c12e9SYatharth Kochar b report_exception /* Prefetch abort */ 45*d48c12e9SYatharth Kochar b report_exception /* Data abort */ 46*d48c12e9SYatharth Kochar b report_exception /* Reserved */ 47*d48c12e9SYatharth Kochar b report_exception /* IRQ */ 48*d48c12e9SYatharth Kochar b report_exception /* FIQ */ 49*d48c12e9SYatharth Kochar 50*d48c12e9SYatharth Kochar 51*d48c12e9SYatharth Kocharfunc bl2_entrypoint 52*d48c12e9SYatharth Kochar /*--------------------------------------------- 53*d48c12e9SYatharth Kochar * Save from r1 the extents of the trusted ram 54*d48c12e9SYatharth Kochar * available to BL2 for future use. 55*d48c12e9SYatharth Kochar * r0 is not currently used. 56*d48c12e9SYatharth Kochar * --------------------------------------------- 57*d48c12e9SYatharth Kochar */ 58*d48c12e9SYatharth Kochar mov r11, r1 59*d48c12e9SYatharth Kochar 60*d48c12e9SYatharth Kochar /* --------------------------------------------- 61*d48c12e9SYatharth Kochar * Set the exception vector to something sane. 62*d48c12e9SYatharth Kochar * --------------------------------------------- 63*d48c12e9SYatharth Kochar */ 64*d48c12e9SYatharth Kochar ldr r0, =bl2_vector_table 65*d48c12e9SYatharth Kochar stcopr r0, VBAR 66*d48c12e9SYatharth Kochar isb 67*d48c12e9SYatharth Kochar 68*d48c12e9SYatharth Kochar /* ----------------------------------------------------- 69*d48c12e9SYatharth Kochar * Enable the instruction cache 70*d48c12e9SYatharth Kochar * ----------------------------------------------------- 71*d48c12e9SYatharth Kochar */ 72*d48c12e9SYatharth Kochar ldcopr r0, SCTLR 73*d48c12e9SYatharth Kochar orr r0, r0, #SCTLR_I_BIT 74*d48c12e9SYatharth Kochar stcopr r0, SCTLR 75*d48c12e9SYatharth Kochar isb 76*d48c12e9SYatharth Kochar 77*d48c12e9SYatharth Kochar /* --------------------------------------------- 78*d48c12e9SYatharth Kochar * Since BL2 executes after BL1, it is assumed 79*d48c12e9SYatharth Kochar * here that BL1 has already has done the 80*d48c12e9SYatharth Kochar * necessary register initializations. 81*d48c12e9SYatharth Kochar * --------------------------------------------- 82*d48c12e9SYatharth Kochar */ 83*d48c12e9SYatharth Kochar 84*d48c12e9SYatharth Kochar /* --------------------------------------------- 85*d48c12e9SYatharth Kochar * Invalidate the RW memory used by the BL2 86*d48c12e9SYatharth Kochar * image. This includes the data and NOBITS 87*d48c12e9SYatharth Kochar * sections. This is done to safeguard against 88*d48c12e9SYatharth Kochar * possible corruption of this memory by dirty 89*d48c12e9SYatharth Kochar * cache lines in a system cache as a result of 90*d48c12e9SYatharth Kochar * use by an earlier boot loader stage. 91*d48c12e9SYatharth Kochar * --------------------------------------------- 92*d48c12e9SYatharth Kochar */ 93*d48c12e9SYatharth Kochar ldr r0, =__RW_START__ 94*d48c12e9SYatharth Kochar ldr r1, =__RW_END__ 95*d48c12e9SYatharth Kochar sub r1, r1, r0 96*d48c12e9SYatharth Kochar bl inv_dcache_range 97*d48c12e9SYatharth Kochar 98*d48c12e9SYatharth Kochar /* --------------------------------------------- 99*d48c12e9SYatharth Kochar * Zero out NOBITS sections. There are 2 of them: 100*d48c12e9SYatharth Kochar * - the .bss section; 101*d48c12e9SYatharth Kochar * - the coherent memory section. 102*d48c12e9SYatharth Kochar * --------------------------------------------- 103*d48c12e9SYatharth Kochar */ 104*d48c12e9SYatharth Kochar ldr r0, =__BSS_START__ 105*d48c12e9SYatharth Kochar ldr r1, =__BSS_SIZE__ 106*d48c12e9SYatharth Kochar bl zeromem 107*d48c12e9SYatharth Kochar 108*d48c12e9SYatharth Kochar#if USE_COHERENT_MEM 109*d48c12e9SYatharth Kochar ldr r0, =__COHERENT_RAM_START__ 110*d48c12e9SYatharth Kochar ldr r1, =__COHERENT_RAM_UNALIGNED_SIZE__ 111*d48c12e9SYatharth Kochar bl zeromem 112*d48c12e9SYatharth Kochar#endif 113*d48c12e9SYatharth Kochar 114*d48c12e9SYatharth Kochar /* -------------------------------------------- 115*d48c12e9SYatharth Kochar * Allocate a stack whose memory will be marked 116*d48c12e9SYatharth Kochar * as Normal-IS-WBWA when the MMU is enabled. 117*d48c12e9SYatharth Kochar * There is no risk of reading stale stack 118*d48c12e9SYatharth Kochar * memory after enabling the MMU as only the 119*d48c12e9SYatharth Kochar * primary cpu is running at the moment. 120*d48c12e9SYatharth Kochar * -------------------------------------------- 121*d48c12e9SYatharth Kochar */ 122*d48c12e9SYatharth Kochar bl plat_set_my_stack 123*d48c12e9SYatharth Kochar 124*d48c12e9SYatharth Kochar /* --------------------------------------------- 125*d48c12e9SYatharth Kochar * Perform early platform setup & platform 126*d48c12e9SYatharth Kochar * specific early arch. setup e.g. mmu setup 127*d48c12e9SYatharth Kochar * --------------------------------------------- 128*d48c12e9SYatharth Kochar */ 129*d48c12e9SYatharth Kochar mov r0, r11 130*d48c12e9SYatharth Kochar bl bl2_early_platform_setup 131*d48c12e9SYatharth Kochar bl bl2_plat_arch_setup 132*d48c12e9SYatharth Kochar 133*d48c12e9SYatharth Kochar /* --------------------------------------------- 134*d48c12e9SYatharth Kochar * Jump to main function. 135*d48c12e9SYatharth Kochar * --------------------------------------------- 136*d48c12e9SYatharth Kochar */ 137*d48c12e9SYatharth Kochar bl bl2_main 138*d48c12e9SYatharth Kochar 139*d48c12e9SYatharth Kochar /* --------------------------------------------- 140*d48c12e9SYatharth Kochar * Should never reach this point. 141*d48c12e9SYatharth Kochar * --------------------------------------------- 142*d48c12e9SYatharth Kochar */ 143*d48c12e9SYatharth Kochar bl plat_panic_handler 144*d48c12e9SYatharth Kochar 145*d48c12e9SYatharth Kocharendfunc bl2_entrypoint 146