blob: a1777f0a1381b413f034c1a37774fdf45ab505c4 [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
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070027.text
28.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:
40 /* do some cpu setup */
41#if ARM_WITH_CP15
42 mrc p15, 0, r0, c1, c0, 0
43 /* XXX this is currently for arm926, revist with armv6 cores */
44 /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */
45 bic r0, r0, #(1<<15| 1<<13 | 1<<12)
46 bic r0, r0, #(1<<2 | 1<<0)
47 /* enable alignment faults */
48 orr r0, r0, #(1<<1)
49 mcr p15, 0, r0, c1, c0, 0
50#endif
51
Brian Swetlanda8cf2b82009-01-01 03:29:51 -080052#if WITH_CPU_EARLY_INIT
53 /* call platform/arch/etc specific init code */
54 bl __cpu_early_init
Ajay Dudani083d0dd2010-07-08 13:16:13 -070055
56 /* declare return address as global to avoid using stack */
57.globl _cpu_early_init_complete
58 _cpu_early_init_complete:
59
Travis Geiselbrechtc3226112008-09-02 02:47:40 -070060#endif
61
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080062#if (!ENABLE_NANDWRITE)
Harry Yang953ff702009-12-03 21:49:00 -080063#if WITH_CPU_WARM_BOOT
64 ldr r0, warm_boot_tag
65 cmp r0, #1
66
67 /* if set, warm boot */
68 ldreq pc, =BASE_ADDR
69
70 mov r0, #1
71 str r0, warm_boot_tag
72#endif
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080073#endif
Harry Yang953ff702009-12-03 21:49:00 -080074
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070075 /* see if we need to relocate */
76 mov r0, pc
77 sub r0, r0, #(.Laddr - _start)
78.Laddr:
79 ldr r1, =_start
80 cmp r0, r1
81 beq .Lstack_setup
82
83 /* we need to relocate ourselves to the proper spot */
84 ldr r2, =__data_end
85
86.Lrelocate_loop:
87 ldr r3, [r0], #4
88 str r3, [r1], #4
89 cmp r1, r2
90 bne .Lrelocate_loop
91
92 /* we're relocated, jump to the right address */
93 ldr r0, =.Lstack_setup
94 bx r0
95
96.ltorg
Harry Yang953ff702009-12-03 21:49:00 -080097#if WITH_CPU_WARM_BOOT
98warm_boot_tag:
99 .word 0
100#endif
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700101
102.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700103 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
104 mrs r0, cpsr
105 bic r0, r0, #0x1f
106
107 ldr r2, =abort_stack_top
108 orr r1, r0, #0x12 // irq
109 msr cpsr_c, r1
110 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
111
112 orr r1, r0, #0x11 // fiq
113 msr cpsr_c, r1
114 mov sp, r2
115
116 orr r1, r0, #0x17 // abort
117 msr cpsr_c, r1
118 mov sp, r2
119
120 orr r1, r0, #0x1b // undefined
121 msr cpsr_c, r1
122 mov sp, r2
123
124 orr r1, r0, #0x1f // system
125 msr cpsr_c, r1
126 mov sp, r2
127
128 orr r1, r0, #0x13 // supervisor
129 msr cpsr_c, r1
130 mov sp, r2
131
132 /* copy the initialized data segment out of rom if necessary */
133 ldr r0, =__data_start_rom
134 ldr r1, =__data_start
135 ldr r2, =__data_end
136
137 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700138 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700139
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700140.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700141 cmp r1, r2
142 ldrlt r3, [r0], #4
143 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700144 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700145
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700146.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700147 /* clear out the bss */
148 ldr r0, =__bss_start
149 ldr r1, =_end
150 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700151.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700152 cmp r0, r1
153 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700154 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700155
Ajay Dudani79d0d402010-04-21 12:38:45 -0700156#ifdef ARM_CPU_CORTEX_A8
157 DSB
158 ISB
159#endif
160
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700161 bl kmain
162 b .
163
164.ltorg
165
166.bss
167.align 2
168 /* the abort stack is for unrecoverable errors.
169 * also note the initial working stack is set to here.
170 * when the threading system starts up it'll switch to a new
171 * dynamically allocated stack, so we don't need it for very long
172 */
173abort_stack:
174 .skip 1024
175abort_stack_top: