Skip to content

Commit c877719

Browse files
committed
fix: unrecognized instruction mnemonic on riscv target
ref: rust-lang/rust#134960
1 parent 1983d50 commit c877719

File tree

1 file changed

+48
-63
lines changed

1 file changed

+48
-63
lines changed

src/arch/riscv.rs

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,9 @@ impl TaskContext {
6161
}
6262

6363
#[cfg(target_arch = "riscv32")]
64-
core::arch::global_asm!(
65-
r"
66-
.ifndef XLENB
67-
.equ XLENB, 4
68-
69-
.macro LDR rd, rs, off
70-
lw \rd, \off*XLENB(\rs)
71-
.endm
72-
.macro STR rs2, rs1, off
73-
sw \rs2, \off*XLENB(\rs1)
74-
.endm
75-
76-
.endif"
77-
);
78-
64+
const XLENB: usize = 4;
7965
#[cfg(target_arch = "riscv64")]
80-
core::arch::global_asm!(
81-
r"
82-
.ifndef XLENB
83-
.equ XLENB, 8
84-
85-
.macro LDR rd, rs, off
86-
ld \rd, \off*XLENB(\rs)
87-
.endm
88-
.macro STR rs2, rs1, off
89-
sd \rs2, \off*XLENB(\rs1)
90-
.endm
91-
92-
.endif",
93-
);
66+
const XLENB: usize = 8;
9467

9568
#[naked]
9669
/// Switches the context from the current task to the next task.
@@ -101,40 +74,52 @@ core::arch::global_asm!(
10174
pub unsafe extern "C" fn context_switch(_current_task: &mut TaskContext, _next_task: &TaskContext) {
10275
unsafe {
10376
naked_asm!(
104-
"
105-
// save old context (callee-saved registers)
106-
STR ra, a0, 0
107-
STR sp, a0, 1
108-
STR s0, a0, 2
109-
STR s1, a0, 3
110-
STR s2, a0, 4
111-
STR s3, a0, 5
112-
STR s4, a0, 6
113-
STR s5, a0, 7
114-
STR s6, a0, 8
115-
STR s7, a0, 9
116-
STR s8, a0, 10
117-
STR s9, a0, 11
118-
STR s10, a0, 12
119-
STR s11, a0, 13
120-
121-
// restore new context
122-
LDR s11, a1, 13
123-
LDR s10, a1, 12
124-
LDR s9, a1, 11
125-
LDR s8, a1, 10
126-
LDR s7, a1, 9
127-
LDR s6, a1, 8
128-
LDR s5, a1, 7
129-
LDR s4, a1, 6
130-
LDR s3, a1, 5
131-
LDR s2, a1, 4
132-
LDR s1, a1, 3
133-
LDR s0, a1, 2
134-
LDR sp, a1, 1
135-
LDR ra, a1, 0
136-
137-
ret",
77+
r"
78+
.ifndef XLENB
79+
.equ XLENB, {XLENB}
80+
81+
.macro LDR rd, rs, off
82+
ld \rd, \off*XLENB(\rs)
83+
.endm
84+
.macro STR rs2, rs1, off
85+
sd \rs2, \off*XLENB(\rs1)
86+
.endm
87+
.endif
88+
89+
// save old context (callee-saved registers)
90+
STR ra, a0, 0
91+
STR sp, a0, 1
92+
STR s0, a0, 2
93+
STR s1, a0, 3
94+
STR s2, a0, 4
95+
STR s3, a0, 5
96+
STR s4, a0, 6
97+
STR s5, a0, 7
98+
STR s6, a0, 8
99+
STR s7, a0, 9
100+
STR s8, a0, 10
101+
STR s9, a0, 11
102+
STR s10, a0, 12
103+
STR s11, a0, 13
104+
105+
// restore new context
106+
LDR s11, a1, 13
107+
LDR s10, a1, 12
108+
LDR s9, a1, 11
109+
LDR s8, a1, 10
110+
LDR s7, a1, 9
111+
LDR s6, a1, 8
112+
LDR s5, a1, 7
113+
LDR s4, a1, 6
114+
LDR s3, a1, 5
115+
LDR s2, a1, 4
116+
LDR s1, a1, 3
117+
LDR s0, a1, 2
118+
LDR sp, a1, 1
119+
LDR ra, a1, 0
120+
121+
ret",
122+
XLENB = const XLENB
138123
)
139124
}
140125
}

0 commit comments

Comments
 (0)