1 | .file "rom_reset.S" |
---|
2 | |
---|
3 | /* |
---|
4 | * General notice: |
---|
5 | * This code is part of a boot-monitor package developed as a generic base |
---|
6 | * platform for embedded system designs. As such, it is likely to be |
---|
7 | * distributed to various projects beyond the control of the original |
---|
8 | * author. Please notify the author of any enhancements made or bugs found |
---|
9 | * so that all may benefit from the changes. In addition, notification back |
---|
10 | * to the author will allow the new user to pick up changes that may have |
---|
11 | * been made by other users after this version of the code was distributed. |
---|
12 | * |
---|
13 | * Author: Ed Sutter |
---|
14 | * email: esutter@lucent.com |
---|
15 | * phone: 908-582-2351 |
---|
16 | * |
---|
17 | * |
---|
18 | * Modified for the CSB740 - OMAP3530 Single Board |
---|
19 | * |
---|
20 | * rom_reset.s: |
---|
21 | */ |
---|
22 | |
---|
23 | #include "warmstart.h" |
---|
24 | #include "am335x.h" |
---|
25 | #include "config.h" |
---|
26 | |
---|
27 | /* |
---|
28 | * Have a separate stack for each processor mode. |
---|
29 | */ |
---|
30 | |
---|
31 | /* define sizes for each mode's stack */ |
---|
32 | .equ FiqStackSz, 4096 |
---|
33 | .equ IrqStackSz, 4096 |
---|
34 | .equ AbtStackSz, 4096 |
---|
35 | .equ UndStackSz, 4096 |
---|
36 | .equ SysStackSz, 4096 |
---|
37 | |
---|
38 | /* declare the stacks */ |
---|
39 | .extern MonStack |
---|
40 | .global FiqStack |
---|
41 | .global IrqStack |
---|
42 | .global AbtStack |
---|
43 | .global UndStack |
---|
44 | .global SysStack |
---|
45 | .global raise |
---|
46 | .global cache_init |
---|
47 | |
---|
48 | /* allocate the stacks */ |
---|
49 | .comm FiqStack, FiqStackSz /* for the FIQ mode */ |
---|
50 | .comm IrqStack, IrqStackSz /* for the IRQ mode */ |
---|
51 | .comm AbtStack, AbtStackSz /* for the Abort mode */ |
---|
52 | .comm UndStack, UndStackSz /* for the Undef mode */ |
---|
53 | .comm SysStack, SysStackSz /* for the System mode */ |
---|
54 | /* User mode has the same stack as system mode. */ |
---|
55 | |
---|
56 | /*********************************************************************/ |
---|
57 | |
---|
58 | .extern start |
---|
59 | .extern pll_init |
---|
60 | .extern ddr_init |
---|
61 | |
---|
62 | .global reset |
---|
63 | .global coldstart |
---|
64 | .global lukewarmstart |
---|
65 | .global warmstart |
---|
66 | |
---|
67 | .text |
---|
68 | |
---|
69 | /* |
---|
70 | * Exception table at address 0 |
---|
71 | */ |
---|
72 | reset: |
---|
73 | b coldstart |
---|
74 | b undefined_instruction |
---|
75 | b software_interrupt |
---|
76 | b abort_prefetch |
---|
77 | b abort_data |
---|
78 | b not_assigned |
---|
79 | b interrupt_request |
---|
80 | b fast_interrupt_request |
---|
81 | |
---|
82 | #include "etheraddr.S" |
---|
83 | #include "moncomptr.S" |
---|
84 | #include "alttfsdevtbl.S" |
---|
85 | |
---|
86 | coldstart: |
---|
87 | ldr pc, =coldstart_1 // jump to actual ROM location |
---|
88 | nop |
---|
89 | |
---|
90 | coldstart_1: |
---|
91 | /* Make sure interrupts are off, and we're in supervisor mode... |
---|
92 | */ |
---|
93 | mrs r0,cpsr // Retreive current program status register |
---|
94 | bic r0,r0,#0x1f // Clear all mode bits. |
---|
95 | orr r0,r0,#0xd3 // Set mode to supervisor, IRQ FIQ disabled. |
---|
96 | msr cpsr,r0 |
---|
97 | |
---|
98 | // bl cache_init |
---|
99 | |
---|
100 | /********************************************************************/ |
---|
101 | |
---|
102 | midstart: |
---|
103 | ldr r0, =INITIALIZE |
---|
104 | |
---|
105 | /* fall-through to 'lukewarmstart' */ |
---|
106 | |
---|
107 | /********************************************************************/ |
---|
108 | |
---|
109 | lukewarmstart: |
---|
110 | /* Save the argument to r11 */ |
---|
111 | mov r11, r0 |
---|
112 | |
---|
113 | /* |
---|
114 | * *** DO NOT TOUCH R11 *** |
---|
115 | */ |
---|
116 | |
---|
117 | /* |
---|
118 | * Set-up the stack-pointers for all operating modes |
---|
119 | */ |
---|
120 | |
---|
121 | /* FIQ mode */ |
---|
122 | mrs r0, cpsr /* move CPSR to r0 */ |
---|
123 | bic r0, r0, #0x1f /* clear all mode bits */ |
---|
124 | orr r0, r0, #0x11 /* set FIQ mode bits */ |
---|
125 | msr CPSR_c, r0 /* move back to CPSR */ |
---|
126 | ldr sp, =(FiqStack + FiqStackSz - 4) /* initialize the stack ptr */ |
---|
127 | /* IRQ mode */ |
---|
128 | mrs r0, cpsr /* move CPSR to r0 */ |
---|
129 | bic r0, r0, #0x1f /* clear all mode bits */ |
---|
130 | orr r0, r0, #0x12 /* set IRQ mode bits */ |
---|
131 | msr CPSR_c, r0 /* move back to CPSR */ |
---|
132 | ldr sp, =(IrqStack + IrqStackSz - 4) /* initialize the stack ptr */ |
---|
133 | /* Abort mode */ |
---|
134 | mrs r0, cpsr /* move CPSR to r0 */ |
---|
135 | bic r0, r0, #0x1f /* clear all mode bits */ |
---|
136 | orr r0, r0, #0x17 /* set Abort mode bits */ |
---|
137 | msr CPSR_c, r0 /* move back to CPSR */ |
---|
138 | ldr sp, =(AbtStack + AbtStackSz - 4) /* initialize the stack ptr */ |
---|
139 | /* Undef mode */ |
---|
140 | mrs r0, cpsr /* move CPSR to r0 */ |
---|
141 | bic r0, r0, #0x1f /* clear all mode bits */ |
---|
142 | orr r0, r0, #0x1b /* set Undef mode bits */ |
---|
143 | msr CPSR_c, r0 /* move back to CPSR */ |
---|
144 | ldr sp, =(UndStack + UndStackSz - 4) /* initialize the stack ptr */ |
---|
145 | /* System mode */ |
---|
146 | mrs r0, cpsr /* move CPSR to r0 */ |
---|
147 | bic r0, r0, #0x1f /* clear all mode bits */ |
---|
148 | orr r0, r0, #0x1f /* set System mode bits */ |
---|
149 | msr CPSR_c, r0 /* move back to CPSR */ |
---|
150 | ldr sp, =(SysStack + SysStackSz - 4) /* initialize the stack ptr */ |
---|
151 | /* 'warmstart' will take us back to SVC mode |
---|
152 | stack for SVC mode will also be setup in warmstart */ |
---|
153 | |
---|
154 | mov r0, r11 /* get argument back from r11 */ |
---|
155 | b warmstart |
---|
156 | |
---|
157 | |
---|
158 | /********************************************************************/ |
---|
159 | |
---|
160 | warmstart: |
---|
161 | /* Save the argument to r11 */ |
---|
162 | mov r11, r0 |
---|
163 | |
---|
164 | /* |
---|
165 | * *** DO NOT TOUCH R11 *** |
---|
166 | */ |
---|
167 | |
---|
168 | |
---|
169 | /* Change (back) to SVC mode */ |
---|
170 | mrs r0, cpsr /* move CPSR to r0 */ |
---|
171 | bic r0, r0, #0x1f /* clear all mode bits */ |
---|
172 | orr r0, r0, #0x13 /* set System mode bits */ |
---|
173 | msr CPSR_c, r0 /* move back to CPSR */ |
---|
174 | /* Reset the stack pointer for the SVC mode (our current mode) */ |
---|
175 | ldr sp, =(MonStack + MONSTACKSIZE - 4) |
---|
176 | |
---|
177 | /* Initialize the MPU, Core, DDR, and Per PLLs. Furthermore, |
---|
178 | * initialize the external DDR3 memory as well. |
---|
179 | */ |
---|
180 | dev_init: |
---|
181 | bl pll_init |
---|
182 | bl ddr_init |
---|
183 | |
---|
184 | /* |
---|
185 | * Restore argument which was saved to r11 and jump to |
---|
186 | * the C function start(). |
---|
187 | */ |
---|
188 | |
---|
189 | mov r0, r11 |
---|
190 | jump_to_c: |
---|
191 | bl start |
---|
192 | |
---|
193 | /* the C code should never return */ |
---|
194 | b reset |
---|
195 | |
---|
196 | .align 4 |
---|
197 | |
---|
198 | |
---|
199 | /********************************************************************* |
---|
200 | * simple delay loop |
---|
201 | */ |
---|
202 | delay_200: |
---|
203 | ldr r3, =200 /* loop count */ |
---|
204 | delay_loop: |
---|
205 | subs r3,r3,#1 |
---|
206 | bne delay_loop |
---|
207 | nop |
---|
208 | |
---|
209 | mov pc, lr |
---|
210 | |
---|
211 | raise: mov pc, lr /* to make linker happy */ |
---|
212 | |
---|
213 | /********************************************************************* |
---|
214 | * Cache initialization: |
---|
215 | * Turn everything down and invalidate... |
---|
216 | */ |
---|
217 | cache_init: |
---|
218 | /* Make sure caches are turned down... |
---|
219 | */ |
---|
220 | mrc p15, 0, r3, cr1, cr0, 0 // turn off I/D-cache |
---|
221 | bic r3, r3, #4096 // I |
---|
222 | bic r3, r3, #4 // D |
---|
223 | mcr p15, 0, r3, cr1, cr0, 0 |
---|
224 | |
---|
225 | mov r0, #0 |
---|
226 | // mcr p15, 0, r0, cr7, cr7, 0 // arm_cache_invalidate |
---|
227 | mcr p15, 0, r0, cr7, cr6, 0 // arm_dcache_invalidate |
---|
228 | mcr p15, 0, r0, cr7, cr5, 0 // arm_icache_invalidate |
---|
229 | |
---|
230 | mrc p15, 0, r0, cr1, cr0, 1 // l2cache_disable |
---|
231 | bic r0, r0, #2 |
---|
232 | mcr p15, 0, r0, cr1, cr0, 1 |
---|
233 | |
---|
234 | mov r0, #1 |
---|
235 | mrc p15, 1, r0, cr0, cr0, 1 // emu_ext_boot_l2_inv |
---|
236 | mov pc, lr |
---|
237 | |
---|