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
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2022 repnop
//
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at https://mozilla.org/MPL/2.0/.
use crate::;
/// Hart state management extension ID
pub const EXTENSION_ID: usize = 0x48534D;
/// Start the specific hart ID at the given physical address along with a
/// user-defined value. On success, the hart begins execution at the physical
/// address with the following register states:
///
/// `satp` is reset to a value of `0` (virtual memory protection disabled)
///
/// `sstatus.SIE` is reset to a value of `0` (supervisor interrupts disabled)
///
/// `a0` contains the current hart ID
///
/// `a1` contains the value of the `opaque` parameter
///
/// All other registers are in an undefined state
///
/// ### Safety
///
/// This function is marked unsafe as it allows arbitrary execution at a given
/// physical address, which can cause undefined behavior if used incorrectly.
///
/// ### Possible errors
///
/// [`SbiError::INVALID_ADDRESS`]: `start_address` is an invalid address because
/// it is either an invalid physical address or execution is prohibited by
/// physical memory protection.
///
/// [`SbiError::INVALID_PARAMETER`]: The specified hart ID is either not valid
/// or cannot be started in S-mode.
///
/// [`SbiError::ALREADY_AVAILABLE`]: The specified hart ID is already started.
///
/// [`SbiError::FAILED`]: Start request failed for unknown reasons.
pub unsafe
/// This SBI call stops S-mode execution on the current hart and yields
/// execution back to the SBI implementation. Note: **this function must be
/// called with supervisor and user interrupts disabled.**
///
/// ### Possible errors
///
/// [`SbiError::FAILED`]: The request failed for an unknown reason.
/// Retrieve the state of the specified hart ID.
///
/// ### Possible errors
///
/// [`SbiError::INVALID_PARAMETER`]: The specified hart ID is not valid.
/// Places the current hart into a suspended or low power state specified by the
/// `suspend_type` parameter. The hart will resume normal execution after an
/// interrupt or platform-specific hardware event. The resume behavior depends
/// on the type of suspension passed to this call: retentive suspend types will
/// save all supervisor register and CSR states, and the hart will continue the
/// execution path after being woken (as in, from the supervisor point-of-view,
/// the SBI call returned normally with nothing changing inbetween).
/// Non-retentive suspend types will **not** save any supervisor register or CSR
/// state, and will resume execution at the given `resume_address` with:
///
/// `satp` is reset to a value of `0` (virtual memory protection disabled)
///
/// `sstatus.SIE` is reset to a value of `0` (supervisor interrupts disabled)
///
/// `a0` contains the current hart ID
///
/// `a1` contains the value of the `opaque` parameter
///
/// All other register states are undefined
///
/// ### Safety
///
/// This function is unsafe as it allows arbitrary execution at a given physical
/// address, which may cause undefined behavior if used incorrectly.
///
/// ### Possible errors
///
/// [`SbiError::INVALID_ADDRESS`]: An invalid address was given for
/// `resume_address` because it was either: an invalid physical address, or
/// the resume address is probited by Physical Memory Protection (PMP) to
/// run in supervisor mode.
///
/// [`SbiError::NOT_SUPPORTED`]: The given `suspend_type` is valid but not
/// implemented.
///
/// [`SbiError::FAILED`]: The suspension request failed for an unknown reason.
pub unsafe
/// The type of suspension to be executed whe ncalling [`hart_suspend`]
/// Execution state for a hart