2 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 #include <asm_macros.S>
10 #include <bl_common.h>
12 #include <smccc_helpers.h>
13 #include <smccc_macros.S>
14 #include <xlat_tables.h>
16 .globl bl1_aarch32_smc_handler
19 func bl1_aarch32_smc_handler
20 /* On SMC entry, `sp` points to `smc_ctx_t`. Save `lr`. */
21 str lr, [sp, #SMC_CTX_LR_MON]
23 /* ------------------------------------------------
24 * SMC in BL1 is handled assuming that the MMU is
26 * ------------------------------------------------
29 /* ----------------------------------------------
30 * Detect if this is a RUN_IMAGE or other SMC.
31 * ----------------------------------------------
33 mov lr, #BL1_SMC_RUN_IMAGE
37 /* ------------------------------------------------
38 * Make sure only Secure world reaches here.
39 * ------------------------------------------------
45 /* ---------------------------------------------------------------------
46 * Pass control to next secure image.
47 * Here it expects r1 to contain the address of a entry_point_info_t
48 * structure describing the BL entrypoint.
49 * ---------------------------------------------------------------------
53 bl bl1_print_next_bl_ep_info
56 bl print_debug_loop_message
62 bl bl1_plat_prepare_exit
69 * Extract PC and SPSR based on struct `entry_point_info_t`
70 * and load it in LR and SPSR registers respectively.
72 ldr lr, [r8, #ENTRY_POINT_INFO_PC_OFFSET]
73 ldr r1, [r8, #(ENTRY_POINT_INFO_PC_OFFSET + 4)]
76 /* Some BL32 stages expect lr_svc to provide the BL33 entry address */
78 ldr lr, [r8, #ENTRY_POINT_INFO_LR_SVC_OFFSET]
81 add r8, r8, #ENTRY_POINT_INFO_ARGS_OFFSET
82 ldm r8, {r0, r1, r2, r3}
84 endfunc bl1_aarch32_smc_handler
86 /* -----------------------------------------------------
87 * Save Secure/Normal world context and jump to
89 * -----------------------------------------------------
92 /* -----------------------------------------------------
93 * Save the GP registers.
94 * -----------------------------------------------------
96 smccc_save_gp_mode_regs
99 * `sp` still points to `smc_ctx_t`. Save it to a register
100 * and restore the C runtime stack pointer to `sp`.
103 ldr sp, [r6, #SMC_CTX_SP_MON]
105 ldr r0, [r6, #SMC_CTX_SCR]
106 and r7, r0, #SCR_NS_BIT /* flags */
108 /* Switch to Secure Mode */
113 /* If caller is from Secure world then turn on the MMU */
117 /* Turn on the MMU */
118 mov r0, #DISABLE_DCACHE
119 bl enable_mmu_svc_mon
121 /* Enable the data cache. */
123 orr r9, r9, #SCTLR_C_BIT
128 /* Prepare arguments for BL1 SMC wrapper. */
129 ldr r0, [r6, #SMC_CTX_GPREG_R0] /* smc_fid */
130 mov r1, #0 /* cookie */
131 mov r2, r6 /* handle */
132 mov r3, r7 /* flags */
135 /* Get the smc_context for next BL image */
139 /* Only turn-off MMU if going to secure world */
140 ldr r5, [r4, #SMC_CTX_SCR]
144 /* Disable the MMU */
145 bl disable_mmu_icache_secure
151 /* -----------------------------------------------------
152 * Do the transition to next BL image.
153 * -----------------------------------------------------