xref: /aosp_15_r20/external/pigweed/targets/emcraft_sf2_som/vector_table.c (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include <stdbool.h>
16 
17 #include "pw_boot/boot.h"
18 #include "pw_boot_cortex_m/boot.h"
19 #include "pw_preprocessor/compiler.h"
20 
21 // Default handler to insert into the ARMv7-M vector table (below).
22 // This function exists for convenience. If a device isn't doing what you
23 // expect, it might have hit a fault and ended up here.
DefaultFaultHandler(void)24 static void DefaultFaultHandler(void) {
25   while (true) {
26     // Wait for debugger to attach.
27   }
28 }
29 
30 // This is the device's interrupt vector table. It's not referenced in any
31 // code because the platform (SmartFusion) expects this table to be present at
32 // the beginning of flash. The exact address is specified in the pw_boot_armv7m
33 // configuration as part of the target config.
34 //
35 // For more information, see ARMv7-M Architecture Reference Manual DDI 0403E.b
36 // section B1.5.3.
37 
38 // This typedef is for convenience when building the vector table. With the
39 // exception of SP_main (0th entry in the vector table), all the entries of the
40 // vector table are function pointers.
41 typedef void (*InterruptHandler)(void);
42 
43 // Interrupt handlers critical for OS operation.
44 void SVC_Handler(void);
45 void PendSV_Handler(void);
46 void SysTick_Handler(void);
47 void sf2_SocInit(void);
48 
49 PW_KEEP_IN_SECTION(".vector_table")
50 const InterruptHandler vector_table[] = {
51     // The starting location of the stack pointer.
52     // This address is NOT an interrupt handler/function pointer, it is simply
53     // the address that the main stack pointer should be initialized to. The
54     // value is reinterpret casted because it needs to be in the vector table.
55     [0] = (InterruptHandler)(&pw_boot_stack_high_addr),
56 
57     // Reset handler, dictates how to handle reset interrupt. This is the
58     // address that the Program Counter (PC) is initialized to at boot.
59     [1] = sf2_SocInit,
60 
61     // NMI handler.
62     [2] = DefaultFaultHandler,
63     // HardFault handler.
64     [3] = DefaultFaultHandler,
65     // 4-6: Specialized fault handlers.
66     // 7-10: Reserved.
67     // SVCall handler.
68     [11] = SVC_Handler,
69     // DebugMon handler.
70     [12] = DefaultFaultHandler,
71     // 13: Reserved.
72     // PendSV handler.
73     [14] = PendSV_Handler,
74     // SysTick handler.
75     [15] = SysTick_Handler,
76 };
77