1*57356e90SAchin Gupta/* 2*57356e90SAchin Gupta * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3*57356e90SAchin Gupta * 4*57356e90SAchin Gupta * Redistribution and use in source and binary forms, with or without 5*57356e90SAchin Gupta * modification, are permitted provided that the following conditions are met: 6*57356e90SAchin Gupta * 7*57356e90SAchin Gupta * Redistributions of source code must retain the above copyright notice, this 8*57356e90SAchin Gupta * list of conditions and the following disclaimer. 9*57356e90SAchin Gupta * 10*57356e90SAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 11*57356e90SAchin Gupta * this list of conditions and the following disclaimer in the documentation 12*57356e90SAchin Gupta * and/or other materials provided with the distribution. 13*57356e90SAchin Gupta * 14*57356e90SAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 15*57356e90SAchin Gupta * to endorse or promote products derived from this software without specific 16*57356e90SAchin Gupta * prior written permission. 17*57356e90SAchin Gupta * 18*57356e90SAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*57356e90SAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*57356e90SAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*57356e90SAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*57356e90SAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*57356e90SAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*57356e90SAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*57356e90SAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*57356e90SAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*57356e90SAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*57356e90SAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 29*57356e90SAchin Gupta */ 30*57356e90SAchin Gupta 31*57356e90SAchin Gupta#include <bl_common.h> 32*57356e90SAchin Gupta#include <arch.h> 33*57356e90SAchin Gupta#include <tsp.h> 34*57356e90SAchin Gupta#include <asm_macros.S> 35*57356e90SAchin Gupta 36*57356e90SAchin Gupta 37*57356e90SAchin Gupta /* ---------------------------------------------------- 38*57356e90SAchin Gupta * The caller-saved registers x0-x18 and LR are saved 39*57356e90SAchin Gupta * here. 40*57356e90SAchin Gupta * ---------------------------------------------------- 41*57356e90SAchin Gupta */ 42*57356e90SAchin Gupta 43*57356e90SAchin Gupta#define SCRATCH_REG_SIZE #(20 * 8) 44*57356e90SAchin Gupta 45*57356e90SAchin Gupta .macro save_caller_regs_and_lr 46*57356e90SAchin Gupta sub sp, sp, SCRATCH_REG_SIZE 47*57356e90SAchin Gupta stp x0, x1, [sp] 48*57356e90SAchin Gupta stp x2, x3, [sp, #0x10] 49*57356e90SAchin Gupta stp x4, x5, [sp, #0x20] 50*57356e90SAchin Gupta stp x6, x7, [sp, #0x30] 51*57356e90SAchin Gupta stp x8, x9, [sp, #0x40] 52*57356e90SAchin Gupta stp x10, x11, [sp, #0x50] 53*57356e90SAchin Gupta stp x12, x13, [sp, #0x60] 54*57356e90SAchin Gupta stp x14, x15, [sp, #0x70] 55*57356e90SAchin Gupta stp x16, x17, [sp, #0x80] 56*57356e90SAchin Gupta stp x18, x30, [sp, #0x90] 57*57356e90SAchin Gupta .endm 58*57356e90SAchin Gupta 59*57356e90SAchin Gupta .macro restore_caller_regs_and_lr 60*57356e90SAchin Gupta ldp x0, x1, [sp] 61*57356e90SAchin Gupta ldp x2, x3, [sp, #0x10] 62*57356e90SAchin Gupta ldp x4, x5, [sp, #0x20] 63*57356e90SAchin Gupta ldp x6, x7, [sp, #0x30] 64*57356e90SAchin Gupta ldp x8, x9, [sp, #0x40] 65*57356e90SAchin Gupta ldp x10, x11, [sp, #0x50] 66*57356e90SAchin Gupta ldp x12, x13, [sp, #0x60] 67*57356e90SAchin Gupta ldp x14, x15, [sp, #0x70] 68*57356e90SAchin Gupta ldp x16, x17, [sp, #0x80] 69*57356e90SAchin Gupta ldp x18, x30, [sp, #0x90] 70*57356e90SAchin Gupta add sp, sp, SCRATCH_REG_SIZE 71*57356e90SAchin Gupta .endm 72*57356e90SAchin Gupta 73*57356e90SAchin Gupta .globl tsp_exceptions 74*57356e90SAchin Gupta 75*57356e90SAchin Gupta /* ----------------------------------------------------- 76*57356e90SAchin Gupta * TSP exception handlers. 77*57356e90SAchin Gupta * ----------------------------------------------------- 78*57356e90SAchin Gupta */ 79*57356e90SAchin Gupta .section .vectors, "ax"; .align 11 80*57356e90SAchin Gupta 81*57356e90SAchin Gupta .align 7 82*57356e90SAchin Guptatsp_exceptions: 83*57356e90SAchin Gupta /* ----------------------------------------------------- 84*57356e90SAchin Gupta * Current EL with _sp_el0 : 0x0 - 0x180. No exceptions 85*57356e90SAchin Gupta * are expected and treated as irrecoverable errors. 86*57356e90SAchin Gupta * ----------------------------------------------------- 87*57356e90SAchin Gupta */ 88*57356e90SAchin Guptasync_exception_sp_el0: 89*57356e90SAchin Gupta wfi 90*57356e90SAchin Gupta b sync_exception_sp_el0 91*57356e90SAchin Gupta check_vector_size sync_exception_sp_el0 92*57356e90SAchin Gupta 93*57356e90SAchin Gupta .align 7 94*57356e90SAchin Gupta 95*57356e90SAchin Guptairq_sp_el0: 96*57356e90SAchin Gupta b irq_sp_el0 97*57356e90SAchin Gupta check_vector_size irq_sp_el0 98*57356e90SAchin Gupta 99*57356e90SAchin Gupta .align 7 100*57356e90SAchin Guptafiq_sp_el0: 101*57356e90SAchin Gupta b fiq_sp_el0 102*57356e90SAchin Gupta check_vector_size fiq_sp_el0 103*57356e90SAchin Gupta 104*57356e90SAchin Gupta .align 7 105*57356e90SAchin Guptaserror_sp_el0: 106*57356e90SAchin Gupta b serror_sp_el0 107*57356e90SAchin Gupta check_vector_size serror_sp_el0 108*57356e90SAchin Gupta 109*57356e90SAchin Gupta 110*57356e90SAchin Gupta /* ----------------------------------------------------- 111*57356e90SAchin Gupta * Current EL with SPx: 0x200 - 0x380. Only IRQs/FIQs 112*57356e90SAchin Gupta * are expected and handled 113*57356e90SAchin Gupta * ----------------------------------------------------- 114*57356e90SAchin Gupta */ 115*57356e90SAchin Gupta .align 7 116*57356e90SAchin Guptasync_exception_sp_elx: 117*57356e90SAchin Gupta wfi 118*57356e90SAchin Gupta b sync_exception_sp_elx 119*57356e90SAchin Gupta check_vector_size sync_exception_sp_elx 120*57356e90SAchin Gupta 121*57356e90SAchin Gupta .align 7 122*57356e90SAchin Guptairq_sp_elx: 123*57356e90SAchin Gupta b irq_sp_elx 124*57356e90SAchin Gupta check_vector_size irq_sp_elx 125*57356e90SAchin Gupta 126*57356e90SAchin Gupta .align 7 127*57356e90SAchin Guptafiq_sp_elx: 128*57356e90SAchin Gupta save_caller_regs_and_lr 129*57356e90SAchin Gupta bl tsp_fiq_handler 130*57356e90SAchin Gupta cbz x0, fiq_sp_elx_done 131*57356e90SAchin Gupta 132*57356e90SAchin Gupta /* 133*57356e90SAchin Gupta * This FIQ was not targetted to S-EL1 so send it to 134*57356e90SAchin Gupta * the monitor and wait for execution to resume. 135*57356e90SAchin Gupta */ 136*57356e90SAchin Gupta smc #0 137*57356e90SAchin Guptafiq_sp_elx_done: 138*57356e90SAchin Gupta restore_caller_regs_and_lr 139*57356e90SAchin Gupta eret 140*57356e90SAchin Gupta check_vector_size fiq_sp_elx 141*57356e90SAchin Gupta 142*57356e90SAchin Gupta .align 7 143*57356e90SAchin Guptaserror_sp_elx: 144*57356e90SAchin Gupta b serror_sp_elx 145*57356e90SAchin Gupta check_vector_size serror_sp_elx 146*57356e90SAchin Gupta 147*57356e90SAchin Gupta 148*57356e90SAchin Gupta /* ----------------------------------------------------- 149*57356e90SAchin Gupta * Lower EL using AArch64 : 0x400 - 0x580. No exceptions 150*57356e90SAchin Gupta * are handled since TSP does not implement a lower EL 151*57356e90SAchin Gupta * ----------------------------------------------------- 152*57356e90SAchin Gupta */ 153*57356e90SAchin Gupta .align 7 154*57356e90SAchin Guptasync_exception_aarch64: 155*57356e90SAchin Gupta wfi 156*57356e90SAchin Gupta b sync_exception_aarch64 157*57356e90SAchin Gupta check_vector_size sync_exception_aarch64 158*57356e90SAchin Gupta 159*57356e90SAchin Gupta .align 7 160*57356e90SAchin Guptairq_aarch64: 161*57356e90SAchin Gupta b irq_aarch64 162*57356e90SAchin Gupta check_vector_size irq_aarch64 163*57356e90SAchin Gupta 164*57356e90SAchin Gupta .align 7 165*57356e90SAchin Guptafiq_aarch64: 166*57356e90SAchin Gupta b fiq_aarch64 167*57356e90SAchin Gupta check_vector_size fiq_aarch64 168*57356e90SAchin Gupta 169*57356e90SAchin Gupta .align 7 170*57356e90SAchin Guptaserror_aarch64: 171*57356e90SAchin Gupta b serror_aarch64 172*57356e90SAchin Gupta check_vector_size serror_aarch64 173*57356e90SAchin Gupta 174*57356e90SAchin Gupta 175*57356e90SAchin Gupta /* ----------------------------------------------------- 176*57356e90SAchin Gupta * Lower EL using AArch32 : 0x600 - 0x780. No exceptions 177*57356e90SAchin Gupta * handled since the TSP does not implement a lower EL. 178*57356e90SAchin Gupta * ----------------------------------------------------- 179*57356e90SAchin Gupta */ 180*57356e90SAchin Gupta .align 7 181*57356e90SAchin Guptasync_exception_aarch32: 182*57356e90SAchin Gupta wfi 183*57356e90SAchin Gupta b sync_exception_aarch32 184*57356e90SAchin Gupta check_vector_size sync_exception_aarch32 185*57356e90SAchin Gupta 186*57356e90SAchin Gupta .align 7 187*57356e90SAchin Guptairq_aarch32: 188*57356e90SAchin Gupta b irq_aarch32 189*57356e90SAchin Gupta check_vector_size irq_aarch32 190*57356e90SAchin Gupta 191*57356e90SAchin Gupta .align 7 192*57356e90SAchin Guptafiq_aarch32: 193*57356e90SAchin Gupta b fiq_aarch32 194*57356e90SAchin Gupta check_vector_size fiq_aarch32 195*57356e90SAchin Gupta 196*57356e90SAchin Gupta .align 7 197*57356e90SAchin Guptaserror_aarch32: 198*57356e90SAchin Gupta b serror_aarch32 199*57356e90SAchin Gupta check_vector_size serror_aarch32 200*57356e90SAchin Gupta .align 7 201