Document the inclusion of the Broadcom BCM4329 driver from the Linux kernel.
[bootloader-ap.git] / arch / arch-init-7x30.S
1 /*
2  * Copyright (c) 2008, Google Inc.
3  * All rights reserved.
4  * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *  * Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *  * Neither the name of Google, Inc. nor the names of its contributors
16  *    may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33
34 /* TODO:
35  * - style cleanup
36  * - do we need to do *all* of this at boot?
37  */
38
39 .text
40 .code 32
41
42 #include <boot/arm-missing-opcodes.h>
43
44 /*
45  ; LVT Ring Osc counter
46  ; used to determine sense amp settings
47  ; Clobbers registers r0, r4, r5, r6, r7, r9, r10, r11
48 */
49 .equ CLK_CTL_BASE,     0xA8600000
50 .equ A_GLBL_CLK_ENA,   0x0000
51 .equ A_PRPH_WEB_NS_REG,0x0080
52 .equ A_MSM_CLK_RINGOSC,0x00D0
53 .equ A_TCXO_CNT,       0x00D4
54 .equ A_TCXO_CNT_DONE,  0x00D8
55 .equ A_RINGOSC_CNT,    0x00DC
56 .equ A_MISC_CLK_CTL,   0x0108
57 .equ CLK_TEST,         0xA8600114
58 .equ SPSS_CSR_BASE,    0xAC100000
59 .equ A_SCRINGOSC,      0x0510
60
61 //;; Number of TCXO cycles to count ring oscillations
62 .equ TCXO_CNT_VAL,     0x100
63
64 //; Halcyon addresses
65 .equ TCSR_CONF_FUSE_1, 0xAB600060 //; TCSR_CONF_FUSE_1 register
66 .equ TCSR_CONF_FUSE_4, 0xAB60006C //; TCSR_CONF_FUSE_4 register
67
68 //; SCORPION_L1_ACC (1:0) Fuses bit location
69 .equ L1_ACC_BIT_0,     12       //;12th bit of TCSR_CONF_FUSE_4
70 .equ L1_ACC_BIT_1,     13       //;13th bit of TCSR_CONF_FUSE_4
71 //; SCORPION_L2_ACC (2:0) Fuses bit location
72 .equ L2_ACC_BIT_0,     25       //;25th bit of TCSR_CONF_FUSE_1
73 .equ L2_ACC_BIT_1,     10       //;10th bit of TCSR_CONF_FUSE_4
74 .equ L2_ACC_BIT_2,     11       //;11th bit of TCSR_CONF_FUSE_4
75
76 //; CP15: PVR2F0 values according to  SCORPION_L1_ACC (1:0)
77 .equ PVR2F0_00,        0x00000000
78 .equ PVR2F0_01,        0x04000000
79 .equ PVR2F0_10,        0x08000000
80 .equ PVR2F0_11,        0x0C000000
81
82 //; CP15: PVR2F1 values according to  SCORPION_L1_ACC (1:0)
83 .equ PVR2F1_00,        0x00000008
84 .equ PVR2F1_01,        0x00000008
85 .equ PVR2F1_10,        0x00000208
86 .equ PVR2F1_11,        0x00000208
87
88 //; CP15: PVR0F2 values according to  SCORPION_L1_ACC (1:0)
89 .equ PVR0F2_00,        0x00000000
90 .equ PVR0F2_01,        0x00000000
91 .equ PVR0F2_10,        0x00000200
92 .equ PVR0F2_11,        0x00000200
93
94 //; CP15: PVR0F0 values according to  SCORPION_L1_ACC (1:0)
95 .equ PVR0F0_00,        0x7F000000
96 .equ PVR0F0_01,        0x7F000400
97 .equ PVR0F0_10,        0x7F000000
98 .equ PVR0F0_11,        0x7F000400
99
100 //; CP15: L2VR3F1 values according to  SCORPION_L2_ACC (2:0)
101 .equ L2VR3F1_000,      0x00FFFF60
102 .equ L2VR3F1_001,      0x00FFFF40
103 .equ L2VR3F1_010,      0x00FFFC60
104 .equ L2VR3F1_011,      0x00FFFC40
105 .equ L2VR3F1_100,      0x00FCFF60
106 .equ L2VR3F1_101,      0x00FCFF40
107 .equ L2VR3F1_110,      0x00FCFC60
108 .equ L2VR3F1_111,      0x00FCFC40
109
110 .globl SET_SA
111 SET_SA:
112
113         //;--------------------------------------------------------------------
114         //; Fuse bits used to determine sense amp settings
115         //;--------------------------------------------------------------------
116
117         //; Reading L1_ACC
118         LDR     r4, = 0x0
119
120         //; Read L1_ACC_BIT_0
121         LDR     r1, =TCSR_CONF_FUSE_4
122         LDR     r2, =L1_ACC_BIT_0
123         LDR     r3, [r1]
124         MOV     r3, r3, LSR r2
125         AND     r3, r3, #1
126         ORR     r4, r3, r4
127
128         //; Read L1_ACC_BIT_1
129         LDR     r1, =TCSR_CONF_FUSE_4
130         LDR     r2, =L1_ACC_BIT_1
131         LDR     r3, [r1]
132         MOV     r3, r3, LSR r2
133         AND     r3, r3, #1
134         MOV     r3, r3, LSL #1
135         ORR     r4, r3, r4
136
137 l1_ck_0:
138         //; if L1_[1:0] == 00
139         LDR     r5, = 0x0
140         CMP     r4, r5
141         BNE     l1_ck_1
142         LDR     r0, =PVR0F0_00
143         LDR     r1, =PVR0F2_00
144         LDR     r2, =PVR2F0_00
145         LDR     r3, =PVR2F1_00
146         B       WRITE_L1_SA_SETTINGS
147
148 l1_ck_1:
149         //; if L1_[1:0] == 01
150         LDR     r1, = 0x01
151         CMP     r4, r1
152         BNE     l1_ck_2
153         LDR     r0, =PVR0F0_01
154         LDR     r1, =PVR0F2_01
155         LDR     r2, =PVR2F0_01
156         LDR     r3, =PVR2F1_01
157         B       WRITE_L1_SA_SETTINGS
158
159 l1_ck_2:
160         //; if L1_[2:0] == 10
161         LDR     r1, = 0x02
162         CMP     r4, r1
163         BNE     l1_ck_3
164         LDR     r0, =PVR0F0_10
165         LDR     r1, =PVR0F2_10
166         LDR     r2, =PVR2F0_10
167         LDR     r3, =PVR2F1_10
168         B       WRITE_L1_SA_SETTINGS
169
170 l1_ck_3:
171         //; if L1_[2:0] == 11
172         LDR     r1, = 0x03
173         CMP     r4, r1
174         LDR     r0, =PVR0F0_11
175         LDR     r1, =PVR0F2_11
176         LDR     r2, =PVR2F0_11
177         LDR     r3, =PVR2F1_11
178         B       WRITE_L1_SA_SETTINGS
179
180
181 WRITE_L1_SA_SETTINGS:
182
183         //;WCP15_PVR0F0   r0
184         MCR     p15, 0x0, r0, c15, c15, 0x0   //; write R0 to PVR0F0
185
186         //;WCP15_PVR0F2   r1
187         MCR     p15, 0x0, r1, c15, c15, 0x2   //; write R1 to PVR0F2
188
189         //;WCP15_PVR2F0   r2
190         MCR     p15, 0x2, r2, c15, c15, 0x0   //; write R2 to PVR2F0
191
192         // Disable predecode repair cache on certain Scorpion revisions
193         // (Raptor V2 and earlier, or Halcyon V1)
194         MRC    p15, 0, r1, c0, c0, 0      //; MIDR
195         BIC    r2, r1, #0xf0              //; check for Halcyon V1
196         LDR    r3, =0x511f0000
197         CMP    r2, r3
198         BNE    PVR2F1
199
200 DPRC:
201         MRC    p15, 0, r1, c15, c15, 2    //; PVR0F2
202         ORR    r1, r1, #0x10              //; enable bit 4
203         MCR    p15, 0, r1, c15, c15, 2    //; disable predecode repair cache
204
205 PVR2F1:
206         //;WCP15_PVR2F1   r3
207         MCR     p15, 0x2, r3, c15, c15, 0x1   //; write R3 to PVR2F1
208
209         //; Reading L2_ACC
210         LDR     r4, = 0x0
211
212         //; Read L2_ACC_BIT_0
213         LDR     r1, =TCSR_CONF_FUSE_1
214         LDR     r2, =L2_ACC_BIT_0
215         LDR     r3, [r1]
216         MOV     r3, r3, LSR r2
217         AND     r3, r3, #1
218         ORR     r4, r3, r4
219
220         //; Read L2_ACC_BIT_1
221         LDR     r1, =TCSR_CONF_FUSE_4
222         LDR     r2, =L2_ACC_BIT_1
223         LDR     r3, [r1]
224         MOV     r3, r3, LSR r2
225         AND     r3, r3, #1
226         MOV     r3, r3, LSL #1
227         ORR     r4, r3, r4
228
229         //; Read L2_ACC_BIT_2
230         LDR     r1, =TCSR_CONF_FUSE_4
231         LDR     r2, =L2_ACC_BIT_2
232         LDR     r3, [r1]
233         MOV     r3, r3, LSR r2
234         AND     r3, r3, #1
235         MOV     r3, r3, LSL #2
236         ORR     r4, r3, r4
237
238 l2_ck_0:
239         //; if L2_[2:0] == 000
240         LDR     r5, = 0x0
241         CMP     r4, r5
242         BNE     l2_ck_1
243         LDR     r0, =L2VR3F1_000
244         B       WRITE_L2_SA_SETTINGS
245
246 l2_ck_1:
247         //; if L2_[2:0] == 001
248         LDR     r5, = 0x1
249         CMP     r4, r5
250         BNE     l2_ck_2
251         LDR     r0, =L2VR3F1_001
252         B       WRITE_L2_SA_SETTINGS
253
254 l2_ck_2:
255         //; if L2_[2:0] == 010
256         LDR     r5, = 0x2
257         CMP     r4, r5
258         BNE     l2_ck_3
259         LDR     r0, =L2VR3F1_010
260         B       WRITE_L2_SA_SETTINGS
261
262 l2_ck_3:
263         //; if L2_[2:0] == 011
264         LDR     r5, = 0x3
265         CMP     r4, r5
266         BNE     l2_ck_4
267         LDR     r0, =L2VR3F1_011
268         B       WRITE_L2_SA_SETTINGS
269
270 l2_ck_4:
271         //; if L2_[2:0] == 100
272         LDR     r5, = 0x4
273         CMP     r4, r5
274         BNE     l2_ck_5
275         LDR     r0, =L2VR3F1_100
276         B       WRITE_L2_SA_SETTINGS
277
278 l2_ck_5:
279         //; if L2_[2:0] == 101
280         LDR     r5, = 0x5
281         CMP     r4, r5
282         BNE     l2_ck_6
283         LDR     r0, =L2VR3F1_101
284         B       WRITE_L2_SA_SETTINGS
285
286 l2_ck_6:
287         //; if L2_[2:0] == 110
288         LDR     r5, = 0x6
289         CMP     r4, r5
290         BNE     l2_ck_7
291         LDR     r0, =L2VR3F1_110
292         B       WRITE_L2_SA_SETTINGS
293
294 l2_ck_7:
295         //; if L2_[2:0] == 111
296         LDR     r5, = 0x7
297         CMP     r4, r5
298         LDR     r0, =L2VR3F1_111
299         B       WRITE_L2_SA_SETTINGS
300
301 WRITE_L2_SA_SETTINGS:
302         //;WCP15_L2VR3F1  r0
303         MCR     p15, 0x3, r0, c15, c15, 0x1     //;write r0 to L2VR3F1
304         DSB
305         ISB
306
307         LDR     r0, =0                   //;make sure the registers we touched
308         LDR     r1, =0                   //;are cleared when we return
309         LDR     r2, =0
310         LDR     r3, =0
311         LDR     r4, =0
312         LDR     r5, =0
313
314         //; routine complete
315         BX      LR
316
317 .ltorg
318
319
320 .globl __cpu_early_init
321 __cpu_early_init:
322         //; Zero out r0 for use throughout this code. All other GPRs
323         //; (r1-r3) are set throughout this code to help establish
324         //; a consistent startup state for any code that follows.
325         //; Users should add code at the end of this routine to establish
326         //; their own stack address (r13), add translation page tables, enable
327         //; the caches, etc.
328         MOV    r0,  #0x0
329
330
331         //; Remove hardcoded cache settings. appsbl_handler.s calls Set_SA
332         //;   API to dynamically configure cache for slow/nominal/fast parts
333
334         //; DCIALL to invalidate L2 cache bank (needs to be run 4 times, once per bank)
335         //; This must be done early in code (prior to enabling the caches)
336         MOV    r1, #0x2
337         MCR    p15, 0, r1, c9, c0, 6   //; DCIALL bank D ([15:14] == 2'b00)
338         ORR    r1, r1, #0x00004000
339         MCR    p15, 0, r1, c9, c0, 6   //; DCIALL bank C ([15:14] == 2'b01)
340         ADD    r1, r1, #0x00004000
341         MCR    p15, 0, r1, c9, c0, 6   //; DCIALL bank B ([15:14] == 2'b10)
342         ADD    r1, r1, #0x00004000
343         MCR    p15, 0, r1, c9, c0, 6   //; DCIALL bank A ([15:14] == 2'b11)
344
345         //; Initialize the BPCR - setup Global History Mask (GHRM) to all 1's
346         //; and have all address bits (AM) participate.
347         //; Different settings can be used to improve performance
348         // MOVW   r1, #0x01FF
349 .word 0xe30011ff  // hardcoded MOVW instruction due to lack of compiler support
350         // MOVT   r1, #0x01FF
351 .word 0xe34011ff  // hardcoded MOVT instruction due to lack of compiler support
352         MCR    p15, 7, r1, c15, c0, 2   //; WCP15_BPCR
353
354
355         //; Initialize all I$ Victim Registers to 0 for startup
356         MCR    p15, 0, r0, c9, c1, 0    //; WCP15_ICVIC0    r0
357         MCR    p15, 0, r0, c9, c1, 1    //; WCP15_ICVIC1    r0
358         MCR    p15, 0, r0, c9, c1, 2    //; WCP15_ICVIC2    r0
359         MCR    p15, 0, r0, c9, c1, 3    //; WCP15_ICVIC3    r0
360         MCR    p15, 0, r0, c9, c1, 4    //; WCP15_ICVIC4    r0
361         MCR    p15, 0, r0, c9, c1, 5    //; WCP15_ICVIC5    r0
362         MCR    p15, 0, r0, c9, c1, 6    //; WCP15_ICVIC5    r0
363         MCR    p15, 0, r0, c9, c1, 7    //; WCP15_ICVIC7    r0
364
365         //; Initialize all I$ Locked Victim Registers (Unlocked Floors) to 0
366         MCR    p15, 1, r0, c9, c1, 0    //; WCP15_ICFLOOR0  r0
367         MCR    p15, 1, r0, c9, c1, 1    //; WCP15_ICFLOOR1  r0
368         MCR    p15, 1, r0, c9, c1, 2    //; WCP15_ICFLOOR2  r0
369         MCR    p15, 1, r0, c9, c1, 3    //; WCP15_ICFLOOR3  r0
370         MCR    p15, 1, r0, c9, c1, 4    //; WCP15_ICFLOOR4  r0
371         MCR    p15, 1, r0, c9, c1, 5    //; WCP15_ICFLOOR5  r0
372         MCR    p15, 1, r0, c9, c1, 6    //; WCP15_ICFLOOR6  r0
373         MCR    p15, 1, r0, c9, c1, 7    //; WCP15_ICFLOOR7  r0
374
375         //; Initialize all D$ Victim Registers to 0
376         MCR    p15, 2, r0, c9, c1, 0    //; WP15_DCVIC0    r0
377         MCR    p15, 2, r0, c9, c1, 1    //; WP15_DCVIC1    r0
378         MCR    p15, 2, r0, c9, c1, 2    //; WP15_DCVIC2    r0
379         MCR    p15, 2, r0, c9, c1, 3    //; WP15_DCVIC3    r0
380         MCR    p15, 2, r0, c9, c1, 4    //; WP15_DCVIC4    r0
381         MCR    p15, 2, r0, c9, c1, 5    //; WP15_DCVIC5    r0
382         MCR    p15, 2, r0, c9, c1, 6    //; WP15_DCVIC6    r0
383         MCR    p15, 2, r0, c9, c1, 7    //; WP15_DCVIC7    r0
384
385         //; Initialize all D$ Locked VDCtim Registers (Unlocked Floors) to 0
386         MCR    p15, 3, r0, c9, c1, 0    //; WCP15_DCFLOOR0  r0
387         MCR    p15, 3, r0, c9, c1, 1    //; WCP15_DCFLOOR1  r0
388         MCR    p15, 3, r0, c9, c1, 2    //; WCP15_DCFLOOR2  r0
389         MCR    p15, 3, r0, c9, c1, 3    //; WCP15_DCFLOOR3  r0
390         MCR    p15, 3, r0, c9, c1, 4    //; WCP15_DCFLOOR4  r0
391         MCR    p15, 3, r0, c9, c1, 5    //; WCP15_DCFLOOR5  r0
392         MCR    p15, 3, r0, c9, c1, 6    //; WCP15_DCFLOOR6  r0
393         MCR    p15, 3, r0, c9, c1, 7    //; WCP15_DCFLOOR7  r0
394
395         //; Initialize ASID to zero
396         MCR    p15, 0, r0, c13, c0, 1   //; WCP15_CONTEXTIDR r0
397
398         //; ICIALL to invalidate entire I-Cache
399         MCR    p15, 0, r0, c7, c5, 0    //; ICIALLU
400
401         //; DCIALL to invalidate entire D-Cache
402         MCR    p15, 0, r0, c9, c0, 6    //; DCIALL  r0
403
404         //; Initialize ADFSR to zero
405         MCR    p15, 0, r0, c5, c1, 0    //; ADFSR   r0
406
407         //; Initialize EFSR to zero
408         MCR    p15, 7, r0, c15, c0, 1   //; EFSR    r0
409
410         //; The VBAR (Vector Base Address Register) should be initialized
411         //; early in your code. We are setting it to zero
412         MCR    p15, 0, r0, c12, c0, 0   //; WCP15_VBAR  r0
413
414         //; Ensure the MCR's above have completed their operation before continuing
415         DSB
416         ISB
417
418         //;-------------------------------------------------------------------
419         //; There are a number of registers that must be set prior to enabling
420         //; the MMU. The DCAR is one of these registers. We are setting
421         //; it to zero (no access) to easily detect improper setup in subsequent
422         //; code sequences
423         //;-------------------------------------------------------------------
424         //; Setup DACR (Domain Access Control Register) to zero
425         MCR    p15, 0, r0, c3, c0, 0    //; WCP15_DACR  r0
426
427         //; Setup DCLKCR to allow normal D-Cache line fills
428         MCR    p15, 1, r0, c9, c0, 7    //; WCP15_DCLKCR r0
429
430         //; Setup the TLBLKCR
431         //; Victim = 6'b000000; Floor = 6'b000000;
432         //; IASIDCFG = 2'b00 (State-Machine); IALLCFG = 2'b01 (Flash); BNA = 1'b0;
433         MOV    r1, #0x02
434         MCR    p15, 0, r1, c10, c1, 3     //; WCP15_TLBLKCR  r1
435
436         //;Make sure TLBLKCR is complete before continuing
437         ISB
438
439         //; Invalidate the UTLB
440         MCR    p15, 0, r0, c8, c7, 0      //; UTLBIALL
441
442         //; Make sure UTLB request has been presented to macro before continuing
443         ISB
444
445 SYSI2:
446         //; setup L2CR1 to some default Instruction and data prefetching values
447         //; Users may want specific settings for various performance enhancements
448         //; In Halcyon we do not have broadcasting barriers. So we need to turn
449         //  ; on bit 8 of L2CR1; which DBB:( Disable barrier broadcast )
450         LDR    r2, =0x133
451         MCR    p15, 3, r2, c15, c0, 3     //; WCP15_L2CR1  r0
452
453
454         //; Enable Z bit to enable branch prediction (default is off)
455         MRC    p15, 0, r2, c1, c0, 0      //; RCP15_SCTLR  r2
456         ORR    r2, r2, #0x00000800
457         MCR    p15, 0, r2, c1, c0, 0      //; WCP15_SCTLR  r2
458
459         //; Make sure Link stack is initialized with branch and links to sequential addresses
460         //; This aids in creating a predictable startup environment
461        BL      SEQ1
462 SEQ1:  BL      SEQ2
463 SEQ2:  BL      SEQ3
464 SEQ3:  BL      SEQ4
465 SEQ4:  BL      SEQ5
466 SEQ5:  BL      SEQ6
467 SEQ6:  BL      SEQ7
468 SEQ7:  BL      SEQ8
469 SEQ8:
470
471         //; REMOVE FOLLOWING THREE INSTRUCTIONS WHEN POWER COLLAPSE IS ENA
472         //;Make sure the DBGOSLSR[LOCK] bit is cleared to allow access to the debug registers
473         //; Writing anything but the "secret code" to the DBGOSLAR clears the DBGOSLSR[LOCK] bit
474         MCR    p14, 0, r0, c1, c0, 4       //; WCP14_DBGOSLAR r0
475
476
477         //; Read the DBGPRSR to clear the DBGPRSR[STICKYPD]
478         //; Any read to DBGPRSR clear the STICKYPD bit
479         //; ISB guarantees the read completes before attempting to
480         //; execute a CP14 instruction.
481         MRC    p14, 0, r3, c1, c5, 4       //; RCP14_DBGPRSR r3
482         ISB
483
484         //; Initialize the Watchpoint Control Registers to zero (optional)
485         //;;; MCR    p14, 0, r0, c0, c0, 7       ; WCP14_DBGWCR0  r0
486         //;;; MCR    p14, 0, r0, c0, c1, 7       ; WCP14_DBGWCR1  r0
487
488
489         //;----------------------------------------------------------------------
490         //; The saved Program Status Registers (SPSRs) should be setup
491         //; prior to any automatic mode switches. The following
492         //; code sets these registers up to a known state. Users will need to
493         //; customize these settings to meet their needs.
494         //;----------------------------------------------------------------------
495         MOV    r2,  #0x1f
496         MOV    r1,  #0xd7                 //;ABT mode
497         msr    cpsr_c, r1                 //;ABT mode
498         msr    spsr_cxfs, r2              //;clear the spsr
499         MOV    r1,  #0xdb                 //;UND mode
500         msr    cpsr_c, r1                 //;UND mode
501         msr    spsr_cxfs, r2              //;clear the spsr
502         MOV    r1,  #0xd1                 //;FIQ mode
503         msr    cpsr_c, r1                 //;FIQ mode
504         msr    spsr_cxfs, r2              //;clear the spsr
505         MOV    r1,  #0xd2                 //;IRQ mode
506         msr    cpsr_c, r1                 //;IRQ mode
507         msr    spsr_cxfs, r2              //;clear the spsr
508         MOV    r1,  #0xd6                 //;Monitor mode
509         msr    cpsr_c, r1                 //;Monitor mode
510         msr    spsr_cxfs, r2              //;clear the spsr
511         MOV    r1,  #0xd3                 //;SVC mode
512         msr    cpsr_c, r1                 //;SVC mode
513         msr    spsr_cxfs, r2              //;clear the spsr
514
515
516         //;----------------------------------------------------------------------
517         //; Enabling Error reporting is something users may want to do at
518         //; some other point in time. We have chosen some default settings
519         //; that should be reviewed. Most of these registers come up in an
520         //; unpredictable state after reset.
521         //;----------------------------------------------------------------------
522 //;Start of error and control setting
523
524         //; setup L2CR0 with various L2/TCM control settings
525         //; enable out of order bus attributes and error reporting
526         //; this register comes up unpredictable after reset
527         // MOVW   r1, #0x0F0F
528 .word 0xe3001f0f  // hardcoded MOVW instruction due to lack of compiler support
529         // MOVT   r1, #0xC005
530 .word 0xe34c1005  // hardcoded MOVW instruction due to lack of compiler support
531         MCR    p15, 3, r1, c15, c0, 1    //; WCP15_L2CR0  r1
532
533         //; setup L2CPUCR
534         //; MOV    r2, #0xFF
535         //; Enable I and D cache parity
536         //;L2CPUCR[7:5] = 3~Rh7 ~V enable parity error reporting for modified,
537         //;tag, and data parity errors
538         MOV    r2, #0xe0
539         MCR    p15, 3, r2, c15, c0, 2    //; WCP15_L2CPUCR  r2
540
541         //; setup SPCR
542         //; enable all error reporting (reset value is unpredicatble for most bits)
543         MOV    r3, #0x0F
544         MCR    p15, 0, r3, c9, c7, 0     //; WCP15_SPCR  r3
545
546         //; setup DMACHCRs (reset value unpredictable)
547         //; control setting and enable all error reporting
548         MOV   r1, #0x0F
549
550         //; DMACHCR0 = 0000000F
551         MOV   r2, #0x00                  //; channel 0
552         MCR   p15, 0, r2, c11, c0, 0     //; WCP15_DMASELR  r2
553         MCR   p15, 0, r1, c11, c0, 2     //; WCP15_DMACHCR  r1
554
555         //; DMACHCR1 = 0000000F
556         MOV   r2, #0x01                  //; channel 1
557         MCR   p15, 0, r2, c11, c0, 0     //; WCP15_DMASELR  r2
558         MCR   p15, 0, r1, c11, c0, 2     //; WCP15_DMACHCR  r1
559
560         //; DMACHCR2 = 0000000F
561         MOV   r2, #0x02                  //; channel 2
562         MCR   p15, 0, r2, c11, c0, 0     //; WCP15_DMASELR  r2
563         MCR   p15, 0, r1, c11, c0, 2     //; WCP15_DMACHCR  r1
564
565         //; DMACHCR3 = 0000000F
566         MOV   r2, #0x03                  //; channel 3
567         MCR   p15, 0, r2, c11, c0, 0     //; WCP15_DMASELR  r2
568         MCR   p15, 0, r1, c11, c0, 2     //; WCP15_DMACHCR  r1
569
570         //; Set ACTLR (reset unpredictable)
571         //; Set AVIVT control, error reporting, etc.
572         //; MOV   r3, #0x07
573         //; Enable I and D cache parity
574         //;ACTLR[2:0] = 3'h7 - enable parity error reporting from L2/I$/D$)
575         //;ACTLR[5:4] = 2'h3 - enable parity
576         //;ACTLR[19:18] =2'h3 - always generate and check parity(when MMU disabled).
577         //;Value to be written #0xC0037
578         // MOVW   r3, #0x0037
579 .word 0xe3003037  // hardcoded MOVW instruction due to lack of compiler support
580         // MOVT   r3, #0x000C
581 .word 0xe340300c  // hardcoded MOVW instruction due to lack of compiler support
582         MCR   p15, 0, r3, c1, c0, 1      //; WCP15_ACTLR  r3
583
584 //;End of error and control setting
585
586         //;----------------------------------------------------------------------
587         //; Unlock ETM and read StickyPD to halt the ETM clocks from running.
588         //; This is required for power saving whether the ETM is used or not.
589         //;----------------------------------------------------------------------
590
591         //;Clear ETMOSLSR[LOCK] bit
592         MOV   r1, #0x00000000
593         MCR   p14, 1, r1, c1, c0, 4        //; WCP14_ETMOSLAR      r1
594
595         //;Clear ETMPDSR[STICKYPD] bit
596         MRC   p14, 1, r2, c1, c5, 4        //; RCP14_ETMPDSR       r2
597
598 /*
599 #ifdef APPSBL_ETM_ENABLE
600         ;----------------------------------------------------------------------
601         ; Optionally Enable the ETM (Embedded Trace Macro) which is used for debug
602         ;----------------------------------------------------------------------
603
604         ; enable ETM clock if disabled
605         MRC   p15, 7, r1, c15, c0, 5       ; RCP15_CPMR           r1
606         ORR   r1, r1, #0x00000008
607         MCR   p15, 7, r1, c15, c0, 5       ; WCP15_CPMR           r1
608         ISB
609
610         ; set trigger event to counter1 being zero
611         MOV   r3, #0x00000040
612         MCR   p14, 1, r3, c0, c2, 0        ; WCP14_ETMTRIGGER     r3
613
614         ; clear ETMSR
615         MOV   r2, #0x00000000
616         MCR   p14, 1, r2, c0, c4, 0        ; WCP14_ETMSR          r2
617
618         ; clear trace enable single address comparator usage
619         MCR   p14, 1, r2, c0, c7, 0        ; WCP14_ETMTECR2       r2
620
621         ; set trace enable to always
622         MOV   r2, #0x0000006F
623         MCR   p14, 1, r2, c0, c8, 0        ; WCP14_ETMTEEVR       r2
624
625         ; clear trace enable address range comparator usage and exclude nothing
626         MOV   r2, #0x01000000
627         MCR   p14, 1, r2, c0, c9, 0        ; WCP14_ETMTECR1       r2
628
629         ; set view data to always
630         MOV   r2, #0x0000006F
631         MCR   p14, 1, r2, c0, c12, 0       ; WCP14_ETMVDEVR       r2
632
633         ; clear view data single address comparator usage
634         MOV   r2, #0x00000000
635         MCR   p14, 1, r2, c0, c13, 0       ;  WCP14_ETMVDCR1       r2
636
637         ; clear view data address range comparator usage and exclude nothing
638         MOV   r2, #0x00010000
639         MCR   p14, 1, r2, c0, c15, 0       ;  WCP14_ETMVDCR3       r2
640
641         ; set counter1 to 194
642         MOV   r2, #0x000000C2
643         MCR   p14, 1, r2, c0, c0, 5        ;  WCP14_ETMCNTRLDVR1   r2
644
645         ; set counter1 to never reload
646         MOV   r2, #0x0000406F
647         MCR   p14, 1, r2, c0, c8, 5        ;  WCP14_ETMCNTRLDEVR1  r2
648
649         ; set counter1 to decrement every cycle
650         MOV   r2, #0x0000006F
651         MCR   p14, 1, r2, c0, c4, 5        ; WCP14_ETMCNTENR1     r2
652
653         ; Set trace synchronization frequency 1024 bytes
654         MOV   r2, #0x00000400
655         MCR   p14, 1, r2, c0, c8, 7        ; WCP14_ETMSYNCFR      r2
656
657         ; Program etm control register
658         ;  - Set the CPU to ETM clock ratio to 1:1
659         ;  - Set the ETM to perform data address tracing
660         MOV   r2, #0x00002008
661         MCR   p14, 1, r2, c0, c0, 0        ; WCP14_ETMCR          r2
662         ISB
663 #endif *//* APPSBL_ETM_ENABLE */
664
665 /*
666 #ifdef APPSBL_VFP_ENABLE
667        ;----------------------------------------------------------------------
668        ; Perform the following operations if you intend to make use of
669        ; the VFP/Neon unit. Note that the FMXR instruction requires a CPU ID
670        ; indicating the VFP unit is present (i.e.Cortex-A8). .
671        ; Some tools will require full double precision floating point support
672        ; which will become available in Scorpion pass 2
673        ;----------------------------------------------------------------------
674        ; allow full access to CP 10 and 11 space for VFP/NEON use
675         MRC   p15, 0, r1, c1, c0, 2        ; Read CP Access Control Register
676         ORR   r1, r1, #0x00F00000          ; enable full access for p10,11
677         MCR   p15, 0, r1, c1, c0, 2        ; Write CPACR
678
679         ;make sure the CPACR is complete before continuing
680         ISB
681
682        ; Enable VFP itself (certain OSes may want to dynamically set/clear
683        ; the enable bit based on the application being executed
684         MOV   r1, #0x40000000
685         FMXR  FPEXC, r1
686 #endif *//* APPSBL_VFP_ENABLE */
687
688         BX LR
689
690
691 .ltorg