diff options
Diffstat (limited to 'firmware/target/arm/imx233/crt0.S')
-rw-r--r-- | firmware/target/arm/imx233/crt0.S | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/crt0.S b/firmware/target/arm/imx233/crt0.S new file mode 100644 index 0000000000..836c3e88cb --- /dev/null +++ b/firmware/target/arm/imx233/crt0.S | |||
@@ -0,0 +1,117 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Amaury Pouly | ||
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 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | |||
24 | .section .vectors,"ax",%progbits | ||
25 | .code 32 | ||
26 | .global start | ||
27 | start: | ||
28 | /* most handlers are in DRAM which is too far away for a relative jump */ | ||
29 | ldr pc, =newstart | ||
30 | ldr pc, =undef_instr_handler | ||
31 | ldr pc, =software_int_handler | ||
32 | ldr pc, =prefetch_abort_handler | ||
33 | ldr pc, =data_abort_handler | ||
34 | ldr pc, =reserved_handler | ||
35 | ldr pc, =irq_handler | ||
36 | ldr pc, =fiq_handler | ||
37 | |||
38 | .text | ||
39 | newstart: | ||
40 | msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */ | ||
41 | /* Set up some stack and munge it with 0xdeadbeef */ | ||
42 | ldr sp, =stackend | ||
43 | ldr r2, =stackbegin | ||
44 | ldr r3, =0xdeadbeef | ||
45 | 1: | ||
46 | cmp sp, r2 | ||
47 | strhi r3, [r2], #4 | ||
48 | bhi 1b | ||
49 | |||
50 | /* Set up stack for IRQ mode */ | ||
51 | msr cpsr_c, #0xd2 | ||
52 | ldr sp, =irq_stack | ||
53 | |||
54 | /* Set up stack for FIQ mode */ | ||
55 | msr cpsr_c, #0xd1 | ||
56 | ldr sp, =fiq_stack | ||
57 | |||
58 | /* Let abort and undefined modes use IRQ stack */ | ||
59 | msr cpsr_c, #0xd7 | ||
60 | ldr sp, =irq_stack | ||
61 | msr cpsr_c, #0xdb | ||
62 | ldr sp, =irq_stack | ||
63 | |||
64 | /* Switch back to supervisor mode */ | ||
65 | msr cpsr_c, #0xd3 | ||
66 | |||
67 | /* Disable MMU, disable caching and buffering; | ||
68 | * use low exception range address (the core uses high range by default) */ | ||
69 | mrc p15, 0, r0, c1, c0, 0 | ||
70 | ldr r1, =0x3005 | ||
71 | bic r0, r1 | ||
72 | mcr p15, 0, r0, c1, c0, 0 | ||
73 | |||
74 | /* Jump to main */ | ||
75 | bl main | ||
76 | 1: | ||
77 | b 1b | ||
78 | |||
79 | /* All illegal exceptions call into UIE with exception address as first | ||
80 | * parameter. This is calculated differently depending on which exception | ||
81 | * we're in. Second parameter is exception number, used for a string lookup | ||
82 | * in UIE. */ | ||
83 | undef_instr_handler: | ||
84 | sub r0, lr, #4 @ r0 points to the faulty ARM instruction | ||
85 | #ifdef USE_THUMB | ||
86 | mrs r1, spsr | ||
87 | tst r1, #(1<<5) @ T bit set ? | ||
88 | subne r0, lr, #2 @ if yes, r0 points to the faulty THUMB instruction | ||
89 | #endif /* USE_THUMB */ | ||
90 | mov r1, #0 | ||
91 | b UIE | ||
92 | |||
93 | /* We run supervisor mode most of the time, and should never see a software | ||
94 | * exception being thrown. Perhaps make it illegal and call UIE? */ | ||
95 | software_int_handler: | ||
96 | reserved_handler: | ||
97 | movs pc, lr | ||
98 | |||
99 | prefetch_abort_handler: | ||
100 | sub r0, lr, #4 | ||
101 | mov r1, #1 | ||
102 | b UIE | ||
103 | |||
104 | data_abort_handler: | ||
105 | sub r0, lr, #8 | ||
106 | mov r1, #2 | ||
107 | b UIE | ||
108 | |||
109 | /* 256 words of IRQ stack */ | ||
110 | .space 256*4 | ||
111 | irq_stack: | ||
112 | |||
113 | /* 256 words of FIQ stack */ | ||
114 | .space 256*4 | ||
115 | fiq_stack: | ||
116 | |||
117 | end: | ||