5 #define WEAK __attribute__ ((weak))
6 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
7 #define AFTER_VECTORS __attribute__ ((section(".after_vectors")))
10 WEAK void NMI_Handler (void);
11 WEAK void HardFault_Handler (void);
12 WEAK void SVC_Handler (void);
13 WEAK void PendSV_Handler (void);
14 WEAK void SysTick_Handler (void);
15 WEAK void IntDefaultHandler (void);
16 void FLEX_INT0_IRQHandler(void) ALIAS(IntDefaultHandler);
17 void FLEX_INT1_IRQHandler(void) ALIAS(IntDefaultHandler);
18 void FLEX_INT2_IRQHandler(void) ALIAS(IntDefaultHandler);
19 void FLEX_INT3_IRQHandler(void) ALIAS(IntDefaultHandler);
20 void FLEX_INT4_IRQHandler(void) ALIAS(IntDefaultHandler);
21 void FLEX_INT5_IRQHandler(void) ALIAS(IntDefaultHandler);
22 void FLEX_INT6_IRQHandler(void) ALIAS(IntDefaultHandler);
23 void FLEX_INT7_IRQHandler(void) ALIAS(IntDefaultHandler);
24 void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
25 void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
26 void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);
27 void I2C_IRQHandler (void) ALIAS(IntDefaultHandler);
28 void TIMER16_0_IRQHandler(void) ALIAS(IntDefaultHandler);
29 void TIMER16_1_IRQHandler(void) ALIAS(IntDefaultHandler);
30 void TIMER32_0_IRQHandler(void) ALIAS(IntDefaultHandler);
31 void TIMER32_1_IRQHandler(void) ALIAS(IntDefaultHandler);
32 void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
33 void UART_IRQHandler (void) ALIAS(IntDefaultHandler);
34 void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
35 void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
36 void ADC_IRQHandler (void) ALIAS(IntDefaultHandler);
37 void WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
38 void BOD_IRQHandler (void) ALIAS(IntDefaultHandler);
39 void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
40 void USBWakeup_IRQHandler(void) ALIAS(IntDefaultHandler);
42 extern void __libc_init_array(void);
43 extern int main(void);
44 extern void _vStackTop(void);
46 extern void (* const g_pfnVectors[])(void);
47 __attribute__ ((section(".isr_vector")))
48 void (* const g_pfnVectors[])(void) = {
99 AFTER_VECTORS void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
100 unsigned int *pulDest = (unsigned int*) start;
101 unsigned int *pulSrc = (unsigned int*) romstart;
103 for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = *pulSrc++;
106 AFTER_VECTORS void bss_init(unsigned int start, unsigned int len) {
107 unsigned int *pulDest = (unsigned int*) start;
109 for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = 0;
112 extern unsigned int __data_section_table;
113 extern unsigned int __data_section_table_end;
114 extern unsigned int __bss_section_table_end;
116 extern "C" void software_init_hook(void) __attribute__((weak));
118 AFTER_VECTORS void ResetISR(void) {
119 unsigned int LoadAddr, ExeAddr, SectionLen;
120 unsigned int *SectionTableAddr;
123 SectionTableAddr = &__data_section_table;
124 while (SectionTableAddr < &__data_section_table_end) {
125 LoadAddr = *SectionTableAddr++;
126 ExeAddr = *SectionTableAddr++;
127 SectionLen = *SectionTableAddr++;
128 data_init(LoadAddr, ExeAddr, SectionLen);
132 while (SectionTableAddr < &__bss_section_table_end) {
133 ExeAddr = *SectionTableAddr++;
134 SectionLen = *SectionTableAddr++;
135 bss_init(ExeAddr, SectionLen);
139 if (software_init_hook) // give control to the RTOS
140 software_init_hook(); // this will also call __libc_init_array
148 AFTER_VECTORS void NMI_Handler (void) {while(1){}}
149 AFTER_VECTORS void HardFault_Handler(void) {while(1){}}
150 AFTER_VECTORS void SVC_Handler (void) {while(1){}}
151 AFTER_VECTORS void PendSV_Handler (void) {while(1){}}
152 AFTER_VECTORS void SysTick_Handler (void) {while(1){}}
153 AFTER_VECTORS void IntDefaultHandler(void) {while(1){}}
157 void *operator new (size_t size) {return malloc(size);}
158 void *operator new[](size_t size) {return malloc(size);}
160 void operator delete (void *p) {free(p);}
161 void operator delete[](void *p) {free(p);}
163 int __aeabi_atexit(void *object, void (*destructor)(void *), void *dso_handle) {