blob: 9196d1086bc60f1dc7b032bec2e4527c68172369 [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
Travis Geiselbrecht887061f2008-09-05 01:47:07 -070053 /* see if we need to relocate */
54 mov r0, pc
55 sub r0, r0, #(.Laddr - _start)
56.Laddr:
57 ldr r1, =_start
58 cmp r0, r1
59 beq .Lstack_setup
60
61 /* we need to relocate ourselves to the proper spot */
62 ldr r2, =__data_end
63
64.Lrelocate_loop:
65 ldr r3, [r0], #4
66 str r3, [r1], #4
67 cmp r1, r2
68 bne .Lrelocate_loop
69
70 /* we're relocated, jump to the right address */
71 ldr r0, =.Lstack_setup
72 bx r0
73
74.ltorg
75
76.Lstack_setup:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070077 /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
78 mrs r0, cpsr
79 bic r0, r0, #0x1f
80
81 ldr r2, =abort_stack_top
82 orr r1, r0, #0x12 // irq
83 msr cpsr_c, r1
84 ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */
85
86 orr r1, r0, #0x11 // fiq
87 msr cpsr_c, r1
88 mov sp, r2
89
90 orr r1, r0, #0x17 // abort
91 msr cpsr_c, r1
92 mov sp, r2
93
94 orr r1, r0, #0x1b // undefined
95 msr cpsr_c, r1
96 mov sp, r2
97
98 orr r1, r0, #0x1f // system
99 msr cpsr_c, r1
100 mov sp, r2
101
102 orr r1, r0, #0x13 // supervisor
103 msr cpsr_c, r1
104 mov sp, r2
105
106 /* copy the initialized data segment out of rom if necessary */
107 ldr r0, =__data_start_rom
108 ldr r1, =__data_start
109 ldr r2, =__data_end
110
111 cmp r0, r1
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700112 beq .L__do_bss
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700113
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700114.L__copy_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700115 cmp r1, r2
116 ldrlt r3, [r0], #4
117 strlt r3, [r1], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700118 blt .L__copy_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700119
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700120.L__do_bss:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700121 /* clear out the bss */
122 ldr r0, =__bss_start
123 ldr r1, =_end
124 mov r2, #0
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700125.L__bss_loop:
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700126 cmp r0, r1
127 strlt r2, [r0], #4
Travis Geiselbrecht887061f2008-09-05 01:47:07 -0700128 blt .L__bss_loop
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700129
130 bl kmain
131 b .
132
133.ltorg
134
135.bss
136.align 2
137 /* the abort stack is for unrecoverable errors.
138 * also note the initial working stack is set to here.
139 * when the threading system starts up it'll switch to a new
140 * dynamically allocated stack, so we don't need it for very long
141 */
142abort_stack:
143 .skip 1024
144abort_stack_top: