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