blob: 7f1ad16605ca9e002c257c39204d21738275e257 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
Ajay Dudani79d0d402010-04-21 12:38:45 -070023
24#define DSB .byte 0x4f, 0xf0, 0x7f, 0xf5
25#define ISB .byte 0x6f, 0xf0, 0x7f, 0xf5
26
Ajay Dudanic713ab82011-05-18 19:50:14 -070027.section ".text.boot"
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070028.globl _start
29_start:
30 b reset
31 b arm_undefined
32 b arm_syscall
33 b arm_prefetch_abort
34 b arm_data_abort
35 b arm_reserved
36 b arm_irq
37 b arm_fiq
38
39reset:
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080040
41#ifdef ENABLE_TRUSTZONE
42 /*Add reference to TZ symbol so linker includes it in final image */
43 ldr r7, =_binary_tzbsp_tzbsp_bin_start
44#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070045 /* do some cpu setup */
46#if ARM_WITH_CP15
Amol Jadica4f4c92011-01-13 20:19:34 -080047 /* Read SCTLR */
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070048 mrc p15, 0, r0, c1, c0, 0
49 /* XXX this is currently for arm926, revist with armv6 cores */
50 /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */
51 bic r0, r0, #(1<<15| 1<<13 | 1<<12)
52 bic r0, r0, #(1<<2 | 1<<0)
53 /* enable alignment faults */
54 orr r0, r0, #(1<<1)
Amol Jadica4f4c92011-01-13 20:19:34 -080055 /* Write SCTLR */
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070056 mcr p15, 0, r0, c1, c0, 0
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080057#ifdef ENABLE_TRUSTZONE
58 /*nkazi: not needed ? Setting VBAR to location of new vector table : 0x80000 */
59 ldr r0, =0x00080000
60 mcr p15, 0, r0, c12, c0, 0
61#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070062#endif
63
Brian Swetlanda8cf2b82009-01-01 03:29:51 -080064#if WITH_CPU_EARLY_INIT
65 /* call platform/arch/etc specific init code */
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080066#ifndef ENABLE_TRUSTZONE
67 /* Not needed when TrustZone is the first bootloader that runs.*/
Brian Swetlanda8cf2b82009-01-01 03:29:51 -080068 bl __cpu_early_init
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080069#endif
Ajay Dudani083d0dd2010-07-08 13:16:13 -070070 /* declare return address as global to avoid using stack */
71.globl _cpu_early_init_complete
72 _cpu_early_init_complete:
73
Travis Geiselbrechtc3226112008-09-02 02:47:40 -070074#endif
75
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080076#if (!ENABLE_NANDWRITE)
Harry Yang953ff702009-12-03 21:49:00 -080077#if WITH_CPU_WARM_BOOT
78 ldr r0, warm_boot_tag
79 cmp r0, #1
80
81 /* if set, warm boot */
82 ldreq pc, =BASE_ADDR
83
84 mov r0, #1
85 str r0, warm_boot_tag
86#endif
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080087#endif
Harry Yang953ff702009-12-03 21:49:00 -080088
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070089 /* see if we need to relocate */
90 mov r0, pc
91 sub r0, r0, #(.Laddr - _start)
92.Laddr:
93 ldr r1, =_start
94 cmp r0, r1
95 beq .Lstack_setup
96
97 /* we need to relocate ourselves to the proper spot */
98 ldr r2, =__data_end
99
100.Lrelocate_loop:
101 ldr r3, [r0], #4
102 str r3, [r1], #4
103 cmp r1, r2
104 bne .Lrelocate_loop
105
106 /* we're relocated, jump to the right address */
107 ldr r0, =.Lstack_setup
108 bx r0
109
110.ltorg
Harry Yang953ff702009-12-03 21:49:00 -0800111#if WITH_CPU_WARM_BOOT
112warm_boot_tag:
113 .word 0
114#endif
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700115
116.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700117 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
118 mrs r0, cpsr
119 bic r0, r0, #0x1f
120
121 ldr r2, =abort_stack_top
122 orr r1, r0, #0x12 // irq
123 msr cpsr_c, r1
124 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
125
126 orr r1, r0, #0x11 // fiq
127 msr cpsr_c, r1
128 mov sp, r2
129
130 orr r1, r0, #0x17 // abort
131 msr cpsr_c, r1
132 mov sp, r2
133
134 orr r1, r0, #0x1b // undefined
135 msr cpsr_c, r1
136 mov sp, r2
137
138 orr r1, r0, #0x1f // system
139 msr cpsr_c, r1
140 mov sp, r2
141
142 orr r1, r0, #0x13 // supervisor
143 msr cpsr_c, r1
144 mov sp, r2
145
146 /* copy the initialized data segment out of rom if necessary */
147 ldr r0, =__data_start_rom
148 ldr r1, =__data_start
149 ldr r2, =__data_end
150
151 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700152 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700153
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700154.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700155 cmp r1, r2
156 ldrlt r3, [r0], #4
157 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700158 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700159
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700160.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700161 /* clear out the bss */
162 ldr r0, =__bss_start
163 ldr r1, =_end
164 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700165.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700166 cmp r0, r1
167 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700168 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700169
Ajay Dudani79d0d402010-04-21 12:38:45 -0700170#ifdef ARM_CPU_CORTEX_A8
171 DSB
172 ISB
173#endif
174
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700175 bl kmain
176 b .
177
178.ltorg
179
180.bss
181.align 2
182 /* the abort stack is for unrecoverable errors.
183 * also note the initial working stack is set to here.
184 * when the threading system starts up it'll switch to a new
185 * dynamically allocated stack, so we don't need it for very long
186 */
187abort_stack:
188 .skip 1024
189abort_stack_top: