1 ;/*******************************************************************************
\r
3 ;* This software is supplied by Renesas Electronics Corporation and is only
\r
4 ;* intended for use with Renesas products. No other uses are authorized. This
\r
5 ;* software is owned by Renesas Electronics Corporation and is protected under
\r
6 ;* all applicable laws, including copyright laws.
\r
7 ;* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
\r
8 ;* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
\r
9 ;* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
\r
10 ;* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
\r
11 ;* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
\r
12 ;* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
\r
13 ;* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
\r
14 ;* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
\r
15 ;* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
16 ;* Renesas reserves the right, without notice, to make changes to this software
\r
17 ;* and to discontinue the availability of this software. By using this software,
\r
18 ;* you agree to the additional terms and conditions found by accessing the
\r
20 ;* http://www.renesas.com/disclaimer
\r
22 ;* Copyright (C) 2012 Renesas Electronics Corporation. All rights reserved.
\r
23 ;*******************************************************************************/
\r
24 ;/*******************************************************************************
\r
25 ;* File Name : reset_handler.s
\r
27 ;* Device(s) : Aragon
\r
28 ;* Tool-Chain : DS-5 Ver 5.8
\r
31 ;* H/W Platform : Aragon CPU Board
\r
32 ;* Description : Aragon Sample Program - Reset handler
\r
33 ;*******************************************************************************/
\r
34 ;/*******************************************************************************
\r
35 ;* History : DD.MM.YYYY Version Description
\r
36 ;* : 23.05.2012 0.01
\r
37 ;*******************************************************************************/
\r
39 ; Standard definitions of mode bits and interrupt (I & F) flags in PSRs
\r
47 Thum_bit EQU 0x20 ; CPSR/SPSR Thumb bit
\r
50 ;==================================================================
\r
51 ; Entry point for the Reset handler
\r
52 ;==================================================================
\r
54 AREA RESET_HANDLER, CODE, READONLY
\r
56 IMPORT ||Image$$ARM_LIB_STACK$$ZI$$Limit|| ; Linker symbol from scatter file
\r
57 IMPORT ||Image$$IRQ_STACK$$ZI$$Limit|| ; Linker symbol from scatter file
\r
58 IMPORT ||Image$$FIQ_STACK$$ZI$$Limit|| ; Linker symbol from scatter file
\r
59 IMPORT ||Image$$SVC_STACK$$ZI$$Limit|| ; Linker symbol from scatter file
\r
60 IMPORT ||Image$$ABT_STACK$$ZI$$Limit|| ; Linker symbol from scatter file
\r
62 IMPORT Peripheral_BasicInit
\r
66 EXPORT reset_handler
\r
67 EXPORT undefined_handler
\r
69 EXPORT prefetch_handler
\r
70 EXPORT abort_handler
\r
71 EXPORT reserved_handler
\r
73 ;==================================================================
\r
75 ;==================================================================
\r
76 reset_handler FUNCTION {}
\r
78 ;==================================================================
\r
79 ; Disable cache and MMU in case it was left enabled from an earlier run
\r
80 ; This does not need to be done from a cold reset
\r
81 ;==================================================================
\r
82 MRC p15, 0, r0, c1, c0, 0 ;;; Read CP15 System Control register (SCTLR)
\r
83 BIC r0, r0, #(0x1 << 12) ;;; Clear I bit 12 to disable I Cache
\r
84 BIC r0, r0, #(0x1 << 2) ;;; Clear C bit 2 to disable D Cache
\r
85 BIC r0, r0, #0x1 ;;; Clear M bit 0 to disable MMU
\r
86 MCR p15, 0, r0, c1, c0, 0 ;;; Write value back to CP15 System Control register
\r
88 ;==================================================================
\r
89 ; Setting up Stack Area
\r
90 ;==================================================================
\r
91 ;;; SVC Mode(Default)
\r
92 LDR sp, =||Image$$SVC_STACK$$ZI$$Limit||
\r
94 CPS #IRQ_MODE ;;; IRQ Mode
\r
95 LDR sp, =||Image$$IRQ_STACK$$ZI$$Limit||
\r
97 CPS #FIQ_MODE ;;; FIQ Mode
\r
98 LDR sp, =||Image$$FIQ_STACK$$ZI$$Limit||
\r
100 CPS #ABT_MODE ;;; ABT Mode
\r
101 LDR sp, =||Image$$ABT_STACK$$ZI$$Limit||
\r
104 ;; FreeRTOS does not need a System/User mode stack as only tasks run in
\r
105 ;; System/User mode, and their stack is allocated when the task is created.
\r
106 ;; Therefore the CSTACK allocated in the linker script is instead given to
\r
107 ;; Supervisor mode, and main() is called from Supervisor mode.
\r
109 CPS #SVC_MODE ;;; SVC Mode
\r
111 ;; SVC mode Stack pointer is set up ARM_LIB_STACK in the __main()->__entry()
\r
112 LDR sp, =||Image$$ARM_LIB_STACK$$ZI$$Limit||
\r
114 ;==================================================================
\r
115 ; TLB maintenance, Invalidate Data and Instruction TLBs
\r
116 ;==================================================================
\r
118 MCR p15, 0, r0, c8, c7, 0 ;;; Cortex-A9 I-TLB and D-TLB invalidation (TLBIALL)
\r
120 ;===================================================================
\r
121 ; Invalidate instruction cache, also flushes BTAC
\r
122 ;===================================================================
\r
124 MCR p15, 0, r0, c7, c5, 0 ;;; ICIALLU - Invalidate entire I Cache, and flushes branch target cache
\r
126 ;==================================================================
\r
127 ; Cache Invalidation code for Cortex-A9
\r
128 ;==================================================================
\r
129 ;;; Invalidate L1 Instruction Cache
\r
130 MRC p15, 1, r0, c0, c0, 1 ;;; Read Cache Level ID Register (CLIDR)
\r
131 TST r0, #0x3 ;;; Harvard Cache?
\r
133 MCRNE p15, 0, r0, c7, c5, 0 ;;; Invalidate Instruction Cache
\r
135 ;;; Invalidate Data/Unified Caches
\r
136 MRC p15, 1, r0, c0, c0, 1 ;;; Read CLIDR
\r
137 ANDS r3, r0, #0x07000000 ;;; Extract coherency level
\r
138 MOV r3, r3, LSR #23 ;;; Total cache levels << 1
\r
139 BEQ Finished ;;; If 0, no need to clean
\r
141 MOV r10, #0 ;;; R10 holds current cache level << 1
\r
143 ADD r2, r10, r10, LSR #1 ;;; R2 holds cache "Set" position
\r
144 MOV r1, r0, LSR r2 ;;; Bottom 3 bits are the Cache-type for this level
\r
145 AND r1, r1, #7 ;;; Isolate those lower 3 bits
\r
147 BLT Skip ;;; No cache or only instruction cache at this level
\r
149 MCR p15, 2, r10, c0, c0, 0 ;;; Write the Cache Size selection register (CSSELR)
\r
150 ISB ;;; ISB to sync the change to the CacheSizeID reg
\r
151 MRC p15, 1, r1, c0, c0, 0 ;;; Reads current Cache Size ID register (CCSIDR)
\r
152 AND r2, r1, #7 ;;; Extract the line length field
\r
153 ADD r2, r2, #4 ;;; Add 4 for the line length offset (log2 16 bytes)
\r
155 ANDS r4, r4, r1, LSR #3 ;;; R4 is the max number on the way size (right aligned)
\r
156 CLZ r5, r4 ;;; R5 is the bit position of the way size increment
\r
158 ANDS r7, r7, r1, LSR #13 ;;; R7 is the max number of the index size (right aligned)
\r
160 MOV r9, r4 ;;; R9 working copy of the max way size (right aligned)
\r
163 ORR r11, r10, r9, LSL r5 ;;; Factor in the Way number and cache number into R11
\r
164 ORR r11, r11, r7, LSL r2 ;;; Factor in the Set number
\r
165 MCR p15, 0, r11, c7, c6, 2 ;;; Invalidate by Set/Way (DCISW)
\r
166 SUBS r9, r9, #1 ;;; Decrement the Way number
\r
168 SUBS r7, r7, #1 ;;; Decrement the Set number
\r
171 ADD r10, r10, #2 ;;; increment the cache number
\r
177 ;==================================================================
\r
179 ;==================================================================
\r
180 BL init_TTB ;;; Initialize TTB
\r
182 ;===================================================================
\r
183 ; Setup domain control register - Enable all domains to client mode
\r
184 ;===================================================================
\r
185 MRC p15, 0, r0, c3, c0, 0 ;;; Read Domain Access Control Register (DACR)
\r
186 LDR r0, =0x55555555 ;;; Initialize every domain entry to b01 (client)
\r
187 MCR p15, 0, r0, c3, c0, 0 ;;; Write Domain Access Control Register
\r
189 IF {TARGET_FEATURE_NEON} || {TARGET_FPU_VFP}
\r
190 ;==================================================================
\r
191 ; Enable access to NEON/VFP by enabling access to Coprocessors 10 and 11.
\r
192 ; Enables Full Access i.e. in both privileged and non privileged modes
\r
193 ;==================================================================
\r
194 MRC p15, 0, r0, c1, c0, 2 ;;; Read Coprocessor Access Control Register (CPACR)
\r
195 ORR r0, r0, #(0xF << 20) ;;; Enable access to CP 10 & 11
\r
196 MCR p15, 0, r0, c1, c0, 2 ;;; Write Coprocessor Access Control Register (CPACR)
\r
199 ;=================================================================
\r
200 ; Switch on the VFP and NEON hardware
\r
201 ;=================================================================
\r
202 MOV r0, #0x40000000
\r
203 VMSR FPEXC, r0 ;;; Write FPEXC register, EN bit set
\r
207 ;===================================================================
\r
209 ; Leaving the caches disabled until after scatter loading(__main).
\r
210 ;===================================================================
\r
211 MRC p15, 0, r0, c1, c0, 0 ;;; Read CP15 System Control register (SCTLR)
\r
212 BIC r0, r0, #(0x1 << 12) ;;; Clear I bit 12 to disable I Cache
\r
213 BIC r0, r0, #(0x1 << 2) ;;; Clear C bit 2 to disable D Cache
\r
214 BIC r0, r0, #0x2 ;;; Clear A bit 1 to disable strict alignment fault checking
\r
215 ORR r0, r0, #0x1 ;;; Set M bit 0 to enable MMU before scatter loading
\r
216 MCR p15, 0, r0, c1, c0, 0 ;;; Write CP15 System Control register
\r
218 ;==================================================================
\r
219 ; Hardware initialize
\r
220 ; Initialize CPG, BSC for CS0 and CS1, and enable On-Chip Data-Retention RAM
\r
221 ;==================================================================
\r
222 LDR r12,=Peripheral_BasicInit ;;; Save this in register for possible long jump
\r
223 BLX r12 ;;; Hardware Initialize
\r
225 ;===================================================================
\r
227 ;===================================================================
\r
228 LDR r12,=__main ;;; Save this in register for possible long jump
\r
229 BX r12 ;;; Branch to __main C library entry point
\r
238 ;==================================================================
\r
240 ;==================================================================
\r
242 B undefined_handler ;;; Ž©”Ô’nƒ‹�[ƒv
\r
245 B svc_handler ;;; Ž©”Ô’nƒ‹�[ƒv
\r
248 B prefetch_handler ;;; Ž©”Ô’nƒ‹�[ƒv
\r
251 B abort_handler ;;; Ž©”Ô’nƒ‹�[ƒv
\r
254 B reserved_handler ;;; Ž©”Ô’nƒ‹�[ƒv
\r