1 /* Copyright (C) 2017  Adam Green (https://github.com/adamgreen)
2 
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6 
7        http://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,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14 */
15 /* Private header file shared with unit tests. */
16 #ifndef _CRASH_CATCHER_PRIV_H_
17 #define _CRASH_CATCHER_PRIV_H_
18 
19 
20 /* Definitions used by assembly language and C code. */
21 #define CRASH_CATCHER_STACK_WORD_COUNT 125
22 
23 
24 /* Definitions only required from C code. */
25 #if !__ASSEMBLER__
26 
27 #include <stdint.h>
28 #include "CrashCatcherApi.h"
29 
30 
31 /* Bit in LR to indicate whether PSP was used for automatic stacking of registers during exception entry. */
32 #define LR_PSP (1 << 2)
33 
34 /* Bit in LR set to 0 when automatic stacking of floating point registers occurs during exception handling. */
35 #define LR_FLOAT (1 << 4)
36 
37 
38 /* Bit in auto stacked xPSR which indicates whether stack was force 8-byte aligned. */
39 #define PSR_STACK_ALIGN (1 << 9)
40 
41 
42 /* This structure contains the integer registers that are automatically stacked by Cortex-M processor when it enters
43    an exception handler. */
44 typedef struct
45 {
46     uint32_t r0;
47     uint32_t r1;
48     uint32_t r2;
49     uint32_t r3;
50     uint32_t r12;
51     uint32_t lr;
52     uint32_t pc;
53     uint32_t psr;
54     /* The following floating point registers are only stacked when the LR_FLOAT bit is set in exceptionLR. */
55     uint32_t floats[16];
56     uint32_t fpscr;
57     uint32_t reserved; /* keeps 8-byte alignment */
58 } CrashCatcherStackedRegisters;
59 
60 
61 /* This is the area of memory that would normally be used for the stack when running on an actual Cortex-M
62    processor.  Unit tests can write to this buffer to simulate stack overflow. */
63 extern uint32_t g_crashCatcherStack[CRASH_CATCHER_STACK_WORD_COUNT];
64 
65 
66 /* Called from CrashCatcher core to copy all floating point registers to supplied buffer. The supplied buffer must be
67    large enough to contain 33 32-bit values (S0-S31 & FPCSR). */
68 void CrashCatcher_CopyAllFloatingPointRegisters(uint32_t* pBuffer);
69 
70 /* Called from CrashCatcher core to copy upper 16 floating point registers to supplied buffer. The supplied buffer must be
71    large enough to contain 16 32-bit values (S16-S31). */
72 void CrashCatcher_CopyUpperFloatingPointRegisters(uint32_t* pBuffer);
73 
74 #endif // #if !__ASSEMBLER__
75 
76 
77 #endif /* _CRASH_CATCHER_PRIV_H_ */
78