14f6ad66aSAchin Gupta/* 2e83b0cadSDan Handley * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 44f6ad66aSAchin Gupta * Redistribution and use in source and binary forms, with or without 54f6ad66aSAchin Gupta * modification, are permitted provided that the following conditions are met: 64f6ad66aSAchin Gupta * 74f6ad66aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 84f6ad66aSAchin Gupta * list of conditions and the following disclaimer. 94f6ad66aSAchin Gupta * 104f6ad66aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 114f6ad66aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 124f6ad66aSAchin Gupta * and/or other materials provided with the distribution. 134f6ad66aSAchin Gupta * 144f6ad66aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 154f6ad66aSAchin Gupta * to endorse or promote products derived from this software without specific 164f6ad66aSAchin Gupta * prior written permission. 174f6ad66aSAchin Gupta * 184f6ad66aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 194f6ad66aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204f6ad66aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214f6ad66aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 224f6ad66aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234f6ad66aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244f6ad66aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254f6ad66aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264f6ad66aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274f6ad66aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284f6ad66aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 294f6ad66aSAchin Gupta */ 304f6ad66aSAchin Gupta 314f6ad66aSAchin Gupta#include <bl_common.h> 324f6ad66aSAchin Gupta#include <platform.h> 33c10bd2ceSSandrine Bailleux#include <arch.h> 34caa84939SJeenu Viswambharan#include "cm_macros.S" 354f6ad66aSAchin Gupta 364f6ad66aSAchin Gupta 374f6ad66aSAchin Gupta .globl bl31_entrypoint 384f6ad66aSAchin Gupta 394f6ad66aSAchin Gupta 408d69a03fSSandrine Bailleux .section .text, "ax"; .align 3 414f6ad66aSAchin Gupta 424f6ad66aSAchin Gupta /* ----------------------------------------------------- 434f6ad66aSAchin Gupta * bl31_entrypoint() is the cold boot entrypoint, 444f6ad66aSAchin Gupta * executed only by the primary cpu. 454f6ad66aSAchin Gupta * ----------------------------------------------------- 464f6ad66aSAchin Gupta */ 474f6ad66aSAchin Gupta 484f6ad66aSAchin Guptabl31_entrypoint: ; .type bl31_entrypoint, %function 494f6ad66aSAchin Gupta /* --------------------------------------------- 50*e4d084eaSAchin Gupta * BL2 has populated x0 with the opcode 51*e4d084eaSAchin Gupta * indicating BL31 should be run, x3 with 52*e4d084eaSAchin Gupta * a pointer to a 'bl31_args' structure & x4 53*e4d084eaSAchin Gupta * with any other optional information 54c10bd2ceSSandrine Bailleux * --------------------------------------------- 55c10bd2ceSSandrine Bailleux */ 56c10bd2ceSSandrine Bailleux 57c10bd2ceSSandrine Bailleux /* --------------------------------------------- 58c10bd2ceSSandrine Bailleux * Set the exception vector to something sane. 59c10bd2ceSSandrine Bailleux * --------------------------------------------- 60c10bd2ceSSandrine Bailleux */ 61b739f22aSAchin Gupta adr x1, early_exceptions 62c10bd2ceSSandrine Bailleux msr vbar_el3, x1 63c10bd2ceSSandrine Bailleux 644f603683SHarry Liebel /* --------------------------------------------------------------------- 654f603683SHarry Liebel * The initial state of the Architectural feature trap register 664f603683SHarry Liebel * (CPTR_EL3) is unknown and it must be set to a known state. All 674f603683SHarry Liebel * feature traps are disabled. Some bits in this register are marked as 684f603683SHarry Liebel * Reserved and should not be modified. 694f603683SHarry Liebel * 704f603683SHarry Liebel * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1 714f603683SHarry Liebel * or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2. 724f603683SHarry Liebel * CPTR_EL3.TTA: This causes access to the Trace functionality to trap 734f603683SHarry Liebel * to EL3 when executed from EL0, EL1, EL2, or EL3. If system register 744f603683SHarry Liebel * access to trace functionality is not supported, this bit is RES0. 754f603683SHarry Liebel * CPTR_EL3.TFP: This causes instructions that access the registers 764f603683SHarry Liebel * associated with Floating Point and Advanced SIMD execution to trap 774f603683SHarry Liebel * to EL3 when executed from any exception level, unless trapped to EL1 784f603683SHarry Liebel * or EL2. 794f603683SHarry Liebel * --------------------------------------------------------------------- 804f603683SHarry Liebel */ 814f603683SHarry Liebel mrs x1, cptr_el3 824f603683SHarry Liebel bic w1, w1, #TCPAC_BIT 834f603683SHarry Liebel bic w1, w1, #TTA_BIT 844f603683SHarry Liebel bic w1, w1, #TFP_BIT 854f603683SHarry Liebel msr cptr_el3, x1 864f603683SHarry Liebel 87c10bd2ceSSandrine Bailleux /* --------------------------------------------- 88c10bd2ceSSandrine Bailleux * Enable the instruction cache. 89c10bd2ceSSandrine Bailleux * --------------------------------------------- 90c10bd2ceSSandrine Bailleux */ 91c10bd2ceSSandrine Bailleux mrs x1, sctlr_el3 92c10bd2ceSSandrine Bailleux orr x1, x1, #SCTLR_I_BIT 93c10bd2ceSSandrine Bailleux msr sctlr_el3, x1 94c10bd2ceSSandrine Bailleux 95c10bd2ceSSandrine Bailleux isb 96c10bd2ceSSandrine Bailleux 97c10bd2ceSSandrine Bailleux /* --------------------------------------------- 98c10bd2ceSSandrine Bailleux * Check the opcodes out of paranoia. 994f6ad66aSAchin Gupta * --------------------------------------------- 1004f6ad66aSAchin Gupta */ 1014f6ad66aSAchin Gupta mov x19, #RUN_IMAGE 1024f6ad66aSAchin Gupta cmp x0, x19 1034f6ad66aSAchin Gupta b.ne _panic 1044f6ad66aSAchin Gupta mov x20, x3 1054f6ad66aSAchin Gupta mov x21, x4 1064f6ad66aSAchin Gupta 1074f6ad66aSAchin Gupta /* --------------------------------------------- 1084f6ad66aSAchin Gupta * This is BL31 which is expected to be executed 1094f6ad66aSAchin Gupta * only by the primary cpu (at least for now). 1104f6ad66aSAchin Gupta * So, make sure no secondary has lost its way. 1114f6ad66aSAchin Gupta * --------------------------------------------- 1124f6ad66aSAchin Gupta */ 1134f6ad66aSAchin Gupta bl read_mpidr 1144f6ad66aSAchin Gupta mov x19, x0 1154f6ad66aSAchin Gupta bl platform_is_primary_cpu 1164f6ad66aSAchin Gupta cbz x0, _panic 1174f6ad66aSAchin Gupta 11865f546a1SSandrine Bailleux /* --------------------------------------------- 11965f546a1SSandrine Bailleux * Zero out NOBITS sections. There are 2 of them: 12065f546a1SSandrine Bailleux * - the .bss section; 12165f546a1SSandrine Bailleux * - the coherent memory section. 12265f546a1SSandrine Bailleux * --------------------------------------------- 12365f546a1SSandrine Bailleux */ 12465f546a1SSandrine Bailleux ldr x0, =__BSS_START__ 12565f546a1SSandrine Bailleux ldr x1, =__BSS_SIZE__ 12665f546a1SSandrine Bailleux bl zeromem16 12765f546a1SSandrine Bailleux 12865f546a1SSandrine Bailleux ldr x0, =__COHERENT_RAM_START__ 12965f546a1SSandrine Bailleux ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__ 13065f546a1SSandrine Bailleux bl zeromem16 13165f546a1SSandrine Bailleux 132caa84939SJeenu Viswambharan /* --------------------------------------------- 133caa84939SJeenu Viswambharan * Use SP_EL0 for the C runtime stack. 134caa84939SJeenu Viswambharan * --------------------------------------------- 135caa84939SJeenu Viswambharan */ 136caa84939SJeenu Viswambharan msr spsel, #0 137caa84939SJeenu Viswambharan 1384f6ad66aSAchin Gupta /* -------------------------------------------- 1394f6ad66aSAchin Gupta * Give ourselves a small coherent stack to 1404f6ad66aSAchin Gupta * ease the pain of initializing the MMU 1414f6ad66aSAchin Gupta * -------------------------------------------- 1424f6ad66aSAchin Gupta */ 1434f6ad66aSAchin Gupta mov x0, x19 1444f6ad66aSAchin Gupta bl platform_set_coherent_stack 1454f6ad66aSAchin Gupta 1464f6ad66aSAchin Gupta /* --------------------------------------------- 1474f6ad66aSAchin Gupta * Perform platform specific early arch. setup 1484f6ad66aSAchin Gupta * --------------------------------------------- 1494f6ad66aSAchin Gupta */ 1504f6ad66aSAchin Gupta mov x0, x20 1514f6ad66aSAchin Gupta mov x1, x21 1524f6ad66aSAchin Gupta bl bl31_early_platform_setup 1534f6ad66aSAchin Gupta bl bl31_plat_arch_setup 1544f6ad66aSAchin Gupta 1554f6ad66aSAchin Gupta /* --------------------------------------------- 1564f6ad66aSAchin Gupta * Give ourselves a stack allocated in Normal 1574f6ad66aSAchin Gupta * -IS-WBWA memory 1584f6ad66aSAchin Gupta * --------------------------------------------- 1594f6ad66aSAchin Gupta */ 1604f6ad66aSAchin Gupta mov x0, x19 1614f6ad66aSAchin Gupta bl platform_set_stack 1624f6ad66aSAchin Gupta 1634f6ad66aSAchin Gupta /* --------------------------------------------- 1644f6ad66aSAchin Gupta * Jump to main function. 1654f6ad66aSAchin Gupta * --------------------------------------------- 1664f6ad66aSAchin Gupta */ 1674f6ad66aSAchin Gupta bl bl31_main 1684f6ad66aSAchin Gupta 169caa84939SJeenu Viswambharan /* --------------------------------------------- 170caa84939SJeenu Viswambharan * Use the more complex exception vectors now 171caa84939SJeenu Viswambharan * that context management is setup. SP_EL3 is 172caa84939SJeenu Viswambharan * pointing to a 'cpu_context' structure which 173caa84939SJeenu Viswambharan * has an exception stack allocated. Since 174caa84939SJeenu Viswambharan * we're just about to leave this EL with ERET, 175caa84939SJeenu Viswambharan * we don't need an ISB here 176caa84939SJeenu Viswambharan * --------------------------------------------- 177caa84939SJeenu Viswambharan */ 178caa84939SJeenu Viswambharan adr x1, runtime_exceptions 179caa84939SJeenu Viswambharan msr vbar_el3, x1 180caa84939SJeenu Viswambharan 181caa84939SJeenu Viswambharan zero_callee_saved_regs 182caa84939SJeenu Viswambharan b el3_exit 183caa84939SJeenu Viswambharan 1844f6ad66aSAchin Gupta_panic: 185caa84939SJeenu Viswambharan wfi 1864f6ad66aSAchin Gupta b _panic 187