xref: /arm-trusted-firmware/bl2u/aarch64/bl2u_entrypoint.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2015-2021, 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	.globl	bl2u_entrypoint
12*91f16700Schasinglulu
13*91f16700Schasinglulu
14*91f16700Schasinglulufunc bl2u_entrypoint
15*91f16700Schasinglulu	/*---------------------------------------------
16*91f16700Schasinglulu	 * Store the extents of the tzram available to
17*91f16700Schasinglulu	 * BL2U and other platform specific information
18*91f16700Schasinglulu	 * for future use. x0 is currently not used.
19*91f16700Schasinglulu	 * ---------------------------------------------
20*91f16700Schasinglulu	 */
21*91f16700Schasinglulu	mov	x20, x1
22*91f16700Schasinglulu	mov	x21, x2
23*91f16700Schasinglulu
24*91f16700Schasinglulu	/* ---------------------------------------------
25*91f16700Schasinglulu	 * Set the exception vector to something sane.
26*91f16700Schasinglulu	 * ---------------------------------------------
27*91f16700Schasinglulu	 */
28*91f16700Schasinglulu	adr	x0, early_exceptions
29*91f16700Schasinglulu	msr	vbar_el1, x0
30*91f16700Schasinglulu	isb
31*91f16700Schasinglulu
32*91f16700Schasinglulu	/* ---------------------------------------------
33*91f16700Schasinglulu	 * Enable the SError interrupt now that the
34*91f16700Schasinglulu	 * exception vectors have been setup.
35*91f16700Schasinglulu	 * ---------------------------------------------
36*91f16700Schasinglulu	 */
37*91f16700Schasinglulu	msr	daifclr, #DAIF_ABT_BIT
38*91f16700Schasinglulu
39*91f16700Schasinglulu	/* ---------------------------------------------
40*91f16700Schasinglulu	 * Enable the instruction cache, stack pointer
41*91f16700Schasinglulu	 * and data access alignment checks and disable
42*91f16700Schasinglulu	 * speculative loads.
43*91f16700Schasinglulu	 * ---------------------------------------------
44*91f16700Schasinglulu	 */
45*91f16700Schasinglulu	mov	x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
46*91f16700Schasinglulu	mrs	x0, sctlr_el1
47*91f16700Schasinglulu	orr	x0, x0, x1
48*91f16700Schasinglulu	bic	x0, x0, #SCTLR_DSSBS_BIT
49*91f16700Schasinglulu	msr	sctlr_el1, x0
50*91f16700Schasinglulu	isb
51*91f16700Schasinglulu
52*91f16700Schasinglulu	/* ---------------------------------------------
53*91f16700Schasinglulu	 * Invalidate the RW memory used by the BL2U
54*91f16700Schasinglulu	 * image. This includes the data and NOBITS
55*91f16700Schasinglulu	 * sections. This is done to safeguard against
56*91f16700Schasinglulu	 * possible corruption of this memory by dirty
57*91f16700Schasinglulu	 * cache lines in a system cache as a result of
58*91f16700Schasinglulu	 * use by an earlier boot loader stage.
59*91f16700Schasinglulu	 * ---------------------------------------------
60*91f16700Schasinglulu	 */
61*91f16700Schasinglulu	adr	x0, __RW_START__
62*91f16700Schasinglulu	adr	x1, __RW_END__
63*91f16700Schasinglulu	sub	x1, x1, x0
64*91f16700Schasinglulu	bl	inv_dcache_range
65*91f16700Schasinglulu
66*91f16700Schasinglulu	/* ---------------------------------------------
67*91f16700Schasinglulu	 * Zero out NOBITS sections. There are 2 of them:
68*91f16700Schasinglulu	 *   - the .bss section;
69*91f16700Schasinglulu	 *   - the coherent memory section.
70*91f16700Schasinglulu	 * ---------------------------------------------
71*91f16700Schasinglulu	 */
72*91f16700Schasinglulu	adrp	x0, __BSS_START__
73*91f16700Schasinglulu	add	x0, x0, :lo12:__BSS_START__
74*91f16700Schasinglulu	adrp	x1, __BSS_END__
75*91f16700Schasinglulu	add	x1, x1, :lo12:__BSS_END__
76*91f16700Schasinglulu	sub	x1, x1, x0
77*91f16700Schasinglulu	bl	zeromem
78*91f16700Schasinglulu
79*91f16700Schasinglulu	/* --------------------------------------------
80*91f16700Schasinglulu	 * Allocate a stack whose memory will be marked
81*91f16700Schasinglulu	 * as Normal-IS-WBWA when the MMU is enabled.
82*91f16700Schasinglulu	 * There is no risk of reading stale stack
83*91f16700Schasinglulu	 * memory after enabling the MMU as only the
84*91f16700Schasinglulu	 * primary cpu is running at the moment.
85*91f16700Schasinglulu	 * --------------------------------------------
86*91f16700Schasinglulu	 */
87*91f16700Schasinglulu	bl	plat_set_my_stack
88*91f16700Schasinglulu
89*91f16700Schasinglulu	/* ---------------------------------------------
90*91f16700Schasinglulu	 * Initialize the stack protector canary before
91*91f16700Schasinglulu	 * any C code is called.
92*91f16700Schasinglulu	 * ---------------------------------------------
93*91f16700Schasinglulu	 */
94*91f16700Schasinglulu#if STACK_PROTECTOR_ENABLED
95*91f16700Schasinglulu	bl	update_stack_protector_canary
96*91f16700Schasinglulu#endif
97*91f16700Schasinglulu
98*91f16700Schasinglulu	/* ---------------------------------------------
99*91f16700Schasinglulu	 * Perform early platform setup & platform
100*91f16700Schasinglulu	 * specific early arch. setup e.g. mmu setup
101*91f16700Schasinglulu	 * ---------------------------------------------
102*91f16700Schasinglulu	 */
103*91f16700Schasinglulu	mov	x0, x20
104*91f16700Schasinglulu	mov	x1, x21
105*91f16700Schasinglulu	bl	bl2u_early_platform_setup
106*91f16700Schasinglulu	bl	bl2u_plat_arch_setup
107*91f16700Schasinglulu
108*91f16700Schasinglulu#if ENABLE_PAUTH
109*91f16700Schasinglulu	/* ---------------------------------------------
110*91f16700Schasinglulu	 * Program APIAKey_EL1
111*91f16700Schasinglulu	 * and enable pointer authentication.
112*91f16700Schasinglulu	 * ---------------------------------------------
113*91f16700Schasinglulu	 */
114*91f16700Schasinglulu	bl	pauth_init_enable_el1
115*91f16700Schasinglulu#endif
116*91f16700Schasinglulu
117*91f16700Schasinglulu	/* ---------------------------------------------
118*91f16700Schasinglulu	 * Jump to bl2u_main function.
119*91f16700Schasinglulu	 * ---------------------------------------------
120*91f16700Schasinglulu	 */
121*91f16700Schasinglulu	bl	bl2u_main
122*91f16700Schasinglulu
123*91f16700Schasinglulu	/* ---------------------------------------------
124*91f16700Schasinglulu	 * Should never reach this point.
125*91f16700Schasinglulu	 * ---------------------------------------------
126*91f16700Schasinglulu	 */
127*91f16700Schasinglulu	no_ret	plat_panic_handler
128*91f16700Schasinglulu
129*91f16700Schasingluluendfunc bl2u_entrypoint
130