blob: 54ccea7b2e2d04e3c2d1cf91f21896e87453dea6 (
plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
*
* Authors:
* Anup Patel <anup.patel@wdc.com>
*/
#ifndef __SBI_TRAP_H__
#define __SBI_TRAP_H__
/* clang-format off */
/** Index of zero member in sbi_trap_regs */
#define SBI_TRAP_REGS_zero 0
/** Index of ra member in sbi_trap_regs */
#define SBI_TRAP_REGS_ra 1
/** Index of sp member in sbi_trap_regs */
#define SBI_TRAP_REGS_sp 2
/** Index of gp member in sbi_trap_regs */
#define SBI_TRAP_REGS_gp 3
/** Index of tp member in sbi_trap_regs */
#define SBI_TRAP_REGS_tp 4
/** Index of t0 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t0 5
/** Index of t1 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t1 6
/** Index of t2 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t2 7
/** Index of s0 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s0 8
/** Index of s1 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s1 9
/** Index of a0 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a0 10
/** Index of a1 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a1 11
/** Index of a2 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a2 12
/** Index of a3 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a3 13
/** Index of a4 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a4 14
/** Index of a5 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a5 15
/** Index of a6 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a6 16
/** Index of a7 member in sbi_trap_regs */
#define SBI_TRAP_REGS_a7 17
/** Index of s2 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s2 18
/** Index of s3 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s3 19
/** Index of s4 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s4 20
/** Index of s5 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s5 21
/** Index of s6 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s6 22
/** Index of s7 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s7 23
/** Index of s8 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s8 24
/** Index of s9 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s9 25
/** Index of s10 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s10 26
/** Index of s11 member in sbi_trap_regs */
#define SBI_TRAP_REGS_s11 27
/** Index of t3 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t3 28
/** Index of t4 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t4 29
/** Index of t5 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t5 30
/** Index of t6 member in sbi_trap_regs */
#define SBI_TRAP_REGS_t6 31
/** Index of mepc member in sbi_trap_regs */
#define SBI_TRAP_REGS_mepc 32
/** Index of mstatus member in sbi_trap_regs */
#define SBI_TRAP_REGS_mstatus 33
/** Index of mstatusH member in sbi_trap_regs */
#define SBI_TRAP_REGS_mstatusH 34
/** Last member index in sbi_trap_regs */
#define SBI_TRAP_REGS_last 35
/** Index of epc member in sbi_trap_info */
#define SBI_TRAP_INFO_epc 0
/** Index of cause member in sbi_trap_info */
#define SBI_TRAP_INFO_cause 1
/** Index of tval member in sbi_trap_info */
#define SBI_TRAP_INFO_tval 2
/** Index of tval2 member in sbi_trap_info */
#define SBI_TRAP_INFO_tval2 3
/** Index of tinst member in sbi_trap_info */
#define SBI_TRAP_INFO_tinst 4
/** Last member index in sbi_trap_info */
#define SBI_TRAP_INFO_last 5
/* clang-format on */
/** Get offset of member with name 'x' in sbi_trap_regs */
#define SBI_TRAP_REGS_OFFSET(x) ((SBI_TRAP_REGS_##x) * __SIZEOF_POINTER__)
/** Size (in bytes) of sbi_trap_regs */
#define SBI_TRAP_REGS_SIZE SBI_TRAP_REGS_OFFSET(last)
/** Get offset of member with name 'x' in sbi_trap_info */
#define SBI_TRAP_INFO_OFFSET(x) ((SBI_TRAP_INFO_##x) * __SIZEOF_POINTER__)
/** Size (in bytes) of sbi_trap_info */
#define SBI_TRAP_INFO_SIZE SBI_TRAP_INFO_OFFSET(last)
#ifndef __ASSEMBLY__
#include <sbi/sbi_types.h>
/** Representation of register state at time of trap/interrupt */
struct sbi_trap_regs {
/** zero register state */
unsigned long zero;
/** ra register state */
unsigned long ra;
/** sp register state */
unsigned long sp;
/** gp register state */
unsigned long gp;
/** tp register state */
unsigned long tp;
/** t0 register state */
unsigned long t0;
/** t1 register state */
unsigned long t1;
/** t2 register state */
unsigned long t2;
/** s0 register state */
unsigned long s0;
/** s1 register state */
unsigned long s1;
/** a0 register state */
unsigned long a0;
/** a1 register state */
unsigned long a1;
/** a2 register state */
unsigned long a2;
/** a3 register state */
unsigned long a3;
/** a4 register state */
unsigned long a4;
/** a5 register state */
unsigned long a5;
/** a6 register state */
unsigned long a6;
/** a7 register state */
unsigned long a7;
/** s2 register state */
unsigned long s2;
/** s3 register state */
unsigned long s3;
/** s4 register state */
unsigned long s4;
/** s5 register state */
unsigned long s5;
/** s6 register state */
unsigned long s6;
/** s7 register state */
unsigned long s7;
/** s8 register state */
unsigned long s8;
/** s9 register state */
unsigned long s9;
/** s10 register state */
unsigned long s10;
/** s11 register state */
unsigned long s11;
/** t3 register state */
unsigned long t3;
/** t4 register state */
unsigned long t4;
/** t5 register state */
unsigned long t5;
/** t6 register state */
unsigned long t6;
/** mepc register state */
unsigned long mepc;
/** mstatus register state */
unsigned long mstatus;
/** mstatusH register state (only for 32-bit) */
unsigned long mstatusH;
} __packed;
/** Representation of trap details */
struct sbi_trap_info {
/** epc Trap program counter */
unsigned long epc;
/** cause Trap exception cause */
unsigned long cause;
/** tval Trap value */
unsigned long tval;
/** tval2 Trap value 2 */
unsigned long tval2;
/** tinst Trap instruction */
unsigned long tinst;
};
struct sbi_scratch;
int sbi_trap_redirect(struct sbi_trap_regs *regs,
struct sbi_trap_info *trap);
void sbi_trap_handler(struct sbi_trap_regs *regs,
struct sbi_scratch *scratch);
#endif
#endif
|