xref: /rk3399_ARM-atf/plat/rockchip/rk3399/drivers/m0/src/startup.c (revision 51faada71a219a8b94cd8d8e423f0f22e9da4d8f)
1 /*
2  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of ARM nor the names of its contributors may be used
15  * to endorse or promote products derived from this software without specific
16  * prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "rk3399_mcu.h"
32 
33 /* Stack configuration */
34 #define STACK_SIZE	0x00000100
35 __attribute__ ((section(".co_stack")))
36 unsigned long pstack[STACK_SIZE];
37 
38 /* Macro definition */
39 #define WEAK __attribute__ ((weak))
40 
41 /* System exception vector handler */
42 __attribute__ ((used))
43 void WEAK reset_handler(void);
44 void WEAK nmi_handler(void);
45 void WEAK hardware_fault_handler(void);
46 void WEAK svc_handler(void);
47 void WEAK pend_sv_handler(void);
48 void WEAK systick_handler(void);
49 
50 extern int main(void);
51 
52 /* Function prototypes */
53 static void default_reset_handler(void);
54 static void default_handler(void);
55 
56 /*
57  * The minimal vector table for a Cortex M3.  Note that the proper constructs
58  * must be placed on this to ensure that it ends up at physical address
59  * 0x00000000.
60  */
61 __attribute__ ((used, section(".isr_vector")))
62 void (* const g_pfnVectors[])(void) = {
63 	/* core Exceptions */
64 	(void *)&pstack[STACK_SIZE], /* the initial stack pointer */
65 	reset_handler,
66 	nmi_handler,
67 	hardware_fault_handler,
68 	0, 0, 0, 0, 0, 0, 0,
69 	svc_handler,
70 	0, 0,
71 	pend_sv_handler,
72 	systick_handler,
73 
74 	/* external exceptions */
75 	0, 0, 0, 0, 0, 0, 0,
76 	0, 0, 0, 0, 0, 0, 0,
77 	0, 0, 0, 0, 0, 0, 0,
78 	0, 0, 0, 0, 0, 0, 0,
79 	0, 0, 0, 0
80 };
81 
82 /**
83  * This is the code that gets called when the processor first
84  * starts execution following a reset event. Only the absolutely
85  * necessary set is performed, after which the application
86  * supplied main() routine is called.
87  */
88 static void default_reset_handler(void)
89 {
90 	/* call the application's entry point */
91 	main();
92 }
93 
94 /**
95  * Provide weak aliases for each Exception handler to the Default_Handler.
96  * As they are weak aliases, any function with the same name will override
97  * this definition.
98  */
99 #pragma weak reset_handler = default_reset_handler
100 #pragma weak nmi_handler = default_handler
101 #pragma weak hardware_fault_handler = default_handler
102 #pragma weak svc_handler = default_handler
103 #pragma weak pend_sv_handler = default_handler
104 #pragma weak systick_handler = default_handler
105 
106 /**
107  * This is the code that gets called when the processor receives
108  * an unexpected interrupt.  This simply enters an infinite loop,
109  * preserving the system state for examination by a debugger.
110  */
111 static void default_handler(void)
112 {
113     /* go into an infinite loop. */
114 	while (1)
115 		;
116 }
117