xref: /aosp_15_r20/external/google-breakpad/src/google_breakpad/common/minidump_cpu_riscv.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 /* minidump_format.h: A cross-platform reimplementation of minidump-related
2  * portions of DbgHelp.h from the Windows Platform SDK.
3  *
4  * (This is C99 source, please don't corrupt it with C++.)
5  *
6  * This file contains the necessary definitions to read minidump files
7  * produced on RISCV and RISCV64. These files may be read on any platform
8  * provided that the alignments of these structures on the processing system
9  * are identical to the alignments of these structures on the producing
10  * system. For this reason, precise-sized types are used. The structures
11  * defined by this file have been laid out to minimize alignment problems by
12  * ensuring that all members are aligned on their natural boundaries.
13  * In some cases, tail-padding may be significant when different ABIs specify
14  * different tail-padding behaviors. To avoid problems when reading or
15  * writing affected structures, MD_*_SIZE macros are provided where needed,
16  * containing the useful size of the structures without padding.
17  *
18  * Structures that are defined by Microsoft to contain a zero-length array
19  * are instead defined here to contain an array with one element, as
20  * zero-length arrays are forbidden by standard C and C++. In these cases,
21  * *_minsize constants are provided to be used in place of sizeof. For a
22  * cleaner interface to these sizes when using C++, see minidump_size.h.
23  *
24  * These structures are also sufficient to populate minidump files.
25  *
26  * Because precise data type sizes are crucial for this implementation to
27  * function properly and portably, a set of primitive types with known sizes
28  * are used as the basis of each structure defined by this file.
29  *
30  * Author: Iacopo Colonnelli
31  */
32 
33 /*
34  * RISCV and RISCV64 support
35  */
36 
37 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_RISCV_H__
38 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_RISCV_H__
39 
40 #include "google_breakpad/common/breakpad_types.h"
41 
42 #define MD_CONTEXT_RISCV_GPR_COUNT 32
43 #define MD_CONTEXT_RISCV_FPR_COUNT 32
44 
45 enum MDRISCVRegisterNumbers {
46   MD_CONTEXT_RISCV_REG_PC     = 0,
47   MD_CONTEXT_RISCV_REG_RA     = 1,
48   MD_CONTEXT_RISCV_REG_SP     = 2,
49 };
50 
51 /* For (MDRawContextRISCV).context_flags.  These values indicate the type of
52  * context stored in the structure. */
53 #define MD_CONTEXT_RISCV 0x00800000
54 #define MD_CONTEXT_RISCV_INTEGER (MD_CONTEXT_RISCV | 0x00000001)
55 #define MD_CONTEXT_RISCV_FLOATING_POINT (MD_CONTEXT_RISCV | 0x00000002)
56 #define MD_CONTEXT_RISCV_FULL (MD_CONTEXT_RISCV_INTEGER | \
57                                MD_CONTEXT_RISCV_FLOATING_POINT)
58 
59 typedef struct {
60   /* Determines which fields of this struct are populated */
61   uint32_t context_flags;
62   uint32_t version;
63 
64   uint32_t pc;
65   uint32_t ra;
66   uint32_t sp;
67   uint32_t gp;
68   uint32_t tp;
69   uint32_t t0;
70   uint32_t t1;
71   uint32_t t2;
72   uint32_t s0;
73   uint32_t s1;
74   uint32_t a0;
75   uint32_t a1;
76   uint32_t a2;
77   uint32_t a3;
78   uint32_t a4;
79   uint32_t a5;
80   uint32_t a6;
81   uint32_t a7;
82   uint32_t s2;
83   uint32_t s3;
84   uint32_t s4;
85   uint32_t s5;
86   uint32_t s6;
87   uint32_t s7;
88   uint32_t s8;
89   uint32_t s9;
90   uint32_t s10;
91   uint32_t s11;
92   uint32_t t3;
93   uint32_t t4;
94   uint32_t t5;
95   uint32_t t6;
96 
97   /* 32 floating point registers, f0 .. f31. Breakpad only supports RISCV32
98    * with 32 bit floating point. */
99   uint32_t fpregs[MD_CONTEXT_RISCV_FPR_COUNT];
100   uint32_t fcsr;
101 } MDRawContextRISCV;
102 
103 /* For (MDRawContextRISCV64).context_flags.  These values indicate the type of
104  * context stored in the structure. */
105 #define MD_CONTEXT_RISCV64 0x08000000
106 #define MD_CONTEXT_RISCV64_INTEGER (MD_CONTEXT_RISCV64 | 0x00000001)
107 #define MD_CONTEXT_RISCV64_FLOATING_POINT (MD_CONTEXT_RISCV64 | 0x00000002)
108 #define MD_CONTEXT_RISCV64_FULL (MD_CONTEXT_RISCV64_INTEGER | \
109                                  MD_CONTEXT_RISCV64_FLOATING_POINT)
110 
111 typedef struct {
112   /* Determines which fields of this struct are populated */
113   uint32_t context_flags;
114   uint32_t version;
115 
116   uint64_t pc;
117   uint64_t ra;
118   uint64_t sp;
119   uint64_t gp;
120   uint64_t tp;
121   uint64_t t0;
122   uint64_t t1;
123   uint64_t t2;
124   uint64_t s0;
125   uint64_t s1;
126   uint64_t a0;
127   uint64_t a1;
128   uint64_t a2;
129   uint64_t a3;
130   uint64_t a4;
131   uint64_t a5;
132   uint64_t a6;
133   uint64_t a7;
134   uint64_t s2;
135   uint64_t s3;
136   uint64_t s4;
137   uint64_t s5;
138   uint64_t s6;
139   uint64_t s7;
140   uint64_t s8;
141   uint64_t s9;
142   uint64_t s10;
143   uint64_t s11;
144   uint64_t t3;
145   uint64_t t4;
146   uint64_t t5;
147   uint64_t t6;
148 
149   /* 32 floating point registers, f0 .. f31. Breakpad only supports RISCV64 with
150    * 64 bit floating point. */
151   uint64_t fpregs[MD_CONTEXT_RISCV_FPR_COUNT];
152   uint32_t fcsr;
153 } MDRawContextRISCV64;
154 
155 
156 #endif  /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_RISCV_H__ */
157