blob: c33d6dd5202b0e54e340a0cf3ed163136a6553c6 [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
Harry Yang953ff702009-12-03 21:49:00 -080053#if WITH_CPU_WARM_BOOT
54 ldr r0, warm_boot_tag
55 cmp r0, #1
56
57 /* if set, warm boot */
58 ldreq pc, =BASE_ADDR
59
60 mov r0, #1
61 str r0, warm_boot_tag
62#endif
63
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070064 /* see if we need to relocate */
65 mov r0, pc
66 sub r0, r0, #(.Laddr - _start)
67.Laddr:
68 ldr r1, =_start
69 cmp r0, r1
70 beq .Lstack_setup
71
72 /* we need to relocate ourselves to the proper spot */
73 ldr r2, =__data_end
74
75.Lrelocate_loop:
76 ldr r3, [r0], #4
77 str r3, [r1], #4
78 cmp r1, r2
79 bne .Lrelocate_loop
80
81 /* we're relocated, jump to the right address */
82 ldr r0, =.Lstack_setup
83 bx r0
84
85.ltorg
Harry Yang953ff702009-12-03 21:49:00 -080086#if WITH_CPU_WARM_BOOT
87warm_boot_tag:
88 .word 0
89#endif
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070090
91.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070092 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
93 mrs r0, cpsr
94 bic r0, r0, #0x1f
95
96 ldr r2, =abort_stack_top
97 orr r1, r0, #0x12 // irq
98 msr cpsr_c, r1
99 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
100
101 orr r1, r0, #0x11 // fiq
102 msr cpsr_c, r1
103 mov sp, r2
104
105 orr r1, r0, #0x17 // abort
106 msr cpsr_c, r1
107 mov sp, r2
108
109 orr r1, r0, #0x1b // undefined
110 msr cpsr_c, r1
111 mov sp, r2
112
113 orr r1, r0, #0x1f // system
114 msr cpsr_c, r1
115 mov sp, r2
116
117 orr r1, r0, #0x13 // supervisor
118 msr cpsr_c, r1
119 mov sp, r2
120
121 /* copy the initialized data segment out of rom if necessary */
122 ldr r0, =__data_start_rom
123 ldr r1, =__data_start
124 ldr r2, =__data_end
125
126 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700127 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700128
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700129.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700130 cmp r1, r2
131 ldrlt r3, [r0], #4
132 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700133 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700134
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700135.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700136 /* clear out the bss */
137 ldr r0, =__bss_start
138 ldr r1, =_end
139 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700140.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700141 cmp r0, r1
142 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700143 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700144
145 bl kmain
146 b .
147
148.ltorg
149
150.bss
151.align 2
152 /* the abort stack is for unrecoverable errors.
153 * also note the initial working stack is set to here.
154 * when the threading system starts up it'll switch to a new
155 * dynamically allocated stack, so we don't need it for very long
156 */
157abort_stack:
158 .skip 1024
159abort_stack_top: