xref: /rk3399_ARM-atf/bl2/aarch32/bl2_entrypoint.S (revision 02b57943965c89887170604e8eb801e17fd8cb99)
1d48c12e9SYatharth Kochar/*
29d93fc2fSAntonio Nino Diaz * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
3d48c12e9SYatharth Kochar *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
5d48c12e9SYatharth Kochar */
6d48c12e9SYatharth Kochar
7d48c12e9SYatharth Kochar#include <arch.h>
8d48c12e9SYatharth Kochar#include <asm_macros.S>
909d40e0eSAntonio Nino Diaz#include <common/bl_common.h>
10d48c12e9SYatharth Kochar
11d48c12e9SYatharth Kochar	.globl	bl2_vector_table
12d48c12e9SYatharth Kochar	.globl	bl2_entrypoint
13d48c12e9SYatharth Kochar
14d48c12e9SYatharth Kochar
15d48c12e9SYatharth Kocharvector_base bl2_vector_table
16d48c12e9SYatharth Kochar	b	bl2_entrypoint
17d48c12e9SYatharth Kochar	b	report_exception	/* Undef */
18d48c12e9SYatharth Kochar	b	report_exception	/* SVC call */
19d48c12e9SYatharth Kochar	b	report_exception	/* Prefetch abort */
20d48c12e9SYatharth Kochar	b	report_exception	/* Data abort */
21d48c12e9SYatharth Kochar	b	report_exception	/* Reserved */
22d48c12e9SYatharth Kochar	b	report_exception	/* IRQ */
23d48c12e9SYatharth Kochar	b	report_exception	/* FIQ */
24d48c12e9SYatharth Kochar
25d48c12e9SYatharth Kochar
26d48c12e9SYatharth Kocharfunc bl2_entrypoint
27d48c12e9SYatharth Kochar	/*---------------------------------------------
28a6f340feSSoby Mathew	 * Save arguments x0 - x3 from BL1 for future
29a6f340feSSoby Mathew	 * use.
30d48c12e9SYatharth Kochar	 * ---------------------------------------------
31d48c12e9SYatharth Kochar	 */
32a6f340feSSoby Mathew	mov	r9, r0
33a6f340feSSoby Mathew	mov	r10, r1
34a6f340feSSoby Mathew	mov	r11, r2
35a6f340feSSoby Mathew	mov	r12, r3
36d48c12e9SYatharth Kochar
37d48c12e9SYatharth Kochar	/* ---------------------------------------------
38d48c12e9SYatharth Kochar	 * Set the exception vector to something sane.
39d48c12e9SYatharth Kochar	 * ---------------------------------------------
40d48c12e9SYatharth Kochar	 */
41d48c12e9SYatharth Kochar	ldr	r0, =bl2_vector_table
42d48c12e9SYatharth Kochar	stcopr	r0, VBAR
43d48c12e9SYatharth Kochar	isb
44d48c12e9SYatharth Kochar
45*02b57943SJohn Tsichritzis	/* --------------------------------------------------------
46*02b57943SJohn Tsichritzis	 * Enable the instruction cache - disable speculative loads
47*02b57943SJohn Tsichritzis	 * --------------------------------------------------------
48d48c12e9SYatharth Kochar	 */
49d48c12e9SYatharth Kochar	ldcopr	r0, SCTLR
50d48c12e9SYatharth Kochar	orr	r0, r0, #SCTLR_I_BIT
51*02b57943SJohn Tsichritzis	bic	r0, r0, #SCTLR_DSSBS_BIT
52d48c12e9SYatharth Kochar	stcopr	r0, SCTLR
53d48c12e9SYatharth Kochar	isb
54d48c12e9SYatharth Kochar
55d48c12e9SYatharth Kochar	/* ---------------------------------------------
56d48c12e9SYatharth Kochar	 * Since BL2 executes after BL1, it is assumed
57d48c12e9SYatharth Kochar	 * here that BL1 has already has done the
58d48c12e9SYatharth Kochar	 * necessary register initializations.
59d48c12e9SYatharth Kochar	 * ---------------------------------------------
60d48c12e9SYatharth Kochar	 */
61d48c12e9SYatharth Kochar
62d48c12e9SYatharth Kochar	/* ---------------------------------------------
63d48c12e9SYatharth Kochar	 * Invalidate the RW memory used by the BL2
64d48c12e9SYatharth Kochar	 * image. This includes the data and NOBITS
65d48c12e9SYatharth Kochar	 * sections. This is done to safeguard against
66d48c12e9SYatharth Kochar	 * possible corruption of this memory by dirty
67d48c12e9SYatharth Kochar	 * cache lines in a system cache as a result of
68d48c12e9SYatharth Kochar	 * use by an earlier boot loader stage.
69d48c12e9SYatharth Kochar	 * ---------------------------------------------
70d48c12e9SYatharth Kochar	 */
71d48c12e9SYatharth Kochar	ldr	r0, =__RW_START__
72d48c12e9SYatharth Kochar	ldr	r1, =__RW_END__
73d48c12e9SYatharth Kochar	sub	r1, r1, r0
74d48c12e9SYatharth Kochar	bl	inv_dcache_range
75d48c12e9SYatharth Kochar
76d48c12e9SYatharth Kochar	/* ---------------------------------------------
77d48c12e9SYatharth Kochar	 * Zero out NOBITS sections. There are 2 of them:
78d48c12e9SYatharth Kochar	 *   - the .bss section;
79d48c12e9SYatharth Kochar	 *   - the coherent memory section.
80d48c12e9SYatharth Kochar	 * ---------------------------------------------
81d48c12e9SYatharth Kochar	 */
82d48c12e9SYatharth Kochar	ldr	r0, =__BSS_START__
83d48c12e9SYatharth Kochar	ldr	r1, =__BSS_SIZE__
84d48c12e9SYatharth Kochar	bl	zeromem
85d48c12e9SYatharth Kochar
86d48c12e9SYatharth Kochar#if USE_COHERENT_MEM
87d48c12e9SYatharth Kochar	ldr	r0, =__COHERENT_RAM_START__
88d48c12e9SYatharth Kochar	ldr	r1, =__COHERENT_RAM_UNALIGNED_SIZE__
89d48c12e9SYatharth Kochar	bl	zeromem
90d48c12e9SYatharth Kochar#endif
91d48c12e9SYatharth Kochar
92d48c12e9SYatharth Kochar	/* --------------------------------------------
93d48c12e9SYatharth Kochar	 * Allocate a stack whose memory will be marked
94d48c12e9SYatharth Kochar	 * as Normal-IS-WBWA when the MMU is enabled.
95d48c12e9SYatharth Kochar	 * There is no risk of reading stale stack
96d48c12e9SYatharth Kochar	 * memory after enabling the MMU as only the
97d48c12e9SYatharth Kochar	 * primary cpu is running at the moment.
98d48c12e9SYatharth Kochar	 * --------------------------------------------
99d48c12e9SYatharth Kochar	 */
100d48c12e9SYatharth Kochar	bl	plat_set_my_stack
101d48c12e9SYatharth Kochar
102d48c12e9SYatharth Kochar	/* ---------------------------------------------
10351faada7SDouglas Raillard	 * Initialize the stack protector canary before
10451faada7SDouglas Raillard	 * any C code is called.
10551faada7SDouglas Raillard	 * ---------------------------------------------
10651faada7SDouglas Raillard	 */
10751faada7SDouglas Raillard#if STACK_PROTECTOR_ENABLED
10851faada7SDouglas Raillard	bl	update_stack_protector_canary
10951faada7SDouglas Raillard#endif
11051faada7SDouglas Raillard
11151faada7SDouglas Raillard	/* ---------------------------------------------
1129d93fc2fSAntonio Nino Diaz	 * Perform BL2 setup
113d48c12e9SYatharth Kochar	 * ---------------------------------------------
114d48c12e9SYatharth Kochar	 */
115a6f340feSSoby Mathew	mov	r0, r9
116a6f340feSSoby Mathew	mov	r1, r10
117a6f340feSSoby Mathew	mov	r2, r11
118a6f340feSSoby Mathew	mov	r3, r12
1199d93fc2fSAntonio Nino Diaz
1209d93fc2fSAntonio Nino Diaz	bl	bl2_setup
121d48c12e9SYatharth Kochar
122d48c12e9SYatharth Kochar	/* ---------------------------------------------
123d48c12e9SYatharth Kochar	 * Jump to main function.
124d48c12e9SYatharth Kochar	 * ---------------------------------------------
125d48c12e9SYatharth Kochar	 */
126d48c12e9SYatharth Kochar	bl	bl2_main
127d48c12e9SYatharth Kochar
128d48c12e9SYatharth Kochar	/* ---------------------------------------------
129d48c12e9SYatharth Kochar	 * Should never reach this point.
130d48c12e9SYatharth Kochar	 * ---------------------------------------------
131d48c12e9SYatharth Kochar	 */
132a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
133d48c12e9SYatharth Kochar
134d48c12e9SYatharth Kocharendfunc bl2_entrypoint
135