blob: 3a3d776618db7056d427b5c91761a56e86dd70a4 [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
Travis Geiselbrechtc3226112008-09-02 02:47:40 -070055#endif
56
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080057#if (!ENABLE_NANDWRITE)
Harry Yang953ff702009-12-03 21:49:00 -080058#if WITH_CPU_WARM_BOOT
59 ldr r0, warm_boot_tag
60 cmp r0, #1
61
62 /* if set, warm boot */
63 ldreq pc, =BASE_ADDR
64
65 mov r0, #1
66 str r0, warm_boot_tag
67#endif
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080068#endif
Harry Yang953ff702009-12-03 21:49:00 -080069
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070070 /* see if we need to relocate */
71 mov r0, pc
72 sub r0, r0, #(.Laddr - _start)
73.Laddr:
74 ldr r1, =_start
75 cmp r0, r1
76 beq .Lstack_setup
77
78 /* we need to relocate ourselves to the proper spot */
79 ldr r2, =__data_end
80
81.Lrelocate_loop:
82 ldr r3, [r0], #4
83 str r3, [r1], #4
84 cmp r1, r2
85 bne .Lrelocate_loop
86
87 /* we're relocated, jump to the right address */
88 ldr r0, =.Lstack_setup
89 bx r0
90
91.ltorg
Harry Yang953ff702009-12-03 21:49:00 -080092#if WITH_CPU_WARM_BOOT
93warm_boot_tag:
94 .word 0
95#endif
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070096
97.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070098 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
99 mrs r0, cpsr
100 bic r0, r0, #0x1f
101
102 ldr r2, =abort_stack_top
103 orr r1, r0, #0x12 // irq
104 msr cpsr_c, r1
105 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
106
107 orr r1, r0, #0x11 // fiq
108 msr cpsr_c, r1
109 mov sp, r2
110
111 orr r1, r0, #0x17 // abort
112 msr cpsr_c, r1
113 mov sp, r2
114
115 orr r1, r0, #0x1b // undefined
116 msr cpsr_c, r1
117 mov sp, r2
118
119 orr r1, r0, #0x1f // system
120 msr cpsr_c, r1
121 mov sp, r2
122
123 orr r1, r0, #0x13 // supervisor
124 msr cpsr_c, r1
125 mov sp, r2
126
127 /* copy the initialized data segment out of rom if necessary */
128 ldr r0, =__data_start_rom
129 ldr r1, =__data_start
130 ldr r2, =__data_end
131
132 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700133 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700134
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700135.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700136 cmp r1, r2
137 ldrlt r3, [r0], #4
138 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700139 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700140
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700141.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700142 /* clear out the bss */
143 ldr r0, =__bss_start
144 ldr r1, =_end
145 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700146.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700147 cmp r0, r1
148 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700149 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700150
Ajay Dudani79d0d402010-04-21 12:38:45 -0700151#ifdef ARM_CPU_CORTEX_A8
152 DSB
153 ISB
154#endif
155
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700156 bl kmain
157 b .
158
159.ltorg
160
161.bss
162.align 2
163 /* the abort stack is for unrecoverable errors.
164 * also note the initial working stack is set to here.
165 * when the threading system starts up it'll switch to a new
166 * dynamically allocated stack, so we don't need it for very long
167 */
168abort_stack:
169 .skip 1024
170abort_stack_top: