blob: d5b4a32c6dc0b1ca611edda988ec5dc2b517aef5 [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 */
23.text
24.globl _start
25_start:
26 b reset
27 b arm_undefined
28 b arm_syscall
29 b arm_prefetch_abort
30 b arm_data_abort
31 b arm_reserved
32 b arm_irq
33 b arm_fiq
34
35reset:
36 /* do some cpu setup */
37#if ARM_WITH_CP15
38 mrc p15, 0, r0, c1, c0, 0
39 /* XXX this is currently for arm926, revist with armv6 cores */
40 /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */
41 bic r0, r0, #(1<<15| 1<<13 | 1<<12)
42 bic r0, r0, #(1<<2 | 1<<0)
43 /* enable alignment faults */
44 orr r0, r0, #(1<<1)
45 mcr p15, 0, r0, c1, c0, 0
46#endif
47
Brian Swetlanda8cf2b82009-01-01 03:29:51 -080048#if WITH_CPU_EARLY_INIT
49 /* call platform/arch/etc specific init code */
50 bl __cpu_early_init
Travis Geiselbrechtc3226112008-09-02 02:47:40 -070051#endif
52
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080053#if (!ENABLE_NANDWRITE)
Harry Yang953ff702009-12-03 21:49:00 -080054#if WITH_CPU_WARM_BOOT
55 ldr r0, warm_boot_tag
56 cmp r0, #1
57
58 /* if set, warm boot */
59 ldreq pc, =BASE_ADDR
60
61 mov r0, #1
62 str r0, warm_boot_tag
63#endif
Chandan Uddaraju6cc1e3d2009-12-15 15:21:06 -080064#endif
Harry Yang953ff702009-12-03 21:49:00 -080065
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070066 /* see if we need to relocate */
67 mov r0, pc
68 sub r0, r0, #(.Laddr - _start)
69.Laddr:
70 ldr r1, =_start
71 cmp r0, r1
72 beq .Lstack_setup
73
74 /* we need to relocate ourselves to the proper spot */
75 ldr r2, =__data_end
76
77.Lrelocate_loop:
78 ldr r3, [r0], #4
79 str r3, [r1], #4
80 cmp r1, r2
81 bne .Lrelocate_loop
82
83 /* we're relocated, jump to the right address */
84 ldr r0, =.Lstack_setup
85 bx r0
86
87.ltorg
Harry Yang953ff702009-12-03 21:49:00 -080088#if WITH_CPU_WARM_BOOT
89warm_boot_tag:
90 .word 0
91#endif
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070092
93.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070094 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
95 mrs r0, cpsr
96 bic r0, r0, #0x1f
97
98 ldr r2, =abort_stack_top
99 orr r1, r0, #0x12 // irq
100 msr cpsr_c, r1
101 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
102
103 orr r1, r0, #0x11 // fiq
104 msr cpsr_c, r1
105 mov sp, r2
106
107 orr r1, r0, #0x17 // abort
108 msr cpsr_c, r1
109 mov sp, r2
110
111 orr r1, r0, #0x1b // undefined
112 msr cpsr_c, r1
113 mov sp, r2
114
115 orr r1, r0, #0x1f // system
116 msr cpsr_c, r1
117 mov sp, r2
118
119 orr r1, r0, #0x13 // supervisor
120 msr cpsr_c, r1
121 mov sp, r2
122
123 /* copy the initialized data segment out of rom if necessary */
124 ldr r0, =__data_start_rom
125 ldr r1, =__data_start
126 ldr r2, =__data_end
127
128 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700129 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700130
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700131.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700132 cmp r1, r2
133 ldrlt r3, [r0], #4
134 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700135 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700136
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700137.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700138 /* clear out the bss */
139 ldr r0, =__bss_start
140 ldr r1, =_end
141 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700142.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700143 cmp r0, r1
144 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700145 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700146
147 bl kmain
148 b .
149
150.ltorg
151
152.bss
153.align 2
154 /* the abort stack is for unrecoverable errors.
155 * also note the initial working stack is set to here.
156 * when the threading system starts up it'll switch to a new
157 * dynamically allocated stack, so we don't need it for very long
158 */
159abort_stack:
160 .skip 1024
161abort_stack_top: