File tree 2 files changed +38
-9
lines changed
2 files changed +38
-9
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ readme = "README.md"
17
17
v2 = []
18
18
v3 = [" qingke/v3" ]
19
19
v4 = []
20
+
21
+ u-mode = []
20
22
# v5 is not released yet
21
23
# v5 = []
22
24
Original file line number Diff line number Diff line change @@ -120,12 +120,24 @@ unsafe extern "C" fn qingke_setup_interrupts() {
120
120
// 0x3 both nested interrupts and hardware stack
121
121
// 0x1 only hardware stack
122
122
123
+ // for user mode: mstatus = 0x80
124
+ // mpp(m-mode previous privilege) = 0b00 = U
125
+ // mpie(m-mode previous interrupt enable) = 0b1
126
+ // mie(m-mode interrupt enable) = 0b0
127
+ // interrupts will be enabled when mret at the end of handle_reset
128
+ // jumps to main (mret does mie = mpie)
129
+ // for machine mode: mstatus = 0x1880
130
+ // mpp = 0b11
131
+ // mpie = 0b1
132
+ // mie = 0b0
133
+
123
134
// Qingke V2A, V2C
135
+ // (does not have user mode)
124
136
#[ cfg( feature = "v2" ) ]
125
137
{
126
138
core:: arch:: asm!(
127
139
"
128
- li t0, 0x80
140
+ li t0, 0x1880
129
141
csrw mstatus, t0
130
142
li t0, 0x3
131
143
csrw 0x804, t0
@@ -136,33 +148,48 @@ unsafe extern "C" fn qingke_setup_interrupts() {
136
148
// Qingke V3A
137
149
#[ cfg( feature = "v3" ) ]
138
150
{
151
+ #[ cfg( feature = "u-mode" ) ]
152
+ core:: arch:: asm!(
153
+ "
154
+ li t0, 0x80
155
+ csrs mstatus, t0
156
+ "
157
+ ) ;
158
+ #[ cfg( not( feature = "u-mode" ) ) ]
139
159
core:: arch:: asm!(
140
160
"
141
- li t0, 0x88
161
+ li t0, 0x1880
142
162
csrs mstatus, t0
143
- "
163
+ "
144
164
) ;
145
165
}
146
166
147
- // return to user mode
148
- // mstate
149
- // - use 0x88 to set mpp=0, return to user mode
150
- // - use 0x1888 to set mpp=3, return to machine mode
151
-
152
167
// corecfgr(0xbc0): 流水线控制位 & 动态预测控制位
153
168
// corecfgr(0xbc0): Pipeline control bit & Dynamic prediction control
154
169
#[ cfg( any(
155
170
feature = "v4" ,
156
171
not( any( feature = "v2" , feature = "v3" , feature = "v4" ) ) // Fallback condition
157
172
) ) ]
158
173
{
174
+ #[ cfg( feature = "u-mode" ) ]
175
+ core:: arch:: asm!(
176
+ "
177
+ li t0, 0x1f
178
+ csrw 0xbc0, t0
179
+ li t0, 0x3
180
+ csrw 0x804, t0
181
+ li t0, 0x80
182
+ csrs mstatus, t0
183
+ "
184
+ ) ;
185
+ #[ cfg( not( feature = "u-mode" ) ) ]
159
186
core:: arch:: asm!(
160
187
"
161
188
li t0, 0x1f
162
189
csrw 0xbc0, t0
163
190
li t0, 0x3
164
191
csrw 0x804, t0
165
- li t0, 0x88
192
+ li t0, 0x1880
166
193
csrs mstatus, t0
167
194
"
168
195
) ;
You can’t perform that action at this time.
0 commit comments