blob: dd7d78feb24152c1658e771c1272dbf903ba42e2 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000031#include <arch.h>
Andrew Thoelke38bde412014-03-18 13:46:55 +000032#include <asm_macros.S>
Achin Gupta4f6ad662013-10-25 09:08:21 +010033
Jeenu Viswambharan2a30a752014-03-11 11:06:45 +000034 .globl bl1_entrypoint
Achin Gupta4f6ad662013-10-25 09:08:21 +010035
36
Achin Gupta4f6ad662013-10-25 09:08:21 +010037 /* -----------------------------------------------------
Jeenu Viswambharan2a30a752014-03-11 11:06:45 +000038 * bl1_entrypoint() is the entry point into the trusted
Achin Gupta4f6ad662013-10-25 09:08:21 +010039 * firmware code when a cpu is released from warm or
40 * cold reset.
41 * -----------------------------------------------------
42 */
43
Andrew Thoelke38bde412014-03-18 13:46:55 +000044func bl1_entrypoint
Achin Gupta4f6ad662013-10-25 09:08:21 +010045 /* ---------------------------------------------
Andrew Thoelkef994ffb2014-04-24 15:33:24 +010046 * Set the CPU endianness before doing anything
Achin Gupta9f098352014-07-18 18:38:28 +010047 * that might involve memory reads or writes.
Andrew Thoelkef994ffb2014-04-24 15:33:24 +010048 * ---------------------------------------------
49 */
50 mrs x0, sctlr_el3
51 bic x0, x0, #SCTLR_EE_BIT
52 msr sctlr_el3, x0
53 isb
54
55 /* ---------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +010056 * Perform any processor specific actions upon
57 * reset e.g. cache, tlb invalidations etc.
58 * ---------------------------------------------
59 */
60 bl cpu_reset_handler
61
Achin Gupta9f098352014-07-18 18:38:28 +010062 /* ---------------------------------------------
63 * Enable the instruction cache, stack pointer
64 * and data access alignment checks
65 * ---------------------------------------------
Vikram Kanigiri96377452014-04-24 11:02:16 +010066 */
Achin Gupta9f098352014-07-18 18:38:28 +010067 mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
Vikram Kanigiri96377452014-04-24 11:02:16 +010068 mrs x0, sctlr_el3
Achin Gupta9f098352014-07-18 18:38:28 +010069 orr x0, x0, x1
Vikram Kanigiri96377452014-04-24 11:02:16 +010070 msr sctlr_el3, x0
71 isb
72
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000073 /* ---------------------------------------------
74 * Set the exception vector to something sane.
75 * ---------------------------------------------
76 */
Sandrine Bailleux4d052752014-03-24 10:24:08 +000077 adr x0, bl1_exceptions
Sandrine Bailleuxc10bd2c2013-11-12 16:41:16 +000078 msr vbar_el3, x0
79
Harry Liebel4f603682014-01-14 18:11:48 +000080 /* ---------------------------------------------------------------------
81 * The initial state of the Architectural feature trap register
82 * (CPTR_EL3) is unknown and it must be set to a known state. All
83 * feature traps are disabled. Some bits in this register are marked as
84 * Reserved and should not be modified.
85 *
86 * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1
87 * or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2.
88 * CPTR_EL3.TTA: This causes access to the Trace functionality to trap
89 * to EL3 when executed from EL0, EL1, EL2, or EL3. If system register
90 * access to trace functionality is not supported, this bit is RES0.
91 * CPTR_EL3.TFP: This causes instructions that access the registers
92 * associated with Floating Point and Advanced SIMD execution to trap
93 * to EL3 when executed from any exception level, unless trapped to EL1
94 * or EL2.
95 * ---------------------------------------------------------------------
96 */
97 mrs x0, cptr_el3
98 bic w0, w0, #TCPAC_BIT
99 bic w0, w0, #TTA_BIT
100 bic w0, w0, #TFP_BIT
101 msr cptr_el3, x0
102
Vikram Kanigiricf79bf52014-06-02 14:59:00 +0100103 /* -------------------------------------------------------
104 * Will not return from this macro if it is a warm boot.
105 * -------------------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +0100106 */
Vikram Kanigiri96377452014-04-24 11:02:16 +0100107 wait_for_entrypoint
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108
Vikram Kanigiri96377452014-04-24 11:02:16 +0100109 bl platform_mem_init
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110
Achin Gupta4f6ad662013-10-25 09:08:21 +0100111 /* ---------------------------------------------
Sandrine Bailleux65f546a2013-11-28 09:43:06 +0000112 * Init C runtime environment.
113 * - Zero-initialise the NOBITS sections.
114 * There are 2 of them:
115 * - the .bss section;
116 * - the coherent memory section.
117 * - Copy the data section from BL1 image
118 * (stored in ROM) to the correct location
119 * in RAM.
120 * ---------------------------------------------
121 */
122 ldr x0, =__BSS_START__
123 ldr x1, =__BSS_SIZE__
124 bl zeromem16
125
126 ldr x0, =__COHERENT_RAM_START__
127 ldr x1, =__COHERENT_RAM_UNALIGNED_SIZE__
128 bl zeromem16
129
130 ldr x0, =__DATA_RAM_START__
131 ldr x1, =__DATA_ROM_START__
132 ldr x2, =__DATA_SIZE__
133 bl memcpy16
134
Achin Guptaf4a97092014-06-25 19:26:22 +0100135 /* --------------------------------------------
136 * Allocate a stack whose memory will be marked
137 * as Normal-IS-WBWA when the MMU is enabled.
138 * There is no risk of reading stale stack
139 * memory after enabling the MMU as only the
140 * primary cpu is running at the moment.
141 * --------------------------------------------
Vikram Kanigiri96377452014-04-24 11:02:16 +0100142 */
143 mrs x0, mpidr_el1
Achin Guptaf4a97092014-06-25 19:26:22 +0100144 bl platform_set_stack
Vikram Kanigiri96377452014-04-24 11:02:16 +0100145
146 /* ---------------------------------------------
147 * Architectural init. can be generic e.g.
148 * enabling stack alignment and platform spec-
149 * ific e.g. MMU & page table setup as per the
150 * platform memory map. Perform the latter here
151 * and the former in bl1_main.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152 * ---------------------------------------------
153 */
Vikram Kanigiri96377452014-04-24 11:02:16 +0100154 bl bl1_early_platform_setup
155 bl bl1_plat_arch_setup
Achin Gupta4f6ad662013-10-25 09:08:21 +0100156
Vikram Kanigiri96377452014-04-24 11:02:16 +0100157 /* --------------------------------------------------
158 * Initialize platform and jump to our c-entry point
159 * for this type of reset. Panic if it returns
160 * --------------------------------------------------
161 */
162 bl bl1_main
163panic:
164 b panic