libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
vector.c
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>,
5 * Copyright (C) 2012 chrysn <chrysn@fsfe.org>
6 *
7 * This library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <libopencm3/cm3/scb.h>
23
24/* load optional platform dependent initialization routines */
25#include "../dispatch/vector_chipset.c"
26/* load the weak symbols for IRQ_HANDLERS */
27#include "../dispatch/vector_nvic.c"
28
29/* Less common symbols exported by the linker script(s): */
30typedef void (*funcp_t) (void);
34
35int main(void);
36void blocking_handler(void);
37void null_handler(void);
38
39__attribute__ ((section(".vectors")))
42 .reset = reset_handler,
43 .nmi = nmi_handler,
44 .hard_fault = hard_fault_handler,
45
46/* Those are defined only on CM3 or CM4 */
47#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
48 .memory_manage_fault = mem_manage_handler,
49 .bus_fault = bus_fault_handler,
50 .usage_fault = usage_fault_handler,
51 .debug_monitor = debug_monitor_handler,
52#endif
53
54 .sv_call = sv_call_handler,
55 .pend_sv = pend_sv_handler,
56 .systick = sys_tick_handler,
57 .irq = {
59 }
60};
61
62void __attribute__ ((weak)) reset_handler(void)
63{
64 volatile unsigned *src, *dest;
65 funcp_t *fp;
66
67 for (src = &_data_loadaddr, dest = &_data;
68 dest < &_edata;
69 src++, dest++) {
70 *dest = *src;
71 }
72
73 while (dest < &_ebss) {
74 *dest++ = 0;
75 }
76
77 /* Ensure 8-byte alignment of stack pointer on interrupts */
78 /* Enabled by default on most Cortex-M parts, but not M3 r1 */
80
81 /* might be provided by platform specific vector.c */
82 pre_main();
83
84 /* Constructors. */
85 for (fp = &__preinit_array_start; fp < &__preinit_array_end; fp++) {
86 (*fp)();
87 }
88 for (fp = &__init_array_start; fp < &__init_array_end; fp++) {
89 (*fp)();
90 }
91
92 /* Call the application's entry point. */
93 (void)main();
94
95 /* Destructors. */
96 for (fp = &__fini_array_start; fp < &__fini_array_end; fp++) {
97 (*fp)();
98 }
99
100}
101
103{
104 while (1);
105}
106
107void null_handler(void)
108{
109 /* Do nothing. */
110}
111
112#pragma weak nmi_handler = null_handler
113#pragma weak hard_fault_handler = blocking_handler
114#pragma weak sv_call_handler = null_handler
115#pragma weak pend_sv_handler = null_handler
116#pragma weak sys_tick_handler = null_handler
117
118/* Those are defined only on CM3 or CM4 */
119#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
120#pragma weak mem_manage_handler = blocking_handler
121#pragma weak bus_fault_handler = blocking_handler
122#pragma weak usage_fault_handler = blocking_handler
123#pragma weak debug_monitor_handler = null_handler
124#endif
125
void usage_fault_handler(void)
void debug_monitor_handler(void)
void mem_manage_handler(void)
void pend_sv_handler(void)
void hard_fault_handler(void)
void nmi_handler(void)
void reset_handler(void)
Definition: vector.c:62
void sv_call_handler(void)
void bus_fault_handler(void)
void sys_tick_handler(void)
#define SCB_CCR_STKALIGN
STKALIGN set to zero to break things :)
Definition: scb.h:346
#define SCB_CCR
CCR: Configuration Control Register.
Definition: scb.h:58
#define IRQ_HANDLERS
unsigned int * initial_sp_value
Initial stack pointer value.
Definition: vector.h:48
funcp_t __fini_array_end
Definition: vector.c:33
vector_table_t vector_table
Definition: vector.c:40
funcp_t __init_array_start
void(* funcp_t)(void)
Definition: vector.c:30
funcp_t __preinit_array_start
int main(void)
void blocking_handler(void)
Definition: vector.c:102
funcp_t __fini_array_start
void null_handler(void)
Definition: vector.c:107
funcp_t __init_array_end
Definition: vector.c:32
funcp_t __preinit_array_end
Definition: vector.c:31
Definitions for handling vector tables.
unsigned _data_loadaddr
unsigned _stack
Definition: vector.h:65
unsigned _ebss
Definition: vector.h:65
unsigned _data
Definition: vector.h:65
unsigned _edata
Definition: vector.h:65
static void pre_main(void)