]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pdk_k2g_1_0_1_0_eng/packages/ti/board/diag/common/AM437x/diag_entry.S
Add alpha files for car
[processor-sdk/performance-audio-sr.git] / pdk_k2g_1_0_1_0_eng / packages / ti / board / diag / common / AM437x / diag_entry.S
1 @******************************************************************************
2 @
3 @ rtc_init.S - Init code routines
4 @
5 @******************************************************************************
6 @
7 @ Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8 @
9 @
10 @  Redistribution and use in source and binary forms, with or without
11 @  modification, are permitted provided that the following conditions
12 @  are met:
13 @
14 @    Redistributions of source code must retain the above copyright
15 @    notice, this list of conditions and the following disclaimer.
16 @
17 @    Redistributions in binary form must reproduce the above copyright
18 @    notice, this list of conditions and the following disclaimer in the
19 @    documentation and/or other materials provided with the
20 @    distribution.
21 @
22 @    Neither the name of Texas Instruments Incorporated nor the names of
23 @    its contributors may be used to endorse or promote products derived
24 @    from this software without specific prior written permission.
25 @
26 @  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 @  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 @  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 @  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 @  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 @  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 @  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 @  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 @  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 @  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 @  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 @
38 @******************************************************************************
40 @****************************** Global Symbols*********************************
41         .global Entry
42         .global _stack
43         .global _bss_start
44         .global _bss_end
45         .global start_boot
46         .global IRQHandler
47         .global FIQHandler
48         .global AbortHandler
49         .global SVC_Handler
50         .global UndefInstHandler
51         .global INTCCommonIntrHandler
53 @************************ Internal Definitions ********************************
54 @
55 @ Define the stack sizes for different modes. The user/system mode will use
56 @ the rest of the total stack size
57 @
58         .set  UND_STACK_SIZE, 0x8
59         .set  ABT_STACK_SIZE, 0x8
60         .set  FIQ_STACK_SIZE, 0x8
61         .set  IRQ_STACK_SIZE, 0x1000
62         .set  SVC_STACK_SIZE, 0x8
64 @
65 @ to set the mode bits in CPSR for different modes
66 @
67         .set  MODE_USR, 0x10
68         .set  MODE_FIQ, 0x11
69         .set  MODE_IRQ, 0x12
70         .set  MODE_SVC, 0x13
71         .set  MODE_ABT, 0x17
72         .set  MODE_UND, 0x1B
73         .set  MODE_SYS, 0x1F
75         .equ  I_F_BIT, 0xC0
76         .equ MASK_SVC_NUM, 0x1
78 @**************************** Code Seection ***********************************
79         .text
81 @
82 @ This code is assembled for ARM instructions
83 @
84         .code 32
86 @******************************************************************************
87 @
88 @******************************************************************************
89 @
90 @ The reset handler in StarterWare is named as 'Entry'.
91 @ The reset handler sets up the stack pointers for all the modes. The FIQ and
92 @ IRQ shall be disabled during this. Then clear the BSS sections and finally
93 @ switch to the function calling the main() function.
94 @
95 Entry:
96         STMFD sp!, {lr}                       @ Store link reg
97         LDR r9, =0xfeedfeed
98         CMP r0, r9
99         BEQ Diag_jump
100         @LDR r1, _DIAG_STK_PTR
101         @STR sp, [r1]
102         @MOV r5, lr
105 @ Set up the Stack for Undefined mode
107         LDR   r0, =_stack                  @ Read the stack address
108         MSR   cpsr_c, #MODE_UND|I_F_BIT    @ switch to undef  mode
109         MOV   sp,r0                        @ write the stack pointer
110         SUB   r0, r0, #UND_STACK_SIZE      @ give stack space
112 @ Set up the Stack for abort mode
114         MSR   cpsr_c, #MODE_ABT|I_F_BIT    @ Change to abort mode
115         MOV   sp, r0                       @ write the stack pointer
116         SUB   r0,r0, #ABT_STACK_SIZE       @ give stack space
118 @ Set up the Stack for FIQ mode
120         MSR   cpsr_c, #MODE_FIQ|I_F_BIT    @ change to FIQ mode
121         MOV   sp,r0                        @ write the stack pointer
122         SUB   r0,r0, #FIQ_STACK_SIZE       @ give stack space
124 @ Set up the Stack for IRQ mode
126         MSR   cpsr_c, #MODE_IRQ|I_F_BIT    @ change to IRQ mode
127         MOV   sp,r0                        @ write the stack pointer
128         SUB   r0,r0, #IRQ_STACK_SIZE       @ give stack space
130 @ Set up the Stack for SVC mode
132         MSR   cpsr_c, #MODE_SVC|I_F_BIT    @ change to SVC mode
133         MOV   sp,r0                        @ write the stack pointer
134         SUB   r0,r0, #SVC_STACK_SIZE       @ give stack space
136 @ Set up the Stack for USer/System mode
138         MSR   cpsr_c, #MODE_SYS|I_F_BIT    @ change to system mode
139         MOV   sp,r0                        @ write the stack pointer
141 @ Invalidate and Enable Branch Prediction
142         MOV     r0, #0
143         MCR     p15, #0, r0, c7, c5, #6
144         ISB
145         MRC     p15, #0, r0, c1, c0, #0
146         ORR     r0, r0, #0x00000800
147         MCR     p15, #0, r0, c1, c0, #0
150 @ Enable Neon/VFP Co-Processor
152         MRC p15, #0, r1, c1, c0, #2        @ r1 = Access Control Register
153         ORR r1, r1, #(0xf << 20)           @ enable full access for p10,11
154         MCR p15, #0, r1, c1, c0, #2        @ Access Control Register = r1
155         MOV r1, #0
156         MCR p15, #0, r1, c7, c5, #4        @ flush prefetch buffer
157         MOV r0,#0x40000000
158         FMXR FPEXC, r0                     @ Set Neon/VFP Enable bit
160 Diag_jump:
162 @ Clear the BSS section here
164 Clear_Bss_Section:
166         LDR   r0, =_bss_start              @ Start address of BSS
167         LDR   r1, =(_bss_end - 0x04)       @ End address of BSS
168         MOV   r2, #0
169 Loop:
170         STR   r2, [r0], #4                 @ Clear one word in BSS
171         CMP   r0, r1
172         BLE   Loop                         @ Clear till BSS end
173         B Diag_return_main
175 @******************************************************************************
176 @*                  Function Definition of SWI Handler
177 @******************************************************************************
179 @ The SVC Handler switches to system mode if the SVC number is 1. If the
180 @ SVC number is different, no mode switching will be done. No other SVC are
181 @ handled here
183 SVC_Handler:
184         STMFD     r13!, {r0-r1, r14}       @ Save context in SVC stack
185         SUB       r13, r13, #0x4           @ Adjust the stack pointer
186         LDR       r0, [r14, #-4]           @ R0 points to SWI instruction
187         BIC       r0, r0, #MASK_SVC_NUM    @ Get the SWI number
188         CMP       r0, #458752
189         MRSEQ     r1, spsr                 @ Copy SPSR
190         ORREQ     r1, r1, #0x1F            @ Change the mode to System
191         MSREQ     spsr_cf, r1              @ Restore SPSR
192         ADD       r13, r13, #0x4           @ Adjust the stack pointer
193         LDMFD     r13!, {r0-r1, pc}^       @ Restore registers from IRQ stack
195 @******************************************************************************
196 @*                  Function Definition of IRQ Handler
197 @******************************************************************************
199 @ The IRQ handler saves the context and jumps to the common handler which calls
200 @ the handlers of highest priority pending IRQ.
202 IRQHandler:
203         SUB       r14, r14, #4             @ Apply lr correction
204         STMFD     r13!, {r0-r3, r12, r14}  @ Save context
205         MRS       r12, spsr                @ Copy spsr
206         VMRS      r1, FPSCR                @ Copy fpscr
207         VMRS      r2, FPEXC                @ Copy fpexc
208         STMFD     r13!, {r1-r2, r12}       @ Save spsr, fpscr and fpexc
209         VSTMDB    r13!, {d0-d7}            @ Save D0-D7 Neon/VFP registers
210         VSTMDB    r13!, {d16-d31}          @ Save D16-D31 Neon/VFP registers
212         bl        INTCCommonIntrHandler
214         VLDMIA    r13!, {d16-d31}          @ Restore D16-D31 Neon/VFP registers
215         VLDMIA    r13!, {d0-d7}            @ Restore D0-D7 Neon/VFP registers
216         LDMFD     r13!, {r1-r2, r12}       @ Get fpscr, fpexc and spsr
217         MSR       spsr, r12                @ Restore spsr
218         VMSR      fpscr, r1                @ Restore fpscr
219         VMSR      fpexc, r2                @ Restore fpexc
221         LDMFD     r13!, {r0-r3, r12, pc}^  @ Restore the context and return
223 @******************************************************************************
224 @*                  Function Definition of FIQ Handler
225 @******************************************************************************
227 @ FIQ is not supported in this version of software.
229 FIQHandler:
230         SUBS      pc, r14, #0x4            @ Return to program before FIQ
232 @******************************************************************************
233 @*             Function Definition of Abort/Undef Handler
234 @******************************************************************************
236 @ The Abort handler goes to the C handler of abort mode. Note that the undefined
237 @ instruction is not handled separately.
238 @ if nothing is done in the abort mode, the execution enters infinite loop.
240 AbortHandler:
241 UndefInstHandler:
243 @ Go to infinite loop.
245 loop0:
246         B         loop0
248 Diag_return_main:
249     LDR   r10, =main                      @ Get the address of main
250     MOV   lr,pc                           @ Dummy return to main
251     BX    r10                             @ Branch to main
253 Diag_return:
254     MOV r9, r0
255     LDMFD sp!, {pc}
258 @ End of the file
260          .end