blob: 51c9a2e3885e715604ab21ba278ba1a37493bfa2 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
Channagoud Kadabi1ee9e412014-07-01 14:07:46 -07004 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
5 *
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
Ajay Dudani79d0d402010-04-21 12:38:45 -070025
26#define DSB .byte 0x4f, 0xf0, 0x7f, 0xf5
27#define ISB .byte 0x6f, 0xf0, 0x7f, 0xf5
28
Ajay Dudanic713ab82011-05-18 19:50:14 -070029.section ".text.boot"
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070030.globl _start
31_start:
32 b reset
33 b arm_undefined
34 b arm_syscall
35 b arm_prefetch_abort
36 b arm_data_abort
37 b arm_reserved
38 b arm_irq
39 b arm_fiq
40
41reset:
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080042
43#ifdef ENABLE_TRUSTZONE
44 /*Add reference to TZ symbol so linker includes it in final image */
45 ldr r7, =_binary_tzbsp_tzbsp_bin_start
46#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070047 /* do some cpu setup */
48#if ARM_WITH_CP15
Amol Jadica4f4c92011-01-13 20:19:34 -080049 /* Read SCTLR */
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070050 mrc p15, 0, r0, c1, c0, 0
51 /* XXX this is currently for arm926, revist with armv6 cores */
52 /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */
53 bic r0, r0, #(1<<15| 1<<13 | 1<<12)
54 bic r0, r0, #(1<<2 | 1<<0)
Deepa Dinamanid7820fa2013-10-01 18:03:28 -070055 /* disable alignment faults */
56 bic r0, r0, #(1<<1)
Channagoud Kadabi1ee9e412014-07-01 14:07:46 -070057 /* Enable CP15 barriers by default */
58#ifdef ARM_CORE_V8
59 orr r0, r0, #(1<<5)
60#endif
Amol Jadica4f4c92011-01-13 20:19:34 -080061 /* Write SCTLR */
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070062 mcr p15, 0, r0, c1, c0, 0
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080063#ifdef ENABLE_TRUSTZONE
64 /*nkazi: not needed ? Setting VBAR to location of new vector table : 0x80000 */
65 ldr r0, =0x00080000
66 mcr p15, 0, r0, c12, c0, 0
67#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070068#endif
69
Brian Swetlanda8cf2b82009-01-01 03:29:51 -080070#if WITH_CPU_EARLY_INIT
71 /* call platform/arch/etc specific init code */
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080072#ifndef ENABLE_TRUSTZONE
73 /* Not needed when TrustZone is the first bootloader that runs.*/
Brian Swetlanda8cf2b82009-01-01 03:29:51 -080074 bl __cpu_early_init
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080075#endif
Ajay Dudani083d0dd2010-07-08 13:16:13 -070076 /* declare return address as global to avoid using stack */
77.globl _cpu_early_init_complete
78 _cpu_early_init_complete:
79
Travis Geiselbrechtc3226112008-09-02 02:47:40 -070080#endif
81
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080082#if (!ENABLE_NANDWRITE)
Harry Yang953ff702009-12-03 21:49:00 -080083#if WITH_CPU_WARM_BOOT
84 ldr r0, warm_boot_tag
85 cmp r0, #1
86
87 /* if set, warm boot */
88 ldreq pc, =BASE_ADDR
89
90 mov r0, #1
91 str r0, warm_boot_tag
92#endif
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080093#endif
Harry Yang953ff702009-12-03 21:49:00 -080094
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070095 /* see if we need to relocate */
96 mov r0, pc
97 sub r0, r0, #(.Laddr - _start)
98.Laddr:
99 ldr r1, =_start
100 cmp r0, r1
101 beq .Lstack_setup
102
103 /* we need to relocate ourselves to the proper spot */
104 ldr r2, =__data_end
105
106.Lrelocate_loop:
107 ldr r3, [r0], #4
108 str r3, [r1], #4
109 cmp r1, r2
110 bne .Lrelocate_loop
111
112 /* we're relocated, jump to the right address */
113 ldr r0, =.Lstack_setup
114 bx r0
115
116.ltorg
Harry Yang953ff702009-12-03 21:49:00 -0800117#if WITH_CPU_WARM_BOOT
118warm_boot_tag:
119 .word 0
120#endif
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700121
122.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700123 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
124 mrs r0, cpsr
125 bic r0, r0, #0x1f
126
127 ldr r2, =abort_stack_top
128 orr r1, r0, #0x12 // irq
129 msr cpsr_c, r1
130 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
131
132 orr r1, r0, #0x11 // fiq
133 msr cpsr_c, r1
134 mov sp, r2
135
136 orr r1, r0, #0x17 // abort
137 msr cpsr_c, r1
138 mov sp, r2
139
140 orr r1, r0, #0x1b // undefined
141 msr cpsr_c, r1
142 mov sp, r2
143
144 orr r1, r0, #0x1f // system
145 msr cpsr_c, r1
146 mov sp, r2
147
148 orr r1, r0, #0x13 // supervisor
149 msr cpsr_c, r1
150 mov sp, r2
151
152 /* copy the initialized data segment out of rom if necessary */
153 ldr r0, =__data_start_rom
154 ldr r1, =__data_start
155 ldr r2, =__data_end
156
157 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700158 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700159
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700160.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700161 cmp r1, r2
162 ldrlt r3, [r0], #4
163 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700164 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700165
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700166.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700167 /* clear out the bss */
168 ldr r0, =__bss_start
169 ldr r1, =_end
170 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700171.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700172 cmp r0, r1
173 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700174 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700175
Ajay Dudani79d0d402010-04-21 12:38:45 -0700176#ifdef ARM_CPU_CORTEX_A8
177 DSB
178 ISB
179#endif
180
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700181 bl kmain
182 b .
183
184.ltorg
185
186.bss
187.align 2
188 /* the abort stack is for unrecoverable errors.
189 * also note the initial working stack is set to here.
190 * when the threading system starts up it'll switch to a new
191 * dynamically allocated stack, so we don't need it for very long
192 */
193abort_stack:
Mayank Groverb0f48a02017-12-19 15:02:47 +0530194 .skip 4096
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700195abort_stack_top: