Battery blinks if >BATTERY_LEVEL_DANGEROUS
[kugel-rb.git] / firmware / crt0.S
blob99aab838674f8bbf02d14fbe20108532d85594e6
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2002 by Linus Nielsen Feltzing
11  *
12  * All files in this archive are subject to the GNU General Public License.
13  * See the file COPYING in the source tree root for full license agreement.
14  *
15  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16  * KIND, either express or implied.
17  *
18  ****************************************************************************/
19         .section .init.text
20         .global start
21 start:
22         /* We begin with some tricks. If we have built our code to be loaded
23          * via the standalone GDB stub, we will have out VBR at some other
24          * location than 0x9000000. We must copy the trap vectors for the
25          * GDB stub to our vector table.
26          * If, on the other hand, we are running standalone we will have
27          * the VBR at 0x9000000, and the copy will not do any harm.
28          */
29         mov.l   vbr_k,r1        
30         mov.l   orig_vbr_k,r2
31         
32         /* Move the invalid instruction vector (4) */
33         mov     #4,r0
34         shll2   r0
35         mov.l   @(r0,r2),r3
36         mov.l   r3,@(r0,r1)
37         
38         /* Move the invalid slot vector (6) */
39         mov     #6,r0
40         shll2   r0
41         mov.l   @(r0,r2),r3
42         mov.l   r3,@(r0,r1)
43         
44         /* Move the bus error vector (9) */
45         mov     #9,r0
46         shll2   r0
47         mov.l   @(r0,r2),r3
48         mov.l   r3,@(r0,r1)
49         
50         /* Move the DMA bus error vector (10) */
51         mov     #10,r0
52         shll2   r0
53         mov.l   @(r0,r2),r3
54         mov.l   r3,@(r0,r1)
55         
56         /* Move the NMI vector as well (11) */
57         mov     #11,r0
58         shll2   r0
59         mov.l   @(r0,r2),r3
60         mov.l   r3,@(r0,r1)
61         
62         /* Move the breakpoint trap vector (32) */
63         mov     #32,r0
64         shll2   r0
65         mov.l   @(r0,r2),r3
66         mov.l   r3,@(r0,r1)
67         
68         /* Move the IO trap vector (33) */
69         mov     #33,r0
70         shll2   r0
71         mov.l   @(r0,r2),r3
72         mov.l   r3,@(r0,r1)
73         
74         /* Move the serial Rx interrupt vector (105) */
75         mov     #105,r0
76         shll2   r0
77         mov.l   @(r0,r2),r3
78         mov.l   r3,@(r0,r1)
80         /* Move the single step trap vector (127) */
81         mov     #127,r0
82         shll2   r0
83         mov.l   @(r0,r2),r3
84         mov.l   r3,@(r0,r1)
85         
86         ldc     r1,vbr
88         /* Now let's get on with the normal business */
89         mov.l   stack_k,r15
91         /* zero out bss */
92         mov.l   edata_k,r0
93         mov.l   end_k,r1
94         mov     #0,r2
95 start_l:
96         mov.l   r2,@r0
97         add     #4,r0
98         cmp/ge  r1,r0
99         bf      start_l
100         nop
102         /* copy the .iram section */
103         mov.l   iramcopy_k,r0
104         mov.l   iram_k,r1
105         mov.l   iramend_k,r2
106 copy_l:
107         mov.l   @r0,r3
108         mov.l   r3,@r1
109         add     #4,r0
110         add     #4,r1
111         cmp/ge  r2,r1
112         bf      copy_l
113         nop
115         /* Munge the main thread stack */
116         mov.l   stack_k,r2
117         mov.l   deadbeef_k,r0
118         mov.l   stackbegin_k,r1
119 munge_loop:
120         mov.l   r0,@r1
121         add     #4,r1
122         cmp/ge  r2,r1
123         bf      munge_loop
124         nop
126         mov     #0,r0
127         ldc     r0,gbr
128         
129         ! call the mainline     
130         mov.l   main_k,r0
131         jsr     @r0
132         nop
133 .hoo:
134     bra .hoo
136         .align 2
137 stack_k:
138         .long   _stackend       
139 stackbegin_k:
140         .long   _stackbegin
141 deadbeef_k:
142         .long   0xdeadbeef
143 edata_k:
144         .long   _edata
145 end_k:
146         .long   _end
147 iramcopy_k:
148         .long   _iramcopy
149 iram_k:
150         .long   _iramstart
151 iramend_k:
152         .long   _iramend
153 main_k:
154         .long   _main
155 vbr_k:
156         .long   vectors
157 orig_vbr_k:
158         .long 0x9000000
160         .section .resetvectors
161 vectors:
162         .long start
163         .long _stackend
164         .long start
165         .long _stackend