xref: /arm-trusted-firmware/bl2/aarch64/bl2_entrypoint.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu#include <arch.h>
8*91f16700Schasinglulu#include <asm_macros.S>
9*91f16700Schasinglulu#include <common/bl_common.h>
10*91f16700Schasinglulu
11*91f16700Schasinglulu
12*91f16700Schasinglulu	.globl	bl2_entrypoint
13*91f16700Schasinglulu
14*91f16700Schasinglulu
15*91f16700Schasinglulu
16*91f16700Schasinglulufunc bl2_entrypoint
17*91f16700Schasinglulu	/*---------------------------------------------
18*91f16700Schasinglulu	 * Save arguments x0 - x3 from BL1 for future
19*91f16700Schasinglulu	 * use.
20*91f16700Schasinglulu	 * ---------------------------------------------
21*91f16700Schasinglulu	 */
22*91f16700Schasinglulu	mov	x20, x0
23*91f16700Schasinglulu	mov	x21, x1
24*91f16700Schasinglulu	mov	x22, x2
25*91f16700Schasinglulu	mov	x23, x3
26*91f16700Schasinglulu
27*91f16700Schasinglulu	/* ---------------------------------------------
28*91f16700Schasinglulu	 * Set the exception vector to something sane.
29*91f16700Schasinglulu	 * ---------------------------------------------
30*91f16700Schasinglulu	 */
31*91f16700Schasinglulu	adr	x0, early_exceptions
32*91f16700Schasinglulu	msr	vbar_el1, x0
33*91f16700Schasinglulu	isb
34*91f16700Schasinglulu
35*91f16700Schasinglulu	/* ---------------------------------------------
36*91f16700Schasinglulu	 * Enable the SError interrupt now that the
37*91f16700Schasinglulu	 * exception vectors have been setup.
38*91f16700Schasinglulu	 * ---------------------------------------------
39*91f16700Schasinglulu	 */
40*91f16700Schasinglulu	msr	daifclr, #DAIF_ABT_BIT
41*91f16700Schasinglulu
42*91f16700Schasinglulu	/* ---------------------------------------------
43*91f16700Schasinglulu	 * Enable the instruction cache, stack pointer
44*91f16700Schasinglulu	 * and data access alignment checks and disable
45*91f16700Schasinglulu	 * speculative loads.
46*91f16700Schasinglulu	 * ---------------------------------------------
47*91f16700Schasinglulu	 */
48*91f16700Schasinglulu	mov	x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
49*91f16700Schasinglulu	mrs	x0, sctlr_el1
50*91f16700Schasinglulu	orr	x0, x0, x1
51*91f16700Schasinglulu	bic	x0, x0, #SCTLR_DSSBS_BIT
52*91f16700Schasinglulu	msr	sctlr_el1, x0
53*91f16700Schasinglulu	isb
54*91f16700Schasinglulu
55*91f16700Schasinglulu	/* ---------------------------------------------
56*91f16700Schasinglulu	 * Invalidate the RW memory used by the BL2
57*91f16700Schasinglulu	 * image. This includes the data and NOBITS
58*91f16700Schasinglulu	 * sections. This is done to safeguard against
59*91f16700Schasinglulu	 * possible corruption of this memory by dirty
60*91f16700Schasinglulu	 * cache lines in a system cache as a result of
61*91f16700Schasinglulu	 * use by an earlier boot loader stage.
62*91f16700Schasinglulu	 * ---------------------------------------------
63*91f16700Schasinglulu	 */
64*91f16700Schasinglulu	adr	x0, __RW_START__
65*91f16700Schasinglulu	adr	x1, __RW_END__
66*91f16700Schasinglulu	sub	x1, x1, x0
67*91f16700Schasinglulu	bl	inv_dcache_range
68*91f16700Schasinglulu
69*91f16700Schasinglulu	/* ---------------------------------------------
70*91f16700Schasinglulu	 * Zero out NOBITS sections. There are 2 of them:
71*91f16700Schasinglulu	 *   - the .bss section;
72*91f16700Schasinglulu	 *   - the coherent memory section.
73*91f16700Schasinglulu	 * ---------------------------------------------
74*91f16700Schasinglulu	 */
75*91f16700Schasinglulu	adrp	x0, __BSS_START__
76*91f16700Schasinglulu	add	x0, x0, :lo12:__BSS_START__
77*91f16700Schasinglulu	adrp	x1, __BSS_END__
78*91f16700Schasinglulu	add	x1, x1, :lo12:__BSS_END__
79*91f16700Schasinglulu	sub	x1, x1, x0
80*91f16700Schasinglulu	bl	zeromem
81*91f16700Schasinglulu
82*91f16700Schasinglulu#if USE_COHERENT_MEM
83*91f16700Schasinglulu	adrp	x0, __COHERENT_RAM_START__
84*91f16700Schasinglulu	add	x0, x0, :lo12:__COHERENT_RAM_START__
85*91f16700Schasinglulu	adrp	x1, __COHERENT_RAM_END_UNALIGNED__
86*91f16700Schasinglulu	add	x1, x1, :lo12:__COHERENT_RAM_END_UNALIGNED__
87*91f16700Schasinglulu	sub	x1, x1, x0
88*91f16700Schasinglulu	bl	zeromem
89*91f16700Schasinglulu#endif
90*91f16700Schasinglulu
91*91f16700Schasinglulu	/* --------------------------------------------
92*91f16700Schasinglulu	 * Allocate a stack whose memory will be marked
93*91f16700Schasinglulu	 * as Normal-IS-WBWA when the MMU is enabled.
94*91f16700Schasinglulu	 * There is no risk of reading stale stack
95*91f16700Schasinglulu	 * memory after enabling the MMU as only the
96*91f16700Schasinglulu	 * primary cpu is running at the moment.
97*91f16700Schasinglulu	 * --------------------------------------------
98*91f16700Schasinglulu	 */
99*91f16700Schasinglulu	bl	plat_set_my_stack
100*91f16700Schasinglulu
101*91f16700Schasinglulu	/* ---------------------------------------------
102*91f16700Schasinglulu	 * Initialize the stack protector canary before
103*91f16700Schasinglulu	 * any C code is called.
104*91f16700Schasinglulu	 * ---------------------------------------------
105*91f16700Schasinglulu	 */
106*91f16700Schasinglulu#if STACK_PROTECTOR_ENABLED
107*91f16700Schasinglulu	bl	update_stack_protector_canary
108*91f16700Schasinglulu#endif
109*91f16700Schasinglulu
110*91f16700Schasinglulu	/* ---------------------------------------------
111*91f16700Schasinglulu	 * Perform BL2 setup
112*91f16700Schasinglulu	 * ---------------------------------------------
113*91f16700Schasinglulu	 */
114*91f16700Schasinglulu	mov	x0, x20
115*91f16700Schasinglulu	mov	x1, x21
116*91f16700Schasinglulu	mov	x2, x22
117*91f16700Schasinglulu	mov	x3, x23
118*91f16700Schasinglulu	bl	bl2_setup
119*91f16700Schasinglulu
120*91f16700Schasinglulu#if ENABLE_PAUTH
121*91f16700Schasinglulu	/* ---------------------------------------------
122*91f16700Schasinglulu	 * Program APIAKey_EL1
123*91f16700Schasinglulu	 * and enable pointer authentication.
124*91f16700Schasinglulu	 * ---------------------------------------------
125*91f16700Schasinglulu	 */
126*91f16700Schasinglulu	bl	pauth_init_enable_el1
127*91f16700Schasinglulu#endif /* ENABLE_PAUTH */
128*91f16700Schasinglulu
129*91f16700Schasinglulu	/* ---------------------------------------------
130*91f16700Schasinglulu	 * Jump to main function.
131*91f16700Schasinglulu	 * ---------------------------------------------
132*91f16700Schasinglulu	 */
133*91f16700Schasinglulu	bl	bl2_main
134*91f16700Schasinglulu
135*91f16700Schasinglulu	/* ---------------------------------------------
136*91f16700Schasinglulu	 * Should never reach this point.
137*91f16700Schasinglulu	 * ---------------------------------------------
138*91f16700Schasinglulu	 */
139*91f16700Schasinglulu	no_ret	plat_panic_handler
140*91f16700Schasinglulu
141*91f16700Schasingluluendfunc bl2_entrypoint
142