FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / mips / ingenic_jz47xx / crt0.S
blob7035c5ab0bd1ee03a2f856e341b5ae187d21a15e
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2008 by Maurus Cuelenaere
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18  * KIND, either express or implied.
19  *
20  ****************************************************************************/
23  * init.S
24  *
25  * Initialization code for JzRISC.
26  *
27  * Author: Seeger Chin
28  * e-mail: seeger.chin@gmail.com
29  *
30  * Copyright (C) 2006 Ingenic Semiconductor Inc.
31  * 
32  * This program is free software; you can redistribute it and/or modify
33  * it under the terms of the GNU General Public License version 2 as
34  * published by the Free Software Foundation.
35  *
36  */
38 #include "config.h"
39 #include "mips.h"
41     .text
43     .extern system_main
44     .extern main
45     .global _start
47     .section .init.text
48     .set    mips32
49     .set    noreorder
50     .set    noat
52 #ifdef BOOTLOADER
53     /* These will get filled in by scramble */
54     .word 0 /* Empty    */
55     .word 0 /* Filesize */
57     /* Relocate bootloader */
58     la     t0, (_loadaddress-0xE00000)
59     la     t1, _loadaddress
60     la     t2, _bootend
61 _relocate_loop:
62     lw     t3, 0(t0)
63     sw     t3, 0(t1)
64     addiu  t1, 4
65     bne    t1, t2, _relocate_loop
66     addiu  t0, 4
67 #endif
69 _start:
70     la      ra, _start
71     /*
72       ----------------------------------------------------
73        Init CP0 registers.
74       ----------------------------------------------------
75     */
76     mtc0    zero, C0_WATCHLO
77     mtc0    zero, C0_WATCHHI
79     li      t0, (M_StatusBEV  | M_StatusIM7 | M_StatusIM6 \
80                 | M_StatusIM5 | M_StatusIM4 | M_StatusIM3 \
81                 | M_StatusIM2 | M_StatusERL)
82              /*
83                  BEV = Enable Boot Exception Vectors
84                  IMx = Interrupt mask
85                  ERL = Denotes error level
86              */
87     mtc0    t0, C0_STATUS
89     li      t0, M_CauseIV
90     mtc0    t0, C0_CAUSE
92     /*
93       ----------------------------------------------------
94        Init caches, assumes a 4way*128set*32byte I/D cache
95       ----------------------------------------------------
96     */
97     li      t0, 3            # enable cache for kseg0 accesses
98     mtc0    t0, C0_CONFIG    # CONFIG reg
99     la      t0, 0x80000000   # an idx op should use an unmappable address
100     ori     t1, t0, 0x4000   # 16kB cache
101     mtc0    zero, C0_TAGLO   # TAGLO reg
102     mtc0    zero, C0_TAGHI   # TAGHI reg
104 _cache_loop:
105     cache   0x8, 0(t0)       # index store icache tag
106     cache   0x9, 0(t0)       # index store dcache tag
107     bne     t0, t1, _cache_loop
108     addiu   t0, t0, 0x20     # 32 bytes per cache line
109     nop
111     /*
112       ----------------------------------------------------
113        Invalidate BTB
114       ----------------------------------------------------
115     */
116     mfc0    t0, C0_CONFIG
117     nop
118     ori     t0, 2
119     mtc0    t0, C0_CONFIG
120     nop
121     
122     /*
123       ----------------------------------------------------
124        Copy IRAM section
125         * copy IRAM first before BSS gets cleared, as both
126           have the same address
127       ----------------------------------------------------
128     */
129     la     t0, _iramcopy
130     la     t1, _iramstart
131     la     t2, _iramend
132 _iram_loop:
133     lw     t3, 0(t0)
134     sw     t3, 0(t1)
135     addiu  t1, 4
136     bne    t1, t2, _iram_loop
137     addiu  t0, 4
138     
139     /*
140       ----------------------------------------------------
141        Clear BSS section
142       ----------------------------------------------------
143     */
144     la     t0, _edata
145     la     t1, _end
146 _bss_loop:
147     sw     zero, 0(t0)
148     bne    t0, t1, _bss_loop
149     addiu  t0, 4
151     /*
152       ----------------------------------------------------
153        Set up stack
154       ----------------------------------------------------
155     */
156     la      sp, stackend
157     la      t0, stackbegin
158     li      t1, 0xDEADBEEF
159     
160 _stack_loop:    
161     sw      t1, 0(t0)
162     bne     t0, sp, _stack_loop
163     addiu   t0, t0, 4
165     /*
166       ----------------------------------------------------
167        Jump to C code
168       ----------------------------------------------------
169     */
170     jal     system_main  /* Init clocks etc first */
171     nop
172     j       main
173     nop
175     
176     /*
177      * 0x0   - Simple TLB refill handler
178      * 0x100 - Cache error handler
179      * 0x180 - Exception/Interrupt handler
180      * 0x200 - Special Exception Interrupt handler (when IV is set in CP0_CAUSE)
181      */
182     
183     .section .vectors.1, "ax", %progbits
184     j      tlb_refill_handler
185     nop
186     
187     .section .vectors.2, "ax", %progbits
188     j      real_exception_handler
189     nop
190     
191     .section .vectors.3, "ax", %progbits
192     j      real_exception_handler
193     nop
194     
195     .section .vectors.4, "ax", %progbits
196     j      real_exception_handler
197     nop
199     .section .vectors, "ax", %progbits
200 real_exception_handler:
201     addiu   sp, -0x80
202     sw      ra,    0(sp)
203     sw      fp,    4(sp)
204     sw      gp,    8(sp)
205     sw      t9,  0xC(sp)
206     sw      t8, 0x10(sp)
207     sw      s7, 0x14(sp)
208     sw      s6, 0x18(sp)
209     sw      s5, 0x1C(sp)
210     sw      s4, 0x20(sp)
211     sw      s3, 0x24(sp)
212     sw      s2, 0x28(sp)
213     sw      s1, 0x2C(sp)
214     sw      s0, 0x30(sp)
215     sw      t7, 0x34(sp)
216     sw      t6, 0x38(sp)
217     sw      t5, 0x3C(sp)
218     sw      t4, 0x40(sp)
219     sw      t3, 0x44(sp)
220     sw      t2, 0x48(sp)
221     sw      t1, 0x4C(sp)
222     sw      t0, 0x50(sp)
223     sw      a3, 0x54(sp)
224     sw      a2, 0x58(sp)
225     sw      a1, 0x5C(sp)
226     sw      a0, 0x60(sp)
227     sw      v1, 0x64(sp)
228     sw      v0, 0x68(sp)
229     sw      $1, 0x6C(sp)
230     mflo    k0
231     nop
232     sw      k0, 0x70(sp)
233     mfhi    k0
234     nop
235     sw      k0, 0x74(sp)
236     mfc0    k0, C0_STATUS
237     sll     zero, 1
238     sll     zero, 1
239     sll     zero, 1
240     sll     zero, 1
241     sw      k0, 0x78(sp)
242     mfc0    k0, C0_EPC
243     sll     zero, 1
244     sll     zero, 1
245     sll     zero, 1
246     sll     zero, 1
247     sw      k0, 0x7C(sp)
248     
249     li      k1, M_CauseExcCode
250     mfc0    k0, C0_CAUSE
251     and     k0, k1
252     beq     zero, k0, _int
253     nop
254     j       _exception
255     nop
256     
257 _int:
258     jal     intr_handler
259     nop
260     j       _exception_return
261     
262 _exception:
263     move    a0, sp
264     mfc0    a1, C0_CAUSE
265     sll     zero, 1
266     sll     zero, 1
267     sll     zero, 1
268     sll     zero, 1
269     mfc0    a2, C0_EPC
270     sll     zero, 1
271     sll     zero, 1
272     sll     zero, 1
273     sll     zero, 1
274     jal     exception_handler
275     nop
277 _exception_return:
278     lw      ra,    0(sp)
279     lw      fp,    4(sp)
280     lw      gp,    8(sp)
281     lw      t9,  0xC(sp)
282     lw      t8, 0x10(sp)
283     lw      s7, 0x14(sp)
284     lw      s6, 0x18(sp)
285     lw      s5, 0x1C(sp)
286     lw      s4, 0x20(sp)
287     lw      s3, 0x24(sp)
288     lw      s2, 0x28(sp)
289     lw      s1, 0x2C(sp)
290     lw      s0, 0x30(sp)
291     lw      t7, 0x34(sp)
292     lw      t6, 0x38(sp)
293     lw      t5, 0x3C(sp)
294     lw      t4, 0x40(sp)
295     lw      t3, 0x44(sp)
296     lw      t2, 0x48(sp)
297     lw      t1, 0x4C(sp)
298     lw      t0, 0x50(sp)
299     lw      a3, 0x54(sp)
300     lw      a2, 0x58(sp)
301     lw      a1, 0x5C(sp)
302     lw      a0, 0x60(sp)
303     lw      v1, 0x64(sp)
304     lw      v0, 0x68(sp)
305     lw      $1, 0x6C(sp)
306     lw      k0, 0x70(sp)
307     mtlo    k0
308     nop
309     lw      k0, 0x74(sp)
310     mthi    k0
311     nop
312     lw      k0, 0x78(sp)
313     mtc0    k0, C0_STATUS
314     nop
315     sll     zero, 1
316     sll     zero, 1
317     sll     zero, 1
318     sll     zero, 1
319     lw      k0, 0x7C(sp)
320     mtc0    k0, C0_EPC
321     nop
322     sll     zero, 1
323     sll     zero, 1
324     sll     zero, 1
325     sll     zero, 1
326     addiu   sp, 0x80
327     eret
328     nop
329     .set reorder
330     .set at