xref: /rk3399_ARM-atf/bl1/aarch64/bl1_entrypoint.S (revision dce74b891e0e6020d0a18384e32f280133631d9b)
1/*
2 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3 *
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
31#include <arch.h>
32#include <asm_macros.S>
33
34	.globl	bl1_entrypoint
35
36
37	/* -----------------------------------------------------
38	 * bl1_entrypoint() is the entry point into the trusted
39	 * firmware code when a cpu is released from warm or
40	 * cold reset.
41	 * -----------------------------------------------------
42	 */
43
44func bl1_entrypoint
45	/* ---------------------------------------------
46	 * Set the CPU endianness before doing anything
47	 * that might involve memory reads or writes
48	 * ---------------------------------------------
49	 */
50	mrs	x0, sctlr_el3
51	bic	x0, x0, #SCTLR_EE_BIT
52	msr	sctlr_el3, x0
53	isb
54
55	/* ---------------------------------------------
56	 * Perform any processor specific actions upon
57	 * reset e.g. cache, tlb invalidations etc.
58	 * ---------------------------------------------
59	 */
60	bl	cpu_reset_handler
61
62	/* -------------------------------
63	 * Enable the instruction cache.
64	 * -------------------------------
65	 */
66	mrs	x0, sctlr_el3
67	orr	x0, x0, #SCTLR_I_BIT
68	msr	sctlr_el3, x0
69	isb
70
71	/* ---------------------------------------------
72	 * Set the exception vector to something sane.
73	 * ---------------------------------------------
74	 */
75	adr	x0, bl1_exceptions
76	msr	vbar_el3, x0
77
78	/* ---------------------------------------------------------------------
79	 * The initial state of the Architectural feature trap register
80	 * (CPTR_EL3) is unknown and it must be set to a known state. All
81	 * feature traps are disabled. Some bits in this register are marked as
82	 * Reserved and should not be modified.
83	 *
84	 * CPTR_EL3.TCPAC: This causes a direct access to the CPACR_EL1 from EL1
85	 *  or the CPTR_EL2 from EL2 to trap to EL3 unless it is trapped at EL2.
86	 * CPTR_EL3.TTA: This causes access to the Trace functionality to trap
87	 *  to EL3 when executed from EL0, EL1, EL2, or EL3. If system register
88	 *  access to trace functionality is not supported, this bit is RES0.
89	 * CPTR_EL3.TFP: This causes instructions that access the registers
90	 *  associated with Floating Point and Advanced SIMD execution to trap
91	 *  to EL3 when executed from any exception level, unless trapped to EL1
92	 *  or EL2.
93	 * ---------------------------------------------------------------------
94	 */
95	mrs	x0, cptr_el3
96	bic	w0, w0, #TCPAC_BIT
97	bic	w0, w0, #TTA_BIT
98	bic	w0, w0, #TFP_BIT
99	msr	cptr_el3, x0
100
101	/* ---------------------------------------------
102	 * Find the type of reset and jump to handler
103	 * if present. If the handler is null then it is
104	 * a cold boot. The primary cpu will set up the
105	 * platform while the secondaries wait for
106	 * their turn to be woken up
107	 * ---------------------------------------------
108	 */
109	wait_for_entrypoint
110
111	bl	platform_mem_init
112
113	/* ---------------------------------------------
114	 * Init C runtime environment.
115	 *   - Zero-initialise the NOBITS sections.
116	 *     There are 2 of them:
117	 *       - the .bss section;
118	 *       - the coherent memory section.
119	 *   - Copy the data section from BL1 image
120	 *     (stored in ROM) to the correct location
121	 *     in RAM.
122	 * ---------------------------------------------
123	 */
124	ldr	x0, =__BSS_START__
125	ldr	x1, =__BSS_SIZE__
126	bl	zeromem16
127
128	ldr	x0, =__COHERENT_RAM_START__
129	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
130	bl	zeromem16
131
132	ldr	x0, =__DATA_RAM_START__
133	ldr	x1, =__DATA_ROM_START__
134	ldr	x2, =__DATA_SIZE__
135	bl	memcpy16
136
137	/* ---------------------------------------------
138	 * Give ourselves a small coherent stack to
139	 * ease the pain of initializing the MMU and
140	 * CCI in assembler
141	 * ---------------------------------------------
142	 */
143	mrs	x0, mpidr_el1
144	bl	platform_set_coherent_stack
145
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.
152	 * ---------------------------------------------
153	 */
154	bl	bl1_early_platform_setup
155	bl	bl1_plat_arch_setup
156
157	/* ---------------------------------------------
158	 * Give ourselves a stack allocated in Normal
159	 * -IS-WBWA memory
160	 * ---------------------------------------------
161	 */
162	mrs	x0, mpidr_el1
163	bl	platform_set_stack
164
165	/* --------------------------------------------------
166	 * Initialize platform and jump to our c-entry point
167	 * for this type of reset. Panic if it returns
168	 * --------------------------------------------------
169	 */
170	bl	bl1_main
171panic:
172	b	panic
173