blob: 3ab8b5abc13b3d4b2b0bb985da9f943d955b3c90 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Douglas Raillard21362a92016-12-02 13:51:54 +00002 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +00007#include <arch.h>
Andrew Thoelke38bde412014-03-18 13:46:55 +00008#include <asm_macros.S>
Dan Handley2bd4ef22014-04-09 13:14:54 +01009#include <bl_common.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010010
11
12 .globl bl2_entrypoint
13
14
Achin Gupta4f6ad662013-10-25 09:08:21 +010015
Andrew Thoelke38bde412014-03-18 13:46:55 +000016func bl2_entrypoint
Achin Gupta4f6ad662013-10-25 09:08:21 +010017 /*---------------------------------------------
Yatharth Kochar57d334c2015-10-29 12:47:02 +000018 * Save from x1 the extents of the tzram
19 * available to BL2 for future use.
20 * x0 is not currently used.
Achin Gupta4f6ad662013-10-25 09:08:21 +010021 * ---------------------------------------------
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +000022 */
23 mov x20, x1
Achin Gupta4f6ad662013-10-25 09:08:21 +010024
25 /* ---------------------------------------------
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000026 * Set the exception vector to something sane.
27 * ---------------------------------------------
28 */
29 adr x0, early_exceptions
30 msr vbar_el1, x0
Achin Guptaed1744e2014-08-04 23:13:10 +010031 isb
32
33 /* ---------------------------------------------
34 * Enable the SError interrupt now that the
35 * exception vectors have been setup.
36 * ---------------------------------------------
37 */
38 msr daifclr, #DAIF_ABT_BIT
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000039
40 /* ---------------------------------------------
Achin Gupta9f098352014-07-18 18:38:28 +010041 * Enable the instruction cache, stack pointer
42 * and data access alignment checks
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000043 * ---------------------------------------------
44 */
Achin Gupta9f098352014-07-18 18:38:28 +010045 mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000046 mrs x0, sctlr_el1
Achin Gupta9f098352014-07-18 18:38:28 +010047 orr x0, x0, x1
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000048 msr sctlr_el1, x0
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000049 isb
50
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000051 /* ---------------------------------------------
Achin Guptae9c4a642015-09-11 16:03:13 +010052 * Invalidate the RW memory used by the BL2
53 * image. This includes the data and NOBITS
54 * sections. This is done to safeguard against
55 * possible corruption of this memory by dirty
56 * cache lines in a system cache as a result of
57 * use by an earlier boot loader stage.
58 * ---------------------------------------------
59 */
60 adr x0, __RW_START__
61 adr x1, __RW_END__
62 sub x1, x1, x0
63 bl inv_dcache_range
64
65 /* ---------------------------------------------
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000066 * Zero out NOBITS sections. There are 2 of them:
67 * - the .bss section;
68 * - the coherent memory section.
69 * ---------------------------------------------
70 */
71 ldr x0, =__BSS_START__
72 ldr x1, =__BSS_SIZE__
Douglas Raillard21362a92016-12-02 13:51:54 +000073 bl zeromem
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000074
Soby Mathew2ae20432015-01-08 18:02:44 +000075#if USE_COHERENT_MEM
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000076 ldr x0, =__COHERENT_RAM_START__
77 ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__
Douglas Raillard21362a92016-12-02 13:51:54 +000078 bl zeromem
Soby Mathew2ae20432015-01-08 18:02:44 +000079#endif
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000080
Achin Gupta4f6ad662013-10-25 09:08:21 +010081 /* --------------------------------------------
Achin Guptaf4a97092014-06-25 19:26:22 +010082 * Allocate a stack whose memory will be marked
83 * as Normal-IS-WBWA when the MMU is enabled.
84 * There is no risk of reading stale stack
85 * memory after enabling the MMU as only the
86 * primary cpu is running at the moment.
Achin Gupta4f6ad662013-10-25 09:08:21 +010087 * --------------------------------------------
88 */
Soby Mathew3700a922015-07-13 11:21:11 +010089 bl plat_set_my_stack
Achin Gupta4f6ad662013-10-25 09:08:21 +010090
91 /* ---------------------------------------------
Douglas Raillard306593d2017-02-24 18:14:15 +000092 * Initialize the stack protector canary before
93 * any C code is called.
94 * ---------------------------------------------
95 */
96#if STACK_PROTECTOR_ENABLED
97 bl update_stack_protector_canary
98#endif
99
100 /* ---------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +0100101 * Perform early platform setup & platform
102 * specific early arch. setup e.g. mmu setup
103 * ---------------------------------------------
104 */
Yatharth Kochar57d334c2015-10-29 12:47:02 +0000105 mov x0, x20
Achin Gupta4f6ad662013-10-25 09:08:21 +0100106 bl bl2_early_platform_setup
107 bl bl2_plat_arch_setup
108
109 /* ---------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110 * Jump to main function.
111 * ---------------------------------------------
112 */
113 bl bl2_main
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000114
115 /* ---------------------------------------------
116 * Should never reach this point.
117 * ---------------------------------------------
118 */
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000119 no_ret plat_panic_handler
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000120
Kévin Petita877c252015-03-24 14:03:57 +0000121endfunc bl2_entrypoint