forked from kiibohd/controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm_cortex.h
154 lines (131 loc) · 6.66 KB
/
arm_cortex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Copyright (C) 2018 by Rowan Decker
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// ----- Defines -----
/* Auxiliary Control Register Definitions */
#define SCnSCB_ACTLR *(volatile uint32_t *)0xE000E008 // Auxiliary control
#define SCnSCB_ACTLR_DISOOFP_Pos 9 /*!< ACTLR: DISOOFP Position */
#define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */
#define SCnSCB_ACTLR_DISFPCA_Pos 8 /*!< ACTLR: DISFPCA Position */
#define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */
#define SCnSCB_ACTLR_DISFOLD_Pos 2 /*!< ACTLR: DISFOLD Position */
#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1 /*!< ACTLR: DISDEFWBUF Position */
#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */
#define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */
#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos) /*!< ACTLR: DISMCYCINT Mask */
// ----- Types -----
/*
* Exception type Position Priority Description
* -------------- ------------ -------- ------------------------------------
* Reset 1 –3 (highest) Invoked on power up and warm reset. On first instruction,
* drops to lowest priority (Thread mode). This is asynchronous
* Non-maskable Int 2 –2 Cannot be stopped or pre-empted by any exception but reset.
* This is asynchronous.
* Hard Fault 3 –1 All classes of Fault, when the fault cannot activate because of
* priority or the Configurable Fault handler has been disabled.
* This is synchronous.
* Memory Management 4 Configurable Memory Protection Unit (MPU) mismatch, including access
* violation and no match. This is synchronous. This is used
* even if the MPU is disabled or not present, to support the
* Executable Never (XN) regions of the default memory map.
* Bus Fault 5 Configurable Pre-fetch fault, memory access fault, and other
* address/memory related. This is synchronous when precise
* and asynchronous when imprecise.
* Usage Fault 6 Configurable Usage fault, such as Undefined instruction executed or illegal
* state transition attempt. This is synchronous.
* - 7-10 - Reserved
* SVCall 11 Configurable System service call with SVC instruction. This is
* synchronous.
* Debug Monitor 12 Configurable Debug monitor, when not halting. This is synchronous, but
* only active when enabled. It does not activate if lower priority
* than the current activation.
* - 13 - Reserved
* PendSV 14 Configurable Pendable request for system service. This is asynchronous
* and only pended by software.
* SysTick 15 Configurable System tick timer has fired. This is asynchronous.
*
* External Interrupt 16 and above Configurable Asserted from outside the core, INTISR[239:0], and fed
* through the NVIC (prioritized). These are all asynchronous.
*/
typedef enum {
IRQ_Reset = 1,
IRQ_NMI = 2,
IRQ_HardFault = 3,
IRQ_MemoryManagement = 4,
IRQ_BusFault = 5,
IRQ_UsageFault = 6,
IRQ_SVCall = 11,
IRQ_PendSV = 14,
IRQ_SysTick = 15,
IRQ_External = 16
} Cortex_IRQ;
typedef struct __attribute__((packed)) {
uint8_t IACCVIOL: 1;
uint8_t DACCVIOL: 1;
uint8_t: 1;
uint8_t MUNSTKERR: 1;
uint8_t MSTKERR: 1;
unsigned: 2;
uint8_t MMARVALID: 1;
} MMFSR_t;
typedef struct __attribute__((packed)) {
uint8_t IBUSERR: 1;
uint8_t PRECISERR: 1;
uint8_t IMPRECISERR: 1;
uint8_t UNSTKERR: 1;
uint8_t STKERR: 1;
uint8_t: 2;
uint8_t BFARVALID: 1;
} BFSR_t;
typedef struct __attribute__((packed)) {
uint8_t UNDEFINSTR: 1;
uint8_t INVSTATE: 1;
uint8_t INVPC: 1;
uint8_t NOCP: 1;
uint8_t: 4;
uint8_t UNALIGNED: 1;
uint8_t DIVBYZERO: 1;
} UFSR_t;
typedef struct __attribute__((packed)) {
MMFSR_t MMFSR;
BFSR_t BFSR;
UFSR_t UFSR;
} CFSR_t;
typedef struct __attribute__((packed)) {
uint8_t: 1;
uint8_t VECTTBL: 1;
uint32_t: 28;
uint8_t FORCED: 1;
uint8_t DEBUGEVT: 1;
} HFSR_t;
typedef struct __attribute__((packed)) {
uint8_t BKPT: 1;
uint8_t DWTRAP: 1;
uint8_t VCATCH: 1;
uint8_t EXTERNAL: 1;
uint32_t: 28;
} DFSR_t;
// ----- Functions -----
extern void __attribute__((naked)) debug_isr ( void );
Cortex_IRQ get_current_isr();
void read_stacked_fault_frame( uint32_t *faultStackedAddress );
void disable_write_buffering();